@socketsecurity/cli 0.4.2 → 0.5.2
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/lib/commands/index.js +2 -0
- package/lib/commands/info/index.js +9 -27
- package/lib/commands/npm/index.js +22 -0
- package/lib/commands/npx/index.js +22 -0
- package/lib/commands/report/create.js +26 -35
- package/lib/commands/report/view.js +9 -28
- package/lib/flags/index.js +2 -0
- package/lib/flags/output.js +16 -0
- package/lib/flags/validation.js +14 -0
- package/lib/shadow/bin/npm +2 -0
- package/lib/shadow/bin/npx +2 -0
- package/lib/shadow/global.d.ts +3 -0
- package/lib/shadow/link.cjs +43 -0
- package/lib/shadow/npm-cli.cjs +27 -0
- package/lib/shadow/npm-injection.cjs +369 -0
- package/lib/shadow/npx-cli.cjs +27 -0
- package/lib/shadow/package.json +3 -0
- package/lib/shadow/translations.json +689 -0
- package/lib/utils/api-helpers.js +3 -2
- package/lib/utils/flags.js +27 -0
- package/lib/utils/formatting.js +20 -9
- package/package.json +17 -7
package/lib/utils/api-helpers.js
CHANGED
|
@@ -4,12 +4,13 @@ import { ErrorWithCause } from 'pony-cause'
|
|
|
4
4
|
import { AuthError } from './errors.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @template T
|
|
7
|
+
* @template {import('@socketsecurity/sdk').SocketSdkOperations} T
|
|
8
|
+
* @param {T} _name
|
|
8
9
|
* @param {import('@socketsecurity/sdk').SocketSdkErrorType<T>} result
|
|
9
10
|
* @param {import('ora').Ora} spinner
|
|
10
11
|
* @returns {void}
|
|
11
12
|
*/
|
|
12
|
-
export function handleUnsuccessfulApiResponse (result, spinner) {
|
|
13
|
+
export function handleUnsuccessfulApiResponse (_name, result, spinner) {
|
|
13
14
|
const resultError = 'error' in result && result.error && typeof result.error === 'object' ? result.error : {}
|
|
14
15
|
const message = 'message' in resultError && typeof resultError.message === 'string' ? resultError.message : 'No error message returned'
|
|
15
16
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef FlagExtensions
|
|
3
|
+
* @property {string} description
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @template {import('meow').FlagType} Type
|
|
8
|
+
* @template Default
|
|
9
|
+
* @template {boolean} [IsMultiple=false]
|
|
10
|
+
* @typedef {import('meow').Flag<Type, Default, IsMultiple> & FlagExtensions} Flag
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @typedef {Flag<'string', string> | Flag<'string', string[], true>} StringFlag */
|
|
14
|
+
/** @typedef {Flag<'boolean', boolean> | Flag<'boolean', boolean[], true>} BooleanFlag */
|
|
15
|
+
/** @typedef {Flag<'number', number> | Flag<'number', number[], true>} NumberFlag */
|
|
16
|
+
/** @typedef {StringFlag | BooleanFlag | NumberFlag} AnyFlag */
|
|
17
|
+
/** @typedef {Record<string, AnyFlag>} AnyFlags */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @template {AnyFlags} Flags
|
|
21
|
+
* @param {Flags} flags
|
|
22
|
+
* @returns {Readonly<Flags>}
|
|
23
|
+
*/
|
|
24
|
+
export function prepareFlags (flags) {
|
|
25
|
+
// As we can't do "satisfies AnyFlags" in JS yet (+ we add a bonus through Readonly<>)
|
|
26
|
+
return flags
|
|
27
|
+
}
|
package/lib/utils/formatting.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
/** @typedef {string|{ description: string }} ListDescription */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef HelpListOptions
|
|
5
|
+
* @property {string} [keyPrefix]
|
|
6
|
+
* @property {number} [padName]
|
|
7
|
+
*/
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* @param {Record<string,ListDescription>} list
|
|
5
11
|
* @param {number} indent
|
|
6
|
-
* @param {
|
|
12
|
+
* @param {HelpListOptions} options
|
|
7
13
|
* @returns {string}
|
|
8
14
|
*/
|
|
9
|
-
export function printHelpList (list, indent,
|
|
15
|
+
export function printHelpList (list, indent, options = {}) {
|
|
16
|
+
const {
|
|
17
|
+
keyPrefix = '',
|
|
18
|
+
padName = 18,
|
|
19
|
+
} = options
|
|
20
|
+
|
|
10
21
|
const names = Object.keys(list).sort()
|
|
11
22
|
|
|
12
23
|
let result = ''
|
|
@@ -15,22 +26,22 @@ export function printHelpList (list, indent, padName = 18) {
|
|
|
15
26
|
const rawDescription = list[name]
|
|
16
27
|
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || ''
|
|
17
28
|
|
|
18
|
-
result += ''.padEnd(indent) + name.padEnd(padName) + description + '\n'
|
|
29
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n'
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
return result.trim()
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
/**
|
|
25
|
-
* @param {Record<string,ListDescription>} list
|
|
36
|
+
* @param {Record<string, ListDescription>} list
|
|
26
37
|
* @param {number} indent
|
|
27
|
-
* @param {
|
|
38
|
+
* @param {HelpListOptions} options
|
|
28
39
|
* @returns {string}
|
|
29
40
|
*/
|
|
30
|
-
|
|
41
|
+
export function printFlagList (list, indent, options = {}) {
|
|
31
42
|
return printHelpList({
|
|
32
|
-
'
|
|
33
|
-
'
|
|
43
|
+
'help': 'Print this help and exits.',
|
|
44
|
+
'version': 'Prints current version and exits.',
|
|
34
45
|
...list,
|
|
35
|
-
}, indent,
|
|
46
|
+
}, indent, { keyPrefix: '--', ...options })
|
|
36
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "CLI tool for Socket.dev",
|
|
5
5
|
"homepage": "http://github.com/SocketDev/socket-cli-js",
|
|
6
6
|
"repository": {
|
|
@@ -15,18 +15,24 @@
|
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": "^14.18.0 ||
|
|
18
|
+
"node": "^14.18.0 || ^16.13.0 || >=18.0.0"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
21
|
"bin": {
|
|
22
|
-
"socket": "cli.js"
|
|
22
|
+
"socket": "cli.js",
|
|
23
|
+
"socket-npm": "lib/shadow/npm-cli.cjs",
|
|
24
|
+
"socket-npx": "lib/shadow/npx-cli.cjs"
|
|
23
25
|
},
|
|
24
26
|
"files": [
|
|
25
27
|
"cli.js",
|
|
26
|
-
"lib/**/*.js"
|
|
28
|
+
"lib/**/*.js",
|
|
29
|
+
"lib/**/*.json",
|
|
30
|
+
"lib/**/*.cjs",
|
|
31
|
+
"lib/shadow/**"
|
|
27
32
|
],
|
|
28
33
|
"scripts": {
|
|
29
|
-
"
|
|
34
|
+
"echo": "echo $PATH",
|
|
35
|
+
"check:dependency-check": "dependency-check '*.js' 'lib/shadow/*.cjs' '*.mjs' 'test/**/*.js' --no-dev",
|
|
30
36
|
"check:installed-check": "installed-check -i eslint-plugin-jsdoc",
|
|
31
37
|
"check:lint": "eslint --report-unused-disable-directives .",
|
|
32
38
|
"check:tsc": "tsc",
|
|
@@ -45,8 +51,11 @@
|
|
|
45
51
|
"@types/mocha": "^10.0.0",
|
|
46
52
|
"@types/mock-fs": "^4.13.1",
|
|
47
53
|
"@types/node": "^14.18.31",
|
|
54
|
+
"@types/npm": "^7.19.0",
|
|
55
|
+
"@types/npmcli__arborist": "^5.6.1",
|
|
48
56
|
"@types/prompts": "^2.4.1",
|
|
49
57
|
"@types/update-notifier": "^6.0.2",
|
|
58
|
+
"@types/which": "^2.0.2",
|
|
50
59
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
51
60
|
"@typescript-eslint/parser": "^5.51.0",
|
|
52
61
|
"c8": "^7.12.0",
|
|
@@ -76,7 +85,7 @@
|
|
|
76
85
|
"dependencies": {
|
|
77
86
|
"@apideck/better-ajv-errors": "^0.3.6",
|
|
78
87
|
"@socketsecurity/config": "^2.0.0",
|
|
79
|
-
"@socketsecurity/sdk": "^0.5.
|
|
88
|
+
"@socketsecurity/sdk": "^0.5.4",
|
|
80
89
|
"chalk": "^5.1.2",
|
|
81
90
|
"globby": "^13.1.3",
|
|
82
91
|
"hpagent": "^1.2.0",
|
|
@@ -89,6 +98,7 @@
|
|
|
89
98
|
"pony-cause": "^2.1.8",
|
|
90
99
|
"prompts": "^2.4.2",
|
|
91
100
|
"terminal-link": "^3.0.0",
|
|
92
|
-
"update-notifier": "^6.0.2"
|
|
101
|
+
"update-notifier": "^6.0.2",
|
|
102
|
+
"which": "^3.0.0"
|
|
93
103
|
}
|
|
94
104
|
}
|