fix: print warning when pnpmfile exports undefined

close #1615
PR #2269
This commit is contained in:
Zoltan Kochan
2020-01-12 13:52:29 +02:00
committed by GitHub
parent 16accedaa4
commit 2b7635b0de
4 changed files with 18 additions and 1 deletions

View File

@@ -13,7 +13,7 @@
"scripts": {
"lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts",
"tsc": "rimraf lib && tsc",
"test": "pnpm run tsc",
"test": "pnpm run tsc && ts-node test --type-check",
"prepublishOnly": "pnpm run tsc"
},
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/pnpmfile",

View File

@@ -31,6 +31,13 @@ export default (pnpmFilePath: string, prefix: string) => {
message: `Using hooks from: ${pnpmFilePath}`,
prefix,
})
if (typeof pnpmfile === 'undefined') {
logger.warn({
message: `Ignoring the pnpmfile at "${pnpmFilePath}". It exports "undefined".`,
prefix,
})
return undefined
}
if (pnpmfile?.hooks?.readPackage && typeof pnpmfile.hooks.readPackage !== 'function') {
throw new TypeError('hooks.readPackage should be a function')
}

View File

@@ -0,0 +1,9 @@
import { requirePnpmfile } from '@pnpm/pnpmfile'
import path = require('path')
import test = require('tape')
test('ignoring a pnpmfile that exports undefined', (t) => {
const pnpmfile = requirePnpmfile(path.join(__dirname, 'pnpmfiles/undefined.js'), __dirname)
t.equal(typeof pnpmfile, 'undefined')
t.end()
})

View File

@@ -0,0 +1 @@
module.exports = undefined