fix: improve how ignored lifecycle scripts are reported (#8899)

This commit is contained in:
Zoltan Kochan
2024-12-22 21:22:06 +01:00
committed by GitHub
parent e8c0ae354b
commit 516c4b301b
9 changed files with 46 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/core-loggers": minor
---
Add new logger for ignored scripts.

View File

@@ -0,0 +1,7 @@
---
"@pnpm/default-reporter": minor
"@pnpm/build-modules": minor
"pnpm": patch
---
Improve how packages with blocked lifecycle scripts are reported during installation. Always print the list of ignored scripts at the end of the output. Include a hint about how to allow the execution of those packages.

View File

@@ -137,6 +137,7 @@ export function toOutput$ (
const statsPushStream = new Rx.Subject<logs.StatsLog>()
const packageImportMethodPushStream = new Rx.Subject<logs.PackageImportMethodLog>()
const installCheckPushStream = new Rx.Subject<logs.InstallCheckLog>()
const ignoredScriptsPushStream = new Rx.Subject<logs.IgnoredScriptsLog>()
const registryPushStream = new Rx.Subject<logs.RegistryLog>()
const rootPushStream = new Rx.Subject<logs.RootLog>()
const packageManifestPushStream = new Rx.Subject<logs.PackageManifestLog>()
@@ -187,6 +188,9 @@ export function toOutput$ (
case 'pnpm:install-check':
installCheckPushStream.next(log)
break
case 'pnpm:ignored-scripts':
ignoredScriptsPushStream.next(log)
break
case 'pnpm:registry':
registryPushStream.next(log)
break
@@ -238,6 +242,7 @@ export function toOutput$ (
executionTime: Rx.from(executionTimePushStream),
hook: Rx.from(hookPushStream),
installCheck: Rx.from(installCheckPushStream),
ignoredScripts: Rx.from(ignoredScriptsPushStream),
lifecycle: Rx.from(lifecyclePushStream),
link: Rx.from(linkPushStream),
other,

View File

@@ -33,6 +33,7 @@ export function reporterForClient (
context: Rx.Observable<logs.ContextLog>
fetchingProgress: Rx.Observable<logs.FetchingProgressLog>
executionTime: Rx.Observable<logs.ExecutionTimeLog>
ignoredScripts: Rx.Observable<logs.IgnoredScriptsLog>
progress: Rx.Observable<logs.ProgressLog>
stage: Rx.Observable<logs.StageLog>
deprecation: Rx.Observable<logs.DeprecationLog>

View File

@@ -1,5 +1,6 @@
import path from 'path'
import {
type IgnoredScriptsLog,
type DeprecationLog,
type PackageManifestLog,
type RootLog,
@@ -37,6 +38,7 @@ export function reportSummary (
summary: Rx.Observable<SummaryLog>
root: Rx.Observable<RootLog>
packageManifest: Rx.Observable<PackageManifestLog>
ignoredScripts: Rx.Observable<IgnoredScriptsLog>
},
opts: {
cmd: string
@@ -53,11 +55,12 @@ export function reportSummary (
return Rx.combineLatest(
pkgsDiff$,
log$.ignoredScripts.pipe(Rx.startWith({ packageNames: undefined })),
summaryLog$
)
.pipe(
take(1),
map(([pkgsDiff]) => {
map(([pkgsDiff, ignoredScripts]) => {
let msg = ''
for (const depType of ['prod', 'optional', 'peer', 'dev', 'nodeModulesOnly'] as const) {
let diffs: PackageDiff[] = Object.values(pkgsDiff[depType as keyof typeof pkgsDiff])
@@ -82,6 +85,13 @@ export function reportSummary (
msg += EOL
}
}
if (ignoredScripts.packageNames && ignoredScripts.packageNames.length > 0) {
msg += EOL
msg += `The following dependencies have build scripts that were ignored: ${Array.from(ignoredScripts.packageNames).sort().join(', ')}`
msg += EOL
msg += 'To allow the execution of build scripts for these packages, add their names to "pnpm.onlyBuiltDependencies" in your "package.json", then run "pnpm rebuild"'
msg += EOL
}
return Rx.of({ msg })
})
)

View File

@@ -2,7 +2,7 @@ import assert from 'assert'
import path from 'path'
import util from 'util'
import { calcDepState, type DepsStateCache } from '@pnpm/calc-dep-state'
import { skippedOptionalDependencyLogger } from '@pnpm/core-loggers'
import { skippedOptionalDependencyLogger, ignoredScriptsLogger } from '@pnpm/core-loggers'
import { runPostinstallHooks } from '@pnpm/lifecycle'
import { linkBins, linkBinsOfPackages } from '@pnpm/link-bins'
import { logger } from '@pnpm/logger'
@@ -83,12 +83,7 @@ export async function buildModules<T extends string> (
)
})
await runGroups(opts.childConcurrency ?? 4, groups)
if (ignoredPkgs.size > 0) {
logger.info({
message: `The following dependencies have build scripts that were ignored: ${Array.from(ignoredPkgs).sort().join(', ')}`,
prefix: opts.lockfileDir,
})
}
ignoredScriptsLogger.debug({ packageNames: Array.from(ignoredPkgs) })
}
async function buildDependency<T extends string> (

View File

@@ -3,6 +3,7 @@ export * from './deprecationLogger'
export * from './fetchingProgressLogger'
export * from './hookLogger'
export * from './installCheckLogger'
export * from './ignoredScriptsLogger'
export * from './lifecycleLogger'
export * from './linkLogger'
export * from './packageImportMethodLogger'

View File

@@ -0,0 +1,12 @@
import {
type LogBase,
logger,
} from '@pnpm/logger'
export const ignoredScriptsLogger = logger('ignored-scripts')
export interface IgnoredScriptsMessage {
packageNames: string[]
}
export type IgnoredScriptsLog = { name: 'pnpm:ignored-scripts' } & LogBase & IgnoredScriptsMessage

View File

@@ -5,6 +5,7 @@ import {
type ExecutionTimeLog,
type HookLog,
type InstallCheckLog,
type IgnoredScriptsLog,
type LifecycleLog,
type LinkLog,
type PackageImportMethodLog,
@@ -31,6 +32,7 @@ export type Log =
| ExecutionTimeLog
| HookLog
| InstallCheckLog
| IgnoredScriptsLog
| LifecycleLog
| LinkLog
| PackageManifestLog