From 40e8d078238e5b7b32642b7515cd649678ebb104 Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Sun, 28 May 2023 19:05:13 -0700 Subject: [PATCH] Add import.meta.url polyfill to refresh setup --- bindings/Cargo.lock | 142 +++--------------- .../src/refresh_setup/mod.rs | 21 ++- .../src/refresh_setup/tests.rs | 10 +- node-swc/__tests__/transform/reflame_test.mjs | 79 ++++++++++ node-swc/src/binding.js | 15 ++ 5 files changed, 145 insertions(+), 122 deletions(-) create mode 100644 node-swc/__tests__/transform/reflame_test.mjs diff --git a/bindings/Cargo.lock b/bindings/Cargo.lock index 0bdfd26da2fd..31ba562a1874 100644 --- a/bindings/Cargo.lock +++ b/bindings/Cargo.lock @@ -84,8 +84,6 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "ast_node" version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c704e2f6ee1a98223f5a7629a6ef0f3decb3b552ed282889dc957edff98ce1e6" dependencies = [ "pmutil", "proc-macro2", @@ -227,9 +225,7 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.50.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9306930a934635b3c9121118a46728d600f82f07687568be0016e83d9faa0080" +version = "0.50.27" dependencies = [ "anyhow", "console_error_panic_hook", @@ -950,8 +946,6 @@ dependencies = [ [[package]] name = "from_variant" version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d449976075322384507443937df2f1d5577afbf4282f12a5a66ef29fa3e6307" dependencies = [ "pmutil", "proc-macro2", @@ -2002,8 +1996,6 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "preset_env_base" version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a48d8ea8b031bde7755cdf6f87f7123a0cbefc36b0cd09cbb2de726594393" dependencies = [ "ahash", "anyhow", @@ -2745,8 +2737,6 @@ dependencies = [ [[package]] name = "string_enum" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0090512bdfee4b56d82480d66c0fd8a6f53f0fe0f97e075e949b252acdd482e0" dependencies = [ "pmutil", "proc-macro2", @@ -2797,9 +2787,7 @@ dependencies = [ [[package]] name = "swc" -version = "0.261.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab85534089a63d8aebf48acae90e2712bec6872571fb58489751460fe983561" +version = "0.261.27" dependencies = [ "ahash", "anyhow", @@ -2850,8 +2838,6 @@ dependencies = [ [[package]] name = "swc_atoms" version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d0307dc4bfd107d49c7528350c372758cfca94fb503629b9a056e6a1572860" dependencies = [ "bytecheck", "once_cell", @@ -2865,9 +2851,7 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.214.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4e83459d305955cae138398edc536ad0b445b1bc4dc116f0e0504b9b7904db3" +version = "0.214.21" dependencies = [ "ahash", "anyhow", @@ -2933,8 +2917,6 @@ dependencies = [ [[package]] name = "swc_common" version = "0.31.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20fd4a53e21f2fd0c184a6391b505eacafa1e1b596ff1199abf723107c9c24f7" dependencies = [ "ahash", "anyhow", @@ -2965,8 +2947,6 @@ dependencies = [ [[package]] name = "swc_config" version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89c8fc2c12bb1634c7c32fc3c9b6b963ad8f034cc62c4ecddcf215dc4f6f959d" dependencies = [ "indexmap", "serde", @@ -2977,8 +2957,6 @@ dependencies = [ [[package]] name = "swc_config_macro" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dadb9998d4f5fc36ef558ed5a092579441579ee8c6fcce84a5228cca9df4004" dependencies = [ "pmutil", "proc-macro2", @@ -2989,9 +2967,7 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.76.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53402c0ece866b780dba00812c3a25febb141613d4147891bca3341b075c3e6" +version = "0.76.32" dependencies = [ "binding_macros", "swc", @@ -3014,8 +2990,6 @@ dependencies = [ [[package]] name = "swc_ecma_ast" version = "0.104.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed057aa0db9150059f2129175970c6f54249fa6fe877c31073923e554906e9b5" dependencies = [ "bitflags 2.2.1", "bytecheck", @@ -3032,9 +3006,7 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.139.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0032cbef4536b713d01665892359ee985032bd933867bc866748ecee0dd35b2d" +version = "0.139.13" dependencies = [ "memchr", "num-bigint", @@ -3052,8 +3024,6 @@ dependencies = [ [[package]] name = "swc_ecma_codegen_macros" version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ee0caee1018808d94ecd09490cb7affd3d504b19aa11c49238f5fc4b54901" dependencies = [ "pmutil", "proc-macro2", @@ -3064,9 +3034,7 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.103.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "018d1d2c466470596f1fdb76e0aeb5cff14ab30951e72deae49a722494cb2656" +version = "0.103.12" dependencies = [ "phf", "swc_atoms", @@ -3078,9 +3046,7 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.82.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ff2f68f60bbef3d83e3427bc18d4625bd0a263299274b0bb2caac3667ee8b81" +version = "0.82.14" dependencies = [ "ahash", "auto_impl", @@ -3100,8 +3066,6 @@ dependencies = [ [[package]] name = "swc_ecma_loader" version = "0.43.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace7885cc24831a0fd5fbbb1651682297f33a6ac6ec03278a3beb0af35a0bd59" dependencies = [ "ahash", "anyhow", @@ -3121,9 +3085,7 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.181.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c382d06a398169344a3829ea95f7938d808fd806648ccfc2fc6498276c8ca09" +version = "0.181.21" dependencies = [ "ahash", "arrayvec", @@ -3157,9 +3119,7 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.134.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02b8f9f999ef048c079b2b8de9a720d14f9c0ecbd4f9064d425001b83e974" +version = "0.134.11" dependencies = [ "either", "lexical", @@ -3177,9 +3137,7 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.195.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb290ae8fade76b1bd1e848017a949130a8d10b2ed1ec88cfd331f4d501c733a" +version = "0.195.19" dependencies = [ "ahash", "anyhow", @@ -3202,7 +3160,7 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.34.1" +version = "0.45.11" dependencies = [ "anyhow", "pmutil", @@ -3213,14 +3171,12 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn", + "syn 1.0.109", ] [[package]] name = "swc_ecma_transforms" -version = "0.218.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b12c993e94b2448a90e813fe4cafe34277543d7167e222576e7a4800fc357079" +version = "0.218.18" dependencies = [ "swc_atoms", "swc_common", @@ -3238,9 +3194,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.127.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66b08ab71c274cb9e858603e062ee67d3c6df9b79319b9a3bb6071cc7c220b6" +version = "0.127.14" dependencies = [ "better_scoped_tls", "bitflags 2.2.1", @@ -3262,9 +3216,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.116.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f6971a416594a1ab6c0bbba1474c35b5de322defc57f76b72c7d52998248c1" +version = "0.116.14" dependencies = [ "swc_atoms", "swc_common", @@ -3276,9 +3228,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.153.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "430a53a5e2e991a902e76bbb19c7599060eb008d9fd190b2e626d1408189c5c3" +version = "0.153.16" dependencies = [ "ahash", "arrayvec", @@ -3304,8 +3254,6 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_macros" version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984d5ac69b681fc5438f9abf82b0fda34fe04e119bc75f8213b7e01128c7c9a2" dependencies = [ "pmutil", "proc-macro2", @@ -3316,9 +3264,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.170.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bf9691fa404080c462b59e06f32102dd680fafe4ce4f4924d11c76fb078af2" +version = "0.170.16" dependencies = [ "Inflector", "ahash", @@ -3344,9 +3290,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.187.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001238051117ad172b06d9125aad6e6d0dba967e3263e7f78f5e06ef6c41ddbc" +version = "0.187.18" dependencies = [ "ahash", "dashmap", @@ -3370,9 +3314,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.161.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9b3fa1a6afb7a9f6a26f592a7422703f465047cd2ddd2f6ebfd9ec20cc1e980" +version = "0.161.18" dependencies = [ "either", "rustc-hash", @@ -3390,9 +3332,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.173.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2ac277729eb47163d70db82f3f58d91e469141fe3804a9ada36c233cc5a3cc8" +version = "0.173.16" dependencies = [ "ahash", "base64 0.13.1", @@ -3417,9 +3357,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.177.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98fcfbcf4e1a189567518a2733c74cec5073b29df1e22454cde17d0959c5e195" +version = "0.177.18" dependencies = [ "serde", "swc_atoms", @@ -3433,9 +3371,7 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.13.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b83869ba5db9c5720b4dc7b5f5badc7d3e01738e117ee541f537de15c3e64367" +version = "0.13.14" dependencies = [ "ahash", "indexmap", @@ -3451,9 +3387,7 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.117.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27af37cc5c6054b8b32fd572bd539748ff9818a473a2477d2c96cf4f6bcb4be" +version = "0.117.12" dependencies = [ "indexmap", "num_cpus", @@ -3471,8 +3405,6 @@ dependencies = [ [[package]] name = "swc_ecma_visit" version = "0.90.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "580203f0f520e9fbb0a8eed6bf841e7513b2c4fc64113c2144c80a7150170778" dependencies = [ "num-bigint", "swc_atoms", @@ -3495,8 +3427,6 @@ dependencies = [ [[package]] name = "swc_error_reporters" version = "0.15.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40447c9a45f005713fd7471e212e06283f29a97ecd330b515f2813f6bc2c52a1" dependencies = [ "anyhow", "miette", @@ -3508,8 +3438,6 @@ dependencies = [ [[package]] name = "swc_fast_graph" version = "0.19.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8028a7ce23426f6afd2c49a36ab6220d34f358527dadad163ed5847b32d9c76" dependencies = [ "indexmap", "petgraph", @@ -3520,8 +3448,6 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" version = "0.20.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13a666f025c1a9ee99cc267043006fc631a555cd3c0441cfec21552ababd4f5" dependencies = [ "ahash", "auto_impl", @@ -3533,8 +3459,6 @@ dependencies = [ [[package]] name = "swc_macros_common" version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e582c3e3c2269238524923781df5be49e011dbe29cf7683a2215d600a562ea6" dependencies = [ "pmutil", "proc-macro2", @@ -3552,9 +3476,7 @@ dependencies = [ [[package]] name = "swc_node_bundler" -version = "0.48.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "131d9e445f9cddbf324f8a04aeadc91827308f8b894769f4eee0f01773701efe" +version = "0.48.27" dependencies = [ "anyhow", "dashmap", @@ -3582,8 +3504,6 @@ dependencies = [ [[package]] name = "swc_node_comments" version = "0.18.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5773506ea76f6a1b8282078a2a4e8d437a8ef522193923649d87155ae7e676b" dependencies = [ "ahash", "dashmap", @@ -3594,8 +3514,6 @@ dependencies = [ [[package]] name = "swc_nodejs_common" version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c405e950d345754892691ec2bd30482592672f79db90188392d069a829d3b3ff" dependencies = [ "anyhow", "napi", @@ -3608,8 +3526,6 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" version = "0.33.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27580f5f062e1eda0dfebefd33403eace8bae46f1175c21b02a25318c2b0dd7b" dependencies = [ "better_scoped_tls", "rkyv", @@ -3621,9 +3537,7 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "0.95.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41749c8034202c7db341edde22211dc5fa76fe5d7b5c5f86dc7f1b571cc333f7" +version = "0.95.14" dependencies = [ "anyhow", "enumset", @@ -3644,8 +3558,6 @@ dependencies = [ [[package]] name = "swc_timer" version = "0.19.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ead4ffe0e69ac6a7aa7014e1b1ddd47da05ec4330787bf4a0cbcdae43e0538" dependencies = [ "tracing", ] @@ -3662,8 +3574,6 @@ dependencies = [ [[package]] name = "swc_visit" version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f412dd4fbc58f509a04e64f5c8038333142fc139e8232f01b883db0094b3b51" dependencies = [ "either", "swc_visit_macros", @@ -3672,8 +3582,6 @@ dependencies = [ [[package]] name = "swc_visit_macros" version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cfc226380ba54a5feed2c12f3ccd33f1ae8e959160290e5d2d9b4e918b6472a" dependencies = [ "Inflector", "pmutil", diff --git a/crates/swc_ecma_transforms_react/src/refresh_setup/mod.rs b/crates/swc_ecma_transforms_react/src/refresh_setup/mod.rs index 7acf8a7f5b3b..e00f05ddea62 100644 --- a/crates/swc_ecma_transforms_react/src/refresh_setup/mod.rs +++ b/crates/swc_ecma_transforms_react/src/refresh_setup/mod.rs @@ -1,11 +1,14 @@ use serde::{Deserialize, Deserializer, Serialize}; +use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_quote_macros::internal_quote; use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith}; #[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] -pub struct RefreshSetupOptions {} +pub struct RefreshSetupOptions { + pub pathname: Option, +} #[derive(Deserialize)] #[serde(untagged)] @@ -32,14 +35,14 @@ mod tests; pub fn refresh_setup(dev: bool, options: Option) -> impl Fold + VisitMut { as_folder(RefreshSetup { enable: dev && options.is_some(), - // options: options.unwrap_or_default(), + options: options.unwrap_or_default(), }) } #[derive(Clone)] struct RefreshSetup { enable: bool, - // options: RefreshSetupOptions, + options: RefreshSetupOptions, } impl VisitMut for RefreshSetup { @@ -53,9 +56,21 @@ impl VisitMut for RefreshSetup { module_items.visit_mut_children_with(self); + let pathname = match &self.options.pathname { + Some(_) => self.options.pathname.as_ref().unwrap(), + None => { + panic!("wrong pathname") + } + }; + // Intuitively this feels like it should be faster than individual .inserts // TODO: benchmark if doing individual inserts makes a difference? let statements_before = [ + ModuleItem::Stmt(internal_quote!( + r#" + import.meta.url = new URL($pathname, location.origin)"# as Stmt, + pathname = Ident::new(format!("\"{pathname}\"",).into(), DUMMY_SP), + )), ModuleItem::Stmt(internal_quote!( r#" const $reflamePathname = new URL(import.meta.url).pathname"# as Stmt diff --git a/crates/swc_ecma_transforms_react/src/refresh_setup/tests.rs b/crates/swc_ecma_transforms_react/src/refresh_setup/tests.rs index a7a8ce1a1e28..0a1e8b4ad604 100644 --- a/crates/swc_ecma_transforms_react/src/refresh_setup/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh_setup/tests.rs @@ -7,7 +7,12 @@ test!( jsx: true, ..Default::default() }), - |_| refresh_setup(true, Some(RefreshSetupOptions {}),), + |_| refresh_setup( + true, + Some(RefreshSetupOptions { + pathname: Some("/hi.js".into()), + }), + ), basic_sample, // Input codes r#" @@ -19,6 +24,7 @@ export const blah = 1234 "#, // Output codes after transformed with plugin r#" +import.meta.url = new URL("/hi.js", location.origin) const $reflamePathname = new URL(import.meta.url).pathname const $reflamePreviousRefreshReg = self.$RefreshReg$ const $reflamePreviousRefreshSig = self.$RefreshSig$ @@ -57,7 +63,7 @@ test!( jsx: true, ..Default::default() }), - |_| refresh_setup(false, Some(RefreshSetupOptions {}),), + |_| refresh_setup(false, None,), disabled, // Input codes r#" diff --git a/node-swc/__tests__/transform/reflame_test.mjs b/node-swc/__tests__/transform/reflame_test.mjs new file mode 100644 index 000000000000..870714cdb722 --- /dev/null +++ b/node-swc/__tests__/transform/reflame_test.mjs @@ -0,0 +1,79 @@ +import swc from "../../.."; + +it("should support refreshSetup option", async () => { + const { code } = await swc.transform( + `import '../blah.ts' + +export const Test = () => { + return
Test
+} +`, + { + module: { + type: 'es6' + }, + filename: 'index.tsx', + jsc: { + target: "es2022", + parser: { + syntax: 'typescript', + tsx: true, + dynamicImport: true, + }, + transform: { + react: { + runtime: 'automatic', + throwIfNamespace: true, + development: true, + useBuiltins: true, + refresh: true, + refreshSetup: { + pathname: '/test/index.ts' + }, + // refresh: { + // // refreshReg: String; + // // refreshSig: String; + // // emitFullSignatures: boolean; + // }, + }, + } + } + } + ); + expect(code).toEqual(`import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime"; +import.meta.url = new URL("/test/index.ts", location.origin); +const $reflamePathname = new URL(import.meta.url).pathname; +const $reflamePreviousRefreshReg = self.$RefreshReg$; +const $reflamePreviousRefreshSig = self.$RefreshSig$; +self.$RefreshReg$ = (type, id)=>{ + const fullId = $reflamePathname + \` \${id}\`; + self.$reflame.reactRefreshRuntime.register(type, fullId); +}; +self.$RefreshSig$ = self.$reflame.reactRefreshRuntime.createSignatureFunctionForTransform; +import '../blah.ts'; +export const Test = ()=>{ + return /*#__PURE__*/ _jsxDEV("div", { + children: "Test" + }, void 0, false, { + fileName: "index.tsx", + lineNumber: 4, + columnNumber: 10 + }, this); +}; +_c = Test; +var _c; +$RefreshReg$(_c, "Test"); +self.$RefreshReg$ = $reflamePreviousRefreshReg; +self.$RefreshSig$ = $reflamePreviousRefreshSig; +self.$reflame.registerAcceptCallback({ + pathname: $reflamePathname, + callback: ({ pathname , id })=>{ + if (id) { + console.debug("accepting", pathname, "to", id); + } else { + console.debug("accepting", pathname); + } + self.$reflame.performReactRefresh(); + } +});\n`); +}); \ No newline at end of file diff --git a/node-swc/src/binding.js b/node-swc/src/binding.js index 9929ec1bbb56..dc09af85f19a 100644 --- a/node-swc/src/binding.js +++ b/node-swc/src/binding.js @@ -1,3 +1,9 @@ +/* tslint:disable */ +/* eslint-disable */ +/* prettier-ignore */ + +/* auto-generated by NAPI-RS */ + const { existsSync, readFileSync } = require('fs') const { join } = require('path') @@ -102,6 +108,15 @@ switch (platform) { } break case 'darwin': + localFileExisted = existsSync(join(__dirname, 'swc.darwin-universal.node')) + try { + if (localFileExisted) { + nativeBinding = require('./swc.darwin-universal.node') + } else { + nativeBinding = require('@lewisl9029/swc-core-darwin-universal') + } + break + } catch {} switch (arch) { case 'x64': localFileExisted = existsSync(join(__dirname, 'swc.darwin-x64.node'))