diff --git a/ember-scoped-css/src/build/babel-plugin.js b/ember-scoped-css/src/build/babel-plugin.js index fc861f5e..fbb77d98 100644 --- a/ember-scoped-css/src/build/babel-plugin.js +++ b/ember-scoped-css/src/build/babel-plugin.js @@ -97,11 +97,27 @@ export default (env, options, workingDirectory) => { let cssPath = cssPathFor(fileName); - if (existsSync(cssPath)) { - let baseCSS = nodePath.basename(cssPath); - - state.importUtil.importForSideEffect(`./${baseCSS}`); + if (!existsSync(cssPath)) { + // check if we have an extraneous folder path + // this can happen because plugins have tried using + // the module path instead of the real path on disk. + // it's tricky to support both when there are no standards + // around managing these paths. + // But also, in normal projects, they are not different paths. + let [, ...parts] = cssPath.split('/'); + + cssPath = ['app', ...parts].join('/'); + + if (!existsSync(cssPath)) { + // there is no css path + // we don't want to add an import of the CSS file doesn't exist + return; + } } + + let baseCSS = nodePath.basename(cssPath); + + state.importUtil.importForSideEffect(`./${baseCSS}`); } }, }, diff --git a/ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts b/ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts index ab70145a..b4b0c6dc 100644 --- a/ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts +++ b/ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts @@ -12,7 +12,7 @@ describe('hashFromAbsolutePath', () => { let expected = 'ea418816b'; it('matches the module path', () => { - let postfix = hashFromModulePath(`embroider-app/${file}`); + let postfix = hashFromModulePath(`test-app/${file}`); expect(postfix).to.equal(expected); }); diff --git a/ember-scoped-css/src/lib/path/utils.appPath.test.ts b/ember-scoped-css/src/lib/path/utils.appPath.test.ts index c0ab26b9..edc4b86a 100644 --- a/ember-scoped-css/src/lib/path/utils.appPath.test.ts +++ b/ember-scoped-css/src/lib/path/utils.appPath.test.ts @@ -14,20 +14,20 @@ describe('appPath()', () => { ); let result = appPath(file); - expect(result).to.equal('embroider-app/templates/application'); + expect(result).to.equal('test-app/templates/application'); }); it('handles extraneous /app/', () => { let file = path.join(paths.embroiderApp, 'app', 'templates/application'); let result = appPath(file); - expect(result).to.equal('embroider-app/templates/application'); + expect(result).to.equal('test-app/templates/application'); }); it('handles psuedo module', () => { let file = path.join(paths.embroiderApp, 'templates/application'); let result = appPath(file); - expect(result).to.equal('embroider-app/templates/application'); + expect(result).to.equal('test-app/templates/application'); }); }); diff --git a/sync-test-apps.mjs b/sync-test-apps.mjs new file mode 100644 index 00000000..7e109100 --- /dev/null +++ b/sync-test-apps.mjs @@ -0,0 +1,30 @@ +import path from 'node:path'; +import fs from 'node:fs/promises'; + +const cwd = process.cwd(); +const source = 'test-apps/classic-app'; +const sourceComponents = path.join(source, 'app/components'); +const sourceTests = path.join(source, 'tests/shared-scenarios'); + +const otherApps = ['embroider-app', 'pods-classic-app', 'pods-embroider-app']; + +async function sync(source, destination) { + let target = path.join('../../', source).replace('/test-apps/', '/'); + + console.log(target); + + await fs.rm(destination, { force: true, recursive: true }); + await fs.symlink(target, destination); +} + +for (let app of otherApps) { + await sync( + sourceComponents, + path.join(cwd, 'test-apps', app, 'app/components'), + ); + + await sync( + sourceTests, + path.join(cwd, 'test-apps', app, 'tests/shared-scenarios'), + ); +} diff --git a/test-apps/classic-app/app/app.js b/test-apps/classic-app/app/app.js index a4857677..83bc0d2b 100644 --- a/test-apps/classic-app/app/app.js +++ b/test-apps/classic-app/app/app.js @@ -1,8 +1,8 @@ import Application from '@ember/application'; -import config from 'classic-app/config/environment'; import loadInitializers from 'ember-load-initializers'; import Resolver from 'ember-resolver'; +import config from 'test-app/config/environment'; export default class App extends Application { modulePrefix = config.modulePrefix; diff --git a/test-apps/classic-app/app/index.html b/test-apps/classic-app/app/index.html index 7aca2277..64824bfd 100644 --- a/test-apps/classic-app/app/index.html +++ b/test-apps/classic-app/app/index.html @@ -9,11 +9,7 @@ {{content-for "head"}} - + {{content-for "head-footer"}} @@ -21,7 +17,7 @@ {{content-for "body"}} - + {{content-for "body-footer"}}
{{content-for "body"}} {{content-for "test-body"}} @@ -27,7 +27,7 @@ - + {{content-for "body-footer"}} {{content-for "test-body-footer"}} diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/at-class-test.gts b/test-apps/classic-app/tests/shared-scenarios/in-app/at-class-test.gts index 08c89393..2512afb3 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/at-class-test.gts +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/at-class-test.gts @@ -2,7 +2,7 @@ import { render } from '@ember/test-helpers'; import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import CallsAtHasClass from 'classic-app/components/in-app/at-class-ts/calls-has-at-class'; +import CallsAtHasClass from 'test-app/components/in-app/at-class-ts/calls-has-at-class'; import { scopedClass } from 'ember-scoped-css/test-support'; @@ -16,8 +16,8 @@ module('[In App] at-class-ts', function(hooks) { ); - assert.dom('p').hasClass('text-color_ed46c3a30'); - assert.dom('p').hasClass(scopedClass('text-color', 'classic-app/components/in-app/at-class-ts/calls-has-at-class')); + assert.dom('p').hasClass('text-color_e859f8885'); + assert.dom('p').hasClass(scopedClass('text-color', 'test-app/components/in-app/at-class-ts/calls-has-at-class')); assert.dom('p').hasStyle({ color: 'rgb(51, 51, 119)' }); }); }); diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/basic-test.gts b/test-apps/classic-app/tests/shared-scenarios/in-app/basic-test.gts index 4ab08268..43c43172 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/basic-test.gts +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/basic-test.gts @@ -2,7 +2,7 @@ import { render } from '@ember/test-helpers'; import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import Basic from 'classic-app/components/in-app/basic'; +import Basic from 'test-app/components/in-app/basic'; import { scopedClass } from 'ember-scoped-css/test-support'; @@ -17,7 +17,7 @@ module('[In App] basic', function(hooks) { ); assert.dom('div').hasClass('has-a-style_e8d85123f'); - assert.dom('div').hasClass(scopedClass('has-a-style', 'classic-app/components/in-app/basic')); + assert.dom('div').hasClass(scopedClass('has-a-style', 'test-app/components/in-app/basic')); assert.dom('div').hasStyle({ color: 'rgb(0, 100, 50)', fontWeight: '700' }); }); }); diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/component-at-class-test.gjs b/test-apps/classic-app/tests/shared-scenarios/in-app/component-at-class-test.gjs index 56c7c715..b0fa0d70 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/component-at-class-test.gjs +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/component-at-class-test.gjs @@ -3,7 +3,7 @@ import { hbs } from 'ember-cli-htmlbars'; import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import ComponentAtClass from 'classic-app/components/component-at-class'; +import ComponentAtClass from 'test-app/components/component-at-class'; import { scopedClass } from 'ember-scoped-css/test-support'; @@ -20,7 +20,7 @@ module('[In App] @class', function (hooks) { assert .dom('p') .hasClass( - scopedClass('text-color', 'classic-app/components/component-at-class') + scopedClass('text-color', 'test-app/components/component-at-class') ); assert.dom('p').hasStyle({ color: 'rgb(0, 0, 255)' }); }); @@ -33,7 +33,7 @@ module('[In App] @class', function (hooks) { assert .dom('p') .hasClass( - scopedClass('text-color', 'classic-app/components/component-at-class') + scopedClass('text-color', 'test-app/components/component-at-class') ); assert.dom('p').hasStyle({ color: 'rgb(0, 0, 255)' }); }); diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/header-test.js b/test-apps/classic-app/tests/shared-scenarios/in-app/header-test.js index 63ab4832..0c668951 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/header-test.js +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/header-test.js @@ -5,7 +5,7 @@ import { setupRenderingTest } from 'ember-qunit'; import { scopedClass } from 'ember-scoped-css/test-support'; -module('[In App] header', function (hooks) { +module('[In App] header', function (hooks) { setupRenderingTest(hooks); test('it has scoped class', async function (assert) { @@ -15,6 +15,6 @@ module('[In App] header', function (hooks) { assert.dom('h1').hasStyle({ color: 'rgb(255, 0, 0)' }); assert .dom('h1') - .hasClass(scopedClass('test-header', 'classic-app/components/header')); + .hasClass(scopedClass('test-header', 'test-app/components/header')); }); }); diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/subexpression-test.gjs b/test-apps/classic-app/tests/shared-scenarios/in-app/subexpression-test.gjs index f4fbf563..e0dc4bae 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/subexpression-test.gjs +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/subexpression-test.gjs @@ -2,8 +2,8 @@ import { render, settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import SubExpression from 'classic-app/components/subexpression'; import { cell } from 'ember-resources'; +import SubExpression from 'test-app/components/subexpression'; import { scopedClass } from 'ember-scoped-css/test-support'; @@ -27,7 +27,7 @@ module('[In App] subexpression', function (hooks) { assert .dom('div') .hasClass( - scopedClass('a-local-class', 'classic-app/components/subexpression') + scopedClass('a-local-class', 'test-app/components/subexpression') ); assert.dom('div').hasStyle({ color: 'rgb(0, 0, 255)' }); }); diff --git a/test-apps/classic-app/tests/shared-scenarios/in-app/template-only-test.js b/test-apps/classic-app/tests/shared-scenarios/in-app/template-only-test.js index f92016d9..3ce9108c 100644 --- a/test-apps/classic-app/tests/shared-scenarios/in-app/template-only-test.js +++ b/test-apps/classic-app/tests/shared-scenarios/in-app/template-only-test.js @@ -13,9 +13,7 @@ module('[In App] template-only', function (hooks) { assert .dom('div') - .hasClass( - scopedClass('some-class', 'classic-app/components/template-only'), - ); + .hasClass(scopedClass('some-class', 'test-app/components/template-only')); assert.dom('div').hasStyle({ color: 'rgb(0, 0, 255)' }); }); }); diff --git a/test-apps/classic-app/tests/test-helper.js b/test-apps/classic-app/tests/test-helper.js index 3e92a514..5990eca2 100644 --- a/test-apps/classic-app/tests/test-helper.js +++ b/test-apps/classic-app/tests/test-helper.js @@ -3,8 +3,8 @@ import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; import { start } from 'ember-qunit'; -import Application from 'classic-app/app'; -import config from 'classic-app/config/environment'; +import Application from 'test-app/app'; +import config from 'test-app/config/environment'; setApplication(Application.create(config.APP)); diff --git a/test-apps/embroider-app/app/app.js b/test-apps/embroider-app/app/app.js index a8e9a7ca..83bc0d2b 100644 --- a/test-apps/embroider-app/app/app.js +++ b/test-apps/embroider-app/app/app.js @@ -2,7 +2,7 @@ import Application from '@ember/application'; import loadInitializers from 'ember-load-initializers'; import Resolver from 'ember-resolver'; -import config from 'embroider-app/config/environment'; +import config from 'test-app/config/environment'; export default class App extends Application { modulePrefix = config.modulePrefix; diff --git a/test-apps/embroider-app/app/components b/test-apps/embroider-app/app/components new file mode 120000 index 00000000..29ee9fab --- /dev/null +++ b/test-apps/embroider-app/app/components @@ -0,0 +1 @@ +../../classic-app/app/components \ No newline at end of file diff --git a/test-apps/embroider-app/app/components/.gitkeep b/test-apps/embroider-app/app/components/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test-apps/embroider-app/app/components/forth.css b/test-apps/embroider-app/app/components/forth.css deleted file mode 100644 index f40bc5a6..00000000 --- a/test-apps/embroider-app/app/components/forth.css +++ /dev/null @@ -1,19 +0,0 @@ -div { - width: 250px; - border: 1px solid black; - padding: 0px 15px; - margin-top: 15px; -} - -.header { - margin-top: 0; - background-color: lightslategrey; - padding: 15px; - margin: 0px -15px; - text-align: right; -} - -.message { - font-weight: bold; - font-size: 3em; -} diff --git a/test-apps/embroider-app/app/components/forth.gjs b/test-apps/embroider-app/app/components/forth.gjs deleted file mode 100644 index b094340d..00000000 --- a/test-apps/embroider-app/app/components/forth.gjs +++ /dev/null @@ -1,10 +0,0 @@ - -