diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index 8962b0f90..f970b6c02 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -156,7 +156,7 @@ export interface ModuleRequest { // This is generic because different build systems have different ways of // representing a found module, and we just pass those values through. export type Resolution = - | { type: 'found'; filename: string; result: T } + | { type: 'found'; filename: string; isVirtual: boolean; result: T } | { type: 'not_found'; err: E }; export type ResolverFunction = ( @@ -465,7 +465,7 @@ export class Resolver { let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from)); - if (resolution.type === 'found') { + if (resolution.type === 'found' && !resolution.isVirtual) { hbsModule = resolution; break; } diff --git a/packages/core/src/node-resolve.ts b/packages/core/src/node-resolve.ts index 9f86f0d53..24e03992a 100644 --- a/packages/core/src/node-resolve.ts +++ b/packages/core/src/node-resolve.ts @@ -75,6 +75,7 @@ export class NodeModuleRequest implements ModuleRequest { return { type: 'found', filename: request.specifier, + isVirtual: true, result: { type: 'virtual' as 'virtual', content: virtualContent(request.specifier, this.resolver).src, @@ -129,7 +130,7 @@ export class NodeModuleRequest implements ModuleRequest { continue; } - return { type: 'found', filename, result: { type: 'real' as 'real', filename } }; + return { type: 'found', filename, result: { type: 'real' as 'real', filename }, isVirtual: false }; } return { type: 'not_found', err: initialError }; diff --git a/packages/vite/src/esbuild-request.ts b/packages/vite/src/esbuild-request.ts index 0ffb2daee..3fd394982 100644 --- a/packages/vite/src/esbuild-request.ts +++ b/packages/vite/src/esbuild-request.ts @@ -131,6 +131,7 @@ export class EsBuildModuleRequest implements ModuleRequest { type: 'found', filename: request.specifier, result: { path: request.specifier, namespace: 'embroider' }, + isVirtual: this.isVirtual, }; } if (request.isNotFound) { @@ -157,7 +158,7 @@ export class EsBuildModuleRequest implements ModuleRequest { if (result.errors.length > 0) { return { type: 'not_found', err: result }; } else { - return { type: 'found', filename: result.path, result }; + return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual }; } } } diff --git a/packages/vite/src/request.ts b/packages/vite/src/request.ts index 4d92f32dc..a1d0a766a 100644 --- a/packages/vite/src/request.ts +++ b/packages/vite/src/request.ts @@ -88,6 +88,7 @@ export class RollupModuleRequest implements ModuleRequest { type: 'found', filename: this.specifier, result: { id: this.specifier, resolvedBy: this.fromFile }, + isVirtual: this.isVirtual, }; } if (this.isNotFound) { @@ -107,7 +108,7 @@ export class RollupModuleRequest implements ModuleRequest { }, }); if (result) { - return { type: 'found', filename: result.id, result }; + return { type: 'found', filename: result.id, result, isVirtual: this.isVirtual }; } else { return { type: 'not_found', err: undefined }; } diff --git a/packages/webpack/src/webpack-resolver-plugin.ts b/packages/webpack/src/webpack-resolver-plugin.ts index a73939f5f..d3ef991ba 100644 --- a/packages/webpack/src/webpack-resolver-plugin.ts +++ b/packages/webpack/src/webpack-resolver-plugin.ts @@ -108,7 +108,12 @@ function getAdaptedResolve( // and other unexpected exceptions here. resolve({ type: 'not_found', err }); } else { - resolve({ type: 'found', result: value, filename: value ? String(value.id) : value }); + resolve({ + type: 'found', + result: value, + isVirtual: request.isVirtual, + filename: value ? String(value.id) : value, + }); } }) as CB); });