Skip to content

Commit

Permalink
Make ember-source compat adapter tolerant of upcoming ember-source ch…
Browse files Browse the repository at this point in the history
…anges

I'm working to land a [Build Reform](emberjs/ember.js#20675) branch in ember-source that, among other things, uses only rollup for Ember's prepublication build, ensuring that it's all ES-module clean.

The inter-package imports within `ember-source/dist/packages` switch from being package names (which require non-standard resolving to work) to relative imports (which do not). As a consequence of that it's simpler to ship all of `dist/packages` and `dist/dependencies` together as `dist/packages`. So our compat adapter needs to tolerate `dist/dependencies` not existing.

The special handling we had for enumerating the contents of `dist/dependencies` and removing them from package.json dependencies was only needed to deal with the magical inter-package resolving, so it's correct that it becomes a no-op for these new ember versions.
  • Loading branch information
ef4 committed May 7, 2024
1 parent 6fa063b commit 043a1bc
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 043a1bc

Please sign in to comment.