diff --git a/packages/shared-internals/src/package.ts b/packages/shared-internals/src/package.ts index e9a413edd..691a0b257 100644 --- a/packages/shared-internals/src/package.ts +++ b/packages/shared-internals/src/package.ts @@ -8,14 +8,8 @@ import flatMap from 'lodash/flatMap'; export default class Package { private dependencyKeys: ('dependencies' | 'devDependencies' | 'peerDependencies')[]; - constructor(readonly root: string, protected packageCache: PackageCache, isApp?: boolean) { - // In stage1 and stage2, we're careful to make sure our PackageCache entry - // for the app itself gets created with an explicit `isApp` flag. In stage3 - // we don't have that much control, but we can rely on the v2-formatted app - // being easy to identify from its metadata. - let mayUseDevDeps = typeof isApp === 'boolean' ? isApp : this.isV2App(); - - this.dependencyKeys = mayUseDevDeps + constructor(readonly root: string, protected packageCache: PackageCache, isApp: boolean) { + this.dependencyKeys = isApp ? ['dependencies', 'devDependencies', 'peerDependencies'] : ['dependencies', 'peerDependencies']; } @@ -137,15 +131,15 @@ export default class Package { // which is why this logic is here in nonResolvableDeps. If you try // to ship broken stuff in regular dependencies, NPM is going to // stop you. - let pkg; + let pkg, main; try { pkg = this.packageCache.get(join(this.packageCache.basedir(this), path)); + main = pkg.packageJSON['ember-addon']?.main || pkg.packageJSON['main']; } catch (err) { // package was missing or had invalid package.json return false; } - let main = - (pkg.packageJSON['ember-addon'] && pkg.packageJSON['ember-addon'].main) || pkg.packageJSON['main']; + if (!main || main === '.' || main === './') { main = 'index.js'; } else if (!extname(main)) { diff --git a/packages/shared-internals/tests/package.test.ts b/packages/shared-internals/tests/package.test.ts index 538fffee9..8ba8b5514 100644 --- a/packages/shared-internals/tests/package.test.ts +++ b/packages/shared-internals/tests/package.test.ts @@ -17,7 +17,7 @@ describe('package', () => { fixturify.writeSync(tmpLocation, projectJSON); let packageCache = new PackageCache(tmpLocation); - let packageInstance = new Package(tmpLocation, packageCache); + let packageInstance = new Package(tmpLocation, packageCache, true); let originalProcessValue = process.env['BROCCOLI_ENABLED_MEMOIZE']; process.env['BROCCOLI_ENABLED_MEMOIZE'] = 'true'; @@ -60,7 +60,7 @@ describe('package', () => { fixturify.writeSync(tmpLocation, projectJSON); let packageCache = new PackageCache(tmpLocation); - let packageInstance = new Package(tmpLocation, packageCache); + let packageInstance = new Package(tmpLocation, packageCache, true); let nonResolvableDeps = packageInstance.nonResolvableDeps; if (!nonResolvableDeps) { @@ -102,7 +102,7 @@ describe('package', () => { fixturify.writeSync(tmpLocation, projectJSON); let packageCache = new PackageCache(tmpLocation); - let packageInstance = new Package(tmpLocation, packageCache); + let packageInstance = new Package(tmpLocation, packageCache, true); let dependencies = packageInstance.dependencies; expect(dependencies.length).toBe(2);