From 1c903b7905e8c5151f403ffeb4c4609cdb514758 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 30 Aug 2022 21:13:18 +0800 Subject: [PATCH] Upgrade next-swc-napi to NAPI-RS v2 --- .github/workflows/build_test_deploy.yml | 2 +- packages/next-swc/Cargo.lock | 242 +++--------------- packages/next-swc/crates/napi/Cargo.toml | 45 ++-- .../next-swc/crates/napi/src/bundle/mod.rs | 211 --------------- packages/next-swc/crates/napi/src/lib.rs | 55 +--- packages/next-swc/crates/napi/src/minify.rs | 48 ++-- packages/next-swc/crates/napi/src/parse.rs | 46 ++-- .../next-swc/crates/napi/src/transform.rs | 123 +++++---- packages/next-swc/crates/napi/src/util.rs | 150 +++-------- packages/next-swc/package.json | 6 +- packages/next/build/swc/index.d.ts | 1 - packages/next/build/swc/index.js | 9 - packages/next/package.json | 2 +- pnpm-lock.yaml | 12 +- 14 files changed, 226 insertions(+), 726 deletions(-) delete mode 100644 packages/next-swc/crates/napi/src/bundle/mod.rs diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 37b71a4632f0a..05fb710eb0e6d 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -7,7 +7,7 @@ on: name: Build, test, and deploy env: - NAPI_CLI_VERSION: 2.7.0 + NAPI_CLI_VERSION: 2.11.4 TURBO_VERSION: 1.3.2-canary.1 RUST_TOOLCHAIN: nightly-2022-02-23 PNPM_VERSION: 7.2.1 diff --git a/packages/next-swc/Cargo.lock b/packages/next-swc/Cargo.lock index 52433026a0685..d64cffdfd67ed 100644 --- a/packages/next-swc/Cargo.lock +++ b/packages/next-swc/Cargo.lock @@ -349,22 +349,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - [[package]] name = "corosensei" version = "0.1.2" @@ -750,21 +734,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -1056,19 +1025,6 @@ dependencies = [ "tokio-rustls", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -1502,55 +1458,59 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "napi" -version = "1.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5586ff59e18f42d41f68139a8ca72ef1dbcc243ec62c5696e6383169a8a05a4" +checksum = "0e2f9ad803cde148d81d0ca9e5fd4d80773d15e992d09e3a44f62f41b9af4558" dependencies = [ + "bitflags", + "ctor", "napi-sys", + "once_cell", "serde", "serde_json", - "winapi", + "thread_local", ] [[package]] name = "napi-build" -version = "1.2.1" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd4419172727423cf30351406c54f6cc1b354a2cfb4f1dba3e6cd07f6d5522b" +checksum = "882a73d9ef23e8dc2ebbffb6a6ae2ef467c0f18ac10711e4cc59c5485d41df0e" [[package]] name = "napi-derive" -version = "1.1.2" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee880798e942fc785e2e234544b9db578019a1d7676f45dad7f38d432ab0fe4" +checksum = "1be75210f300e9fbf386ccac1c8eaaed23410e2f7f7aa9295b78c436a172ef51" dependencies = [ + "convert_case", + "napi-derive-backend", "proc-macro2", "quote", "syn", ] [[package]] -name = "napi-sys" -version = "1.1.2" +name = "napi-derive-backend" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf20e0081fea04e044aa4adf74cfea8ddc0324eec2894b1c700f4cafc72a56" +checksum = "92ba4800264fac8a7726b208d5dd4c6d637d1027d73b026061a69d3339a0a930" +dependencies = [ + "convert_case", + "once_cell", + "proc-macro2", + "quote", + "regex", + "syn", +] [[package]] -name = "native-tls" -version = "0.2.10" +name = "napi-sys" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "529671ebfae679f2ce9630b62dd53c72c56b3eb8b2c852e7e2fa91704ff93d67" dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "libloading", ] [[package]] @@ -1733,51 +1693,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "openssl" -version = "0.10.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "ordered-float" version = "2.10.0" @@ -1987,12 +1902,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - [[package]] name = "pmutil" version = "0.5.3" @@ -2285,13 +2194,11 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", - "hyper-tls", "ipnet", "js-sys", "lazy_static", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", "rustls", @@ -2300,7 +2207,6 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", - "tokio-native-tls", "tokio-rustls", "tower-service", "url", @@ -2429,16 +2335,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" -dependencies = [ - "lazy_static", - "windows-sys 0.36.1", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -2467,29 +2363,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "security-framework" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2976,6 +2849,8 @@ dependencies = [ "indexmap", "json_comments", "lru", + "napi", + "napi-derive", "once_cell", "parking_lot", "pathdiff", @@ -4153,16 +4028,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.23.4" @@ -4397,12 +4262,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -4950,19 +4809,6 @@ dependencies = [ "windows_x86_64_msvc 0.33.0", ] -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows_aarch64_msvc" version = "0.32.0" @@ -4975,12 +4821,6 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_i686_gnu" version = "0.32.0" @@ -4993,12 +4833,6 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_msvc" version = "0.32.0" @@ -5011,12 +4845,6 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_x86_64_gnu" version = "0.32.0" @@ -5029,12 +4857,6 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_msvc" version = "0.32.0" @@ -5047,12 +4869,6 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "winreg" version = "0.10.1" diff --git a/packages/next-swc/crates/napi/Cargo.toml b/packages/next-swc/crates/napi/Cargo.toml index e05340a4034fe..266e149c6c534 100644 --- a/packages/next-swc/crates/napi/Cargo.toml +++ b/packages/next-swc/crates/napi/Cargo.toml @@ -1,8 +1,8 @@ [package] edition = "2018" name = "next-swc-napi" -version = "0.0.0" publish = false +version = "0.0.0" [lib] crate-type = ["cdylib", "rlib"] @@ -18,49 +18,56 @@ plugin = [ "swc_plugin_runner/default", "wasmer/default", "wasmer-wasi/default", - "next-swc/plugin" + "next-swc/plugin", ] -sentry_native_tls = ["_sentry_native_tls"] -sentry_rustls = ["_sentry_rustls"] +crash-report = ["sentry"] [dependencies] anyhow = "1.0" backtrace = "0.3" fxhash = "0.2.1" -napi = {version = "1", features = ["serde-json"]} -napi-derive = "1" -next-swc = {version = "0.0.0", path = "../core"} +napi = { version = "2", default-features = false, features = [ + "napi3", + "serde-json", +] } +napi-derive = { version = "2", default-features = false } +next-swc = { version = "0.0.0", path = "../core" } once_cell = "1.13.0" serde = "1" serde_json = "1" -swc = "0.214.9" +swc = { version = "0.214.9", features = ["node"] } swc_atoms = "0.4.8" swc_bundler = { version = "0.177.4", features = ["concurrent"] } swc_common = { version = "0.27.11", features = ["concurrent", "sourcemap"] } swc_ecma_loader = { version = "0.39.4", features = ["node", "lru"] } -swc_ecmascript = { version = "0.189.4", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] } -swc_plugin_runner = { version = "0.71.15", optional = true } +swc_ecmascript = { version = "0.189.4", features = [ + "codegen", + "minifier", + "optimization", + "parser", + "react", + "transforms", + "typescript", + "utils", + "visit", +] } swc_node_base = "0.5.5" +swc_plugin_runner = { version = "0.71.15", optional = true } tracing = { version = "0.1.32", features = ["release_max_level_info"] } +tracing-chrome = "0.5.0" tracing-futures = "0.2.5" tracing-subscriber = "0.3.9" -tracing-chrome = "0.5.0" wasmer = { version = "2.3.0", optional = true, default-features = false } wasmer-wasi = { version = "2.3.0", optional = true, default-features = false } -# There are few build targets we can't use native-tls which default features rely on, -# allow to specify alternative (rustls) instead via features. -# Note to opt in rustls default-features should be disabled -# (--no-default-features --features sentry_rustls) -_sentry_native_tls = { package = "sentry", version = "0.27.0", optional = true } -_sentry_rustls = { package = "sentry", version = "0.27.0", default-features = false, features = [ +sentry = { version = "0.27.0", default-features = false, features = [ "backtrace", "contexts", "panic", "rustls", - "reqwest" + "reqwest", ], optional = true } [build-dependencies] -napi-build = "1" +napi-build = "2" serde = "1" serde_json = "1" diff --git a/packages/next-swc/crates/napi/src/bundle/mod.rs b/packages/next-swc/crates/napi/src/bundle/mod.rs deleted file mode 100644 index a573002efb046..0000000000000 --- a/packages/next-swc/crates/napi/src/bundle/mod.rs +++ /dev/null @@ -1,211 +0,0 @@ -use crate::{ - complete_output, get_compiler, - util::{CtxtExt, MapErr}, -}; -use anyhow::{anyhow, bail, Context, Error}; -use napi::{CallContext, JsObject, Task}; -use once_cell::sync::Lazy; -use serde::Deserialize; -use std::{collections::HashMap, path::PathBuf, sync::Arc}; -use swc::{config::SourceMapsConfig, try_with_handler, TransformOutput}; -use swc_atoms::JsWord; -use swc_bundler::{Bundler, ModuleData, ModuleRecord}; -use swc_common::{ - collections::AHashMap, - errors::{ColorConfig, Handler}, - BytePos, FileName, SourceMap, Span, -}; -use swc_ecma_loader::{ - resolvers::{lru::CachingResolver, node::NodeModulesResolver}, - TargetEnv, NODE_BUILTINS, -}; -use swc_ecmascript::{ - ast::*, - parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax}, - visit::{noop_visit_type, Visit, VisitWith}, -}; - -#[js_function(1)] -pub fn bundle(cx: CallContext) -> napi::Result { - let option = cx.get_buffer_as_string(0)?; - - let task = BundleTask { - c: get_compiler(&cx), - config: option, - }; - - cx.env.spawn(task).map(|t| t.promise_object()) -} - -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields, rename_all = "camelCase")] -struct BundleOption { - entry: PathBuf, -} - -struct BundleTask { - c: Arc, - config: String, -} - -impl Task for BundleTask { - type Output = TransformOutput; - - type JsValue = JsObject; - - fn compute(&mut self) -> napi::Result { - let option: BundleOption = crate::util::deserialize_json(&self.config).convert_err()?; - - try_with_handler( - self.c.cm.clone(), - swc::HandlerOpts { - color: ColorConfig::Never, - skip_filename: true, - }, - |handler| { - let builtins = NODE_BUILTINS - .iter() - .copied() - .map(JsWord::from) - .collect::>(); - - let comments = self.c.comments().clone(); - // - let mut bundler = Bundler::new( - self.c.globals(), - self.c.cm.clone(), - CustomLoader { - cm: self.c.cm.clone(), - handler, - }, - make_resolver(), - swc_bundler::Config { - require: true, - disable_inliner: false, - external_modules: builtins, - module: swc_bundler::ModuleType::Es, - ..Default::default() - }, - Box::new(CustomHook), - ); - - let mut entries = HashMap::default(); - let path: PathBuf = option.entry; - let path = path - .canonicalize() - .context("failed to canonicalize entry file")?; - entries.insert("main".to_string(), FileName::Real(path)); - let outputs = bundler.bundle(entries)?; - - let output = outputs - .into_iter() - .next() - .ok_or_else(|| anyhow!("swc_bundler::Bundle::bundle returned empty result"))?; - - let source_map_names = { - let mut v = SourceMapIdentCollector { - names: Default::default(), - }; - - output.module.visit_with(&mut v); - - v.names - }; - - let code = self.c.print( - &output.module, - None, - None, - true, - EsVersion::Es5, - SourceMapsConfig::Bool(true), - &source_map_names, - None, - false, - Some(&comments), - true, - false, - )?; - - Ok(code) - }, - ) - .convert_err() - } - - fn resolve(self, env: napi::Env, output: Self::Output) -> napi::Result { - complete_output(&env, output, Default::default()) - } -} - -type Resolver = Arc>; - -fn make_resolver() -> Resolver { - static CACHE: Lazy = Lazy::new(|| { - // TODO: Make target env and alias configurable - let r = NodeModulesResolver::new(TargetEnv::Node, Default::default(), true); - let r = CachingResolver::new(256, r); - Arc::new(r) - }); - - (*CACHE).clone() -} - -struct CustomLoader<'a> { - handler: &'a Handler, - cm: Arc, -} - -impl swc_bundler::Load for CustomLoader<'_> { - fn load(&self, f: &FileName) -> Result { - let fm = match f { - FileName::Real(path) => self.cm.load_file(path)?, - _ => unreachable!(), - }; - - let lexer = Lexer::new( - Syntax::Es(EsConfig { - ..Default::default() - }), - EsVersion::Es2020, - StringInput::from(&*fm), - None, - ); - - let mut parser = Parser::new_from(lexer); - let module = parser.parse_module().map_err(|err| { - err.into_diagnostic(self.handler).emit(); - anyhow!("failed to parse") - })?; - - Ok(ModuleData { - fm, - module, - helpers: Default::default(), - }) - } -} - -struct CustomHook; - -impl swc_bundler::Hook for CustomHook { - fn get_import_meta_props( - &self, - _span: Span, - _module_record: &ModuleRecord, - ) -> Result, Error> { - bail!("`import.meta` is not supported yet") - } -} - -pub struct SourceMapIdentCollector { - names: AHashMap, -} - -impl Visit for SourceMapIdentCollector { - noop_visit_type!(); - - fn visit_ident(&mut self, ident: &Ident) { - self.names.insert(ident.span.lo, ident.sym.clone()); - } -} diff --git a/packages/next-swc/crates/napi/src/lib.rs b/packages/next-swc/crates/napi/src/lib.rs index e102cfbe7365e..0187613af5426 100644 --- a/packages/next-swc/crates/napi/src/lib.rs +++ b/packages/next-swc/crates/napi/src/lib.rs @@ -34,18 +34,18 @@ extern crate napi_derive; /// Explicit extern crate to use allocator. extern crate swc_node_base; +use std::{env, panic::set_hook, sync::Arc}; + use backtrace::Backtrace; use fxhash::FxHashSet; -use napi::{CallContext, Env, JsObject, JsUndefined}; -use std::{env, panic::set_hook, sync::Arc}; +use napi::bindgen_prelude::*; use swc::{Compiler, TransformOutput}; use swc_common::{self, sync::Lazy, FilePathMapping, SourceMap}; -mod bundle; -mod minify; -mod parse; -mod transform; -mod util; +pub mod minify; +pub mod parse; +pub mod transform; +pub mod util; static COMPILER: Lazy> = Lazy::new(|| { let cm = Arc::new(SourceMap::new(FilePathMapping::empty())); @@ -53,53 +53,26 @@ static COMPILER: Lazy> = Lazy::new(|| { Arc::new(Compiler::new(cm)) }); -#[module_exports] -fn init(mut exports: JsObject) -> napi::Result<()> { +#[napi::module_init] +fn init() { if cfg!(debug_assertions) || env::var("SWC_DEBUG").unwrap_or_default() == "1" { set_hook(Box::new(|panic_info| { let backtrace = Backtrace::new(); println!("Panic: {:?}\nBacktrace: {:?}", panic_info, backtrace); })); } - - exports.create_named_method("bundle", bundle::bundle)?; - - exports.create_named_method("transform", transform::transform)?; - exports.create_named_method("transformSync", transform::transform_sync)?; - - exports.create_named_method("minify", minify::minify)?; - exports.create_named_method("minifySync", minify::minify_sync)?; - - exports.create_named_method("parse", parse::parse)?; - - exports.create_named_method("getTargetTriple", util::get_target_triple)?; - exports.create_named_method( - "initCustomTraceSubscriber", - util::init_custom_trace_subscriber, - )?; - exports.create_named_method("teardownTraceSubscriber", util::teardown_trace_subscriber)?; - - exports.create_named_method("initCrashReporter", util::init_crash_reporter)?; - exports.create_named_method("teardownCrashReporter", util::teardown_crash_reporter)?; - - Ok(()) } -fn get_compiler(_ctx: &CallContext) -> Arc { +#[inline] +fn get_compiler() -> Arc { COMPILER.clone() } -#[js_function] -fn construct_compiler(ctx: CallContext) -> napi::Result { - // TODO: Assign swc::Compiler - ctx.env.get_undefined() -} - pub fn complete_output( env: &Env, output: TransformOutput, eliminated_packages: FxHashSet, -) -> napi::Result { +) -> napi::Result { let mut js_output = env.create_object()?; js_output.set_named_property("code", env.create_string_from_std(output.code)?)?; if let Some(map) = output.map { @@ -108,9 +81,7 @@ pub fn complete_output( if !eliminated_packages.is_empty() { js_output.set_named_property( "eliminatedPackages", - env.create_string_from_std(serde_json::to_string( - &eliminated_packages.into_iter().collect::>(), - )?)?, + env.create_string_from_std(serde_json::to_string(&eliminated_packages)?)?, )?; } Ok(js_output) diff --git a/packages/next-swc/crates/napi/src/minify.rs b/packages/next-swc/crates/napi/src/minify.rs index 042373c653899..0446bae4ff529 100644 --- a/packages/next-swc/crates/napi/src/minify.rs +++ b/packages/next-swc/crates/napi/src/minify.rs @@ -25,18 +25,15 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use crate::{ - complete_output, get_compiler, - util::{CtxtExt, MapErr}, -}; +use crate::{get_compiler, util::MapErr}; use fxhash::FxHashMap; -use napi::{CallContext, JsObject, Task}; +use napi::bindgen_prelude::*; use serde::Deserialize; use std::sync::Arc; use swc::{config::JsMinifyOptions, try_with_handler, TransformOutput}; use swc_common::{errors::ColorConfig, sync::Lrc, FileName, SourceFile, SourceMap}; -struct MinifyTask { +pub struct MinifyTask { c: Arc, code: MinifyTarget, opts: swc::config::JsMinifyOptions, @@ -70,10 +67,11 @@ impl MinifyTarget { } } +#[napi] impl Task for MinifyTask { type Output = TransformOutput; - type JsValue = JsObject; + type JsValue = TransformOutput; fn compute(&mut self) -> napi::Result { try_with_handler( @@ -97,33 +95,37 @@ impl Task for MinifyTask { .convert_err() } - fn resolve(self, env: napi::Env, output: Self::Output) -> napi::Result { - complete_output(&env, output, Default::default()) + fn resolve(&mut self, _: napi::Env, output: Self::Output) -> napi::Result { + Ok(output) } } -#[js_function(2)] -pub fn minify(cx: CallContext) -> napi::Result { - let code = cx.get_deserialized(0)?; - let opts = cx.get_deserialized(1)?; +#[napi] +pub fn minify( + input: Buffer, + opts: Buffer, + signal: Option, +) -> napi::Result> { + let code = serde_json::from_slice(&input)?; + let opts = serde_json::from_slice(&opts)?; - let c = get_compiler(&cx); + let c = get_compiler(); let task = MinifyTask { c, code, opts }; - cx.env.spawn(task).map(|t| t.promise_object()) + Ok(AsyncTask::with_optional_signal(task, signal)) } -#[js_function(2)] -pub fn minify_sync(cx: CallContext) -> napi::Result { - let code: MinifyTarget = cx.get_deserialized(0)?; - let opts = cx.get_deserialized(1)?; +#[napi] +pub fn minify_sync(input: Buffer, opts: Buffer) -> napi::Result { + let code: MinifyTarget = serde_json::from_slice(&input)?; + let opts = serde_json::from_slice(&opts)?; - let c = get_compiler(&cx); + let c = get_compiler(); let fm = code.to_file(c.cm.clone()); - let output = try_with_handler( + try_with_handler( c.cm.clone(), swc::HandlerOpts { color: ColorConfig::Never, @@ -131,7 +133,5 @@ pub fn minify_sync(cx: CallContext) -> napi::Result { }, |handler| c.minify(fm, handler, &opts), ) - .convert_err()?; - - complete_output(cx.env, output, Default::default()) + .convert_err() } diff --git a/packages/next-swc/crates/napi/src/parse.rs b/packages/next-swc/crates/napi/src/parse.rs index 3210443953e05..565e04205e9d1 100644 --- a/packages/next-swc/crates/napi/src/parse.rs +++ b/packages/next-swc/crates/napi/src/parse.rs @@ -1,6 +1,6 @@ -use crate::util::{deserialize_json, CtxtExt, MapErr}; +use crate::util::MapErr; use anyhow::Context as _; -use napi::{CallContext, Either, Env, JsObject, JsString, JsUndefined, Task}; +use napi::bindgen_prelude::*; use std::sync::Arc; use swc::{config::ParseOptions, try_with_handler}; use swc_common::{comments::Comments, errors::ColorConfig, FileName, FilePathMapping, SourceMap}; @@ -8,21 +8,18 @@ use swc_common::{comments::Comments, errors::ColorConfig, FileName, FilePathMapp pub struct ParseTask { pub filename: FileName, pub src: String, - pub options: String, -} - -pub fn complete_parse(env: &Env, ast_json: String) -> napi::Result { - env.create_string_from_std(ast_json) + pub options: Buffer, } +#[napi] impl Task for ParseTask { type Output = String; - type JsValue = JsString; + type JsValue = String; fn compute(&mut self) -> napi::Result { let c = swc::Compiler::new(Arc::new(SourceMap::new(FilePathMapping::empty()))); - let options: ParseOptions = deserialize_json(&self.options).convert_err()?; + let options: ParseOptions = serde_json::from_slice(&self.options)?; let comments = c.comments().clone(); let comments: Option<&dyn Comments> = if options.comments { Some(&comments) @@ -57,27 +54,26 @@ impl Task for ParseTask { Ok(ast_json) } - fn resolve(self, env: Env, result: Self::Output) -> napi::Result { - complete_parse(&env, result) + fn resolve(&mut self, _: Env, result: Self::Output) -> napi::Result { + Ok(result) } } -#[js_function(3)] -pub fn parse(ctx: CallContext) -> napi::Result { - let src = ctx.get::(0)?.into_utf8()?.as_str()?.to_string(); - let options = ctx.get_buffer_as_string(1)?; - let filename = ctx.get::>(2)?; - let filename = if let Either::A(value) = filename { - FileName::Real(value.into_utf8()?.as_str()?.to_owned().into()) +#[napi] +pub fn parse( + src: String, + options: Buffer, + filename: Option, +) -> napi::Result> { + let filename = if let Some(value) = filename { + FileName::Real(value.into()) } else { FileName::Anon }; - ctx.env - .spawn(ParseTask { - filename, - src, - options, - }) - .map(|t| t.promise_object()) + Ok(AsyncTask::new(ParseTask { + filename, + src, + options, + })) } diff --git a/packages/next-swc/crates/napi/src/transform.rs b/packages/next-swc/crates/napi/src/transform.rs index ad97c0ed1b57f..6b993a230b326 100644 --- a/packages/next-swc/crates/napi/src/transform.rs +++ b/packages/next-swc/crates/napi/src/transform.rs @@ -26,22 +26,20 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use crate::{ - complete_output, get_compiler, - util::{deserialize_json, CtxtExt, MapErr}, -}; -use anyhow::{anyhow, bail, Context as _}; -use fxhash::FxHashSet; -use napi::{CallContext, Env, JsBoolean, JsBuffer, JsObject, JsString, JsUnknown, Status, Task}; -use next_swc::{custom_before_pass, TransformOptions}; -use std::fs::read_to_string; use std::{ cell::RefCell, - convert::TryFrom, + fs::read_to_string, + mem, panic::{catch_unwind, AssertUnwindSafe}, rc::Rc, sync::Arc, }; + +use crate::{complete_output, get_compiler, util::MapErr}; +use anyhow::{anyhow, bail, Context as _}; +use fxhash::FxHashSet; +use napi::bindgen_prelude::*; +use next_swc::{custom_before_pass, TransformOptions}; use swc::{try_with_handler, Compiler, TransformOutput}; use swc_common::{errors::ColorConfig, FileName}; use swc_ecmascript::transforms::pass::noop; @@ -55,18 +53,26 @@ pub enum Input { FromFilename, } +impl Default for Input { + fn default() -> Self { + Self::FromFilename + } +} + pub struct TransformTask { pub c: Arc, pub input: Input, - pub options: String, + pub options: Buffer, } +#[napi] impl Task for TransformTask { type Output = (TransformOutput, FxHashSet); - type JsValue = JsObject; + type JsValue = Object; fn compute(&mut self) -> napi::Result { let eliminated_packages: Rc>> = Default::default(); + let input = mem::take(&mut self.input); let res = catch_unwind(AssertUnwindSafe(|| { try_with_handler( self.c.cm.clone(), @@ -76,8 +82,8 @@ impl Task for TransformTask { }, |handler| { self.c.run(|| { - let options: TransformOptions = deserialize_json(&self.options)?; - let fm = match &self.input { + let options: TransformOptions = serde_json::from_slice(&self.options)?; + let fm = match input { Input::Source { src } => { let filename = if options.swc.filename.is_empty() { FileName::Anon @@ -85,7 +91,7 @@ impl Task for TransformTask { FileName::Real(options.swc.filename.clone().into()) }; - self.c.cm.new_source_file(filename, src.to_string()) + self.c.cm.new_source_file(filename, src) } Input::FromFilename => { let filename = &options.swc.filename; @@ -146,7 +152,7 @@ impl Task for TransformTask { } fn resolve( - self, + &mut self, env: Env, (output, eliminated_packages): Self::Output, ) -> napi::Result { @@ -154,56 +160,47 @@ impl Task for TransformTask { } } -/// returns `compiler, (src / path), options, plugin, callback` -pub fn schedule_transform(cx: &CallContext, op: F) -> napi::Result -where - F: FnOnce(&Arc, Input, bool, String) -> TransformTask, -{ - let c = get_compiler(cx); - - let unknown_src = cx.get::(0)?; - let src = match unknown_src.get_type()? { - napi::ValueType::String => napi::Result::Ok(Input::Source { - src: JsString::try_from(unknown_src)? - .into_utf8()? - .as_str()? - .to_owned(), - }), - napi::ValueType::Object => napi::Result::Ok(Input::Source { - src: String::from_utf8_lossy(JsBuffer::try_from(unknown_src)?.into_value()?.as_ref()) - .to_string(), - }), - napi::ValueType::Undefined => napi::Result::Ok(Input::FromFilename), - _ => Err(napi::Error::new( - Status::GenericFailure, - "first argument must be a String or Buffer".to_string(), - )), - }?; - let is_module = cx.get::(1)?; - let options = cx.get_buffer_as_string(2)?; - - Ok(op(&c, src, is_module.get_value()?, options)) -} - -#[js_function(4)] -pub fn transform(cx: CallContext) -> napi::Result { - let task = schedule_transform(&cx, |c, input, _, options| TransformTask { - c: c.clone(), - input, - options, - })?; - cx.env.spawn(task).map(|handle| handle.promise_object()) +#[napi] +pub fn transform( + src: Either3, + _is_module: bool, + options: Buffer, + signal: Option, +) -> napi::Result> { + let c = get_compiler(); + + let input = match src { + Either3::A(src) => Input::Source { src }, + Either3::B(src) => Input::Source { + src: String::from_utf8_lossy(&src).to_string(), + }, + Either3::C(_) => Input::FromFilename, + }; + + let task = TransformTask { c, input, options }; + Ok(AsyncTask::with_optional_signal(task, signal)) } -#[js_function(4)] -pub fn transform_sync(cx: CallContext) -> napi::Result { - let mut task = schedule_transform(&cx, |c, input, _, options| TransformTask { - c: c.clone(), - input, - options, - })?; +#[napi] +pub fn transform_sync( + env: Env, + src: Either3, + _is_module: bool, + options: Buffer, +) -> napi::Result { + let c = get_compiler(); + + let input = match src { + Either3::A(src) => Input::Source { src }, + Either3::B(src) => Input::Source { + src: String::from_utf8_lossy(&src).to_string(), + }, + Either3::C(_) => Input::FromFilename, + }; + + let mut task = TransformTask { c, input, options }; let output = task.compute()?; - task.resolve(*cx.env, output) + task.resolve(env, output) } #[test] diff --git a/packages/next-swc/crates/napi/src/util.rs b/packages/next-swc/crates/napi/src/util.rs index c416dc8ed901b..6fb3a3f85b092 100644 --- a/packages/next-swc/crates/napi/src/util.rs +++ b/packages/next-swc/crates/napi/src/util.rs @@ -26,10 +26,12 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use anyhow::{anyhow, Context, Error}; -use napi::{CallContext, Env, JsBuffer, JsExternal, JsString, JsUndefined, JsUnknown, Status}; -use serde::de::DeserializeOwned; -use std::{any::type_name, cell::RefCell, convert::TryFrom, env, path::PathBuf}; +use std::{cell::RefCell, env, path::PathBuf}; + +use anyhow::anyhow; +use napi::bindgen_prelude::{External, Status}; +#[cfg(feature = "crash-report")] +use sentry::{init, types::Dsn, ClientInitGuard, ClientOptions}; use tracing_chrome::{ChromeLayerBuilder, FlushGuard}; use tracing_subscriber::{filter, prelude::*, util::SubscriberInitExt, Layer}; @@ -37,9 +39,9 @@ static TARGET_TRIPLE: &str = include_str!(concat!(env!("OUT_DIR"), "/triple.txt" #[allow(unused)] static PACKAGE_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/package.txt")); -#[contextless_function] -pub fn get_target_triple(env: Env) -> napi::ContextlessResult { - env.create_string(TARGET_TRIPLE).map(Some) +#[napi] +pub fn get_target_triple() -> String { + TARGET_TRIPLE.to_owned() } pub trait MapErr: Into> { @@ -51,63 +53,13 @@ pub trait MapErr: Into> { impl MapErr for Result {} -pub trait CtxtExt { - fn get_buffer_as_string(&self, index: usize) -> napi::Result; - /// Currently this uses JsBuffer - fn get_deserialized(&self, index: usize) -> napi::Result - where - T: DeserializeOwned; -} - -impl CtxtExt for CallContext<'_> { - fn get_buffer_as_string(&self, index: usize) -> napi::Result { - let buffer = self.get::(index)?.into_value()?; - - Ok(String::from_utf8_lossy(buffer.as_ref()).to_string()) - } - - fn get_deserialized(&self, index: usize) -> napi::Result - where - T: DeserializeOwned, - { - let buffer = self.get::(index)?.into_value()?; - let v = serde_json::from_slice(&buffer) - .with_context(|| { - format!( - "Failed to deserialize argument at `{}` as {}\nJSON: {}", - index, - type_name::(), - String::from_utf8_lossy(&buffer) - ) - }) - .convert_err()?; - - Ok(v) - } -} - -pub(crate) fn deserialize_json(s: &str) -> Result -where - T: DeserializeOwned, -{ - serde_json::from_str(s) - .with_context(|| format!("failed to deserialize as {}\nJSON: {}", type_name::(), s)) -} - /// Initialize tracing subscriber to emit traces. This configures subscribers /// for Trace Event Format (https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview). -#[js_function(1)] -pub fn init_custom_trace_subscriber(cx: CallContext) -> napi::Result { - let optional_trace_out_file_path = cx.get::(0)?; - let trace_out_file_path = match optional_trace_out_file_path.get_type()? { - napi::ValueType::String => Some(PathBuf::from( - JsString::try_from(optional_trace_out_file_path)? - .into_utf8()? - .as_str()? - .to_owned(), - )), - _ => None, - }; +#[napi] +pub fn init_custom_trace_subscriber( + trace_out_file_path: Option, +) -> napi::Result>>> { + let trace_out_file_path = trace_out_file_path.map(PathBuf::from); let mut layer = ChromeLayerBuilder::new().include_args(true); if let Some(trace_out_file) = trace_out_file_path { @@ -129,57 +81,47 @@ pub fn init_custom_trace_subscriber(cx: CallContext) -> napi::Result .expect("Failed to register tracing subscriber"); let guard_cell = RefCell::new(Some(guard)); - cx.env.create_external(guard_cell, None) + Ok(External::new(guard_cell)) } /// Teardown currently running tracing subscriber to flush out remaining traces. /// This should be called when parent node.js process exits, otherwise generated /// trace may drop traces in the buffer. -#[js_function(1)] -pub fn teardown_trace_subscriber(cx: CallContext) -> napi::Result { - let guard_external = cx.get::(0)?; - let guard_cell = &*cx - .env - .get_value_external::>>(&guard_external)?; +#[napi] +pub fn teardown_trace_subscriber(guard_external: External>>) { + let guard_cell = &*guard_external; if let Some(guard) = guard_cell.take() { drop(guard); } - cx.env.get_undefined() } -#[cfg(any( - target_arch = "wasm32", +#[cfg(all( all(target_os = "windows", target_arch = "aarch64"), - not(all(feature = "sentry_native_tls", feature = "sentry_rustls")) + feature = "crash-report" ))] -#[js_function(1)] -pub fn init_crash_reporter(cx: CallContext) -> napi::Result { +#[napi] +pub fn init_crash_reporter() -> External>> { let guard: Option = None; let guard_cell = RefCell::new(guard); - cx.env.create_external(guard_cell, None) + External::new(guard_cell) } /// Initialize crash reporter to collect unexpected native next-swc crashes. #[cfg(all( - not(target_arch = "wasm32"), not(all(target_os = "windows", target_arch = "aarch64")), - any(feature = "sentry_native_tls", feature = "sentry_rustls") + feature = "crash-report" ))] -#[js_function(1)] -pub fn init_crash_reporter(cx: CallContext) -> napi::Result { +#[napi] +pub fn init_crash_reporter() -> External>> { + use std::{borrow::Cow, str::FromStr}; + // Attempts to follow https://nextjs.org/telemetry's debug behavior. // However, this is techinically not identical to the behavior of the telemetry // itself as sentry's debug option does not provides full payuload output. let debug = env::var("NEXT_TELEMETRY_DEBUG").map_or_else(|_| false, |v| v == "1"); let guard = { - #[cfg(feature = "sentry_native_tls")] - use _sentry_native_tls::{init, types::Dsn, ClientOptions}; - #[cfg(feature = "sentry_rustls")] - use _sentry_rustls::{init, types::Dsn, ClientOptions}; - use std::{borrow::Cow, str::FromStr}; - let dsn = if debug { None } else { @@ -201,42 +143,34 @@ pub fn init_crash_reporter(cx: CallContext) -> napi::Result { }; let guard_cell = RefCell::new(guard); - cx.env.create_external(guard_cell, None) + External::new(guard_cell) } -#[cfg(any( - target_arch = "wasm32", +#[cfg(all( all(target_os = "windows", target_arch = "aarch64"), - not(all(feature = "sentry_native_tls", feature = "sentry_rustls")) + feature = "crash-report" ))] -#[js_function(1)] -pub fn teardown_crash_reporter(cx: CallContext) -> napi::Result { - cx.env.get_undefined() +#[napi] +pub fn teardown_crash_reporter(guard_external: External>>) { + let guard_cell = &*guard_external; + + if let Some(guard) = guard_cell.take() { + drop(guard); + } } /// Trying to drop crash reporter guard if exists. This is the way to hold /// guards to not to be dropped immediately after crash reporter is initialized /// in napi context. #[cfg(all( - not(target_arch = "wasm32"), not(all(target_os = "windows", target_arch = "aarch64")), - any(feature = "sentry_native_tls", feature = "sentry_rustls") + feature = "crash-report" ))] -#[js_function(1)] -pub fn teardown_crash_reporter(cx: CallContext) -> napi::Result { - #[cfg(feature = "sentry_native_tls")] - use _sentry_native_tls::ClientInitGuard; - #[cfg(feature = "sentry_rustls")] - use _sentry_rustls::ClientInitGuard; - - let guard_external = cx.get::(0)?; - let guard_cell = &*cx - .env - .get_value_external::>>(&guard_external)?; +#[napi] +pub fn teardown_crash_reporter(guard_external: External>>) { + let guard_cell = &*guard_external; if let Some(guard) = guard_cell.take() { drop(guard); } - - cx.env.get_undefined() } diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index 68abb3a5a023f..9609641669840 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -3,8 +3,8 @@ "version": "12.2.6-canary.6", "private": true, "scripts": { - "build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi native --features plugin", - "build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi native", + "build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --features plugin --js false native", + "build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --js false native", "build-wasm": "wasm-pack build crates/wasm --scope=next" }, "napi": { @@ -26,6 +26,6 @@ } }, "devDependencies": { - "@napi-rs/cli": "2.7.0" + "@napi-rs/cli": "2.11.4" } } diff --git a/packages/next/build/swc/index.d.ts b/packages/next/build/swc/index.d.ts index c1993f93823fd..8427a91168cac 100644 --- a/packages/next/build/swc/index.d.ts +++ b/packages/next/build/swc/index.d.ts @@ -3,7 +3,6 @@ export function transform(src: string, options?: any): Promise export function transformSync(src: string, options?: any): any export function minify(src: string, options: any): Promise export function minifySync(src: string, options: any): string -export function bundle(options: any): Promise export function parse(src: string, options: any): any export const lockfilePatchPromise: { cur?: Promise } export function initCustomTraceSubscriber(traceFileName?: string): void diff --git a/packages/next/build/swc/index.js b/packages/next/build/swc/index.js index bbc60d0c06c5c..4f55cde98453d 100644 --- a/packages/next/build/swc/index.js +++ b/packages/next/build/swc/index.js @@ -325,10 +325,6 @@ function loadNative() { return bindings.minifySync(toBuffer(src), toBuffer(options ?? {})) }, - bundle(options) { - return bindings.bundle(toBuffer(options)) - }, - parse(src, options) { return bindings.parse(src, toBuffer(options ?? {})) }, @@ -373,11 +369,6 @@ export function minifySync(src, options) { return bindings.minifySync(src, options) } -export async function bundle(options) { - let bindings = loadBindingsSync() - return bindings.bundle(toBuffer(options)) -} - export async function parse(src, options) { let bindings = await loadBindings() let parserOptions = getParserOptions(options) diff --git a/packages/next/package.json b/packages/next/package.json index 35cb97df563f0..67fdd81b3ae29 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -119,7 +119,7 @@ "@babel/types": "7.18.0", "@edge-runtime/primitives": "1.1.0-beta.31", "@hapi/accept": "5.0.2", - "@napi-rs/cli": "2.7.0", + "@napi-rs/cli": "2.11.4", "@napi-rs/triples": "1.1.0", "@next/polyfill-module": "12.2.6-canary.6", "@next/polyfill-nomodule": "12.2.6-canary.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6458115474091..edcdf57723c61 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -417,7 +417,7 @@ importers: '@babel/types': 7.18.0 '@edge-runtime/primitives': 1.1.0-beta.31 '@hapi/accept': 5.0.2 - '@napi-rs/cli': 2.7.0 + '@napi-rs/cli': 2.11.4 '@napi-rs/triples': 1.1.0 '@next/env': 12.2.6-canary.6 '@next/polyfill-module': 12.2.6-canary.6 @@ -610,7 +610,7 @@ importers: '@babel/types': 7.18.0 '@edge-runtime/primitives': 1.1.0-beta.31 '@hapi/accept': 5.0.2 - '@napi-rs/cli': 2.7.0 + '@napi-rs/cli': 2.11.4 '@napi-rs/triples': 1.1.0 '@next/polyfill-module': link:../next-polyfill-module '@next/polyfill-nomodule': link:../next-polyfill-nomodule @@ -834,9 +834,9 @@ importers: packages/next-swc: specifiers: - '@napi-rs/cli': 2.7.0 + '@napi-rs/cli': 2.11.4 devDependencies: - '@napi-rs/cli': 2.7.0 + '@napi-rs/cli': 2.11.4 packages/react-dev-overlay: specifiers: @@ -5682,10 +5682,10 @@ packages: glob-to-regexp: 0.3.0 dev: true - /@napi-rs/cli/2.7.0: + /@napi-rs/cli/2.11.4: resolution: { - integrity: sha512-bQb+r9/xW8LFRbpEN7A/4fX8LnEWbI0JzyOzXGDpO+cI8dXRxX7OPySOpzT2nBgP1brA2Ydkw/t9lyxLN9TlxQ==, + integrity: sha512-rjU651owB4GJetO3pnu3B8TyVM3Fis3AYb+U16bKxYyykp81S+dJlIgWc8Lc0t55PYbHlBM3hxdgy4pultxMAw==, } engines: { node: '>= 10' } hasBin: true