diff --git a/src/api/install.ts b/src/api/install.ts index 9021ca3452..8c0426ffe9 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -67,7 +67,7 @@ export async function install (maybeOpts?: PnpmOptions) { specs.forEach(spec => { if (ctx.shrinkwrap.specifiers && ctx.shrinkwrap.specifiers[spec.name] !== spec.rawSpec) { - delete ctx.shrinkwrap.packages['/'].dependencies[spec.name] + delete ctx.shrinkwrap.dependencies[spec.name] } }) @@ -146,7 +146,7 @@ export async function installPkgs (fuzzyDeps: string[] | Dependencies, maybeOpts const installCtx = await createInstallCmd(opts, ctx.shrinkwrap, ctx.skipped) packagesToInstall.forEach(spec => { - delete ctx.shrinkwrap.packages['/'].dependencies[spec.name] + delete ctx.shrinkwrap.dependencies[spec.name] }) if (opts.lock === false) { @@ -218,7 +218,7 @@ async function installInContext ( alwaysAuth: opts.alwaysAuth, }), metaCache: opts.metaCache, - resolvedDependencies: ctx.shrinkwrap.packages['/'].dependencies, + resolvedDependencies: ctx.shrinkwrap.dependencies, offline: opts.offline, rawNpmConfig: opts.rawNpmConfig, nodeModules: nodeModulesPath, @@ -259,7 +259,7 @@ async function installInContext ( } if (newPkg) { - ctx.shrinkwrap.packages['/'].dependencies = ctx.shrinkwrap.packages['/'].dependencies || {} + ctx.shrinkwrap.dependencies = ctx.shrinkwrap.dependencies || {} ctx.shrinkwrap.specifiers = ctx.shrinkwrap.specifiers || {} const deps = newPkg.dependencies || {} @@ -269,14 +269,14 @@ async function installInContext ( const getSpecFromPkg = (depName: string) => deps[depName] || devDeps[depName] || optionalDeps[depName] pkgs.forEach(dep => { - ctx.shrinkwrap.packages['/'].dependencies[dep.name] = pkgIdToRef(dep.id, dep.name, dep.resolution, ctx.shrinkwrap.registry) + ctx.shrinkwrap.dependencies[dep.name] = pkgIdToRef(dep.id, dep.name, dep.resolution, ctx.shrinkwrap.registry) ctx.shrinkwrap.specifiers[dep.name] = getSpecFromPkg(dep.name) }) - Object.keys(ctx.shrinkwrap.packages['/'].dependencies) + Object.keys(ctx.shrinkwrap.dependencies) .filter(pkgName => !getSpecFromPkg(pkgName)) .forEach(removedDep => { delete ctx.shrinkwrap.specifiers[removedDep] - delete ctx.shrinkwrap.packages['/'].dependencies[removedDep] + delete ctx.shrinkwrap.dependencies[removedDep] }) } diff --git a/src/api/prune.ts b/src/api/prune.ts index eb7186297e..06b796a7cf 100644 --- a/src/api/prune.ts +++ b/src/api/prune.ts @@ -35,7 +35,7 @@ export async function prune(maybeOpts?: PnpmOptions): Promise { const newShr = ctx.shrinkwrap extraneousPkgs.forEach(depName => { - delete newShr.packages['/'].dependencies[depName] + delete newShr.dependencies[depName] delete newShr.specifiers[depName] }) diff --git a/src/api/removeOrphanPkgs.ts b/src/api/removeOrphanPkgs.ts index 4fe31a6134..6ac5a2c994 100644 --- a/src/api/removeOrphanPkgs.ts +++ b/src/api/removeOrphanPkgs.ts @@ -15,8 +15,8 @@ export default async function removeOrphanPkgs ( root: string, storePath: string ): Promise { - const oldPkgNames = Object.keys(oldShr.packages['/'].dependencies) - const newPkgNames = Object.keys(newShr.packages['/'].dependencies) + const oldPkgNames = Object.keys(oldShr.dependencies) + const newPkgNames = Object.keys(newShr.dependencies) const removedTopDeps = R.difference(oldPkgNames, newPkgNames) diff --git a/src/api/uninstall.ts b/src/api/uninstall.ts index a10d887040..89ad783ac3 100644 --- a/src/api/uninstall.ts +++ b/src/api/uninstall.ts @@ -47,9 +47,9 @@ export async function uninstallInContext (pkgsToUninstall: string[], pkg: Packag if (saveType) { const pkgJsonPath = path.join(ctx.root, 'package.json') const pkg = await removeDeps(pkgJsonPath, pkgsToUninstall, saveType) - for (let depName in ctx.shrinkwrap.packages['/'].dependencies) { + for (let depName in ctx.shrinkwrap.dependencies) { if (!isDependentOn(pkg, depName)) { - delete ctx.shrinkwrap.packages['/'].dependencies[depName] + delete ctx.shrinkwrap.dependencies[depName] delete ctx.shrinkwrap.specifiers[depName] } } diff --git a/src/fs/shrinkwrap.ts b/src/fs/shrinkwrap.ts index 3a834af988..f0d598fba5 100644 --- a/src/fs/shrinkwrap.ts +++ b/src/fs/shrinkwrap.ts @@ -23,11 +23,8 @@ function getDefaultShrinkwrap (registry: string) { version: SHRINKWRAP_VERSION, createdWith: CREATED_WITH, specifiers: {}, - packages: { - '/': { - dependencies: {}, - }, - }, + dependencies: {}, + packages: {}, registry, } } @@ -36,17 +33,13 @@ export type Shrinkwrap = { version: number, createdWith: string, specifiers: ResolvedDependencies, + dependencies: ResolvedDependencies, packages: ResolvedPackages, registry: string, } export type ResolvedPackages = { - '/': { - dependencies: ResolvedDependencies, - }, - [pkgId: string]: DependencyShrinkwrap | { - dependencies: ResolvedDependencies, - }, + [pkgId: string]: DependencyShrinkwrap, } export type DependencyShrinkwrap = string | { @@ -124,7 +117,7 @@ export function save (pkgPath: string, shrinkwrap: Shrinkwrap) { const privateShrinkwrapPath = path.join(pkgPath, PRIVATE_SHRINKWRAP_FILENAME) // empty shrinkwrap is not saved - if (Object.keys(shrinkwrap.packages[PROJECT_ID].dependencies).length === 0) { + if (Object.keys(shrinkwrap.dependencies).length === 0) { return Promise.all([ rimraf(shrinkwrapPath), rimraf(privateShrinkwrapPath), @@ -143,25 +136,22 @@ export function save (pkgPath: string, shrinkwrap: Shrinkwrap) { ]) } -export const PROJECT_ID = '/' - export function prune (shr: Shrinkwrap): Shrinkwrap { return { version: SHRINKWRAP_VERSION, createdWith: shr.createdWith || CREATED_WITH, specifiers: shr.specifiers, registry: shr.registry, + dependencies: shr.dependencies, packages: copyDependencyTree(shr, shr.registry), } } function copyDependencyTree (shr: Shrinkwrap, registry: string): ResolvedPackages { - const resolvedPackages: ResolvedPackages = { - '/': shr.packages[PROJECT_ID] - } + const resolvedPackages: ResolvedPackages = {} - let pkgIds: string[] = R.keys(shr.packages[PROJECT_ID].dependencies) - .map((pkgName: string) => getPkgShortId(shr.packages[PROJECT_ID].dependencies[pkgName], pkgName)) + let pkgIds: string[] = R.keys(shr.dependencies) + .map((pkgName: string) => getPkgShortId(shr.dependencies[pkgName], pkgName)) while (pkgIds.length) { let nextPkgIds: string[] = [] diff --git a/test/install/local.ts b/test/install/local.ts index d7eaf63431..b3c9f47293 100644 --- a/test/install/local.ts +++ b/test/install/local.ts @@ -42,12 +42,10 @@ test('local file', async function (t: tape.Test) { specifiers: { 'local-pkg': `file:..${path.sep}local-pkg`, }, + dependencies: { + 'local-pkg': 'file:../local-pkg', + }, packages: { - '/': { - dependencies: { - 'local-pkg': 'file:../local-pkg', - }, - }, 'file:../local-pkg': { resolution: { root: '../local-pkg', diff --git a/test/shrinkwrap.ts b/test/shrinkwrap.ts index 514e465e68..539c29d15f 100644 --- a/test/shrinkwrap.ts +++ b/test/shrinkwrap.ts @@ -23,11 +23,10 @@ test('shrinkwrap file has correct format', async t => { t.ok(shr.registry, 'has registry field') t.ok(shr.specifiers, 'has specifiers field') - t.ok(shr.packages['/'], 'has root field') - t.ok(shr.packages['/'].dependencies, 'has root dependencies field') - t.equal(shr.packages['/'].dependencies['pkg-with-1-dep'], '100.0.0', 'has dependency resolved') - t.ok(shr.packages['/'].dependencies['@rstacruz/tap-spec'], 'has scoped dependency resolved') - t.ok(shr.packages['/'].dependencies['is-negative'].indexOf('/') !== -1, 'has not shortened tarball from the non-standard registry') + t.ok(shr.dependencies, 'has dependencies field') + t.equal(shr.dependencies['pkg-with-1-dep'], '100.0.0', 'has dependency resolved') + t.ok(shr.dependencies['@rstacruz/tap-spec'], 'has scoped dependency resolved') + t.ok(shr.dependencies['is-negative'].indexOf('/') !== -1, 'has not shortened tarball from the non-standard registry') t.ok(shr.packages, 'has packages field') t.ok(shr.packages[id], `has resolution for ${id}`) @@ -49,9 +48,9 @@ test('shrinkwrap file has dev deps even when installing for prod only', async (t const shr = await project.loadShrinkwrap() const id = '/is-negative/2.1.0' - t.ok(shr.packages, 'has packages field') + t.ok(shr.dependencies, 'has dependencies field') - t.equal(shr.packages['/'].dependencies['is-negative'], '2.1.0', 'has dependency resolved') + t.equal(shr.dependencies['is-negative'], '2.1.0', 'has dependency resolved') t.ok(shr.packages[id], `has resolution for ${id}`) }) @@ -64,12 +63,10 @@ test('shrinkwrap with scoped package', async t => { }) await writeYamlFile('shrinkwrap.yaml', { + dependencies: { + '@types/semver': '5.3.31', + }, packages: { - '/': { - dependencies: { - '@types/semver': '5.3.31', - }, - }, '/@types/semver/5.3.31': 'b999d7d935f43f5207b01b00d3de20852f4ca75f', }, registry: 'http://localhost:4873', @@ -89,12 +86,10 @@ test('fail when shasum from shrinkwrap does not match with the actual one', asyn await writeYamlFile('shrinkwrap.yaml', { version: 2, registry: 'http://localhost:4873', + dependencies: { + 'is-negative': '2.1.0', + }, packages: { - '/': { - dependencies: { - 'is-negative': '2.1.0', - }, - }, '/is-negative/2.1.0': { resolution: { shasum: '00000000000000000000000000000000000000000', @@ -128,7 +123,7 @@ test("shrinkwrap doesn't lock subdependencies that don't satisfy the new specs", const shr = await project.loadShrinkwrap() - t.equal(Object.keys(shr.packages['/'].dependencies).length, 1, 'resolutions not duplicated') + t.equal(Object.keys(shr.dependencies).length, 1, 'resolutions not duplicated') }) test('shrinkwrap not created when no deps in package.json', async t => { @@ -145,12 +140,10 @@ test('shrinkwrap removed when no deps in package.json', async t => { await writeYamlFile('shrinkwrap.yaml', { version: 2, registry: 'http://localhost:4873', + dependencies: { + 'is-negative': '2.1.0', + }, packages: { - '/': { - dependencies: { - 'is-negative': '2.1.0', - }, - }, '/is-negative/2.1.0': { resolution: { tarball: 'http://localhost:4873/is-negative/-/is-negative-2.1.0.tgz', @@ -212,7 +205,7 @@ test("recreates shrinkwrap file if it doesn't match the dependencies in package. await installPkgs(['is-negative@2.0.0'], testDefaults({saveExact: true})) const shr1 = await project.loadShrinkwrap() - t.equal(shr1.packages['/'].dependencies['is-negative'], '2.0.0') + t.equal(shr1.dependencies['is-negative'], '2.0.0') t.equal(shr1.specifiers['is-negative'], '2.0.0') const pkg = await readPkg() @@ -225,7 +218,7 @@ test("recreates shrinkwrap file if it doesn't match the dependencies in package. const shr = await project.loadShrinkwrap() - t.equal(shr.packages['/'].dependencies['is-negative'], '2.1.0') + t.equal(shr.dependencies['is-negative'], '2.1.0') t.equal(shr.specifiers['is-negative'], '^2.1.0') }) @@ -236,7 +229,7 @@ test('repeat install with shrinkwrap should not mutate shrinkwrap when dependenc const shr1 = await project.loadShrinkwrap() - t.equal(shr1.packages['/'].dependencies['highmaps-release'], '5.0.11') + t.equal(shr1.dependencies['highmaps-release'], '5.0.11') await rimraf('node_modules') diff --git a/test/uninstall.ts b/test/uninstall.ts index 3b3e9b13ed..6c2e9baf6d 100644 --- a/test/uninstall.ts +++ b/test/uninstall.ts @@ -81,9 +81,12 @@ test('uninstall package with dependencies and do not touch other deps', async fu t.deepEqual(pkgJson.dependencies, {'is-negative': '^2.1.0'}, 'camelcase-keys has been removed from dependencies') const shr = await project.loadShrinkwrap() - t.deepEqual(shr.packages['/'].dependencies, { + t.deepEqual(shr.dependencies, { 'is-negative': '2.1.0', }, 'camelcase-keys removed from shrinkwrap dependencies') + t.deepEqual(shr.specifiers, { + 'is-negative': '^2.1.0', + }, 'camelcase-keys removed from shrinkwrap specifiers') }) test('uninstall package with its bin files', async function (t) {