@node-cli/run 1.0.0 → 1.0.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/README.md CHANGED
@@ -53,3 +53,7 @@ const { exitCode, shortMessage } = await runCommand("ls /not-a-folder", {
53
53
  });
54
54
  // -> exitCode is 1 and shortMessage is "Command failed with exit code 1: ls /not-a-folder"
55
55
  ```
56
+
57
+ ## License
58
+
59
+ MIT © Arno Versini
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
4
 
5
- export * from "./index";
5
+ export * from "./run";
package/dist/run.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runs a shell command asynchronously and
3
+ * returns both `stdout` and `stderr`.
4
+ * If the command fails to run (invalid command or the commands status is
5
+ * anything but 0), the call will throw an exception. The exception can be
6
+ * ignored if the `options.ignoreError` flag is true.
7
+ *
8
+ * @async
9
+ */
10
+ export type RunResult = {
11
+ stderr?: string | number;
12
+ stdout?: string | number;
13
+ exitCode?: number;
14
+ shortMessage?: string;
15
+ };
16
+ export declare const run: (command: string, options?: {
17
+ ignoreError?: boolean;
18
+ }) => Promise<RunResult>;
@@ -1,20 +1,12 @@
1
1
  import { execaCommand } from "execa";
2
2
  import kleur from "kleur";
3
- /**
4
- * Runs a shell command asynchronously and
5
- * returns both `stdout` and `stderr`.
6
- * If the command fails to run (invalid command or the commands status is
7
- * anything but 0), the call will throw an exception. The exception can be
8
- * ignored if the `options.ignoreError` flag is true.
9
- *
10
- * @async
11
- */ export const run = async (command, options)=>{
12
- const { ignoreError } = {
3
+ export const run = async (command, options)=>{
4
+ const { ignoreError } = {
13
5
  ignoreError: false,
14
6
  ...options
15
7
  };
16
8
  try {
17
- const { stdout , stderr } = await execaCommand(command, {
9
+ const { stdout, stderr } = await execaCommand(command, {
18
10
  /**
19
11
  * For some reason, a command with a " or ' in execa.command() will
20
12
  * fail, but it works if shell is set to true... It would work if
@@ -40,4 +32,4 @@ import kleur from "kleur";
40
32
  }
41
33
  };
42
34
 
43
- //# sourceMappingURL=index.js.map
35
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run.ts"],"sourcesContent":["import { execaCommand } from \"execa\";\nimport kleur from \"kleur\";\n\n/**\n * Runs a shell command asynchronously and\n * returns both `stdout` and `stderr`.\n * If the command fails to run (invalid command or the commands status is\n * anything but 0), the call will throw an exception. The exception can be\n * ignored if the `options.ignoreError` flag is true.\n *\n * @async\n */\nexport type RunResult = {\n\tstderr?: string | number;\n\tstdout?: string | number;\n\texitCode?: number;\n\tshortMessage?: string;\n};\nexport const run = async (\n\tcommand: string,\n\toptions?: { ignoreError?: boolean },\n): Promise<RunResult> => {\n\tconst { ignoreError } = {\n\t\tignoreError: false,\n\t\t...options,\n\t};\n\ttry {\n\t\tconst { stdout, stderr } = await execaCommand(command, {\n\t\t\t/**\n\t\t\t * For some reason, a command with a \" or ' in execa.command() will\n\t\t\t * fail, but it works if shell is set to true... It would work if\n\t\t\t * the execaCommand() API is not used:\n\t\t\t * execa(\"ls\", [\"-l\", \"|\", \"wc\"]);\n\t\t\t * Same problems with &, &&, | and ||.\n\t\t\t */\n\t\t\tshell:\n\t\t\t\tcommand.includes('\"') ||\n\t\t\t\tcommand.includes(\"'\") ||\n\t\t\t\tcommand.includes(\"&&\") ||\n\t\t\t\tcommand.includes(\"&\") ||\n\t\t\t\tcommand.includes(\"||\") ||\n\t\t\t\tcommand.includes(\"|\"),\n\t\t});\n\n\t\treturn { stderr, stdout };\n\t} catch (error) {\n\t\tif (ignoreError) {\n\t\t\treturn {\n\t\t\t\texitCode: error.exitCode === undefined ? 1 : error.exitCode,\n\t\t\t\tshortMessage: error.shortMessage,\n\t\t\t\tstderr: error.exitCode === undefined ? 1 : error.exitCode,\n\t\t\t};\n\t\t} else {\n\t\t\tthrow new Error(kleur.red(error));\n\t\t}\n\t}\n};\n"],"names":["execaCommand","kleur","run","command","options","ignoreError","stdout","stderr","shell","includes","error","exitCode","undefined","shortMessage","Error","red"],"mappings":"AAAA,SAASA,YAAY,QAAQ,QAAQ;AACrC,OAAOC,WAAW,QAAQ;AAiB1B,OAAO,MAAMC,MAAM,OAClBC,SACAC;IAEA,MAAM,EAAEC,WAAW,EAAE,GAAG;QACvBA,aAAa;QACb,GAAGD,OAAO;IACX;IACA,IAAI;QACH,MAAM,EAAEE,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMP,aAAaG,SAAS;YACtD;;;;;;IAMC,GACDK,OACCL,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC;QACnB;QAEA,OAAO;YAAEF;YAAQD;QAAO;IACzB,EAAE,OAAOI,OAAO;QACf,IAAIL,aAAa;YAChB,OAAO;gBACNM,UAAUD,MAAMC,QAAQ,KAAKC,YAAY,IAAIF,MAAMC,QAAQ;gBAC3DE,cAAcH,MAAMG,YAAY;gBAChCN,QAAQG,MAAMC,QAAQ,KAAKC,YAAY,IAAIF,MAAMC,QAAQ;YAC1D;QACD,OAAO;YACN,MAAM,IAAIG,MAAMb,MAAMc,GAAG,CAACL;QAC3B;IACD;AACD,EAAE"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@node-cli/run",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "A wrapper for child_process for nodejs CLI apps",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",
9
- "exports": "./dist/index.js",
9
+ "exports": "./dist/run.js",
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
13
  "node": ">=16",
14
14
  "dependencies": {
15
- "execa": "7.1.1",
15
+ "execa": "8.0.1",
16
16
  "kleur": "4.1.5"
17
17
  },
18
18
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  "build:js": "swc --source-maps --out-dir dist src",
22
22
  "build:types": "tsc",
23
23
  "clean": "rimraf dist types coverage",
24
- "lint": "eslint \"src/*.ts\"",
24
+ "lint": "prettier --write \"src/*.ts\" && eslint --fix \"src/*.ts\"",
25
25
  "test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules jest",
26
26
  "test:coverage": "npm run test -- --coverage",
27
27
  "watch": "swc --watch --out-dir dist src"
@@ -29,5 +29,5 @@
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "fe6401830d153ab91166243c2cafd96f6cc0d9b5"
32
+ "gitHead": "14e79a79e03610f47ab1269076315f183d8a3a0e"
33
33
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { execaCommand } from \"execa\";\nimport kleur from \"kleur\";\n\n/**\n * Runs a shell command asynchronously and\n * returns both `stdout` and `stderr`.\n * If the command fails to run (invalid command or the commands status is\n * anything but 0), the call will throw an exception. The exception can be\n * ignored if the `options.ignoreError` flag is true.\n *\n * @async\n */\nexport const run = async (\n\tcommand: string,\n\toptions?: { ignoreError?: boolean }\n): Promise<any> => {\n\tconst { ignoreError } = {\n\t\tignoreError: false,\n\t\t...options,\n\t};\n\ttry {\n\t\tconst { stdout, stderr } = await execaCommand(command, {\n\t\t\t/**\n\t\t\t * For some reason, a command with a \" or ' in execa.command() will\n\t\t\t * fail, but it works if shell is set to true... It would work if\n\t\t\t * the execaCommand() API is not used:\n\t\t\t * execa(\"ls\", [\"-l\", \"|\", \"wc\"]);\n\t\t\t * Same problems with &, &&, | and ||.\n\t\t\t */\n\t\t\tshell:\n\t\t\t\tcommand.includes('\"') ||\n\t\t\t\tcommand.includes(\"'\") ||\n\t\t\t\tcommand.includes(\"&&\") ||\n\t\t\t\tcommand.includes(\"&\") ||\n\t\t\t\tcommand.includes(\"||\") ||\n\t\t\t\tcommand.includes(\"|\"),\n\t\t});\n\n\t\treturn { stderr, stdout };\n\t} catch (error) {\n\t\tif (ignoreError) {\n\t\t\treturn {\n\t\t\t\texitCode: error.exitCode === undefined ? 1 : error.exitCode,\n\t\t\t\tshortMessage: error.shortMessage,\n\t\t\t\tstderr: error.exitCode === undefined ? 1 : error.exitCode,\n\t\t\t};\n\t\t} else {\n\t\t\tthrow new Error(kleur.red(error));\n\t\t}\n\t}\n};\n"],"names":["execaCommand","kleur","run","command","options","ignoreError","stdout","stderr","shell","includes","error","exitCode","undefined","shortMessage","Error","red"],"mappings":"AAAA,SAASA,YAAY,QAAQ,QAAQ;AACrC,OAAOC,WAAW,QAAQ;AAE1B;;;;;;;;CAQC,GACD,OAAO,MAAMC,MAAM,OAClBC,SACAC,UACkB;IAClB,MAAM,EAAEC,YAAW,EAAE,GAAG;QACvBA,aAAa,KAAK;QAClB,GAAGD,OAAO;IACX;IACA,IAAI;QACH,MAAM,EAAEE,OAAM,EAAEC,OAAM,EAAE,GAAG,MAAMP,aAAaG,SAAS;YACtD;;;;;;IAMC,GACDK,OACCL,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC;QACnB;QAEA,OAAO;YAAEF;YAAQD;QAAO;IACzB,EAAE,OAAOI,OAAO;QACf,IAAIL,aAAa;YAChB,OAAO;gBACNM,UAAUD,MAAMC,QAAQ,KAAKC,YAAY,IAAIF,MAAMC,QAAQ;gBAC3DE,cAAcH,MAAMG,YAAY;gBAChCN,QAAQG,MAAMC,QAAQ,KAAKC,YAAY,IAAIF,MAAMC,QAAQ;YAC1D;QACD,OAAO;YACN,MAAM,IAAIG,MAAMb,MAAMc,GAAG,CAACL,QAAQ;QACnC,CAAC;IACF;AACD,EAAE"}