Skip to content

Commit

Permalink
Merge pull request #59 from iambumblehead/node-18.6.0-support
Browse files Browse the repository at this point in the history
updated load to shortCircuit
  • Loading branch information
iambumblehead authored Jul 14, 2022
2 parents 3b49ab7 + 66fc281 commit 6f7fbae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/esmockLoader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const urlDummy = 'file:///' + path
.replace(/^\//, '');

const esmockGlobalsAndAfterRe = /\?esmockGlobals=.*/;
const esMockGlobalsAndBeforeRe = /.*\?esmockGlobals=/;
const esmockGlobalsAndBeforeRe = /.*\?esmockGlobals=/;
const esmockModuleKeysRe = /#esmockModuleKeys/;
const exportNamesRe = /.*exportNames=(.*)/;
const esmockKeyRe = /esmockKey=\d*/;
Expand All @@ -49,7 +49,7 @@ const resolve = async (specifier, context, defaultResolve) => {
'.*(' + resolvedurl + '\\?' + esmockKeyParam + '[^#]*).*');

const [ keyUrl, keys ] = esmockKeyLong.split(esmockModuleKeysRe);
const moduleGlobals = keyUrl.replace(esMockGlobalsAndBeforeRe, '');
const moduleGlobals = keyUrl.replace(esmockGlobalsAndBeforeRe, '');
const moduleKeyChild = moduleKeyRe.test(keys)
&& keys.replace(moduleKeyRe, '$1');
const moduleKeyGlobal = moduleKeyRe.test(moduleGlobals)
Expand Down Expand Up @@ -83,6 +83,8 @@ const load = async (url, context, defaultGetSource) => {
if (exportedNames.length) {
return {
format : 'module',
shortCircuit : true,
responseURL : url.replace(/\s+/g,'%20'),
source : exportedNames.map(name => name === 'default'
? `export default global.esmockCacheGet("${url}").default`
: `export const ${name} = global.esmockCacheGet("${url}").${name}`
Expand Down

0 comments on commit 6f7fbae

Please sign in to comment.