feat(CLI): add pnpm verify command

Rel #585
This commit is contained in:
zkochan
2017-02-05 17:20:09 +02:00
parent f119581587
commit 848922d551
6 changed files with 57 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ import dirsum from '../fs/dirsum'
export default async function (maybeOpts: PnpmOptions) {
const opts = extendOptions(maybeOpts)
const ctx = await getContext(opts)
if (!ctx.graph) return
if (!ctx.graph) return []
const pkgPaths = Object.keys(ctx.graph)
.filter(pkgPath => !isProjectPath(pkgPath))

View File

@@ -18,6 +18,7 @@ import publishCmd from '../cmd/publish'
import pruneCmd from '../cmd/prune'
import installTestCmd from '../cmd/installTest'
import runCmd from '../cmd/run'
import verifyCmd from '../cmd/verify'
import bole = require('bole')
import initReporter from '../reporter'
@@ -32,6 +33,7 @@ const pnpmCmds = {
prune: pruneCmd,
'install-test': installTestCmd,
run: runCmd,
verify: verifyCmd,
}
const supportedCmds = new Set([
@@ -44,6 +46,7 @@ const supportedCmds = new Set([
'prune',
'install-test',
'run',
'verify',
])
async function run (argv: string[]) {

View File

@@ -4,8 +4,11 @@ import delocalizeDeps = require('delocalize-dependencies')
import readPkgUp = require('read-pkg-up')
import {PnpmOptions} from '../types'
import writePkg = require('write-pkg')
import verifyCmd from './verify'
export default async function (input: string[], opts: PnpmOptions) {
await verifyCmd(input, opts)
if (!opts.linkLocal) {
runNpmPublish()
}

18
src/cmd/verify.ts Normal file
View File

@@ -0,0 +1,18 @@
import verify from '../api/verify'
import {PnpmOptions} from '../types'
import {PnpmError} from '../errorTypes'
export default async function (input: string[], opts: PnpmOptions) {
const modifiedPkgs = await verify(opts)
if (!modifiedPkgs || !modifiedPkgs.length) return
throw new VerificationError(modifiedPkgs)
}
class VerificationError extends PnpmError {
constructor (modified: string[]) {
super('MODIFIED_DEPENDENCY', '')
this.modified = modified
}
modified: string[]
}

View File

@@ -1,4 +1,7 @@
export type PnpmErrorCode = 'UNEXPECTED_STORE' | 'STORE_BREAKING_CHANGE' | 'MODULES_BREAKING_CHANGE'
export type PnpmErrorCode = 'UNEXPECTED_STORE'
| 'STORE_BREAKING_CHANGE'
| 'MODULES_BREAKING_CHANGE'
| 'MODIFIED_DEPENDENCY'
export class PnpmError extends Error {
constructor (code: PnpmErrorCode, message: string) {

View File

@@ -4,6 +4,7 @@ import rimraf = require('rimraf-then')
import prepare from './support/prepare'
import testDefaults from './support/testDefaults'
import {verify, installPkgs} from '../src'
import execPnpm from './support/execPnpm'
const test = promisifyTape(tape)
@@ -32,3 +33,30 @@ test('verify returns path to the modified package', async function (t: tape.Test
t.equal(mutatedPkgs && mutatedPkgs.length, 1, '1 package was modified')
t.ok(mutatedPkgs && mutatedPkgs[0].indexOf('is-positive') !== -1, 'is-positive was modified')
})
test('CLI fails when verify finds modified packages', async function (t: tape.Test) {
const project = prepare(t)
const opts = testDefaults()
await installPkgs(['is-positive@3.1.0'], opts)
const isPositive = await project.resolve('is-positive', '3.1.0', 'index.js')
await rimraf(isPositive)
try {
await execPnpm('verify')
t.fail('CLI should have failed')
} catch (err) {
t.pass('CLI failed')
}
})
test('CLI does not fail when verify does not find modified packages', async function (t: tape.Test) {
const project = prepare(t)
const opts = testDefaults()
await installPkgs(['is-positive@3.1.0'], opts)
await execPnpm('verify')
t.pass('CLI did not fail')
})