Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/compat/src/v1-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ export default class V1Addon {

@Memoize()
get root(): string {
// addonInstance.root gets modified by a customized "main" or
// "ember-addon.main" in package.json. We want the real package root here
// (the place where package.json lives).
return dirname(pkgUpSync({ cwd: this.addonInstance.root })!);
return v1AddonRoot(this.addonInstance);
}

@Memoize()
Expand Down Expand Up @@ -1065,6 +1062,15 @@ export default class V1Addon {
}
}

/**
* addonInstance.root gets modified by a customized "main" or
* "ember-addon.main" in package.json. We want the real package root here
* (the place where package.json lives).
*/
export function v1AddonRoot(addonInstance: AddonInstance) {
return dirname(pkgUpSync({ cwd: addonInstance.root })!);
}

export interface V1AddonConstructor {
new (
addonInstance: any,
Expand Down
18 changes: 11 additions & 7 deletions packages/compat/src/v1-instance-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// between the new and old words.

import type { V1AddonConstructor } from './v1-addon';
import V1Addon from './v1-addon';
import V1Addon, { v1AddonRoot } from './v1-addon';
import { pathExistsSync } from 'fs-extra';
import type { AddonInstance, PackageCache } from '@embroider/core';
import { getOrCreate } from '@embroider/core';
Expand All @@ -13,7 +13,7 @@ export default class V1InstanceCache {
// maps from package root directories to known V1 instances of that packages.
// There can be many because a single copy of an addon may be consumed by many
// other packages and each gets an instance.
private addons: Map<string, V1Addon[]> = new Map();
private addons: Map<string, V1Addon> = new Map();
private orderIdx: number;

constructor(private app: CompatApp, private packageCache: PackageCache) {
Expand Down Expand Up @@ -62,13 +62,17 @@ export default class V1InstanceCache {
addonInstance.addons.forEach(a => this.addAddon(a));

this.orderIdx += 1;
let Klass = this.adapterClass(addonInstance);
let v1Addon = new Klass(addonInstance, this.app.options, this.app, this.packageCache, this.orderIdx);
let pkgs = getOrCreate(this.addons, v1Addon.root, () => []);
pkgs.push(v1Addon);
const root = v1AddonRoot(addonInstance);

getOrCreate(this.addons, root, () => {
let Klass = this.adapterClass(addonInstance);
let v1Addon = new Klass(addonInstance, this.app.options, this.app, this.packageCache, this.orderIdx);
return v1Addon;
});
}

getAddons(root: string): V1Addon[] {
return this.addons.get(root) || [];
const addon = this.addons.get(root);
return addon ? [addon] : [];
}
}
Loading