From b0df18bf703a794024e4ce4d22e8e41d62c99f7c Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Mon, 16 Dec 2024 13:52:51 -0500 Subject: [PATCH] adjust separators and update core resolver tests --- packages/core/src/virtual-content.ts | 4 +- tests/scenarios/core-resolver-test.ts | 53 +++++++++++++++++---------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/packages/core/src/virtual-content.ts b/packages/core/src/virtual-content.ts index 0aae27f1a..75186c84e 100644 --- a/packages/core/src/virtual-content.ts +++ b/packages/core/src/virtual-content.ts @@ -134,7 +134,7 @@ const pairComponentMarker = '/embroider-pair-component/'; const pairComponentPattern = /\/embroider-pair-component\/(?[^\/]*)\/__vpc__\/(?[^\/]*)$/; export function virtualPairComponent(appRoot: string, hbsModule: string, jsModule: string | undefined): string { - return `${appRoot}/embroider-pair-component${encodeURIComponent(hbsModule)}/__vpc__${encodeURIComponent( + return `${appRoot}/embroider-pair-component/${encodeURIComponent(hbsModule)}/__vpc__/${encodeURIComponent( jsModule ?? '' )}`; } @@ -154,7 +154,7 @@ function decodeVirtualPairComponent( return { hbsModule: decodeURIComponent(hbsModule), jsModule: jsModule ? decodeURIComponent(jsModule) : null, - debugName: basename(hbsModule).replace(/\.(js|hbs)$/, ''), + debugName: basename(decodeURIComponent(hbsModule)).replace(/\.(js|hbs)$/, ''), }; } diff --git a/tests/scenarios/core-resolver-test.ts b/tests/scenarios/core-resolver-test.ts index 5e1970481..95b7ffee6 100644 --- a/tests/scenarios/core-resolver-test.ts +++ b/tests/scenarios/core-resolver-test.ts @@ -242,7 +242,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./hello-world.hbs"; + import template from "${app.dir}/templates/components/hello-world.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'hello-world'.", @@ -258,12 +258,14 @@ Scenarios.fromProject(() => new Project()) }, } ); - import component from "../../components/hello-world.js"; + import component from "${app.dir}/components/hello-world.js"; export default setComponentTemplate(template, component); `); - pairModule.resolves('./hello-world.hbs').to('./templates/components/hello-world.hbs'); - pairModule.resolves('../../components/hello-world.js').to('./components/hello-world.js'); + pairModule + .resolves(`${app.dir}/templates/components/hello-world.hbs`) + .to('./templates/components/hello-world.hbs'); + pairModule.resolves(`${app.dir}/components/hello-world.js`).to('./components/hello-world.js'); }); test('hbs-only component', async function () { @@ -281,7 +283,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./hello-world.hbs"; + import template from "${app.dir}/templates/components/hello-world.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'hello-world'.", @@ -301,7 +303,9 @@ Scenarios.fromProject(() => new Project()) export default setComponentTemplate(template, templateOnlyComponent(undefined, "hello-world")); `); - pairModule.resolves('./hello-world.hbs').to('./templates/components/hello-world.hbs'); + pairModule + .resolves(`${app.dir}/templates/components/hello-world.hbs`) + .to('./templates/components/hello-world.hbs'); }); test('explicitly namedspaced component', async function () { @@ -394,7 +398,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./template.hbs"; + import template from "${app.dir}/components/hello-world/template.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'template'.", @@ -414,7 +418,9 @@ Scenarios.fromProject(() => new Project()) export default setComponentTemplate(template, templateOnlyComponent(undefined, "template")); `); - pairModule.resolves('./template.hbs').to('./components/hello-world/template.hbs'); + pairModule + .resolves(`${app.dir}/components/hello-world/template.hbs`) + .to('./components/hello-world/template.hbs'); }); test('podded hbs-only component with non-blank podModulePrefix', async function () { @@ -432,7 +438,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./template.hbs"; + import template from "${app.dir}/pods/components/hello-world/template.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'template'.", @@ -452,7 +458,9 @@ Scenarios.fromProject(() => new Project()) export default setComponentTemplate(template, templateOnlyComponent(undefined, "template")); `); - pairModule.resolves('./template.hbs').to('./pods/components/hello-world/template.hbs'); + pairModule + .resolves(`${app.dir}/pods/components/hello-world/template.hbs`) + .to('./pods/components/hello-world/template.hbs'); }); test('podded js-and-hbs component with blank podModulePrefix', async function () { @@ -471,7 +479,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./template.hbs"; + import template from "${app.dir}/components/hello-world/template.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'template'.", @@ -487,12 +495,16 @@ Scenarios.fromProject(() => new Project()) }, } ); - import component from "./component.js"; + import component from "${app.dir}/components/hello-world/component.js"; export default setComponentTemplate(template, component); `); - pairModule.resolves('./template.hbs').to('./components/hello-world/template.hbs'); - pairModule.resolves('./component.js').to('./components/hello-world/component.js'); + pairModule + .resolves(`${app.dir}/components/hello-world/template.hbs`) + .to('./components/hello-world/template.hbs'); + pairModule + .resolves(`${app.dir}/components/hello-world/component.js`) + .to('./components/hello-world/component.js'); }); test('podded js-and-hbs component with non-blank podModulePrefix', async function () { @@ -511,7 +523,7 @@ Scenarios.fromProject(() => new Project()) pairModule.codeEquals(` import { setComponentTemplate } from "@ember/component"; - import template from "./template.hbs"; + import template from "${app.dir}/pods/components/hello-world/template.hbs"; import { deprecate } from "@ember/debug"; true && !false && deprecate( "Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup 'template'.", @@ -527,12 +539,15 @@ Scenarios.fromProject(() => new Project()) }, } ); - import component from "./component.js"; + import component from "${app.dir}/pods/components/hello-world/component.js"; export default setComponentTemplate(template, component); `); - - pairModule.resolves('./template.hbs').to('./pods/components/hello-world/template.hbs'); - pairModule.resolves('./component.js').to('./pods/components/hello-world/component.js'); + pairModule + .resolves(`${app.dir}/pods/components/hello-world/template.hbs`) + .to('./pods/components/hello-world/template.hbs'); + pairModule + .resolves(`${app.dir}/pods/components/hello-world/component.js`) + .to('./pods/components/hello-world/component.js'); }); test('plain helper', async function () {