@socketsecurity/cli 0.4.0 → 0.4.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/LICENSE +1 -1
- package/README.md +7 -1
- package/cli.js +6 -0
- package/lib/utils/meow-with-subcommands.js +37 -18
- package/lib/utils/path-resolve.js +3 -0
- package/lib/utils/sdk.js +9 -2
- package/lib/utils/type-helpers.js +0 -10
- package/package.json +9 -9
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Socket CLI
|
|
2
2
|
|
|
3
|
-
[](https://socket.dev/npm/package/@socketsecurity/cli)
|
|
4
4
|
[](https://www.npmjs.com/package/@socketsecurity/cli)
|
|
5
5
|
[](https://github.com/SocketDev/eslint-config)
|
|
6
6
|
[](https://twitter.com/SocketSecurity)
|
|
@@ -34,6 +34,12 @@ socket report view QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
|
34
34
|
|
|
35
35
|
* `socket report view <report-id>` - looks up issues and scores from a report
|
|
36
36
|
|
|
37
|
+
## Aliases
|
|
38
|
+
|
|
39
|
+
All aliases supports flags and arguments of the commands they alias.
|
|
40
|
+
|
|
41
|
+
* `socket ci` - alias for `socket report create --view --strict` which creates a report and quits with an exit code if the result is unhealthy. Use like eg. `socket ci .` for a report for the current folder
|
|
42
|
+
|
|
37
43
|
## Flags
|
|
38
44
|
|
|
39
45
|
### Command specific flags
|
package/cli.js
CHANGED
|
@@ -18,6 +18,12 @@ try {
|
|
|
18
18
|
await meowWithSubcommands(
|
|
19
19
|
cliCommands,
|
|
20
20
|
{
|
|
21
|
+
aliases: {
|
|
22
|
+
ci: {
|
|
23
|
+
description: 'Alias for "report create --view --strict"',
|
|
24
|
+
argv: ['report', 'create', '--view', '--strict']
|
|
25
|
+
},
|
|
26
|
+
},
|
|
21
27
|
argv: process.argv.slice(2),
|
|
22
28
|
name: 'socket',
|
|
23
29
|
importMeta: import.meta
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import meow from 'meow'
|
|
2
2
|
|
|
3
3
|
import { printFlagList, printHelpList } from './formatting.js'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef CliAlias
|
|
7
|
+
* @property {string} description
|
|
8
|
+
* @property {readonly string[]} argv
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** @typedef {Record<string, CliAlias>} CliAliases */
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* @callback CliSubcommandRun
|
|
@@ -20,39 +27,51 @@ import { ensureIsKeyOf } from './type-helpers.js'
|
|
|
20
27
|
/**
|
|
21
28
|
* @template {import('meow').AnyFlags} Flags
|
|
22
29
|
* @param {Record<string, CliSubcommand>} subcommands
|
|
23
|
-
* @param {import('meow').Options<Flags> & { argv: readonly string[], name: string }} options
|
|
30
|
+
* @param {import('meow').Options<Flags> & { aliases?: CliAliases, argv: readonly string[], name: string }} options
|
|
24
31
|
* @returns {Promise<void>}
|
|
25
32
|
*/
|
|
26
33
|
export async function meowWithSubcommands (subcommands, options) {
|
|
27
34
|
const {
|
|
35
|
+
aliases = {},
|
|
28
36
|
argv,
|
|
29
37
|
name,
|
|
30
38
|
importMeta,
|
|
31
39
|
...additionalOptions
|
|
32
40
|
} = options
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
|
|
42
|
+
const [commandOrAliasName, ...rawCommandArgv] = argv
|
|
43
|
+
|
|
44
|
+
// If we got at least some args, then lets find out if we can find a command
|
|
45
|
+
if (commandOrAliasName) {
|
|
46
|
+
const alias = aliases[commandOrAliasName]
|
|
47
|
+
|
|
48
|
+
// First: Resolve argv data from alias if its an alias that's been given
|
|
49
|
+
const [commandName, ...commandArgv] = alias
|
|
50
|
+
? [...alias.argv, ...rawCommandArgv]
|
|
51
|
+
: [commandOrAliasName, ...rawCommandArgv]
|
|
52
|
+
|
|
53
|
+
// Second: Find a command definition using that data
|
|
54
|
+
const commandDefinition = commandName ? subcommands[commandName] : undefined
|
|
55
|
+
|
|
56
|
+
// Third: If a valid command has been found, then we run it...
|
|
57
|
+
if (commandDefinition) {
|
|
58
|
+
return await commandDefinition.run(
|
|
59
|
+
commandArgv,
|
|
60
|
+
importMeta,
|
|
61
|
+
{
|
|
62
|
+
parentName: name
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
// ...else provide basic instructions and help
|
|
68
|
+
// ...else we provide basic instructions and help
|
|
50
69
|
const cli = meow(`
|
|
51
70
|
Usage
|
|
52
71
|
$ ${name} <command>
|
|
53
72
|
|
|
54
73
|
Commands
|
|
55
|
-
${printHelpList(subcommands, 6)}
|
|
74
|
+
${printHelpList({ ...subcommands, ...aliases }, 6)}
|
|
56
75
|
|
|
57
76
|
Options
|
|
58
77
|
${printFlagList({}, 6)}
|
|
@@ -39,6 +39,9 @@ const GLOB_IGNORE = [
|
|
|
39
39
|
* @throws {InputError}
|
|
40
40
|
*/
|
|
41
41
|
export async function getPackageFiles (cwd, inputPaths, config, debugLog) {
|
|
42
|
+
debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)
|
|
43
|
+
|
|
44
|
+
// TODO: Does not support `~/` paths
|
|
42
45
|
const entries = await globby(inputPaths, {
|
|
43
46
|
absolute: true,
|
|
44
47
|
cwd,
|
package/lib/utils/sdk.js
CHANGED
|
@@ -9,10 +9,17 @@ import prompts from 'prompts'
|
|
|
9
9
|
import { AuthError } from './errors.js'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The API key should be stored globally for the duration of the CLI execution
|
|
13
|
+
*
|
|
14
|
+
* @type {string | undefined}
|
|
13
15
|
*/
|
|
16
|
+
let apiKey
|
|
17
|
+
|
|
18
|
+
/** @returns {Promise<import('@socketsecurity/sdk').SocketSdk>} */
|
|
14
19
|
export async function setupSdk () {
|
|
15
|
-
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
apiKey = process.env['SOCKET_SECURITY_API_KEY']
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
if (!apiKey && isInteractive()) {
|
|
18
25
|
const input = await prompts({
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @template T
|
|
3
|
-
* @param {T} obj
|
|
4
|
-
* @param {string|undefined} key
|
|
5
|
-
* @returns {(keyof T) | undefined}
|
|
6
|
-
*/
|
|
7
|
-
export function ensureIsKeyOf (obj, key) {
|
|
8
|
-
return /** @type {keyof T} */ (key && Object.prototype.hasOwnProperty.call(obj, key) ? key : undefined)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
1
|
/**
|
|
12
2
|
* @param {unknown} value
|
|
13
3
|
* @returns {value is NodeJS.ErrnoException}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "CLI tool for Socket.dev",
|
|
5
5
|
"homepage": "http://github.com/SocketDev/socket-cli-js",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "run-s check test:*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@socketsecurity/eslint-config": "^
|
|
41
|
+
"@socketsecurity/eslint-config": "^2.0.0",
|
|
42
42
|
"@tsconfig/node14": "^1.0.3",
|
|
43
43
|
"@types/chai": "^4.3.3",
|
|
44
44
|
"@types/chai-as-promised": "^7.1.5",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
"@types/mock-fs": "^4.13.1",
|
|
47
47
|
"@types/node": "^14.18.31",
|
|
48
48
|
"@types/prompts": "^2.4.1",
|
|
49
|
-
"@types/update-notifier": "^6.0.
|
|
50
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
51
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
+
"@types/update-notifier": "^6.0.2",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
51
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
52
52
|
"c8": "^7.12.0",
|
|
53
53
|
"chai": "^4.3.6",
|
|
54
54
|
"chai-as-promised": "^7.1.1",
|
|
55
55
|
"dependency-check": "^5.0.0-7",
|
|
56
|
-
"eslint": "^8.
|
|
56
|
+
"eslint": "^8.34.0",
|
|
57
57
|
"eslint-config-standard": "^17.0.0",
|
|
58
58
|
"eslint-config-standard-jsx": "^11.0.0",
|
|
59
59
|
"eslint-import-resolver-typescript": "^3.5.3",
|
|
60
60
|
"eslint-plugin-import": "^2.27.5",
|
|
61
|
-
"eslint-plugin-jsdoc": "^
|
|
61
|
+
"eslint-plugin-jsdoc": "^40.0.0",
|
|
62
62
|
"eslint-plugin-n": "^15.6.1",
|
|
63
63
|
"eslint-plugin-promise": "^6.1.1",
|
|
64
|
-
"eslint-plugin-react": "^7.32.
|
|
64
|
+
"eslint-plugin-react": "^7.32.2",
|
|
65
65
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
66
66
|
"eslint-plugin-unicorn": "^45.0.2",
|
|
67
67
|
"husky": "^8.0.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"nock": "^13.3.0",
|
|
72
72
|
"npm-run-all2": "^6.0.2",
|
|
73
73
|
"type-coverage": "^2.24.1",
|
|
74
|
-
"typescript": "~4.9.
|
|
74
|
+
"typescript": "~4.9.5"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@apideck/better-ajv-errors": "^0.3.6",
|