Skip to content

Commit

Permalink
fix: don't remove ignored builds list on repeat install (#9083)
Browse files Browse the repository at this point in the history
close #9045
  • Loading branch information
zkochan authored Feb 12, 2025
1 parent b60661a commit a5b36b7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/few-ducks-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/headless": patch
"@pnpm/build-modules": patch
"pnpm": patch
---

`pnpm approve-builds` should work after two consecutive `pnpm install` runs [#9083](https://github.com/pnpm/pnpm/pull/9083).
3 changes: 2 additions & 1 deletion exec/build-modules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export async function buildModules<T extends string> (
rootModulesDir: string
hoistedLocations?: Record<string, string[]>
}
): Promise<{ ignoredBuilds: string[] }> {
): Promise<{ ignoredBuilds?: string[] }> {
if (!rootDepPaths.length) return {}
const warn = (message: string) => {
logger.warn({ message, prefix: opts.lockfileDir })
}
Expand Down
7 changes: 7 additions & 0 deletions pkg-manager/headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
WANTED_LOCKFILE,
} from '@pnpm/constants'
import {
ignoredScriptsLogger,
packageManifestLogger,
progressLogger,
stageLogger,
Expand Down Expand Up @@ -46,6 +47,7 @@ import {
import { prune } from '@pnpm/modules-cleaner'
import {
type IncludedDependencies,
type Modules,
writeModulesManifest,
} from '@pnpm/modules-yaml'
import { type HoistingLimits } from '@pnpm/real-hoist'
Expand Down Expand Up @@ -174,6 +176,7 @@ export interface HeadlessOptions {
useLockfile?: boolean
supportedArchitectures?: SupportedArchitectures
hoistWorkspacePackages?: boolean
modulesFile?: Modules | null
}

export interface InstallationResultStats {
Expand Down Expand Up @@ -547,6 +550,10 @@ export async function headlessInstall (opts: HeadlessOptions): Promise<Installat
unsafePerm: opts.unsafePerm,
userAgent: opts.userAgent,
})).ignoredBuilds
if (ignoredBuilds == null && opts.modulesFile?.ignoredBuilds?.length) {
ignoredBuilds = opts.modulesFile.ignoredBuilds
ignoredScriptsLogger.debug({ packageNames: ignoredBuilds })
}
}

const projectsToBeBuilt = extendProjectsWithTargetDirs(selectedProjects, wantedLockfile, {
Expand Down
12 changes: 12 additions & 0 deletions pnpm/test/install/lifecycleScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,15 @@ test('throw an error when strict-dep-builds is true and there are ignored script
'@pnpm.e2e/pre-and-postinstall-scripts-example': '1.0.0',
})
})

test('the list of ignored builds is preserved after a repeat install', async () => {
const project = prepare({})
execPnpmSync(['add', '@pnpm.e2e/pre-and-postinstall-scripts-example@1.0.0', '--config.optimistic-repeat-install=false'])

const result = execPnpmSync(['install'])
// The warning is printed on repeat install too
expect(result.stdout.toString()).toContain('Ignored build scripts:')

const modulesManifest = project.readModulesManifest()
expect(modulesManifest?.ignoredBuilds).toStrictEqual(['@pnpm.e2e/pre-and-postinstall-scripts-example'])
})

0 comments on commit a5b36b7

Please # to comment.