Skip to content

Commit 613a6e9

Browse files
committed
fix(libnpmpack): obey ignoreScripts
1 parent 37bf6d3 commit 613a6e9

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

workspaces/libnpmpack/lib/index.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const spawk = require('spawk')
55
module.exports = tspawk
66

77
function tspawk (t) {
8-
spawk.preventUnmatched()
98
t.teardown(function () {
109
spawk.unload()
1110
})

workspaces/libnpmpack/test/index.js

Lines changed: 38 additions & 2 deletions
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,40 @@ 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+
spawk.clean()
206+
207+
t.teardown(async () => {
208+
process.chdir(cwd)
209+
})
210+
})

0 commit comments

Comments
 (0)