-
-
Notifications
You must be signed in to change notification settings - Fork 938
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: pnpm.ignoredOptionalDependencies #7714
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
45c6bf0
feat: pnpm.ignoredOptionalDependencies
KSXGitHub 06b6669
refactor: safer types
KSXGitHub 6a06746
refactor: correct a name
KSXGitHub 0a48a66
refactor: use one type keyword
KSXGitHub bb5154f
refactor: shorten the code
KSXGitHub 342135b
feat(lockfile): ignoredOptionalDependencies
KSXGitHub 0bcf912
fix: false mismatch
KSXGitHub 063566c
fix: toSorted is not available on older Node.js
KSXGitHub 0f79b9b
Merge branch 'main' into ignored-optional-dependencies
zkochan 18a1e7d
feat: sort before adding to lockfile
KSXGitHub 987c1c5
test: createOptionalDependenciesRemover
KSXGitHub 765871d
test: ignoredOptionalDependencies
KSXGitHub 9ea337b
docs: changeset
KSXGitHub c271a7a
docs(changeset): remove unnecessary words
KSXGitHub 9d3079b
feat(ignoredOptionalDependencies): patterns
KSXGitHub 0c43885
test: move a test
KSXGitHub File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"@pnpm/resolve-dependencies": minor | ||
"@pnpm/merge-lockfile-changes": minor | ||
"@pnpm/package-requester": minor | ||
"@pnpm/directory-fetcher": minor | ||
"@pnpm/tarball-fetcher": minor | ||
"@pnpm/exec.pkg-requires-build": minor | ||
"@pnpm/hooks.read-package-hook": minor | ||
"@pnpm/lockfile-types": minor | ||
"@pnpm/prune-lockfile": minor | ||
"@pnpm/create-cafs-store": minor | ||
"@pnpm/lockfile-file": minor | ||
"@pnpm/fetcher-base": minor | ||
"@pnpm/headless": minor | ||
"@pnpm/deps.graph-builder": minor | ||
"@pnpm/node.fetcher": minor | ||
"@pnpm/core": minor | ||
"@pnpm/cafs-types": minor | ||
"@pnpm/types": minor | ||
"@pnpm/config": minor | ||
"@pnpm/store.cafs": minor | ||
"@pnpm/worker": minor | ||
"pnpm": minor | ||
--- | ||
|
||
Add a field named `ignoredOptionalDependencies`. This is an array of strings. If an optional dependency has its name included in this array, it will be skipped. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
hooks/read-package-hook/src/createOptionalDependenciesRemover.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { BaseManifest, ReadPackageHook } from '@pnpm/types' | ||
|
||
export function createOptionalDependenciesRemover (toBeRemoved: string[]): ReadPackageHook { | ||
return <Manifest extends BaseManifest> (manifest: Manifest) => removeOptionalDependencies(manifest, toBeRemoved) | ||
} | ||
|
||
function removeOptionalDependencies<Manifest extends BaseManifest> (manifest: Manifest, toBeRemoved: string[]): Manifest { | ||
for (const optionalDependency in manifest.optionalDependencies) { | ||
if (toBeRemoved.includes(optionalDependency)) { | ||
delete manifest.optionalDependencies[optionalDependency] | ||
delete manifest.dependencies?.[optionalDependency] | ||
} | ||
} | ||
return manifest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
hooks/read-package-hook/test/createOptionalDependenciesRemover.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createOptionalDependenciesRemover } from '../lib/createOptionalDependenciesRemover' | ||
|
||
test('createOptionalDependenciesRemover() removes optional dependencies', async () => { | ||
const removeOptionalDependencies = createOptionalDependenciesRemover(['foo', 'bar']) | ||
expect( | ||
await removeOptionalDependencies({ | ||
dependencies: { | ||
foo: '0.1.2', | ||
bar: '2.1.0', | ||
baz: '1.0.0', | ||
qux: '2.0.0', | ||
}, | ||
optionalDependencies: { | ||
foo: '0.1.2', | ||
bar: '2.1.0', | ||
baz: '1.0.0', | ||
}, | ||
}) | ||
).toStrictEqual({ | ||
dependencies: { | ||
baz: '1.0.0', | ||
qux: '2.0.0', | ||
}, | ||
optionalDependencies: { | ||
baz: '1.0.0', | ||
}, | ||
}) | ||
}) | ||
|
||
test('createOptionalDependenciesRemover() does not remove non-optional packages', async () => { | ||
const removeOptionalDependencies = createOptionalDependenciesRemover(['foo', 'bar']) | ||
expect( | ||
await removeOptionalDependencies({ | ||
dependencies: { | ||
foo: '0.1.2', | ||
bar: '2.1.0', | ||
baz: '1.0.0', | ||
qux: '2.0.0', | ||
}, | ||
optionalDependencies: { | ||
foo: '0.1.2', | ||
baz: '1.0.0', | ||
}, | ||
}) | ||
).toStrictEqual({ | ||
dependencies: { | ||
bar: '2.1.0', | ||
baz: '1.0.0', | ||
qux: '2.0.0', | ||
}, | ||
optionalDependencies: { | ||
baz: '1.0.0', | ||
}, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
pkg-manager/core/test/install/ignoredOptionalDependencies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { prepareEmpty } from '@pnpm/prepare' | ||
import { addDependenciesToPackage } from '@pnpm/core' | ||
import { | ||
testDefaults, | ||
} from '../utils' | ||
|
||
test('ignoredOptionalDependencies causes listed optional dependencies to be skipped', async () => { | ||
const project = prepareEmpty() | ||
|
||
await addDependenciesToPackage( | ||
{}, | ||
['@pnpm.e2e/pkg-with-good-optional@1.0.0'], | ||
testDefaults({ ignoredOptionalDependencies: ['is-positive'] }) | ||
) | ||
|
||
const lockfile = project.readLockfile() | ||
expect(lockfile.ignoredOptionalDependencies).toStrictEqual(['is-positive']) | ||
expect(lockfile.packages).not.toHaveProperty(['/is-positive@1.0.0']) | ||
expect(lockfile.packages).toHaveProperty(['/@pnpm.e2e/pkg-with-good-optional@1.0.0']) | ||
}) | ||
|
||
test('empty ignoredOptionalDependencies is not recorded in lockfile', async () => { | ||
const project = prepareEmpty() | ||
|
||
await addDependenciesToPackage( | ||
{}, | ||
['@pnpm.e2e/pkg-with-good-optional@1.0.0'], | ||
testDefaults({ ignoredOptionalDependencies: [] }) | ||
) | ||
|
||
const lockfile = project.readLockfile() | ||
expect(lockfile).not.toHaveProperty(['ignoredOptionalDependencies']) | ||
expect(lockfile.packages).toHaveProperty(['/is-positive@1.0.0']) | ||
expect(lockfile.packages).toHaveProperty(['/@pnpm.e2e/pkg-with-good-optional@1.0.0']) | ||
}) | ||
|
||
test('names in ignoredOptionalDependencies are sorted alphabetically in the lockfile', async () => { | ||
const project = prepareEmpty() | ||
|
||
await addDependenciesToPackage( | ||
{}, | ||
['@pnpm.e2e/pkg-with-good-optional@1.0.0'], | ||
testDefaults({ ignoredOptionalDependencies: ['foo', 'bar', 'baz', 'qux'] }) | ||
) | ||
|
||
const lockfile = project.readLockfile() | ||
expect(lockfile.ignoredOptionalDependencies).toStrictEqual(['bar', 'baz', 'foo', 'qux']) | ||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should be moved to core too. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type ProjectManifest } from '@pnpm/types' | ||
import { prepare } from '@pnpm/prepare' | ||
import { writeProjectManifest } from '@pnpm/write-project-manifest' | ||
import { execPnpm } from '../utils' | ||
|
||
test('adding or changing manifest.pnpm.ignoredOptionalDependencies should change lockfile.ignoredOptionalDependencies and module structure', async () => { | ||
const manifest: ProjectManifest = { | ||
dependencies: { | ||
'@pnpm.e2e/pkg-with-good-optional': '1.0.0', | ||
}, | ||
} | ||
const project = prepare(manifest) | ||
await execPnpm(['install']) | ||
{ | ||
const lockfile = project.readLockfile() | ||
expect(lockfile).not.toHaveProperty(['ignoredOptionalDependencies']) | ||
expect(lockfile.packages).toHaveProperty(['/@pnpm.e2e/pkg-with-good-optional@1.0.0']) | ||
expect(lockfile.packages).toHaveProperty(['/is-positive@1.0.0']) | ||
} | ||
|
||
await writeProjectManifest('package.json', { | ||
...manifest, | ||
pnpm: { | ||
...manifest.pnpm, | ||
ignoredOptionalDependencies: ['is-positive'], | ||
}, | ||
}) | ||
await execPnpm(['install']) | ||
{ | ||
const lockfile = project.readLockfile() | ||
expect(lockfile.ignoredOptionalDependencies).toStrictEqual(['is-positive']) | ||
expect(lockfile.packages).toHaveProperty(['/@pnpm.e2e/pkg-with-good-optional@1.0.0']) | ||
expect(lockfile.packages).not.toHaveProperty(['/is-positive@1.0.0']) | ||
} | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we need to support pattern matching. Same way like here:
pnpm/hooks/read-package-hook/src/createPeerDependencyPatcher.ts
Line 13 in 0e6b757