From eea643e4794339b56f76113af9abc406fbb52cbe Mon Sep 17 00:00:00 2001 From: zkochan Date: Mon, 2 Oct 2017 02:14:30 +0300 Subject: [PATCH] feat: store package name of non-npm-hosted packages bump shrinkwrapFile version to 3.1 --- src/constants.ts | 1 + src/prune.ts | 3 +-- src/read.ts | 13 ++++++++----- src/types.ts | 1 + test/fixtures/1/node_modules/.shrinkwrap.yaml | 2 +- test/fixtures/1/shrinkwrap.yaml | 2 +- test/fixtures/2/node_modules/.shrinkwrap.yaml | 2 +- test/fixtures/2/shrinkwrap.yaml | 2 +- test/prune.ts | 16 ++++++++-------- test/read.ts | 8 ++++---- 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 8811280879..7f0f525b0f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,3 +2,4 @@ import path = require('path') export const SHRINKWRAP_FILENAME = 'shrinkwrap.yaml' export const PRIVATE_SHRINKWRAP_FILENAME = path.join('node_modules', '.shrinkwrap.yaml') +export const SHRINKWRAP_VERSION = 3.1 diff --git a/src/prune.ts b/src/prune.ts index 586c71fc81..b3fa82266a 100644 --- a/src/prune.ts +++ b/src/prune.ts @@ -7,8 +7,7 @@ import { ResolvedDependencies, } from './types' import {refToRelative} from 'dependency-path' - -const SHRINKWRAP_VERSION = 3 +import {SHRINKWRAP_VERSION} from './constants' export default function prune (shr: Shrinkwrap, pkg: Package): Shrinkwrap { const packages: ResolvedPackages = {} diff --git a/src/read.ts b/src/read.ts index 6418510e04..5eada3ad50 100644 --- a/src/read.ts +++ b/src/read.ts @@ -6,8 +6,7 @@ import { } from './constants' import {Shrinkwrap} from './types' import loadYamlFile = require('load-yaml-file') - -const SHRINKWRAP_VERSION = 3 +import {SHRINKWRAP_VERSION} from './constants' // TODO: move to separate package type PnpmErrorCode = 'SHRINKWRAP_BREAKING_CHANGE' @@ -64,12 +63,16 @@ async function _read ( return null } // for backward compatibility - if (shrinkwrap && shrinkwrap['version'] === SHRINKWRAP_VERSION) { - shrinkwrap.shrinkwrapVersion = SHRINKWRAP_VERSION + if (shrinkwrap && shrinkwrap['version'] && !shrinkwrap.shrinkwrapVersion) { + shrinkwrap.shrinkwrapVersion = shrinkwrap['version'] delete shrinkwrap['version'] return shrinkwrap } - if (shrinkwrap && shrinkwrap.shrinkwrapVersion === SHRINKWRAP_VERSION) { + if (shrinkwrap && Math.floor(shrinkwrap.shrinkwrapVersion) === Math.floor(SHRINKWRAP_VERSION)) { + if (shrinkwrap.shrinkwrapVersion > SHRINKWRAP_VERSION) { + logger.warn(`Your shrinkwrap.yaml was generated by a newer version of pnpm. + It is a compatible version but it might get downgraded to version ${SHRINKWRAP_VERSION}`) + } return shrinkwrap } if (opts.ignoreIncompatible) { diff --git a/src/types.ts b/src/types.ts index 484fadf742..c7679e503d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -55,6 +55,7 @@ export type DependencyShrinkwrap = { id?: string, dev?: true, optional?: true, + name?: string, // is only needed for packages that are hosted not in the npm registry resolution: ShrinkwrapResolution, dependencies?: ResolvedDependencies, optionalDependencies?: ResolvedDependencies, diff --git a/test/fixtures/1/node_modules/.shrinkwrap.yaml b/test/fixtures/1/node_modules/.shrinkwrap.yaml index 0a70affa4b..0ee15e353a 100644 --- a/test/fixtures/1/node_modules/.shrinkwrap.yaml +++ b/test/fixtures/1/node_modules/.shrinkwrap.yaml @@ -1 +1 @@ -version: 3 +version: 3.1 diff --git a/test/fixtures/1/shrinkwrap.yaml b/test/fixtures/1/shrinkwrap.yaml index 0a70affa4b..0ee15e353a 100644 --- a/test/fixtures/1/shrinkwrap.yaml +++ b/test/fixtures/1/shrinkwrap.yaml @@ -1 +1 @@ -version: 3 +version: 3.1 diff --git a/test/fixtures/2/node_modules/.shrinkwrap.yaml b/test/fixtures/2/node_modules/.shrinkwrap.yaml index e604f8eedc..62a63992b8 100644 --- a/test/fixtures/2/node_modules/.shrinkwrap.yaml +++ b/test/fixtures/2/node_modules/.shrinkwrap.yaml @@ -1 +1 @@ -shrinkwrapVersion: 3 +shrinkwrapVersion: 3.1 diff --git a/test/fixtures/2/shrinkwrap.yaml b/test/fixtures/2/shrinkwrap.yaml index e604f8eedc..62a63992b8 100644 --- a/test/fixtures/2/shrinkwrap.yaml +++ b/test/fixtures/2/shrinkwrap.yaml @@ -1 +1 @@ -shrinkwrapVersion: 3 +shrinkwrapVersion: 3.1 diff --git a/test/prune.ts b/test/prune.ts index 09faa3c682..24391c8856 100644 --- a/test/prune.ts +++ b/test/prune.ts @@ -30,7 +30,7 @@ test('remove one redundant package', t => { 'is-positive': '^1.0.0' } }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'is-positive': '1.0.0' @@ -90,7 +90,7 @@ test('keep all', t => { 'is-negative': '^1.0.0', } }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'is-positive': '1.0.0', @@ -164,7 +164,7 @@ test('optional dependency should have optional = true', t => { 'pkg-with-good-optional': '^1.0.0', }, }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'pkg-with-good-optional': '1.0.0', @@ -232,7 +232,7 @@ test('optional dependency should not have optional = true if used not only as op 'is-positive': '^1.0.0', }, }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'pkg-with-good-optional': '1.0.0', @@ -298,7 +298,7 @@ test('dev dependency should have dev = true', t => { 'pkg-with-good-optional': '^1.0.0', }, }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'pkg-with-good-optional': '1.0.0', @@ -367,7 +367,7 @@ test('dev dependency should not have dev = true if it is used not only as dev', 'some-pkg': '^1.0.0', }, }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'some-pkg': '1.0.0', @@ -438,7 +438,7 @@ test('remove dependencies that are not in the package', t => { name: 'foo', version: '1.0.0', }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', specifiers: {}, }) @@ -471,7 +471,7 @@ test('ignore dependencies that are in package.json but are not in shrinkwrap.yam 'is-negative': '^1.0.0', } }), { - shrinkwrapVersion: 3, + shrinkwrapVersion: 3.1, registry: 'https://registry.npmjs.org', dependencies: { 'is-positive': '1.0.0' diff --git a/test/read.ts b/test/read.ts index b14f3a5f21..89e7578bc9 100644 --- a/test/read.ts +++ b/test/read.ts @@ -9,13 +9,13 @@ test('read()', async t => { const shr = await read(path.join('fixtures', '1'), { ignoreIncompatible: false, }) - t.equal(shr!.shrinkwrapVersion, 3, 'converted version to shrinkwrapVersion') + t.equal(shr!.shrinkwrapVersion, 3.1, 'converted version to shrinkwrapVersion') } { const shr = await read(path.join('fixtures', '2'), { ignoreIncompatible: false, }) - t.equal(shr!.shrinkwrapVersion, 3) + t.equal(shr!.shrinkwrapVersion, 3.1) } t.end() }) @@ -25,13 +25,13 @@ test('readPrivate()', async t => { const shr = await readPrivate(path.join('fixtures', '1'), { ignoreIncompatible: false, }) - t.equal(shr!.shrinkwrapVersion, 3, 'converted version to shrinkwrapVersion') + t.equal(shr!.shrinkwrapVersion, 3.1, 'converted version to shrinkwrapVersion') } { const shr = await readPrivate(path.join('fixtures', '2'), { ignoreIncompatible: false, }) - t.equal(shr!.shrinkwrapVersion, 3) + t.equal(shr!.shrinkwrapVersion, 3.1) } t.end() })