Skip to content

Commit 08abe7a

Browse files
authored
improve templates moduleName
rootDir is not always enough/correct. it ends with /rewritten-app. but there is also /rewritten-packages which will keep the full path. same for node_modules, which have the full path see emberjs/ember-inspector#2425
1 parent 67f82f3 commit 08abe7a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/shared-internals/src/hbs-to-js.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ export function hbsToJS(hbsContents: string, options?: Options): string {
2020
let filename = options.filename;
2121
let { compatModuleNaming: renaming } = options;
2222
if (renaming) {
23-
if (filename.startsWith(renaming.rootDir)) {
24-
filename = renaming.modulePrefix + filename.slice(renaming.rootDir.length);
23+
let rootDir = renaming.rootDir;
24+
if (filename.startsWith(rootDir)) {
25+
filename = renaming.modulePrefix + filename.slice(rootDir.length);
2526
}
26-
if (sep !== '/') {
27-
filename = filename.replace(/\\/g, '/');
27+
if (rootDir.endsWith('rewritten-app')) {
28+
rootDir = rootDir.replace(/rewritten-app$/, 'rewritten-packages');
29+
if (filename.startsWith(rootDir)) {
30+
filename = renaming.modulePrefix + filename.slice(rootDir.length);
31+
}
32+
}
33+
if (filename.includes('node_modules')) {
34+
filename = filename.split('node_modules').slice(-1)[0];
2835
}
2936
}
3037
optsSource = `,{ moduleName: "${jsStringEscape(filename)}" }`;

0 commit comments

Comments
 (0)