Skip to content

Commit

Permalink
Merge pull request #1863 from embroider-build/streamline-resolver-config
Browse files Browse the repository at this point in the history
add isLazy to resolver config and streamline Engine interface
  • Loading branch information
ef4 authored Apr 2, 2024
2 parents 8e692cc + 16875d5 commit 35f9ecd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
19 changes: 9 additions & 10 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class CompatAppBuilder {
// that the last one wins. Our resolver's order is the order to
// search, so first one wins.
.reverse(),
isLazy: appFiles.engine.package.isLazyEngine(),
})),
amdCompatibility: this.options.amdCompatibility,

Expand Down Expand Up @@ -526,7 +527,7 @@ export class CompatAppBuilder {

html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);

const parentEngine = appFiles.find(e => !e.engine.parent)!;
const parentEngine = appFiles.find(e => e.engine.isApp)!;
let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
if (vendorJS) {
html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
Expand Down Expand Up @@ -659,13 +660,12 @@ export class CompatAppBuilder {
}
}

private partitionEngines(appJSPath: string): Engine[] {
private partitionEngines(): Engine[] {
let queue: Engine[] = [
{
package: this.appPackageWithMovedDeps,
addons: new Map(),
parent: undefined,
sourcePath: appJSPath,
isApp: true,
modulePrefix: this.modulePrefix(),
appRelativePath: '.',
},
Expand All @@ -684,8 +684,7 @@ export class CompatAppBuilder {
queue.push({
package: addon,
addons: new Map(),
parent: current,
sourcePath: addon.root,
isApp: !current,
modulePrefix: addon.name,
appRelativePath: explicitRelative(this.root, addon.root),
});
Expand Down Expand Up @@ -719,8 +718,8 @@ export class CompatAppBuilder {

private updateAppJS(appJSPath: string): AppFiles[] {
if (!this.engines) {
this.engines = this.partitionEngines(appJSPath).map(engine => {
if (engine.sourcePath === appJSPath) {
this.engines = this.partitionEngines().map(engine => {
if (engine.isApp) {
// this is the app. We have more to do for the app than for other
// engines.
let fastbootSync: SyncDir | undefined;
Expand All @@ -741,7 +740,7 @@ export class CompatAppBuilder {
// their files, not doing any actual copying or building.
return {
engine,
appSync: new SyncDir(engine.sourcePath, undefined),
appSync: new SyncDir(engine.package.root, undefined),

// AFAIK, we've never supported a fastboot overlay directory in an
// engine. But if we do need that, it would go here.
Expand Down Expand Up @@ -1226,7 +1225,7 @@ export class CompatAppBuilder {
let styles = [];
// only import styles from engines with a parent (this excludeds the parent application) as their styles
// will be inserted via a direct <link> tag.
if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
for (let style of implicitStyles) {
styles.push({
Expand Down
1 change: 1 addition & 0 deletions packages/compat/tests/audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('audit', function () {
fastbootFiles: {},
activeAddons: [],
root: app.baseDir,
isLazy: false,
},
],
resolvableExtensions,
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/app-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,10 @@ export interface Engine {
package: Package;
// the set of active addons in the engine. For each one we keep track of a file that can resolve the addon, because we'll need that later.
addons: Map<AddonPackage, string>;
// the parent engine, if any
parent: Engine | undefined;
// where the engine's own V2 code comes from
sourcePath: string;
// is this the top-level engine?
isApp: boolean;
// runtime name for the engine's own module namespace
modulePrefix: string;
// this is destPath but relative to the app itself
// TODO: remove this after we remove the stage2 entrypoint
appRelativePath: string;
}
5 changes: 4 additions & 1 deletion packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ export interface Options {
amdCompatibility: Required<UserOptions['amdCompatibility']>;
}

interface EngineConfig {
// TODO: once we can remove the stage2 entrypoint this type can get streamlined
// to the parts we actually need
export interface EngineConfig {
packageName: string;
activeAddons: { name: string; root: string; canResolveFromFile: string }[];
fastbootFiles: { [appName: string]: { localFilename: string; shadowedFilename: string | undefined } };
root: string;
isLazy: boolean;
}

type MergeEntry =
Expand Down
1 change: 1 addition & 0 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Scenarios.fromProject(() => new Project())
root: app.dir,
activeAddons: [],
fastbootFiles: {},
isLazy: false,
},
],
modulePrefix: 'my-app',
Expand Down
1 change: 1 addition & 0 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Scenarios.fromProject(() => new Project())
engines: [
{
packageName: 'my-app',
isLazy: false,
root: app.dir,
fastbootFiles: opts?.fastbootFiles ?? {},
activeAddons: [
Expand Down

0 comments on commit 35f9ecd

Please sign in to comment.