From da0c3861b9f510ceac46f8fb4023daa86920c1bb Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Wed, 3 Nov 2021 21:11:53 +0300 Subject: [PATCH 1/4] fix: fix re-export at esm entry point --- modules/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/index.js b/modules/index.js index aaac8bf..93ce072 100644 --- a/modules/index.js +++ b/modules/index.js @@ -1,4 +1,4 @@ -import tslib from '../tslib.js'; +import * as tslib from '../tslib.js'; const { __extends, __assign, @@ -25,7 +25,7 @@ const { __classPrivateFieldGet, __classPrivateFieldSet, __classPrivateFieldIn, -} = tslib; +} = tslib.default || tslib; export { __extends, __assign, From 47fea20ef492dafb8829129f29f7113e96bfdbb0 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 4 Nov 2021 01:11:17 +0300 Subject: [PATCH 2/4] test: add vm-modules test --- test/vm-modules/index.js | 23 +++++++++++++++++++++++ test/vm-modules/package.json | 9 +++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/vm-modules/index.js create mode 100644 test/vm-modules/package.json diff --git a/test/vm-modules/index.js b/test/vm-modules/index.js new file mode 100644 index 0000000..dd82d0f --- /dev/null +++ b/test/vm-modules/index.js @@ -0,0 +1,23 @@ +import fs from "node:fs" +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import vm from 'node:vm'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const modulerefContents = fs.readFileSync(resolve(__dirname, "../../modules/index.js"), {encoding: "utf8"}); +const tslibjsContents = fs.readFileSync(resolve(__dirname, "../../tslib.js"), {encoding: "utf8"}); +const contextifiedObject = vm.createContext({}); + +async function linker(specifier, referencingModule) { + if (specifier === '../tslib.js') { + return new vm.SourceTextModule(tslibjsContents, { context: referencingModule.context }); + } + throw new Error(`Unable to resolve dependency: ${specifier}`); +} + +const m = new vm.SourceTextModule(modulerefContents, { context: contextifiedObject }) + +await m.link(linker); +await m.evaluate(); diff --git a/test/vm-modules/package.json b/test/vm-modules/package.json new file mode 100644 index 0000000..5f9ee8c --- /dev/null +++ b/test/vm-modules/package.json @@ -0,0 +1,9 @@ +{ + "type": "module", + "scripts": { + "test": "node index.js" + }, + "engines": { + "node": "14" + } +} From 8fbcddc67e876b12e0fea023c9c63d08df81a48c Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 4 Nov 2021 01:22:29 +0300 Subject: [PATCH 3/4] ci: run vm-modules test on Node.js v14 only --- .github/workflows/CI.yml | 4 +++- test/runTests.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6114ef1..d6b7aab 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -22,5 +22,7 @@ jobs: run: node ./test/runTests.js - name: Run tests - run: node ./test/validateModuleExportsMatchCommonJS/index.js if: matrix.node-version == '14.x' + run: | + node ./test/validateModuleExportsMatchCommonJS/index.js + NODE_OPTIONS=--experimental-vm-modules node ./test/vm-modules/index.js diff --git a/test/runTests.js b/test/runTests.js index 51090c1..a96d552 100644 --- a/test/runTests.js +++ b/test/runTests.js @@ -5,7 +5,7 @@ const mainVersion = Number(process.version.replace("v","").split(".")[0]) // Loop through all the folders and run `npm test` -const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules"]; +const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules", "vm-modules"]; const filesInTest = fs.readdirSync(__dirname); const tests = filesInTest .filter((f) => fs.statSync(path.join(__dirname, f)).isDirectory()) From 94bf5bd4ce13273b96e95ffc9e65fecaa35d4642 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 4 Nov 2021 11:06:40 +0300 Subject: [PATCH 4/4] ci: add Node.js v16 to test matrix --- .github/workflows/CI.yml | 4 ++-- test/vm-modules/package.json | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d6b7aab..6bf0864 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 14.x] + node-version: [10.x, 12.x, 14.x, 16.x] steps: - uses: actions/checkout@v2 @@ -22,7 +22,7 @@ jobs: run: node ./test/runTests.js - name: Run tests - if: matrix.node-version == '14.x' + if: matrix.node-version >= '14.x' run: | node ./test/validateModuleExportsMatchCommonJS/index.js NODE_OPTIONS=--experimental-vm-modules node ./test/vm-modules/index.js diff --git a/test/vm-modules/package.json b/test/vm-modules/package.json index 5f9ee8c..166e509 100644 --- a/test/vm-modules/package.json +++ b/test/vm-modules/package.json @@ -2,8 +2,5 @@ "type": "module", "scripts": { "test": "node index.js" - }, - "engines": { - "node": "14" } }