Skip to content

Commit

Permalink
improve templates moduleName
Browse files Browse the repository at this point in the history
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
  • Loading branch information
patricklx committed Jul 6, 2023
1 parent 67f82f3 commit 520c26c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/shared-internals/src/hbs-to-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ export function hbsToJS(hbsContents: string, options?: Options): string {
let filename = options.filename;
let { compatModuleNaming: renaming } = options;
if (renaming) {
if (filename.startsWith(renaming.rootDir)) {
filename = renaming.modulePrefix + filename.slice(renaming.rootDir.length);
let rootDir = renaming.rootDir;
if (filename.startsWith(rootDir)) {
filename = renaming.modulePrefix + filename.slice(rootDir.length);
}
if (rootDir.endsWith('rewritten-app')) {
rootDir = rootDir.replace(/rewritten-app$/, 'rewritten-packages');
if (filename.startsWith(rootDir)) {
filename = filename.slice(rootDir.length);
}
}
if (filename.includes('node_modules')) {
filename = filename.split('node_modules').slice(-1)[0];
}
if (sep !== '/') {
filename = filename.replace(/\\/g, '/');
}
filename = filename.replace(/^\//, '');
}
optsSource = `,{ moduleName: "${jsStringEscape(filename)}" }`;
}
Expand Down

0 comments on commit 520c26c

Please sign in to comment.