From 2362ff10f3f1f0e95ec8f17c805d083c4bab0e74 Mon Sep 17 00:00:00 2001 From: Ayan Khan Date: Fri, 1 Dec 2023 14:31:07 -0500 Subject: [PATCH] try again --- hook.js | 9 +++++++-- package.json | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hook.js b/hook.js index 4c887bf..57cef86 100644 --- a/hook.js +++ b/hook.js @@ -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" @@ -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') @@ -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') diff --git a/package.json b/package.json index 5d2b190..b94a52f 100644 --- a/package.json +++ b/package.json @@ -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'" },