Implement typeof window inlining for Turbopack (#66128)

## What?

Update: Implemented a feature in Turbopack for `typeof window` inlining:
https://github.com/vercel/turbo/pull/8211. Verified the changes in that
PR + this PR fix the test 💯


Turbopack upgrade:

* https://github.com/vercel/turbo/pull/8081 <!-- Alexander Lyon - add
support for upload speed / remaining in the cache upload step -->
* https://github.com/vercel/turbo/pull/7673 <!-- Alexander Lyon -
[turbo-trace] add additional filter modes for allocs over time -->
* https://github.com/vercel/turbo/pull/8191 <!-- Will Binns-Smith -
Turbopack: Register react refresh exports in module factory -->
* https://github.com/vercel/turbo/pull/8195 <!-- Donny/강동윤 - feat:
Remove lint for `grid-template-areas`" -->
* https://github.com/vercel/turbo/pull/8207 <!-- Benjamin Woodruff -
chore: Remove unused `base16` dependency and dead `hex` wrapper function
-->
* https://github.com/vercel/turbo/pull/8185 <!-- Tim Neutkens - Update
contributing guide to mention snapshot test updating -->
* https://github.com/vercel/turbo/pull/8211 <!-- Tim Neutkens - Add
option for inlining typeof window -->
* https://github.com/vercel/turbo/pull/8214 <!-- Will Binns-Smith -
Revert "Turbopack: Register react refresh exports in module factory
(#8191)" -->

---

Previous PR description::

Implements a failing test for issue #66058.
The test only fails when using Turbopack.

While digging into that issue I found that `typeof window` replacement
is either not applied or does not cause `import()` or `require()` to be
removed. In the reproduction that approach is used to load a particular
package only in Node.js and another only in the browser.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
This commit is contained in:
Tim Neutkens 2024-05-26 12:25:40 +02:00 committed by GitHub
parent 20201a11a2
commit 216ce33b5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 123 additions and 276 deletions

305
Cargo.lock generated
View file

@ -321,7 +321,7 @@ dependencies = [
[[package]]
name = "auto-hash-map"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"serde",
"smallvec",
@ -399,12 +399,6 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "base16"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8"
[[package]]
name = "base64"
version = "0.13.1"
@ -450,29 +444,6 @@ dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.69.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
dependencies = [
"bitflags 2.5.0",
"cexpr",
"clang-sys",
"itertools 0.12.0",
"lazy_static",
"lazycell",
"log",
"prettyplease",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 2.0.58",
"which",
]
[[package]]
name = "binding_macros"
version = "0.66.0"
@ -701,15 +672,6 @@ dependencies = [
"libc",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-expr"
version = "0.15.4"
@ -741,17 +703,6 @@ dependencies = [
"windows-targets 0.48.1",
]
[[package]]
name = "clang-sys"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clap"
version = "4.5.2"
@ -1691,12 +1642,6 @@ dependencies = [
"libc",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "funty"
version = "2.0.0"
@ -2021,15 +1966,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "hstr"
version = "0.2.8"
@ -2152,41 +2088,6 @@ dependencies = [
"tungstenite 0.18.0",
]
[[package]]
name = "iai-callgrind"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e99bf26f496b13ac6273014f40afda46a233fbfb0289ce50fb4daaad2f2ffc80"
dependencies = [
"bincode",
"bindgen",
"cc",
"iai-callgrind-macros",
"iai-callgrind-runner",
"regex",
]
[[package]]
name = "iai-callgrind-macros"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2a4bb39225592c0a28cfca6f70af52ebd8da23f533c2cdd0a3329c1fa252d56"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.58",
]
[[package]]
name = "iai-callgrind-runner"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c23a951b9eccaa1e38556d27473d1462a9c247a27961812edcaac156af861282"
dependencies = [
"serde",
]
[[package]]
name = "iana-time-zone"
version = "0.1.57"
@ -2503,12 +2404,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "leb128"
version = "0.2.5"
@ -3106,28 +3001,6 @@ dependencies = [
"vergen 7.5.1",
]
[[package]]
name = "next-build-test"
version = "0.1.0"
dependencies = [
"anyhow",
"futures-util",
"iai-callgrind",
"next-api",
"next-core",
"num_cpus",
"rand 0.8.5",
"serde_json",
"tempdir",
"tokio",
"tokio-stream",
"tracing",
"tracing-subscriber",
"turbo-tasks",
"turbo-tasks-malloc",
"turbopack-binding",
]
[[package]]
name = "next-core"
version = "0.1.0"
@ -3220,7 +3093,7 @@ dependencies = [
[[package]]
name = "node-file-trace"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"serde",
@ -3726,7 +3599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
dependencies = [
"phf_shared 0.10.0",
"rand 0.8.5",
"rand",
]
[[package]]
@ -3736,7 +3609,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared 0.11.2",
"rand 0.8.5",
"rand",
]
[[package]]
@ -3889,16 +3762,6 @@ dependencies = [
"yansi",
]
[[package]]
name = "prettyplease"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7"
dependencies = [
"proc-macro2",
"syn 2.0.58",
]
[[package]]
name = "priority-queue"
version = "1.3.1"
@ -4028,19 +3891,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce082a9940a7ace2ad4a8b7d0b1eac6aa378895f18be598230c5f2284ac05426"
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
@ -4049,7 +3899,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core 0.6.4",
"rand_core",
]
[[package]]
@ -4059,24 +3909,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
@ -4121,7 +3956,7 @@ dependencies = [
"num-traits",
"once_cell",
"paste",
"rand 0.8.5",
"rand",
"rand_chacha",
"rust_hawktracer",
"rustc_version 0.4.0",
@ -4172,15 +4007,6 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "react_remove_properties"
version = "0.24.12"
@ -4312,15 +4138,6 @@ dependencies = [
"swc_ecma_visit",
]
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "rend"
version = "0.4.0"
@ -4902,12 +4719,6 @@ dependencies = [
"memmap2 0.6.2",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook"
version = "0.3.17"
@ -6651,16 +6462,6 @@ version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5"
[[package]]
name = "tempdir"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
dependencies = [
"rand 0.4.6",
"remove_dir_all",
]
[[package]]
name = "tempfile"
version = "3.8.0"
@ -7117,7 +6918,7 @@ dependencies = [
"http 0.2.11",
"httparse",
"log",
"rand 0.8.5",
"rand",
"sha1",
"thiserror",
"url",
@ -7136,7 +6937,7 @@ dependencies = [
"http 1.1.0",
"httparse",
"log",
"rand 0.8.5",
"rand",
"sha1",
"thiserror",
"url",
@ -7146,7 +6947,7 @@ dependencies = [
[[package]]
name = "turbo-tasks"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-trait",
@ -7178,7 +6979,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-build"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"cargo-lock",
@ -7190,7 +6991,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-bytes"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"bytes",
@ -7204,7 +7005,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-env"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"dotenvs",
@ -7218,7 +7019,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-fetch"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"lazy_static",
@ -7234,7 +7035,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-fs"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"auto-hash-map",
@ -7266,10 +7067,8 @@ dependencies = [
[[package]]
name = "turbo-tasks-hash"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"base16",
"hex",
"md4",
"turbo-tasks-macros",
"twox-hash",
@ -7278,7 +7077,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-macros"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"proc-macro-error",
@ -7292,7 +7091,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-macros-shared"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"proc-macro2",
"quote",
@ -7302,7 +7101,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-malloc"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"mimalloc",
]
@ -7310,7 +7109,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-memory"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"auto-hash-map",
@ -7336,7 +7135,7 @@ dependencies = [
[[package]]
name = "turbopack"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-recursion",
@ -7366,7 +7165,7 @@ dependencies = [
[[package]]
name = "turbopack-binding"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"auto-hash-map",
"mdxjs",
@ -7407,7 +7206,7 @@ dependencies = [
[[package]]
name = "turbopack-browser"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7430,7 +7229,7 @@ dependencies = [
[[package]]
name = "turbopack-cli-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"clap",
@ -7447,7 +7246,7 @@ dependencies = [
[[package]]
name = "turbopack-core"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-recursion",
@ -7476,7 +7275,7 @@ dependencies = [
[[package]]
name = "turbopack-css"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7503,7 +7302,7 @@ dependencies = [
[[package]]
name = "turbopack-dev-server"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-compression",
@ -7539,7 +7338,7 @@ dependencies = [
[[package]]
name = "turbopack-ecmascript"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-trait",
@ -7574,7 +7373,7 @@ dependencies = [
[[package]]
name = "turbopack-ecmascript-hmr-protocol"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"serde",
"serde_json",
@ -7585,7 +7384,7 @@ dependencies = [
[[package]]
name = "turbopack-ecmascript-plugins"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-trait",
@ -7609,7 +7408,7 @@ dependencies = [
[[package]]
name = "turbopack-ecmascript-runtime"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indoc",
@ -7625,7 +7424,7 @@ dependencies = [
[[package]]
name = "turbopack-env"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7641,7 +7440,7 @@ dependencies = [
[[package]]
name = "turbopack-image"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"base64 0.21.4",
@ -7660,7 +7459,7 @@ dependencies = [
[[package]]
name = "turbopack-json"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"serde",
@ -7675,7 +7474,7 @@ dependencies = [
[[package]]
name = "turbopack-mdx"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"mdxjs",
@ -7690,7 +7489,7 @@ dependencies = [
[[package]]
name = "turbopack-node"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"async-stream",
@ -7724,7 +7523,7 @@ dependencies = [
[[package]]
name = "turbopack-nodejs"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7744,7 +7543,7 @@ dependencies = [
[[package]]
name = "turbopack-resolve"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7762,7 +7561,7 @@ dependencies = [
[[package]]
name = "turbopack-static"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"serde",
@ -7778,7 +7577,7 @@ dependencies = [
[[package]]
name = "turbopack-swc-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"swc_core",
"turbo-tasks",
@ -7789,7 +7588,7 @@ dependencies = [
[[package]]
name = "turbopack-trace-server"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"either",
@ -7809,7 +7608,7 @@ dependencies = [
[[package]]
name = "turbopack-trace-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"crossbeam-channel",
@ -7825,7 +7624,7 @@ dependencies = [
[[package]]
name = "turbopack-wasm"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240521.2#2af6b12b3dc142316a2ba882ea5332c9a847f2a4"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240526.2#63c39e68e0f9903405b3ba527425ee1f2ec47f2c"
dependencies = [
"anyhow",
"indexmap 1.9.3",
@ -7847,7 +7646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if",
"rand 0.8.5",
"rand",
"static_assertions",
]
@ -8571,7 +8370,7 @@ dependencies = [
"once_cell",
"petgraph",
"pin-project",
"rand 0.8.5",
"rand",
"rusty_pool",
"semver 1.0.23",
"serde",
@ -8702,7 +8501,7 @@ dependencies = [
"lexical-sort",
"once_cell",
"path-clean 1.0.1",
"rand 0.8.5",
"rand",
"semver 1.0.23",
"serde",
"serde_cbor",
@ -8743,18 +8542,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "which"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
dependencies = [
"either",
"home",
"once_cell",
"rustix",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -6,7 +6,6 @@ members = [
"packages/next-swc/crates/napi",
"packages/next-swc/crates/wasm",
"packages/next-swc/crates/next-api",
"packages/next-swc/crates/next-build-test",
"packages/next-swc/crates/next-build",
"packages/next-swc/crates/next-core",
"packages/next-swc/crates/next-custom-transforms",
@ -23,11 +22,6 @@ debug-assertions = false
[profile.dev.build-override]
opt-level = 3
[profile.release-with-debug]
inherits = "release"
debug = true
lto = "thin"
[workspace.dependencies]
# Workspace crates
next-api = { path = "packages/next-swc/crates/next-api" }
@ -43,12 +37,11 @@ swc_core = { version = "0.92.5", features = [
testing = { version = "0.35.24" }
# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240526.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240526.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }
turbo-tasks-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240521.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240526.2" }
# General Deps

View file

@ -27,7 +27,7 @@ use turbopack_binding::{
condition::ContextCondition,
module_options::{
module_options_context::ModuleOptionsContext, JsxTransformOptions, ModuleRule,
TypescriptTransformOptions,
TypeofWindow, TypescriptTransformOptions,
},
resolve_options_context::ResolveOptionsContext,
},
@ -270,6 +270,7 @@ pub async fn get_client_module_options_context(
let enable_foreign_postcss_transform = Some(postcss_foreign_transform_options.cell());
let module_options_context = ModuleOptionsContext {
enable_typeof_window_inlining: Some(TypeofWindow::Object),
preset_env_versions: Some(env),
execution_context: Some(execution_context),
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
@ -280,6 +281,7 @@ pub async fn get_client_module_options_context(
// node_modules context
let foreign_codes_options_context = ModuleOptionsContext {
enable_typeof_window_inlining: None,
enable_webpack_loaders: foreign_enable_webpack_loaders,
enable_postcss_transform: enable_foreign_postcss_transform,
custom_rules: foreign_next_client_rules,

View file

@ -27,7 +27,8 @@ use turbopack_binding::{
turbopack::{
condition::ContextCondition,
module_options::{
JsxTransformOptions, ModuleOptionsContext, ModuleRule, TypescriptTransformOptions,
JsxTransformOptions, ModuleOptionsContext, ModuleRule, TypeofWindow,
TypescriptTransformOptions,
},
resolve_options_context::ResolveOptionsContext,
transition::Transition,
@ -461,6 +462,7 @@ pub async fn get_server_module_options_context(
let styled_jsx_transform_rule = get_styled_jsx_transform_rule(next_config, versions).await?;
let module_options_context = ModuleOptionsContext {
enable_typeof_window_inlining: Some(TypeofWindow::Undefined),
execution_context: Some(execution_context),
use_swc_css,
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
@ -509,6 +511,7 @@ pub async fn get_server_module_options_context(
};
let foreign_code_module_options_context = ModuleOptionsContext {
enable_typeof_window_inlining: None,
custom_rules: foreign_next_server_rules.clone(),
enable_webpack_loaders: foreign_enable_webpack_loaders,
// NOTE(WEB-1016) PostCSS transforms should also apply to foreign code.
@ -563,6 +566,7 @@ pub async fn get_server_module_options_context(
next_server_rules.extend(source_transform_rules);
let foreign_code_module_options_context = ModuleOptionsContext {
enable_typeof_window_inlining: None,
custom_rules: foreign_next_server_rules.clone(),
enable_webpack_loaders: foreign_enable_webpack_loaders,
// NOTE(WEB-1016) PostCSS transforms should also apply to foreign code.

View file

@ -206,7 +206,7 @@
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.27.1",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240521.2",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240526.2",
"acorn": "8.11.3",
"amphtml-validator": "1.0.35",
"anser": "1.4.9",

View file

@ -1090,8 +1090,8 @@ importers:
specifier: 0.27.1
version: 0.27.1
'@vercel/turbopack-ecmascript-runtime':
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240521.2
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240521.2'
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240526.2
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240526.2'
acorn:
specifier: 8.11.3
version: 8.11.3
@ -25806,8 +25806,8 @@ packages:
/zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240521.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240521.2}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240526.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240526.2}
name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0
dependencies:

View file

@ -0,0 +1,7 @@
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}

View file

@ -0,0 +1,10 @@
'use client'
if (typeof window !== 'undefined') {
import('my-differentiated-files/browser').then((mod) => {
console.log({ TEST: mod.default })
})
}
export default function Page() {
return <h1>Page loaded</h1>
}

View file

@ -0,0 +1 @@
export default 'BROWSER'

View file

@ -0,0 +1 @@
export default 'SERVER'

View file

@ -0,0 +1,14 @@
{
"name": "my-differentiated-files",
"type": "module",
"exports": {
"./browser": {
"browser": "./my-file-browser.js",
"node": null
},
"./server": {
"browser": null,
"node": "./my-file-server.js"
}
}
}

View file

@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig

View file

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"my-differentiated-files": "file:./my-differentiated-files.tar"
}
}

View file

@ -0,0 +1,16 @@
import { nextTestSetup } from 'e2e-utils'
import path from 'path'
describe('typeof-window', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
'my-differentiated-files': `file:${path.join(__dirname, 'my-differentiated-files.tar')}`,
},
})
it('should work using cheerio', async () => {
const $ = await next.render$('/')
expect($('h1').text()).toBe('Page loaded')
})
})