7
7
needsSyntheticComponentJS ,
8
8
isInComponents ,
9
9
templateOnlyComponentSource ,
10
+ syntheticJStoHBS ,
10
11
} from '@embroider/core' ;
11
12
12
13
const resolverLoader = new ResolverLoader ( process . cwd ( ) ) ;
@@ -31,18 +32,46 @@ export function hbs(): Plugin {
31
32
skipSelf : true ,
32
33
} ) ;
33
34
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 ,
42
55
} ,
43
56
} ,
44
- } ;
57
+ } ) ;
45
58
}
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
+ } ;
46
75
}
47
76
48
77
return resolution ;
0 commit comments