Skip to content

Commit 0176664

Browse files
committed
Simplify npm/npx commands
1 parent ab9bfae commit 0176664

File tree

2 files changed

+10
-66
lines changed

2 files changed

+10
-66
lines changed

src/commands/npm.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,12 @@
1-
import path from 'node:path'
2-
3-
import spawn from '@npmcli/promise-spawn'
4-
51
import constants from '../constants'
62

73
import type { CliSubcommand } from '../utils/meow-with-subcommands'
84

9-
const { abortSignal, execPath, rootBinPath } = constants
10-
11-
const description = 'npm wrapper functionality'
12-
135
export const npm: CliSubcommand = {
14-
description,
15-
async run(argv, _importMeta, _ctx) {
16-
const wrapperPath = path.join(rootBinPath, 'npm-cli.js')
17-
process.exitCode = 1
18-
const spawnPromise = spawn(
19-
execPath,
20-
[
21-
// Lazily access constants.nodeNoWarningsFlags.
22-
...constants.nodeNoWarningsFlags,
23-
wrapperPath,
24-
...argv
25-
],
26-
{
27-
signal: abortSignal,
28-
stdio: 'inherit'
29-
}
30-
)
31-
spawnPromise.process.on('exit', (code, signal) => {
32-
if (signal) {
33-
process.kill(process.pid, signal)
34-
} else if (code !== null) {
35-
process.exit(code)
36-
}
37-
})
38-
await spawnPromise
6+
description: 'npm wrapper functionality',
7+
async run(argv) {
8+
// Lazily access constants.DIST_TYPE.
9+
const shadowBin = require(`../dist/${constants.DIST_TYPE}/shadow-bin.js`)
10+
await shadowBin('npm', argv)
3911
}
4012
}

src/commands/npx.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,12 @@
1-
import path from 'node:path'
2-
3-
import spawn from '@npmcli/promise-spawn'
4-
51
import constants from '../constants'
62

73
import type { CliSubcommand } from '../utils/meow-with-subcommands'
84

9-
const { abortSignal, execPath, rootBinPath } = constants
10-
11-
const description = 'npx wrapper functionality'
12-
135
export const npx: CliSubcommand = {
14-
description,
15-
async run(argv, _importMeta, _ctx) {
16-
const wrapperPath = path.join(rootBinPath, 'npx-cli.js')
17-
process.exitCode = 1
18-
const spawnPromise = spawn(
19-
execPath,
20-
[
21-
// Lazily access constants.nodeNoWarningsFlags.
22-
...constants.nodeNoWarningsFlags,
23-
wrapperPath,
24-
...argv
25-
],
26-
{
27-
abortSignal,
28-
stdio: 'inherit'
29-
}
30-
)
31-
spawnPromise.process.on('exit', (code, signal) => {
32-
if (signal) {
33-
process.kill(process.pid, signal)
34-
} else if (code !== null) {
35-
process.exit(code)
36-
}
37-
})
38-
await spawnPromise
6+
description: 'npx wrapper functionality',
7+
async run(argv) {
8+
// Lazily access constants.DIST_TYPE.
9+
const shadowBin = require(`../dist/${constants.DIST_TYPE}/shadow-bin.js`)
10+
await shadowBin('npx', argv)
3911
}
4012
}

0 commit comments

Comments
 (0)