@node-cli/run 1.1.3 → 1.1.5
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/run.d.ts +2 -2
- package/dist/run.js +2 -2
- package/dist/run.js.map +1 -1
- package/dist/utilities.js +2 -2
- package/dist/utilities.js.map +1 -1
- package/package.json +10 -6
package/dist/run.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Runs a shell command asynchronously and
|
|
3
|
-
* returns both `stdout` and `stderr`.
|
|
2
|
+
* Runs a shell command asynchronously and returns both `stdout` and `stderr`.
|
|
4
3
|
* If the command fails to run (invalid command or the commands status is
|
|
5
4
|
* anything but 0), the call will throw an exception. The exception can be
|
|
6
5
|
* ignored if the `options.ignoreError` flag is true.
|
|
7
6
|
*
|
|
8
7
|
* @async
|
|
8
|
+
*
|
|
9
9
|
*/
|
|
10
10
|
export type RunResult = {
|
|
11
11
|
stderr?: string | number;
|
package/dist/run.js
CHANGED
|
@@ -13,13 +13,13 @@ export const run = async (command, options)=>{
|
|
|
13
13
|
if (command.includes("&&") || command.includes("&") || command.includes("||") || command.includes("|")) {
|
|
14
14
|
execaOptions.shell = true;
|
|
15
15
|
}
|
|
16
|
-
/* v8 ignore
|
|
16
|
+
/* v8 ignore start */ if (options?.streamOutput) {
|
|
17
17
|
execaOptions.stdout = [
|
|
18
18
|
"pipe",
|
|
19
19
|
"inherit"
|
|
20
20
|
];
|
|
21
21
|
}
|
|
22
|
-
try {
|
|
22
|
+
/* v8 ignore stop */ try {
|
|
23
23
|
if (execaOptions.shell) {
|
|
24
24
|
const { stdout, stderr } = await execaCommand(command, execaOptions);
|
|
25
25
|
return {
|
package/dist/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/run.ts"],"sourcesContent":["import { execa, execaCommand } from \"execa\";\nimport kleur from \"kleur\";\nimport { parseCommandString } from \"./utilities.js\";\n\n/**\n * Runs a shell command asynchronously and
|
|
1
|
+
{"version":3,"sources":["../src/run.ts"],"sourcesContent":["import { execa, execaCommand } from \"execa\";\nimport kleur from \"kleur\";\nimport { parseCommandString } from \"./utilities.js\";\n\n/**\n * Runs a shell command asynchronously and 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 *\n */\nexport type RunResult = {\n\tstderr?: string | number;\n\tstdout?: string | number;\n\texitCode?: number;\n\tshortMessage?: string;\n};\nexport type RunOptions = {\n\tignoreError?: boolean;\n\tstreamOutput?: boolean;\n};\ntype ExecaOptions = {\n\tpreferLocal: boolean;\n\tshell: boolean;\n\tstdout?: [\"pipe\", \"inherit\"];\n};\n\nexport const run = async (\n\tcommand: string,\n\toptions?: RunOptions,\n): Promise<RunResult> => {\n\tconst { ignoreError } = {\n\t\tignoreError: false,\n\t\t...options,\n\t};\n\tconst execaOptions: ExecaOptions = {\n\t\tshell: false,\n\t\tpreferLocal: true,\n\t};\n\n\tif (\n\t\tcommand.includes(\"&&\") ||\n\t\tcommand.includes(\"&\") ||\n\t\tcommand.includes(\"||\") ||\n\t\tcommand.includes(\"|\")\n\t) {\n\t\texecaOptions.shell = true;\n\t}\n\n\t/* v8 ignore start */\n\tif (options?.streamOutput) {\n\t\texecaOptions.stdout = [\"pipe\", \"inherit\"];\n\t}\n\t/* v8 ignore stop */\n\n\ttry {\n\t\tif (execaOptions.shell) {\n\t\t\tconst { stdout, stderr } = await execaCommand(command, execaOptions);\n\t\t\treturn { stderr, stdout };\n\t\t} else {\n\t\t\tconst commandArray = parseCommandString(command);\n\t\t\tconst { stdout, stderr } = await execa(\n\t\t\t\tcommandArray[0],\n\t\t\t\tcommandArray.slice(1),\n\t\t\t\texecaOptions,\n\t\t\t);\n\t\t\treturn { stderr, stdout };\n\t\t}\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":["execa","execaCommand","kleur","parseCommandString","run","command","options","ignoreError","execaOptions","shell","preferLocal","includes","streamOutput","stdout","stderr","commandArray","slice","error","exitCode","undefined","shortMessage","Error","red"],"mappings":"AAAA,SAASA,KAAK,EAAEC,YAAY,QAAQ,QAAQ;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,kBAAkB,QAAQ,iBAAiB;AA2BpD,OAAO,MAAMC,MAAM,OAClBC,SACAC;IAEA,MAAM,EAAEC,WAAW,EAAE,GAAG;QACvBA,aAAa;QACb,GAAGD,OAAO;IACX;IACA,MAAME,eAA6B;QAClCC,OAAO;QACPC,aAAa;IACd;IAEA,IACCL,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC,QACjBN,QAAQM,QAAQ,CAAC,SACjBN,QAAQM,QAAQ,CAAC,MAChB;QACDH,aAAaC,KAAK,GAAG;IACtB;IAEA,mBAAmB,GACnB,IAAIH,SAASM,cAAc;QAC1BJ,aAAaK,MAAM,GAAG;YAAC;YAAQ;SAAU;IAC1C;IACA,kBAAkB,GAElB,IAAI;QACH,IAAIL,aAAaC,KAAK,EAAE;YACvB,MAAM,EAAEI,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMb,aAAaI,SAASG;YACvD,OAAO;gBAAEM;gBAAQD;YAAO;QACzB,OAAO;YACN,MAAME,eAAeZ,mBAAmBE;YACxC,MAAM,EAAEQ,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMd,MAChCe,YAAY,CAAC,EAAE,EACfA,aAAaC,KAAK,CAAC,IACnBR;YAED,OAAO;gBAAEM;gBAAQD;YAAO;QACzB;IACD,EAAE,OAAOI,OAAO;QACf,IAAIV,aAAa;YAChB,OAAO;gBACNW,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,MAAMnB,MAAMoB,GAAG,CAACL;QAC3B;IACD;AACD,EAAE"}
|
package/dist/utilities.js
CHANGED
|
@@ -6,10 +6,10 @@ export const parseCommandString = (command)=>{
|
|
|
6
6
|
}
|
|
7
7
|
const tokens = [];
|
|
8
8
|
for (const token of trimmedCommand.split(SPACES_REGEXP)){
|
|
9
|
-
// Allow spaces to be escaped by a backslash if not meant as a delimiter
|
|
9
|
+
// Allow spaces to be escaped by a backslash if not meant as a delimiter.
|
|
10
10
|
const previousToken = tokens.at(-1);
|
|
11
11
|
/* v8 ignore next 4 */ if (previousToken && previousToken.endsWith("\\")) {
|
|
12
|
-
// Merge previous token with current one
|
|
12
|
+
// Merge previous token with current one.
|
|
13
13
|
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
|
|
14
14
|
} else {
|
|
15
15
|
tokens.push(token);
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["const SPACES_REGEXP = / +/g;\n\nexport const parseCommandString = (command: string) => {\n\tconst trimmedCommand = command.trim();\n\tif (trimmedCommand === \"\") {\n\t\treturn [];\n\t}\n\tconst tokens = [];\n\tfor (const token of trimmedCommand.split(SPACES_REGEXP)) {\n\t\t// Allow spaces to be escaped by a backslash if not meant as a delimiter
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["const SPACES_REGEXP = / +/g;\n\nexport const parseCommandString = (command: string) => {\n\tconst trimmedCommand = command.trim();\n\tif (trimmedCommand === \"\") {\n\t\treturn [];\n\t}\n\tconst tokens = [];\n\tfor (const token of trimmedCommand.split(SPACES_REGEXP)) {\n\t\t// Allow spaces to be escaped by a backslash if not meant as a delimiter.\n\t\tconst previousToken = tokens.at(-1);\n\t\t/* v8 ignore next 4 */\n\t\tif (previousToken && previousToken.endsWith(\"\\\\\")) {\n\t\t\t// Merge previous token with current one.\n\t\t\ttokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;\n\t\t} else {\n\t\t\ttokens.push(token);\n\t\t}\n\t}\n\treturn tokens;\n};\n"],"names":["SPACES_REGEXP","parseCommandString","command","trimmedCommand","trim","tokens","token","split","previousToken","at","endsWith","length","slice","push"],"mappings":"AAAA,MAAMA,gBAAgB;AAEtB,OAAO,MAAMC,qBAAqB,CAACC;IAClC,MAAMC,iBAAiBD,QAAQE,IAAI;IACnC,IAAID,mBAAmB,IAAI;QAC1B,OAAO,EAAE;IACV;IACA,MAAME,SAAS,EAAE;IACjB,KAAK,MAAMC,SAASH,eAAeI,KAAK,CAACP,eAAgB;QACxD,yEAAyE;QACzE,MAAMQ,gBAAgBH,OAAOI,EAAE,CAAC,CAAC;QACjC,oBAAoB,GACpB,IAAID,iBAAiBA,cAAcE,QAAQ,CAAC,OAAO;YAClD,yCAAyC;YACzCL,MAAM,CAACA,OAAOM,MAAM,GAAG,EAAE,GAAG,GAAGH,cAAcI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAEN,OAAO;QACrE,OAAO;YACND,OAAOQ,IAAI,CAACP;QACb;IACD;IACA,OAAOD;AACR,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/run",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "A wrapper for child_process for nodejs CLI apps",
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": "./dist/run.js",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"node": ">=16",
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"execa": "9.6.
|
|
16
|
+
"execa": "9.6.1",
|
|
16
17
|
"kleur": "4.1.5"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
@@ -21,7 +22,9 @@
|
|
|
21
22
|
"build:js": "swc --strip-leading-paths --source-maps --out-dir dist src",
|
|
22
23
|
"build:types": "tsc",
|
|
23
24
|
"clean": "rimraf dist types coverage",
|
|
25
|
+
"comments:fix": "comments --merge-line-comments 'src/**/*.ts'",
|
|
24
26
|
"lint": "biome lint src",
|
|
27
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
25
28
|
"test": "vitest run --globals",
|
|
26
29
|
"test:coverage": "vitest run --coverage --globals",
|
|
27
30
|
"test:echo": "echo \"testing testing\"",
|
|
@@ -32,8 +35,9 @@
|
|
|
32
35
|
"access": "public"
|
|
33
36
|
},
|
|
34
37
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"vitest": "
|
|
38
|
+
"@node-cli/comments": "0.2.7",
|
|
39
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
40
|
+
"vitest": "4.0.16"
|
|
37
41
|
},
|
|
38
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "096003826471508d839f2ec3346bb12b1a73b7fe"
|
|
39
43
|
}
|