Skip to content

Commit

Permalink
Merge pull request #223 from iambumblehead/try-resolve-2.3.4-issue
Browse files Browse the repository at this point in the history
explicity define commonjs or module format only for import globals
  • Loading branch information
iambumblehead authored Jul 31, 2023
2 parents 35ada4d + cd74616 commit 17cbe8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "esmock",
"type": "module",
"version": "2.3.4",
"version": "2.3.5",
"license": "ISC",
"readmeFilename": "README.md",
"description": "provides native ESM import and globals mocking for unit tests",
Expand Down
8 changes: 4 additions & 4 deletions src/esmockLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ const load = async (url, context, nextLoad) => {
const source = String((await nextLoad(url, context)).source)
const hbang = (source.match(hashbangRe) || [])[0] || ''
const sourcesafe = hbang ? source.replace(hashbangRe, '') : source
const importexpr = context.format === 'module'
? `import {${importedNames}} from '${specifier}';`
: `const {${importedNames}} = require('${specifier}');`
const importexpr = context.format === 'commonjs'
? `const {${importedNames}} = require('${specifier}');`
: `import {${importedNames}} from '${specifier}';`

return {
format: context.format,
format: context.format === 'commonjs' ? 'commonjs' : 'module',
shortCircuit: true,
responseURL: encodeURI(url),
source: hbang + importexpr + sourcesafe
Expand Down

0 comments on commit 17cbe8d

Please sign in to comment.