Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions esm_loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -29,4 +29,3 @@ export async function resolve(specifier, context, defaultResolve) {
throw originalError
}
}

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"pnpm"
],
"license": "MIT",
"engines": {
"node": ">=22.15.0"
},
"packageManager": "pnpm@10.12.1"
}
6 changes: 2 additions & 4 deletions pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const path = require('node:path')
const { pathToFileURL } = require('node:url');
const { pathToFileURL } = require('node:url')

module.exports = {
hooks: {
updateConfig: (config) => {
// 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});`
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// Create NODE_OPTIONS with properly encoded data URL
const importFlag = `--import=data:text/javascript,${encodeURIComponent(registrationCode)}`
Expand All @@ -19,4 +18,3 @@ module.exports = {
},
},
}