Skip to content

Commit

Permalink
Merge pull request #2088 from embroider-build/separate-template-depre…
Browse files Browse the repository at this point in the history
…cation

Implement ember's component-template-resolving deprecation
  • Loading branch information
ef4 authored Sep 20, 2024
2 parents fae4059 + 00bdcd2 commit 33af88c
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"lodash": "^4.17.21",
"resolve": "^1.20.0",
"resolve-package-path": "^4.0.1",
"semver": "^7.3.5",
"typescript-memoize": "^1.0.1",
"walk-sync": "^3.0.0"
},
Expand All @@ -59,6 +60,7 @@
"@types/lodash": "^4.14.170",
"@types/node": "^15.12.2",
"@types/resolve": "^1.20.0",
"@types/semver": "^7.3.5",
"@types/tmp": "^0.1.0",
"fixturify": "^2.1.1",
"tmp": "^0.1.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Memoize } from 'typescript-memoize';
import { describeExports } from './describe-exports';
import { readFileSync } from 'fs';
import type UserOptions from './options';
import { satisfies } from 'semver';

const debug = makeDebug('embroider:resolver');
function logTransition<R extends ModuleRequest>(reason: string, before: R, after: R = before): R {
Expand Down Expand Up @@ -513,6 +514,11 @@ export class Resolver {
}

if (hbsModule) {
if (!this.emberVersionSupportsSeparateTemplates) {
throw new Error(
`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule}.`
);
}
return logTransition(
`resolveComponent found legacy HBS`,
request,
Expand Down Expand Up @@ -723,6 +729,17 @@ export class Resolver {
return owningEngine;
}

get emberVersion(): string {
return this.packageCache.get(this.options.engines[0].root).dependencies.find(d => d.name === 'ember-source')!
.version;
}

@Memoize() get emberVersionSupportsSeparateTemplates(): boolean {
return satisfies(this.emberVersion, '< 6.0.0-alpha.0', {
includePrerelease: true,
});
}

private handleRewrittenPackages<R extends ModuleRequest>(request: R): R {
if (request.isVirtual) {
return request;
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ function renderESExternalShim({ moduleName, exports }: { moduleName: string; exp
const pairedComponentShim = compile(`
import { setComponentTemplate } from "@ember/component";
import template from "{{{js-string-escape relativeHBSModule}}}";
import { deprecate } from "@ember/debug";
deprecate("Components with separately resolved templates are deprecated. Migrate to either co-located js/ts + hbs files or to gjs/gts. Tried to lookup '{{debugName}}'.",
false, {
id: 'component-template-resolving',
url: 'https://deprecations.emberjs.com/id/component-template-resolving',
until: '6.0.0',
for: 'ember-source',
since: {
available: '5.10.0',
enabled: '5.10.0',
},
}
);
{{#if relativeJSModule}}
import component from "{{{js-string-escape relativeJSModule}}}";
export default setComponentTemplate(template, component);
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const { module: Qmodule, test } = QUnit;

Scenarios.fromProject(() => new Project())
.map('core-resolver-test', app => {
app.linkDevDependency('ember-source', { baseDir: __dirname });

let appMeta: AppMeta = {
type: 'app',
version: 2,
Expand Down Expand Up @@ -182,6 +184,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../hello-world.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import component from "../../../components/hello-world.js";
export default setComponentTemplate(template, component);
`);
Expand All @@ -206,6 +223,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../hello-world.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import templateOnlyComponent from "@ember/component/template-only";
export default setComponentTemplate(template, templateOnlyComponent(undefined, "hello-world"));
`);
Expand Down Expand Up @@ -304,6 +336,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../template.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import templateOnlyComponent from "@ember/component/template-only";
export default setComponentTemplate(template, templateOnlyComponent(undefined, "template"));
`);
Expand All @@ -327,6 +374,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../template.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import templateOnlyComponent from "@ember/component/template-only";
export default setComponentTemplate(template, templateOnlyComponent(undefined, "template"));
`);
Expand All @@ -351,6 +413,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../template.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import component from "../component.js";
export default setComponentTemplate(template, component);
`);
Expand All @@ -376,6 +453,21 @@ Scenarios.fromProject(() => new Project())
pairModule.codeEquals(`
import { setComponentTemplate } from "@ember/component";
import template from "../template.hbs";
import { deprecate } from "@ember/debug";
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'.",
false,
{
id: "component-template-resolving",
url: "https://deprecations.emberjs.com/id/component-template-resolving",
until: "6.0.0",
for: "ember-source",
since: {
available: "5.10.0",
enabled: "5.10.0",
},
}
);
import component from "../component.js";
export default setComponentTemplate(template, component);
`);
Expand Down

0 comments on commit 33af88c

Please sign in to comment.