Skip to content

Commit 270683f

Browse files
committed
Add params to npm commands to make it less chatty
1 parent dbefac8 commit 270683f

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

src/commands/optimize.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,14 @@ export const optimize: CliSubcommand = {
897897
const wrapperPath = path.join(distPath, 'npm-cli.js')
898898
await spawn(
899899
process.execPath,
900-
[wrapperPath, 'install', '--no-audit', '--no-fund'],
900+
[
901+
wrapperPath,
902+
'install',
903+
'--no-audit',
904+
'--no-fund',
905+
'--no-progress',
906+
'--quiet'
907+
],
901908
{
902909
stdio: 'ignore',
903910
env: {

test/socket-npm.test.cjs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,49 @@ const { spawnSync } = require('node:child_process')
55
const path = require('node:path')
66
const { describe, it } = require('node:test')
77

8+
const spawn = require('@npmcli/promise-spawn')
9+
810
const constants = require('../scripts/constants')
911
const { distPath } = constants
1012

1113
const testPath = __dirname
1214
const entryPath = path.join(distPath, 'cli.js')
13-
14-
function spawnNPM({ args = [], cwd, installDir }) {
15-
return spawnSync(process.execPath, [entryPath, 'npm', ...args], {
16-
cwd: path.join(testPath, cwd),
17-
encoding: 'utf8',
18-
env: {
19-
// Make sure we don't borrow TTY from parent.
20-
SOCKET_SECURITY_TTY_IPC: undefined,
21-
PATH: `${path.join(installDir, 'node_modules', '.bin')}:${process.env.PATH}`
22-
},
23-
stdio: ['pipe', 'pipe', 'pipe']
24-
})
25-
}
15+
const npmFixturesPath = path.join(testPath, 'socket-npm-fixtures')
2616

2717
// These aliases are defined in package.json.
2818
for (const npm of ['npm8', 'npm10']) {
29-
const installDir = path.join(testPath, `/socket-npm-fixtures/${npm}`)
30-
spawnSync('npm', ['install'], {
31-
cwd: installDir,
32-
stdio: 'ignore'
33-
})
19+
const npmPath = path.join(npmFixturesPath, npm)
20+
const npmBinPath = path.join(npmPath, 'node_modules', '.bin')
21+
22+
spawnSync(
23+
'npm',
24+
['install', '--no-audit', '--no-fund', '--no-progress', '--quiet'],
25+
{
26+
cwd: npmPath,
27+
stdio: 'ignore'
28+
}
29+
)
3430

3531
describe(`Socket npm wrapper for ${npm}`, () => {
36-
it('should bail on new typosquat', () => {
37-
const ret = spawnNPM({
38-
cwd: './socket-npm-fixtures/lacking-typosquat',
39-
installDir,
40-
args: ['i', 'bowserify']
41-
})
42-
assert.strictEqual(ret.status, 1, ret.stderr)
43-
assert.ok(ret.stderr.includes('Unable to prompt'), ret.stderr)
32+
it('should bail on new typosquat', async () => {
33+
try {
34+
await spawn(
35+
process.execPath,
36+
[entryPath, 'npm', 'install', 'bowserify'],
37+
{
38+
cwd: path.join(npmFixturesPath, 'lacking-typosquat'),
39+
encoding: 'utf8',
40+
env: {
41+
// Make sure we don't borrow TTY from parent.
42+
SOCKET_SECURITY_TTY_IPC: undefined,
43+
PATH: `${npmBinPath}:${process.env.PATH}`
44+
}
45+
}
46+
)
47+
assert.ok(false, 'typosquat not error')
48+
} catch (e) {
49+
assert.ok(e?.stderr.includes('Unable to prompt'), e?.stderr)
50+
}
4451
})
4552
})
4653
}

0 commit comments

Comments
 (0)