fix(pnpmfile): installation should fail if pnpmfile fails

close #1247
This commit is contained in:
Zoltan Kochan
2018-06-29 02:17:26 +03:00
parent b013ad128c
commit 1dfbfcf068
2 changed files with 28 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import logger from '@pnpm/logger'
import chalk from 'chalk'
import path = require('path')
import fs = require('fs')
export default (pnpmFilePath: string) => {
try {
@@ -33,7 +33,22 @@ export default (pnpmFilePath: string) => {
process.exit(1)
return
}
if (err.code !== 'MODULE_NOT_FOUND') throw err
if (err.code !== 'MODULE_NOT_FOUND' || pnpmFileExistsSync(pnpmFilePath)) {
const errWrapper = new Error(`Error during pnpmfile execution. pnpmfile: "${pnpmFilePath}". Error: "${err.message}".`)
// tslint:disable:no-string-literal
errWrapper['code'] = 'ERR_PNPM_PNPMFILE_FAIL'
err['pnpmfile'] = pnpmFilePath
errWrapper['originalError'] = err
// tslint:enable:no-string-literal
throw errWrapper
}
return undefined
}
}
function pnpmFileExistsSync (pnpmFilePath: string) {
const pnpmFileRealName = pnpmFilePath.endsWith('.js')
? pnpmFilePath
: `${pnpmFilePath}.js`
return fs.existsSync(pnpmFileRealName)
}

View File

@@ -184,6 +184,17 @@ test('prints meaningful error when there is syntax error in pnpmfile.js', async
t.equal(proc.status, 1)
})
test('fails when pnpmfile.js requires a non-existend module', async (t: tape.Test) => {
const project = prepare(t)
await fs.writeFile('pnpmfile.js', 'module.exports = require("./this-does-node-exist")', 'utf8')
const proc = execPnpmSync('install', 'pkg-with-1-dep')
t.ok(proc.stdout.toString().indexOf('Error during pnpmfile execution') !== -1)
t.equal(proc.status, 1)
})
test('ignore pnpmfile.js when --ignore-pnpmfile is used', async (t: tape.Test) => {
const project = prepare(t)