fix(independent-leaves): direct deps linking

This commit is contained in:
Zoltan Kochan
2018-12-21 15:32:46 +02:00
parent cca1e6ae76
commit 0a09bbff79
3 changed files with 13 additions and 2 deletions

View File

@@ -145,6 +145,7 @@ export interface ResolvedPackage {
optionalDependencies: Set<string>,
hasBin: boolean,
hasBundledDependencies: boolean,
independent: boolean,
prepare: boolean,
requiresBuild: boolean | undefined, // added to fix issue #1201
additionalInfo: {
@@ -587,6 +588,9 @@ async function resolveDependency (
hasBin,
hasBundledDependencies: !!(pkg.bundledDependencies || pkg.bundleDependencies),
id: pkgResponse.body.id,
independent: (pkg.dependencies === undefined || R.isEmpty(pkg.dependencies)) &&
(pkg.optionalDependencies === undefined || R.isEmpty(pkg.optionalDependencies)) &&
(pkg.peerDependencies === undefined || R.isEmpty(pkg.peerDependencies)),
name: pkg.name,
optional: wantedDependency.optional,
optionalDependencies: new Set(R.keys(pkg.optionalDependencies)),

View File

@@ -212,7 +212,7 @@ function resolvePeersOfNode (
ctx.absolutePathsByNodeId[nodeId] = absolutePath
if (!ctx.depGraph[absolutePath] || ctx.depGraph[absolutePath].depth > node.depth) {
const independent = ctx.independentLeaves && R.isEmpty(children) && R.isEmpty(node.resolvedPackage.peerDependencies)
const independent = ctx.independentLeaves && node.resolvedPackage.independent
const centralLocation = node.resolvedPackage.engineCache || path.join(node.resolvedPackage.path, 'node_modules', node.resolvedPackage.name)
const peripheralLocation = !independent
? path.join(modules, node.resolvedPackage.name)

View File

@@ -1,5 +1,8 @@
import prepare from '@pnpm/prepare'
import { addDependenciesToPackage } from 'supi'
import isSubdir = require('is-subdir')
import path = require('path')
import resolveLinkTarget = require('resolve-link-target')
import { addDependenciesToPackage, install } from 'supi'
import tape = require('tape')
import promisifyTape from 'tape-promise'
import { testDefaults } from '../utils'
@@ -14,6 +17,10 @@ test('install with --independent-leaves', async (t: tape.Test) => {
const m = project.requireModule('rimraf')
t.ok(typeof m === 'function', 'rimraf() is available')
await project.isExecutable('.bin/rimraf')
await install(await testDefaults({ independentLeaves: true, preferFrozenShrinkwrap: false }))
t.ok(isSubdir(path.resolve('node_modules'), await resolveLinkTarget(path.resolve('node_modules/rimraf'))), 'non-independent package is not symlinked directly from store')
})
test('--independent-leaves throws exception when executed on node_modules installed w/o the option', async (t: tape.Test) => {