Skip to content

Commit

Permalink
refactor how we rehydrate an install instance fixing the --production…
Browse files Browse the repository at this point in the history
… flag in yarn licenses - fixes #1103
  • Loading branch information
Sebastian McKenzie committed Oct 15, 2016
1 parent 7de47e5 commit 232351c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/cli/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function run(
}

// get patterns that are installed when running `yarn install`
const [depRequests, rawPatterns] = await install.fetchRequestFromCwd();
const [, rawPatterns] = await install.hydrate();

// check if patterns exist in lockfile
for (const pattern of rawPatterns) {
Expand All @@ -62,10 +62,6 @@ export async function run(
reportError("Couldn't find an integrity hash file");
}
} else {
// seed resolver
await install.resolver.init(depRequests, install.flags.flat);
await install.flatten(rawPatterns);

// check if any of the node_modules are out of sync
const res = await install.linker.getFlatHoistedTree(rawPatterns);
for (const [loc, {originalKey, pkg}] of res) {
Expand Down
29 changes: 29 additions & 0 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,35 @@ export class Install {

return crypto.hash(opts.join('-'), 'sha256');
}

/**
* Load the dependency graph of the current install. Only does package resolving and wont write to the cwd.
*/

async hydrate(fetch?: boolean): Promise<InstallCwdRequest> {
const request = await this.fetchRequestFromCwd();
const [depRequests, rawPatterns] = request;

await this.resolver.init(depRequests, this.flags.flat);
await this.flatten(rawPatterns);

if (fetch) {
// fetch packages, should hit cache most of the time
await this.fetcher.init();

// expand minimal manifests
for (const manifest of this.resolver.getManifests()) {
const ref = manifest._reference;
invariant(ref, 'expected reference');

const loc = this.config.generateHardModulePath(ref);
const newPkg = await this.config.readManifest(loc);
await this.resolver.updateManifest(ref, newPkg);
}
}

return request;
}
}

export function _setFlags(commander: Object) {
Expand Down
11 changes: 10 additions & 1 deletion src/cli/commands/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export function setFlags(commander: Object) {
async function getManifests(config: Config, flags: Object): Promise<Array<Manifest>> {
const lockfile = await Lockfile.fromDirectory(config.cwd);
const install = new Install({skipIntegrity: true, ...flags}, config, new NoopReporter(), lockfile);
await install.init();
await install.hydrate(true);

let manifests = install.resolver.getManifests();

// sort by name
manifests = manifests.sort(function(a, b): number {
if (!a.name && !b.name) {
return 0;
Expand All @@ -40,6 +42,13 @@ async function getManifests(config: Config, flags: Object): Promise<Array<Manife

return a.name.localeCompare(b.name);
});

// filter ignored manifests
manifests = manifests.filter((manifest: Manifest): boolean => {
const ref = manifest._reference;
return !!ref && !ref.ignore;
});

return manifests;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ if (outputWrapper) {
reporter.header(commandName, pkg);
}

if (command.noArguments && args.length) {
if (command.noArguments && commander.args.length) {
reporter.error(reporter.lang('noArguments'));
reporter.info(getDocsInfo(commandName));
process.exit(1);
Expand Down

0 comments on commit 232351c

Please sign in to comment.