Skip to content

Commit

Permalink
adjust separators and update core resolver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Dec 16, 2024
1 parent 26979eb commit b0df18b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const pairComponentMarker = '/embroider-pair-component/';
const pairComponentPattern = /\/embroider-pair-component\/(?<hbsModule>[^\/]*)\/__vpc__\/(?<jsModule>[^\/]*)$/;

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 ?? ''
)}`;
}
Expand All @@ -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)$/, ''),
};
}

Expand Down
53 changes: 34 additions & 19 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'.",
Expand All @@ -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 () {
Expand All @@ -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'.",
Expand All @@ -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 () {
Expand Down Expand Up @@ -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'.",
Expand All @@ -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 () {
Expand All @@ -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'.",
Expand All @@ -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 () {
Expand All @@ -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'.",
Expand All @@ -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 () {
Expand All @@ -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'.",
Expand All @@ -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 () {
Expand Down

0 comments on commit b0df18b

Please sign in to comment.