Skip to content

Commit

Permalink
Support v2 ember-source
Browse files Browse the repository at this point in the history
These minor compatibility tweaks are needed to support an upcoming ember-source release that declares itself as a v2 addon.
  • Loading branch information
ef4 committed Nov 5, 2024
1 parent c05d415 commit c61c6ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ export class CompatAppBuilder {

let resolver = new Resolver(resolverConfig);
let resolution = resolver.nodeResolve(
'ember-source/vendor/ember/ember-template-compiler',
'ember-source/dist/ember-template-compiler',
resolvePath(this.root, 'package.json')
);
if (resolution.type !== 'real') {
Expand Down
18 changes: 18 additions & 0 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { readFileSync } from 'fs';
import semver from 'semver';
import type { Transform } from 'babel-plugin-ember-template-compilation';
import { CompatAppBuilder } from './compat-app-builder';
import writeFile from 'broccoli-file-creator';

interface Group {
outputFiles: OutputFileToInputFileMap;
Expand Down Expand Up @@ -346,6 +347,23 @@ export default class CompatApp {
destDir: 'vendor',
})
);

let emberSource = this.legacyEmberAppInstance.project.addons.find(a => a.name === 'ember-source');
if (emberSource && (emberSource.pkg['ember-addon']?.['version'] ?? 1) >= 2) {
// there's stuff in the ecosystem that assumes these files will always be
// present in the vendor tree. But when ember-source is V2, it cannot put
// them there, so @embroider/compat will fill in defaults. The bundles are
// empty because we're just trying to keep the build from blowing up, the
// actual ember modules get loaded as modules instead.
//
// The template compiler is still here so that apps using a V2 ember can
// still app.import the traditional runtime template compiler.
trees.push(writeFile('vendor/ember/ember.js', () => ''));
trees.push(writeFile('vendor/ember/ember-testing.js', () => ''));
const templateCompilerSrc = readFileSync(join(emberSource.root, 'dist/ember-template-compiler.js'), 'utf8');
trees.push(writeFile('vendor/ember/ember-testing.js', () => templateCompilerSrc));
}

if (this.vendorTree) {
trees.push(
buildFunnel(this.vendorTree, {
Expand Down

0 comments on commit c61c6ff

Please sign in to comment.