fix: installing prod deps only

close #2882
PR #2899
This commit is contained in:
Zoltan Kochan
2020-09-26 21:45:29 +03:00
committed by GitHub
parent d7b7277958
commit 9e774ae20f
3 changed files with 56 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"supi": patch
---
When a package is both a dev dependency and a prod dependency, the package should be linked when installing prod dependencies only. This was an issue only when a lockfile was not present during installation.

View File

@@ -83,7 +83,7 @@ export default async function linkPackages (
depNodes = depNodes.filter(({ dev, optional }) => dev || optional)
}
if (!opts.include.devDependencies) {
depNodes = depNodes.filter(({ dev }) => !dev)
depNodes = depNodes.filter(({ optional, prod }) => prod || optional)
}
if (!opts.include.optionalDependencies) {
depNodes = depNodes.filter(({ optional }) => !optional)
@@ -150,12 +150,17 @@ export default async function linkPackages (
.map(([rootAlias, depPath]) => ({ rootAlias, depGraphNode: depGraph[depPath] }))
.filter(({ depGraphNode }) => depGraphNode)
.map(async ({ rootAlias, depGraphNode }) => {
const isDev = Boolean(manifest.devDependencies?.[depGraphNode.name])
const isOptional = Boolean(manifest.optionalDependencies?.[depGraphNode.name])
if (
isDev && !opts.include.devDependencies ||
isOptional && !opts.include.optionalDependencies ||
!isDev && !isOptional && !opts.include.dependencies
) return
if (
(await symlinkDependency(depGraphNode.dir, modulesDir, rootAlias)).reused
) return
const isDev = Boolean(manifest.devDependencies?.[depGraphNode.name])
const isOptional = Boolean(manifest.optionalDependencies?.[depGraphNode.name])
rootLogger.debug({
added: {
dependencyType: isDev && 'dev' || isOptional && 'optional' || 'prod',

View File

@@ -4,6 +4,7 @@ import { addDependenciesToPackage, install } from 'supi'
import promisifyTape from 'tape-promise'
import { testDefaults } from '../utils'
import path = require('path')
import exists = require('path-exists')
import tape = require('tape')
const test = promisifyTape(tape)
@@ -14,12 +15,17 @@ test('production install (with --production flag)', async (t: tape.Test) => {
await install({
dependencies: {
'pkg-with-1-dep': '100.0.0',
'write-yaml': '1.0.0',
},
devDependencies: {
'@zkochan/foo': '1.0.0',
once: '^1.4.0', // once is also a transitive dependency of rimraf
// js-yaml is also a dependency of write-yaml
// covers issue https://github.com/pnpm/pnpm/issues/2882
'js-yaml': '3.14.0',
once: '^1.4.0',
},
}, await testDefaults({
fastUnpack: false,
include: {
dependencies: true,
devDependencies: false,
@@ -27,8 +33,44 @@ test('production install (with --production flag)', async (t: tape.Test) => {
},
}))
t.notOk(await exists(path.resolve('node_modules/.pnpm/@zkochan/foo@1.0.0')))
t.ok(await exists(path.resolve('node_modules/.pnpm/js-yaml@3.14.0')))
await project.has('pkg-with-1-dep')
await project.has('write-yaml')
await project.hasNot('@zkochan/foo')
await project.hasNot('js-yaml')
})
test('production install with --no-optional', async (t: tape.Test) => {
const project = prepareEmpty(t)
await install({
dependencies: {
'pkg-with-1-dep': '100.0.0',
'write-yaml': '1.0.0',
},
optionalDependencies: {
'@zkochan/foo': '1.0.0',
// js-yaml is also a dependency of write-yaml
// covers issue https://github.com/pnpm/pnpm/issues/2882
'js-yaml': '3.14.0',
once: '^1.4.0',
},
}, await testDefaults({
fastUnpack: false,
include: {
dependencies: true,
devDependencies: false,
optionalDependencies: false,
},
}))
t.notOk(await exists(path.resolve('node_modules/.pnpm/@zkochan/foo@1.0.0')))
t.ok(await exists(path.resolve('node_modules/.pnpm/js-yaml@3.14.0')))
await project.has('pkg-with-1-dep')
await project.has('write-yaml')
await project.hasNot('@zkochan/foo')
await project.hasNot('js-yaml')
})
test('install dev dependencies only', async (t: tape.Test) => {