Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 committed Dec 1, 2023
1 parent 630ba66 commit 2362ff1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const fs = require('fs');
const { fileURLToPath } = require('url')
const astParse = require('./lib/ast-parse.js')
const specifiers = new Map()
const isWin = process.platform === "win32"

Expand All @@ -24,6 +23,12 @@ if (NODE_MAJOR >= 20) {
getExports = (url) => import(url).then(Object.keys)
}

if (NODE_MAJOR >= 16) {
astParse = require('./lib/ast-parse.js')
} else {
astParse = undefined
}

function hasIitm (url) {
try {
return new URL(url).searchParams.has('iitm')
Expand Down Expand Up @@ -148,7 +153,7 @@ register(${JSON.stringify(realUrl)}, namespace, set, ${JSON.stringify(specifiers
`
}
}
else if (context.format === 'module' && NODE_MAJOR >= 16) {
else if (NODE_MAJOR >= 16 && context.format === 'module') {
let fileContents
try {
fileContents = fs.readFileSync(fileURLToPath(url), 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Intercept imports in Node.js",
"main": "index.js",
"scripts": {
"test": "c8 --check-coverage --lines 85 imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/*",
"test": "c8 --check-coverage --lines 80 imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/*",
"test:ts": "c8 imhotap --runner 'node test/runtest' --files test/typescript/*.test.mts",
"coverage": "c8 --reporter html imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/* && echo '\nNow open coverage/index.html\n'"
},
Expand Down

0 comments on commit 2362ff1

Please sign in to comment.