mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-01 03:15:15 -04:00
* chore: upgrade @typescript/native-preview to 7.0.0-dev.20260421.2
- Add explicit `types: ["node"]` to the shared tsconfig because tsgo
20260421 no longer auto-acquires `@types/*` from `node_modules`.
- Refactor test files to explicitly import jest globals (`describe`,
`it`, `test`, `expect`, `beforeEach`, etc.) from `@jest/globals`
instead of relying on `@types/jest` ambient declarations. Under the
new tsgo build, `import { jest } from '@jest/globals'` shadows the
ambient `jest` namespace, breaking `@types/jest`'s `declare var
describe: jest.Describe;` globals.
- Add `@jest/globals` to each package's devDependencies where tests
now import from it, and add `@types/node` to packages that need it
but were relying on hoisted resolution.
- Replace `fail()` calls with `throw new Error(...)` since `fail` is
no longer globally available.
* chore: fix remaining tsgo type-strictness errors
- Strip `as <PnpmType>` casts on objects passed to toMatchObject /
toStrictEqual / toEqual; @jest/globals rejects the typed objects
(which include AsymmetricMatchers) vs. the repo-specific type.
- Type `jest.fn<...>()` explicitly where the mock's signature matters
for toHaveBeenCalledWith.
- Replace `beforeEach(() => X)` with `beforeEach(() => { X })` so the
return value is void, as the stricter jest typing requires.
- Use `expect.objectContaining({...})` in one place where the full
expected object triggered stricter type resolution.
- Cast `prompt.mock.calls` arg through `as unknown as Record<...>[]`
for patch.test.ts's nested-array matchers.
- Fix off-by-one `<reference path>` in pnpm/test/getConfig.test.ts
that only surfaced now.
- Move `@jest/globals` from devDependencies to dependencies in the
two `__utils__` packages that import it from `src/`.
- Clean up unused imports from the @jest/globals migration.
* chore: address Copilot review on #11332
- Move misplaced `@jest/globals` imports to the top import block in
checkEngine, run.ts, and workspace/root-finder tests where the
script dropped them below executable code.
- Replace `try { await x(); throw new Error('should have thrown') } catch`
in bins/linker, lockfile/fs, and resolving/local-resolver tests with
`await expect(x()).rejects.toMatchObject({...})`. The old pattern
swallowed an unrelated `throw` if the under-test call silently
succeeded, which would fail on the catch-block assertion with a
misleading message.
182 lines
5.3 KiB
TypeScript
182 lines
5.3 KiB
TypeScript
import { expect, test } from '@jest/globals'
|
|
import { hashObject as _hashObject } from '@pnpm/crypto.object-hasher'
|
|
import { PnpmError } from '@pnpm/error'
|
|
import { addDependenciesToPackage, install, mutateModulesInSingleProject } from '@pnpm/installing.deps-installer'
|
|
import { prepareEmpty } from '@pnpm/prepare'
|
|
import type { PackageExtension, ProjectManifest, ProjectRootDir } from '@pnpm/types'
|
|
|
|
import {
|
|
testDefaults,
|
|
} from '../utils/index.js'
|
|
|
|
function hashObject (obj: Record<string, unknown>): string {
|
|
return `sha256-${_hashObject(obj)}`
|
|
}
|
|
|
|
test('manifests are extended with fields specified by packageExtensions', async () => {
|
|
const project = prepareEmpty()
|
|
|
|
const packageExtensions: Record<string, PackageExtension> = {
|
|
'is-positive': {
|
|
dependencies: {
|
|
'@pnpm.e2e/bar': '100.1.0',
|
|
},
|
|
},
|
|
}
|
|
const { updatedManifest: manifest } = await addDependenciesToPackage(
|
|
{},
|
|
['is-positive@1.0.0'],
|
|
testDefaults({ packageExtensions })
|
|
)
|
|
|
|
{
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.snapshots['is-positive@1.0.0'].dependencies?.['@pnpm.e2e/bar']).toBe('100.1.0')
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(hashObject({
|
|
'is-positive': {
|
|
dependencies: {
|
|
'@pnpm.e2e/bar': '100.1.0',
|
|
},
|
|
},
|
|
}))
|
|
const currentLockfile = project.readCurrentLockfile()
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(currentLockfile.packageExtensionsChecksum)
|
|
}
|
|
|
|
// The lockfile is updated if the overrides are changed
|
|
packageExtensions['is-positive'].dependencies!['@pnpm.e2e/foobar'] = '100.0.0'
|
|
await mutateModulesInSingleProject({
|
|
manifest,
|
|
mutation: 'install',
|
|
rootDir: process.cwd() as ProjectRootDir,
|
|
}, testDefaults({ packageExtensions }))
|
|
|
|
{
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.snapshots['is-positive@1.0.0'].dependencies?.['@pnpm.e2e/foobar']).toBe('100.0.0')
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(hashObject({
|
|
'is-positive': {
|
|
dependencies: {
|
|
'@pnpm.e2e/bar': '100.1.0',
|
|
'@pnpm.e2e/foobar': '100.0.0',
|
|
},
|
|
},
|
|
}))
|
|
const currentLockfile = project.readCurrentLockfile()
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(currentLockfile.packageExtensionsChecksum)
|
|
}
|
|
|
|
await mutateModulesInSingleProject({
|
|
manifest,
|
|
mutation: 'install',
|
|
rootDir: process.cwd() as ProjectRootDir,
|
|
}, testDefaults({ frozenLockfile: true, packageExtensions }))
|
|
|
|
{
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(hashObject({
|
|
'is-positive': {
|
|
dependencies: {
|
|
'@pnpm.e2e/bar': '100.1.0',
|
|
'@pnpm.e2e/foobar': '100.0.0',
|
|
},
|
|
},
|
|
}))
|
|
const currentLockfile = project.readCurrentLockfile()
|
|
expect(lockfile.packageExtensionsChecksum).toStrictEqual(currentLockfile.packageExtensionsChecksum)
|
|
}
|
|
|
|
packageExtensions['is-positive'].dependencies!['@pnpm.e2e/bar'] = '100.0.1'
|
|
await expect(
|
|
mutateModulesInSingleProject({
|
|
manifest,
|
|
mutation: 'install',
|
|
rootDir: process.cwd() as ProjectRootDir,
|
|
}, testDefaults({ frozenLockfile: true, packageExtensions }))
|
|
).rejects.toThrow(
|
|
new PnpmError('LOCKFILE_CONFIG_MISMATCH',
|
|
'Cannot proceed with the frozen installation. The current "packageExtensionsChecksum" configuration doesn\'t match the value found in the lockfile'
|
|
)
|
|
)
|
|
})
|
|
|
|
test('packageExtensionsChecksum does not change regardless of keys order', async () => {
|
|
const project = prepareEmpty()
|
|
|
|
const packageExtensions1: Record<string, PackageExtension> = {
|
|
'is-odd': {
|
|
peerDependencies: {
|
|
'is-number': '*',
|
|
},
|
|
},
|
|
'is-even': {
|
|
peerDependencies: {
|
|
'is-number': '*',
|
|
},
|
|
},
|
|
}
|
|
|
|
const packageExtensions2: Record<string, PackageExtension> = {
|
|
'is-even': {
|
|
peerDependencies: {
|
|
'is-number': '*',
|
|
},
|
|
},
|
|
'is-odd': {
|
|
peerDependencies: {
|
|
'is-number': '*',
|
|
},
|
|
},
|
|
}
|
|
|
|
const manifest = (): ProjectManifest => ({
|
|
dependencies: {
|
|
'is-even': '*',
|
|
'is-odd': '*',
|
|
},
|
|
})
|
|
|
|
await install(manifest(), testDefaults({
|
|
packageExtensions: packageExtensions1,
|
|
}))
|
|
const lockfile1 = project.readLockfile()
|
|
const checksum1 = lockfile1.packageExtensionsChecksum
|
|
|
|
await install(manifest(), testDefaults({
|
|
packageExtensions: packageExtensions2,
|
|
}))
|
|
const lockfile2 = project.readLockfile()
|
|
const checksum2 = lockfile2.packageExtensionsChecksum
|
|
|
|
expect(checksum1).toBe(checksum2)
|
|
expect(checksum1).not.toBeFalsy()
|
|
})
|
|
|
|
test('manifests are patched by extensions from the compatibility database', async () => {
|
|
const project = prepareEmpty()
|
|
|
|
await addDependenciesToPackage(
|
|
{},
|
|
['debug@4.0.0'],
|
|
testDefaults()
|
|
)
|
|
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packages['debug@4.0.0'].peerDependenciesMeta?.['supports-color']?.optional).toBe(true)
|
|
})
|
|
|
|
test('manifests are not patched by extensions from the compatibility database when ignoreCompatibilityDb is true', async () => {
|
|
const project = prepareEmpty()
|
|
|
|
await addDependenciesToPackage(
|
|
{},
|
|
['debug@4.0.0'],
|
|
testDefaults({
|
|
ignoreCompatibilityDb: true,
|
|
})
|
|
)
|
|
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packages['debug@4.0.0'].peerDependenciesMeta).toBeUndefined()
|
|
})
|