Skip to content

Commit d497306

Browse files
committed
restoring an hbs fallback case that was actually needed
1 parent 7b68bdf commit d497306

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

packages/vite/src/hbs.ts

+38-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
needsSyntheticComponentJS,
88
isInComponents,
99
templateOnlyComponentSource,
10+
syntheticJStoHBS,
1011
} from '@embroider/core';
1112

1213
const resolverLoader = new ResolverLoader(process.cwd());
@@ -31,18 +32,46 @@ export function hbs(): Plugin {
3132
skipSelf: true,
3233
});
3334

34-
if (resolution) {
35-
let syntheticId = needsSyntheticComponentJS(source, resolution.id);
36-
if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
37-
return {
38-
id: syntheticId,
39-
meta: {
40-
'rollup-hbs-plugin': {
41-
type: 'template-only-component-js',
35+
if (!resolution) {
36+
// vite already has extension search fallback for extensionless imports.
37+
// This is different, it covers an explicit .js import fallback to the
38+
// corresponding hbs.
39+
let hbsSource = syntheticJStoHBS(source);
40+
if (hbsSource) {
41+
resolution = await this.resolve(hbsSource, importer, {
42+
skipSelf: true,
43+
custom: {
44+
embroider: {
45+
// we don't want to recurse into the whole embroider compatbility
46+
// resolver here. It has presumably already steered our request to the
47+
// correct place. All we want to do is slightly modify the request we
48+
// were given (changing the extension) and check if that would resolve
49+
// instead.
50+
//
51+
// Currently this guard is only actually exercised in rollup, not in
52+
// vite, due to https://github.com/vitejs/vite/issues/13852
53+
enableCustomResolver: false,
54+
isExtensionSearch: true,
4255
},
4356
},
44-
};
57+
});
4558
}
59+
60+
if (!resolution) {
61+
return null;
62+
}
63+
}
64+
65+
let syntheticId = needsSyntheticComponentJS(source, resolution.id);
66+
if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
67+
return {
68+
id: syntheticId,
69+
meta: {
70+
'rollup-hbs-plugin': {
71+
type: 'template-only-component-js',
72+
},
73+
},
74+
};
4675
}
4776

4877
return resolution;

0 commit comments

Comments
 (0)