Skip to content

Commit

Permalink
Merge pull request #211 from soxhub/bugfixes-for-template-plugin
Browse files Browse the repository at this point in the history
Fix template path transform issue with the app name had "app" in the name
  • Loading branch information
NullVoxPopuli authored Jun 6, 2024
2 parents ffc8179 + f59d030 commit c448455
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ember-scoped-css/src/lib/path/template-transform-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export function fixFilename(filename) {
let fileName = filename;
let workspace = findWorkspacePath(fileName);

/**
* For a simple case, there are sometimes duplicate module paths in the fileName
* let's collapse that and
*/
let potentialModuleName = path.basename(workspace);
let deduped = fileName.replace(
`${potentialModuleName}/${potentialModuleName}/`,
`${potentialModuleName}/app/`,
);

if (deduped !== fileName) {
return deduped;
}

/**
* ember-source 5.8:
* - the filename looks like an absolute path, but swapped out the 'app' part of the path
Expand Down
26 changes: 26 additions & 0 deletions ember-scoped-css/src/lib/path/template-transform-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('fixFilename()', () => {
);
});

it('is not confused with "app" in the component path', () => {
let file = path.join(
paths.classicApp,
'app',
'components/app/page/template-only.hbs',
);
let corrected = fixFilename(file);

expect(corrected).to.equal(
path.join(paths.classicApp, 'app/components/app/page/template-only.hbs'),
);
});

it('works with classic paths (w/ module name)', () => {
let file = path.join(
paths.classicApp,
Expand All @@ -44,4 +57,17 @@ describe('fixFilename()', () => {
path.join(paths.classicApp, 'app/components/template-only.hbs'),
);
});

it('is not confused with "app" in the component path (w/ module name)', () => {
let file = path.join(
paths.classicApp,
'classic-app',
'components/app/page/template-only.hbs',
);
let corrected = fixFilename(file);

expect(corrected).to.equal(
path.join(paths.classicApp, 'app/components/app/page/template-only.hbs'),
);
});
});

0 comments on commit c448455

Please sign in to comment.