diff --git a/esm_loader.mjs b/esm_loader.mjs index 56b840a..9d712c1 100644 --- a/esm_loader.mjs +++ b/esm_loader.mjs @@ -6,9 +6,9 @@ const extraNodePaths = (process.env.NODE_PATH || '') .split(delimiter) .filter(Boolean) -export async function resolve(specifier, context, defaultResolve) { +export function resolve(specifier, context, nextResolve) { try { - return await defaultResolve(specifier, context, defaultResolve) + return nextResolve(specifier, context) } catch (originalError) { if (specifier.startsWith('.') || specifier.startsWith('/') || specifier.match(/^node:/)) { // Don't handle relative, absolute, or node: specifiers @@ -19,7 +19,7 @@ export async function resolve(specifier, context, defaultResolve) { const require = createRequire(pathToFileURL(basePath).href) try { const resolved = require.resolve(specifier) - return { url: pathToFileURL(resolved).href } + return { url: pathToFileURL(resolved).href, shortCircuit: true } } catch { // Skip and try next } @@ -29,4 +29,3 @@ export async function resolve(specifier, context, defaultResolve) { throw originalError } } - diff --git a/package.json b/package.json index 4db68bf..f4935df 100644 --- a/package.json +++ b/package.json @@ -8,5 +8,8 @@ "pnpm" ], "license": "MIT", + "engines": { + "node": ">=22.15.0" + }, "packageManager": "pnpm@10.12.1" } diff --git a/pnpmfile.cjs b/pnpmfile.cjs index 9a02fdb..c4ba6f8 100644 --- a/pnpmfile.cjs +++ b/pnpmfile.cjs @@ -1,5 +1,5 @@ const path = require('node:path') -const { pathToFileURL } = require('node:url'); +const { pathToFileURL } = require('node:url') module.exports = { hooks: { @@ -7,10 +7,9 @@ module.exports = { // Resolve paths and convert to proper file URLs const loaderPath = path.resolve(__dirname, 'esm_loader.mjs') const loaderUrl = pathToFileURL(loaderPath).href - const baseUrl = pathToFileURL(path.resolve('./')).href // Build the registration code - const registrationCode = `import{register}from'node:module';register('${loaderUrl}','${baseUrl}');` + const registrationCode = `import{registerHooks}from'node:module';import{resolve}from'${loaderUrl}';registerHooks({resolve});` // Create NODE_OPTIONS with properly encoded data URL const importFlag = `--import=data:text/javascript,${encodeURIComponent(registrationCode)}` @@ -19,4 +18,3 @@ module.exports = { }, }, } -