Skip to content

Commit

Permalink
restoring an hbs fallback case that was actually needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Oct 8, 2024
1 parent 7b68bdf commit d497306
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
needsSyntheticComponentJS,
isInComponents,
templateOnlyComponentSource,
syntheticJStoHBS,
} from '@embroider/core';

const resolverLoader = new ResolverLoader(process.cwd());
Expand All @@ -31,18 +32,46 @@ export function hbs(): Plugin {
skipSelf: 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) {
// vite already has extension search fallback for extensionless imports.
// This is different, it covers an explicit .js import fallback to the
// corresponding hbs.
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) {
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;
Expand Down

0 comments on commit d497306

Please sign in to comment.