Skip to content

Commit 242251b

Browse files
authored
fix: added missing npm_package_json env variable (#49)
* Added missing env variable. * Added a minimal test.
1 parent 419131b commit 242251b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function lifecycle (pkg, stage, wd, opts) {
8080
const env = makeEnv(pkg, opts)
8181
env.npm_lifecycle_event = stage
8282
env.npm_node_execpath = env.NODE = env.NODE || process.execPath
83+
env.npm_package_json = path.join(wd, 'package.json')
8384
if (process.pkg != null) {
8485
// If the pnpm CLI was bundled by vercel/pkg then we cannot use the js path for npm_execpath
8586
// because in that case the js is in a virtual filesystem inside the executor.

test/fixtures/count-to-10/postinstall.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
console.log('line 1')
44
console.log('line 2')
55
console.error('some error')
6+
if (process.env.npm_package_json) {
7+
console.log('package.json')
8+
}

test/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ test("reports child's output", async (t) => {
6868
}
6969
const dir = path.join(__dirname, '..')
7070

71-
const pkg = require(path.join(fixture, 'package.json'))
71+
const pkgFileName = path.resolve(fixture, 'package.json')
72+
const pkg = require(pkgFileName)
7273

7374
await lifecycle(pkg, 'postinstall', fixture, {
7475
stdio: 'pipe',
@@ -103,6 +104,15 @@ test("reports child's output", async (t) => {
103104
),
104105
'stderr reported'
105106
)
107+
t.ok(
108+
verbose.calledWithMatch(
109+
'lifecycle',
110+
'undefined~postinstall:',
111+
'stdout',
112+
'package.json'
113+
),
114+
'package json reported'
115+
)
106116
t.ok(
107117
silly.calledWithMatch(
108118
'lifecycle',

0 commit comments

Comments
 (0)