Skip to content

Commit

Permalink
Merge pull request #1907 from embroider-build/update-ember-source-ada…
Browse files Browse the repository at this point in the history
…pter

Make ember-source compat adapter tolerant of upcoming ember-source changes
  • Loading branch information
ef4 authored May 7, 2024
2 parents c3a9e01 + cc9f590 commit dfa3d6e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/compat/src/compat-adapters/ember-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type * as Babel from '@babel/core';
import type { NodePath } from '@babel/traverse';
import Plugin from 'broccoli-plugin';
import type { Node } from 'broccoli-node-api';
import { existsSync } from 'fs';

export default class extends V1Addon {
get v2Tree() {
Expand All @@ -21,11 +22,27 @@ export default class extends V1Addon {
return this.app.options.staticEmberSource;
}

// ember-source inlines a whole bunch of dependencies into itself
// versions of ember-source prior to
// https://github.com/emberjs/ember.js/pull/20675 ship dist/packages and
// dist/dependencies separately and the imports between them are package-name
// imports. Since many of the dependencies are also true package.json
// dependencies (in order to get typescript types), and our module-resolver
// prioritizes true dependencies, it's necessary to detect and remove the
// package.json dependencies.
//
// After the above linked change, ember-source ships only dist/packages and
// the inter-package imports are all relative. Some of the things in
// dist/packages are still the rolled-in dependencies, but now that the
// imports are all relative we need no special handling for them (beyond the
// normal v2 addon renamed-modules support.
@Memoize()
private get includedDependencies() {
let result: string[] = [];
for (let name of readdirSync(resolve(this.root, 'dist', 'dependencies'))) {
let depsDir = resolve(this.root, 'dist', 'dependencies');
if (!existsSync(depsDir)) {
return result;
}
for (let name of readdirSync(depsDir)) {
if (name[0] === '@') {
for (let innerName of readdirSync(resolve(this.root, 'dist', 'dependencies', name))) {
if (innerName.endsWith('.js')) {
Expand Down Expand Up @@ -87,6 +104,7 @@ export default class extends V1Addon {
packages,
buildFunnel(this.rootTree, {
srcDir: 'dist/dependencies',
allowEmpty: true,
}),
];

Expand Down

0 comments on commit dfa3d6e

Please sign in to comment.