refactor: pass all configs to reporter during initialization

pnpm-default-reporter:

BREAKING CHANGE:

new API
This commit is contained in:
Zoltan Kochan
2018-08-13 22:43:56 +03:00
parent 9efe0950e1
commit 901c36e3f6
13 changed files with 352 additions and 112 deletions

View File

@@ -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,
}

View File

@@ -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<PnpmConfigs> => {
const packageManager = opts && opts.packageManager || {name: 'pnpm', version: 'undefined'}
const cliArgs = opts && opts.cliArgs || {}

View File

@@ -1,2 +0,0 @@
#!/usr/bin/env node
require('./lib/bin/pnpm-default-reporter')

View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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<supi.Log>('data', streamParser)
if (opts.context.argv[0] === 'server') {
const log$ = most.fromEvent<supi.Log>('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<string> {
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<most.Stream<most.Stream<{msg: string}>>> = 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)),

View File

@@ -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<most.Stream<most.Stream<{msg: string}>>> {
const width = opts.width || process.stdout.columns || 80
const outputs: Array<most.Stream<most.Stream<{msg: string}>>> = []
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<most.Stream<{msg: string}>>
@@ -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']}`,
{

View File

@@ -1,4 +1,5 @@
///<reference path="../typings/index.d.ts"/>
import {PnpmConfigs} from '@pnpm/config'
import logger, {
createStreamParser,
} from '@pnpm/logger'
@@ -40,7 +41,12 @@ const skippedOptionalDependencyLogger = logger<object>('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<string>
const stream$: most.Stream<string>[] = []
@@ -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'

View File

@@ -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;

View File

@@ -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)

View File

@@ -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

View File

@@ -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':