Skip to content

Commit

Permalink
Omit packages from the early boot set that do not appear in the root …
Browse files Browse the repository at this point in the history
…package's package.json
  • Loading branch information
NullVoxPopuli committed Jan 11, 2023
1 parent 0e7b31e commit f762cca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/ember-auto-import/ts/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default class AutoImport implements AutoImportSharedAPI {
hasFastboot: this.rootPackage.isFastBootEnabled,
earlyBootSet: this.rootPackage.earlyBootSet,
v2Addons: this.v2Addons,
rootPackage: this.rootPackage,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/ember-auto-import/ts/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface BundlerOptions {
hasFastboot: boolean;
earlyBootSet: undefined | ((defaultModules: string[]) => string[]);
v2Addons: Map<string, string>;
rootPackage: Package;
}

export interface BuildResult {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-auto-import/ts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default class Package {
// maps from packageName to packageRoot
magicDeps: Map<string, string> | undefined;

private hasDependency(name: string): boolean {
hasDependency(name: string): boolean {
let { pkg } = this;
return Boolean(
pkg.dependencies?.[name] ||
Expand Down
30 changes: 25 additions & 5 deletions packages/ember-auto-import/ts/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,38 @@ export default class WebpackBundler extends Plugin implements Bundler {
*/
let v2Addons = this.opts.v2Addons.keys();
let isEmberSourceV2 = this.opts.v2Addons.has('ember-source');
// eslint-disable-next-line @typescript-eslint/no-var-requires
let host = this.opts.rootPackage;

function depNameForPath(modulePath: string) {
if (modulePath.startsWith('@')) {
let [scope, name] = modulePath.split('/');

return `${scope}/${name}`;
}

return modulePath.split('/')[0];
}

function isFromEmberSource(modulePath: string) {
return BOOT_SET_FROM_EMBER_SOURCE.some((fromEmber) =>
modulePath.startsWith(fromEmber)
);
}

result = result.filter((modulePath) => {
if (isEmberSourceV2) {
let isFromEmberSource = BOOT_SET_FROM_EMBER_SOURCE.some((fromEmber) =>
modulePath.startsWith(fromEmber)
);

if (isFromEmberSource) {
if (isFromEmberSource(modulePath)) {
return false;
}
}

let depName = depNameForPath(modulePath);

if (!host.hasDependency(depName) && !isFromEmberSource(modulePath)) {
return false;
}

for (let v2Addon of v2Addons) {
// Omit modulePaths from v2 addons
if (modulePath.startsWith(v2Addon)) {
Expand Down

0 comments on commit f762cca

Please sign in to comment.