Unify repeat-install freshness and `verifyDepsBeforeRun` validation across pnpm v11 and v12 (Closes pnpm/tasks#161, pnpm/tasks#157, pnpm/tasks#148): 1. Centralize v11 workspace state updates in `@pnpm/workspace.state` (`preserveCarriedSettings`) and `@pnpm/installing.commands` (`workspaceStateUpdate.ts`), preserving carried `dev`/`optional`/`production` settings when `ignoredWorkspaceStateSettings` ignores them and preserving v12-recorded `autoDedupe`. A filtered install that prunes direct dependencies no longer records the workspace root as installed. 2. Hold `{.}...` workspace dependencies for non-recursive `pnpm run`, `pnpm exec`, and `pnpm restart` inside a workspace project in v11 (`selectProjectsToVerify.ts`). 3. Align v11 recorded validation (`checkRecordedWorkspace`) and legacy unrecorded validation (`checkModifiedSinceLastValidation`) in `@pnpm/deps.status` with v12's `check_freshness`, including empty-project handling, `dedupeDirectDeps`, `dedupePeerDependents`, `autoInstallPeers`, `excludeLinksFromLockfile`, catalog/override config comparison, and `opts.lockfileDir` resolution. 4. Forward effective CLI flags (`--lockfile-dir`, `--modules-dir`, `--virtual-store-dir`, `--store-dir`, `--dir`, `--workspace-root`, `--prod`, `--dev`, `--no-optional`, `--filter`, `--filter-prod`, `--test-pattern`, `--changed-files-ignore-pattern`, and `--config.*`) when `verifyDepsBeforeRun: install` spawns `pnpm install` in both v11 and v12. 5. Align `GatePolicy::dedupe_peers` and empty-project predicates in v12 `pnpm-package-manager`, and run `repeat_install_oracle.rs` across v12, v11, and mixed v11/v12 writers in CI, with a longer nextest period for the peer convergence harness that shares the job. 6. Parse `--config.<key>=<value>` with the type the command declares for `<key>` in v11, so the list and number options forwarded to the spawned install arrive as lists and numbers; forward `--npmrc-auth-file` in v11 and `--test-pattern` / `--changed-files-ignore-pattern` in v12, so both forward the same set; and skip the current-lockfile read for a project whose manifest changed but whose lockfile did not, as v12 does. 7. Resolve relative v11 store overrides against the workspace or project root before forwarding them to the spawned install. Remove the isolated linker's duplicate package merge so filtered installs retain unselected dependencies and drop obsolete selected dependencies from the current lockfile. Cover both cases with CLI regressions. The restore API also handles a selected project absent from the previous current lockfile. 8. Record workspace validation from the projects the installers actually processed. Ignored projects receive no new proof, and empty or entirely ignored selections leave state untouched. Cover both lockfile modes and an ignored workspace root.
64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { expect, test } from '@jest/globals'
|
|
import { preparePackages } from '@pnpm/prepare'
|
|
import { filterProjectsBySelectorObjectsFromDir } from '@pnpm/workspace.projects-filter'
|
|
import type { WorkspaceState } from '@pnpm/workspace.state'
|
|
import { loadJsonFileSync } from 'load-json-file'
|
|
|
|
import { recursiveInstallThenUpdateWorkspaceState } from '../src/workspaceStateUpdate.js'
|
|
import { DEFAULT_OPTS } from './utils/index.js'
|
|
|
|
test.each([
|
|
[true, false],
|
|
[false, false],
|
|
[true, true],
|
|
[false, true],
|
|
])('an empty workspace install does not record installation proof (shared lockfile: %s, ignored: %s)', async (sharedWorkspaceLockfile, ignored) => {
|
|
preparePackages([
|
|
{ location: '.', package: { name: 'root', version: '1.0.0' } },
|
|
{ name: 'child', version: '1.0.0', dependencies: { 'is-positive': '1.0.0' } },
|
|
])
|
|
const { allProjects, allProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
await recursiveInstallThenUpdateWorkspaceState(allProjects, [], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
allProjectsGraph,
|
|
lockfileDir: sharedWorkspaceLockfile ? process.cwd() : undefined,
|
|
selectedProjectsGraph: ignored ? allProjectsGraph : {},
|
|
ignoredPackages: ignored ? new Set(Object.keys(allProjectsGraph)) : undefined,
|
|
sharedWorkspaceLockfile,
|
|
workspaceDir: process.cwd(),
|
|
}, 'install')
|
|
|
|
expect(fs.existsSync(path.resolve('node_modules/.pnpm-workspace-state-v1.json'))).toBe(false)
|
|
})
|
|
|
|
test.each([
|
|
[true, false],
|
|
[false, false],
|
|
[true, true],
|
|
[false, true],
|
|
])('ignored projects receive no installation proof (shared lockfile: %s, ignored root: %s)', async (sharedWorkspaceLockfile, ignoredRoot) => {
|
|
preparePackages([
|
|
{ location: '.', package: { name: 'root', version: '1.0.0' } },
|
|
{ name: 'child', version: '1.0.0', dependencies: { 'is-positive': '1.0.0' } },
|
|
])
|
|
const { allProjects, allProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
await recursiveInstallThenUpdateWorkspaceState(allProjects, [], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
allProjectsGraph,
|
|
lockfileDir: sharedWorkspaceLockfile ? process.cwd() : undefined,
|
|
selectedProjectsGraph: allProjectsGraph,
|
|
ignoredPackages: new Set([ignoredRoot ? process.cwd() : path.resolve('child')]),
|
|
sharedWorkspaceLockfile,
|
|
workspaceDir: process.cwd(),
|
|
}, 'install')
|
|
|
|
const state = loadJsonFileSync<WorkspaceState>('node_modules/.pnpm-workspace-state-v1.json')
|
|
expect(state.filteredInstall).toBe(true)
|
|
expect(Object.keys(state.validation!.manifests)).toStrictEqual([ignoredRoot ? 'child' : '.'])
|
|
})
|