mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-05 22:47:50 -04:00
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user