mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-07 15:38:24 -04:00
fix: print warning when pnpmfile exports undefined
close #1615 PR #2269
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
9
packages/pnpmfile/test/index.ts
Normal file
9
packages/pnpmfile/test/index.ts
Normal 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()
|
||||
})
|
||||
1
packages/pnpmfile/test/pnpmfiles/undefined.js
Normal file
1
packages/pnpmfile/test/pnpmfiles/undefined.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = undefined
|
||||
Reference in New Issue
Block a user