Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore-compatibility-db #5140

Merged
merged 1 commit into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5132 (comment) :

It's also worth considering whether these fixups should be applied earlier, since pnpmfile.cjs is less useful if it is not the final authority about version selections.

(This part could maybe be a separate PR since it doesn't affect our use case with ignoreCompatibilityDb=true. But I do suspect that users would be surprised to learn that the input to pnpmfile.cjs does not reflect some hooks, and the actions of pnpmfile.cjs may get overridden by compatibility db fixups.)

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()
})