diff --git a/ember-scoped-css/src/lib/path/template-transform-paths.js b/ember-scoped-css/src/lib/path/template-transform-paths.js index 31d13721..af1da015 100644 --- a/ember-scoped-css/src/lib/path/template-transform-paths.js +++ b/ember-scoped-css/src/lib/path/template-transform-paths.js @@ -1,8 +1,6 @@ import path from 'node:path'; -import { existsSync } from 'fs'; - -import { findWorkspacePath, withoutExtension } from './utils'; +import { findWorkspacePath } from './utils'; /** * template plugins do not hand us the correct file path. @@ -36,7 +34,10 @@ export function fixFilename(filename) { * - the filename looks like an absolute path, but swapped out the 'app' part of the path * with the module name, so the file paths never exist on disk */ - if (!fileName.includes('/app/')) { + if ( + !fileName.includes('/app/') && + !fileName.includes('/node_modules/.embroider/') + ) { let maybeModule = fileName.replace(workspace, ''); let [maybeScope, ...rest] = maybeModule.split('/').filter(Boolean); let parts = rest; @@ -57,11 +58,7 @@ export function fixFilename(filename) { */ let candidatePath = path.join(workspace, 'app', relative); - let resolved = findCandidate(candidatePath); - - if (resolved) { - return resolved; - } + return candidatePath; } /** @@ -76,11 +73,7 @@ export function fixFilename(filename) { '/app/', ); - let resolved = findCandidate(candidatePath); - - if (resolved) { - return resolved; - } + return candidatePath; } // TODO: why are we passed files to other projects? @@ -93,23 +86,3 @@ export function fixFilename(filename) { // unhandled scenarios with the file names in the plugin infra return fileName; } - -const COMPILES_TO_JS = ['.hbs', '.gjs', '.gts']; - -function findCandidate(filePath) { - if (existsSync(filePath)) { - return filePath; - } - - let withoutExt = withoutExtension(filePath); - - for (let ext of COMPILES_TO_JS) { - let candidatePath = withoutExt + ext; - - if (existsSync(candidatePath)) { - return candidatePath; - } - } - - return null; -} diff --git a/ember-scoped-css/src/lib/path/template-transform-paths.test.ts b/ember-scoped-css/src/lib/path/template-transform-paths.test.ts index 94febae9..372331de 100644 --- a/ember-scoped-css/src/lib/path/template-transform-paths.test.ts +++ b/ember-scoped-css/src/lib/path/template-transform-paths.test.ts @@ -45,6 +45,22 @@ describe('fixFilename()', () => { ); }); + it('is not confused with "app" in the embroider rewritten location', () => { + let file = path.join( + paths.embroiderApp, + paths.rewritten, + 'components/app/page/template-only.hbs', + ); + let corrected = fixFilename(file); + + expect(corrected).to.equal( + path.join( + paths.embroiderApp, + 'app/components/app/page/template-only.hbs', + ), + ); + }); + it('works with classic paths (w/ module name)', () => { let file = path.join( paths.classicApp,