Skip to content

Commit

Permalink
feat: ignore-compatibility-db (#5140)
Browse files Browse the repository at this point in the history
close #5132
  • Loading branch information
zkochan committed Aug 1, 2022
1 parent 761be97 commit 29a8159
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/tidy-seas-dance.md
@@ -0,0 +1,7 @@
---
"@pnpm/config": minor
"@pnpm/core": minor
"pnpm": minor
---

When `ignore-compatibility-db` is set to `true`, the [compatibility database](https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-extensions/sources/index.ts) will not be used to patch dependencies [#5132](https://github.com/pnpm/pnpm/issues/5132).
1 change: 1 addition & 0 deletions packages/config/src/Config.ts
Expand Up @@ -28,6 +28,7 @@ export interface Config {
dir: string
bin: string
ignoreScripts?: boolean
ignoreCompatibilityDb?: boolean
includeWorkspaceRoot?: boolean
save?: boolean
saveProd?: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Expand Up @@ -60,6 +60,7 @@ export const types = Object.assign({
'git-branch-lockfile': Boolean,
hoist: Boolean,
'hoist-pattern': Array,
'ignore-compatibility-db': Boolean,
'ignore-pnpmfile': Boolean,
'ignore-workspace': Boolean,
'ignore-workspace-root-check': Boolean,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/getPeerDependencyIssues.ts
Expand Up @@ -8,6 +8,7 @@ import { DEFAULT_REGISTRIES } from '@pnpm/normalize-registries'

export type ListMissingPeersOptions = Partial<GetContextOptions>
& Pick<InstallOptions, 'hooks'
| 'ignoreCompatibilityDb'
| 'linkWorkspacePackagesDepth'
| 'nodeVersion'
| 'nodeLinker'
Expand Down Expand Up @@ -57,6 +58,7 @@ export async function getPeerDependencyIssues (
forceFullResolution: true,
hooks: {
readPackage: createReadPackageHook({
ignoreCompatibilityDb: opts.ignoreCompatibilityDb,
lockfileDir,
overrides: opts.overrides,
packageExtensions: opts.packageExtensions,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/install/extendInstallOptions.ts
Expand Up @@ -32,6 +32,7 @@ export interface StrictInstallOptions {
linkWorkspacePackagesDepth: number
lockfileOnly: boolean
fixLockfile: boolean
ignoreCompatibilityDb: boolean
ignorePackageManifest: boolean
preferFrozenLockfile: boolean
saveWorkspaceProtocol: boolean | 'rolling'
Expand Down Expand Up @@ -147,6 +148,7 @@ const defaults = async (opts: InstallOptions) => {
nodeLinker: 'isolated',
overrides: {},
ownLifecycleHooksStdio: 'inherit',
ignoreCompatibilityDb: false,
ignorePackageManifest: false,
packageExtensions: {},
packageManager,
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/install/index.ts
Expand Up @@ -177,6 +177,7 @@ export async function mutateModules (
// so reading its manifest explicitly here.
await safeReadProjectManifestOnly(opts.lockfileDir)
opts.hooks.readPackage = createReadPackageHook({
ignoreCompatibilityDb: opts.ignoreCompatibilityDb,
readPackageHook: opts.hooks.readPackage,
overrides: opts.overrides,
lockfileDir: opts.lockfileDir,
Expand Down Expand Up @@ -546,12 +547,14 @@ export function createObjectChecksum (obj: Object) {

export function createReadPackageHook (
{
ignoreCompatibilityDb,
lockfileDir,
overrides,
packageExtensions,
peerDependencyRules,
readPackageHook,
}: {
ignoreCompatibilityDb?: boolean
lockfileDir: string
overrides?: Record<string, string>
packageExtensions?: Record<string, PackageExtension>
Expand All @@ -563,7 +566,9 @@ export function createReadPackageHook (
if (!isEmpty(overrides ?? {})) {
hooks.push(createVersionsOverrider(overrides!, lockfileDir))
}
hooks.push(createPackageExtender(fromPairs(compatPackageExtensions)))
if (!ignoreCompatibilityDb) {
hooks.push(createPackageExtender(fromPairs(compatPackageExtensions)))
}
if (!isEmpty(packageExtensions ?? {})) {
hooks.push(createPackageExtender(packageExtensions!))
}
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/install/packageExtensions.ts
Expand Up @@ -114,3 +114,18 @@ test('manifests are patched by extensions from the compatibility database', asyn
const lockfile = await 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'],
await testDefaults({
ignoreCompatibilityDb: true,
})
)

const lockfile = await project.readLockfile()
expect(lockfile.packages['/debug/4.0.0'].peerDependenciesMeta).toBeUndefined()
})

0 comments on commit 29a8159

Please sign in to comment.