Skip to content

Commit

Permalink
virtual case should still use full paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Dec 21, 2023
1 parent 01e7862 commit 070928b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,18 @@ export class Resolver {
private resolveComponent<R extends ModuleRequest>(path: string, inEngine: EngineConfig, request: R): R {
let target = this.parseGlobalPath(path, inEngine);

let hbsModule: string | null = null;
let jsModule: string | null = null;
let hbsModule: { requested: string; found: string } | null = null;
let jsModule: { requested: string; found: string } | null = null;

// first, the various places our template might be.
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}.hbs`;
let resolution = this.nodeResolve(
`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`,
target.from
);
if (resolution.type === 'real') {
hbsModule = candidateSpecifier;
hbsModule = { requested: candidateSpecifier, found: resolution.filename };
break;
}
}
Expand All @@ -478,7 +478,7 @@ export class Resolver {
// It matches as a priority lower than .js, so finding an .hbs means
// there's definitely not a .js.
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
jsModule = candidateSpecifier;
jsModule = { requested: candidateSpecifier, found: resolution.filename };
break;
}
}
Expand All @@ -487,10 +487,14 @@ export class Resolver {
return logTransition(
`resolveComponent found legacy HBS`,
request,
request.virtualize(virtualPairComponent(hbsModule, jsModule))
request.virtualize(virtualPairComponent(hbsModule.found, jsModule?.found))
);
} else if (jsModule) {
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
return logTransition(
`resolveComponent found only JS`,
request,
request.alias(jsModule.requested).rehome(target.from)
);
} else {
return logTransition(`resolveComponent failed`, request);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function decodeVirtualExternalCJSModule(filename: string) {
const pairComponentMarker = '/embroider-pair-component';
const pairComponentPattern = /^(?<hbsModule>.*)\/(?<jsModule>[^\/]*)\/embroider-pair-component$/;

export function virtualPairComponent(hbsModule: string, jsModule: string | null): string {
export function virtualPairComponent(hbsModule: string, jsModule: string | undefined): string {
let relativeJSModule = '';
if (jsModule) {
// The '/j/' here represents the relativeJSModule itself that we're about to
Expand Down

0 comments on commit 070928b

Please sign in to comment.