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

Add name lookups to ls command - fixes #1599 #1643

Merged
merged 1 commit into from
Nov 3, 2016
Merged
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
27 changes: 26 additions & 1 deletion src/cli/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type Config from '../../config.js';
import type PackageResolver from '../../package-resolver.js';
import type PackageLinker from '../../package-linker.js';
import type {Trees} from '../../reporters/types.js';
import {MessageError} from '../../errors.js';
import {Install} from './install.js';
import Lockfile from '../../lockfile/wrapper.js';

const invariant = require('invariant');

export const requireLockfile = true;
export const noArguments = true;

function buildCount(trees: ?Trees): number {
if (!trees || !trees.length) {
Expand Down Expand Up @@ -136,6 +136,31 @@ export async function run(
const [depRequests, patterns] = await install.fetchRequestFromCwd();
await install.resolver.init(depRequests, install.flags.flat);

let filteredPatterns: Array<string> = [];

if (args.length) {
const matchedArgs: Array<string> = [];

for (const pattern of patterns) {
const pkg = install.resolver.getStrictResolvedPattern(pattern);

// ignore patterns if their package names have been specified in arguments
if (args.indexOf(pkg.name) >= 0) {
matchedArgs.push(pkg.name);
filteredPatterns.push(pattern);
}
}

// throw an error if any package names were passed to filter that don't exist
for (const arg of args) {
if (matchedArgs.indexOf(arg) < 0) {
throw new MessageError(reporter.lang('unknownPackage', arg));
}
}
} else {
filteredPatterns = patterns;
}

const {trees} = await buildTree(install.resolver, install.linker, patterns);
reporter.tree('ls', trees);
}