Port the rest of the fixture-portable optionalDependencies block (:213, :344, :391, :419, :540, :563, :574, :618, :633, :648, :712) plus updatingPkgJson.ts:88; :470 and :552 become known_failures stubs (missing --filter installs; edge-aware engineStrict, pnpm/pnpm#13143); :436/:703 stay deferred (real-registry-scale graphs). Two behavioral fixes land with the ports: - supportedArchitectures changes invalidate the up-to-date fast paths in both stacks: TS adds the key to WORKSPACE_STATE_SETTING_KEYS (verified broken on 11.13.1); pacquet records the CLI-merged value in the workspace state, compares it in the repeat-install drift check, and guards the frozen path's lockfile-up-to-date early return, which otherwise sees no change when only the architecture set differs. - pnpm add without a --save-* flag implements guessDependencyType: an already-declared package updates in the group it occupies, a peer-only entry stays untouched, and only a new package lands in dependencies. The save target threads through the add pipeline as an Option, None meaning "infer per package".
134 lines
3.7 KiB
TypeScript
134 lines
3.7 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import { expect, test } from '@jest/globals'
|
|
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
|
|
import type { ProjectRootDir } from '@pnpm/types'
|
|
|
|
import { createWorkspaceState } from '../src/createWorkspaceState.js'
|
|
|
|
test('createWorkspaceState() on empty list', () => {
|
|
prepareEmpty()
|
|
|
|
expect(
|
|
createWorkspaceState({
|
|
allProjects: [],
|
|
pnpmfiles: [],
|
|
filteredInstall: false,
|
|
settings: {
|
|
autoInstallPeers: true,
|
|
dedupeDirectDeps: true,
|
|
excludeLinksFromLockfile: false,
|
|
preferWorkspacePackages: false,
|
|
linkWorkspacePackages: false,
|
|
injectWorkspacePackages: false,
|
|
},
|
|
})
|
|
).toStrictEqual(expect.objectContaining({
|
|
projects: {},
|
|
pnpmfiles: [],
|
|
lastValidatedTimestamp: expect.any(Number),
|
|
}))
|
|
})
|
|
|
|
test('createWorkspaceState() saves lockfile-affecting settings', () => {
|
|
prepareEmpty()
|
|
|
|
const state = createWorkspaceState({
|
|
allProjects: [],
|
|
pnpmfiles: [],
|
|
filteredInstall: false,
|
|
settings: {
|
|
allowBuilds: {
|
|
'@pnpm.e2e/pre-and-postinstall-scripts-example': false,
|
|
},
|
|
autoInstallPeers: true,
|
|
dedupeDirectDeps: true,
|
|
excludeLinksFromLockfile: false,
|
|
preferWorkspacePackages: false,
|
|
linkWorkspacePackages: false,
|
|
injectWorkspacePackages: false,
|
|
overrides: {
|
|
foo: '1.0.0',
|
|
},
|
|
packageExtensions: {
|
|
bar: { dependencies: { baz: '2.0.0' } },
|
|
},
|
|
ignoredOptionalDependencies: ['qux'],
|
|
patchedDependencies: {
|
|
'some-pkg': 'patches/some-pkg.patch',
|
|
},
|
|
peersSuffixMaxLength: 100,
|
|
supportedArchitectures: {
|
|
os: ['darwin'],
|
|
cpu: ['x64'],
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(state.settings.allowBuilds).toStrictEqual({
|
|
'@pnpm.e2e/pre-and-postinstall-scripts-example': false,
|
|
})
|
|
expect(state.settings.overrides).toStrictEqual({ foo: '1.0.0' })
|
|
expect(state.settings.packageExtensions).toStrictEqual({
|
|
bar: { dependencies: { baz: '2.0.0' } },
|
|
})
|
|
expect(state.settings.ignoredOptionalDependencies).toStrictEqual(['qux'])
|
|
expect(state.settings.patchedDependencies).toStrictEqual({
|
|
'some-pkg': 'patches/some-pkg.patch',
|
|
})
|
|
expect(state.settings.peersSuffixMaxLength).toBe(100)
|
|
expect(state.settings.supportedArchitectures).toStrictEqual({
|
|
os: ['darwin'],
|
|
cpu: ['x64'],
|
|
})
|
|
})
|
|
|
|
test('createWorkspaceState() on non-empty list', () => {
|
|
preparePackages(['a', 'b', 'c', 'd'].map(name => ({
|
|
location: `./packages/${name}`,
|
|
package: { name },
|
|
})))
|
|
|
|
expect(
|
|
createWorkspaceState({
|
|
allProjects: [
|
|
{ rootDir: path.resolve('packages/c') as ProjectRootDir, manifest: {} },
|
|
{ rootDir: path.resolve('packages/b') as ProjectRootDir, manifest: {} },
|
|
{ rootDir: path.resolve('packages/a') as ProjectRootDir, manifest: {} },
|
|
{ rootDir: path.resolve('packages/d') as ProjectRootDir, manifest: {} },
|
|
],
|
|
settings: {
|
|
autoInstallPeers: true,
|
|
dedupeDirectDeps: true,
|
|
excludeLinksFromLockfile: false,
|
|
preferWorkspacePackages: false,
|
|
linkWorkspacePackages: false,
|
|
injectWorkspacePackages: false,
|
|
catalogs: {
|
|
default: {
|
|
foo: '0.1.2',
|
|
},
|
|
},
|
|
},
|
|
pnpmfiles: [],
|
|
filteredInstall: false,
|
|
})
|
|
).toStrictEqual(expect.objectContaining({
|
|
settings: expect.objectContaining({
|
|
catalogs: {
|
|
default: {
|
|
foo: '0.1.2',
|
|
},
|
|
},
|
|
}),
|
|
lastValidatedTimestamp: expect.any(Number),
|
|
projects: {
|
|
[path.resolve('packages/a')]: {},
|
|
[path.resolve('packages/b')]: {},
|
|
[path.resolve('packages/c')]: {},
|
|
[path.resolve('packages/d')]: {},
|
|
},
|
|
pnpmfiles: [],
|
|
}))
|
|
})
|