Skip to content

Commit

Permalink
Merge pull request #1718 from patricklx/vite-test
Browse files Browse the repository at this point in the history
vite test ci
  • Loading branch information
ef4 authored Dec 21, 2023
2 parents a9f892a + 070928b commit 2edb355
Show file tree
Hide file tree
Showing 17 changed files with 2,484 additions and 302 deletions.
24 changes: 14 additions & 10 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,32 +453,32 @@ 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}.hbs`;
let resolution = this.nodeResolve(
`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`,
target.from
);
if (resolution.type === 'real') {
hbsModule = resolution.filename;
hbsModule = { requested: candidateSpecifier, found: resolution.filename };
break;
}
}

// then the various places our javascript might be.
for (let candidate of this.componentJSCandidates(target.packageName)) {
let resolution = this.nodeResolve(
`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`,
target.from
);
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;

let resolution = this.nodeResolve(candidateSpecifier, target.from);
// .hbs is a resolvable extension for us, so we need to exclude it here.
// 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 = resolution.filename;
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
1 change: 0 additions & 1 deletion packages/vite/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from './src/esbuild-resolver.js';
export * from './src/hbs.js';
export * from './src/scripts.js';
export * from './src/template-tag.js';
export * from './src/addons.js';
export * from './src/optimize-deps.js';
2 changes: 0 additions & 2 deletions packages/vite/src/esbuild-request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { type ModuleRequest, cleanUrl } from '@embroider/core';

export const virtualNamespace = 'embroider';

export class EsBuildModuleRequest implements ModuleRequest {
static from(
source: string,
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function defaultResolve(
},
};
}

let result = await context.resolve(request.specifier, {
importer: request.fromFile,
resolveDir: dirname(request.fromFile),
Expand Down
Loading

0 comments on commit 2edb355

Please sign in to comment.