Skip to content

Commit

Permalink
expose isVirtual on all Resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Feb 22, 2024
1 parent 633c418 commit ca49e7b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export interface ModuleRequest<Res extends Resolution = Resolution> {
// 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<T = unknown, E = unknown> =
| { type: 'found'; filename: string; result: T }
| { type: 'found'; filename: string; isVirtual: boolean; result: T }
| { type: 'not_found'; err: E };

export type ResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/node-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/esbuild-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 };
}
}
}
3 changes: 2 additions & 1 deletion packages/vite/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 };
}
Expand Down
7 changes: 6 additions & 1 deletion packages/webpack/src/webpack-resolver-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit ca49e7b

Please sign in to comment.