Skip to content
Open
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
18 changes: 18 additions & 0 deletions packages/register/esm.mts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {

const parsedUrl = parseUrl(specifier)

if (context.parentURL && parsedUrl?.protocol === 'file:') {
debug('skip resolve: dynamic import', specifier)
return addShortCircuitSignal({
...context,
url: specifier,
importAttributes: {
...context.importAttributes,
dynamic: 'true',
},
})
}

// as entrypoint, just return specifier
if (!context.parentURL || parsedUrl?.protocol === 'file:') {
debug('skip resolve: absolute path or entrypoint', specifier)
Expand Down Expand Up @@ -281,6 +293,12 @@ const tsconfigForSWCNode = {
export const load: LoadHook = async (url, context, nextLoad) => {
debug('load', url, JSON.stringify(context))

if (context.importAttributes.dynamic === 'true') {
debug('skip load: dynamic file url', url)
delete context.importAttributes.dynamic
return nextLoad(url, context)
}

if (url.startsWith('data:')) {
debug('skip load: data url', url)

Expand Down