Skip to content

Commit a990c3c

Browse files
winterqtfritzy
authored andcommitted
fix(libnpmpack): obey ignoreScripts
1 parent fb4be71 commit a990c3c

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

workspaces/libnpmpack/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function pack (spec = 'file:.', opts = {}) {
2121

2222
const stdio = opts.foregroundScripts ? 'inherit' : 'pipe'
2323

24-
if (spec.type === 'directory') {
24+
if (spec.type === 'directory' && !opts.ignoreScripts) {
2525
// prepack
2626
await runScript({
2727
...opts,
@@ -48,7 +48,7 @@ async function pack (spec = 'file:.', opts = {}) {
4848
await writeFile(destination, tarball)
4949
}
5050

51-
if (spec.type === 'directory') {
51+
if (spec.type === 'directory' && !opts.ignoreScripts) {
5252
// postpack
5353
await runScript({
5454
...opts,

workspaces/libnpmpack/test/fixtures/tspawk.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ const spawk = require('spawk')
55
module.exports = tspawk
66

77
function tspawk (t) {
8-
spawk.preventUnmatched()
98
t.teardown(function () {
10-
spawk.unload()
11-
})
12-
t.afterEach(function () {
139
spawk.done()
10+
spawk.unload()
1411
})
1512
return spawk
1613
}

workspaces/libnpmpack/test/index.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const t = require('tap')
44

55
const tspawk = require('./fixtures/tspawk.js')
6+
const spawk = tspawk(t)
67

78
const fs = require('fs')
89
const path = require('path')
@@ -138,8 +139,6 @@ t.test('packs from registry spec', async t => {
138139
})
139140

140141
t.test('runs scripts in foreground when foregroundScripts === true', async t => {
141-
const spawk = tspawk(t)
142-
143142
const testDir = t.testdir({
144143
'package.json': JSON.stringify({
145144
name: 'my-cool-pkg',
@@ -172,3 +171,39 @@ t.test('runs scripts in foreground when foregroundScripts === true', async t =>
172171
process.chdir(cwd)
173172
})
174173
})
174+
175+
t.test('doesn\'t run scripts when ignoreScripts === true', async t => {
176+
const testDir = t.testdir({
177+
'package.json': JSON.stringify({
178+
name: 'my-cool-pkg',
179+
version: '1.0.0',
180+
scripts: {
181+
prepack: 'touch prepack',
182+
},
183+
}, null, 2),
184+
})
185+
186+
const cwd = process.cwd()
187+
process.chdir(testDir)
188+
189+
const [scriptShell, scriptArgs] = makeSpawnArgs({
190+
event: 'prepack',
191+
path: testDir,
192+
cmd: 'touch prepack',
193+
})
194+
195+
const prepack = spawk.spawn(scriptShell, scriptArgs)
196+
197+
await pack('file:.', {
198+
packDestination: testDir,
199+
foregroundScripts: true,
200+
ignoreScripts: true,
201+
})
202+
203+
t.ok(!prepack.called)
204+
205+
t.teardown(async () => {
206+
process.chdir(cwd)
207+
spawk.clean()
208+
})
209+
})

0 commit comments

Comments
 (0)