From ea85d51d00a249454036dbef6b1fab142251c496 Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 16:17:22 -0400 Subject: [PATCH 1/8] Adds tetsts for webpack 5 --- .github/workflows/CI.yml | 38 +------------ test/esm-node-native/package.json | 3 ++ test/runTests.js | 54 +++++++++++++++++++ test/snowpack-modules/package.json | 3 ++ .../index.js | 0 .../package.json | 0 .../webpack.config.js | 0 test/webpack-5-modules/index.js | 2 + test/webpack-5-modules/package.json | 9 ++++ test/webpack-5-modules/webpack.config.js | 12 +++++ 10 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 test/runTests.js rename test/{webpack-modules => webpack-4-modules}/index.js (100%) rename test/{webpack-modules => webpack-4-modules}/package.json (100%) rename test/{webpack-modules => webpack-4-modules}/webpack.config.js (100%) create mode 100644 test/webpack-5-modules/index.js create mode 100644 test/webpack-5-modules/package.json create mode 100644 test/webpack-5-modules/webpack.config.js diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4b8d00a..a020565 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,40 +18,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Setup Testing Infra - run: | - cd test - npm install + - name: Run tests + run: node ./test/runTests.js - - name: "CommonJS Test" - run: | - cd test/cjs - npm run test - - - name: "ES Modules Test" - run: | - cd test/esm-node-native - npm run test - if: ${{ matrix.node-version == '14.x' }} - - - name: "Validate ES Modules == CommonJS" - run: | - cd test/validateModuleExportsMatchCommonJS - npm run test - if: ${{ matrix.node-version == '14.x' }} - - - name: "Rollup Tree-shaking Test" - run: | - cd test/rollup-modules - npm run test - - - name: "Webpack Tree-shaking Test" - run: | - cd test/webpack-modules - npm run test - - - name: "Snowpack Tree-shaking Test" - run: | - cd test/snowpack-modules - npm run test - if: ${{ matrix.node-version == '14.x' }} diff --git a/test/esm-node-native/package.json b/test/esm-node-native/package.json index 166e509..5f9ee8c 100644 --- a/test/esm-node-native/package.json +++ b/test/esm-node-native/package.json @@ -2,5 +2,8 @@ "type": "module", "scripts": { "test": "node index.js" + }, + "engines": { + "node": "14" } } diff --git a/test/runTests.js b/test/runTests.js new file mode 100644 index 0000000..51090c1 --- /dev/null +++ b/test/runTests.js @@ -0,0 +1,54 @@ +const { spawnSync } = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const mainVersion = Number(process.version.replace("v","").split(".")[0]) + +// Loop through all the folders and run `npm test` + +const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules"]; +const filesInTest = fs.readdirSync(__dirname); +const tests = filesInTest + .filter((f) => fs.statSync(path.join(__dirname, f)).isDirectory()) + .filter((f) => !blocklist.includes(f)); + +// Support setting up the test node modules +if (!filesInTest.includes("node_modules")) { + console.log("Installing Deps..."); + spawnSync("npm", ["install"], { cwd: __dirname }); + console.log("Installed"); +} + +const chalk = require("chalk").default; +for (const test of tests) { + console.log("---> " + chalk.bold(test)); + + const pgkJSON = require(path.join(__dirname, test, "package.json")); + + // Allow skipping things which need a minimum of node 14 (es modules) + if (pgkJSON.engines && pgkJSON.engines.node) { + const minVersion = Number(pgkJSON.engines.node) + if (minVersion > mainVersion) { + console.log("Skipping") + continue + } + } + + // The webpack 5 tests have unique deps + if (pgkJSON.dependencies || pgkJSON.devDependencies) { + const nodeModsInstalled = fs.existsSync(path.join(__dirname, test, "node_modules")); + if (!nodeModsInstalled) { + spawnSync("npm", ["install"], { cwd: path.join(__dirname, test) }); + } + } + + // Run the test command + const results = spawnSync("npm", ["test"], { cwd: path.join(__dirname, test) }); + console.log(results.stdout.toString()) + if (results.status) { + console.log(chalk.bold.red("Error running test: ") + chalk.bold(test)) + console.log(results.stderr.toString()) + console.log(chalk.bold.red("^^^ Error running test: ") + chalk.bold(test)) + process.exitCode = results.status + } +} + diff --git a/test/snowpack-modules/package.json b/test/snowpack-modules/package.json index 2936b57..ca7826b 100644 --- a/test/snowpack-modules/package.json +++ b/test/snowpack-modules/package.json @@ -3,5 +3,8 @@ "scripts": { "test": "../node_modules/.bin/snowpack build; node build/index.js" + }, + "engines": { + "node": "14" } } diff --git a/test/webpack-modules/index.js b/test/webpack-4-modules/index.js similarity index 100% rename from test/webpack-modules/index.js rename to test/webpack-4-modules/index.js diff --git a/test/webpack-modules/package.json b/test/webpack-4-modules/package.json similarity index 100% rename from test/webpack-modules/package.json rename to test/webpack-4-modules/package.json diff --git a/test/webpack-modules/webpack.config.js b/test/webpack-4-modules/webpack.config.js similarity index 100% rename from test/webpack-modules/webpack.config.js rename to test/webpack-4-modules/webpack.config.js diff --git a/test/webpack-5-modules/index.js b/test/webpack-5-modules/index.js new file mode 100644 index 0000000..a147352 --- /dev/null +++ b/test/webpack-5-modules/index.js @@ -0,0 +1,2 @@ +import { __awaiter } from "tslib"; +if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/webpack-5-modules/package.json b/test/webpack-5-modules/package.json new file mode 100644 index 0000000..81e83aa --- /dev/null +++ b/test/webpack-5-modules/package.json @@ -0,0 +1,9 @@ +{ + "scripts": { + "test": "webpack && node build/main.js" + }, + "devDependencies": { + "webpack": "5.0.0-rc.4", + "webpack-cli": "3.3.12" + } +} diff --git a/test/webpack-5-modules/webpack.config.js b/test/webpack-5-modules/webpack.config.js new file mode 100644 index 0000000..47956e1 --- /dev/null +++ b/test/webpack-5-modules/webpack.config.js @@ -0,0 +1,12 @@ +const path = require('path'); + +/** @type {import("webpack").Configuration} */ +const config = { + mode: "production", + entry: "./index", + output: { + path: path.join(process.cwd(), 'build') + } +} + +module.exports = config From 3926215fbcba1d44da36a97980974669152804ec Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 9 Oct 2020 13:05:11 -0700 Subject: [PATCH 2/8] Add `webpack` condition, so webpack loads es6 module version Even when handling the `exports` table, as done in `webpack` 5. `webpack` 5, at least at present, doesn't handle esm/cjs interop the same way as `node`, so we can;t use the same source as in `node`. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7b1f61b..0bc9d45 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "sideEffects": false, "exports": { ".": { + "webpack": "./tslib.es6.js", "import": "./modules/index.js", "default": "./tslib.js" }, From d89ca6be0237271083d87bb945ecab5b610cfd8b Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 16:37:38 -0400 Subject: [PATCH 3/8] Try use module instead of webpack --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bc9d45..3b1abd9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "sideEffects": false, "exports": { ".": { - "webpack": "./tslib.es6.js", + "module": "./tslib.es6.js", "import": "./modules/index.js", "default": "./tslib.js" }, From 3830f5bc0431893f5c06399c3c1bb8f9ed09f338 Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 16:39:18 -0400 Subject: [PATCH 4/8] Revert the extra exports reference --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 3b1abd9..7b1f61b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "sideEffects": false, "exports": { ".": { - "module": "./tslib.es6.js", "import": "./modules/index.js", "default": "./tslib.js" }, From c2b174621a9d2969a26bd9961aa160bd68053fb1 Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 16:40:39 -0400 Subject: [PATCH 5/8] Try #150 --- modules/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/index.js b/modules/index.js index d241d04..c5db9d1 100644 --- a/modules/index.js +++ b/modules/index.js @@ -1,4 +1,5 @@ -import tslib from '../tslib.js'; +import * as tslib from '../tslib.js'; + const { __extends, __assign, @@ -23,7 +24,7 @@ const { __importDefault, __classPrivateFieldGet, __classPrivateFieldSet, -} = tslib; +} = tslib.default || tslib; export { __extends, __assign, From 9da1f4f0fba23a1cddbfaf09ce82a60efd166196 Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 16:42:20 -0400 Subject: [PATCH 6/8] Reverts the #150 change --- modules/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/index.js b/modules/index.js index c5db9d1..d241d04 100644 --- a/modules/index.js +++ b/modules/index.js @@ -1,5 +1,4 @@ -import * as tslib from '../tslib.js'; - +import tslib from '../tslib.js'; const { __extends, __assign, @@ -24,7 +23,7 @@ const { __importDefault, __classPrivateFieldGet, __classPrivateFieldSet, -} = tslib.default || tslib; +} = tslib; export { __extends, __assign, From b4b7884becb97e83bc65ac1ad02e6854a7585725 Mon Sep 17 00:00:00 2001 From: Orta Date: Fri, 9 Oct 2020 17:11:34 -0400 Subject: [PATCH 7/8] Fix CI to correctly use the right tslib in webpack 5 --- test/rollup-modules/index.js | 2 +- test/webpack-5-modules/package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/rollup-modules/index.js b/test/rollup-modules/index.js index a147352..78adf19 100644 --- a/test/rollup-modules/index.js +++ b/test/rollup-modules/index.js @@ -1,2 +1,2 @@ -import { __awaiter } from "tslib"; +import { __awaiter } from "../../"; if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/webpack-5-modules/package.json b/test/webpack-5-modules/package.json index 81e83aa..e634d9a 100644 --- a/test/webpack-5-modules/package.json +++ b/test/webpack-5-modules/package.json @@ -3,6 +3,7 @@ "test": "webpack && node build/main.js" }, "devDependencies": { + "tslib": "file:../..", "webpack": "5.0.0-rc.4", "webpack-cli": "3.3.12" } From ae5486071eb5d6180e46f04dd580ac9a45f7a122 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 9 Oct 2020 13:58:41 -0700 Subject: [PATCH 8/8] Merge #129 into this PR --- package.json | 1 + test/rollup-modules/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7b1f61b..3b1abd9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "sideEffects": false, "exports": { ".": { + "module": "./tslib.es6.js", "import": "./modules/index.js", "default": "./tslib.js" }, diff --git a/test/rollup-modules/index.js b/test/rollup-modules/index.js index 78adf19..a147352 100644 --- a/test/rollup-modules/index.js +++ b/test/rollup-modules/index.js @@ -1,2 +1,2 @@ -import { __awaiter } from "../../"; +import { __awaiter } from "tslib"; if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");