Skip to content

Commit

Permalink
Implement ember's component-template-resolving deprecation
Browse files Browse the repository at this point in the history
When using embroider with staticComponents enabled, users will never see Ember's [component-template-resolving](https://deprecations.emberjs.com/id/component-template-resolving/) deprecation, since Embroider takes care of implementing the whole feature at build time before Ember can see it at runtime.

This implements the same deprecation logic in Embroider apps so everybody can stay consistent.
  • Loading branch information
ef4 committed Aug 30, 2024
1 parent fae4059 commit 106ceee
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 156 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
Loading

0 comments on commit 106ceee

Please sign in to comment.