@socketsecurity/cli 0.4.0 → 0.4.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
3
  Copyright (c) 2022 Socket Inc
4
4
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Socket CLI
2
2
 
3
- [![Socket Badge](https://socket.dev/api/badge/npm/pkg/@socketsecurity/cli)](https://socket.dev/npm/package/@socketsecurity/cli)
3
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/@socketsecurity/cli)](https://socket.dev/npm/package/@socketsecurity/cli)
4
4
  [![npm version](https://img.shields.io/npm/v/@socketsecurity/cli.svg?style=flat)](https://www.npmjs.com/package/@socketsecurity/cli)
5
5
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/SocketDev/eslint-config)
6
6
  [![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](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
- import { ensureIsKeyOf } from './type-helpers.js'
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
- const [rawCommandName, ...commandArgv] = argv
34
-
35
- const commandName = ensureIsKeyOf(subcommands, rawCommandName)
36
- const command = commandName ? subcommands[commandName] : undefined
37
-
38
- // If a valid command has been specified, run it...
39
- if (command) {
40
- return await command.run(
41
- commandArgv,
42
- importMeta,
43
- {
44
- parentName: name
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,
@@ -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.0",
3
+ "version": "0.4.1",
4
4
  "description": "CLI tool for Socket.dev",
5
5
  "homepage": "http://github.com/SocketDev/socket-cli-js",
6
6
  "repository": {