Skip to content

Commit

Permalink
filter out appImports from AMD
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jul 13, 2023
1 parent ddf09c9 commit 34653b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/ember-auto-import/ts/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import semver from 'semver';
import type { TransformOptions } from '@babel/core';
import { MARKER } from './analyzer-syntax';
import path from 'path';
import funnel from 'broccoli-funnel';

const debugTree = buildDebugCallback('ember-auto-import');

Expand Down Expand Up @@ -66,6 +67,9 @@ export default class AutoImport implements AutoImportSharedAPI {
let topmostAddon = findTopmostAddon(addonInstance);
this.packages.add(Package.lookupParentOf(topmostAddon));
let host = topmostAddon.app;

this.installAppFilter(host);

this.env = host.env;
this.bundles = new BundleConfig(host.options.outputPaths);
if (!this.env) {
Expand All @@ -75,6 +79,20 @@ export default class AutoImport implements AutoImportSharedAPI {
this.consoleWrite = (...args) => addonInstance.project.ui.write(...args);
}

installAppFilter(_host: AppInstance) {
// TODO upstream this type change to @embroider/shared-internals
let host: AppInstance & {
trees: {
app: Node;
};
} = _host as any;
if (this.rootPackage.allowAppImports.length) {
host.trees.app = funnel(host.trees.app, {
exclude: this.rootPackage.allowAppImports,
});
}
}

// we don't actually call this ourselves anymore, but earlier versions of
// ember-auto-import will still call it on us. For them the answer is always
// false.
Expand Down
10 changes: 10 additions & 0 deletions packages/ember-auto-import/ts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface Options {
forbidEval?: boolean;
skipBabel?: { package: string; semverRange?: string }[];
watchDependencies?: (string | string[])[];
allowAppImports?: string[];
insertScriptsAt?: string;
insertStylesAt?: string;
}
Expand Down Expand Up @@ -481,6 +482,15 @@ export default class Package {
}
}

get allowAppImports(): string[] {
// only apps (not addons) are allowed to set this
if (!this.isAddon) {
return this.autoImportOptions?.allowAppImports ?? [];
}

return [];
}

cleanBabelConfig(): TransformOptions {
if (this.isAddon) {
throw new Error(`Only the app can generate auto-import's babel config`);
Expand Down

0 comments on commit 34653b9

Please sign in to comment.