fix: print an info message when NODE_ENV is set to production (#4362)

close #4309
This commit is contained in:
Zoltan Kochan
2022-02-21 03:23:30 +02:00
parent 96df82be00
commit 5f00eb0e03
5 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---
When some dependency types are skipped, let the user know via the installation summary.

View File

@@ -27,6 +27,7 @@ export default function (
context: {
argv: string[]
config?: Config
env?: NodeJS.ProcessEnv
}
}
): () => void {
@@ -37,7 +38,13 @@ export default function (
return () => subscription.unsubscribe()
}
const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (process.stdout.columns && process.stdout.columns - 2) ?? 80
const output$ = toOutput$({ ...opts, reportingOptions: { ...opts.reportingOptions, outputMaxWidth } })
const output$ = toOutput$({
...opts,
reportingOptions: {
...opts.reportingOptions,
outputMaxWidth,
},
})
if (opts.reportingOptions?.appendOnly) {
const writeNext = opts.useStderr
? console.error.bind(console)
@@ -87,6 +94,7 @@ export function toOutput$ (
context: {
argv: string[]
config?: Config
env?: NodeJS.ProcessEnv
}
}
): Rx.Observable<string> {
@@ -217,6 +225,7 @@ export function toOutput$ (
appendOnly: opts.reportingOptions?.appendOnly,
cmd: opts.context.argv[0],
config: opts.context.config,
env: opts.context.env ?? process.env,
isRecursive: opts.context.config?.['recursive'] === true,
logLevel: opts.reportingOptions?.logLevel,
pnpmConfig: opts.context.config,

View File

@@ -47,6 +47,7 @@ export default function (
appendOnly?: boolean
cmd: string
config?: Config
env: NodeJS.ProcessEnv
isRecursive: boolean
logLevel?: LogLevel
pnpmConfig?: Config
@@ -107,6 +108,7 @@ export default function (
if (!opts.isRecursive) {
outputs.push(reportSummary(log$, {
cwd,
env: opts.env,
pnpmConfig: opts.pnpmConfig,
}))
}

View File

@@ -20,6 +20,12 @@ import {
REMOVED_CHAR,
} from './outputConstants'
const CONFIG_BY_DEP_TYPE = {
prod: 'production',
dev: 'dev',
optional: 'optional',
}
export default (
log$: {
deprecation: Rx.Observable<DeprecationLog>
@@ -29,6 +35,7 @@ export default (
},
opts: {
cwd: string
env: NodeJS.ProcessEnv
pnpmConfig?: Config
}
) => {
@@ -56,6 +63,13 @@ export default (
msg += EOL
msg += printDiffs(diffs, { prefix: opts.cwd })
msg += EOL
} else if (opts.pnpmConfig?.[CONFIG_BY_DEP_TYPE[depType]] === false) {
msg += EOL
msg += `${chalk.cyanBright(`${propertyByDependencyType[depType] as string}:`)} skipped`
if (opts.env.NODE_ENV === 'production' && depType === 'dev') {
msg += ' because NODE_ENV is set to production'
}
msg += EOL
}
}
return Rx.of({ msg })

View File

@@ -383,6 +383,80 @@ ${ADD} bar ${versionColor('2.0.0')}
})
})
test('in the installation summary report which dependency types are skipped', (done) => {
const prefix = '/home/jane/.nvs/node/10.0.0/x64/pnpm-global/1'
const output$ = toOutput$({
context: {
argv: ['install'],
config: {
dir: prefix,
production: true,
dev: false,
optional: false,
} as Config,
env: {
NODE_ENV: 'production',
},
},
streamParser: createStreamParser(),
})
packageManifestLogger.debug({
initial: {
name: 'foo',
version: '1.0.0',
dependencies: {
bar: '^2.0.0',
foo: '^1.0.0',
},
optionalDependencies: {
foo: '^1.0.0',
},
},
prefix,
})
rootLogger.debug({
added: {
dependencyType: 'prod',
id: 'registry.npmjs.org/bar/2.0.0',
name: 'bar',
realName: 'bar',
version: '2.0.0',
},
prefix,
})
packageManifestLogger.debug({
prefix,
updated: {
dependencies: {
bar: '^2.0.0',
},
optionalDependencies: {
foo: '^1.0.0',
},
},
})
summaryLogger.debug({ prefix })
expect.assertions(1)
output$.pipe(take(1), map(normalizeNewline)).subscribe({
complete: () => done(),
error: done,
next: output => {
expect(output).toBe(EOL + `\
${h1('dependencies:')}
${ADD} bar ${versionColor('2.0.0')}
${h1('optionalDependencies:')} skipped
${h1('devDependencies:')} skipped because NODE_ENV is set to production
`)
},
})
})
test('prints summary when some packages fail', (done) => {
const output$ = toOutput$({
context: { argv: ['run'], config: { recursive: true } as Config },