Skip to content

Commit

Permalink
Add verbose flag - fixes #763
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian McKenzie committed Nov 22, 2016
1 parent 45a32e0 commit 9db7f65
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 98 deletions.
24 changes: 12 additions & 12 deletions __tests__/commands/_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ export async function run(
dir: string,
checkInitialized: ?(config: Config) => ?Promise<void>,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
24 changes: 12 additions & 12 deletions __tests__/commands/_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ export async function run(
beforeInstall: ?(cwd: string) => ?Promise<void>,
cleanupAfterInstall: boolean,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

if (beforeInstall) {
await beforeInstall(cwd);
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ test.concurrent('add with new dependency should be deterministic 3', (): Promise
return runAdd({}, [], 'install-should-cleanup-when-package-json-changed-3', async (config, reporter) => {
// expecting yarn check after installation not to fail

await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'));
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'), reporter);
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'), reporter);

const lockfile = await createLockfile(config.cwd);
const install = new Install({}, config, reporter, lockfile);
Expand Down
24 changes: 12 additions & 12 deletions __tests__/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ async function runGlobal(
name: string,
checkGlobal?: ?(config: Config, reporter: Reporter, out: string) => ?Promise<void>,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.JSONReporter({stdout});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.JSONReporter({stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
10 changes: 5 additions & 5 deletions __tests__/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ test.concurrent(
await fs.unlink(path.join(config.cwd, 'yarn.lock'));
await fs.unlink(path.join(config.cwd, 'package.json'));

await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'));
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'), reporter);
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'), reporter);

const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
Expand Down Expand Up @@ -434,8 +434,8 @@ test.concurrent(
await fs.unlink(path.join(config.cwd, 'yarn.lock'));
await fs.unlink(path.join(config.cwd, 'package.json'));

await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'));
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'yarn.lock.after'), path.join(config.cwd, 'yarn.lock'), reporter);
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'), reporter);

const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
Expand Down Expand Up @@ -614,7 +614,7 @@ test.concurrent('install should update a dependency to yarn and mirror (PR impor
'2.0.0',
);

await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'package.json.after'), path.join(config.cwd, 'package.json'), reporter);

const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
Expand Down
6 changes: 3 additions & 3 deletions __tests__/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ async function runList(
name: string,
checkList?: ?(config: Config, reporter: BufferReporter) => ?Promise<void>,
): Promise<void> {
const reporter = new reporters.BufferReporter({stdout: null, stdin: null});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
Expand All @@ -49,8 +51,6 @@ async function runList(

const out = '';

const reporter = new reporters.BufferReporter({stdout: null, stdin: null});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
24 changes: 12 additions & 12 deletions __tests__/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ async function runOutdated(
name: string,
checkOutdated?: ?(config: Config, reporter: Reporter, out: string) => ?Promise<void>,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.JSONReporter({stdout});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.JSONReporter({stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
24 changes: 12 additions & 12 deletions __tests__/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ async function runRemove(
name: string,
checkRemove?: ?(config: Config, reporter: Reporter) => ?Promise<void>,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.ConsoleReporter({stdout, stderr: stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
6 changes: 3 additions & 3 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ async function runRun(
name: string,
checkRun?: ?(config: Config, reporter: BufferReporter) => ?Promise<void>,
): Promise<void> {
const reporter = new reporters.BufferReporter({stdout: null, stdin: null});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
Expand All @@ -41,8 +43,6 @@ async function runRun(

const out = '';

const reporter = new reporters.BufferReporter({stdout: null, stdin: null});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
24 changes: 12 additions & 12 deletions __tests__/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ async function runUpgrade(
name: string,
checkUpgrade?: ?(config: Config, reporter: Reporter) => ?Promise<void>,
): Promise<void> {
let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.NoopReporter({stdout});

const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);
await fs.copy(dir, cwd, reporter);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.NoopReporter({stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
Expand Down
3 changes: 2 additions & 1 deletion __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import NoopReporter from '../src/reporters/base-reporter.js';
import makeTemp from './_temp';
import * as fs from '../src/util/fs.js';

Expand All @@ -15,7 +16,7 @@ async function execCommand(cmd: string, packageName: string): Promise<string> {
const srcPackageDir = path.join(fixturesLoc, packageName);
const packageDir = await makeTemp(packageName);

await fs.copy(srcPackageDir, packageDir);
await fs.copy(srcPackageDir, packageDir, new NoopReporter);

return new Promise((resolve, reject) => {
const env = Object.assign({}, process.env);
Expand Down
4 changes: 4 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ for (let i = 0; i < args.length; i++) {
// set global options
commander.version(pkg.version);
commander.usage('[command] [flags]');
commander.option('--verbose', 'output verbose messages on internal operations');
commander.option('--offline', 'trigger an error if any required dependencies are not available in local cache');
commander.option('--prefer-offline', 'use network only if dependencies are not available in local cache');
commander.option('--strict-semver');
Expand Down Expand Up @@ -185,6 +186,7 @@ if (commander.json) {
}
const reporter = new Reporter({
emoji: commander.emoji && process.stdout.isTTY && process.platform === 'darwin',
verbose: commander.verbose,
noProgress: !commander.progress,
});
reporter.initPeakMemoryCounter();
Expand Down Expand Up @@ -379,6 +381,8 @@ config.init({
return run().then(exit);
}
}).catch((err: Error) => {
reporter.verbose(err.stack);

if (err instanceof MessageError) {
reporter.error(err.message);
} else {
Expand Down
Loading

0 comments on commit 9db7f65

Please sign in to comment.