Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install transitive dependencies even if listed as devDependencies in the project #2895

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function mockConstants(base: Config, mocks: Object, cb: (config: Config) =
// the Yarn environment.

const opts = {};

opts.binLinks = base.binLinks;
opts.cwd = base.cwd;
opts.globalFolder = base.globalFolder;
Expand Down Expand Up @@ -231,6 +231,17 @@ test.concurrent('--production flag does not link dev dependency bin scripts', ()
});
});

test.concurrent('--production flag installs transitive dependencies even if they are top-level devDependencies', () => {
// Root package: dependencies: ['a'], devDependencies: ['b']
// 'a' package: dependencies: ['b']
// 'b' should be installed, even with --production
return runInstall({production: true}, 'install-production-transitive-dep', async (config) => {
assert.ok(
await fs.exists(path.join(config.cwd, 'node_modules', 'dep-b')),
);
});
});

test.concurrent("doesn't write new lockfile if existing one satisfied", (): Promise<void> => {
return runInstall({}, 'install-dont-write-lockfile-if-satisfied', async (config): Promise<void> => {
const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-offline-mirror=./mirror-for-offline
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"dep-a": "1.0.0"
},
"devDependencies": {
"dep-b": "1.0.0"
},
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
[email protected]:
version "1.0.0"
resolved dep-a-1.0.0.tar
dependencies:
dep-b "1.0.0"

[email protected]:
version "1.0.0"
resolved dep-b-1.0.0.tar
24 changes: 6 additions & 18 deletions src/package-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const semver = require('semver');
export default class PackageResolver {
constructor(config: Config, lockfile: Lockfile) {
this.patternsByPackage = map();
this.fetchingPatterns = map();
this.fetchingQueue = new BlockingQueue('resolver fetching');
this.newPatterns = [];
this.newPatterns = new Set();
this.patterns = map();
this.usedRegistries = new Set();
this.flat = false;
Expand All @@ -41,13 +40,8 @@ export default class PackageResolver {
end: () => void
};

// patterns we've already resolved or are in the process of resolving
fetchingPatterns: {
[key: string]: true
};

// new patterns that didn't exist in the lockfile
newPatterns: Array<string>;
newPatterns: Set<string>;

// TODO
fetchingQueue: BlockingQueue;
Expand Down Expand Up @@ -83,7 +77,7 @@ export default class PackageResolver {
*/

isNewPattern(pattern: string): boolean {
return this.newPatterns.indexOf(pattern) >= 0;
return this.newPatterns.has(pattern);
}

/**
Expand Down Expand Up @@ -269,7 +263,8 @@ export default class PackageResolver {
const ref = pkg._reference;
invariant(ref, 'expected package reference');
ref.patterns = [newPattern];
this.newPatterns.splice(this.newPatterns.indexOf(pattern), 1, newPattern);
this.newPatterns.delete(pattern);
this.newPatterns.add(newPattern);
this.addPattern(newPattern, pkg);
this.removePattern(pattern);
}
Expand Down Expand Up @@ -423,19 +418,12 @@ export default class PackageResolver {
*/

async find(req: DependencyRequestPattern): Promise<void> {
const fetchKey = `${req.registry}:${req.pattern}`;
if (this.fetchingPatterns[fetchKey]) {
return;
} else {
this.fetchingPatterns[fetchKey] = true;
}

if (this.activity) {
this.activity.tick(req.pattern);
}

if (!this.lockfile.getLocked(req.pattern, true)) {
this.newPatterns.push(req.pattern);
this.newPatterns.add(req.pattern);
}

const request = new PackageRequest(req, this);
Expand Down