From 901c36e3f669c8af6c1bceaaeec81307d25e7c95 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 13 Aug 2018 22:43:56 +0300 Subject: [PATCH] refactor: pass all configs to reporter during initialization pnpm-default-reporter: BREAKING CHANGE: new API --- packages/config/src/PnpmConfigs.ts | 71 ++++++ packages/config/src/index.ts | 5 +- packages/default-reporter/bin.js | 2 - packages/default-reporter/package.json | 4 +- packages/default-reporter/shrinkwrap.yaml | 18 +- .../src/bin/pnpm-default-reporter.ts | 8 - packages/default-reporter/src/index.ts | 65 +++--- .../default-reporter/src/reporterForClient.ts | 25 +- packages/default-reporter/test/index.ts | 219 +++++++++++++++--- packages/default-reporter/typings/local.d.ts | 5 - packages/pnpm/src/cmd/link.ts | 3 +- packages/pnpm/src/main.ts | 4 +- packages/pnpm/src/reporter/index.ts | 35 +-- 13 files changed, 352 insertions(+), 112 deletions(-) create mode 100644 packages/config/src/PnpmConfigs.ts delete mode 100644 packages/default-reporter/bin.js delete mode 100644 packages/default-reporter/src/bin/pnpm-default-reporter.ts diff --git a/packages/config/src/PnpmConfigs.ts b/packages/config/src/PnpmConfigs.ts new file mode 100644 index 0000000000..df4ef30e21 --- /dev/null +++ b/packages/config/src/PnpmConfigs.ts @@ -0,0 +1,71 @@ +export interface PnpmConfigs { + bail: boolean, + cliArgs: object, + filter: string[], + rawNpmConfig: object, + globalPrefix: string, + globalBin: string, + dryRun?: boolean, // This option might be not supported ever + global?: boolean, + prefix: string, + bin?: string, + ignoreScripts?: boolean + save?: boolean, + saveProd?: boolean, + saveDev?: boolean, + saveOptional?: boolean, + scope: string, // TODO: deprecate this flag + production?: boolean, + development?: boolean, + fetchRetries?: number, + fetchRetryFactor?: number, + fetchRetryMintimeout?: number, + fetchRetryMaxtimeout?: number, + saveExact?: boolean, + savePrefix?: string, + force?: boolean, + depth?: number, + engineStrict?: boolean, + nodeVersion?: string, + offline?: boolean, + registry?: string, + optional?: boolean, + unsafePerm?: boolean, + loglevel?: 'silent' | 'error' | 'warn' | 'notice' | 'http' | 'timing' | 'info' | 'verbose' | 'silly', + + // proxy + proxy?: string, + httpsProxy?: string, + localAddress?: string, + + // ssl + cert?: string, + key?: string, + ca?: string, + strictSsl?: boolean, + + userAgent?: string, + tag?: string, + + alwaysAuth?: boolean, + + // pnpm specific configs + store?: string, + verifyStoreIntegrity?: boolean, + networkConcurrency?: number, + fetchingConcurrency?: number, + lockStaleDuration?: number, + lock: boolean, + childConcurrency?: number, + repeatInstallDepth?: number, + ignorePnpmfile?: boolean, + pnpmfile: string, + independentLeaves?: boolean, + packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'reflink', + shamefullyFlatten?: boolean, + shrinkwrapOnly?: boolean, // like npm's --package-lock-only + useStoreServer?: boolean, + workspaceConcurrency: number, + workspacePrefix?: string, + reporter?: string, +} diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 1a33d1a1ba..e73c1a7282 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -4,6 +4,9 @@ import camelcase = require('camelcase') import findUp = require('find-up') import path = require('path') import whichcb = require('which') +import {PnpmConfigs} from './PnpmConfigs' + +export {PnpmConfigs} const npmDefaults = loadNpmConf.defaults @@ -63,7 +66,7 @@ export default async ( version: string, }, }, -) => { +): Promise => { const packageManager = opts && opts.packageManager || {name: 'pnpm', version: 'undefined'} const cliArgs = opts && opts.cliArgs || {} diff --git a/packages/default-reporter/bin.js b/packages/default-reporter/bin.js deleted file mode 100644 index 855174a611..0000000000 --- a/packages/default-reporter/bin.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('./lib/bin/pnpm-default-reporter') diff --git a/packages/default-reporter/package.json b/packages/default-reporter/package.json index a0c97b583d..12bc61c6ac 100644 --- a/packages/default-reporter/package.json +++ b/packages/default-reporter/package.json @@ -5,10 +5,8 @@ "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ - "bin.js", "lib" ], - "bin": "bin.js", "scripts": { "lint": "tslint -c tslint.json --project .", "pretty-test": "preview && ts-node test | tap-diff", @@ -39,6 +37,7 @@ "supi": ">=0.22.0 <0.24.0" }, "dependencies": { + "@pnpm/config": "^1.3.1", "@types/common-tags": "^1.2.5", "@types/node": "^9.3.0 || 10", "@types/ramda": "0.25.34", @@ -49,7 +48,6 @@ "cli-cursor": "^2.1.0", "common-tags": "^1.4.0", "most": "^1.7.2", - "ndjson": "^1.5.0", "normalize-path": "^3.0.0", "pretty-bytes": "^5.0.0", "ramda": "^0.25.0", diff --git a/packages/default-reporter/shrinkwrap.yaml b/packages/default-reporter/shrinkwrap.yaml index 8cc4581fab..586f97948c 100644 --- a/packages/default-reporter/shrinkwrap.yaml +++ b/packages/default-reporter/shrinkwrap.yaml @@ -1,4 +1,5 @@ dependencies: + '@pnpm/config': 'link:../config' '@types/common-tags': 1.4.0 '@types/node': 10.5.8 '@types/ramda': 0.25.34 @@ -9,7 +10,6 @@ dependencies: cli-cursor: 2.1.0 common-tags: 1.8.0 most: 1.7.3 - ndjson: 1.5.0 normalize-path: 3.0.0 pnpm-default-reporter: 'link:' pretty-bytes: 5.1.0 @@ -429,6 +429,7 @@ packages: resolution: integrity: sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw== /core-util-is/1.0.2: + dev: true resolution: integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= /cross-spawn/6.0.5: @@ -768,6 +769,7 @@ packages: resolution: integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= /inherits/2.0.3: + dev: true resolution: integrity: sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= /is-arrayish/0.2.1: @@ -841,6 +843,7 @@ packages: resolution: integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== /isarray/1.0.0: + dev: true resolution: integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= /isexe/2.0.0: @@ -864,6 +867,7 @@ packages: resolution: integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw== /json-stringify-safe/5.0.1: + dev: true resolution: integrity: sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= /jsondiffpatch/0.1.43: @@ -1004,6 +1008,7 @@ packages: resolution: integrity: sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= /minimist/1.2.0: + dev: true resolution: integrity: sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= /mkdirp-promise/5.0.1: @@ -1059,6 +1064,7 @@ packages: minimist: 1.2.0 split2: 2.2.0 through2: 2.0.3 + dev: true hasBin: true resolution: integrity: sha1-rmA7NrE0vOw0e0UkIrC/mNWDLsg= @@ -1275,6 +1281,7 @@ packages: resolution: integrity: sha1-Pxjpd6m9jrN/zE/1ZZ176Qhos9g= /process-nextick-args/2.0.0: + dev: true resolution: integrity: sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw== /pump/1.0.3: @@ -1337,6 +1344,7 @@ packages: safe-buffer: 5.1.2 string_decoder: 1.1.1 util-deprecate: 1.0.2 + dev: true resolution: integrity: sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw== /redent/2.0.0: @@ -1400,6 +1408,7 @@ packages: resolution: integrity: sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w== /safe-buffer/5.1.2: + dev: true resolution: integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== /semver/5.5.0: @@ -1476,6 +1485,7 @@ packages: /split2/2.2.0: dependencies: through2: 2.0.3 + dev: true resolution: integrity: sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw== /sprintf-js/1.0.3: @@ -1531,6 +1541,7 @@ packages: /string_decoder/1.1.1: dependencies: safe-buffer: 5.1.2 + dev: true resolution: integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg== /strip-ansi/0.3.0: @@ -1685,6 +1696,7 @@ packages: dependencies: readable-stream: 2.3.6 xtend: 4.0.1 + dev: true resolution: integrity: sha1-AARWmzfHx0ujnEPzzteNGtlBQL4= /to-buffer/1.1.1: @@ -1779,6 +1791,7 @@ packages: resolution: integrity: sha512-h3Ii7ThTL7P5LlX1RuMPsuW4V5EZnLyjPwStIMQ4V0F6rblgmXIS+IkpAOu9THHDZYUO/D8TTJddVc6HIY4S5g== /util-deprecate/1.0.2: + dev: true resolution: integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= /validate-npm-package-license/3.0.4: @@ -1821,6 +1834,7 @@ packages: resolution: integrity: sha1-K2TIozAE1UuGmMdtWFp3zrYdoy8= /xtend/4.0.1: + dev: true engines: node: '>=0.4' resolution: @@ -1845,6 +1859,7 @@ registry: 'https://registry.npmjs.org/' shrinkwrapMinorVersion: 9 shrinkwrapVersion: 3 specifiers: + '@pnpm/config': ^1.3.1 '@pnpm/logger': ^2.1.0 '@types/common-tags': ^1.2.5 '@types/delay': ^2.0.1 @@ -1863,7 +1878,6 @@ specifiers: load-json-file: ^5.0.0 mos-tap-diff: ^1.0.0 most: ^1.7.2 - ndjson: ^1.5.0 normalize-newline: ^3.0.0 normalize-path: ^3.0.0 package-preview: ^1.0.0 diff --git a/packages/default-reporter/src/bin/pnpm-default-reporter.ts b/packages/default-reporter/src/bin/pnpm-default-reporter.ts deleted file mode 100644 index 59df1f55b8..0000000000 --- a/packages/default-reporter/src/bin/pnpm-default-reporter.ts +++ /dev/null @@ -1,8 +0,0 @@ -import ndjson = require('ndjson') -import reporter from '..' - -process.stdin.resume() -process.stdin.setEncoding('utf8') -const streamParser = process.stdin - .pipe(ndjson.parse()) -reporter(streamParser, {cmd: 'install'}) // TODO: make it smarter diff --git a/packages/default-reporter/src/index.ts b/packages/default-reporter/src/index.ts index 17704818a0..176095a1eb 100644 --- a/packages/default-reporter/src/index.ts +++ b/packages/default-reporter/src/index.ts @@ -1,3 +1,4 @@ +import {PnpmConfigs} from '@pnpm/config' import createDiffer = require('ansi-diff') import cliCursor = require('cli-cursor') import most = require('most') @@ -9,24 +10,27 @@ import reporterForClient from './reporterForClient' import reporterForServer from './reporterForServer' export default function ( - streamParser: object, opts: { - cmd: string, - subCmd?: string, - cwd?: string, - appendOnly?: boolean, - throttleProgress?: number, - width?: number, + streamParser: object, + reportingOptions?: { + appendOnly?: boolean, + throttleProgress?: number, + outputMaxWidth?: number, + }, + context: { + argv: string[], + configs?: PnpmConfigs, + }, }, ) { - if (opts.cmd === 'server') { - const log$ = most.fromEvent('data', streamParser) + if (opts.context.argv[0] === 'server') { + const log$ = most.fromEvent('data', opts.streamParser) reporterForServer(log$) return } - const width = opts.width || process.stdout.columns && process.stdout.columns - 2 || 80 - const output$ = toOutput$(streamParser, {...opts, width}) - if (opts.appendOnly) { + const outputMaxWidth = opts.reportingOptions && opts.reportingOptions.outputMaxWidth || process.stdout.columns && process.stdout.columns - 2 || 80 + const output$ = toOutput$({...opts, reportingOptions: {...opts.reportingOptions, outputMaxWidth}}) + if (opts.reportingOptions && opts.reportingOptions.appendOnly) { output$ .subscribe({ complete () {}, // tslint:disable-line:no-empty @@ -38,7 +42,7 @@ export default function ( cliCursor.hide() const diff = createDiffer({ height: process.stdout.rows, - width, + outputMaxWidth, }) output$ .subscribe({ @@ -52,14 +56,17 @@ export default function ( } export function toOutput$ ( - streamParser: object, opts: { - cmd: string, - subCmd?: string, - cwd?: string, - appendOnly?: boolean, - throttleProgress?: number, - width?: number, + streamParser: object, + reportingOptions?: { + appendOnly?: boolean, + throttleProgress?: number, + outputMaxWidth?: number, + }, + context: { + argv: string[], + configs?: PnpmConfigs, + }, }, ): most.Stream { opts = opts || {} @@ -79,7 +86,7 @@ export function toOutput$ ( const hookPushStream = new PushStream() const skippedOptionalDependencyPushStream = new PushStream() setTimeout(() => { // setTimeout is a workaround for a strange bug in most https://github.com/cujojs/most/issues/491 - streamParser['on']('data', (log: supi.Log) => { + opts.streamParser['on']('data', (log: supi.Log) => { switch (log.name) { case 'pnpm:progress': progressPushStream.next(log as supi.ProgressLog) @@ -151,17 +158,17 @@ export function toOutput$ ( const outputs: Array>> = reporterForClient( log$, { - appendOnly: opts.appendOnly, - cmd: opts.cmd, - cwd: opts.cwd || process.cwd(), - isRecursive: opts.cmd === 'recursive', - subCmd: opts.subCmd, - throttleProgress: opts.throttleProgress, - width: opts.width, + appendOnly: opts.reportingOptions && opts.reportingOptions.appendOnly, + cmd: opts.context.argv[0], + isRecursive: opts.context.argv[0] === 'recursive', + pnpmConfigs: opts.context.configs, + subCmd: opts.context.argv[1], + throttleProgress: opts.reportingOptions && opts.reportingOptions.throttleProgress, + width: opts.reportingOptions && opts.reportingOptions.outputMaxWidth, }, ) - if (opts.appendOnly) { + if (opts.reportingOptions && opts.reportingOptions.appendOnly) { return most.join( most.mergeArray(outputs) .map((log: most.Stream<{msg: string}>) => log.map((msg) => msg.msg)), diff --git a/packages/default-reporter/src/reporterForClient.ts b/packages/default-reporter/src/reporterForClient.ts index 66d8ac13ba..6ebf31fb08 100644 --- a/packages/default-reporter/src/reporterForClient.ts +++ b/packages/default-reporter/src/reporterForClient.ts @@ -1,3 +1,4 @@ +import {PnpmConfigs} from '@pnpm/config' import chalk from 'chalk' import most = require('most') import normalize = require('normalize-path') @@ -58,12 +59,12 @@ export default function ( width?: number, appendOnly?: boolean, throttleProgress?: number, - cwd: string, + pnpmConfigs?: PnpmConfigs, }, ): Array>> { const width = opts.width || process.stdout.columns || 80 const outputs: Array>> = [] - const cwd = opts.cwd || process.cwd() + const cwd = opts.pnpmConfigs && opts.pnpmConfigs.prefix || process.cwd() const resolutionDone$ = opts.isRecursive ? most.never() @@ -224,7 +225,7 @@ export default function ( } if (!opts.isRecursive) { - const pkgsDiff$ = getPkgsDiff(log$, {prefix: opts.cwd}) + const pkgsDiff$ = getPkgsDiff(log$, {prefix: cwd}) const summaryLog$ = log$.summary .take(1) @@ -238,7 +239,7 @@ export default function ( msg += EOL msg += chalk.cyanBright(`${propertyByDependencyType[depType]}:`) msg += EOL - msg += printDiffs(diffs, {prefix: opts.cwd}) + msg += printDiffs(diffs, {prefix: cwd}) msg += EOL } } @@ -257,13 +258,13 @@ export default function ( // print warnings only about deprecated packages from the root .filter((log) => log.depth === 0) .map((log) => { - if (!opts.isRecursive && log.prefix === opts.cwd) { + if (!opts.isRecursive && log.prefix === cwd) { return { msg: formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}: ${log.deprecated}`), } } return { - msg: zoomOut(opts.cwd, log.prefix, formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}`)), + msg: zoomOut(cwd, log.prefix, formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}`)), } }) .map(most.of) @@ -274,7 +275,7 @@ export default function ( miscOutput( most.merge(log$.link, log$.registry, log$.other), { - cwd: opts.cwd, + cwd, zoomOutCurrent: opts.isRecursive, }, ), @@ -284,7 +285,7 @@ export default function ( ? log$.stats : log$.stats.filter((log) => log.prefix !== cwd) outputs.push(statsForNotCurrentPackage(stats$, { - currentPrefix: opts.cwd, + currentPrefix: cwd, subCmd: opts.subCmd, width, })) @@ -292,13 +293,13 @@ export default function ( if (!opts.isRecursive) { outputs.push(statsForCurrentPackage(log$.stats, { cmd: opts.cmd, - currentPrefix: opts.cwd, + currentPrefix: cwd, width, })) } const installCheckOutput$ = log$.installCheck - .map(formatInstallCheck.bind(null, opts.cwd)) + .map(formatInstallCheck.bind(null, cwd)) .filter(Boolean) .map((msg) => ({msg})) .map(most.of) as most.Stream> @@ -307,7 +308,7 @@ export default function ( outputs.push( log$.skippedOptionalDependency - .filter((log) => Boolean(log['prefix'] === opts.cwd && log.parents && log.parents.length === 0)) + .filter((log) => Boolean(log['prefix'] === cwd && log.parents && log.parents.length === 0)) .map((log) => most.of({ msg: `info: ${ log.package['id'] || log.package.name && (`${log.package.name}@${log.package.version}`) || log.package['pref'] @@ -318,7 +319,7 @@ export default function ( const hookOutput$ = log$.hook .map((log) => ({ msg: autozoom( - opts.cwd, + cwd, log['prefix'], `${chalk.magentaBright(log['hook'])}: ${log['message']}`, { diff --git a/packages/default-reporter/test/index.ts b/packages/default-reporter/test/index.ts index 6f291f2fa0..729e77bb2c 100644 --- a/packages/default-reporter/test/index.ts +++ b/packages/default-reporter/test/index.ts @@ -1,4 +1,5 @@ /// +import {PnpmConfigs} from '@pnpm/config' import logger, { createStreamParser, } from '@pnpm/logger' @@ -40,7 +41,12 @@ const skippedOptionalDependencyLogger = logger('skipped-optional-depende const EOL = '\n' test('prints progress beginning', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['install'], + }, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -61,7 +67,13 @@ test('prints progress beginning', t => { }) test('prints progress beginning when appendOnly is true', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', appendOnly: true}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + reportingOptions: { + appendOnly: true, + }, + context: {argv: ['install']}, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -82,7 +94,10 @@ test('prints progress beginning when appendOnly is true', t => { }) test('prints progress beginning during recursive install', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['recursive']}, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -103,7 +118,11 @@ test('prints progress beginning during recursive install', t => { }) test('prints progress on first download', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', throttleProgress: 0}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {throttleProgress: 0}, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -129,7 +148,11 @@ test('prints progress on first download', t => { test('moves fixed line to the end', async t => { const prefix = process.cwd() - const output$ = toOutput$(createStreamParser(), {cmd: 'install', throttleProgress: 0}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {throttleProgress: 0}, + }) output$.skip(3).take(1).map(normalizeNewline).subscribe({ next: output => { @@ -161,7 +184,10 @@ test('moves fixed line to the end', async t => { }) test('prints "Already up-to-date"', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const prefix = process.cwd() @@ -183,7 +209,13 @@ test('prints "Already up-to-date"', t => { test('prints summary (of current package only)', t => { const prefix = '/home/jane/project' - const output$ = toOutput$(createStreamParser(), {cmd: 'install', cwd: prefix}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['install'], + configs: {prefix} as PnpmConfigs, + }, + }) statsLogger.debug({ added: 5, prefix: `${prefix}/packages/foo` }) statsLogger.debug({ removed: 1, prefix: `${prefix}/packages/foo` }) @@ -346,7 +378,11 @@ test('prints summary (of current package only)', t => { }) test('groups lifecycle output', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', width: 79}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {outputMaxWidth: 79}, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -442,7 +478,10 @@ test('groups lifecycle output', t => { // Many libs use stderr for logging, so showing all stderr adds not much value test['skip']('prints lifecycle progress', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' @@ -488,7 +527,10 @@ test['skip']('prints lifecycle progress', t => { }) test('prints generic error', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const err = new Error('some error') logger.error(err) @@ -508,7 +550,10 @@ test('prints generic error', t => { }) test('prints generic error when recursive install fails', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['recursive']}, + }) const err = new Error('some error') err['prefix'] = '/home/src/' @@ -530,7 +575,10 @@ test('prints generic error when recursive install fails', t => { }) test('prints no matching version error when many dist-tags exist', async (t) => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) t.plan(1) @@ -560,7 +608,10 @@ test('prints no matching version error when many dist-tags exist', async (t) => }) test('prints no matching version error when only the latest dist-tag exists', async (t) => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) t.plan(1) @@ -585,7 +636,10 @@ test('prints no matching version error when only the latest dist-tag exists', as }) test('prints summary when some packages fail', async (t) => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['recursive']}, + }) t.plan(1) @@ -650,7 +704,10 @@ test('prints summary when some packages fail', async (t) => { }) test('prints info', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) logger.info({message: 'info message', prefix: process.cwd()}) @@ -668,7 +725,11 @@ test('prints info', t => { test('prints progress of big files download', async t => { t.plan(6) - let output$ = toOutput$(createStreamParser(), {cmd: 'install', throttleProgress: 0}) + let output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {throttleProgress: 0}, + }) .map(normalizeNewline) as most.Stream const stream$: most.Stream[] = [] @@ -806,7 +867,10 @@ test('prints progress of big files download', async t => { }) test('prints added/removed stats during installation', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const prefix = process.cwd() statsLogger.debug({ added: 5, prefix }) @@ -827,7 +891,10 @@ test('prints added/removed stats during installation', t => { }) test('prints added/removed stats during installation when 0 removed', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const prefix = process.cwd() statsLogger.debug({ added: 2, prefix }) @@ -848,7 +915,10 @@ test('prints added/removed stats during installation when 0 removed', t => { }) test('prints only the added stats if nothing was removed', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 0, prefix }) @@ -869,7 +939,10 @@ test('prints only the added stats if nothing was removed', t => { }) test('prints only the removed stats if nothing was added', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 1, prefix }) @@ -890,7 +963,11 @@ test('prints only the removed stats if nothing was added', t => { }) test('prints only the added stats if nothing was removed and a lot added', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', width: 20}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {outputMaxWidth: 20}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 0, prefix }) @@ -911,7 +988,11 @@ test('prints only the added stats if nothing was removed and a lot added', t => }) test('prints only the removed stats if nothing was added and a lot removed', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', width: 20}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {outputMaxWidth: 20}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 100, prefix }) @@ -932,7 +1013,11 @@ test('prints only the removed stats if nothing was added and a lot removed', t = }) test('prints at least one remove sign when removed !== 0', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', width: 20}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {outputMaxWidth: 20}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 1, prefix }) @@ -953,7 +1038,11 @@ test('prints at least one remove sign when removed !== 0', t => { }) test('prints at least one add sign when added !== 0', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', width: 20}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['install']}, + reportingOptions: {outputMaxWidth: 20}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 100, prefix }) @@ -974,7 +1063,10 @@ test('prints at least one add sign when added !== 0', t => { }) test('prints just removed during uninstallation', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'uninstall'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: {argv: ['uninstall']}, + }) const prefix = process.cwd() statsLogger.debug({ removed: 4, prefix }) @@ -995,7 +1087,13 @@ test('prints just removed during uninstallation', t => { test('prints added/removed stats and warnings during recursive installation', t => { const rootPrefix = '/home/jane/repo' - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', cwd: rootPrefix}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: rootPrefix} as PnpmConfigs, + }, + }) logger.warn({ message: 'Some issue', prefix: '/home/jane/repo/pkg-5' }) logger.warn({ message: 'Some other issue', prefix: rootPrefix }) @@ -1050,7 +1148,14 @@ test('prints added/removed stats and warnings during recursive installation', t }) test('recursive installation: prints only the added stats if nothing was removed and a lot added', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', width: 60, cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + reportingOptions: {outputMaxWidth: 60}, + }) statsLogger.debug({ removed: 0, prefix: '/home/jane/repo/pkg-1' }) statsLogger.debug({ added: 190, prefix: '/home/jane/repo/pkg-1' }) @@ -1069,7 +1174,14 @@ test('recursive installation: prints only the added stats if nothing was removed }) test('recursive installation: prints only the removed stats if nothing was added and a lot removed', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', width: 60, cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + reportingOptions: {outputMaxWidth: 60}, + }) statsLogger.debug({ removed: 190, prefix: '/home/jane/repo/pkg-1' }) statsLogger.debug({ added: 0, prefix: '/home/jane/repo/pkg-1' }) @@ -1088,7 +1200,14 @@ test('recursive installation: prints only the removed stats if nothing was added }) test('recursive installation: prints at least one remove sign when removed !== 0', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', width: 62, cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + reportingOptions: {outputMaxWidth: 62}, + }) statsLogger.debug({ removed: 1, prefix: '/home/jane/repo/pkg-1' }) statsLogger.debug({ added: 100, prefix: '/home/jane/repo/pkg-1' }) @@ -1107,7 +1226,14 @@ test('recursive installation: prints at least one remove sign when removed !== 0 }) test('recursive installation: prints at least one add sign when added !== 0', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', width: 62, cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + reportingOptions: {outputMaxWidth: 62}, + }) statsLogger.debug({ removed: 100, prefix: '/home/jane/repo/pkg-1' }) statsLogger.debug({ added: 1, prefix: '/home/jane/repo/pkg-1' }) @@ -1126,7 +1252,14 @@ test('recursive installation: prints at least one add sign when added !== 0', t }) test('recursive uninstall: prints removed packages number', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', subCmd: 'uninstall', width: 62, cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive', 'uninstall'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + reportingOptions: {outputMaxWidth: 62}, + }) statsLogger.debug({ removed: 1, prefix: '/home/jane/repo/pkg-1' }) @@ -1144,7 +1277,13 @@ test('recursive uninstall: prints removed packages number', t => { }) test('install: print hook message', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'install', cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['install'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + }) hookLogger.debug({ from: '/home/jane/repo/pnpmfile.js', @@ -1167,7 +1306,13 @@ test('install: print hook message', t => { }) test('recursive: print hook message', t => { - const output$ = toOutput$(createStreamParser(), {cmd: 'recursive', cwd: '/home/jane/repo'}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['recursive'], + configs: {prefix: '/home/jane/repo'} as PnpmConfigs, + }, + }) hookLogger.debug({ from: '/home/jane/repo/pnpmfile.js', @@ -1191,7 +1336,13 @@ test('recursive: print hook message', t => { test('prints skipped optional dependency info message', t => { const prefix = process.cwd() - const output$ = toOutput$(createStreamParser(), {cmd: 'install', cwd: prefix}) + const output$ = toOutput$({ + streamParser: createStreamParser(), + context: { + argv: ['install'], + configs: {prefix} as PnpmConfigs, + }, + }) const pkgId = 'registry.npmjs.org/foo/1.0.0' diff --git a/packages/default-reporter/typings/local.d.ts b/packages/default-reporter/typings/local.d.ts index 2f737b0acd..8abe2e10b2 100644 --- a/packages/default-reporter/typings/local.d.ts +++ b/packages/default-reporter/typings/local.d.ts @@ -8,11 +8,6 @@ declare module 'cli-cursor' { export = anything; } -declare module 'ndjson' { - const anything: any; - export = anything; -} - declare module 'normalize-newline' { const anything: any; export = anything; diff --git a/packages/pnpm/src/cmd/link.ts b/packages/pnpm/src/cmd/link.ts index a2cb85a7ff..69824e177d 100644 --- a/packages/pnpm/src/cmd/link.ts +++ b/packages/pnpm/src/cmd/link.ts @@ -5,6 +5,7 @@ import pathAbsolute = require('path-absolute') import R = require('ramda') import { install, + InstallOptions, link, linkToGlobal, } from 'supi' @@ -64,7 +65,7 @@ export default async ( ...await getConfigs({...opts.cliArgs, prefix}, {excludeReporter: true}), store: s.path, storeController: s.ctrl, - }) + } as InstallOptions) })), ) await link(pkgPaths, path.join(cwd, 'node_modules'), linkOpts) diff --git a/packages/pnpm/src/main.ts b/packages/pnpm/src/main.ts index 6b9ac451e2..afcfe61625 100644 --- a/packages/pnpm/src/main.ts +++ b/packages/pnpm/src/main.ts @@ -183,13 +183,13 @@ export default async function run (argv: string[]) { initReporter(reporterType, { cmd, - prefix: opts.prefix, + pnpmConfigs: opts, subCmd: cliConf.argv.remain[1] && getCommandFullName(cliConf.argv.remain[1]), }) delete opts.reporter // This is a silly workaround because supi expects a function as opts.reporter if (selfUpdate) { - await pnpmCmds.server(['stop'], opts) + await pnpmCmds.server(['stop'], opts as any) // tslint:disable-line:no-any } // NOTE: we defer the next stage, otherwise reporter might not catch all the logs diff --git a/packages/pnpm/src/reporter/index.ts b/packages/pnpm/src/reporter/index.ts index 7f0b86e0d9..b83af48ef5 100644 --- a/packages/pnpm/src/reporter/index.ts +++ b/packages/pnpm/src/reporter/index.ts @@ -1,3 +1,4 @@ +import {PnpmConfigs} from '@pnpm/config' import {streamParser, writeToConsole} from '@pnpm/logger' import defaultReporter from 'pnpm-default-reporter' import silentReporter from './silentReporter' @@ -9,26 +10,34 @@ export default ( opts: { cmd: string, subCmd: string, - prefix: string, + pnpmConfigs: PnpmConfigs, }, ) => { switch (reporterType) { case 'default': - defaultReporter(streamParser, { - appendOnly: false, - cmd: opts.cmd, - cwd: opts.prefix, - subCmd: opts.subCmd, - throttleProgress: 200, + defaultReporter({ + context: { + argv: [opts.cmd, opts.subCmd], + configs: opts.pnpmConfigs, + }, + reportingOptions: { + appendOnly: false, + throttleProgress: 200, + }, + streamParser, }) return case 'append-only': - defaultReporter(streamParser, { - appendOnly: true, - cmd: opts.cmd, - cwd: opts.prefix, - subCmd: opts.subCmd, - throttleProgress: 1000, + defaultReporter({ + context: { + argv: [opts.cmd, opts.subCmd], + configs: opts.pnpmConfigs, + }, + reportingOptions: { + appendOnly: true, + throttleProgress: 1000, + }, + streamParser, }) return case 'ndjson':