Skip to content
This repository has been archived by the owner on May 14, 2018. It is now read-only.

Commit

Permalink
perf: try to preserve subdependencies of updated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Jul 30, 2017
1 parent 1785768 commit 2b7e5f6
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 223 deletions.
33 changes: 26 additions & 7 deletions src/install/installMultiple.ts
Expand Up @@ -27,6 +27,7 @@ import {
} from 'pnpm-shrinkwrap'
import depsToSpecs from '../depsToSpecs'
import getIsInstallable from './getIsInstallable'
import semver = require('semver')

export type PkgAddress = {
nodeId: string,
Expand Down Expand Up @@ -57,22 +58,35 @@ export default async function installMultiple (
parentNodeId: string,
currentDepth: number,
resolvedDependencies?: ResolvedDependencies,
preferedDependencies?: ResolvedDependencies,
parentIsInstallable?: boolean,
update: boolean,
}
): Promise<PkgAddress[]> {
const resolvedDependencies = options.resolvedDependencies || {}
const preferedDependencies = options.preferedDependencies || {}
const update = options.update && options.currentDepth <= ctx.depth
const pkgAddresses = <PkgAddress[]>(
await Promise.all(
specs
.map(async (spec: PackageSpec) => {
const reference = resolvedDependencies[spec.name]

return await install(spec, ctx, Object.assign({},
options,
{
update
let reference = resolvedDependencies[spec.name]
let proceed = false

if (!reference && spec.type === 'range' && preferedDependencies[spec.name] &&
semver.satisfies(preferedDependencies[spec.name], spec.fetchSpec, true)) {

proceed = true
reference = preferedDependencies[spec.name]
}

return await install(spec, ctx, Object.assign({
keypath: options.keypath,
parentNodeId: options.parentNodeId,
currentDepth: options.currentDepth,
parentIsInstallable: options.parentIsInstallable,
update,
proceed,
},
getInfoFromShrinkwrap(ctx.shrinkwrap, reference, spec.name, ctx.registry)))
})
Expand Down Expand Up @@ -155,10 +169,11 @@ async function install (
resolvedDependencies?: ResolvedDependencies,
parentIsInstallable?: boolean,
update: boolean,
proceed: boolean,
}
): Promise<PkgAddress | null> {
const keypath = options.keypath || []
const proceed = !options.resolvedDependencies || ctx.force || keypath.length <= ctx.depth
const proceed = options.proceed || !options.shrinkwrapResolution || ctx.force || keypath.length <= ctx.depth
const parentIsInstallable = options.parentIsInstallable === undefined || options.parentIsInstallable

if (!proceed && options.absoluteDependencyPath &&
Expand Down Expand Up @@ -296,6 +311,9 @@ async function install (
resolvedDependencies: fetchedPkg.id !== options.pkgId
? undefined
: options.resolvedDependencies,
preferedDependencies: fetchedPkg.id !== options.pkgId
? options.resolvedDependencies
: undefined,
update: options.update,
}
)
Expand Down Expand Up @@ -345,6 +363,7 @@ async function installDependencies (
parentNodeId: string,
currentDepth: number,
resolvedDependencies?: ResolvedDependencies,
preferedDependencies?: ResolvedDependencies,
parentIsInstallable: boolean,
update: boolean,
}
Expand Down
1 change: 1 addition & 0 deletions test/install/index.ts
Expand Up @@ -12,3 +12,4 @@ import './global'
import './independentLeaves'
import './store'
import './reporting'
import './update'
40 changes: 40 additions & 0 deletions test/install/update.ts
@@ -0,0 +1,40 @@
import tape = require('tape')
import promisifyTape from 'tape-promise'
import {
prepare,
addDistTag,
testDefaults,
} from '../utils'
import {install, installPkgs} from '../../src'

const test = promisifyTape(tape)

test('preserve subdeps on update', async (t: tape.Test) => {
const project = prepare(t)

await Promise.all([
addDistTag('foobarqar', '1.0.0', 'latest'),
addDistTag('foo', '100.0.0', 'latest'),
addDistTag('bar', '100.0.0', 'latest'),
])

await installPkgs(['foobarqar'], testDefaults())

await Promise.all([
addDistTag('foobarqar', '1.0.1', 'latest'),
addDistTag('foo', '100.1.0', 'latest'),
addDistTag('bar', '100.1.0', 'latest'),
])

await install(testDefaults({update: true, depth: 0}))

const shr = await project.loadShrinkwrap()

t.ok(shr.packages)
t.ok(shr.packages['/foobarqar/1.0.1'])
t.deepEqual(shr.packages['/foobarqar/1.0.1'].dependencies, {
bar: '100.0.0',
foo: '100.0.0',
qar: '100.0.0',
})
})
2 changes: 1 addition & 1 deletion test/package.json
Expand Up @@ -15,7 +15,7 @@
"isexe": "^2.0.0",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.0.1",
"pnpm-registry-mock": "^0.13.0",
"pnpm-registry-mock": "^1.1.0",
"read-pkg": "^2.0.0",
"rimraf": "^2.5.4",
"sepia": "^2.0.2",
Expand Down

0 comments on commit 2b7e5f6

Please sign in to comment.