From f2ab1e6a66ce26c7677ad756c573c8ad0bd7750b Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 27 Jul 2023 16:15:16 -0700 Subject: [PATCH 1/5] do not error when processing sources that include node hashbang --- CHANGELOG.md | 2 ++ package.json | 2 +- src/esmockLoader.js | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8167039..eed917ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # changelog + * 2.3.3 _Jul.27.2023_ + * [do not error when processing node hashbang](https://github.com/iambumblehead/esmock/pull/214) scripts from @tommy-mitchell * 2.3.2 _Jul.22.2023_ * [restore ava unit-test](https://github.com/iambumblehead/esmock/pull/213) process at node20 test pipeline * [investigate problems](https://github.com/iambumblehead/esmock/issues/209) using tsx from @tommy-mitchell diff --git a/package.json b/package.json index 3a1d6bd9..4b735d69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esmock", "type": "module", - "version": "2.3.2", + "version": "2.3.3", "license": "ISC", "readmeFilename": "README.md", "description": "provides native ESM import and globals mocking for unit tests", diff --git a/src/esmockLoader.js b/src/esmockLoader.js index d30d44aa..d492bcbf 100644 --- a/src/esmockLoader.js +++ b/src/esmockLoader.js @@ -18,6 +18,7 @@ const exportNamesRe = /.*exportNames=(.*)/ const withHashRe = /.*#-#/ const isesmRe = /isesm=true/ const isnotfoundRe = /isfound=false/ +const hashbangRe = /^(#![^\n]*[\n])/ const globalPreload = (({ port }) => ( port.addEventListener('message', ev => ( @@ -137,12 +138,16 @@ const load = async (url, context, nextLoad) => { if (treeid) { const [specifier, importedNames] = parseImportsTree(treeidspec) if (importedNames && importedNames.length) { + const source = String((await nextLoad(url, context)).source) + const hbang = (source.match(hashbangRe) || [])[0] || '' + const sourcesafe = hbang ? source.replace(hashbangRe, '') : source + return { format: 'module', shortCircuit: true, responseURL: encodeURI(url), - source: `import {${importedNames}} from '${specifier}';` - + (await nextLoad(url, context)).source + source: hbang + `import {${importedNames}} from '${specifier}';` + + sourcesafe } } } From e90118df337ada88c5c0ae6dc860dd6d6f679b9e Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 27 Jul 2023 16:38:00 -0700 Subject: [PATCH 2/5] use correct link at CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eed917ce..7be35f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # changelog * 2.3.3 _Jul.27.2023_ - * [do not error when processing node hashbang](https://github.com/iambumblehead/esmock/pull/214) scripts from @tommy-mitchell + * [do not error when processing node hashbang](https://github.com/iambumblehead/esmock/pull/217) scripts from @tommy-mitchell * 2.3.2 _Jul.22.2023_ * [restore ava unit-test](https://github.com/iambumblehead/esmock/pull/213) process at node20 test pipeline * [investigate problems](https://github.com/iambumblehead/esmock/issues/209) using tsx from @tommy-mitchell From 74dc976ccdf625ed999521b564ad4fb95883a907 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 27 Jul 2023 21:05:12 -0700 Subject: [PATCH 3/5] update dependencies tests-source-map --- tests/tests-source-map/package.json | 12 ++++++------ tests/tests-source-map/tsconfig.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/tests-source-map/package.json b/tests/tests-source-map/package.json index 3882e8c6..52b87063 100644 --- a/tests/tests-source-map/package.json +++ b/tests/tests-source-map/package.json @@ -7,13 +7,13 @@ }, "dependencies": { "esmock": "file:..", - "@ava/typescript": "^4.0.0", - "@tsconfig/node14": "^1.0.3", - "@types/node": "^20.1.5", - "ava": "^5.2.0", + "@ava/typescript": "^4.1.0", + "@tsconfig/node16": "^16.1.0", + "@types/node": "^20.4.5", + "ava": "^5.3.1", "cross-env": "^7.0.3", - "rimraf": "^3.0.2", - "typescript": "^5.0.4" + "rimraf": "^5.0.1", + "typescript": "^5.1.6" }, "scripts": { "test-metaresolve": "rimraf dist && tsc && cross-env \"NODE_OPTIONS=--experimental-import-meta-resolve --loader=esmock\" NODE_NO_WARNINGS=1 ava", diff --git a/tests/tests-source-map/tsconfig.json b/tests/tests-source-map/tsconfig.json index 5679e046..98f343f8 100644 --- a/tests/tests-source-map/tsconfig.json +++ b/tests/tests-source-map/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "@tsconfig/node14/tsconfig.json", + "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "module": "Node16", "moduleResolution": "Node16", From a98b808fad747096148c6b0c4191c8016eafd686 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 27 Jul 2023 21:24:09 -0700 Subject: [PATCH 4/5] try pinning minor version of node 18.16 for test ci --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index feae2d02..41ee3d40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: # node-14's npm must be updated, but no longer updatable due to: # https://github.com/npm/cli/issues/2663 # because of this, node-14 test strategy is removed :( - node-version: [16.x, 18.x, 20.x] + node-version: [16.x, 18.16.x, 20.x] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 From 3f78d0aeea8c6060f0317ebf207aff5de3aa1258 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 27 Jul 2023 23:32:17 -0700 Subject: [PATCH 5/5] slightly smaller hashbangre --- src/esmockLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/esmockLoader.js b/src/esmockLoader.js index d492bcbf..d4d097b5 100644 --- a/src/esmockLoader.js +++ b/src/esmockLoader.js @@ -18,7 +18,7 @@ const exportNamesRe = /.*exportNames=(.*)/ const withHashRe = /.*#-#/ const isesmRe = /isesm=true/ const isnotfoundRe = /isfound=false/ -const hashbangRe = /^(#![^\n]*[\n])/ +const hashbangRe = /^(#![^\n]*\n)/ const globalPreload = (({ port }) => ( port.addEventListener('message', ev => (