From 0a09bbff792f22384aff664ddec7faaff1d46bbc Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 21 Dec 2018 15:32:46 +0200 Subject: [PATCH] fix(independent-leaves): direct deps linking --- packages/resolve-dependencies/src/resolveDependencies.ts | 4 ++++ packages/supi/src/install/resolvePeers.ts | 2 +- packages/supi/test/install/independentLeaves.ts | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/resolve-dependencies/src/resolveDependencies.ts b/packages/resolve-dependencies/src/resolveDependencies.ts index c9ef5c6f1b..77418a2c52 100644 --- a/packages/resolve-dependencies/src/resolveDependencies.ts +++ b/packages/resolve-dependencies/src/resolveDependencies.ts @@ -145,6 +145,7 @@ export interface ResolvedPackage { optionalDependencies: Set, 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)), diff --git a/packages/supi/src/install/resolvePeers.ts b/packages/supi/src/install/resolvePeers.ts index 59d12ec8b2..07db63b6b2 100644 --- a/packages/supi/src/install/resolvePeers.ts +++ b/packages/supi/src/install/resolvePeers.ts @@ -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) diff --git a/packages/supi/test/install/independentLeaves.ts b/packages/supi/test/install/independentLeaves.ts index 298851f4f1..ecd0acdd9b 100644 --- a/packages/supi/test/install/independentLeaves.ts +++ b/packages/supi/test/install/independentLeaves.ts @@ -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) => {