mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-06 23:19:19 -04:00
fix(headless): should work with --no-optional
"pnpm install --no-optional" should not fail on a project that has an up-to-date lockfile. close #1958 PR #1959
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
"test": "pnpm run lint && pnpm run tsc && pnpm run test:e2e",
|
||||
"tsc": "rimraf lib && tsc",
|
||||
"prepublishOnly": "pnpm run tsc",
|
||||
"runPrepareFixtures": "cd test/fixtures && node ../../../pnpm/lib/bin/pnpm.js m i --lockfile-only --registry http://localhost:4873/ --ignore-scripts --force",
|
||||
"runPrepareFixtures": "cd test/fixtures && node ../../../pnpm/lib/bin/pnpm.js m i --no-shared-workspace-lockfile --no-link-workspace-packages --lockfile-only --registry http://localhost:4873/ --ignore-scripts --force",
|
||||
"prepareFixtures": "registry-mock prepare && run-p -r registry-mock runPrepareFixtures"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -450,6 +450,7 @@ async function linkRootPackages (
|
||||
|
||||
interface LockfileToDepGraphOptions {
|
||||
force: boolean,
|
||||
include: IncludedDependencies,
|
||||
independentLeaves: boolean,
|
||||
importerIds: string[],
|
||||
lockfileDirectory: string,
|
||||
@@ -561,13 +562,20 @@ async function lockfileToDepGraph (
|
||||
}
|
||||
for (const peripheralLocation of R.keys(graph)) {
|
||||
const pkgSnapshot = pkgSnapshotByLocation[peripheralLocation]
|
||||
const allDeps = { ...pkgSnapshot.dependencies, ...pkgSnapshot.optionalDependencies }
|
||||
const allDeps = {
|
||||
...pkgSnapshot.dependencies,
|
||||
...(opts.include.optionalDependencies ? pkgSnapshot.optionalDependencies : {}),
|
||||
}
|
||||
|
||||
graph[peripheralLocation].children = await getChildrenPaths(ctx, allDeps)
|
||||
}
|
||||
for (const importerId of opts.importerIds) {
|
||||
const lockfileImporter = lockfile.importers[importerId]
|
||||
const rootDeps = { ...lockfileImporter.devDependencies, ...lockfileImporter.dependencies, ...lockfileImporter.optionalDependencies }
|
||||
const rootDeps = {
|
||||
...(opts.include.devDependencies ? lockfileImporter.devDependencies : {}),
|
||||
...(opts.include.dependencies ? lockfileImporter.dependencies : {}),
|
||||
...(opts.include.optionalDependencies ? lockfileImporter.optionalDependencies : {}),
|
||||
}
|
||||
directDependenciesByImporterId[importerId] = await getChildrenPaths(ctx, rootDeps)
|
||||
}
|
||||
}
|
||||
|
||||
10
packages/headless/test/fixtures/simple-with-optional-dep/package.json
vendored
Normal file
10
packages/headless/test/fixtures/simple-with-optional-dep/package.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "simple-with-optional-dep",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"pkg-with-good-optional": "*"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"is-positive": "1.0.0"
|
||||
}
|
||||
}
|
||||
28
packages/headless/test/fixtures/simple-with-optional-dep/pnpm-lock.yaml
generated
vendored
Normal file
28
packages/headless/test/fixtures/simple-with-optional-dep/pnpm-lock.yaml
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
dependencies:
|
||||
pkg-with-good-optional: 1.0.0
|
||||
lockfileVersion: 5.1
|
||||
optionalDependencies:
|
||||
is-positive: 1.0.0
|
||||
packages:
|
||||
/dep-of-pkg-with-1-dep/100.0.0:
|
||||
dev: false
|
||||
resolution:
|
||||
integrity: sha512-RWObNQIluSr56fVbOwD75Dt5CE2aiPReTMMUblYEMEqUI+iJw5ovTyO7LzUG/VJ4iVL2uUrbkQ6+rq4z4WOdDw==
|
||||
/is-positive/1.0.0:
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=0.10.0'
|
||||
optional: true
|
||||
resolution:
|
||||
integrity: sha1-iACYVrZKLx632LsBeUGEJK4EUss=
|
||||
/pkg-with-good-optional/1.0.0:
|
||||
dependencies:
|
||||
dep-of-pkg-with-1-dep: 100.0.0
|
||||
dev: false
|
||||
optionalDependencies:
|
||||
is-positive: 1.0.0
|
||||
resolution:
|
||||
integrity: sha512-8R+sVXJbtWl0aNu6HwqtMg36mOkwGgHcE5YECx53WylyvnO+SKSVsofRJpbCov/Gl01bqQyzmaSfqmg0IXWeSQ==
|
||||
specifiers:
|
||||
is-positive: 1.0.0
|
||||
pkg-with-good-optional: '*'
|
||||
@@ -220,6 +220,27 @@ test('installing only optional deps', async (t) => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
// Covers https://github.com/pnpm/pnpm/issues/1958
|
||||
test('not installing optional deps', async (t) => {
|
||||
const prefix = path.join(fixtures, 'simple-with-optional-dep')
|
||||
await rimraf(path.join(prefix, 'node_modules'))
|
||||
|
||||
await headless(await testDefaults({
|
||||
include: {
|
||||
dependencies: true,
|
||||
devDependencies: true,
|
||||
optionalDependencies: false,
|
||||
},
|
||||
lockfileDirectory: prefix,
|
||||
}))
|
||||
|
||||
const project = assertProject(t, prefix)
|
||||
await project.hasNot('is-positive')
|
||||
await project.has('pkg-with-good-optional')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
// Covers https://github.com/pnpm/pnpm/issues/1547
|
||||
test('installing with independent-leaves and shamefully-flatten', async (t) => {
|
||||
const prefix = path.join(fixtures, 'with-1-dep')
|
||||
|
||||
Reference in New Issue
Block a user