diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 277cb49..0f56d34 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,21 +9,14 @@ jobs: ci: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [12.x, 14.x, 16.x] - steps: - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - - name: Use node version ${{ matrix.node-version }} + - name: Setup Node.js uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: - node-version: ${{ matrix.node-version }} + node-version: 22.x - name: Run tests run: node ./test/runTests.js - - name: Run tests - run: node ./test/validateModuleExportsMatchCommonJS/index.js - if: matrix.node-version == '16.x' diff --git a/test/cjs/index.js b/test/cjs/index.js deleted file mode 100644 index 761ae43..0000000 --- a/test/cjs/index.js +++ /dev/null @@ -1,2 +0,0 @@ -const tslib = require("tslib"); -if (typeof tslib.__awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/cjs/package.json b/test/cjs/package.json deleted file mode 100644 index 421857a..0000000 --- a/test/cjs/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "scripts": { - "test": "node index.js" - } -} diff --git a/test/esm-node-native/package.json b/test/esm-node-native/package.json deleted file mode 100644 index 5f9ee8c..0000000 --- a/test/esm-node-native/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "module", - "scripts": { - "test": "node index.js" - }, - "engines": { - "node": "14" - } -} diff --git a/test/node/exportStructure.test.js b/test/node/exportStructure.test.js new file mode 100644 index 0000000..0769d23 --- /dev/null +++ b/test/node/exportStructure.test.js @@ -0,0 +1,38 @@ +import assert from "node:assert"; +import { test } from "node:test"; + +import * as tslibJs from "tslib/tslib.js"; +import * as tslibEs6Js from "tslib/tslib.es6.js"; +import * as tslibEs6Mjs from "tslib/tslib.es6.mjs"; +import * as tslibModulesIndex from "tslib/modules/index.js"; + +test("all helpers available as named exports", () => { + compareKeys("tslib.js", tslibJs, "tslib.es6.js", tslibEs6Js); + compareKeys("tslib.js", tslibJs, "tslib.es6.mjs", tslibEs6Mjs); + compareKeys("tslib.js", tslibJs, "modules/index.js", tslibModulesIndex); +}); + +test("default export contains all named exports", () => { + assert.ok(tslibJs.default); + compareKeys("tslib.js (default export)", tslibJs.default, "tslib.js (namespace)", tslibJs); + assert.ok(tslibEs6Js.default); + compareKeys("tslib.es6.js (default export)", tslibEs6Js.default, "tslib.es6.js (namespace)", tslibEs6Js); + assert.ok(tslibEs6Mjs.default); + compareKeys("tslib.es6.mjs (default export)", tslibEs6Mjs.default, "tslib.es6.mjs (namespace)", tslibEs6Mjs); +}); + +/** + * @param {string} name1 + * @param {object} tslib1 + * @param {string} name2 + * @param {object} tslib2 + */ +function compareKeys(name1, tslib1, name2, tslib2) { + const difference = new Set(Object.keys(tslib1)).symmetricDifference(new Set(Object.keys(tslib2))); + difference.delete("__esModule"); + difference.delete("default"); // Asserted separately where expected + const messages = Array.from(difference).map(missing => `'${missing}' missing in ${missing in tslib1 ? name2 : name1}`); + if (messages.length > 0) { + assert.fail(`Mismatch between ${name1} and ${name2}:\n\n ${messages.join("\n ")}\n`); + } +} \ No newline at end of file diff --git a/test/node/package.json b/test/node/package.json new file mode 100644 index 0000000..23992f6 --- /dev/null +++ b/test/node/package.json @@ -0,0 +1,6 @@ +{ + "type": "module", + "scripts": { + "test": "node --test --experimental-detect-module" + } +} \ No newline at end of file diff --git a/test/node/testHelper.js b/test/node/testHelper.js new file mode 100644 index 0000000..f6a69d5 --- /dev/null +++ b/test/node/testHelper.js @@ -0,0 +1,24 @@ +import { describe } from "node:test"; + +import * as tslibJs from "tslib/tslib.js"; +import * as tslibEs6Js from "tslib/tslib.es6.js"; +import * as tslibEs6Mjs from "tslib/tslib.es6.mjs"; + +/** + * @template {keyof tslibJs} K + * @param {K} helperName + * @param {(helper: tslibJs[K]) => any} test + */ +export function testHelper(helperName, test) { + describe(helperName, () => { + describe("tslib.js", () => { + test(tslibJs[helperName]); + }); + describe("tslib.es6.js", () => { + test(tslibEs6Js[helperName]); + }); + describe("tslib.es6.mjs", () => { + test(tslibEs6Mjs[helperName]); + }); + }); +} diff --git a/test/node/tsconfig.json b/test/node/tsconfig.json new file mode 100644 index 0000000..f25ede6 --- /dev/null +++ b/test/node/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "checkJs": true, + "noEmit": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "types": ["node"], + } +} \ No newline at end of file diff --git a/test/package.json b/test/package.json index 2f35efe..2fdb77a 100644 --- a/test/package.json +++ b/test/package.json @@ -1,11 +1,10 @@ { "dependencies": { + "chalk": "^4.1.2", + "rollup": "4.22.0", "tslib": "file:..", - "rollup": "2.28.2", - "@rollup/plugin-node-resolve": "9.0.0", - "webpack": "4.44.2", - "webpack-cli": "3.3.12", - "snowpack": "2.12.1", - "vite": "2.8.0" + "vite": "5.4.6", + "webpack": "5.94.0", + "webpack-cli": "5.1.4" } } diff --git a/test/rollup-modules/rollup.config.js b/test/rollup-modules/rollup.config.js index 407442c..4875eed 100644 --- a/test/rollup-modules/rollup.config.js +++ b/test/rollup-modules/rollup.config.js @@ -1,10 +1,7 @@ -import { nodeResolve } from '@rollup/plugin-node-resolve'; - export default { input: 'index.js', output: { dir: 'build', format: 'cjs' }, - plugins: [nodeResolve()] }; diff --git a/test/runTests.js b/test/runTests.js index 51090c1..a26e3e5 100644 --- a/test/runTests.js +++ b/test/runTests.js @@ -1,3 +1,4 @@ +// @ts-check const { spawnSync } = require("child_process"); const fs = require("fs"); const path = require("path"); @@ -5,11 +6,10 @@ 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)); + .filter((f) => f !== "node_modules"); // Support setting up the test node modules if (!filesInTest.includes("node_modules")) { @@ -18,7 +18,7 @@ if (!filesInTest.includes("node_modules")) { console.log("Installed"); } -const chalk = require("chalk").default; +const chalk = require("chalk"); for (const test of tests) { console.log("---> " + chalk.bold(test)); diff --git a/test/snowpack-modules/index.js b/test/snowpack-modules/index.js deleted file mode 100644 index a147352..0000000 --- a/test/snowpack-modules/index.js +++ /dev/null @@ -1,2 +0,0 @@ -import { __awaiter } from "tslib"; -if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/snowpack-modules/package.json b/test/snowpack-modules/package.json deleted file mode 100644 index ca7826b..0000000 --- a/test/snowpack-modules/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type": "module", - - "scripts": { - "test": "../node_modules/.bin/snowpack build; node build/index.js" - }, - "engines": { - "node": "14" - } -} diff --git a/test/validateModuleExportsMatchCommonJS/index.js b/test/validateModuleExportsMatchCommonJS/index.js deleted file mode 100644 index 2ff703b..0000000 --- a/test/validateModuleExportsMatchCommonJS/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// This file can only run on node 14+, it validates that all of the commonjs exports -// are correctly re-exported for es modules importers. - -// ES Modules import via the ./modules folder -import * as esTSLib from "../../modules/index.js" - -// Force a commonjs resolve -import { createRequire } from "module"; -const commonJSTSLib = createRequire(import.meta.url)("../../tslib.js"); - -for (const key in commonJSTSLib) { - if (commonJSTSLib.hasOwnProperty(key)) { - if(!esTSLib[key]) throw new Error(`ESModules is missing ${key} - it needs to be re-exported in ./modules/index.js`) - } -} - -console.log("All exports in commonjs are available for es module consumers.") diff --git a/test/validateModuleExportsMatchCommonJS/package.json b/test/validateModuleExportsMatchCommonJS/package.json deleted file mode 100644 index 166e509..0000000 --- a/test/validateModuleExportsMatchCommonJS/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "module", - "scripts": { - "test": "node index.js" - } -} diff --git a/test/webpack-4-modules/index.js b/test/webpack-4-modules/index.js deleted file mode 100644 index a147352..0000000 --- a/test/webpack-4-modules/index.js +++ /dev/null @@ -1,2 +0,0 @@ -import { __awaiter } from "tslib"; -if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/webpack-4-modules/package.json b/test/webpack-4-modules/package.json deleted file mode 100644 index 3601cac..0000000 --- a/test/webpack-4-modules/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "test": "../node_modules/.bin/webpack && node build/main.js" - } -} diff --git a/test/webpack-5-modules/index.js b/test/webpack-5-modules/index.js deleted file mode 100644 index a147352..0000000 --- a/test/webpack-5-modules/index.js +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index e634d9a..0000000 --- a/test/webpack-5-modules/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scripts": { - "test": "webpack && node build/main.js" - }, - "devDependencies": { - "tslib": "file:../..", - "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 deleted file mode 100644 index 47956e1..0000000 --- a/test/webpack-5-modules/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -const path = require('path'); - -/** @type {import("webpack").Configuration} */ -const config = { - mode: "production", - entry: "./index", - output: { - path: path.join(process.cwd(), 'build') - } -} - -module.exports = config diff --git a/test/esm-node-native/index.js b/test/webpack-modules/index.js similarity index 100% rename from test/esm-node-native/index.js rename to test/webpack-modules/index.js diff --git a/test/webpack-modules/package.json b/test/webpack-modules/package.json new file mode 100644 index 0000000..04c09f4 --- /dev/null +++ b/test/webpack-modules/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "test": "webpack && node build/main.js" + } +} diff --git a/test/webpack-4-modules/webpack.config.js b/test/webpack-modules/webpack.config.js similarity index 100% rename from test/webpack-4-modules/webpack.config.js rename to test/webpack-modules/webpack.config.js diff --git a/tslib.es6.js b/tslib.es6.js index fc18d15..9365006 100644 --- a/tslib.es6.js +++ b/tslib.es6.js @@ -354,6 +354,10 @@ export default { __rest: __rest, __decorate: __decorate, __param: __param, + __esDecorate: __esDecorate, + __runInitializers: __runInitializers, + __propKey: __propKey, + __setFunctionName: __setFunctionName, __metadata: __metadata, __awaiter: __awaiter, __generator: __generator, diff --git a/tslib.es6.mjs b/tslib.es6.mjs index 17bb2ff..e669963 100644 --- a/tslib.es6.mjs +++ b/tslib.es6.mjs @@ -353,6 +353,10 @@ export default { __rest, __decorate, __param, + __esDecorate, + __runInitializers, + __propKey, + __setFunctionName, __metadata, __awaiter, __generator, diff --git a/tslib.js b/tslib.js index 429c11a..e53dd2f 100644 --- a/tslib.js +++ b/tslib.js @@ -427,3 +427,37 @@ var __disposeResources; exporter("__addDisposableResource", __addDisposableResource); exporter("__disposeResources", __disposeResources); }); + +0 && (module.exports = { + __extends, + __assign, + __rest, + __decorate, + __param, + __esDecorate, + __runInitializers, + __propKey, + __setFunctionName, + __metadata, + __awaiter, + __generator, + __exportStar, + __createBinding, + __values, + __read, + __spread, + __spreadArrays, + __spreadArray, + __await, + __asyncGenerator, + __asyncDelegator, + __asyncValues, + __makeTemplateObject, + __importStar, + __importDefault, + __classPrivateFieldGet, + __classPrivateFieldSet, + __classPrivateFieldIn, + __addDisposableResource, + __disposeResources, +});