Skip to content

Commit

Permalink
fix fast-failure in nonResolvableDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Jan 12, 2022
1 parent 7134343 commit 9b9fd6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 5 additions & 11 deletions packages/shared-internals/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared-internals/tests/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9b9fd6d

Please sign in to comment.