mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
5
.changeset/mean-spies-rhyme.md
Normal file
5
.changeset/mean-spies-rhyme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lifecycle": minor
|
||||
---
|
||||
|
||||
Added an option for silent execution: opts.silent.
|
||||
6
.changeset/wet-planes-do.md
Normal file
6
.changeset/wet-planes-do.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`run --silent <cmd>` should only print output of the command and nothing from pnpm.
|
||||
@@ -112,7 +112,7 @@ export interface HeadlessOptions {
|
||||
|
||||
export default async (opts: HeadlessOptions) => {
|
||||
const reporter = opts.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ export default async (opts: HeadlessOptions) => {
|
||||
)
|
||||
}
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export type RunLifecycleHookOptions = {
|
||||
pkgRoot: string,
|
||||
rawConfig: object,
|
||||
rootModulesDir: string,
|
||||
silent?: boolean,
|
||||
stdio?: string,
|
||||
unsafePerm: boolean,
|
||||
}
|
||||
@@ -44,7 +45,9 @@ export default async function runLifecycleHook (
|
||||
wd: opts.pkgRoot,
|
||||
})
|
||||
}
|
||||
return lifecycle(m, stage, opts.pkgRoot, {
|
||||
const logLevel = (opts.stdio !== 'inherit' || opts.silent)
|
||||
? 'silent' : undefined
|
||||
await lifecycle(m, stage, opts.pkgRoot, {
|
||||
config: opts.rawConfig,
|
||||
dir: opts.rootModulesDir,
|
||||
extraBinPaths: opts.extraBinPaths || [],
|
||||
@@ -52,7 +55,7 @@ export default async function runLifecycleHook (
|
||||
log: {
|
||||
clearProgress: noop,
|
||||
info: noop,
|
||||
level: opts.stdio === 'inherit' ? undefined : 'silent',
|
||||
level: logLevel,
|
||||
pause: noop,
|
||||
resume: noop,
|
||||
showProgress: noop,
|
||||
|
||||
@@ -84,7 +84,7 @@ export async function rebuildPkgs (
|
||||
maybeOpts: RebuildOptions
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
@@ -129,7 +129,7 @@ export async function rebuild (
|
||||
maybeOpts: RebuildOptions
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
|
||||
@@ -99,7 +99,7 @@ For options that may be used with \`-r\`, see "pnpm help recursive"`,
|
||||
export type RunOpts =
|
||||
& Omit<RecursiveRunOpts, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>
|
||||
& { recursive?: boolean }
|
||||
& Pick<Config, 'dir' | 'engineStrict'>
|
||||
& Pick<Config, 'dir' | 'engineStrict' | 'reporter'>
|
||||
& (
|
||||
& { recursive?: false }
|
||||
& Partial<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>>
|
||||
@@ -136,6 +136,7 @@ export async function handler (
|
||||
pkgRoot: dir,
|
||||
rawConfig: opts.rawConfig,
|
||||
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
|
||||
silent: opts.reporter === 'silent',
|
||||
stdio: 'inherit',
|
||||
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export default async function (
|
||||
}
|
||||
) {
|
||||
const reporter = opts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export default async function (
|
||||
}
|
||||
}))
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ export default async function (
|
||||
}
|
||||
) {
|
||||
const reporter = opts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
await opts.storeController.prune()
|
||||
await opts.storeController.close()
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import extendOptions, {
|
||||
|
||||
export default async function (maybeOpts: StoreStatusOptions) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
@@ -51,7 +51,7 @@ export default async function (maybeOpts: StoreStatusOptions) {
|
||||
return (await dint.check(path.join(virtualStoreDir, pkgIdToFilename(depPath, opts.dir), 'node_modules', name), files)) === false
|
||||
})
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ export default function err (error: Error) {
|
||||
console.log(error)
|
||||
process.exit(1)
|
||||
}
|
||||
if (global['reporterInitialized'] === 'silent') {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// bole passes only the name, message and stack of an error
|
||||
// that is why we pass error as a message as well, to pass
|
||||
|
||||
@@ -123,8 +123,7 @@ export default async function run (inputArgv: string[]) {
|
||||
cmd,
|
||||
config,
|
||||
})
|
||||
global['reporterInitialized'] = true
|
||||
delete config.reporter // This is a silly workaround because supi expects a function as config.reporter
|
||||
global['reporterInitialized'] = reporterType
|
||||
|
||||
if (selfUpdate) {
|
||||
await pnpmCmds.server(config as any, ['stop']) // tslint:disable-line:no-any
|
||||
|
||||
@@ -75,3 +75,15 @@ test('install-test: install dependencies and runs tests', async (t: tape.Test) =
|
||||
'posttest',
|
||||
])
|
||||
})
|
||||
|
||||
test('silent run only prints the output of the child process', async (t: tape.Test) => {
|
||||
prepare(t, {
|
||||
scripts: {
|
||||
hi: 'echo hi && exit 1',
|
||||
},
|
||||
})
|
||||
|
||||
const result = execPnpmSync(['run', '--silent', 'hi'])
|
||||
|
||||
t.ok(result.stdout.toString().trim() === 'hi')
|
||||
})
|
||||
|
||||
@@ -130,7 +130,7 @@ export async function mutateModules (
|
||||
}
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export async function mutateModules (
|
||||
|
||||
const result = await _install()
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function link (
|
||||
}
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
@@ -164,7 +164,7 @@ export default async function link (
|
||||
|
||||
summaryLogger.debug({ prefix: opts.dir })
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ export async function linkFromGlobal (
|
||||
maybeOpts: LinkOptions & {globalDir: string}
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
@@ -216,7 +216,7 @@ export async function linkFromGlobal (
|
||||
const linkFromPkgs = pkgNames.map((pkgName) => path.join(globalPkgPath, 'node_modules', pkgName))
|
||||
const newManifest = await link(linkFromPkgs, path.join(linkTo, 'node_modules'), opts)
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ export async function linkToGlobal (
|
||||
}
|
||||
) {
|
||||
const reporter = maybeOpts?.reporter
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
maybeOpts.lockfileDir = maybeOpts.lockfileDir || maybeOpts.globalDir
|
||||
@@ -243,7 +243,7 @@ export async function linkToGlobal (
|
||||
linkToBin: maybeOpts.globalBin,
|
||||
})
|
||||
|
||||
if (reporter) {
|
||||
if (reporter && typeof reporter === 'function') {
|
||||
streamParser.removeListener('data', reporter)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user