diff --git a/.alexignore b/.alexignore index 1bf6581c26b1..e344f11148c5 100644 --- a/.alexignore +++ b/.alexignore @@ -1,2 +1,3 @@ CODE_OF_CONDUCT.md examples/ +**/*/LICENSE.md diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 01290fe933fd..e4ab4af0ee65 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -1127,7 +1127,7 @@ jobs: toolchain: ${{ env.RUST_TOOLCHAIN }} profile: minimal - - run: cd packages/next-swc && cargo test + - run: cd packages/next-swc && cargo test --workspace --exclude next-dev-tests if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }} test-wasm: diff --git a/.vscode/settings.json b/.vscode/settings.json index c98c9387e7de..69aa16b3e706 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -57,5 +57,16 @@ "explorer.fileNesting.patterns": { "*.ts": "$(capture).test.ts, $(capture).test.tsx", "*.tsx": "$(capture).test.ts, $(capture).test.tsx" + }, + + // Allow to find the cargo project for rust-analyzer. + "rust-analyzer.linkedProjects": ["packages/next-swc/Cargo.toml"], + // Compile rust-analyzer in a separate directory to avoid conflicts with the main project. + "rust-analyzer.checkOnSave.extraEnv": { + "CARGO_TARGET_DIR": "target/rust-analyzer" + }, + "rust-analyzer.server.extraEnv": { + "CARGO_TARGET_DIR": "target/rust-analyzer", + "RUST_BACKTRACE": "0" } } diff --git a/packages/next-swc/.cargo/config.toml b/packages/next-swc/.cargo/config.toml index 3ce2cd799b61..08487cca54f8 100644 --- a/packages/next-swc/.cargo/config.toml +++ b/packages/next-swc/.cargo/config.toml @@ -1,19 +1,33 @@ +[env] +CARGO_WORKSPACE_DIR = { value = "", relative = true } [build] rustdocflags = [] +[target.x86_64-pc-windows-msvc] +linker = "rust-lld" + [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" [target.aarch64-unknown-linux-musl] linker = "aarch64-linux-musl-gcc" rustflags = [ - "-C", - "target-feature=-crt-static", - "-C", - "link-arg=-lgcc", + "--cfg", + "tokio_unstable", + "-Csymbol-mangling-version=v0", + "-Ctarget-feature=-crt-static", + "-Clink-arg=-lgcc", ] [target.armv7-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" + +[target.'cfg(all())'] +rustflags = [ + "--cfg", + "tokio_unstable", + "-Csymbol-mangling-version=v0", + "-Aclippy::too_many_arguments" +] diff --git a/packages/next-swc/Cargo.lock b/packages/next-swc/Cargo.lock index 1bc93a39487d..ee1b34d82ff0 100644 --- a/packages/next-swc/Cargo.lock +++ b/packages/next-swc/Cargo.lock @@ -57,6 +57,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -87,6 +93,25 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "ast_node" version = "0.8.6" @@ -95,10 +120,21 @@ checksum = "cf94863c5fdfee166d0907c44e5fee970123b2b7307046d35d1e671aa93afbba" dependencies = [ "darling 0.13.4", "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", +] + +[[package]] +name = "async-channel" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", ] [[package]] @@ -114,28 +150,188 @@ dependencies = [ "tokio", ] +[[package]] +name = "async-executor" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" +dependencies = [ + "async-lock", + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +dependencies = [ + "async-lock", + "autocfg", + "concurrent-queue", + "futures-lite", + "libc", + "log", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "windows-sys 0.42.0", +] + +[[package]] +name = "async-lock" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-object-pool" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb901c30ebc2fc4ab46395bbfbdba9542c16559d853645d75190c3056caf3bc" +dependencies = [ + "async-std", +] + +[[package]] +name = "async-process" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "libc", + "signal-hook", + "windows-sys 0.42.0", +] + [[package]] name = "async-recursion" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b015a331cc64ebd1774ba119538573603427eaace0a1950c423ab971f903796" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-stream" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad445822218ce64be7a341abfb0b1ea43b5c23aa83902542a4542e78309d8e5e" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965" +dependencies = [ + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] +[[package]] +name = "async-task" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" + [[package]] name = "async-trait" version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] +[[package]] +name = "async-tungstenite" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b71b31561643aa8e7df3effe284fa83ab1a840e52294c5f4bd7bfd8b2becbb" +dependencies = [ + "futures-io", + "futures-util", + "log", + "pin-project-lite", + "tokio", + "tungstenite 0.17.3", +] + +[[package]] +name = "atomic-waker" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" + [[package]] name = "atty" version = "0.2.14" @@ -150,7 +346,7 @@ dependencies = [ [[package]] name = "auto-hash-map" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "serde", ] @@ -162,9 +358,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7862e21c893d65a1650125d157eaeec691439379a1cee17ee49031b79236ada4" dependencies = [ "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -173,6 +369,52 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fb79c228270dcf2426e74864cabc94babb5dbab01a4314e702d2f16540e1591" +dependencies = [ + "async-trait", + "axum-core", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-http", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2f958c80c248b34b9a877a643811be8dbca03ca5ba827f2b63baf3a81e5fc4e" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.67" @@ -212,6 +454,17 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "basic-cookies" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb53b6b315f924c7f113b162e53b3901c05fc9966baf84d201dfcc7432a4bb38" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + [[package]] name = "better_scoped_tls" version = "0.1.0" @@ -242,6 +495,21 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -271,6 +539,20 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", +] + [[package]] name = "browserslist-rs" version = "0.12.3" @@ -285,7 +567,7 @@ dependencies = [ "js-sys", "nom", "once_cell", - "quote", + "quote 1.0.23", "serde", "serde-wasm-bindgen", "serde_json", @@ -317,9 +599,9 @@ version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e576ebe98e605500b3c8041bb888e966653577172df6dd97398714eb30b9bf" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -346,6 +628,18 @@ dependencies = [ "url", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "castaway" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" + [[package]] name = "cc" version = "1.0.79" @@ -370,6 +664,70 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chromiumoxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5506e432f602b1747e8a0d60ac6607c6977af4ee9720237764170305323e62" +dependencies = [ + "async-tungstenite", + "base64 0.13.1", + "cfg-if 1.0.0", + "chromiumoxide_cdp", + "chromiumoxide_types", + "fnv", + "futures", + "futures-timer", + "pin-project-lite", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "url", + "which", + "winreg", +] + +[[package]] +name = "chromiumoxide_cdp" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b6988af5c6bbf097999e7db879729dd7b27a62010c482d4922fddeb4f220d4" +dependencies = [ + "chromiumoxide_pdl", + "chromiumoxide_types", + "serde", + "serde_json", +] + +[[package]] +name = "chromiumoxide_pdl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cdf6513e24d260548345a5ef13a04110f5915b7764c274933e10f9363a43e3b" +dependencies = [ + "chromiumoxide_types", + "either", + "heck", + "once_cell", + "proc-macro2 1.0.51", + "quote 1.0.23", + "regex", + "serde", + "serde_json", +] + +[[package]] +name = "chromiumoxide_types" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1af9c183b5aac7f09639cc7b4ddde8a8551850d2c9bf36530830cb10e28e676f" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "chrono" version = "0.4.23" @@ -385,6 +743,45 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex 0.2.4", + "indexmap", + "textwrap 0.16.0", +] + [[package]] name = "clap" version = "4.1.8" @@ -393,7 +790,7 @@ checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ "bitflags", "clap_derive", - "clap_lex", + "clap_lex 0.3.1", "is-terminal", "once_cell", "strsim", @@ -408,9 +805,18 @@ checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" dependencies = [ "heck", "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -460,6 +866,42 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console-api" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57ff02e8ad8e06ab9731d5dc72dc23bef9200778eae1a89d555d8c42e5d4a86" +dependencies = [ + "prost", + "prost-types", + "tonic", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a3a81dfaf6b66bce5d159eddae701e3a002f194d378cbf7be5f053c281d9be" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures", + "hdrhistogram", + "humantime", + "prost-types", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -618,6 +1060,44 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap 3.2.23", + "criterion-plot", + "futures", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "tokio", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -686,6 +1166,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -702,8 +1188,8 @@ version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ - "quote", - "syn", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -712,6 +1198,37 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "curl" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.60+curl-7.88.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "717abe2cb465a5da6ce06617388a3980c9a2844196734bec8ccb8e575250f13f" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + [[package]] name = "cxx" version = "1.0.90" @@ -733,10 +1250,10 @@ dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "scratch", - "syn", + "syn 1.0.107", ] [[package]] @@ -751,9 +1268,9 @@ version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebf883b7aacd7b2aeb2a7b338648ee19f57c140d4ee8e52c68979c6b2f7f2263" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -784,10 +1301,10 @@ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" dependencies = [ "fnv", "ident_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "strsim", - "syn", + "syn 1.0.107", ] [[package]] @@ -798,9 +1315,9 @@ checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ "fnv", "ident_case", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -810,8 +1327,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core 0.13.4", - "quote", - "syn", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -821,8 +1338,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ "darling_core 0.14.3", - "quote", - "syn", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -880,6 +1397,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -891,6 +1418,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + [[package]] name = "discard" version = "1.0.4" @@ -921,6 +1459,15 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "ena" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2e5d13ca2353ab7d0230988629def93914a8c4015f621f9b13ed2955614731d" +dependencies = [ + "log", +] + [[package]] name = "encoding_rs" version = "0.8.32" @@ -954,9 +1501,9 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -965,9 +1512,9 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "828de45d0ca18782232dfb8f3ea9cc428e8ced380eb26a520baaacfc70de39ce" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -977,9 +1524,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b940da354ae81ef0926c5eaa428207b8f4f091d3956c891dfbd124162bed99" dependencies = [ "pmutil", - "proc-macro2", + "proc-macro2 1.0.51", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -998,9 +1545,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03e7b551eba279bf0fa88b83a46330168c1560a52a94f5126f892f0b364ab3e0" dependencies = [ "darling 0.14.3", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", ] [[package]] @@ -1119,11 +1679,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0981e470d2ab9f643df3921d54f1952ea100c39fdb6a3fdc820e20d2291df6c" dependencies = [ "pmutil", - "proc-macro2", + "proc-macro2 1.0.51", "swc_macros_common", - "syn", + "syn 1.0.107", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "fsevent" version = "0.4.0" @@ -1207,15 +1773,30 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -1241,6 +1822,12 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + [[package]] name = "futures-util" version = "0.3.26" @@ -1307,9 +1894,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" dependencies = [ "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -1335,6 +1922,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "h2" version = "0.3.15" @@ -1354,6 +1953,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "handlebars" version = "4.3.6" @@ -1386,6 +1991,19 @@ dependencies = [ "ahash", ] +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "base64 0.13.1", + "byteorder", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "heck" version = "0.4.1" @@ -1455,6 +2073,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + [[package]] name = "httparse" version = "1.8.0" @@ -1467,6 +2091,43 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "httpmock" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b56b6265f15908780cbee987912c1e98dbca675361f748291605a8a3a1df09" +dependencies = [ + "assert-json-diff", + "async-object-pool", + "async-trait", + "base64 0.13.1", + "basic-cookies", + "clap 4.1.8", + "crossbeam-utils", + "env_logger", + "form_urlencoded", + "futures-util", + "hyper", + "isahc", + "lazy_static", + "levenshtein", + "log", + "regex", + "serde", + "serde_json", + "serde_regex", + "serde_yaml", + "similar", + "tokio", + "url", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.24" @@ -1504,6 +2165,18 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -1527,7 +2200,7 @@ dependencies = [ "pin-project", "tokio", "tokio-tungstenite", - "tungstenite", + "tungstenite 0.18.0", ] [[package]] @@ -1591,8 +2264,8 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", ] [[package]] @@ -1675,9 +2348,9 @@ checksum = "1c068d4c6b922cd6284c609cfa6dec0e41615c9c5a1a4ba729a970d8daba05fb" dependencies = [ "Inflector", "pmutil", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -1698,6 +2371,33 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" +[[package]] +name = "isahc" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "334e04b4d781f436dc315cb1e7515bd96826426345d498149e4bde36b67f8ee9" +dependencies = [ + "async-channel", + "castaway", + "crossbeam-utils", + "curl", + "curl-sys", + "encoding_rs", + "event-listener", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "polling", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1767,6 +2467,47 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lalrpop" +version = "0.19.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" +dependencies = [ + "ascii-canvas", + "atty", + "bit-set", + "diff", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "pico-args", + "regex", + "regex-syntax", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid 0.2.4", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" +dependencies = [ + "regex", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1785,6 +2526,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +[[package]] +name = "levenshtein" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" + [[package]] name = "lexical" version = "6.1.1" @@ -1884,6 +2631,28 @@ dependencies = [ "libc", ] +[[package]] +name = "libnghttp2-sys" +version = "0.1.7+1.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "link-cplusplus" version = "1.0.8" @@ -1916,6 +2685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -1935,8 +2705,8 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" dependencies = [ - "quote", - "syn", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -1990,6 +2760,12 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "matchit" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" + [[package]] name = "md4" version = "0.10.2" @@ -2058,7 +2834,7 @@ dependencies = [ "supports-hyperlinks", "supports-unicode", "terminal_size", - "textwrap", + "textwrap 0.15.2", "thiserror", "unicode-width", ] @@ -2069,9 +2845,9 @@ version = "4.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2083,6 +2859,26 @@ dependencies = [ "libmimalloc-sys", ] +[[package]] +name = "mimalloc-rust" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6973866e0bc6504c03a16b6817b7e70839cc8a1dbd5d6dab00c65d8034868d8b" +dependencies = [ + "cty", + "mimalloc-rust-sys", +] + +[[package]] +name = "mimalloc-rust-sys" +version = "1.7.6-source" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a50daf45336b979a202a19f53b4b382f2c4bd50f392a8dbdb4c6c56ba5dfa64" +dependencies = [ + "cc", + "cty", +] + [[package]] name = "mime" version = "0.3.16" @@ -2226,9 +3022,9 @@ checksum = "03f15c1ac0eac01eca2a24c27905ab47f7411acefd829d0d01fb131dc39befd7" dependencies = [ "convert_case 0.6.0", "napi-derive-backend", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2239,10 +3035,10 @@ checksum = "4930d5fa70f5663b9e7d6b4f0816b70d095574ee7f3c865fdb8c43b0f7e6406d" dependencies = [ "convert_case 0.6.0", "once_cell", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "regex", - "syn", + "syn 1.0.107", ] [[package]] @@ -2298,7 +3094,6 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" [[package]] name = "next-binding" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" dependencies = [ "mdxjs", "modularize_imports", @@ -2314,7 +3109,6 @@ dependencies = [ [[package]] name = "next-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" dependencies = [ "anyhow", "auto-hash-map", @@ -2344,33 +3138,85 @@ dependencies = [ [[package]] name = "next-dev" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" dependencies = [ "anyhow", + "chromiumoxide", + "clap 4.1.8", + "console-subscriber", + "criterion", "dunce", "futures", "mime", "next-core", + "nix", + "once_cell", "owo-colors", + "parking_lot", + "portpicker", + "rand", + "regex", "serde", + "serde_json", + "tempfile", "tokio", + "tungstenite 0.17.3", "turbo-malloc", "turbo-tasks", "turbo-tasks-build", "turbo-tasks-fs", "turbo-tasks-memory", + "turbo-tasks-testing", "turbopack-cli-utils", "turbopack-core", + "turbopack-create-test-app", "turbopack-dev-server", "turbopack-node", + "url", "vergen", "webbrowser", ] +[[package]] +name = "next-dev-tests" +version = "0.1.0" +dependencies = [ + "anyhow", + "chromiumoxide", + "console-subscriber", + "futures", + "httpmock", + "lazy_static", + "mime", + "next-core", + "next-dev", + "owo-colors", + "parking_lot", + "rand", + "regex", + "serde", + "serde_json", + "test-generator", + "tokio", + "tungstenite 0.17.3", + "turbo-malloc", + "turbo-tasks", + "turbo-tasks-build", + "turbo-tasks-fs", + "turbo-tasks-memory", + "turbo-tasks-testing", + "turbopack-cli-utils", + "turbopack-core", + "turbopack-dev-server", + "turbopack-node", + "turbopack-test-utils", + "url", + "webbrowser", +] + [[package]] name = "next-font" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "rustc-hash", "serde", @@ -2427,7 +3273,7 @@ dependencies = [ [[package]] name = "next-transform-dynamic" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "pathdiff", "swc_core", @@ -2436,20 +3282,34 @@ dependencies = [ [[package]] name = "next-transform-strip-page-exports" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "rustc-hash", "swc_core", "tracing", ] +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "libc", + "memoffset 0.7.1", + "pin-utils", + "static_assertions", +] + [[package]] name = "node-file-trace" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", - "clap", + "clap 4.1.8", "serde", "serde_json", "tokio", @@ -2593,6 +3453,12 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "openssl" version = "0.10.45" @@ -2614,9 +3480,9 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2665,6 +3531,12 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.12.1" @@ -2758,9 +3630,9 @@ checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" dependencies = [ "pest", "pest_meta", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2814,9 +3686,9 @@ dependencies = [ "phf_generator", "phf_shared", "proc-macro-hack", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2828,6 +3700,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + [[package]] name = "pin-project" version = "1.0.12" @@ -2843,9 +3721,9 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -2867,14 +3745,67 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] -name = "pmutil" -version = "0.5.3" +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "pmutil" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +dependencies = [ + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "polling" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if 1.0.0", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.45.0", +] + +[[package]] +name = "portpicker" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" dependencies = [ - "proc-macro2", - "quote", - "syn", + "rand", ] [[package]] @@ -2936,9 +3867,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", "version_check", ] @@ -2948,8 +3879,8 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "version_check", ] @@ -2959,6 +3890,15 @@ version = "0.5.20+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.51" @@ -2968,6 +3908,38 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "prost-types" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "379119666929a1afd7a043aa6cf96fa67a6dce9af60c88095a4686dbce4c9c88" +dependencies = [ + "prost", +] + [[package]] name = "psm" version = "0.1.21" @@ -2992,9 +3964,9 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -3006,13 +3978,22 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.51", ] [[package]] @@ -3258,9 +4239,9 @@ version = "0.7.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -3554,9 +4535,9 @@ version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -3613,6 +4594,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f82e6c8c047aa50a7328632d067bcae6ef38772a79e28daf32f735e0e4f3dd10" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha-1" version = "0.10.0" @@ -3700,6 +4694,12 @@ dependencies = [ "libc", ] +[[package]] +name = "similar" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" + [[package]] name = "siphasher" version = "0.3.10" @@ -3715,6 +4715,17 @@ dependencies = [ "autocfg", ] +[[package]] +name = "sluice" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7400c0eff44aa2fcb5e31a5f24ba9716ed90138769e4977a2ba6014ae63eb5" +dependencies = [ + "async-channel", + "futures-core", + "futures-io", +] + [[package]] name = "smallvec" version = "1.10.0" @@ -3803,9 +4814,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "752564de9cd8937fdbc1c55d47ac391758c352ab3755607cc391b659fe87d56b" dependencies = [ "pmutil", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -3834,11 +4845,11 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "serde", "serde_derive", - "syn", + "syn 1.0.107", ] [[package]] @@ -3848,13 +4859,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "serde", "serde_derive", "serde_json", "sha1 0.6.1", - "syn", + "syn 1.0.107", ] [[package]] @@ -3885,8 +4896,8 @@ checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ "phf_generator", "phf_shared", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", ] [[package]] @@ -3896,10 +4907,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "994453cd270ad0265796eb24abf5540091ed03e681c5f3c12bc33e4db33253e1" dependencies = [ "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4133,10 +5144,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb64bc03d90fd5c90d6ab917bb2b1d7fbd31957df39e31ea24a3f554b4372251" dependencies = [ "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4174,6 +5185,7 @@ dependencies = [ "swc_ecma_transforms_typescript", "swc_ecma_utils", "swc_ecma_visit", + "swc_node_base", "swc_nodejs_common", "swc_plugin_proxy", "swc_plugin_runner", @@ -4221,10 +5233,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe27425548d11afee43ddbe1d0cd882cb5e042f61b1503651dae2219c92333f5" dependencies = [ "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4363,10 +5375,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0159c99f81f52e48fe692ef7af1b0990b45d3006b14c6629be0b1ffee1b23aea" dependencies = [ "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4514,14 +5526,14 @@ checksum = "5f861c0631c00f1062c3035d8d0b58ebbeee0b53622ae597b394b2524ed2162f" dependencies = [ "anyhow", "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_atoms", "swc_common", "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4627,10 +5639,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebf907935ec5492256b523ae7935a824d9fdc0368dcadc41375bad0dca91cd8b" dependencies = [ "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", ] [[package]] @@ -4851,9 +5863,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c20468634668c2bbab581947bb8c75c97158d5a6959f4ba33df20983b20b4f6" dependencies = [ "pmutil", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -4901,9 +5913,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4be988307882648d9bc7c71a6a73322b7520ef0211e920489a98f8391d8caa2" dependencies = [ "pmutil", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", +] + +[[package]] +name = "swc_node_base" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6065892f97ac3f42280d0f3eadc351aeff552e8de4d459604bcd9c56eb799ade" +dependencies = [ + "mimalloc-rust", + "tikv-jemallocator", ] [[package]] @@ -4984,9 +6006,9 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4795c8d23e0de62eef9cac0a20ae52429ee2ffc719768e838490f195b7d7267" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -5007,10 +6029,21 @@ checksum = "6098b717cfd4c85f5cddec734af191dbce461c39975ed567c32ac6d0c6d61a6d" dependencies = [ "Inflector", "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "swc_macros_common", - "syn", + "syn 1.0.107", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", ] [[package]] @@ -5019,11 +6052,17 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "target-lexicon" version = "0.12.6" @@ -5044,6 +6083,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi 0.3.9", +] + [[package]] name = "termcolor" version = "1.2.0" @@ -5063,6 +6113,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "test-generator" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b23be2add79223226e1cb6446cb3e37506a5927089870687a0f1149bb7a073a" +dependencies = [ + "glob", + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "testing" version = "0.31.33" @@ -5092,11 +6154,11 @@ dependencies = [ "glob", "once_cell", "pmutil", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "regex", "relative-path", - "syn", + "syn 1.0.107", ] [[package]] @@ -5110,6 +6172,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.38" @@ -5125,9 +6193,9 @@ version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -5140,6 +6208,27 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.4.3+5.2.1-patched.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b7bcecfafe4998587d636f9ae9d55eb9d0499877b88757767c346875067098" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.1.45" @@ -5210,10 +6299,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", - "proc-macro2", - "quote", + "proc-macro2 1.0.51", + "quote 1.0.23", "standback", - "syn", + "syn 1.0.107", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", ] [[package]] @@ -5248,18 +6356,29 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", + "tracing", "windows-sys 0.42.0", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -5303,7 +6422,7 @@ dependencies = [ "futures-util", "log", "tokio", - "tungstenite", + "tungstenite 0.18.0", ] [[package]] @@ -5329,6 +6448,83 @@ dependencies = [ "serde", ] +[[package]] +name = "tonic" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.13.1", + "bytes", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "prost-derive", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", + "tracing-futures", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -5354,9 +6550,9 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] @@ -5435,6 +6631,25 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "tungstenite" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand", + "sha-1", + "thiserror", + "url", + "utf-8", +] + [[package]] name = "tungstenite" version = "0.18.0" @@ -5457,7 +6672,7 @@ dependencies = [ [[package]] name = "turbo-malloc" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "mimalloc", ] @@ -5465,7 +6680,7 @@ dependencies = [ [[package]] name = "turbo-tasks" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "auto-hash-map", @@ -5495,19 +6710,19 @@ dependencies = [ [[package]] name = "turbo-tasks-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "cargo-lock", "glob", - "syn", + "syn 1.0.107", "turbo-tasks-macros-shared", ] [[package]] name = "turbo-tasks-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "dotenvy", @@ -5521,7 +6736,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fetch" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "indexmap", @@ -5538,7 +6753,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "auto-hash-map", @@ -5566,7 +6781,7 @@ dependencies = [ [[package]] name = "turbo-tasks-hash" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "base16", "hex", @@ -5578,31 +6793,31 @@ dependencies = [ [[package]] name = "turbo-tasks-macros" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "convert_case 0.6.0", "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", "turbo-tasks-macros-shared", ] [[package]] name = "turbo-tasks-macros-shared" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] name = "turbo-tasks-memory" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "auto-hash-map", @@ -5621,10 +6836,22 @@ dependencies = [ "turbo-tasks-hash", ] +[[package]] +name = "turbo-tasks-testing" +version = "0.1.0" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" +dependencies = [ + "anyhow", + "auto-hash-map", + "lazy_static", + "tokio", + "turbo-tasks", +] + [[package]] name = "turbopack" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "async-recursion", @@ -5650,10 +6877,10 @@ dependencies = [ [[package]] name = "turbopack-cli-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", - "clap", + "clap 4.1.8", "crossterm", "owo-colors", "serde", @@ -5666,7 +6893,7 @@ dependencies = [ [[package]] name = "turbopack-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "async-trait", @@ -5690,10 +6917,23 @@ dependencies = [ "turbo-tasks-hash", ] +[[package]] +name = "turbopack-create-test-app" +version = "0.1.0" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" +dependencies = [ + "anyhow", + "clap 4.1.8", + "indoc", + "pathdiff", + "serde_json", + "tempfile", +] + [[package]] name = "turbopack-css" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "async-trait", @@ -5715,7 +6955,7 @@ dependencies = [ [[package]] name = "turbopack-dev-server" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "async-compression", @@ -5747,7 +6987,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "async-trait", @@ -5785,7 +7025,7 @@ dependencies = [ [[package]] name = "turbopack-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "serde", @@ -5800,7 +7040,7 @@ dependencies = [ [[package]] name = "turbopack-json" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "serde", @@ -5815,7 +7055,7 @@ dependencies = [ [[package]] name = "turbopack-mdx" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "mdxjs", @@ -5830,7 +7070,7 @@ dependencies = [ [[package]] name = "turbopack-node" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "futures", @@ -5856,7 +7096,7 @@ dependencies = [ [[package]] name = "turbopack-static" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "anyhow", "serde", @@ -5872,7 +7112,7 @@ dependencies = [ [[package]] name = "turbopack-swc-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230310.2#bfa13087b3c3db94e1cc028e4a6ce65f3bde820f" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" dependencies = [ "swc_core", "turbo-tasks", @@ -5880,6 +7120,21 @@ dependencies = [ "turbopack-core", ] +[[package]] +name = "turbopack-test-utils" +version = "0.1.0" +source = "git+https://github.com/vercel/turbo.git?rev=8a8038f94#8a8038f94253de9cba026520b68f52964d2d2400" +dependencies = [ + "anyhow", + "once_cell", + "similar", + "turbo-tasks", + "turbo-tasks-build", + "turbo-tasks-fs", + "turbo-tasks-hash", + "turbopack-core", +] + [[package]] name = "twox-hash" version = "1.6.3" @@ -5976,6 +7231,24 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad2024452afd3874bf539695e04af6732ba06517424dbf958fdb16a01f3bef6c" + [[package]] name = "untrusted" version = "0.7.1" @@ -6022,6 +7295,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.0.0-alpha.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -6049,6 +7332,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "walkdir" version = "2.3.2" @@ -6122,9 +7411,9 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", "wasm-bindgen-shared", ] @@ -6146,7 +7435,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ - "quote", + "quote 1.0.23", "wasm-bindgen-macro-support", ] @@ -6156,9 +7445,9 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6276,9 +7565,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00e50405cc2a2f74ff574584710a5f2c1d5c93744acce2ca0866084739284b51" dependencies = [ "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.107", ] [[package]] diff --git a/packages/next-swc/Cargo.toml b/packages/next-swc/Cargo.toml index 5bb553894f5c..eb7f8f452be4 100644 --- a/packages/next-swc/Cargo.toml +++ b/packages/next-swc/Cargo.toml @@ -1,6 +1,17 @@ [workspace] -members = ["crates/core", "crates/napi", "crates/wasm"] +members = [ + "crates/core", + "crates/napi", + "crates/wasm", + "crates/next-binding", + "crates/next-core", + "crates/next-dev", + "crates/next-dev-tests", + # "crates/next-font", + # "crates/next-transform-dynamic", + # "crates/next-transform-strip-page-exports", +] [profile.dev.package.swc_css_prefixer] opt-level = 2 @@ -11,3 +22,131 @@ debug-assertions = false [profile.release] lto = true + +[workspace.dependencies] +# Workspace crates +next-binding = { path = "crates/next-binding" } +next-core = { path = "crates/next-core" } +next-dev = { path = "crates/next-dev" } +next-dev-tests = { path = "crates/next-dev-tests" } +# next-font = { path = "crates/next-font" } +# next-transform-dynamic = { path = "crates/next-transform-dynamic" } +# next-transform-strip-page-exports = { path = "crates/next-transform-strip-page-exports" } + +# SWC crates +# Keep consistent with preset_env_base through swc_core +browserslist-rs = { version = "0.12.2" } +mdxjs = { version = "0.1.6" } +modularize_imports = { version = "0.26.4" } +styled_components = { version = "0.53.4" } +styled_jsx = { version = "0.30.4" } +swc_core = { version = "0.59.26" } +swc_emotion = { version = "0.29.4" } +testing = { version = "0.31.31" } + +# Turbo crates +auto-hash-map = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +node-file-trace = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +swc-ast-explorer = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-malloc = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94", default-features = false } +turbo-tasks = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-build = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-env = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-fetch = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-hash = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-macros = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-macros-shared = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-memory = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-tasks-testing = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbo-updater = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-cli-utils = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-core = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-create-test-app = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-css = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-dev-server = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-ecmascript = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-env = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-json = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-mdx = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-node = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-static = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-swc-utils = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-test-utils = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } +turbopack-tests = { git = "https://github.com/vercel/turbo.git", rev = "8a8038f94" } + +# General Deps + +# Be careful when selecting tls backend, including change default tls backend. +# If you changed, must verify with ALL build targets with next-swc to ensure +# it works. next-swc have various platforms, some doesn't support native (using openssl-sys) +# and some aren't buildable with rustls. +reqwest = { version = "0.11.14", default-features = false } + +chromiumoxide = { version = "0.4.0", features = [ + "tokio-runtime", +], default-features = false } +# For matching on errors from chromiumoxide. Keep in +# sync with chromiumoxide's tungstenite requirement. +tungstenite = "0.17.3" + +anyhow = "1.0.69" +assert_cmd = "2.0.8" +async-compression = { version = "0.3.13", default-features = false, features = [ + "gzip", + "tokio", +] } +async-trait = "0.1.64" +atty = "0.2.14" +chrono = "0.4.23" +clap = "4.1.6" +clap_complete = "4.1.2" +concurrent-queue = "2.1.0" +console = "0.15.5" +console-subscriber = "0.1.8" +criterion = "0.4.0" +dashmap = "5.4.0" +dialoguer = "0.10.3" +dunce = "1.0.3" +futures = "0.3.26" +futures-retry = "0.6.0" +httpmock = "0.6.7" +indexmap = "1.9.2" +indicatif = "0.17.3" +indoc = "2.0.0" +itertools = "0.10.5" +lazy_static = "1.4.0" +log = "0.4.17" +mime = "0.3.16" +nohash-hasher = "0.2.0" +once_cell = "1.17.1" +owo-colors = "3.5.0" +parking_lot = "0.12.1" +pathdiff = "0.2.1" +pin-project-lite = "0.2.9" +predicates = "2.1.5" +pretty_assertions = "1.3.0" +proc-macro2 = "1.0.51" +qstring = "0.7.2" +quote = "1.0.23" +rand = "0.8.5" +regex = "1.7.0" +rstest = "0.16.0" +rustc-hash = "1.1.0" +semver = "1.0.16" +serde = { version = "1.0.152", features = ["derive"] } +serde_json = "1.0.93" +serde_qs = "0.11.0" +serde_yaml = "0.9.17" +syn = "1.0.107" +tempfile = "3.3.0" +test-generator = "0.3.1" +thiserror = "1.0.38" +tiny-gradient = "0.1.0" +tokio = "1.25.0" +tokio-util = { version = "0.7.7", features = ["io"] } +tracing = "0.1.37" +url = "2.2.2" +urlencoding = "2.1.2" +webbrowser = "0.8.7" diff --git a/packages/next-swc/crates/core/Cargo.toml b/packages/next-swc/crates/core/Cargo.toml index f509177fc451..357a2f82d64c 100644 --- a/packages/next-swc/crates/core/Cargo.toml +++ b/packages/next-swc/crates/core/Cargo.toml @@ -21,7 +21,7 @@ serde_json = "1" sha1 = "0.10.1" tracing = { version = "0.1.37", features = ["release_max_level_info"] } -next-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2", features = [ +next-binding = { path = "../next-binding", features = [ "__swc_core", "__swc_core_next_core", "__swc_transform_styled_jsx", @@ -31,7 +31,7 @@ next-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-2 ] } [dev-dependencies] -next-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2", features = [ +next-binding = { path = "../next-binding", features = [ "__swc_core_testing_transform", "__swc_testing", ] } diff --git a/packages/next-swc/crates/napi/Cargo.toml b/packages/next-swc/crates/napi/Cargo.toml index ef0e24e1bd0a..f33b12989aba 100644 --- a/packages/next-swc/crates/napi/Cargo.toml +++ b/packages/next-swc/crates/napi/Cargo.toml @@ -39,10 +39,10 @@ tracing = { version = "0.1.37", features = ["release_max_level_info"] } tracing-futures = "0.2.5" tracing-subscriber = "0.3.9" tracing-chrome = "0.5.0" -turbopack = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2" } -turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2" } -turbo-tasks-memory = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2" } -next-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2", features = [ +turbopack = { workspace = true } +turbo-tasks = { workspace = true } +turbo-tasks-memory = { workspace = true } +next-binding = { path = "../next-binding", features = [ "__swc_core_binding_napi", "__turbo_next_dev_server", "__turbo_node_file_trace", @@ -51,7 +51,7 @@ next-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-2 [target.'cfg(not(all(target_os = "linux", target_env = "musl", target_arch = "aarch64")))'.dependencies] -turbo-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230310.2" } +turbo-malloc = { workspace = true } # There are few build targets we can't use native-tls which default features rely on, # allow to specify alternative (rustls) instead via features. diff --git a/packages/next-swc/crates/next-binding/Cargo.toml b/packages/next-swc/crates/next-binding/Cargo.toml new file mode 100644 index 000000000000..2242f10c4e7a --- /dev/null +++ b/packages/next-swc/crates/next-binding/Cargo.toml @@ -0,0 +1,114 @@ +[package] +name = "next-binding" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" +autobenches = false + +[lib] +bench = false + +[features] +__swc = [] +__swc_core = ["__swc"] +__swc_core_next_core = [ + "__swc_core", + "swc_core/common_concurrent", + "swc_core/ecma_ast", + "swc_core/ecma_visit", + "swc_core/ecma_loader_node", + "swc_core/ecma_loader_lru", + "swc_core/ecma_utils", + "swc_core/ecma_minifier", + "swc_core/ecma_transforms", + "swc_core/ecma_transforms_react", + "swc_core/ecma_transforms_typescript", + "swc_core/ecma_transforms_optimization", + "swc_core/ecma_parser", + "swc_core/ecma_parser_typescript", + "swc_core/cached", + "swc_core/base", +] + +__swc_core_binding_napi = [ + "__swc_core", + "swc_core/base_concurrent", + "swc_core/base_node", + "swc_core/common_concurrent", + "swc_core/ecma_ast", + "swc_core/ecma_loader_node", + "swc_core/ecma_loader_lru", + "swc_core/bundler", + "swc_core/bundler_concurrent", + "swc_core/ecma_codegen", + "swc_core/ecma_minifier", + "swc_core/ecma_parser", + "swc_core/ecma_parser_typescript", + "swc_core/ecma_transforms", + "swc_core/ecma_transforms_optimization", + "swc_core/ecma_transforms_react", + "swc_core/ecma_transforms_typescript", + "swc_core/ecma_utils", + "swc_core/ecma_visit", +] +__swc_core_binding_napi_plugin = ["swc_core/plugin_transform_host_native"] +__swc_core_binding_napi_allocator = ["swc_core/allocator_node"] + +__swc_core_binding_wasm = [ + "__swc_core", + "swc_core/common_concurrent", + "swc_core/binding_macro_wasm", + "swc_core/ecma_codegen", + "swc_core/ecma_minifier", + "swc_core/ecma_transforms", + "swc_core/ecma_transforms_typescript", + "swc_core/ecma_transforms_optimization", + "swc_core/ecma_transforms_react", + "swc_core/ecma_parser", + "swc_core/ecma_parser_typescript", + "swc_core/ecma_utils", + "swc_core/ecma_visit", +] +__swc_core_binding_wasm_plugin = ["swc_core/plugin_transform_host_js"] + +__swc_core_testing_transform = ["swc_core/testing_transform"] + +__turbo = [] +__turbo_next_dev_server = ["__turbo", "next-dev/serializable"] +__turbo_node_file_trace = ["__turbo", "node-file-trace/node-api"] + +# set tls for downstream dependenices of turbo +__turbo_native_tls = ["next-dev/native-tls"] +__turbo_rustls_tls = ["next-dev/rustls-tls"] + +__features = [] +__feature_mdx_rs = ["__features", "mdxjs/serializable"] + +__swc_custom_transform = [] +__swc_transform_styled_components = [ + "__swc", + "__swc_custom_transform", + "styled_components", +] +__swc_transform_styled_jsx = ["__swc", "__swc_custom_transform", "styled_jsx"] +__swc_transform_emotion = ["__swc", "__swc_custom_transform", "swc_emotion"] +__swc_transform_modularize_imports = [ + "__swc", + "__swc_custom_transform", + "modularize_imports", +] +__swc_testing = ["__swc", "testing"] + +[dependencies] +mdxjs = { optional = true, workspace = true } +modularize_imports = { optional = true, workspace = true } +# TODO: Not sure what's going on, but using `workspace = true` noops `default-features = false`? +next-dev = { optional = true, path = "../next-dev", default-features = false, features = [ + "custom_allocator", +] } +node-file-trace = { optional = true, workspace = true } +styled_components = { optional = true, workspace = true } +styled_jsx = { optional = true, workspace = true } +swc_core = { optional = true, workspace = true } +swc_emotion = { optional = true, workspace = true } +testing = { optional = true, workspace = true } diff --git a/packages/next-swc/crates/next-binding/README.md b/packages/next-swc/crates/next-binding/README.md new file mode 100644 index 000000000000..2eb6cb028ac6 --- /dev/null +++ b/packages/next-swc/crates/next-binding/README.md @@ -0,0 +1,3 @@ +### next-binding + +This is an internal package, does not provide any public interface or stability guarantees. Do not use it directly. diff --git a/packages/next-swc/crates/next-binding/src/lib.rs b/packages/next-swc/crates/next-binding/src/lib.rs new file mode 100644 index 000000000000..03b0741db72a --- /dev/null +++ b/packages/next-swc/crates/next-binding/src/lib.rs @@ -0,0 +1,34 @@ +#[cfg(feature = "__swc")] +pub mod swc { + #[cfg(feature = "__swc_core")] + pub use swc_core as core; + + #[cfg(feature = "__swc_custom_transform")] + pub mod custom_transform { + #[cfg(feature = "__swc_transform_modularize_imports")] + pub use modularize_imports; + #[cfg(feature = "__swc_transform_styled_components")] + pub use styled_components; + #[cfg(feature = "__swc_transform_styled_jsx")] + pub use styled_jsx; + #[cfg(feature = "__swc_transform_emotion")] + pub use swc_emotion as emotion; + } + + #[cfg(feature = "testing")] + pub use testing; +} + +#[cfg(feature = "__turbo")] +pub mod turbo { + #[cfg(feature = "__turbo_next_dev_server")] + pub use next_dev; + #[cfg(feature = "__turbo_node_file_trace")] + pub use node_file_trace; +} + +#[cfg(feature = "__features")] +pub mod features { + #[cfg(feature = "__feature_mdx_rs")] + pub use mdxjs; +} diff --git a/packages/next-swc/crates/next-core/Cargo.toml b/packages/next-swc/crates/next-core/Cargo.toml new file mode 100644 index 000000000000..1414e17cc956 --- /dev/null +++ b/packages/next-swc/crates/next-core/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "next-core" +version = "0.1.0" +description = "TBD" +license = "MPL-2.0" +edition = "2021" + +[lib] +bench = false + +[dependencies] +anyhow = { workspace = true } +auto-hash-map = { workspace = true } +indexmap = { workspace = true, features = ["serde"] } +indoc = { workspace = true } +mime = { workspace = true } +once_cell = { workspace = true } +qstring = { workspace = true } +regex = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +turbo-tasks = { workspace = true } +turbo-tasks-env = { workspace = true } +turbo-tasks-fetch = { workspace = true } +turbo-tasks-fs = { workspace = true } +turbo-tasks-hash = { workspace = true } +turbopack = { workspace = true } +turbopack-core = { workspace = true } +turbopack-dev-server = { workspace = true } +turbopack-ecmascript = { workspace = true } +turbopack-env = { workspace = true } +turbopack-node = { workspace = true } + +swc_core = { workspace = true, features = ["ecma_ast", "common"] } + +[build-dependencies] +turbo-tasks-build = { workspace = true } + +[features] +next-font-local = [] +native-tls = ["turbo-tasks-fetch/native-tls"] +rustls-tls = ["turbo-tasks-fetch/rustls-tls"] +# Internal only. Enabled when building for the Next.js integration test suite. +__internal_nextjs_integration_test = [] diff --git a/packages/next-swc/crates/next-core/build.rs b/packages/next-swc/crates/next-core/build.rs new file mode 100644 index 000000000000..1673efed59cc --- /dev/null +++ b/packages/next-swc/crates/next-core/build.rs @@ -0,0 +1,5 @@ +use turbo_tasks_build::generate_register; + +fn main() { + generate_register(); +} diff --git a/packages/next-swc/crates/next-core/js/build.mjs b/packages/next-swc/crates/next-core/js/build.mjs new file mode 100644 index 000000000000..283d6a719a7e --- /dev/null +++ b/packages/next-swc/crates/next-core/js/build.mjs @@ -0,0 +1,162 @@ +/** + * Build npm package to be able to embed them in the binary + */ + +import { mkdir, writeFile, rm, readFile } from "node:fs/promises"; +import { existsSync } from "node:fs"; +import { createRequire } from "node:module"; +import { join, dirname, basename, extname } from "node:path"; +import { fileURLToPath } from "node:url"; + +import ncc from "@vercel/ncc"; +import { findUp } from "find-up"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const require = createRequire(import.meta.url); + +/** + * @type {{ + * name: string; + * type: "cjs" | "module" | "module-default"; + * types?: string; + * }[]} + */ +const packages = [ + { + name: "anser", + type: "cjs", + }, + { + name: "css.escape", + type: "cjs", + types: "export = CSS.escape;", + }, + { + name: "platform", + type: "cjs", + }, + { + name: "source-map", + type: "module", + }, + { + name: "stacktrace-parser", + type: "module", + }, + { + name: "strip-ansi", + type: "module-default", + }, +]; +const externals = Object.fromEntries( + packages.map((pkg) => [ + pkg.name, + `@vercel/turbopack-next/compiled/${pkg.name}`, + ]) +); + +// adapted from https://github.com/vercel/next.js/blob/8fb5ef18e7958a19874e11b8037ac0f71c48baef/packages/next/taskfile-ncc.js +async function writePackageManifest(packageName, main) { + // some newer packages fail to include package.json in the exports + // so we can't reliably use require.resolve here + let packagePath; + + try { + packagePath = require.resolve(packageName + "/package.json"); + } catch (_) { + packagePath = await findUp("package.json", { + cwd: dirname(require.resolve(packageName)), + }); + } + const { name, author, license } = require(packagePath); + + const compiledPackagePath = join(__dirname, `src/compiled/${packageName}`); + + const potentialLicensePath = join(dirname(packagePath), "./LICENSE"); + if (existsSync(potentialLicensePath)) { + await writeFile( + join(compiledPackagePath, "LICENSE"), + await readFile(potentialLicensePath, "utf8") + ); + } else { + // license might be lower case and not able to be found on case-sensitive + // file systems (ubuntu) + const otherPotentialLicensePath = join(dirname(packagePath), "./license"); + if (existsSync(otherPotentialLicensePath)) { + await writeFile( + join(compiledPackagePath, "LICENSE"), + await readFile(otherPotentialLicensePath, "utf8") + ); + } + } + + await writeFile( + join(compiledPackagePath, "package.json"), + JSON.stringify( + Object.assign( + {}, + { name, main: `${basename(main, "." + extname(main))}` }, + author ? { author } : undefined, + license ? { license } : undefined + ) + ) + "\n" + ); +} + +async function main() { + const baseDir = join(__dirname, "src/compiled"); + + await rm(baseDir, { + force: true, + recursive: true, + }); + + let types = "/* GENERATED FILE, DO NOT EDIT */\n"; + + for (const pkg of packages) { + const input = require.resolve(pkg.name); + + const outputDir = join(baseDir, pkg.name); + await mkdir(outputDir, { recursive: true }); + + const { code, assets } = await ncc(input, { + minify: true, + assetBuilds: true, + quiet: true, + externals, + }); + + await writeFile(join(outputDir, "index.js"), code); + + for (const key in assets) { + await writeFile(join(outputDir, key), assets[key].source); + } + + await writePackageManifest(pkg.name, "index.js"); + + types += `\ndeclare module "@vercel/turbopack-next/compiled/${pkg.name}" {\n`; + if (pkg.types) { + types += ` ${pkg.types}\n`; + } else if (pkg.type === "module-default") { + types += ` import m from "${pkg.name}";\n`; + types += ` export default m;\n`; + } else if (pkg.type === "module") { + types += ` export * from "${pkg.name}";\n`; + } else if (pkg.type === "cjs") { + types += ` import m from "${pkg.name}";\n`; + types += ` export = m;\n`; + } else { + throw new Error(`unknown package type ${pkg.type} for ${pkg.name}`); + } + types += `}\n`; + + console.log(`built ${pkg.name}`); + } + + await writeFile(join(__dirname, "types", "compiled.d.ts"), types); +} + +main().catch((e) => { + console.dir(e); + process.exit(1); +}); diff --git a/packages/next-swc/crates/next-core/js/package.json b/packages/next-swc/crates/next-core/js/package.json new file mode 100644 index 000000000000..e0545cfa8019 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/package.json @@ -0,0 +1,31 @@ +{ + "name": "@vercel/turbopack-next", + "version": "0.0.0", + "description": "turbopack next runtime", + "license": "UNLICENSED", + "private": true, + "scripts": { + "check": "tsc --noEmit", + "build:compiled": "node build.mjs" + }, + "dependencies": { + "@vercel/turbopack-runtime": "https://gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94", + "anser": "^2.1.1", + "css.escape": "^1.5.1", + "next": "*", + "platform": "1.3.6", + "react-dom": "^18.2.0", + "react": "^18.2.0", + "source-map": "0.8.0-beta.0", + "stacktrace-parser": "^0.1.10", + "strip-ansi": "^7.0.1" + }, + "devDependencies": { + "@types/node": "^18.11.11", + "@types/platform": "^1.3.4", + "@types/react": "^18.0.26", + "@types/react-dom": "^18.0.9", + "@vercel/ncc": "^0.36.0", + "find-up": "^6.3.0" + } +} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/anser/LICENSE b/packages/next-swc/crates/next-core/js/src/compiled/anser/LICENSE new file mode 100644 index 000000000000..2c95ac413a12 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/anser/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2012-22 Ionică Bizău (https://ionicabizau.net) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/next-swc/crates/next-core/js/src/compiled/anser/index.js b/packages/next-swc/crates/next-core/js/src/compiled/anser/index.js new file mode 100644 index 000000000000..611c4e404003 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/anser/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={793:e=>{var r=function(){function defineProperties(e,r){for(var s=0;s\"]/gm,(function(e){return e=="&"?"&":e=='"'?""":e=="<"?"<":e==">"?">":""}))}},{key:"linkify",value:function linkify(e){return e.replace(/(https?:\/\/[^\s]+)/gm,(function(e){return''+e+""}))}},{key:"ansiToHtml",value:function ansiToHtml(e,r){return this.process(e,r,true)}},{key:"ansiToJson",value:function ansiToJson(e,r){r=r||{};r.json=true;r.clearLine=false;return this.process(e,r,true)}},{key:"ansiToText",value:function ansiToText(e){return this.process(e,{},false)}},{key:"process",value:function process(e,r,s){var n=this;var o=this;var i=e.split(/\033\[/);var t=i.shift();if(r===undefined||r===null){r={}}r.clearLine=/\r/.test(e);var a=i.map((function(e){return n.processChunk(e,r,s)}));if(r&&r.json){var l=o.processChunkJson("");l.content=t;l.clearLine=r.clearLine;a.unshift(l);if(r.remove_empty){a=a.filter((function(e){return!e.isEmpty()}))}return a}else{a.unshift(t)}return a.join("")}},{key:"processChunkJson",value:function processChunkJson(e,r,n){r=typeof r=="undefined"?{}:r;var o=r.use_classes=typeof r.use_classes!="undefined"&&r.use_classes;var i=r.key=o?"class":"color";var t={content:e,fg:null,bg:null,fg_truecolor:null,bg_truecolor:null,isInverted:false,clearLine:r.clearLine,decoration:null,decorations:[],was_processed:false,isEmpty:function isEmpty(){return!t.content}};var a=e.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);if(!a)return t;var l=t.content=a[4];var c=a[2].split(";");if(a[1]!==""||a[3]!=="m"){return t}if(!n){return t}var u=this;while(c.length>0){var f=c.shift();var h=parseInt(f);if(isNaN(h)||h===0){u.fg=u.bg=null;u.decorations=[]}else if(h===1){u.decorations.push("bold")}else if(h===2){u.decorations.push("dim")}else if(h===3){u.decorations.push("italic")}else if(h===4){u.decorations.push("underline")}else if(h===5){u.decorations.push("blink")}else if(h===7){u.decorations.push("reverse")}else if(h===8){u.decorations.push("hidden")}else if(h===9){u.decorations.push("strikethrough")}else if(h===21){u.removeDecoration("bold")}else if(h===22){u.removeDecoration("bold");u.removeDecoration("dim")}else if(h===23){u.removeDecoration("italic")}else if(h===24){u.removeDecoration("underline")}else if(h===25){u.removeDecoration("blink")}else if(h===27){u.removeDecoration("reverse")}else if(h===28){u.removeDecoration("hidden")}else if(h===29){u.removeDecoration("strikethrough")}else if(h===39){u.fg=null}else if(h===49){u.bg=null}else if(h>=30&&h<38){u.fg=s[0][h%10][i]}else if(h>=90&&h<98){u.fg=s[1][h%10][i]}else if(h>=40&&h<48){u.bg=s[0][h%10][i]}else if(h>=100&&h<108){u.bg=s[1][h%10][i]}else if(h===38||h===48){var v=h===38;if(c.length>=1){var g=c.shift();if(g==="5"&&c.length>=1){var p=parseInt(c.shift());if(p>=0&&p<=255){if(!o){if(!this.PALETTE_COLORS){u.setupPalette()}if(v){u.fg=this.PALETTE_COLORS[p]}else{u.bg=this.PALETTE_COLORS[p]}}else{var d=p>=16?"ansi-palette-"+p:s[p>7?1:0][p%8]["class"];if(v){u.fg=d}else{u.bg=d}}}}else if(g==="2"&&c.length>=3){var b=parseInt(c.shift());var _=parseInt(c.shift());var m=parseInt(c.shift());if(b>=0&&b<=255&&_>=0&&_<=255&&m>=0&&m<=255){var k=b+", "+_+", "+m;if(!o){if(v){u.fg=k}else{u.bg=k}}else{if(v){u.fg="ansi-truecolor";u.fg_truecolor=k}else{u.bg="ansi-truecolor";u.bg_truecolor=k}}}}}}}if(u.fg===null&&u.bg===null&&u.decorations.length===0){return t}else{var y=[];var T=[];var w={};t.fg=u.fg;t.bg=u.bg;t.fg_truecolor=u.fg_truecolor;t.bg_truecolor=u.bg_truecolor;t.decorations=u.decorations;t.decoration=u.decorations.slice(-1).pop()||null;t.was_processed=true;return t}}},{key:"processChunk",value:function processChunk(e,r,n){var o=this;r=r||{};var i=this.processChunkJson(e,r,n);var t=r.use_classes;i.decorations=i.decorations.filter((function(e){if(e==="reverse"){if(!i.fg){i.fg=s[0][7][t?"class":"color"]}if(!i.bg){i.bg=s[0][0][t?"class":"color"]}var r=i.fg;i.fg=i.bg;i.bg=r;var n=i.fg_truecolor;i.fg_truecolor=i.bg_truecolor;i.bg_truecolor=n;i.isInverted=true;return false}return true}));if(r.json){return i}if(i.isEmpty()){return""}if(!i.was_processed){return i.content}var a=[];var l=[];var c=[];var u={};var f=function render_data(e){var r=[];var s=void 0;for(s in e){if(e.hasOwnProperty(s)){r.push("data-"+s+'="'+o.escapeForHtml(e[s])+'"')}}return r.length>0?" "+r.join(" "):""};if(i.isInverted){u["ansi-is-inverted"]="true"}if(i.fg){if(t){a.push(i.fg+"-fg");if(i.fg_truecolor!==null){u["ansi-truecolor-fg"]=i.fg_truecolor;i.fg_truecolor=null}}else{a.push("color:rgb("+i.fg+")")}}if(i.bg){if(t){a.push(i.bg+"-bg");if(i.bg_truecolor!==null){u["ansi-truecolor-bg"]=i.bg_truecolor;i.bg_truecolor=null}}else{a.push("background-color:rgb("+i.bg+")")}}i.decorations.forEach((function(e){if(t){l.push("ansi-"+e);return}if(e==="bold"){l.push("font-weight:bold")}else if(e==="dim"){l.push("opacity:0.5")}else if(e==="italic"){l.push("font-style:italic")}else if(e==="hidden"){l.push("visibility:hidden")}else if(e==="strikethrough"){c.push("line-through")}else{c.push(e)}}));if(c.length){l.push("text-decoration:"+c.join(" "))}if(t){return'"+i.content+""}else{return'"+i.content+""}}},{key:"removeDecoration",value:function removeDecoration(e){var r=this.decorations.indexOf(e);if(r>=0){this.decorations.splice(r,1)}}}]);return Anser}();e.exports=n}};var r={};function __nccwpck_require__(s){var n=r[s];if(n!==undefined){return n.exports}var o=r[s]={exports:{}};var i=true;try{e[s](o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete r[s]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s=__nccwpck_require__(793);module.exports=s})(); \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/anser/package.json b/packages/next-swc/crates/next-core/js/src/compiled/anser/package.json new file mode 100644 index 000000000000..17f339cfac86 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/anser/package.json @@ -0,0 +1 @@ +{"name":"anser","main":"index.js","author":"Ionică Bizău (https://ionicabizau.net)","license":"MIT"} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/css.escape/index.js b/packages/next-swc/crates/next-core/js/src/compiled/css.escape/index.js new file mode 100644 index 000000000000..eaedacfcb97e --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/css.escape/index.js @@ -0,0 +1 @@ +(()=>{var e={969:function(e){(function(r,t){if(true){e.exports=t(r)}else{}})(typeof global!="undefined"?global:this,(function(e){if(e.CSS&&e.CSS.escape){return e.CSS.escape}var cssEscape=function(e){if(arguments.length==0){throw new TypeError("`CSS.escape` requires an argument.")}var r=String(e);var t=r.length;var n=-1;var a;var i="";var u=r.charCodeAt(0);while(++n=1&&a<=31||a==127||n==0&&a>=48&&a<=57||n==1&&a>=48&&a<=57&&u==45){i+="\\"+a.toString(16)+" ";continue}if(n==0&&t==1&&a==45){i+="\\"+r.charAt(n);continue}if(a>=128||a==45||a==95||a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122){i+=r.charAt(n);continue}i+="\\"+r.charAt(n)}return i};if(!e.CSS){e.CSS={}}e.CSS.escape=cssEscape;return cssEscape}))}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var a=r[t]={exports:{}};var i=true;try{e[t].call(a.exports,a,a.exports,__nccwpck_require__);i=false}finally{if(i)delete r[t]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(969);module.exports=t})(); \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/css.escape/package.json b/packages/next-swc/crates/next-core/js/src/compiled/css.escape/package.json new file mode 100644 index 000000000000..5310d97e9207 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/css.escape/package.json @@ -0,0 +1 @@ +{"name":"css.escape","main":"index.js","author":{"name":"Mathias Bynens","url":"https://mathiasbynens.be/"},"license":"MIT"} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/platform/LICENSE b/packages/next-swc/crates/next-core/js/src/compiled/platform/LICENSE new file mode 100644 index 000000000000..598835fe059f --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/platform/LICENSE @@ -0,0 +1,21 @@ +Copyright 2014-2020 Benjamin Tan +Copyright 2011-2013 John-David Dalton + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/next-swc/crates/next-core/js/src/compiled/platform/index.js b/packages/next-swc/crates/next-core/js/src/compiled/platform/index.js new file mode 100644 index 000000000000..12fbfe4b24a3 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/platform/index.js @@ -0,0 +1,7 @@ +(()=>{var e={797:function(e,i,t){e=t.nmd(e); +/*! + * Platform.js v1.3.6 + * Copyright 2014-2020 Benjamin Tan + * Copyright 2011-2013 John-David Dalton + * Available under MIT license + */(function(){"use strict";var t={function:true,object:true};var r=t[typeof window]&&window||this;var a=r;var n=t[typeof i]&&i;var o=t["object"]&&e&&!e.nodeType&&e;var l=n&&o&&typeof global=="object"&&global;if(l&&(l.global===l||l.window===l||l.self===l)){r=l}var s=Math.pow(2,53)-1;var f=/\bOpera/;var b=this;var c=Object.prototype;var p=c.hasOwnProperty;var u=c.toString;function capitalize(e){e=String(e);return e.charAt(0).toUpperCase()+e.slice(1)}function cleanupOS(e,i,t){var r={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};if(i&&t&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])){e="Windows "+r}e=String(e);if(i&&t){e=e.replace(RegExp(i,"i"),t)}e=format(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0]);return e}function each(e,i){var t=-1,r=e?e.length:0;if(typeof r=="number"&&r>-1&&r<=s){while(++t3&&"WebKit"||/\bOpera\b/.test(R)&&(/\bOPR\b/.test(e)?"Blink":"Presto")||/\b(?:Midori|Nook|Safari)\b/i.test(e)&&!/^(?:Trident|EdgeHTML)$/.test(_)&&"WebKit"||!_&&/\bMSIE\b/i.test(e)&&(T=="Mac OS"?"Tasman":"Trident")||_=="WebKit"&&/\bPlayStation\b(?! Vita\b)/i.test(R)&&"NetFront"){_=[M]}if(R=="IE"&&(M=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(e)||0)[1])){R+=" Mobile";T="Windows Phone "+(/\+$/.test(M)?M:M+".x");P.unshift("desktop mode")}else if(/\bWPDesktop\b/i.test(e)){R="IE Mobile";T="Windows Phone 8.x";P.unshift("desktop mode");B||(B=(/\brv:([\d.]+)/.exec(e)||0)[1])}else if(R!="IE"&&_=="Trident"&&(M=/\brv:([\d.]+)/.exec(e))){if(R){P.push("identifying as "+R+(B?" "+B:""))}R="IE";B=M[1]}if(k){if(isHostType(i,"global")){if(m){M=m.lang.System;E=M.getProperty("os.arch");T=T||M.getProperty("os.name")+" "+M.getProperty("os.version")}if(g){try{B=i.require("ringo/engine").version.join(".");R="RingoJS"}catch(e){if((M=i.system)&&M.global.system==i.system){R="Narwhal";T||(T=M[0].os||null)}}if(!R){R="Rhino"}}else if(typeof i.process=="object"&&!i.process.browser&&(M=i.process)){if(typeof M.versions=="object"){if(typeof M.versions.electron=="string"){P.push("Node "+M.versions.node);R="Electron";B=M.versions.electron}else if(typeof M.versions.nw=="string"){P.push("Chromium "+B,"Node "+M.versions.node);R="NW.js";B=M.versions.nw}}if(!R){R="Node.js";E=M.arch;T=M.platform;B=/[\d.]+/.exec(M.version);B=B?B[0]:null}}}else if(getClassOf(M=i.runtime)==p){R="Adobe AIR";T=M.flash.system.Capabilities.os}else if(getClassOf(M=i.phantom)==x){R="PhantomJS";B=(M=M.version||null)&&M.major+"."+M.minor+"."+M.patch}else if(typeof O.documentMode=="number"&&(M=/\bTrident\/(\d+)/i.exec(e))){B=[B,O.documentMode];if((M=+M[1]+4)!=B[1]){P.push("IE "+B[1]+" mode");_&&(_[1]="");B[1]=M}B=R=="IE"?String(B[1].toFixed(1)):B[0]}else if(typeof O.documentMode=="number"&&/^(?:Chrome|Firefox)\b/.test(R)){P.push("masking as "+R+" "+B);R="IE";B="11.0";_=["Trident"];T="Windows"}T=T&&format(T)}if(B&&(M=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(B)||/(?:alpha|beta)(?: ?\d)?/i.exec(e+";"+(k&&n.appMinorVersion))||/\bMinefield\b/i.test(e)&&"a")){C=/b/i.test(M)?"beta":"alpha";B=B.replace(RegExp(M+"\\+?$"),"")+(C=="beta"?v:h)+(/\d+\+?/.exec(M)||"")}if(R=="Fennec"||R=="Firefox"&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(T)){R="Firefox Mobile"}else if(R=="Maxthon"&&B){B=B.replace(/\.[\d.]+/,".x")}else if(/\bXbox\b/i.test(A)){if(A=="Xbox 360"){T=null}if(A=="Xbox 360"&&/\bIEMobile\b/.test(e)){P.unshift("mobile mode")}}else if((/^(?:Chrome|IE|Opera)$/.test(R)||R&&!A&&!/Browser|Mobi/.test(R))&&(T=="Windows CE"||/Mobi/i.test(e))){R+=" Mobile"}else if(R=="IE"&&k){try{if(i.external===null){P.unshift("platform preview")}}catch(e){P.unshift("embedded")}}else if((/\bBlackBerry\b/.test(A)||/\bBB10\b/.test(e))&&(M=(RegExp(A.replace(/ +/g," *")+"/([.\\d]+)","i").exec(e)||0)[1]||B)){M=[M,/BB10/.test(e)];T=(M[1]?(A=null,I="BlackBerry"):"Device Software")+" "+M[0];B=null}else if(this!=forOwn&&A!="Wii"&&(k&&y||/Opera/.test(R)&&/\b(?:MSIE|Firefox)\b/i.test(e)||R=="Firefox"&&/\bOS X (?:\d+\.){2,}/.test(T)||R=="IE"&&(T&&!/^Win/.test(T)&&B>5.5||/\bWindows XP\b/.test(T)&&B>8||B==8&&!/\bTrident\b/.test(e)))&&!f.test(M=parse.call(forOwn,e.replace(f,"")+";"))&&M.name){M="ing as "+M.name+((M=M.version)?" "+M:"");if(f.test(R)){if(/\bIE\b/.test(M)&&T=="Mac OS"){T=null}M="identify"+M}else{M="mask"+M;if(w){R=format(w.replace(/([a-z])([A-Z])/g,"$1 $2"))}else{R="Opera"}if(/\bIE\b/.test(M)){T=null}if(!k){B=null}}_=["Presto"];P.push(M)}if(M=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(e)||0)[1]){M=[parseFloat(M.replace(/\.(\d)$/,".0$1")),M];if(R=="Safari"&&M[1].slice(-1)=="+"){R="WebKit Nightly";C="alpha";B=M[1].slice(0,-1)}else if(B==M[1]||B==(M[2]=(/\bSafari\/([\d.]+\+?)/i.exec(e)||0)[1])){B=null}M[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(e)||0)[1];if(M[0]==537.36&&M[2]==537.36&&parseFloat(M[1])>=28&&_=="WebKit"){_=["Blink"]}if(!k||!s&&!M[1]){_&&(_[1]="like Safari");M=(M=M[0],M<400?1:M<500?2:M<526?3:M<533?4:M<534?"4+":M<535?5:M<537?6:M<538?7:M<601?8:M<602?9:M<604?10:M<606?11:M<608?12:"12")}else{_&&(_[1]="like Chrome");M=M[1]||(M=M[0],M<530?1:M<532?2:M<532.05?3:M<533?4:M<534.03?5:M<534.07?6:M<534.1?7:M<534.13?8:M<534.16?9:M<534.24?10:M<534.3?11:M<535.01?12:M<535.02?"13+":M<535.07?15:M<535.11?16:M<535.19?17:M<536.05?18:M<536.1?19:M<537.01?20:M<537.11?"21+":M<537.13?23:M<537.18?24:M<537.24?25:M<537.36?26:_!="Blink"?"27":"28")}_&&(_[1]+=" "+(M+=typeof M=="number"?".x":/[.+]/.test(M)?"":"+"));if(R=="Safari"&&(!B||parseInt(B)>45)){B=M}else if(R=="Chrome"&&/\bHeadlessChrome/i.test(e)){P.unshift("headless")}}if(R=="Opera"&&(M=/\bzbov|zvav$/.exec(T))){R+=" ";P.unshift("desktop mode");if(M=="zvav"){R+="Mini";B=null}else{R+="Mobile"}T=T.replace(RegExp(" *"+M+"$"),"")}else if(R=="Safari"&&/\bChrome\b/.exec(_&&_[1])){P.unshift("desktop mode");R="Chrome Mobile";B=null;if(/\bOS X\b/.test(T)){I="Apple";T="iOS 4.3+"}else{T=null}}else if(/\bSRWare Iron\b/.test(R)&&!B){B=getVersion("Chrome")}if(B&&B.indexOf(M=/[\d.]+$/.exec(T))==0&&e.indexOf("/"+M+"-")>-1){T=trim(T.replace(M,""))}if(T&&T.indexOf(R)!=-1&&!RegExp(R+" OS").test(T)){T=T.replace(RegExp(" *"+qualify(R)+" *"),"")}if(_&&!/\b(?:Avant|Nook)\b/.test(R)&&(/Browser|Lunascape|Maxthon/.test(R)||R!="Safari"&&/^iOS/.test(T)&&/\bSafari\b/.test(_[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(R)&&_[1])){(M=_[_.length-1])&&P.push(M)}if(P.length){P=["("+P.join("; ")+")"]}if(I&&A&&A.indexOf(I)<0){P.push("on "+I)}if(A){P.push((/^on /.test(P[P.length-1])?"":"on ")+A)}if(T){M=/ ([\d.+]+)$/.exec(T);W=M&&T.charAt(T.length-M[0].length-1)=="/";T={architecture:32,family:M&&!W?T.replace(M[0],""):T,version:M?M[1]:null,toString:function(){var e=this.version;return this.family+(e&&!W?" "+e:"")+(this.architecture==64?" 64-bit":"")}}}if((M=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(E))&&!/\bi686\b/i.test(E)){if(T){T.architecture=64;T.family=T.family.replace(RegExp(" *"+M),"")}if(R&&(/\bWOW64\b/i.test(e)||k&&/\w(?:86|32)$/.test(n.cpuClass||n.platform)&&!/\bWin64; x64\b/i.test(e))){P.unshift("32-bit")}}else if(T&&/^OS X/.test(T.family)&&R=="Chrome"&&parseFloat(B)>=39){T.architecture=64}e||(e=null);var F={};F.description=e;F.layout=_&&_[0];F.manufacturer=I;F.name=R;F.prerelease=C;F.product=A;F.ua=e;F.version=R&&B;F.os=T||{architecture:null,family:null,version:null,toString:function(){return"null"}};F.parse=parse;F.toString=toStringPlatform;if(F.version){P.unshift(B)}if(F.name){P.unshift(R)}if(T&&R&&!(T==String(T).split(" ")[0]&&(T==R.split(" ")[0]||A))){P.push(A?"("+T+")":"on "+T)}if(P.length){F.description=P.join(" ")}return F}var d=parse();if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){r.platform=d;define((function(){return d}))}else if(n&&o){forOwn(d,(function(e,i){n[i]=e}))}else{r.platform=d}}).call(this)}};var i={};function __nccwpck_require__(t){var r=i[t];if(r!==undefined){return r.exports}var a=i[t]={id:t,loaded:false,exports:{}};var n=true;try{e[t].call(a.exports,a,a.exports,__nccwpck_require__);n=false}finally{if(n)delete i[t]}a.loaded=true;return a.exports}(()=>{__nccwpck_require__.nmd=e=>{e.paths=[];if(!e.children)e.children=[];return e}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(797);module.exports=t})(); \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/platform/package.json b/packages/next-swc/crates/next-core/js/src/compiled/platform/package.json new file mode 100644 index 000000000000..27793b3c74c7 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/platform/package.json @@ -0,0 +1 @@ +{"name":"platform","main":"index.js","author":"Benjamin Tan ","license":"MIT"} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/source-map/LICENSE b/packages/next-swc/crates/next-core/js/src/compiled/source-map/LICENSE new file mode 100644 index 000000000000..ed1b7cf27e97 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/source-map/LICENSE @@ -0,0 +1,28 @@ + +Copyright (c) 2009-2011, Mozilla Foundation and contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the names of the Mozilla Foundation nor the names of project + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/next-swc/crates/next-core/js/src/compiled/source-map/index.js b/packages/next-swc/crates/next-core/js/src/compiled/source-map/index.js new file mode 100644 index 000000000000..95ad6c4b0aaf --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/source-map/index.js @@ -0,0 +1 @@ +(()=>{var e={313:(e,n)=>{class ArraySet{constructor(){this._array=[];this._set=new Map}static fromArray(e,n){const t=new ArraySet;for(let r=0,o=e.length;r=0){return n}throw new Error('"'+e+'" is not in the set.')}at(e){if(e>=0&&e{const r=t(612);const o=5;const s=1<>1;return n?-t:t}n.encode=function base64VLQ_encode(e){let n="";let t;let s=toVLQSigned(e);do{t=s&i;s>>>=o;if(s>0){t|=l}n+=r.encode(t)}while(s>0);return n}},612:(e,n)=>{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");n.encode=function(e){if(0<=e&&e{n.GREATEST_LOWER_BOUND=1;n.LEAST_UPPER_BOUND=2;function recursiveSearch(e,t,r,o,s,i){const l=Math.floor((t-e)/2)+e;const a=s(r,o[l],true);if(a===0){return l}else if(a>0){if(t-l>1){return recursiveSearch(l,t,r,o,s,i)}if(i==n.LEAST_UPPER_BOUND){return t1){return recursiveSearch(e,l,r,o,s,i)}if(i==n.LEAST_UPPER_BOUND){return l}return e<0?-1:e}n.search=function search(e,t,r,o){if(t.length===0){return-1}let s=recursiveSearch(-1,t.length,e,t,r,o||n.GREATEST_LOWER_BOUND);if(s<0){return-1}while(s-1>=0){if(r(t[s],t[s-1],true)!==0){break}--s}return s}},627:(e,n,t)=>{const r=t(67);function generatedPositionAfter(e,n){const t=e.generatedLine;const o=n.generatedLine;const s=e.generatedColumn;const i=n.generatedColumn;return o>t||o==t&&i>=s||r.compareByGeneratedPositionsInflated(e,n)<=0}class MappingList{constructor(){this._array=[];this._sorted=true;this._last={generatedLine:-1,generatedColumn:0}}unsortedForEach(e,n){this._array.forEach(e,n)}add(e){if(generatedPositionAfter(this._last,e)){this._last=e;this._array.push(e)}else{this._sorted=false;this._array.push(e)}}toArray(){if(!this._sorted){this._array.sort(r.compareByGeneratedPositionsInflated);this._sorted=true}return this._array}}n.H=MappingList},153:(e,n,t)=>{"use strict";const r=t(147);const o=t(17);e.exports=function readWasm(){return new Promise(((e,n)=>{const o=t.ab+"mappings.wasm";r.readFile(t.ab+"mappings.wasm",null,((t,r)=>{if(t){n(t);return}e(r.buffer)}))}))};e.exports.initialize=e=>{console.debug("SourceMapConsumer.initialize is a no-op when running in node.js")}},316:(e,n,t)=>{var r;const o=t(67);const s=t(217);const i=t(313).I;const l=t(296);const a=t(153);const u=t(482);const c=Symbol("smcInternal");class SourceMapConsumer{constructor(e,n){if(e==c){return Promise.resolve(this)}return _factory(e,n)}static initialize(e){a.initialize(e["lib/mappings.wasm"])}static fromSourceMap(e,n){return _factoryBSM(e,n)}static async with(e,n,t){const r=await new SourceMapConsumer(e,n);try{return await t(r)}finally{r.destroy()}}eachMapping(e,n,t){throw new Error("Subclasses must implement eachMapping")}allGeneratedPositionsFor(e){throw new Error("Subclasses must implement allGeneratedPositionsFor")}destroy(){throw new Error("Subclasses must implement destroy")}}SourceMapConsumer.prototype._version=3;SourceMapConsumer.GENERATED_ORDER=1;SourceMapConsumer.ORIGINAL_ORDER=2;SourceMapConsumer.GREATEST_LOWER_BOUND=1;SourceMapConsumer.LEAST_UPPER_BOUND=2;n.SourceMapConsumer=SourceMapConsumer;class BasicSourceMapConsumer extends SourceMapConsumer{constructor(e,n){return super(c).then((t=>{let r=e;if(typeof e==="string"){r=o.parseSourceMapInput(e)}const s=o.getArg(r,"version");const l=o.getArg(r,"sources").map(String);const a=o.getArg(r,"names",[]);const c=o.getArg(r,"sourceRoot",null);const g=o.getArg(r,"sourcesContent",null);const f=o.getArg(r,"mappings");const h=o.getArg(r,"file",null);if(s!=t._version){throw new Error("Unsupported version: "+s)}t._sourceLookupCache=new Map;t._names=i.fromArray(a.map(String),true);t._sources=i.fromArray(l,true);t._absoluteSources=i.fromArray(t._sources.toArray().map((function(e){return o.computeSourceURL(c,e,n)})),true);t.sourceRoot=c;t.sourcesContent=g;t._mappings=f;t._sourceMapURL=n;t.file=h;t._computedColumnSpans=false;t._mappingsPtr=0;t._wasm=null;return u().then((e=>{t._wasm=e;return t}))}))}_findSourceIndex(e){const n=this._sourceLookupCache.get(e);if(typeof n==="number"){return n}const t=o.computeSourceURL(null,e,this._sourceMapURL);if(this._absoluteSources.has(t)){const n=this._absoluteSources.indexOf(t);this._sourceLookupCache.set(e,n);return n}const r=o.computeSourceURL(this.sourceRoot,e,this._sourceMapURL);if(this._absoluteSources.has(r)){const n=this._absoluteSources.indexOf(r);this._sourceLookupCache.set(e,n);return n}return-1}static fromSourceMap(e,n){return new BasicSourceMapConsumer(e.toString())}get sources(){return this._absoluteSources.toArray()}_getMappingsPtr(){if(this._mappingsPtr===0){this._parseMappings()}return this._mappingsPtr}_parseMappings(){const e=this._mappings;const n=e.length;const t=this._wasm.exports.allocate_mappings(n);const r=new Uint8Array(this._wasm.exports.memory.buffer,t,n);for(let t=0;t{if(n.source!==null){n.source=this._absoluteSources.at(n.source);if(n.name!==null){n.name=this._names.at(n.name)}}if(this._computedColumnSpans&&n.lastGeneratedColumn===null){n.lastGeneratedColumn=Infinity}e.call(r,n)}),(()=>{switch(o){case SourceMapConsumer.GENERATED_ORDER:this._wasm.exports.by_generated_location(this._getMappingsPtr());break;case SourceMapConsumer.ORIGINAL_ORDER:this._wasm.exports.by_original_location(this._getMappingsPtr());break;default:throw new Error("Unknown order of iteration.")}}))}allGeneratedPositionsFor(e){let n=o.getArg(e,"source");const t=o.getArg(e,"line");const r=e.column||0;n=this._findSourceIndex(n);if(n<0){return[]}if(t<1){throw new Error("Line numbers must be >= 1")}if(r<0){throw new Error("Column numbers must be >= 0")}const s=[];this._wasm.withMappingCallback((e=>{let n=e.lastGeneratedColumn;if(this._computedColumnSpans&&n===null){n=Infinity}s.push({line:e.generatedLine,column:e.generatedColumn,lastColumn:n})}),(()=>{this._wasm.exports.all_generated_locations_for(this._getMappingsPtr(),n,t-1,"column"in e,r)}));return s}destroy(){if(this._mappingsPtr!==0){this._wasm.exports.free_mappings(this._mappingsPtr);this._mappingsPtr=0}}computeColumnSpans(){if(this._computedColumnSpans){return}this._wasm.exports.compute_column_spans(this._getMappingsPtr());this._computedColumnSpans=true}originalPositionFor(e){const n={generatedLine:o.getArg(e,"line"),generatedColumn:o.getArg(e,"column")};if(n.generatedLine<1){throw new Error("Line numbers must be >= 1")}if(n.generatedColumn<0){throw new Error("Column numbers must be >= 0")}let t=o.getArg(e,"bias",SourceMapConsumer.GREATEST_LOWER_BOUND);if(t==null){t=SourceMapConsumer.GREATEST_LOWER_BOUND}let r;this._wasm.withMappingCallback((e=>r=e),(()=>{this._wasm.exports.original_location_for(this._getMappingsPtr(),n.generatedLine-1,n.generatedColumn,t)}));if(r){if(r.generatedLine===n.generatedLine){let e=o.getArg(r,"source",null);if(e!==null){e=this._absoluteSources.at(e)}let n=o.getArg(r,"name",null);if(n!==null){n=this._names.at(n)}return{source:e,line:o.getArg(r,"originalLine",null),column:o.getArg(r,"originalColumn",null),name:n}}}return{source:null,line:null,column:null,name:null}}hasContentsOfAllSources(){if(!this.sourcesContent){return false}return this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some((function(e){return e==null}))}sourceContentFor(e,n){if(!this.sourcesContent){return null}const t=this._findSourceIndex(e);if(t>=0){return this.sourcesContent[t]}if(n){return null}throw new Error('"'+e+'" is not in the SourceMap.')}generatedPositionFor(e){let n=o.getArg(e,"source");n=this._findSourceIndex(n);if(n<0){return{line:null,column:null,lastColumn:null}}const t={source:n,originalLine:o.getArg(e,"line"),originalColumn:o.getArg(e,"column")};if(t.originalLine<1){throw new Error("Line numbers must be >= 1")}if(t.originalColumn<0){throw new Error("Column numbers must be >= 0")}let r=o.getArg(e,"bias",SourceMapConsumer.GREATEST_LOWER_BOUND);if(r==null){r=SourceMapConsumer.GREATEST_LOWER_BOUND}let s;this._wasm.withMappingCallback((e=>s=e),(()=>{this._wasm.exports.generated_location_for(this._getMappingsPtr(),t.source,t.originalLine-1,t.originalColumn,r)}));if(s){if(s.source===t.source){let e=s.lastGeneratedColumn;if(this._computedColumnSpans&&e===null){e=Infinity}return{line:o.getArg(s,"generatedLine",null),column:o.getArg(s,"generatedColumn",null),lastColumn:e}}}return{line:null,column:null,lastColumn:null}}}BasicSourceMapConsumer.prototype.consumer=SourceMapConsumer;r=BasicSourceMapConsumer;class IndexedSourceMapConsumer extends SourceMapConsumer{constructor(e,n){return super(c).then((t=>{let r=e;if(typeof e==="string"){r=o.parseSourceMapInput(e)}const s=o.getArg(r,"version");const i=o.getArg(r,"sections");if(s!=t._version){throw new Error("Unsupported version: "+s)}let l={line:-1,column:0};return Promise.all(i.map((e=>{if(e.url){throw new Error("Support for url field in sections not implemented.")}const t=o.getArg(e,"offset");const r=o.getArg(t,"line");const s=o.getArg(t,"column");if(r({generatedOffset:{generatedLine:r+1,generatedColumn:s+1},consumer:e})))}))).then((e=>{t._sections=e;return t}))}))}get sources(){const e=[];for(let n=0;n=0?this._sections[n]:null;const r=n>=0&&n+1=0?this._sections[n]:null;const r=n>=0&&n+1{const n=t.generatedOffset.generatedLine-1;const o=t.generatedOffset.generatedColumn-1;if(e.line===1){e.column+=o;if(typeof e.lastColumn==="number"){e.lastColumn+=o}}if(e.lastColumn===Infinity&&r&&e.line===r.generatedOffset.generatedLine){e.lastColumn=r.generatedOffset.generatedColumn-2}e.line+=n;return e}))}eachMapping(e,n,t){this._sections.forEach(((r,o)=>{const s=o+1{const r=t(296);const o=t(67);const s=t(313).I;const i=t(627).H;class SourceMapGenerator{constructor(e){if(!e){e={}}this._file=o.getArg(e,"file",null);this._sourceRoot=o.getArg(e,"sourceRoot",null);this._skipValidation=o.getArg(e,"skipValidation",false);this._sources=new s;this._names=new s;this._mappings=new i;this._sourcesContents=null}static fromSourceMap(e){const n=e.sourceRoot;const t=new SourceMapGenerator({file:e.file,sourceRoot:n});e.eachMapping((function(e){const r={generated:{line:e.generatedLine,column:e.generatedColumn}};if(e.source!=null){r.source=e.source;if(n!=null){r.source=o.relative(n,r.source)}r.original={line:e.originalLine,column:e.originalColumn};if(e.name!=null){r.name=e.name}}t.addMapping(r)}));e.sources.forEach((function(r){let s=r;if(n!==null){s=o.relative(n,r)}if(!t._sources.has(s)){t._sources.add(s)}const i=e.sourceContentFor(r);if(i!=null){t.setSourceContent(r,i)}}));return t}addMapping(e){const n=o.getArg(e,"generated");const t=o.getArg(e,"original",null);let r=o.getArg(e,"source",null);let s=o.getArg(e,"name",null);if(!this._skipValidation){this._validateMapping(n,t,r,s)}if(r!=null){r=String(r);if(!this._sources.has(r)){this._sources.add(r)}}if(s!=null){s=String(s);if(!this._names.has(s)){this._names.add(s)}}this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:t!=null&&t.line,originalColumn:t!=null&&t.column,source:r,name:s})}setSourceContent(e,n){let t=e;if(this._sourceRoot!=null){t=o.relative(this._sourceRoot,t)}if(n!=null){if(!this._sourcesContents){this._sourcesContents=Object.create(null)}this._sourcesContents[o.toSetString(t)]=n}else if(this._sourcesContents){delete this._sourcesContents[o.toSetString(t)];if(Object.keys(this._sourcesContents).length===0){this._sourcesContents=null}}}applySourceMap(e,n,t){let r=n;if(n==null){if(e.file==null){throw new Error("SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, "+'or the source map\'s "file" property. Both were omitted.')}r=e.file}const i=this._sourceRoot;if(i!=null){r=o.relative(i,r)}const l=this._mappings.toArray().length>0?new s:this._sources;const a=new s;this._mappings.unsortedForEach((function(n){if(n.source===r&&n.originalLine!=null){const r=e.originalPositionFor({line:n.originalLine,column:n.originalColumn});if(r.source!=null){n.source=r.source;if(t!=null){n.source=o.join(t,n.source)}if(i!=null){n.source=o.relative(i,n.source)}n.originalLine=r.line;n.originalColumn=r.column;if(r.name!=null){n.name=r.name}}}const s=n.source;if(s!=null&&!l.has(s)){l.add(s)}const u=n.name;if(u!=null&&!a.has(u)){a.add(u)}}),this);this._sources=l;this._names=a;e.sources.forEach((function(n){const r=e.sourceContentFor(n);if(r!=null){if(t!=null){n=o.join(t,n)}if(i!=null){n=o.relative(i,n)}this.setSourceContent(n,r)}}),this)}_validateMapping(e,n,t,r){if(n&&typeof n.line!=="number"&&typeof n.column!=="number"){throw new Error("original.line and original.column are not numbers -- you probably meant to omit "+"the original mapping entirely and only map the generated position. If so, pass "+"null for the original mapping instead of an object with empty or null values.")}if(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0&&!n&&!t&&!r){}else if(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&t){}else{throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:t,original:n,name:r}))}}_serializeMappings(){let e=0;let n=1;let t=0;let s=0;let i=0;let l=0;let a="";let u;let c;let g;let f;const h=this._mappings.toArray();for(let p=0,m=h.length;p0){if(!o.compareByGeneratedPositionsInflated(c,h[p-1])){continue}u+=","}u+=r.encode(c.generatedColumn-e);e=c.generatedColumn;if(c.source!=null){f=this._sources.indexOf(c.source);u+=r.encode(f-l);l=f;u+=r.encode(c.originalLine-1-s);s=c.originalLine-1;u+=r.encode(c.originalColumn-t);t=c.originalColumn;if(c.name!=null){g=this._names.indexOf(c.name);u+=r.encode(g-i);i=g}}a+=u}return a}_generateSourcesContent(e,n){return e.map((function(e){if(!this._sourcesContents){return null}if(n!=null){e=o.relative(n,e)}const t=o.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,t)?this._sourcesContents[t]:null}),this)}toJSON(){const e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};if(this._file!=null){e.file=this._file}if(this._sourceRoot!=null){e.sourceRoot=this._sourceRoot}if(this._sourcesContents){e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)}return e}toString(){return JSON.stringify(this.toJSON())}}SourceMapGenerator.prototype._version=3;n.SourceMapGenerator=SourceMapGenerator},171:(e,n,t)=>{const r=t(42).SourceMapGenerator;const o=t(67);const s=/(\r?\n)/;const i=10;const l="$$$isSourceNode$$$";class SourceNode{constructor(e,n,t,r,o){this.children=[];this.sourceContents={};this.line=e==null?null:e;this.column=n==null?null:n;this.source=t==null?null:t;this.name=o==null?null:o;this[l]=true;if(r!=null)this.add(r)}static fromStringWithSourceMap(e,n,t){const r=new SourceNode;const i=e.split(s);let l=0;const shiftNextLine=function(){const e=getNextLine();const n=getNextLine()||"";return e+n;function getNextLine(){return l=0;n--){this.prepend(e[n])}}else if(e[l]||typeof e==="string"){this.children.unshift(e)}else{throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e)}return this}walk(e){let n;for(let t=0,r=this.children.length;t0){n=[];for(t=0;t{"use strict";e.exports=typeof URL==="function"?URL:t(310).URL},67:(e,n,t)=>{const r=t(298);function getArg(e,n,t){if(n in e){return e[n]}else if(arguments.length===3){return t}throw new Error('"'+n+'" is a required argument.')}n.getArg=getArg;const o=function(){const e=Object.create(null);return!("__proto__"in e)}();function identity(e){return e}function toSetString(e){if(isProtoString(e)){return"$"+e}return e}n.toSetString=o?identity:toSetString;function fromSetString(e){if(isProtoString(e)){return e.slice(1)}return e}n.fromSetString=o?identity:fromSetString;function isProtoString(e){if(!e){return false}const n=e.length;if(n<9){return false}if(e.charCodeAt(n-1)!==95||e.charCodeAt(n-2)!==95||e.charCodeAt(n-3)!==111||e.charCodeAt(n-4)!==116||e.charCodeAt(n-5)!==111||e.charCodeAt(n-6)!==114||e.charCodeAt(n-7)!==112||e.charCodeAt(n-8)!==95||e.charCodeAt(n-9)!==95){return false}for(let t=n-10;t>=0;t--){if(e.charCodeAt(t)!==36){return false}}return true}function strcmp(e,n){if(e===n){return 0}if(e===null){return 1}if(n===null){return-1}if(e>n){return 1}return-1}function compareByGeneratedPositionsInflated(e,n){let t=e.generatedLine-n.generatedLine;if(t!==0){return t}t=e.generatedColumn-n.generatedColumn;if(t!==0){return t}t=strcmp(e.source,n.source);if(t!==0){return t}t=e.originalLine-n.originalLine;if(t!==0){return t}t=e.originalColumn-n.originalColumn;if(t!==0){return t}return strcmp(e.name,n.name)}n.compareByGeneratedPositionsInflated=compareByGeneratedPositionsInflated;function parseSourceMapInput(e){return JSON.parse(e.replace(/^\)]}'[^\n]*\n/,""))}n.parseSourceMapInput=parseSourceMapInput;const s="http:";const i=`${s}//host`;function createSafeHandler(e){return n=>{const t=getURLType(n);const o=buildSafeBase(n);const l=new r(n,o);e(l);const a=l.toString();if(t==="absolute"){return a}else if(t==="scheme-relative"){return a.slice(s.length)}else if(t==="path-absolute"){return a.slice(i.length)}return computeRelativeURL(o,a)}}function withBase(e,n){return new r(e,n).toString()}function buildUniqueSegment(e,n){let t=0;do{const r=e+t++;if(n.indexOf(r)===-1)return r}while(true)}function buildSafeBase(e){const n=e.split("..").length-1;const t=buildUniqueSegment("p",e);let r=`${i}/`;for(let e=0;e0&&!o[o.length-1]){o.pop()}while(t.length>0&&o.length>0&&t[0]===o[0]){t.shift();o.shift()}const s=o.map((()=>"..")).concat(t).join("/");return s+n.search+n.hash}const a=createSafeHandler((e=>{e.pathname=e.pathname.replace(/\/?$/,"/")}));const u=createSafeHandler((e=>{e.href=new r(".",e.toString()).toString()}));const c=createSafeHandler((e=>{}));n.normalize=c;function join(e,n){const t=getURLType(n);const r=getURLType(e);e=a(e);if(t==="absolute"){return withBase(n,undefined)}if(r==="absolute"){return withBase(n,e)}if(t==="scheme-relative"){return c(n)}if(r==="scheme-relative"){return withBase(n,withBase(e,i)).slice(s.length)}if(t==="path-absolute"){return c(n)}if(r==="path-absolute"){return withBase(n,withBase(e,i)).slice(i.length)}const o=buildSafeBase(n+e);const l=withBase(n,withBase(e,o));return computeRelativeURL(o,l)}n.join=join;function relative(e,n){const t=relativeIfPossible(e,n);return typeof t==="string"?t:c(n)}n.relative=relative;function relativeIfPossible(e,n){const t=getURLType(e);if(t!==getURLType(n)){return null}const o=buildSafeBase(e+n);const s=new r(e,o);const i=new r(n,o);try{new r("",i.toString())}catch(e){return null}if(i.protocol!==s.protocol||i.user!==s.user||i.password!==s.password||i.hostname!==s.hostname||i.port!==s.port){return null}return computeRelativeURL(s,i)}function computeSourceURL(e,n,t){if(e&&getURLType(n)==="path-absolute"){n=n.replace(/^\//,"")}let r=c(n||"");if(e)r=join(e,r);if(t)r=join(u(t),r);return r}n.computeSourceURL=computeSourceURL},482:(e,n,t)=>{const r=t(153);function Mapping(){this.generatedLine=0;this.generatedColumn=0;this.lastGeneratedColumn=null;this.source=null;this.originalLine=null;this.originalColumn=null;this.name=null}let o=null;e.exports=function wasm(){if(o){return o}const e=[];o=r().then((n=>WebAssembly.instantiate(n,{env:{mapping_callback(n,t,r,o,s,i,l,a,u,c){const g=new Mapping;g.generatedLine=n+1;g.generatedColumn=t;if(r){g.lastGeneratedColumn=o-1}if(s){g.source=i;g.originalLine=l+1;g.originalColumn=a;if(u){g.name=c}}e[e.length-1](g)},start_all_generated_locations_for(){console.time("all_generated_locations_for")},end_all_generated_locations_for(){console.timeEnd("all_generated_locations_for")},start_compute_column_spans(){console.time("compute_column_spans")},end_compute_column_spans(){console.timeEnd("compute_column_spans")},start_generated_location_for(){console.time("generated_location_for")},end_generated_location_for(){console.timeEnd("generated_location_for")},start_original_location_for(){console.time("original_location_for")},end_original_location_for(){console.timeEnd("original_location_for")},start_parse_mappings(){console.time("parse_mappings")},end_parse_mappings(){console.timeEnd("parse_mappings")},start_sort_by_generated_location(){console.time("sort_by_generated_location")},end_sort_by_generated_location(){console.timeEnd("sort_by_generated_location")},start_sort_by_original_location(){console.time("sort_by_original_location")},end_sort_by_original_location(){console.timeEnd("sort_by_original_location")}}}))).then((n=>({exports:n.instance.exports,withMappingCallback:(n,t)=>{e.push(n);try{t()}finally{e.pop()}}}))).then(null,(e=>{o=null;throw e}));return o}},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},310:e=>{"use strict";e.exports=require("url")}};var n={};function __nccwpck_require__(t){var r=n[t];if(r!==undefined){return r.exports}var o=n[t]={exports:{}};var s=true;try{e[t](o,o.exports,__nccwpck_require__);s=false}finally{if(s)delete n[t]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{var e=t;e.SourceMapGenerator=__nccwpck_require__(42).SourceMapGenerator;e.SourceMapConsumer=__nccwpck_require__(316).SourceMapConsumer;e.SourceNode=__nccwpck_require__(171).SourceNode})();module.exports=t})(); \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/source-map/mappings.wasm b/packages/next-swc/crates/next-core/js/src/compiled/source-map/mappings.wasm new file mode 100644 index 000000000000..351537072336 Binary files /dev/null and b/packages/next-swc/crates/next-core/js/src/compiled/source-map/mappings.wasm differ diff --git a/packages/next-swc/crates/next-core/js/src/compiled/source-map/package.json b/packages/next-swc/crates/next-core/js/src/compiled/source-map/package.json new file mode 100644 index 000000000000..3e6c79f3ba21 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/source-map/package.json @@ -0,0 +1 @@ +{"name":"source-map","main":"index.js","author":"Nick Fitzgerald ","license":"BSD-3-Clause"} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/LICENSE b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/LICENSE new file mode 100644 index 000000000000..89e0797d875e --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2014-2019 Georg Tavonius + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/index.js b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/index.js new file mode 100644 index 000000000000..83c797ab55a0 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/index.js @@ -0,0 +1 @@ +(()=>{"use strict";if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e={};(()=>{var r=e;Object.defineProperty(r,"__esModule",{value:true});var n="";function parse(e){var r=e.split("\n");return r.reduce((function(e,r){var n=parseChrome(r)||parseWinjs(r)||parseGecko(r)||parseNode(r)||parseJSC(r);if(n){e.push(n)}return e}),[])}var a=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack||\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;var l=/\((\S*)(?::(\d+))(?::(\d+))\)/;function parseChrome(e){var r=a.exec(e);if(!r){return null}var u=r[2]&&r[2].indexOf("native")===0;var t=r[2]&&r[2].indexOf("eval")===0;var i=l.exec(r[2]);if(t&&i!=null){r[2]=i[1];r[3]=i[2];r[4]=i[3]}return{file:!u?r[2]:null,methodName:r[1]||n,arguments:u?[r[2]]:[],lineNumber:r[3]?+r[3]:null,column:r[4]?+r[4]:null}}var u=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;function parseWinjs(e){var r=u.exec(e);if(!r){return null}return{file:r[2],methodName:r[1]||n,arguments:[],lineNumber:+r[3],column:r[4]?+r[4]:null}}var t=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;var i=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i;function parseGecko(e){var r=t.exec(e);if(!r){return null}var a=r[3]&&r[3].indexOf(" > eval")>-1;var l=i.exec(r[3]);if(a&&l!=null){r[3]=l[1];r[4]=l[2];r[5]=null}return{file:r[3],methodName:r[1]||n,arguments:r[2]?r[2].split(","):[],lineNumber:r[4]?+r[4]:null,column:r[5]?+r[5]:null}}var s=/^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;function parseJSC(e){var r=s.exec(e);if(!r){return null}return{file:r[3],methodName:r[1]||n,arguments:[],lineNumber:+r[4],column:r[5]?+r[5]:null}}var o=/^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;function parseNode(e){var r=o.exec(e);if(!r){return null}return{file:r[2],methodName:r[1]||n,arguments:[],lineNumber:+r[3],column:r[4]?+r[4]:null}}r.parse=parse})();module.exports=e})(); \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/package.json b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/package.json new file mode 100644 index 000000000000..61e67ce89dc6 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/stacktrace-parser/package.json @@ -0,0 +1 @@ +{"name":"stacktrace-parser","main":"index.js","author":"Georg Tavonius (http://jaz-lounge.com)","license":"MIT"} diff --git a/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/LICENSE b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/LICENSE new file mode 100644 index 000000000000..fa7ceba3eb4a --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/index.js b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/index.js new file mode 100644 index 000000000000..252ac06be26f --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/index.js @@ -0,0 +1 @@ +var e={};(()=>{e.d=(t,r)=>{for(var n in r){if(e.o(r,n)&&!e.o(t,n)){Object.defineProperty(t,n,{enumerable:true,get:r[n]})}}}})();(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();if(typeof e!=="undefined")e.ab=new URL(".",import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/)?1:0,-1)+"/";var t={};e.d(t,{Z:()=>stripAnsi});function ansiRegex({onlyFirst:e=false}={}){const t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(t,e?undefined:"g")}function stripAnsi(e){if(typeof e!=="string"){throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``)}return e.replace(ansiRegex(),"")}var r=t.Z;export{r as default}; \ No newline at end of file diff --git a/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/package.json b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/package.json new file mode 100644 index 000000000000..fbd6457be777 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/compiled/strip-ansi/package.json @@ -0,0 +1 @@ +{"name":"strip-ansi","main":"index.js","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT"} diff --git a/packages/next-swc/crates/next-core/js/src/dev/bootstrap.ts b/packages/next-swc/crates/next-core/js/src/dev/bootstrap.ts new file mode 100644 index 000000000000..ed6a95a855f3 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/dev/bootstrap.ts @@ -0,0 +1,5 @@ +import { initializeHMR } from "./client"; + +initializeHMR({ + assetPrefix: "", +}); diff --git a/packages/next-swc/crates/next-core/js/src/dev/client.ts b/packages/next-swc/crates/next-core/js/src/dev/client.ts new file mode 100644 index 000000000000..1c5fa32f86ce --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/dev/client.ts @@ -0,0 +1,17 @@ +import { connect } from "./hmr-client"; +import { connectHMR } from "./websocket"; +import { register, ReactDevOverlay } from "../overlay/client"; + +export function initializeHMR(options: { assetPrefix: string }) { + connect({ + assetPrefix: options.assetPrefix, + }); + connectHMR({ + assetPrefix: options.assetPrefix, + log: true, + path: "/turbopack-hmr", + }); + register(); +} + +export { ReactDevOverlay }; diff --git a/packages/next-swc/crates/next-core/js/src/dev/hmr-client.ts b/packages/next-swc/crates/next-core/js/src/dev/hmr-client.ts new file mode 100644 index 000000000000..4654a1af2acf --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/dev/hmr-client.ts @@ -0,0 +1,599 @@ +import type { + ChunkListUpdate, + ChunkUpdate, + ClientMessage, + EcmascriptMergedChunkUpdate, + EcmascriptMergedUpdate, + EcmascriptModuleEntry, + Issue, + ResourceIdentifier, + ServerMessage, +} from "@vercel/turbopack-runtime/types/protocol"; +import type { + ChunkPath, + ModuleId, + UpdateCallback, + TurbopackGlobals, +} from "@vercel/turbopack-runtime/types"; + +import stripAnsi from "@vercel/turbopack-next/compiled/strip-ansi"; + +import { + onBeforeRefresh, + onBuildOk, + onRefresh, + onTurbopackIssues, +} from "../overlay/client"; +import { addEventListener, sendMessage } from "./websocket"; + +declare var globalThis: TurbopackGlobals; + +export type ClientOptions = { + assetPrefix: string; +}; + +export function connect({ assetPrefix }: ClientOptions) { + addEventListener((event) => { + switch (event.type) { + case "connected": + handleSocketConnected(); + break; + case "message": + const msg: ServerMessage = JSON.parse(event.message.data); + handleSocketMessage(msg); + break; + } + }); + + const queued = globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS; + if (queued != null && !Array.isArray(queued)) { + throw new Error("A separate HMR handler was already registered"); + } + globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS = { + push: ([chunkPath, callback]: [ChunkPath, UpdateCallback]) => { + subscribeToChunkUpdate(chunkPath, callback); + }, + }; + + if (Array.isArray(queued)) { + for (const [chunkPath, callback] of queued) { + subscribeToChunkUpdate(chunkPath, callback); + } + } +} + +type UpdateCallbackSet = { + callbacks: Set; + unsubscribe: () => void; +}; + +const updateCallbackSets: Map = new Map(); + +function sendJSON(message: ClientMessage) { + sendMessage(JSON.stringify(message)); +} + +type ResourceKey = string; + +function resourceKey(resource: ResourceIdentifier): ResourceKey { + return JSON.stringify({ + path: resource.path, + headers: resource.headers || null, + }); +} + +function subscribeToUpdates(resource: ResourceIdentifier): () => void { + sendJSON({ + type: "subscribe", + ...resource, + }); + + return () => { + sendJSON({ + type: "unsubscribe", + ...resource, + }); + }; +} + +function handleSocketConnected() { + for (const key of updateCallbackSets.keys()) { + subscribeToUpdates(JSON.parse(key)); + } +} + +// we aggregate all pending updates until the issues are resolved +const chunkListsWithPendingUpdates: Map< + ResourceKey, + { update: ChunkListUpdate; resource: ResourceIdentifier } +> = new Map(); + +function aggregateUpdates( + msg: ServerMessage, + aggregate: boolean +): ServerMessage { + const key = resourceKey(msg.resource); + let aggregated = chunkListsWithPendingUpdates.get(key); + + if (msg.type === "issues" && aggregated != null) { + if (!aggregate) { + chunkListsWithPendingUpdates.delete(key); + } + + return { + ...msg, + type: "partial", + instruction: aggregated.update, + }; + } + + if (msg.type !== "partial") return msg; + + if (aggregated == null) { + if (aggregate) { + chunkListsWithPendingUpdates.set(key, { + resource: msg.resource, + update: msg.instruction, + }); + } + + return msg; + } + + aggregated = { + resource: msg.resource, + update: mergeChunkListUpdates(aggregated.update, msg.instruction), + }; + + if (aggregate) { + chunkListsWithPendingUpdates.set(key, aggregated); + } else { + // Once we receive a partial update with no critical issues, we can stop aggregating updates. + // The aggregated update will be applied. + chunkListsWithPendingUpdates.delete(key); + } + + return { + ...msg, + instruction: aggregated.update, + }; +} + +function mergeChunkListUpdates( + updateA: ChunkListUpdate, + updateB: ChunkListUpdate +): ChunkListUpdate { + let chunks; + if (updateA.chunks != null) { + if (updateB.chunks == null) { + chunks = updateA.chunks; + } else { + chunks = mergeChunkListChunks(updateA.chunks, updateB.chunks); + } + } else if (updateB.chunks != null) { + chunks = updateB.chunks; + } + + let merged; + if (updateA.merged != null) { + if (updateB.merged == null) { + merged = updateA.merged; + } else { + // Since `merged` is an array of updates, we need to merge them all into + // one, consistent update. + // Since there can only be `EcmascriptMergeUpdates` in the array, there is + // no need to key on the `type` field. + let update = updateA.merged[0]; + for (let i = 1; i < updateA.merged.length; i++) { + update = mergeChunkListEcmascriptMergedUpdates( + update, + updateA.merged[i] + ); + } + + for (let i = 0; i < updateB.merged.length; i++) { + update = mergeChunkListEcmascriptMergedUpdates( + update, + updateB.merged[i] + ); + } + + merged = [update]; + } + } else if (updateB.merged != null) { + merged = updateB.merged; + } + + return { + type: "ChunkListUpdate", + chunks, + merged, + }; +} + +function mergeChunkListChunks( + chunksA: Record, + chunksB: Record +): Record { + const chunks: Record = {}; + + for (const [chunkPath, chunkUpdateA] of Object.entries(chunksA)) { + const chunkUpdateB = chunksB[chunkPath]; + if (chunkUpdateB != null) { + const mergedUpdate = mergeChunkUpdates(chunkUpdateA, chunkUpdateB); + if (mergedUpdate != null) { + chunks[chunkPath] = mergedUpdate; + } + } else { + chunks[chunkPath] = chunkUpdateA; + } + } + + for (const [chunkPath, chunkUpdateB] of Object.entries(chunksB)) { + if (chunks[chunkPath] == null) { + chunks[chunkPath] = chunkUpdateB; + } + } + + return chunks; +} + +function mergeChunkUpdates( + updateA: ChunkUpdate, + updateB: ChunkUpdate +): ChunkUpdate | undefined { + if ( + (updateA.type === "added" && updateB.type === "deleted") || + (updateA.type === "deleted" && updateB.type === "added") + ) { + return undefined; + } + + if (updateA.type === "partial") { + invariant(updateA.instruction, "Partial updates are unsupported"); + } + + if (updateB.type === "partial") { + invariant(updateB.instruction, "Partial updates are unsupported"); + } + + return undefined; +} + +function mergeChunkListEcmascriptMergedUpdates( + mergedA: EcmascriptMergedUpdate, + mergedB: EcmascriptMergedUpdate +): EcmascriptMergedUpdate { + const entries = mergeEcmascriptChunkEntries(mergedA.entries, mergedB.entries); + const chunks = mergeEcmascriptChunksUpdates(mergedA.chunks, mergedB.chunks); + + return { + type: "EcmascriptMergedUpdate", + entries, + chunks, + }; +} + +function mergeEcmascriptChunkEntries( + entriesA: Record | undefined, + entriesB: Record | undefined +): Record { + return { ...entriesA, ...entriesB }; +} + +function mergeEcmascriptChunksUpdates( + chunksA: Record | undefined, + chunksB: Record | undefined +): Record | undefined { + if (chunksA == null) { + return chunksB; + } + + if (chunksB == null) { + return chunksA; + } + + const chunks: Record = {}; + + for (const [chunkPath, chunkUpdateA] of Object.entries(chunksA)) { + const chunkUpdateB = chunksB[chunkPath]; + if (chunkUpdateB != null) { + const mergedUpdate = mergeEcmascriptChunkUpdates( + chunkUpdateA, + chunkUpdateB + ); + if (mergedUpdate != null) { + chunks[chunkPath] = mergedUpdate; + } + } else { + chunks[chunkPath] = chunkUpdateA; + } + } + + for (const [chunkPath, chunkUpdateB] of Object.entries(chunksB)) { + if (chunks[chunkPath] == null) { + chunks[chunkPath] = chunkUpdateB; + } + } + + if (Object.keys(chunks).length === 0) { + return undefined; + } + + return chunks; +} + +function mergeEcmascriptChunkUpdates( + updateA: EcmascriptMergedChunkUpdate, + updateB: EcmascriptMergedChunkUpdate +): EcmascriptMergedChunkUpdate | undefined { + if (updateA.type === "added" && updateB.type === "deleted") { + // These two completely cancel each other out. + return undefined; + } + + if (updateA.type === "deleted" && updateB.type === "added") { + const added = []; + const deleted = []; + const deletedModules = new Set(updateA.modules ?? []); + const addedModules = new Set(updateB.modules ?? []); + + for (const moduleId of addedModules) { + if (!deletedModules.has(moduleId)) { + added.push(moduleId); + } + } + + for (const moduleId of deletedModules) { + if (!addedModules.has(moduleId)) { + deleted.push(moduleId); + } + } + + if (added.length === 0 && deleted.length === 0) { + return undefined; + } + + return { + type: "partial", + added, + deleted, + }; + } + + if (updateA.type === "partial" && updateB.type === "partial") { + const added = new Set([...(updateA.added ?? []), ...(updateB.added ?? [])]); + const deleted = new Set([ + ...(updateA.deleted ?? []), + ...(updateB.deleted ?? []), + ]); + + if (updateB.added != null) { + for (const moduleId of updateB.added) { + deleted.delete(moduleId); + } + } + + if (updateB.deleted != null) { + for (const moduleId of updateB.deleted) { + added.delete(moduleId); + } + } + + return { + type: "partial", + added: [...added], + deleted: [...deleted], + }; + } + + if (updateA.type === "added" && updateB.type === "partial") { + const modules = new Set([ + ...(updateA.modules ?? []), + ...(updateB.added ?? []), + ]); + + for (const moduleId of updateB.deleted ?? []) { + modules.delete(moduleId); + } + + return { + type: "added", + modules: [...modules], + }; + } + + if (updateA.type === "partial" && updateB.type === "deleted") { + // We could eagerly return `updateB` here, but this would potentially be + // incorrect if `updateA` has added modules. + + const modules = new Set(updateB.modules ?? []); + + if (updateA.added != null) { + for (const moduleId of updateA.added) { + modules.delete(moduleId); + } + } + + return { + type: "deleted", + modules: [...modules], + }; + } + + // Any other update combination is invalid. + + return undefined; +} + +function invariant(never: never, message: string): never { + throw new Error(`Invariant: ${message}`); +} + +const CRITICAL = ["bug", "error", "fatal"]; + +function compareByList(list: any[], a: any, b: any) { + const aI = list.indexOf(a) + 1 || list.length; + const bI = list.indexOf(b) + 1 || list.length; + return aI - bI; +} + +const chunksWithIssues: Map = new Map(); + +function emitIssues() { + const issues = []; + const deduplicationSet = new Set(); + + for (const [_, chunkIssues] of chunksWithIssues) { + for (const chunkIssue of chunkIssues) { + if (deduplicationSet.has(chunkIssue.formatted)) continue; + + issues.push(chunkIssue); + deduplicationSet.add(chunkIssue.formatted); + } + } + + sortIssues(issues); + + onTurbopackIssues(issues); +} + +function handleIssues(msg: ServerMessage): boolean { + const key = resourceKey(msg.resource); + let hasCriticalIssues = false; + + for (const issue of msg.issues) { + if (CRITICAL.includes(issue.severity)) { + console.error(stripAnsi(issue.formatted)); + hasCriticalIssues = true; + } + } + + if (msg.issues.length > 0) { + chunksWithIssues.set(key, msg.issues); + } else if (chunksWithIssues.has(key)) { + chunksWithIssues.delete(key); + } + + emitIssues(); + + return hasCriticalIssues; +} + +const SEVERITY_ORDER = ["bug", "fatal", "error", "warning", "info", "log"]; +const CATEGORY_ORDER = [ + "parse", + "resolve", + "code generation", + "rendering", + "typescript", + "other", +]; + +function sortIssues(issues: Issue[]) { + issues.sort((a, b) => { + const first = compareByList(SEVERITY_ORDER, a.severity, b.severity); + if (first !== 0) return first; + return compareByList(CATEGORY_ORDER, a.category, b.category); + }); +} + +function handleSocketMessage(msg: ServerMessage) { + sortIssues(msg.issues); + + const hasCriticalIssues = handleIssues(msg); + + // TODO(WEB-582) Disable update aggregation for now. + const aggregate = /* hasCriticalIssues */ false; + const aggregatedMsg = aggregateUpdates(msg, aggregate); + + if (aggregate) return; + + const runHooks = chunkListsWithPendingUpdates.size === 0; + + if (aggregatedMsg.type !== "issues") { + if (runHooks) onBeforeRefresh(); + triggerUpdate(aggregatedMsg); + if (runHooks) onRefresh(); + } + + if (runHooks) onBuildOk(); + + // This is used by the Next.js integration test suite to notify it when HMR + // updates have been completed. + // TODO: Only run this in test environments (gate by `process.env.__NEXT_TEST_MODE`) + if (globalThis.__NEXT_HMR_CB) { + globalThis.__NEXT_HMR_CB(); + globalThis.__NEXT_HMR_CB = null; + } +} + +export function subscribeToChunkUpdate( + chunkPath: ChunkPath, + callback: UpdateCallback +): () => void { + return subscribeToUpdate( + { + path: chunkPath, + }, + callback + ); +} + +export function subscribeToUpdate( + resource: ResourceIdentifier, + callback: UpdateCallback +) { + const key = resourceKey(resource); + let callbackSet: UpdateCallbackSet; + const existingCallbackSet = updateCallbackSets.get(key); + if (!existingCallbackSet) { + callbackSet = { + callbacks: new Set([callback]), + unsubscribe: subscribeToUpdates(resource), + }; + updateCallbackSets.set(key, callbackSet); + } else { + existingCallbackSet.callbacks.add(callback); + callbackSet = existingCallbackSet; + } + + return () => { + callbackSet.callbacks.delete(callback); + + if (callbackSet.callbacks.size === 0) { + callbackSet.unsubscribe(); + updateCallbackSets.delete(key); + } + }; +} + +function triggerUpdate(msg: ServerMessage) { + const key = resourceKey(msg.resource); + const callbackSet = updateCallbackSets.get(key); + if (!callbackSet) { + return; + } + + try { + for (const callback of callbackSet.callbacks) { + callback(msg); + } + + if (msg.type === "notFound") { + // This indicates that the resource which we subscribed to either does not exist or + // has been deleted. In either case, we should clear all update callbacks, so if a + // new subscription is created for the same resource, it will send a new "subscribe" + // message to the server. + // No need to send an "unsubscribe" message to the server, it will have already + // dropped the update stream before sending the "notFound" message. + updateCallbackSets.delete(key); + } + } catch (err) { + console.error( + `An error occurred during the update of resource \`${msg.resource.path}\``, + err + ); + location.reload(); + } +} diff --git a/packages/next-swc/crates/next-core/js/src/dev/hot-reloader.tsx b/packages/next-swc/crates/next-core/js/src/dev/hot-reloader.tsx new file mode 100644 index 000000000000..cee6684283d8 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/dev/hot-reloader.tsx @@ -0,0 +1,35 @@ +"use client"; + +import type React from "react"; +import { useRouter, usePathname } from "next/dist/client/components/navigation"; +import { useEffect } from "react"; +import { subscribeToUpdate } from "./hmr-client"; +import { ReactDevOverlay } from "./client"; + +type HotReloadProps = React.PropsWithChildren<{ + assetPrefix?: string; +}>; + +export default function HotReload({ assetPrefix, children }: HotReloadProps) { + const router = useRouter(); + const path = usePathname()!.slice(1); + + useEffect(() => { + const unsubscribe = subscribeToUpdate( + { + path, + headers: { + rsc: "1", + }, + }, + (update) => { + if (update.type !== "issues") { + router.refresh(); + } + } + ); + return unsubscribe; + }, [router, path]); + + return {children}; +} diff --git a/packages/next-swc/crates/next-core/js/src/dev/websocket.ts b/packages/next-swc/crates/next-core/js/src/dev/websocket.ts new file mode 100644 index 000000000000..53cf2eab42a4 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/dev/websocket.ts @@ -0,0 +1,101 @@ +// Adapted from https://github.com/vercel/next.js/blob/canary/packages/next/client/dev/error-overlay/websocket.ts + +let source: WebSocket; +const eventCallbacks: ((event: WebsocketEvent) => void)[] = []; + +// TODO: add timeout again +// let lastActivity = Date.now() + +function getSocketProtocol(assetPrefix: string): string { + let protocol = location.protocol; + + try { + // assetPrefix is a url + protocol = new URL(assetPrefix).protocol; + } catch (_) {} + + return protocol === "http:" ? "ws" : "wss"; +} + +type WebsocketEvent = + | { + type: "connected"; + } + | { + type: "message"; + message: MessageEvent; + }; + +export function addEventListener(cb: (event: WebsocketEvent) => void) { + eventCallbacks.push(cb); +} + +export function sendMessage(data: any) { + if (!source || source.readyState !== source.OPEN) return; + return source.send(data); +} + +export type HMROptions = { + path: string; + assetPrefix: string; + timeout?: number; + log?: boolean; +}; + +export function connectHMR(options: HMROptions) { + const { timeout = 5 * 1000 } = options; + + function init() { + if (source) source.close(); + + console.log("[HMR] connecting..."); + + function handleOnline() { + eventCallbacks.forEach((cb) => { + cb({ + type: "connected", + }); + }); + + if (options.log) console.log("[HMR] connected"); + // lastActivity = Date.now() + } + + function handleMessage(event: MessageEvent) { + // lastActivity = Date.now() + + eventCallbacks.forEach((cb) => { + cb({ + type: "message", + message: event, + }); + }); + } + + // let timer: NodeJS.Timeout + + function handleDisconnect() { + source.close(); + setTimeout(init, timeout); + } + + const { hostname, port } = location; + const protocol = getSocketProtocol(options.assetPrefix || ""); + const assetPrefix = options.assetPrefix.replace(/^\/+/, ""); + + let url = `${protocol}://${hostname}:${port}${ + assetPrefix ? `/${assetPrefix}` : "" + }`; + + if (assetPrefix.startsWith("http")) { + url = `${protocol}://${assetPrefix.split("://")[1]}`; + } + + source = new window.WebSocket(`${url}${options.path}`); + source.onopen = handleOnline; + source.onerror = handleDisconnect; + source.onmessage = handleMessage; + } + + init(); +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/app-renderer.tsx b/packages/next-swc/crates/next-core/js/src/entry/app-renderer.tsx new file mode 100644 index 000000000000..8abb6612dda0 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app-renderer.tsx @@ -0,0 +1,303 @@ +// Provided by the rust generate code +type FileType = + | "layout" + | "template" + | "error" + | "loading" + | "not-found" + | "head"; +declare global { + // an array of all layouts and the page + const LAYOUT_INFO: ({ + segment: string; + page?: { module: any; chunks: string[] }; + } & { + [componentKey in FileType]?: { module: any; chunks: string[] }; + })[]; + // array of chunks for the bootstrap script + const BOOTSTRAP: string[]; + const IPC: Ipc; +} + +import type { Ipc } from "@vercel/turbopack-next/ipc/index"; +import type { IncomingMessage, ServerResponse } from "node:http"; +import type { + FlightCSSManifest, + FlightManifest, +} from "next/dist/build/webpack/plugins/flight-manifest-plugin"; +import type { RenderData } from "types/turbopack"; + +import "next/dist/server/node-polyfill-fetch"; +import "next/dist/server/node-polyfill-web-streams"; +import "@vercel/turbopack-next/polyfill/async-local-storage"; +import { RenderOpts, renderToHTMLOrFlight } from "next/dist/server/app-render"; +import { PassThrough } from "stream"; +import { ServerResponseShim } from "@vercel/turbopack-next/internal/http"; +import { headersFromEntries } from "@vercel/turbopack-next/internal/headers"; +import { parse, ParsedUrlQuery } from "node:querystring"; + +globalThis.__next_require__ = (data) => { + const [, , , ssr_id] = JSON.parse(data); + return __turbopack_require__(ssr_id); +}; +globalThis.__next_chunk_load__ = () => Promise.resolve(); + +process.env.__NEXT_NEW_LINK_BEHAVIOR = "true"; + +const ipc = IPC as Ipc; + +type IpcIncomingMessage = { + type: "headers"; + data: RenderData; +}; + +type IpcOutgoingMessage = { + type: "response"; + statusCode: number; + headers: Array<[string, string]>; + body: string; +}; + +const MIME_TEXT_HTML_UTF8 = "text/html; charset=utf-8"; + +(async () => { + while (true) { + const msg = await ipc.recv(); + + let renderData: RenderData; + switch (msg.type) { + case "headers": { + renderData = msg.data; + break; + } + default: { + console.error("unexpected message type", msg.type); + process.exit(1); + } + } + + const result = await runOperation(renderData); + + if (result == null) { + throw new Error("no html returned"); + } + + ipc.send({ + type: "response", + statusCode: 200, + ...result, + }); + } +})().catch((err) => { + ipc.sendError(err); +}); + +// TODO expose these types in next.js +type ComponentModule = () => any; +type ModuleReference = [componentModule: ComponentModule, filePath: string]; +export type ComponentsType = { + [componentKey in FileType]?: ModuleReference; +} & { + page?: ModuleReference; +}; +type LoaderTree = [ + segment: string, + parallelRoutes: { [parallelRouterKey: string]: LoaderTree }, + components: ComponentsType +]; + +type ServerComponentsManifest = { + [id: string]: ServerComponentsManifestModule; +}; +type ServerComponentsManifestModule = { + [exportName: string]: { id: string; chunks: string[]; name: string }; +}; + +async function runOperation(renderData: RenderData) { + const layoutInfoChunks: Record = {}; + const pageItem = LAYOUT_INFO[LAYOUT_INFO.length - 1]; + const pageModule = pageItem.page!.module; + let tree: LoaderTree = [ + "", + {}, + { page: [() => pageModule.module, "page.js"] }, + ]; + layoutInfoChunks["page"] = pageItem.page!.chunks; + for (let i = LAYOUT_INFO.length - 2; i >= 0; i--) { + const info = LAYOUT_INFO[i]; + const components: ComponentsType = {}; + for (const key of Object.keys(info)) { + if (key === "segment") { + continue; + } + const k = key as FileType; + components[k] = [() => info[k]!.module.module, `${k}${i}.js`]; + layoutInfoChunks[`${k}${i}`] = info[k]!.chunks; + } + tree = [info.segment, { children: tree }, components]; + } + + const proxyMethodsForModule = ( + id: string + ): ProxyHandler => ({ + get(_target, name) { + return { + id, + chunks: JSON.parse(id)[1], + name, + }; + }, + }); + const proxyMethodsNested = (): ProxyHandler< + FlightManifest["__ssr_module_mapping__"] + > => { + return { + get(target, name, receiver) { + if (name === "__ssr_module_mapping__") { + return manifest; + } + if (name === "__entry_css_files__") { + return __entry_css_files__; + } + return new Proxy({}, proxyMethodsForModule(name as string)); + }, + }; + }; + const proxyMethods = (): ProxyHandler => { + return { + get(_target, key: string) { + if (key === "__ssr_module_mapping__") { + return new Proxy({} as any, proxyMethodsNested()); + } + if (key === "__entry_css_files__") { + return __entry_css_files__; + } + + // The key is a `${file}#${name}`, but `file` can contain `#` itself. + // There are 2 possibilities: + // "file#" => id = "file", name = "" + // "file#foo" => id = "file", name = "foo" + const pos = key.lastIndexOf("#"); + let id = key; + let name = ""; + if (pos === -1) { + throw new Error("key need to be in format of ${file}#${name}"); + } else { + id = key.slice(0, pos); + name = key.slice(pos + 1); + } + + return { + id, + name, + chunks: JSON.parse(id)[1], + }; + }, + }; + }; + const manifest: FlightManifest = new Proxy({} as any, proxyMethods()); + const serverCSSManifest: FlightCSSManifest = {}; + const __entry_css_files__: FlightManifest["__entry_css_files__"] = {}; + for (const [key, chunks] of Object.entries(layoutInfoChunks)) { + const cssChunks = chunks.filter((path) => path.endsWith(".css")); + serverCSSManifest[`${key}.js`] = cssChunks.map((chunk) => + JSON.stringify([chunk, [chunk]]) + ); + __entry_css_files__[key] = cssChunks; + } + serverCSSManifest.__entry_css_mods__ = { + page: serverCSSManifest["page.js"], + }; + const req: IncomingMessage = { + url: renderData.url, + method: renderData.method, + headers: headersFromEntries(renderData.rawHeaders), + } as any; + const res: ServerResponse = new ServerResponseShim(req) as any; + const parsedQuery = parse(renderData.rawQuery); + const query = { ...parsedQuery, ...renderData.params }; + const renderOpt: Omit< + RenderOpts, + "App" | "Document" | "Component" | "pathname" + > & { params: ParsedUrlQuery } = { + params: renderData.params, + supportsDynamicHTML: true, + dev: true, + buildManifest: { + polyfillFiles: [], + rootMainFiles: Object.values(layoutInfoChunks) + .flat() + .concat(BOOTSTRAP) + .filter((path) => path.endsWith(".js")), + devFiles: [], + ampDevFiles: [], + lowPriorityFiles: [], + pages: { + "/_app": [], + }, + ampFirstPages: [], + }, + ComponentMod: { + ...pageModule, + default: undefined, + tree, + pages: ["page.js"], + }, + serverComponentManifest: manifest, + serverCSSManifest, + runtime: "nodejs", + serverComponents: true, + assetPrefix: "", + pageConfig: pageModule.config, + reactLoadableManifest: {}, + }; + const result = await renderToHTMLOrFlight( + req, + res, + renderData.path, + query, + renderOpt as any as RenderOpts + ); + + if (!result) throw new Error("rendering was not successful"); + + let body; + if (result.isDynamic()) { + const stream = new PassThrough(); + result.pipe(stream); + + const chunks = []; + for await (const chunk of stream) { + chunks.push(chunk); + } + body = Buffer.concat(chunks).toString(); + } else { + body = result.toUnchunkedString(); + } + return { + headers: [ + ["Content-Type", result.contentType() ?? MIME_TEXT_HTML_UTF8], + ] as [string, string][], + body, + }; +} + +// This utility is based on https://github.com/zertosh/htmlescape +// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE + +const ESCAPE_LOOKUP = { + "&": "\\u0026", + ">": "\\u003e", + "<": "\\u003c", + "\u2028": "\\u2028", + "\u2029": "\\u2029", +}; + +const ESCAPE_REGEX = /[&><\u2028\u2029]/g; + +export function htmlEscapeJsonString(str: string) { + return str.replace( + ESCAPE_REGEX, + (match) => ESCAPE_LOOKUP[match as keyof typeof ESCAPE_LOOKUP] + ); +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/hydrate.tsx b/packages/next-swc/crates/next-core/js/src/entry/app/hydrate.tsx new file mode 100644 index 000000000000..2be819e8ff67 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/hydrate.tsx @@ -0,0 +1,164 @@ +import ReactDOMClient from "react-dom/client"; +import React, { use } from "react"; +import type { ReactElement } from "react"; +// @ts-expect-error +import { version } from "next/package.json"; +import { createFromReadableStream } from "next/dist/compiled/react-server-dom-webpack/client"; + +import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context"; + +import { initializeHMR } from "@vercel/turbopack-next/dev/client"; + +initializeHMR({ + assetPrefix: "", +}); + +window.next = { + version, + appDir: true, +}; + +globalThis.__next_require__ = (data) => { + const [client_id, chunks, chunkListPath] = JSON.parse(data); + __turbopack_register_chunk_list__(chunkListPath, chunks); + return __turbopack_require__(client_id); +}; +globalThis.__next_chunk_load__ = __turbopack_load__; + +process.env.__NEXT_NEW_LINK_BEHAVIOR = "true"; + +const appElement = document; + +const getCacheKey = () => { + const { pathname, search } = location; + return pathname + search; +}; + +const encoder = new TextEncoder(); +let initialServerDataBuffer: string[] | undefined = undefined; +let initialServerDataWriter: ReadableStreamDefaultController | undefined = + undefined; +let initialServerDataLoaded = false; +let initialServerDataFlushed = false; + +function nextServerDataCallback( + seg: [isBootStrap: 0] | [isNotBootstrap: 1, responsePartial: string] +): number { + if (seg[0] === 0) { + initialServerDataBuffer = []; + } else { + if (!initialServerDataBuffer) + throw new Error("Unexpected server data: missing bootstrap script."); + + if (initialServerDataWriter) { + initialServerDataWriter.enqueue(encoder.encode(seg[1])); + } else { + initialServerDataBuffer.push(seg[1]); + } + } + return 0; +} + +function nextServerDataRegisterWriter(ctr: ReadableStreamDefaultController) { + if (initialServerDataBuffer) { + initialServerDataBuffer.forEach((val) => { + ctr.enqueue(encoder.encode(val)); + }); + if (initialServerDataLoaded && !initialServerDataFlushed) { + ctr.close(); + initialServerDataFlushed = true; + initialServerDataBuffer = undefined; + } + } + + initialServerDataWriter = ctr; +} + +// When `DOMContentLoaded`, we can close all pending writers to finish hydration. +const DOMContentLoaded = function () { + if (initialServerDataWriter && !initialServerDataFlushed) { + initialServerDataWriter.close(); + initialServerDataFlushed = true; + initialServerDataBuffer = undefined; + } + initialServerDataLoaded = true; +}; +// It's possible that the DOM is already loaded. +if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", DOMContentLoaded, false); +} else { + DOMContentLoaded(); +} + +const nextServerDataLoadingGlobal = (self.__next_f = self.__next_f || []); +nextServerDataLoadingGlobal.forEach(nextServerDataCallback); +nextServerDataLoadingGlobal.push = nextServerDataCallback; + +function createResponseCache() { + return new Map(); +} +const rscCache = createResponseCache(); + +function useInitialServerResponse(cacheKey: string) { + const response = rscCache.get(cacheKey); + if (response) return response; + + const readable = new ReadableStream({ + start(controller) { + nextServerDataRegisterWriter(controller); + }, + }); + + const newResponse = createFromReadableStream(readable); + + rscCache.set(cacheKey, newResponse); + return newResponse; +} + +function ServerRoot({ cacheKey }: { cacheKey: string }) { + React.useEffect(() => { + rscCache.delete(cacheKey); + }); + const response = useInitialServerResponse(cacheKey); + const root = use(response) as ReactElement; + return root; +} + +function RSCComponent() { + const cacheKey = getCacheKey(); + return ; +} + +function hydrate() { + const reactEl = ( + + + + + + ); + + const isError = document.documentElement.id === "__next_error__"; + if (isError) { + // cast necessary because of a typing bug + const reactRoot = ReactDOMClient.createRoot( + appElement as unknown as DocumentFragment + ); + reactRoot.render(reactEl); + } else { + React.startTransition(() => { + ReactDOMClient.hydrateRoot(appElement, reactEl); + }); + } +} + +window.next = { + version: "turbo", + appDir: true, +}; + +hydrate(); diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/index.d.ts b/packages/next-swc/crates/next-core/js/src/entry/app/index.d.ts new file mode 100644 index 000000000000..69e3db64322a --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/index.d.ts @@ -0,0 +1,8 @@ +// this file is just here to make typescript happy about the wrapped/virtual assets (import ".") + +declare var Anything: any; +export = Anything; + +export const __turbopack_module_id__: string | number; +export const chunks: string[]; +export const chunkListPath: string; diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/layout-entry.tsx b/packages/next-swc/crates/next-core/js/src/entry/app/layout-entry.tsx new file mode 100644 index 000000000000..7ceb7ce7fae5 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/layout-entry.tsx @@ -0,0 +1,13 @@ +export { default as AppRouter } from "next/dist/client/components/app-router.js"; +export { default as LayoutRouter } from "next/dist/client/components/layout-router.js"; +export { default as RenderFromTemplateContext } from "next/dist/client/components/render-from-template-context.js"; +export { default as GlobalError } from "next/dist/client/components/error-boundary.js"; +export { staticGenerationAsyncStorage } from "next/dist/client/components/static-generation-async-storage.js"; +export { requestAsyncStorage } from "next/dist/client/components/request-async-storage.js"; +import * as serverHooks from "next/dist/client/components/hooks-server-context.js"; +export { serverHooks }; +export { renderToReadableStream } from "next/dist/compiled/react-server-dom-webpack/server.edge"; + +// @ts-expect-error PAGE is provided by rust +import * as module from "PAGE"; +export { module }; diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/route-bootstrap.ts b/packages/next-swc/crates/next-core/js/src/entry/app/route-bootstrap.ts new file mode 100644 index 000000000000..26a913e35adc --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/route-bootstrap.ts @@ -0,0 +1,41 @@ +declare const PAGE: string; + +import { adapter, enhanceGlobals } from "next/dist/server/web/adapter"; +import { getHandle } from "next/dist/build/webpack/loaders/next-edge-app-route-loader/handle"; + +import { staticGenerationAsyncStorage } from "next/dist/client/components/static-generation-async-storage"; +import * as serverHooks from "next/dist/client/components/hooks-server-context"; +import { staticGenerationBailout } from "next/dist/client/components/static-generation-bailout"; +import * as headerHooks from "next/dist/client/components/headers"; +import { requestAsyncStorage } from "next/dist/client/components/request-async-storage"; + +enhanceGlobals(); + +// @ts-expect-error ENTRY is set from rust code +import * as handlers from "ENTRY"; +const mod = { + handlers, + resolvedPagePath: `app/${PAGE}`, + staticGenerationAsyncStorage, + serverHooks, + staticGenerationBailout, + headerHooks, + requestAsyncStorage, +}; +const handler = getHandle({ + mod, + page: `/${PAGE}`, +}); + +// @ts-ignore +globalThis._ENTRIES = { + middleware_edge: { + default: function (opts: any) { + return adapter({ + ...opts, + page: `/${PAGE}`, + handler, + }); + }, + }, +}; diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/route.ts b/packages/next-swc/crates/next-core/js/src/entry/app/route.ts new file mode 100644 index 000000000000..9455883f299c --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/route.ts @@ -0,0 +1,39 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import startHandler from "@vercel/turbopack-next/internal/api-server-handler"; +import { runEdgeFunction } from "@vercel/turbopack-next/internal/edge"; + +import { join } from "path"; + +import "next/dist/server/node-polyfill-fetch.js"; + +import chunkGroup from "ROUTE_CHUNK_GROUP"; + +import { + NodeNextRequest, + NodeNextResponse, +} from "next/dist/server/base-http/node"; + +startHandler(async ({ request, response, query, params, path }) => { + const edgeInfo = { + name: "edge", + paths: chunkGroup.map((chunk: string) => + join(process.cwd(), ".next/server/app", chunk) + ), + wasm: [], + env: [], + assets: [], + }; + await runEdgeFunction({ + edgeInfo, + outputDir: "app", + req: new NodeNextRequest(request), + res: new NodeNextResponse(response), + query, + params, + path, + onWarning(warning) { + console.warn(warning); + }, + }); +}); diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client-ssr.tsx b/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client-ssr.tsx new file mode 100644 index 000000000000..2f57e412afb3 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client-ssr.tsx @@ -0,0 +1,12 @@ +import { createProxy } from "next/dist/build/webpack/loaders/next-flight-loader/module-proxy"; + +("TURBOPACK { chunking-type: isolatedParallel }"); +// @ts-expect-error CLIENT_MODULE is provided by rust +import { __turbopack_module_id__ as id } from "CLIENT_MODULE"; + +// @ts-expect-error CLIENT_CHUNKS is provided by rust +import client_id, { chunks, chunkListPath } from "CLIENT_CHUNKS"; + +export default createProxy( + JSON.stringify([client_id, chunks, chunkListPath, id]) +); diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client.tsx b/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client.tsx new file mode 100644 index 000000000000..142d9e32732d --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/app/server-to-client.tsx @@ -0,0 +1,6 @@ +import { createProxy } from "next/dist/build/webpack/loaders/next-flight-loader/module-proxy"; + +// @ts-expect-error CLIENT_CHUNKS is provided by rust +import client_id, { chunks, chunkListPath } from "CLIENT_CHUNKS"; + +export default createProxy(JSON.stringify([client_id, chunks, chunkListPath])); diff --git a/packages/next-swc/crates/next-core/js/src/entry/config/next.js b/packages/next-swc/crates/next-core/js/src/entry/config/next.js new file mode 100644 index 000000000000..fd5d53bfd28b --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/config/next.js @@ -0,0 +1,60 @@ +import loadConfig from "next/dist/server/config"; +import loadCustomRoutes from "next/dist/lib/load-custom-routes"; +import { PHASE_DEVELOPMENT_SERVER } from "next/dist/shared/lib/constants"; +import assert from "node:assert"; + +const loadNextConfig = async (silent) => { + const nextConfig = await loadConfig( + PHASE_DEVELOPMENT_SERVER, + process.cwd(), + undefined, + undefined, + silent + ); + + nextConfig.generateBuildId = await nextConfig.generateBuildId?.(); + + const customRoutes = await loadCustomRoutes(nextConfig); + + nextConfig.headers = customRoutes.headers; + nextConfig.rewrites = customRoutes.rewrites; + nextConfig.redirects = customRoutes.redirects; + + // TODO: these functions takes arguments, have to be supported in a different way + nextConfig.exportPathMap = nextConfig.exportPathMap && {}; + nextConfig.webpack = nextConfig.webpack && {}; + + if (nextConfig.experimental?.turbopack?.loaders) { + ensureLoadersHaveSerializableOptions( + nextConfig.experimental.turbopack.loaders + ); + } + + return nextConfig; +}; + +export { loadNextConfig as default }; + +function ensureLoadersHaveSerializableOptions(turbopackLoaders) { + for (const [ext, loaderItems] of Object.entries(turbopackLoaders)) { + for (const loaderItem of loaderItems) { + if ( + typeof loaderItem !== "string" && + !deepEqual(loaderItem, JSON.parse(JSON.stringify(loaderItem))) + ) { + throw new Error( + `loader ${loaderItem.loader} for match "${ext}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.` + ); + } + } + } +} + +function deepEqual(a, b) { + try { + assert.deepStrictEqual(a, b); + return true; + } catch { + return false; + } +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/edge-bootstrap.ts b/packages/next-swc/crates/next-core/js/src/entry/edge-bootstrap.ts new file mode 100644 index 000000000000..0ad3d2c9baf8 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/edge-bootstrap.ts @@ -0,0 +1,28 @@ +declare const NAME: string; +declare const PAGE: string; + +import { adapter, enhanceGlobals } from "next/dist/server/web/adapter"; + +enhanceGlobals(); + +var mod = require("ENTRY"); +var handler = mod.middleware || mod.default; + +if (typeof handler !== "function") { + throw new Error( + `The Edge Function "pages/${PAGE}" must export a \`default\` function` + ); +} + +// @ts-ignore +globalThis._ENTRIES = { + [`middleware_${NAME}`]: { + default: function (opts: any) { + return adapter({ + ...opts, + page: `/${PAGE}`, + handler, + }); + }, + }, +}; diff --git a/packages/next-swc/crates/next-core/js/src/entry/error.tsx b/packages/next-swc/crates/next-core/js/src/entry/error.tsx new file mode 100644 index 000000000000..6f78f21b8d55 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/error.tsx @@ -0,0 +1,7 @@ +// TODO(alexkirsz) export * would be preferrable here once supported. +export { + default, + getStaticProps, + __N_SSG, + __N_SSP, +} from "@vercel/turbopack-next/internal/_error"; diff --git a/packages/next-swc/crates/next-core/js/src/entry/fallback.tsx b/packages/next-swc/crates/next-core/js/src/entry/fallback.tsx new file mode 100644 index 000000000000..5aefc76bd0ca --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/fallback.tsx @@ -0,0 +1,34 @@ +import "@vercel/turbopack-next/internal/shims-client"; + +import { createRoot } from "react-dom/client"; + +import { + initializeHMR, + ReactDevOverlay, +} from "@vercel/turbopack-next/dev/client"; +import { subscribeToUpdate } from "@vercel/turbopack-next/dev/hmr-client"; + +const pageChunkPath = location.pathname.slice(1); + +subscribeToUpdate( + { + path: pageChunkPath, + headers: { + accept: "text/html", + }, + }, + (update) => { + if (update.type === "restart" || update.type === "notFound") { + location.reload(); + } + } +); + +initializeHMR({ + assetPrefix: "", +}); + +const el = document.getElementById("__next")!; +el.innerText = ""; + +createRoot(el).render(); diff --git a/packages/next-swc/crates/next-core/js/src/entry/index.d.ts b/packages/next-swc/crates/next-core/js/src/entry/index.d.ts new file mode 100644 index 000000000000..94904f577498 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/index.d.ts @@ -0,0 +1,4 @@ +// this file is just here to make typescript happy about the wrapped/virtual assets (import ".") + +declare var Anything: any; +export = Anything; diff --git a/packages/next-swc/crates/next-core/js/src/entry/manifest/buildManifest.js b/packages/next-swc/crates/next-core/js/src/entry/manifest/buildManifest.js new file mode 100644 index 000000000000..d54074f3e299 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/manifest/buildManifest.js @@ -0,0 +1,18 @@ +((manifest) => { + // adapted from https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/plugins/build-manifest-plugin.ts#L54-L54 + function processRoute(rewrite) { + // omit external rewrite destinations since these aren't + // handled client-side + if (!rewrite.destination.startsWith("/")) { + delete rewrite.destination; + } + return rewrite; + } + + manifest.__rewrites.beforeFiles.map(processRoute); + manifest.__rewrites.afterFiles.map(processRoute); + manifest.__rewrites.fallback.map(processRoute); + + self.__BUILD_MANIFEST = manifest; + self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB(); +})($$MANIFEST$$); diff --git a/packages/next-swc/crates/next-core/js/src/entry/next-hydrate.tsx b/packages/next-swc/crates/next-core/js/src/entry/next-hydrate.tsx new file mode 100644 index 000000000000..3fd0b24361cf --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/next-hydrate.tsx @@ -0,0 +1,212 @@ +import "@vercel/turbopack-next/internal/shims-client"; + +import { + initialize, + hydrate, + router, + emitter, + version, +} from "next/dist/client"; +import type { Router } from "next/dist/client/router"; +import { + assign, + urlQueryToSearchParams, +} from "next/dist/shared/lib/router/utils/querystring"; +import { formatWithValidation } from "next/dist/shared/lib/router/utils/format-url"; +import { initializeHMR } from "@vercel/turbopack-next/dev/client"; +import { + subscribeToUpdate, + subscribeToCssChunkUpdates, +} from "@vercel/turbopack-next/dev/hmr-client"; + +import * as _app from "@vercel/turbopack-next/pages/_app"; +// @ts-expect-error PAGE is provided by rust +import * as page from "PAGE"; + +async function loadPageChunk(assetPrefix: string, chunkPath: string) { + const fullPath = assetPrefix + chunkPath; + + await __turbopack_load__(fullPath); + + // TODO: the turbopack chunk loader should do this somehow + if (chunkPath.endsWith(".css")) { + const link = document.querySelector( + `link[href=${JSON.stringify(fullPath)}]` + ); + if (!link) { + throw new Error("stylesheet should be loaded, but is not"); + } + + subscribeToCssChunkUpdates(assetPrefix, link); + } +} + +(async () => { + console.debug("Initializing Next.js"); + + window.next = { + version: version || "", + // @ts-expect-error + get router() { + return router; + }, + emitter, + }; + + const { assetPrefix } = await initialize({ + webpackHMR: { + // Expected when `process.env.NODE_ENV === 'development'` + onUnrecoverableError() {}, + }, + }); + + initializeHMR({ + assetPrefix, + }); + + // for the page loader + window.__turbopack_load_page_chunks__ = (page, paths) => { + const chunkPromises = paths.map(loadPageChunk.bind(null, assetPrefix)); + + Promise.all(chunkPromises).catch((err) => + console.error("failed to load chunks for page " + page, err) + ); + }; + + const pagePath = window.__NEXT_DATA__.page; + window.__NEXT_P.push(["/_app", () => _app]); + window.__NEXT_P.push([pagePath, () => page]); + + console.debug("Hydrating the page"); + + await hydrate({}); + + // This needs to happen after hydration because the router is initialized + // during hydration. To make this dependency clearer, we pass `router` as an + // explicit argument instead of relying on the `router` import binding. + subscribeToCurrentPageData({ assetPrefix, router }); + subscribeToPageManifest({ assetPrefix }); + + console.debug("The page has been hydrated"); +})().catch((err) => console.error(err)); + +function subscribeToPageManifest({ assetPrefix }: { assetPrefix: string }) { + // adapted from https://github.com/vercel/next.js/blob/836ac9cc7f290e95b564a61341fa95a5f4f0327e/packages/next/src/client/next-dev.ts#L57 + subscribeToUpdate( + { + path: "_next/static/development/_devPagesManifest.json", + }, + (update) => { + if (["restart", "notFound", "partial"].includes(update.type)) { + return; + } + + fetch(`${assetPrefix}/_next/static/development/_devPagesManifest.json`) + .then((res) => res.json()) + .then((manifest) => { + window.__DEV_PAGES_MANIFEST = manifest; + }) + .catch((err) => { + console.log(`Failed to fetch devPagesManifest`, err); + }); + } + ); +} + +/** + * Subscribes to the current page's data updates from the HMR server. + * + * Updates on route change. + */ +function subscribeToCurrentPageData({ + router, + assetPrefix, +}: { + router: Router; + assetPrefix: string; +}) { + let dataPath = getCurrentPageDataHref(); + let unsubscribe = subscribeToPageData({ + router, + dataPath, + assetPrefix, + }); + + router.events.on("routeChangeComplete", () => { + const nextDataPath = getCurrentPageDataHref(); + if (dataPath === nextDataPath) { + return; + } + dataPath = nextDataPath; + + unsubscribe(); + unsubscribe = subscribeToPageData({ + router, + dataPath, + assetPrefix, + }); + }); +} + +function getCurrentPageDataHref(): string { + return router.pageLoader.getDataHref({ + asPath: router.asPath, + href: formatWithValidation({ + // No need to pass `router.query` when `skipInterpolation` is true. + pathname: router.pathname, + }), + skipInterpolation: true, + }); +} + +/** + * TODO(alexkirsz): Handle assetPrefix/basePath. + */ +function subscribeToPageData({ + router, + dataPath, + assetPrefix, +}: { + router: Router; + dataPath: string; + assetPrefix: string; +}): () => void { + return subscribeToUpdate( + { + // We need to remove the leading / from the data path as Turbopack + // resources are not prefixed with a /. + path: dataPath.slice(1), + headers: { + // This header is used by the Next.js server to determine whether this + // is a data request. + "x-nextjs-data": "1", + }, + }, + (update) => { + if (update.type !== "restart") { + return; + } + + // This triggers a reload of the page data. + // Adapted from next.js/packages/next/client/next-dev.js. + router + .replace( + router.pathname + + "?" + + String( + assign( + urlQueryToSearchParams(router.query), + new URLSearchParams(location.search) + ) + ), + router.asPath, + { scroll: false } + ) + .catch(() => { + // trigger hard reload when failing to refresh data + // to show error overlay properly + location.reload(); + }); + } + ); +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/page-loader.ts b/packages/next-swc/crates/next-core/js/src/entry/page-loader.ts new file mode 100644 index 000000000000..743c1935f031 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/page-loader.ts @@ -0,0 +1,18 @@ +import * as page from "PAGE"; + +// inserted by rust code +declare const PAGE_PATH: string; + +// Adapted from https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/loaders/next-client-pages-loader.ts + +(window.__NEXT_P = window.__NEXT_P || []).push([ + PAGE_PATH, + () => { + return page; + }, +]); +if (module.hot) { + module.hot.dispose(function () { + window.__NEXT_P.push([PAGE_PATH]); + }); +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/router.ts b/packages/next-swc/crates/next-core/js/src/entry/router.ts new file mode 100644 index 000000000000..af735359f6ed --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/router.ts @@ -0,0 +1,201 @@ +import type { Ipc } from "@vercel/turbopack-next/ipc/index"; +import type { IncomingMessage, ServerResponse } from "node:http"; +import { Buffer } from "node:buffer"; +import { createServer, makeRequest } from "@vercel/turbopack-next/ipc/server"; +import { toPairs } from "@vercel/turbopack-next/internal/headers"; +import { makeResolver } from "next/dist/server/lib/route-resolver"; +import loadConfig from "next/dist/server/config"; +import { PHASE_DEVELOPMENT_SERVER } from "next/dist/shared/lib/constants"; + +import "next/dist/server/node-polyfill-fetch.js"; + +import middlewareChunkGroup from "MIDDLEWARE_CHUNK_GROUP"; +import middlewareConfig from "MIDDLEWARE_CONFIG"; + +type RouterRequest = { + method: string; + pathname: string; + rawHeaders: [string, string][]; + rawQuery: string; +}; + +type RouteResult = + | { + type: "rewrite"; + url: string; + headers: Record; + } + | { + type: "none"; + }; + +type IpcOutgoingMessage = { + type: "jsonValue"; + data: string; +}; + +type MessageData = + | { type: "middleware-headers"; data: MiddlewareHeadersResponse } + | { type: "middleware-body"; data: Uint8Array } + | { + type: "full-middleware"; + data: { headers: MiddlewareHeadersResponse; body: number[] }; + } + | { + type: "rewrite"; + data: RewriteResponse; + } + | { type: "none" }; + +type RewriteResponse = { + url: string; + headers: [string, string][]; +}; + +type MiddlewareHeadersResponse = { + statusCode: number; + headers: [string, string][]; +}; + +let resolveRouteMemo: Promise< + (req: IncomingMessage, res: ServerResponse) => Promise +>; + +async function getResolveRoute( + dir: string +): ReturnType< + typeof import("next/dist/server/lib/route-resolver").makeResolver +> { + const nextConfig = await loadConfig( + PHASE_DEVELOPMENT_SERVER, + process.cwd(), + undefined, + undefined, + true + ); + + return await makeResolver(dir, nextConfig, { + files: middlewareChunkGroup.filter((f) => /\.[mc]?js$/.test(f)), + matcher: middlewareConfig.matcher, + }); +} + +export default async function route( + ipc: Ipc, + routerRequest: RouterRequest, + dir: string +) { + const [resolveRoute, server] = await Promise.all([ + (resolveRouteMemo ??= getResolveRoute(dir)), + createServer(), + ]); + + try { + const { + clientRequest, + clientResponsePromise, + serverRequest, + serverResponse, + } = await makeRequest( + server, + routerRequest.method, + routerRequest.pathname, + routerRequest.rawQuery, + routerRequest.rawHeaders + ); + + // Send the clientRequest, so the server parses everything. We can then pass + // the serverRequest to Next.js to handle. + clientRequest.end(); + + // The route promise must not block us from starting the client response + // handling, so we cannot await it yet. By making the call, we allow + // Next.js to start writing to the response whenever it's ready. + const routePromise = resolveRoute(serverRequest, serverResponse); + + // Now that the Next.js has started processing the route, the + // clientResponsePromise will resolve once they write data and then we can + // begin streaming. + // We again cannot block on the clientResponsePromise, because an error may + // occur in the routePromise while we're waiting. + const responsePromise = clientResponsePromise.then((c) => + handleClientResponse(ipc, c) + ); + + // Now that both promises are in progress, we await both so that a + // rejection in either will end the routing. + const [response] = await Promise.all([responsePromise, routePromise]); + + server.close(); + return response; + } catch (e) { + // Server doesn't need to be closed, because the sendError will terminate + // the process. + ipc.sendError(e as Error); + } +} + +async function handleClientResponse( + _ipc: Ipc, + clientResponse: IncomingMessage +): Promise { + if (clientResponse.headers["x-nextjs-route-result"] === "1") { + clientResponse.setEncoding("utf8"); + // We're either a redirect or a rewrite + let buffer = ""; + for await (const chunk of clientResponse) { + buffer += chunk; + } + + const data = JSON.parse(buffer) as RouteResult; + + switch (data.type) { + case "none": + return { + type: "none", + }; + case "rewrite": + default: + return { + type: "rewrite", + data: { + url: data.url, + headers: Object.entries(data.headers), + }, + }; + } + } + + const responseHeaders: MiddlewareHeadersResponse = { + statusCode: clientResponse.statusCode!, + headers: toPairs(clientResponse.rawHeaders), + }; + + // TODO: support streaming middleware + // ipc.send({ + // type: "jsonValue", + // data: JSON.stringify({ + // type: "middleware-headers", + // data: responseHeaders, + // }), + // }); + // ipc.send({ + // type: "jsonValue", + // data: JSON.stringify({ + // type: "middleware-body", + // data: chunk as Buffer, + // }), + // }); + + const buffers = []; + for await (const chunk of clientResponse) { + buffers.push(chunk as Buffer); + } + return { + type: "full-middleware", + data: { + headers: responseHeaders, + body: Buffer.concat(buffers).toJSON().data, + }, + }; +} diff --git a/packages/next-swc/crates/next-core/js/src/entry/server-api.tsx b/packages/next-swc/crates/next-core/js/src/entry/server-api.tsx new file mode 100644 index 000000000000..12f0e79576a6 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/server-api.tsx @@ -0,0 +1,39 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import startHandler from "@vercel/turbopack-next/internal/api-server-handler"; + +import "next/dist/server/node-polyfill-fetch.js"; + +// @ts-expect-error INNER is provided by rust +import * as allExports from "INNER"; +import { apiResolver } from "next/dist/server/api-utils/node"; +import { + NodeNextRequest, + NodeNextResponse, +} from "next/dist/server/base-http/node"; +import { parse } from "node:querystring"; + +startHandler(({ request, response, query, params, path }) => { + const parsedQuery = parse(query); + + const mergedQuery = { ...parsedQuery, ...params }; + + // This enables `req.cookies` in API routes. + const req = new NodeNextRequest(request); + const res = new NodeNextResponse(response); + + return apiResolver( + req.originalRequest, + res.originalResponse, + mergedQuery, + allExports, + { + previewModeId: "", + previewModeEncryptionKey: "", + previewModeSigningKey: "", + }, + false, + true, + path + ); +}); diff --git a/packages/next-swc/crates/next-core/js/src/entry/server-data.tsx b/packages/next-swc/crates/next-core/js/src/entry/server-data.tsx new file mode 100644 index 000000000000..67ebcdeade10 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/server-data.tsx @@ -0,0 +1,17 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import startHandler from "@vercel/turbopack-next/internal/page-server-handler"; + +// eslint-disable-next-line +import Document from "next/document"; +import App from "next/app"; +// @ts-expect-error INNER is provided by rust +import * as otherExports from "INNER"; + +startHandler({ + isDataReq: true, + App, + Document, + Component: () => {}, + otherExports, +}); diff --git a/packages/next-swc/crates/next-core/js/src/entry/server-edge-api.tsx b/packages/next-swc/crates/next-core/js/src/entry/server-edge-api.tsx new file mode 100644 index 000000000000..d14825f9e863 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/server-edge-api.tsx @@ -0,0 +1,40 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import startHandler from "@vercel/turbopack-next/internal/api-server-handler"; +import { runEdgeFunction } from "@vercel/turbopack-next/internal/edge"; + +import { join } from "path"; + +import "next/dist/server/node-polyfill-fetch.js"; + +// @ts-expect-error INNER_EDGE_CHUNK_GROUP is provided by rust +import chunkGroup from "INNER_EDGE_CHUNK_GROUP"; + +import { + NodeNextRequest, + NodeNextResponse, +} from "next/dist/server/base-http/node"; + +startHandler(async ({ request, response, query, params, path }) => { + const edgeInfo = { + name: "edge", + paths: chunkGroup.map((chunk: string) => + join(process.cwd(), ".next/server/pages", chunk) + ), + wasm: [], + env: Object.keys(process.env), + assets: [], + }; + await runEdgeFunction({ + edgeInfo, + outputDir: "pages", + req: new NodeNextRequest(request), + res: new NodeNextResponse(response), + query, + params, + path, + onWarning(warning) { + console.warn(warning); + }, + }); +}); diff --git a/packages/next-swc/crates/next-core/js/src/entry/server-renderer.tsx b/packages/next-swc/crates/next-core/js/src/entry/server-renderer.tsx new file mode 100644 index 000000000000..6280bc6cc098 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/entry/server-renderer.tsx @@ -0,0 +1,21 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import startHandler from "@vercel/turbopack-next/internal/page-server-handler"; + +import App from "@vercel/turbopack-next/pages/_app"; +import Document from "@vercel/turbopack-next/pages/_document"; + +// @ts-expect-error INNER is provided by rust +import Component, * as otherExports from "INNER"; + +// @ts-expect-error INNER_CLIENT_CHUNK_GROUP is provided by rust +import chunkGroup from "INNER_CLIENT_CHUNK_GROUP"; + +startHandler({ + isDataReq: false, + App, + Document, + Component, + otherExports, + chunkGroup, +}); diff --git a/packages/next-swc/crates/next-core/js/src/internal/api-server-handler.ts b/packages/next-swc/crates/next-core/js/src/internal/api-server-handler.ts new file mode 100644 index 000000000000..70e38bec60df --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/internal/api-server-handler.ts @@ -0,0 +1,186 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import { IPC } from "@vercel/turbopack-next/ipc/index"; + +import type { RenderData } from "types/turbopack"; +import type { Ipc } from "@vercel/turbopack-next/ipc/index"; +import type { ClientRequest, IncomingMessage, Server } from "node:http"; +import type { ServerResponse } from "node:http"; +import { createServer, makeRequest } from "@vercel/turbopack-next/ipc/server"; +import { toPairs } from "@vercel/turbopack-next/internal/headers"; +import { Buffer } from "node:buffer"; + +const ipc = IPC as Ipc; + +type IpcIncomingMessage = + | { + type: "headers"; + data: RenderData; + } + | { + type: "bodyChunk"; + data: Array; + } + | { type: "bodyEnd" }; + +type IpcOutgoingMessage = + | { + type: "headers"; + data: ResponseHeaders; + } + | { + type: "body"; + data: Array; + }; + +type ResponseHeaders = { + status: number; + headers: [string, string][]; +}; + +type Handler = (data: { + request: IncomingMessage; + response: ServerResponse; + query: string; + params: Record; + path: string; +}) => Promise; + +type Operation = { + clientRequest: ClientRequest; + clientResponsePromise: Promise; + apiOperation: Promise; + server: Server; +}; + +export default function startHandler(handler: Handler): void { + (async () => { + while (true) { + let operationPromise: Promise | null = null; + + const msg = await ipc.recv(); + + switch (msg.type) { + case "headers": { + operationPromise = createOperation(msg.data); + break; + } + default: { + console.error("unexpected message type", msg.type); + process.exit(1); + } + } + + let body = Buffer.alloc(0); + let operation: Operation; + loop: while (true) { + const msg = await ipc.recv(); + + switch (msg.type) { + case "bodyChunk": { + body = Buffer.concat([body, Buffer.from(msg.data)]); + break; + } + case "bodyEnd": { + operation = await operationPromise; + break loop; + } + default: { + console.error("unexpected message type", msg.type); + process.exit(1); + } + } + } + + await Promise.all([ + endOperation(operation, body), + operation.clientResponsePromise.then((clientResponse) => + handleClientResponse(operation.server, clientResponse) + ), + ]); + } + })().catch((err) => { + ipc.sendError(err); + }); + + async function createOperation(renderData: RenderData): Promise { + const server = await createServer(); + + const { + clientRequest, + clientResponsePromise, + serverRequest, + serverResponse, + } = await makeRequest( + server, + renderData.method, + renderData.path, + renderData.rawQuery, + renderData.rawHeaders + ); + + return { + clientRequest, + server, + clientResponsePromise, + apiOperation: handler({ + request: serverRequest, + response: serverResponse, + query: renderData.rawQuery, + params: renderData.params, + path: renderData.path, + }), + }; + } + + function handleClientResponse( + server: Server, + clientResponse: IncomingMessage + ) { + const responseData: Buffer[] = []; + const responseHeaders: ResponseHeaders = { + status: clientResponse.statusCode!, + headers: toPairs(clientResponse.rawHeaders), + }; + + ipc.send({ + type: "headers", + data: responseHeaders, + }); + + clientResponse.on("data", (chunk) => { + responseData.push(chunk); + }); + + clientResponse.once("end", () => { + ipc.send({ + type: "body", + data: Buffer.concat(responseData).toJSON().data, + }); + server.close(); + }); + + clientResponse.once("error", (err) => { + ipc.sendError(err); + }); + } + + /** + * Ends an operation by writing the response body to the client and waiting for the Next.js API resolver to finish. + */ + async function endOperation(operation: Operation, body: Buffer) { + operation.clientRequest.end(body); + + try { + await operation.apiOperation; + } catch (error) { + if (error instanceof Error) { + await ipc.sendError(error); + } else { + await ipc.sendError(new Error("an unknown error occurred")); + } + + return; + } + } +} diff --git a/packages/next-swc/crates/next-core/js/src/internal/edge.ts b/packages/next-swc/crates/next-core/js/src/internal/edge.ts new file mode 100644 index 000000000000..a1016d1714cb --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/internal/edge.ts @@ -0,0 +1,142 @@ +import { join } from "path"; + +import type { + BaseNextRequest, + BaseNextResponse, +} from "next/dist/server/base-http"; +import type { + NodeNextRequest, + NodeNextResponse, +} from "next/dist/server/base-http/node"; +import { parse, ParsedUrlQuery } from "querystring"; +import type { Params } from "next/dist/shared/lib/router/utils/route-matcher"; +import { FetchEventResult } from "next/dist/server/web/types"; +import { getCloneableBody } from "next/dist/server/body-streams"; + +// This is an adapted version of a similar function in next-dev-server. +// TODO exposes this method from next.js instead +export async function runEdgeFunction({ + edgeInfo, + outputDir, + req, + res, + query, + params, + path, + onWarning, +}: { + edgeInfo: { + name: string; + paths: string[]; + wasm: unknown[]; + env: unknown[]; + assets: unknown[]; + }; + outputDir: string; + req: BaseNextRequest | NodeNextRequest; + res: BaseNextResponse | NodeNextResponse; + query: string; + path: string; + params: Params | undefined; + onWarning?: (warning: Error) => void; +}): Promise { + // For edge to "fetch" we must always provide an absolute URL + const initialUrl = new URL(path, "http://n"); + const parsedQuery = parse(query); + const queryString = urlQueryToSearchParams({ + ...Object.fromEntries(initialUrl.searchParams), + ...parsedQuery, + }).toString(); + + initialUrl.search = queryString; + const url = initialUrl.toString(); + + if (!url.startsWith("http")) { + throw new Error( + "To use middleware you must provide a `hostname` and `port` to the Next.js Server" + ); + } + + const { run } = require("next/dist/server/web/sandbox"); + const result = (await run({ + distDir: join(process.cwd(), ".next/server", outputDir), + name: edgeInfo.name, + paths: edgeInfo.paths, + env: edgeInfo.env, + edgeFunctionEntry: edgeInfo, + request: { + headers: req.headers, + method: req.method, + nextConfig: { + basePath: "/", + i18n: undefined, + trailingSlash: true, + }, + url, + page: { + name: path, + ...(params && { params: params }), + }, + body: getCloneableBody(req.body), + }, + useCache: false, + onWarning, + })) as FetchEventResult; + + res.statusCode = result.response.status; + res.statusMessage = result.response.statusText; + + result.response.headers.forEach((value: string, key) => { + // the append handling is special cased for `set-cookie` + if (key.toLowerCase() === "set-cookie") { + res.setHeader(key, value); + } else { + res.appendHeader(key, value); + } + }); + + if (result.response.body) { + // TODO(gal): not sure that we always need to stream + const nodeResStream = (res as NodeNextResponse).originalResponse; + const { + consumeUint8ArrayReadableStream, + } = require("next/dist/compiled/edge-runtime"); + try { + for await (const chunk of consumeUint8ArrayReadableStream( + result.response.body + )) { + nodeResStream.write(chunk); + } + } finally { + nodeResStream.end(); + } + } else { + (res as NodeNextResponse).originalResponse.end(); + } + + return result; +} + +function stringifyUrlQueryParam(param: unknown): string { + if ( + typeof param === "string" || + (typeof param === "number" && !isNaN(param)) || + typeof param === "boolean" + ) { + return String(param); + } else { + return ""; + } +} + +function urlQueryToSearchParams(urlQuery: ParsedUrlQuery): URLSearchParams { + const result = new URLSearchParams(); + Object.entries(urlQuery).forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach((item) => result.append(key, stringifyUrlQueryParam(item))); + } else { + result.set(key, stringifyUrlQueryParam(value)); + } + }); + return result; +} diff --git a/packages/next-swc/crates/next-core/js/src/internal/headers.ts b/packages/next-swc/crates/next-core/js/src/internal/headers.ts new file mode 100644 index 000000000000..5243fdb93421 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/internal/headers.ts @@ -0,0 +1,43 @@ +/** + * Converts an array of raw header entries to a map of header names to values. + */ +export function headersFromEntries( + entries: Array<[string, string]> +): Record { + const headers: Record = Object.create(null); + for (const [key, value] of entries) { + if (key in headers) { + const prevValue = headers[key]; + if (typeof prevValue === "string") { + headers[key] = [prevValue, value]; + } else { + prevValue.push(value); + } + } else { + headers[key] = value; + } + } + return headers; +} + +/** + * Transforms an array of elements into an array of pairs of elements. + * + * ## Example + * + * ```ts + * toPairs(["a", "b", "c", "d"]) // => [["a", "b"], ["c", "d"]] + * ``` + */ +export function toPairs(arr: T[]): Array<[T, T]> { + if (arr.length % 2 !== 0) { + throw new Error("toPairs: expected an even number of elements"); + } + + const pairs: Array<[T, T]> = []; + for (let i = 0; i < arr.length; i += 2) { + pairs.push([arr[i], arr[i + 1]]); + } + + return pairs; +} diff --git a/packages/next-swc/crates/next-core/js/src/internal/http.ts b/packages/next-swc/crates/next-core/js/src/internal/http.ts new file mode 100644 index 000000000000..0346b8458fc6 --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/internal/http.ts @@ -0,0 +1,114 @@ +import type { IncomingMessage, ServerResponse } from "node:http"; + +/** + * Shim for Node.js's http.ServerResponse + * + * @type {ServerResponse} + */ +export class ServerResponseShim { + headersSent = false; + #headers: Map> = new Map(); + #statusCode: number = 200; + req: IncomingMessage; + + constructor(req: IncomingMessage) { + this.req = req; + } + + setHeader(name: string, value: number | string | ReadonlyArray) { + this.#headers.set(name.toLowerCase(), value); + return this; + } + + getHeader(name: string) { + return this.#headers.get(name.toLowerCase()); + } + + getHeaderNames() { + return Array.from(this.#headers.keys()); + } + + getHeaders() { + return Object.fromEntries(this.#headers); + } + + hasHeader(name: string) { + return this.#headers.has(name.toLowerCase()); + } + + removeHeader(name: string) { + this.#headers.delete(name.toLowerCase()); + } + + get statusCode() { + return this.#statusCode; + } + + set statusCode(code) { + this.#statusCode = code; + } + + get statusMessage() { + throw new Error("statusMessage is not implemented"); + } + + set statusMessage(message) { + throw new Error("set statusMessage is not implemented"); + } + + get socket() { + throw new Error("socket is not implemented"); + } + + get sendDate() { + throw new Error("sendDate is not implemented"); + } + + flushHeaders() { + throw new Error("flushHeaders is not implemented"); + } + + end() { + throw new Error("end is not implemented"); + } + + cork() { + throw new Error("cork is not implemented"); + } + + uncork() { + throw new Error("uncork is not implemented"); + } + + addTrailers() { + throw new Error("addTrailers is not implemented"); + } + + setTimeout(_msecs: any, _callback: any) { + throw new Error("setTimeout is not implemented"); + } + + get writableEnded() { + throw new Error("writableEnded is not implemented"); + } + + get writableFinished() { + throw new Error("writableFinished is not implemented"); + } + + write(_chunk: any, _encoding: any, _callback: any) { + throw new Error("write is not implemented"); + } + + writeContinue() { + throw new Error("writeContinue is not implemented"); + } + + writeHead(_statusCode: any, _statusMessage: any, _headers: any) { + throw new Error("writeHead is not implemented"); + } + + writeProcessing() { + throw new Error("writeProcessing is not implemented"); + } +} diff --git a/packages/next-swc/crates/next-core/js/src/internal/page-server-handler.tsx b/packages/next-swc/crates/next-core/js/src/internal/page-server-handler.tsx new file mode 100644 index 000000000000..fb085568d5ea --- /dev/null +++ b/packages/next-swc/crates/next-core/js/src/internal/page-server-handler.tsx @@ -0,0 +1,383 @@ +// IPC need to be the first import to allow it to catch errors happening during +// the other imports +import { IPC } from "@vercel/turbopack-next/ipc/index"; + +import "next/dist/server/node-polyfill-fetch.js"; +import "@vercel/turbopack-next/internal/shims"; + +import type { IncomingMessage, ServerResponse } from "node:http"; + +import { renderToHTML, RenderOpts } from "next/dist/server/render"; +import { getRedirectStatus } from "next/dist/lib/redirect-status"; +import { PERMANENT_REDIRECT_STATUS } from "next/dist/shared/lib/constants"; +import { buildStaticPaths } from "next/dist/build/utils"; +import type { BuildManifest } from "next/dist/server/get-page-files"; +import type { ReactLoadableManifest } from "next/dist/server/load-components"; + +import { ServerResponseShim } from "@vercel/turbopack-next/internal/http"; +import { headersFromEntries } from "@vercel/turbopack-next/internal/headers"; +import type { Ipc } from "@vercel/turbopack-next/ipc/index"; +import type { RenderData } from "types/turbopack"; +import type { ChunkGroup } from "types/next"; +import { parse } from "node:querystring"; + +const ipc = IPC as Ipc; + +type IpcIncomingMessage = { + type: "headers"; + data: RenderData; +}; + +type IpcOutgoingMessage = + | { + type: "response"; + statusCode: number; + headers: Array<[string, string]>; + body: string; + } + | { type: "rewrite"; path: string }; + +const MIME_APPLICATION_JAVASCRIPT = "application/javascript"; +const MIME_TEXT_HTML_UTF8 = "text/html; charset=utf-8"; + +export default function startHandler({ + isDataReq, + App, + Document, + Component, + otherExports, + chunkGroup, +}: { + isDataReq: boolean; + App?: any; + Document?: any; + Component?: any; + otherExports: any; + chunkGroup?: ChunkGroup; +}) { + (async () => { + while (true) { + const msg = await ipc.recv(); + + let renderData: RenderData; + switch (msg.type) { + case "headers": { + renderData = msg.data; + break; + } + default: { + console.error("unexpected message type", msg.type); + process.exit(1); + } + } + + const res = await runOperation(renderData); + + ipc.send(res); + } + })().catch((err) => { + ipc.sendError(err); + }); + + async function runOperation( + renderData: RenderData + ): Promise { + if ("getStaticPaths" in otherExports) { + const { + paths: prerenderRoutes, + fallback: prerenderFallback, + encodedPaths: _encodedPrerenderRoutes, + } = await buildStaticPaths({ + page: renderData.path, + getStaticPaths: otherExports.getStaticPaths, + // TODO(alexkirsz) Provide the correct next.config.js path. + configFileName: "next.config.js", + }); + + // We provide a dummy base URL to the URL constructor so that it doesn't + // throw when we pass a relative URL. + let resolvedPath = new URL(renderData.url, "next://").pathname; + if (isDataReq) { + // we still want to match data requests so we remove the prefix and extension + // to get back the path the page would have + resolvedPath = resolvedPath.replace( + /^\/_next\/data\/development(.+).json$/, + "$1" + ); + } + if ( + prerenderFallback === false && + // TODO(alexkirsz) Strip basePath. + !prerenderRoutes.includes(resolvedPath) + ) { + return createNotFoundResponse(isDataReq); + } + } + + // TODO(alexkirsz) This is missing *a lot* of data, but it's enough to get a + // basic render working. + + const buildManifest: BuildManifest = { + pages: { + // TODO(alexkirsz) We should separate _app and page chunks. Right now, we + // computing the chunk items of `next-hydrate.js`, so they contain both + // _app and page chunks. + "/_app": [], + [renderData.path]: chunkGroup || [], + }, + + devFiles: [], + ampDevFiles: [], + polyfillFiles: [], + lowPriorityFiles: ["static/development/_buildManifest.js"], + rootMainFiles: [], + ampFirstPages: [], + }; + + // When rendering a data request, the default component export is eliminated + // by the Next.js strip export transform. The following checks for this case + // and replaces the default export with a dummy component instead. + const comp = + typeof Component === "undefined" || + (typeof Component === "object" && Object.keys(Component).length === 0) + ? () => {} + : Component; + + const renderOpts: RenderOpts = { + /* LoadComponentsReturnType */ + Component: comp, + App, + Document, + pageConfig: {}, + buildManifest, + reactLoadableManifest: createReactLoadableManifestProxy(), + ComponentMod: { + default: comp, + ...otherExports, + }, + pathname: renderData.path, + buildId: "development", + + /* RenderOptsPartial */ + isDataReq, + runtimeConfig: {}, + assetPrefix: "", + canonicalBase: "", + previewProps: { + previewModeId: "", + previewModeEncryptionKey: "", + previewModeSigningKey: "", + }, + params: renderData.params, + basePath: "", + // TODO(WEB-583) this isn't correct, instead it should set `dev: true` + nextExport: true, + resolvedUrl: renderData.url, + optimizeFonts: false, + optimizeCss: false, + nextScriptWorkers: false, + images: { + deviceSizes: [], + imageSizes: [], + loader: "default", + path: "", + loaderFile: "", + domains: [], + disableStaticImages: false, + minimumCacheTTL: 0, + formats: [], + dangerouslyAllowSVG: false, + contentSecurityPolicy: "", + remotePatterns: [], + unoptimized: true, + }, + }; + + if ("getStaticPaths" in otherExports) { + renderOpts.getStaticPaths = otherExports.getStaticPaths; + } + if ("getStaticProps" in otherExports) { + renderOpts.getStaticProps = otherExports.getStaticProps; + } + if ("getServerSideProps" in otherExports) { + renderOpts.getServerSideProps = otherExports.getServerSideProps; + } + + const req: IncomingMessage = { + url: renderData.url, + method: "GET", + headers: headersFromEntries(renderData.rawHeaders), + } as any; + const res: ServerResponse = new ServerResponseShim(req) as any; + + // Both _error and 404 should receive a 404 status code. + const statusCode = + renderData.path === "/404" + ? 404 + : renderData.path === "/_error" + ? 404 + : 200; + + // Setting the status code on the response object is necessary for + // `Error.getInitialProps` to detect the status code. + res.statusCode = statusCode; + + const parsedQuery = parse(renderData.rawQuery); + const query = { ...parsedQuery, ...renderData.params }; + + const renderResult = await renderToHTML( + /* req: IncomingMessage */ + req, + /* res: ServerResponse */ + res, + /* pathname: string */ + renderData.path, + /* query: ParsedUrlQuery */ + query, + /* renderOpts: RenderOpts */ + renderOpts + ); + + // Set when `getStaticProps` returns `notFound: true`. + const isNotFound = (renderOpts as any).isNotFound; + + if (isNotFound) { + return createNotFoundResponse(isDataReq); + } + + // Set when `getStaticProps` returns `redirect: { destination, permanent, statusCode }`. + const isRedirect = (renderOpts as any).isRedirect; + + if (isRedirect && !isDataReq) { + const pageProps = (renderOpts as any).pageData.pageProps; + const redirect = { + destination: pageProps.__N_REDIRECT, + statusCode: pageProps.__N_REDIRECT_STATUS, + basePath: pageProps.__N_REDIRECT_BASE_PATH, + }; + const statusCode = getRedirectStatus(redirect); + + // TODO(alexkirsz) Handle basePath. + // if ( + // basePath && + // redirect.basePath !== false && + // redirect.destination.startsWith("/") + // ) { + // redirect.destination = `${basePath}${redirect.destination}`; + // } + + const headers: Array<[string, string]> = [ + ["Location", redirect.destination], + ]; + if (statusCode === PERMANENT_REDIRECT_STATUS) { + headers.push(["Refresh", `0;url=${redirect.destination}`]); + } + + return { + type: "response", + statusCode, + headers, + body: redirect.destination, + }; + } + + if (isDataReq) { + // TODO(from next.js): change this to a different passing mechanism + const pageData = (renderOpts as any).pageData; + return { + type: "response", + statusCode, + headers: [["Content-Type", MIME_APPLICATION_JAVASCRIPT]], + // Page data is only returned if the page had getXxyProps. + body: JSON.stringify(pageData === undefined ? {} : pageData), + }; + } + + if (!renderResult) { + throw new Error("no render result returned"); + } + + const body = renderResult.toUnchunkedString(); + + // TODO: handle revalidate + // const sprRevalidate = (renderOpts as any).revalidate; + + return { + type: "response", + statusCode, + headers: [ + ["Content-Type", renderResult.contentType() ?? MIME_TEXT_HTML_UTF8], + ], + body, + }; + } +} + +function createNotFoundResponse(isDataReq: boolean): IpcOutgoingMessage { + if (isDataReq) { + return { + type: "response", + // Returning a 404 status code is required for the client-side router + // to redirect to the error page. + statusCode: 404, + body: '{"notFound":true}', + headers: [["Content-Type", MIME_APPLICATION_JAVASCRIPT]], + }; + } + + return { + type: "rewrite", + // /_next/404 is a Turbopack-internal route that will always redirect to + // the 404 page. + path: "/_next/404", + }; +} + +type ManifestItem = { + id: string; + chunks: string[]; +}; + +/** + * During compilation, Next.js builds a manifest of dynamic imports with the + * `ReactLoadablePlugin` for webpack. + * + * At the same time, the next/dynamic transform converts each `dynamic()` call + * so it contains a key to the corresponding entry within that manifest. + * + * During server-side rendering, each `dynamic()` call will be recorded and its + * corresponding entry in the manifest will be looked up. + * * The entry's chunks will be asynchronously loaded on the client using a + *