Skip to content

Commit

Permalink
Merge pull request #18 from iambumblehead/add-node-17-to-ci
Browse files Browse the repository at this point in the history
add node 17.x
  • Loading branch information
iambumblehead authored Nov 3, 2021
2 parents a35d034 + 3e3b690 commit 3304bf5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 17.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ test('should mock modules and local files at same time', async t => {

### changelog

* 1.0.1 _Nov.02.2001_
* add node v17.x to testing pipelin
* 1.0.0 _Oct.27.2001_
* release version 1.0
* 0.4.2 _Oct.27.2021_
* export 'load' hook from moduleLoader, required by node v16.12.0+
* 0.4.1 _Oct.10.2021_
* version bump, increment devDependencies,
* major improvement to READE, thanks @swivelgames
* major improvement to README, thanks @swivelgames
* 0.4.0 _Sep.07.2021_
* do not runtime error when returuning type '[object Module]' default
* do not runtime error when returning type '[object Module]' default
* 0.3.9 _May.05.2021_
* small change to README
* added a test, update gitlab action to use node 16.x
Expand Down
29 changes: 4 additions & 25 deletions src/esmockLoader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,6 @@ export async function resolve (specifier, context, defaultResolve) {
return resolved;
}

// supported by node version less than 16.12
export async function getSource (url, context, defaultGetSource) {
if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules
return defaultGetSource(url, context, defaultGetSource);

[ url ] = url.split('?esmockGlobals=');
if (url.startsWith(urlDummy)) {
url = url.replace(/[^#]*#/, '');
}

const exportedNames = /exportNames=/.test(url) &&
url.replace(/.*exportNames=(.*)/, '$1').split(',');
if (exportedNames) {
return {
source : exportedNames.map(name => name === 'default'
? `export default global.esmockCacheGet("${url}").default`
: `export const ${name} = global.esmockCacheGet("${url}").${name}`
).join('\n')
};
}

return defaultGetSource(url, context, defaultGetSource);
}

export async function load (url, context, defaultGetSource) {
if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules
return defaultGetSource(url, context, defaultGetSource);
Expand All @@ -88,4 +64,7 @@ export async function load (url, context, defaultGetSource) {
return defaultGetSource(url, context, defaultGetSource);
}


// supported by node version less than 16.12
export async function getSource (url, context, defaultGetSource) {
return load(url, context, defaultGetSource);
}

0 comments on commit 3304bf5

Please sign in to comment.