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.
118 lines
3.8 KiB
TypeScript
118 lines
3.8 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import { describe, expect, test } from '@jest/globals'
|
|
|
|
import { createCliConfigArgs } from '../src/runDepsStatusCheck.js'
|
|
|
|
describe('createCliConfigArgs', () => {
|
|
test.each([true, false])('resolves a relative store against the install root (workspace: %s)', (workspace) => {
|
|
const dir = path.resolve('workspace/packages/project')
|
|
const workspaceDir = workspace ? path.resolve('workspace') : undefined
|
|
expect(createCliConfigArgs({
|
|
dir,
|
|
workspaceDir,
|
|
storeDir: '.store',
|
|
cliOptions: { 'store-dir': '.store' },
|
|
})).toStrictEqual([
|
|
`--config.store-dir=${path.join(workspaceDir ?? dir, '.store')}`,
|
|
])
|
|
})
|
|
|
|
test('returns empty array when rawCliConfig is not provided or empty', () => {
|
|
expect(createCliConfigArgs({})).toStrictEqual([])
|
|
expect(createCliConfigArgs({ rawCliConfig: {} })).toStrictEqual([])
|
|
})
|
|
|
|
test('converts rawCliConfig key-value pairs into --config.<key>=<value> flags', () => {
|
|
expect(createCliConfigArgs({
|
|
rawCliConfig: {
|
|
'lockfile-dir': '/path/to/lockfile',
|
|
registry: 'https://custom.registry.org/',
|
|
frozen: true,
|
|
},
|
|
})).toStrictEqual([
|
|
'--config.lockfile-dir=/path/to/lockfile',
|
|
'--config.registry=https://custom.registry.org/',
|
|
'--config.frozen=true',
|
|
])
|
|
})
|
|
|
|
test('supports array values', () => {
|
|
expect(createCliConfigArgs({
|
|
rawCliConfig: {
|
|
'public-hoist-pattern': ['*eslint*', '*prettier*'],
|
|
},
|
|
})).toStrictEqual([
|
|
'--config.public-hoist-pattern=*eslint*',
|
|
'--config.public-hoist-pattern=*prettier*',
|
|
])
|
|
})
|
|
|
|
test('leaves out dir, which the install starts in', () => {
|
|
expect(createCliConfigArgs({
|
|
rawCliConfig: {
|
|
dir: 'project',
|
|
'lockfile-dir': '..',
|
|
},
|
|
})).toStrictEqual([
|
|
'--config.lockfile-dir=..',
|
|
])
|
|
})
|
|
|
|
test('ignores null and undefined values', () => {
|
|
expect(createCliConfigArgs({
|
|
rawCliConfig: {
|
|
'lockfile-dir': '/path/to/lockfile',
|
|
foo: undefined,
|
|
bar: null,
|
|
},
|
|
})).toStrictEqual([
|
|
'--config.lockfile-dir=/path/to/lockfile',
|
|
])
|
|
})
|
|
|
|
test('forwards install-relevant cliOptions and uses resolved path overrides', () => {
|
|
expect(createCliConfigArgs({
|
|
cliOptions: {
|
|
'lockfile-dir': '../rel-lockfile',
|
|
'store-dir': '../rel-store',
|
|
'modules-dir': 'custom_modules',
|
|
'npmrc-auth-file': '../user.npmrc',
|
|
offline: true,
|
|
'frozen-lockfile': false,
|
|
'ignore-workspace': true,
|
|
'workspace-root': true,
|
|
'test-pattern': ['test/**'],
|
|
'changed-files-ignore-pattern': ['**/*.md'],
|
|
'workspace-packages': ['pkg-a', 'pkg-b'],
|
|
'@my-scope:registry': 'https://scope.registry.example/',
|
|
'//scope.registry.example/:_authToken': 'secret',
|
|
'verify-deps-before-run': 'install',
|
|
filter: ['pkg-a'],
|
|
},
|
|
lockfileDir: '../rel-lockfile',
|
|
npmrcAuthFile: '../user.npmrc',
|
|
storeDir: '/abs/store',
|
|
rawCliConfig: {
|
|
'prefer-offline': true,
|
|
},
|
|
})).toStrictEqual([
|
|
`--config.lockfile-dir=${path.resolve('../rel-lockfile')}`,
|
|
`--config.store-dir=${path.resolve('/abs/store')}`,
|
|
'--config.modules-dir=custom_modules',
|
|
`--config.npmrc-auth-file=${path.resolve('../user.npmrc')}`,
|
|
'--config.offline=true',
|
|
'--config.frozen-lockfile=false',
|
|
'--ignore-workspace',
|
|
'--config.workspace-root=true',
|
|
'--config.test-pattern=test/**',
|
|
'--config.changed-files-ignore-pattern=**/*.md',
|
|
'--workspace-packages=pkg-a',
|
|
'--workspace-packages=pkg-b',
|
|
'--config.@my-scope:registry=https://scope.registry.example/',
|
|
'--config.//scope.registry.example/:_authToken=secret',
|
|
'--config.prefer-offline=true',
|
|
])
|
|
})
|
|
})
|