From d8eaddfab7a87052eca48da0e0fa8383e4a962e9 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:15:25 -0400 Subject: [PATCH] Hit the file system 3 less times per template-using file (hbs, gjs, gts) --- .../src/lib/path/template-transform-paths.js | 34 ++----------------- .../lib/path/template-transform-paths.test.ts | 13 +++++++ 2 files changed, 16 insertions(+), 31 deletions(-) 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..45c07875 100644 --- a/ember-scoped-css/src/lib/path/template-transform-paths.js +++ b/ember-scoped-css/src/lib/path/template-transform-paths.js @@ -36,7 +36,7 @@ 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 +57,7 @@ export function fixFilename(filename) { */ let candidatePath = path.join(workspace, 'app', relative); - let resolved = findCandidate(candidatePath); - - if (resolved) { - return resolved; - } + return candidatePath; } /** @@ -76,11 +72,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 +85,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..791612e4 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,19 @@ 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,