Skip to content

Commit

Permalink
Vite hbs plugin should return resolutions
Browse files Browse the repository at this point in the history
The lack of the return is probably doubling the amount of resoultion work in downstream plugins.

Also the extra fallback here should not be needed anymore given that the default resolve is supposed to check for hbs.
  • Loading branch information
ef4 committed Oct 8, 2024
1 parent 89d7d7f commit 7b68bdf
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
needsSyntheticComponentJS,
isInComponents,
templateOnlyComponentSource,
syntheticJStoHBS,
} from '@embroider/core';

const resolverLoader = new ResolverLoader(process.cwd());
Expand All @@ -32,44 +31,21 @@ export function hbs(): Plugin {
skipSelf: true,
});

if (!resolution) {
let hbsSource = syntheticJStoHBS(source);
if (hbsSource) {
resolution = await this.resolve(hbsSource, importer, {
skipSelf: true,
custom: {
embroider: {
// we don't want to recurse into the whole embroider compatbility
// resolver here. It has presumably already steered our request to the
// correct place. All we want to do is slightly modify the request we
// were given (changing the extension) and check if that would resolve
// instead.
//
// Currently this guard is only actually exercised in rollup, not in
// vite, due to https://github.com/vitejs/vite/issues/13852
enableCustomResolver: false,
isExtensionSearch: true,
if (resolution) {
let syntheticId = needsSyntheticComponentJS(source, resolution.id);
if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
return {
id: syntheticId,
meta: {
'rollup-hbs-plugin': {
type: 'template-only-component-js',
},
},
});
}

if (!resolution) {
return null;
};
}
}

let syntheticId = needsSyntheticComponentJS(source, resolution.id);
if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
return {
id: syntheticId,
meta: {
'rollup-hbs-plugin': {
type: 'template-only-component-js',
},
},
};
}
return resolution;
},

load(id: string) {
Expand Down

0 comments on commit 7b68bdf

Please sign in to comment.