Skip to content

Commit

Permalink
add concept of needsLooseResolving to a package
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 23, 2024
1 parent f0021e0 commit f14736a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,17 +1176,16 @@ export class Resolver {
}

// assertions on what native v2 addons can import
if (!pkg.meta['auto-upgraded']) {
if (
!pkg.meta['auto-upgraded'] &&
!appImportInAppTree(pkg, logicalPackage, packageName) &&
!reliablyResolvable(pkg, packageName)
) {
throw new Error(
`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`
);
}
if (
!pkg.needsLooseResolving() &&
!appImportInAppTree(pkg, logicalPackage, packageName) &&
!reliablyResolvable(pkg, packageName)
) {
throw new Error(
`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`
);
}

return request;
}

Expand Down Expand Up @@ -1326,7 +1325,7 @@ export class Resolver {
}

// auto-upgraded packages can fall back to the set of known active addons
if (pkg.meta['auto-upgraded']) {
if (pkg.needsLooseResolving()) {
let addon = this.locateActiveAddon(packageName);
if (addon) {
const rehomed = request.rehome(addon.canResolveFromFile);
Expand Down Expand Up @@ -1362,7 +1361,7 @@ export class Resolver {
}
}

if (pkg.meta['auto-upgraded'] && (request.meta?.runtimeFallback ?? true)) {
if (pkg.needsLooseResolving() && (request.meta?.runtimeFallback ?? true)) {
// auto-upgraded packages can fall back to attempting to find dependencies at
// runtime. Native v2 packages can only get this behavior in the
// isExplicitlyExternal case above because they need to explicitly ask for
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-internals/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export default class Package {
return this.isV2Ember() && this.packageJSON['ember-addon'].type === 'app';
}

needsLooseResolving(): boolean {
return this.isV2App() || ((this.isV2Addon() && this.meta['auto-upgraded']) ?? false);
}

isV2Addon(): this is V2AddonPackage {
return this.isV2Ember() && this.packageJSON['ember-addon'].type === 'addon';
}
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-internals/src/rewritten-package-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ class WrappedPackage implements PackageTheGoodParts {
return this.plainPkg.isV2Addon();
}

needsLooseResolving(): boolean {
return this.plainPkg.needsLooseResolving();
}

// it's important that we're calling this.dependencies here at this level, not
// plainPkg.dependencies, which wouldn't be correct
findDescendants(filter?: (pkg: Package) => boolean): Package[] {
Expand Down

0 comments on commit f14736a

Please sign in to comment.