Skip to content

Commit efc5ee9

Browse files
committed
fix(@swc-node/register): import of dynamically loaded files; fixes #883
1 parent 5ab459d commit efc5ee9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/register/esm.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
195195

196196
const parsedUrl = parseUrl(specifier)
197197

198+
if (context.parentURL && parsedUrl?.protocol === 'file:') {
199+
debug('skip resolve: dynamic import', specifier);
200+
return addShortCircuitSignal({
201+
...context,
202+
url: specifier,
203+
importAttributes: {
204+
...context.importAttributes,
205+
dynamic: true
206+
}
207+
});
208+
}
209+
198210
// as entrypoint, just return specifier
199211
if (!context.parentURL || parsedUrl?.protocol === 'file:') {
200212
debug('skip resolve: absolute path or entrypoint', specifier)
@@ -281,6 +293,12 @@ const tsconfigForSWCNode = {
281293
export const load: LoadHook = async (url, context, nextLoad) => {
282294
debug('load', url, JSON.stringify(context))
283295

296+
if (context.importAttributes.dynamic) {
297+
debug('skip load: dynamic file url', url);
298+
delete context.importAttributes.dynamic;
299+
return nextLoad(url, context);
300+
}
301+
284302
if (url.startsWith('data:')) {
285303
debug('skip load: data url', url)
286304

0 commit comments

Comments
 (0)