From 71b23ea68e2e831faeff66f89ebe9c77e53e22b7 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 24 Jan 2018 09:13:57 +0200 Subject: [PATCH] fix: --no-optional ref #1014 --- package.json | 1 + shrinkwrap.yaml | 20 +++++++++++++ src/bin/pnpm.ts | 2 -- test/install/index.ts | 1 + test/install/only.ts | 27 +++++------------ test/install/optional.ts | 53 ++++++++++++++++++++++++++++++++++ test/utils/simple-package.json | 3 ++ 7 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 test/install/optional.ts diff --git a/package.json b/package.json index c9115d558d..f8f1b95d50 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@zkochan/husky": "^0.0.0", "anonymous-npm-registry-client": "^0.1.2", "caw": "^2.0.0", + "deep-require-cwd": "^1.0.0", "execa": "^0.9.0", "exists-link": "^2.0.0", "isexe": "^2.0.0", diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index fded0f347a..0d0a07b62a 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -64,6 +64,7 @@ devDependencies: '@zkochan/husky': 0.0.0 anonymous-npm-registry-client: 0.1.2 caw: 2.0.1 + deep-require-cwd: 1.0.0 execa: 0.9.0 exists-link: 2.0.0 isexe: 2.0.0 @@ -1915,6 +1916,24 @@ packages: node: '>=0.12.0' resolution: integrity: sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8= + /deep-require-cwd/1.0.0: + dependencies: + deep-require-from: 1.0.0 + dev: true + resolution: + integrity: sha1-ZWmitmyT7mBlQ2dufUhqk6H3aXc= + /deep-require-from/1.0.0: + dependencies: + deep-resolve-from: 1.1.0 + dev: true + resolution: + integrity: sha1-BkXTXGy+BjfNQisYdps7HnJG3Yk= + /deep-resolve-from/1.1.0: + dependencies: + resolve-from: 3.0.0 + dev: true + resolution: + integrity: sha1-ghlR7I3zWdul9hXzXXa+XJ1Y9Oc= /defaults/1.0.3: dependencies: clone: 1.0.3 @@ -7179,6 +7198,7 @@ specifiers: chalk: ^2.2.0 common-tags: ^1.4.0 cross-spawn: ^5.0.0 + deep-require-cwd: ^1.0.0 delay: ^2.0.0 diable: ^4.0.1 execa: ^0.9.0 diff --git a/src/bin/pnpm.ts b/src/bin/pnpm.ts index 9600d7ee77..4425d350ca 100755 --- a/src/bin/pnpm.ts +++ b/src/bin/pnpm.ts @@ -199,7 +199,6 @@ async function run (argv: string[]) { if (opts.only === 'prod' || opts.only === 'production' || !opts.only && opts.production) { opts.production = true opts.development = false - opts.optional = true } else if (opts.only === 'dev' || opts.only === 'development') { opts.production = false opts.development = true @@ -207,7 +206,6 @@ async function run (argv: string[]) { } else { opts.production = true opts.development = true - opts.optional = true } const reporterType: ReporterType = (() => { diff --git a/test/install/index.ts b/test/install/index.ts index 14f42c66d5..e39b662a8a 100644 --- a/test/install/index.ts +++ b/test/install/index.ts @@ -4,3 +4,4 @@ import './lifecycleScripts' import './hooks' import './preferOffline' import './sideEffects' +import './optional' diff --git a/test/install/only.ts b/test/install/only.ts index 4cb1c15b07..09cd77b7b9 100644 --- a/test/install/only.ts +++ b/test/install/only.ts @@ -11,23 +11,16 @@ import { const basicPackageJson = loadJsonFile.sync(path.join(__dirname, '../utils/simple-package.json')) const test = promisifyTape(tape) +test.only = promisifyTape(tape.only) test('production install (with --production flag)', async (t: tape.Test) => { const project = prepare(t, basicPackageJson) await execPnpm('install', '--production') - const rimrafDir = fs.statSync(path.resolve('node_modules', 'rimraf')) - - let tapStatErrCode: number = 0 - try { - fs.statSync(path.resolve('node_modules', '@rstacruz')) - } catch (err) { - tapStatErrCode = err.code - } - - t.ok(rimrafDir.isSymbolicLink, 'rimraf exists') - t.is(tapStatErrCode, 'ENOENT', 'tap-spec does not exist') + await project.hasNot('@rstacruze/tap-spect') + await project.has('rimraf') + await project.has('is-positive') }) test('production install (with production NODE_ENV)', async (t: tape.Test) => { @@ -40,15 +33,9 @@ test('production install (with production NODE_ENV)', async (t: tape.Test) => { // reset NODE_ENV process.env.NODE_ENV = originalNodeEnv - const rimrafDir = fs.statSync(path.resolve('node_modules', 'rimraf')) - - let tapStatErrCode: number = 0 - try { - fs.statSync(path.resolve('node_modules', '@rstacruz')) - } catch (err) { tapStatErrCode = err.code } - - t.ok(rimrafDir.isSymbolicLink, 'rimraf exists') - t.is(tapStatErrCode, 'ENOENT', 'tap-spec does not exist') + await project.hasNot('@rstacruze/tap-spect') + await project.has('rimraf') + await project.has('is-positive') }) test('install dev dependencies only', async (t: tape.Test) => { diff --git a/test/install/optional.ts b/test/install/optional.ts new file mode 100644 index 0000000000..b548bcff1e --- /dev/null +++ b/test/install/optional.ts @@ -0,0 +1,53 @@ +import path = require('path') +import fs = require('mz/fs') +import tape = require('tape') +import loadJsonFile = require('load-json-file') +import promisifyTape from 'tape-promise' +import deepRequireCwd = require('deep-require-cwd') +import { + prepare, + testDefaults, + execPnpm, +} from '../utils' + +const basicPackageJson = loadJsonFile.sync(path.join(__dirname, '../utils/simple-package.json')) +const test = promisifyTape(tape) +test.only = promisifyTape(tape.only) + +test('installing optional dependencies when --no-optional is not used', async (t: tape.Test) => { + const project = prepare(t, { + dependencies: { + 'pkg-with-good-optional': '*', + }, + optionalDependencies: { + 'is-positive': '1.0.0', + }, + }) + + await execPnpm('install') + + await project.has('is-positive') + await project.has('pkg-with-good-optional') + + t.ok(deepRequireCwd(['pkg-with-good-optional', 'dep-of-pkg-with-1-dep', './package.json'])) + t.ok(deepRequireCwd(['pkg-with-good-optional', 'is-positive', './package.json']), 'optional subdep installed') +}) + +test('not installing optional dependencies when --no-optional is used', async (t: tape.Test) => { + const project = prepare(t, { + dependencies: { + 'pkg-with-good-optional': '*', + }, + optionalDependencies: { + 'is-positive': '1.0.0', + }, + }) + + await execPnpm('install', '--no-optional') + + await project.hasNot('is-positive') + await project.has('pkg-with-good-optional') + + t.ok(deepRequireCwd(['pkg-with-good-optional', 'dep-of-pkg-with-1-dep', './package.json'])) + t.notOk(deepRequireCwd.silent(['pkg-with-good-optional', 'is-positive', './package.json']), 'optional subdep not installed') +}) diff --git a/test/utils/simple-package.json b/test/utils/simple-package.json index 83facb07b4..b435e68979 100644 --- a/test/utils/simple-package.json +++ b/test/utils/simple-package.json @@ -6,5 +6,8 @@ }, "devDependencies": { "@rstacruz/tap-spec": "~4.1.1" + }, + "optionalDependencies": { + "is-positive": "1.0.0" } }