Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinter <winter@winter.cafe>2022-10-06 03:25:10 +0300
committerNathan Fritz <fritzy@github.com>2022-10-12 21:15:09 +0300
commita990c3c9a0e67f0a8b6454213675e159fe49432d (patch)
treeba063aee2d0e666ecda0ac28af49d3dbf45f07e9
parentfb4be71ac9aea405c120d577dc9ee0dc4742cbf0 (diff)
fix(libnpmpack): obey ignoreScripts
-rw-r--r--workspaces/libnpmpack/lib/index.js4
-rw-r--r--workspaces/libnpmpack/test/fixtures/tspawk.js5
-rw-r--r--workspaces/libnpmpack/test/index.js39
3 files changed, 40 insertions, 8 deletions
diff --git a/workspaces/libnpmpack/lib/index.js b/workspaces/libnpmpack/lib/index.js
index baccadc33..70d67d360 100644
--- a/workspaces/libnpmpack/lib/index.js
+++ b/workspaces/libnpmpack/lib/index.js
@@ -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,
@@ -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,
diff --git a/workspaces/libnpmpack/test/fixtures/tspawk.js b/workspaces/libnpmpack/test/fixtures/tspawk.js
index 554a9d402..b2559fc36 100644
--- a/workspaces/libnpmpack/test/fixtures/tspawk.js
+++ b/workspaces/libnpmpack/test/fixtures/tspawk.js
@@ -5,12 +5,9 @@ const spawk = require('spawk')
module.exports = tspawk
function tspawk (t) {
- spawk.preventUnmatched()
t.teardown(function () {
- spawk.unload()
- })
- t.afterEach(function () {
spawk.done()
+ spawk.unload()
})
return spawk
}
diff --git a/workspaces/libnpmpack/test/index.js b/workspaces/libnpmpack/test/index.js
index fb50e197b..aa4f955fa 100644
--- a/workspaces/libnpmpack/test/index.js
+++ b/workspaces/libnpmpack/test/index.js
@@ -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')
@@ -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',
@@ -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()
+ })
+})