diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6114ef1..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,5 +22,7 @@ jobs: run: node ./test/runTests.js - name: Run tests - run: node ./test/validateModuleExportsMatchCommonJS/index.js - 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/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, 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()) 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..166e509 --- /dev/null +++ b/test/vm-modules/package.json @@ -0,0 +1,6 @@ +{ + "type": "module", + "scripts": { + "test": "node index.js" + } +}