From cdfa4e4aa30031c753208a8b77cf64981c48b1f1 Mon Sep 17 00:00:00 2001 From: Andre Wiggins Date: Wed, 4 Oct 2023 23:52:47 -0700 Subject: [PATCH 1/2] In tests, skip babel on node_modules when not down leveling Local tests run a lot faster now since we aren't running babel over all of React --- karma.conf.js | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 469484df8..220d3fe7d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -96,8 +96,11 @@ function createEsbuildPlugin() { return { path: path.join(__dirname, "test/browser/mockFs.js") }; }); - // Apply babel pass whenever we load a .js file + // Apply babel pass whenever we load a TS or JS file build.onLoad({ filter: /\.[mc]?[jt]sx?$/ }, async args => { + // But skip any file from node_modules if we aren't down-leveling + if (!downlevel && args.path.includes("node_modules")) return; + const contents = await fs.readFile(args.path, "utf-8"); // Using a cache is crucial as babel is 30x slower than esbuild @@ -126,6 +129,7 @@ function createEsbuildPlugin() { pragmaFrag: "Fragment", }, ]; + const ts = [ "@babel/preset-typescript", { @@ -141,36 +145,34 @@ function createEsbuildPlugin() { }, ]; + const downlevelPlugin = [ + "@babel/preset-env", + { + loose: true, + modules: false, + targets: { + browsers: ["last 2 versions", "IE >= 11"], + }, + }, + ]; + + const coveragePlugin = [ + "istanbul", + { + include: minify ? "**/dist/**/*.js" : "**/src/**/*.{ts,js}", + }, + ]; + const tmp = await babel.transformAsync(result, { filename: args.path, sourceMaps: "inline", - presets: downlevel - ? [ - ts, - jsx, - [ - "@babel/preset-env", - { - loose: true, - modules: false, - targets: { - browsers: ["last 2 versions", "IE >= 11"], - }, - }, - ], - ] - : [ts, jsx], + presets: downlevel ? [ts, jsx, downlevelPlugin] : [ts, jsx], plugins: [ - coverage && [ - "istanbul", - { - include: minify ? "**/dist/**/*.js" : "**/src/**/*.{ts,js}", - }, - ], + coverage && coveragePlugin, minify && renamePlugin, ].filter(Boolean), }); - result = tmp.code || result; + result = (tmp && tmp.code) || result; cache.set(args.path, { input: contents, result }); // Fire all pending listeners that are waiting on the same From e2d61ba52420173831c0435eba8cfff8322e0be6 Mon Sep 17 00:00:00 2001 From: Andre Wiggins Date: Thu, 5 Oct 2023 02:22:24 -0700 Subject: [PATCH 2/2] Pin volta to node@18 --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 31f90cd28..6cac0dad4 100644 --- a/package.json +++ b/package.json @@ -105,5 +105,8 @@ "microbundle@0.15.1": "patches/microbundle@0.15.1.patch", "@babel/plugin-transform-typescript@7.19.1": "patches/@babel__plugin-transform-typescript@7.19.1.patch" } + }, + "volta": { + "node": "18.18.0" } }