node-power-user 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +5 -0
- package/dist/commands/npx.js +42 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ const ALIASES = {
|
|
|
10
10
|
global: ['-g', '--global'],
|
|
11
11
|
audit: ['--audit'],
|
|
12
12
|
install: ['-i', '--install', 'i'],
|
|
13
|
+
npx: ['--npx'],
|
|
13
14
|
open: ['--open', 'repo', '--repo'],
|
|
14
15
|
outdated: ['-o', 'out', '--outdated', '-u', '--update', 'up', 'update'],
|
|
15
16
|
packages: ['-p', 'pack', '--packages'],
|
|
@@ -46,6 +47,10 @@ function resolveCommand(options) {
|
|
|
46
47
|
function Main() {}
|
|
47
48
|
|
|
48
49
|
Main.prototype.process = async function (options) {
|
|
50
|
+
// Prevent recursion: zsh/PATH wrappers route npm/npx → npu. When npu
|
|
51
|
+
// spawns subprocesses (sfw, npm, npx), they must NOT loop back to npu.
|
|
52
|
+
process.env._NPU_GUARD = '1';
|
|
53
|
+
|
|
49
54
|
// Fix options
|
|
50
55
|
options = options || {};
|
|
51
56
|
options._ = options._ || [];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const logger = new (require('../lib/logger'))('node-power-user');
|
|
3
|
+
const socket = require('../lib/socket');
|
|
4
|
+
|
|
5
|
+
// Module
|
|
6
|
+
module.exports = async function (options) {
|
|
7
|
+
// Get everything after "npx" as the command to run
|
|
8
|
+
const args = (options._ || []).slice(1);
|
|
9
|
+
|
|
10
|
+
if (args.length === 0) {
|
|
11
|
+
logger.error('Usage: npu npx <command> [args...]');
|
|
12
|
+
logger.log(`Example: ${logger.format.cyan('npu npx create-react-app my-app')}`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const command = `npx ${args.join(' ')}`;
|
|
17
|
+
|
|
18
|
+
// Check firewall status upfront (blocks if not installed unless --force)
|
|
19
|
+
await socket.check({ force: options.force });
|
|
20
|
+
|
|
21
|
+
// Log
|
|
22
|
+
logger.log(`Running: ${logger.format.cyan(command)}`);
|
|
23
|
+
|
|
24
|
+
// Wrap with Socket Firewall
|
|
25
|
+
try {
|
|
26
|
+
await socket.wrap(command, { force: options.force });
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (e.reason === 'npm-failed') {
|
|
29
|
+
logger.log('');
|
|
30
|
+
logger.log('npx command failed. See the error output above.');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
logger.log('');
|
|
35
|
+
logger.log('Command blocked. See the output above for details.');
|
|
36
|
+
logger.log('To retry without firewall protection:');
|
|
37
|
+
logger.log(logger.format.cyan(` npu npx ${args.join(' ')} --force`));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
logger.log(logger.format.green('Done.'));
|
|
42
|
+
};
|