Skip to content

Commit

Permalink
fix(libnpmpack): obey ignoreScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
winterqt committed Oct 11, 2022
1 parent 37bf6d3 commit 8aa35c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions workspaces/libnpmpack/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function pack (spec = 'file:.', opts = {}) {

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

if (spec.type === 'directory') {
if (spec.type === 'directory' && !opts.ignoreScripts) {
// prepack
await runScript({
...opts,
Expand All @@ -48,7 +48,7 @@ async function pack (spec = 'file:.', opts = {}) {
await writeFile(destination, tarball)
}

if (spec.type === 'directory') {
if (spec.type === 'directory' && !opts.ignoreScripts) {
// postpack
await runScript({
...opts,
Expand Down
1 change: 0 additions & 1 deletion workspaces/libnpmpack/test/fixtures/tspawk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const spawk = require('spawk')
module.exports = tspawk

function tspawk (t) {
spawk.preventUnmatched()
t.teardown(function () {
spawk.unload()
})
Expand Down
39 changes: 37 additions & 2 deletions workspaces/libnpmpack/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const t = require('tap')

const tspawk = require('./fixtures/tspawk.js')
const spawk = tspawk(t)

const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -138,8 +139,6 @@ t.test('packs from registry spec', async t => {
})

t.test('runs scripts in foreground when foregroundScripts === true', async t => {
const spawk = tspawk(t)

const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
Expand Down Expand Up @@ -172,3 +171,39 @@ t.test('runs scripts in foreground when foregroundScripts === true', async t =>
process.chdir(cwd)
})
})

t.test('doesn\'t run scripts when ignoreScripts === true', async t => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
version: '1.0.0',
scripts: {
prepack: 'touch prepack',
},
}, null, 2),
})

const cwd = process.cwd()
process.chdir(testDir)

const [scriptShell, scriptArgs] = makeSpawnArgs({
event: 'prepack',
path: testDir,
cmd: 'touch prepack',
})

const prepack = spawk.spawn(scriptShell, scriptArgs)

await pack('file:.', {
packDestination: testDir,
foregroundScripts: true,
ignoreScripts: true,
})

t.ok(!prepack.called)

t.teardown(async () => {
process.chdir(cwd)
spawk.clean()
})
})

0 comments on commit 8aa35c4

Please sign in to comment.