@elinzy/core 0.1.1 → 0.2.0
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 +83 -1
- package/dist/child_process.cjs +96 -56
- package/dist/child_process.d.cts +44 -0
- package/dist/child_process.d.mts +44 -0
- package/dist/child_process.mjs +72 -54
- package/dist/index.cjs +6 -10
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -1
- package/package.json +40 -46
- package/dist/child_process.d.ts +0 -39
- package/dist/index.d.ts +0 -22
package/README.md
CHANGED
|
@@ -1 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
# @elinzy/core
|
|
2
|
+
|
|
3
|
+
Node.js runtime primitives for the `e` CLI: process execution built on [execa](https://github.com/sindresorhus/execa), with command logging, dry-run and abbreviated output support.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @elinzy/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
- ESM
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { exec, execSync, execCommand, execCommandSync } from '@elinzy/core';
|
|
17
|
+
|
|
18
|
+
// Asynchronous, array-style (like execa)
|
|
19
|
+
const result = await exec('git', ['status']);
|
|
20
|
+
console.log(result.stdout);
|
|
21
|
+
|
|
22
|
+
// Synchronous, string-style
|
|
23
|
+
const version = execCommandSync('node -v', { abbrev: true });
|
|
24
|
+
|
|
25
|
+
// Dry run: log the command, skip execution
|
|
26
|
+
await exec('rm', ['-rf', 'dist'], { dryRun: true });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- CJS
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const { execSync } = require('@elinzy/core');
|
|
33
|
+
|
|
34
|
+
const stdout = execSync('node', ['-v'], { abbrev: true });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### exec(cmd, args, opts?)
|
|
40
|
+
|
|
41
|
+
Execute a command asynchronously. Returns the execa result promise.
|
|
42
|
+
|
|
43
|
+
### execSync(cmd, args, opts?)
|
|
44
|
+
|
|
45
|
+
Execute a command synchronously. Returns the execa result.
|
|
46
|
+
|
|
47
|
+
### execCommand(cmd, opts?)
|
|
48
|
+
|
|
49
|
+
Execute a command string asynchronously (`'git status'` style). Returns the execa result promise.
|
|
50
|
+
|
|
51
|
+
### execCommandSync(cmd, opts?)
|
|
52
|
+
|
|
53
|
+
Execute a command string synchronously. Returns the execa result.
|
|
54
|
+
|
|
55
|
+
#### cmd
|
|
56
|
+
|
|
57
|
+
- Type: `String`
|
|
58
|
+
|
|
59
|
+
#### args
|
|
60
|
+
|
|
61
|
+
- Type: `String[]`
|
|
62
|
+
|
|
63
|
+
#### opts
|
|
64
|
+
|
|
65
|
+
- Type: `Object`
|
|
66
|
+
- All [execa options](https://github.com/sindresorhus/execa/blob/main/docs/execution.md#options-1) are passed through (`cwd`, `env`, `stdio`, ...), plus:
|
|
67
|
+
|
|
68
|
+
| Option | Type | Default | Description |
|
|
69
|
+
| ------ | ---- | ------- | ----------- |
|
|
70
|
+
| `abbrev` | `Boolean` | `false` | Return only `stdout` instead of the full result |
|
|
71
|
+
| `logger` | `Boolean` | `false` | Print the command before executing it |
|
|
72
|
+
| `dryRun` | `Boolean` | `false` | Print the command but skip execution |
|
|
73
|
+
| `throwOnError` | `Boolean` | `true` | Throw a colored error including `stderr` / stack on failure; when `false`, failures resolve to `undefined` |
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[MIT](https://github.com/Appleec/e/blob/main/packages/core/LICENSE)
|
|
78
|
+
|
|
79
|
+
## Related
|
|
80
|
+
|
|
81
|
+
- [`@elinzy/logger`](https://github.com/Appleec/e/tree/main/packages/logger) — styled terminal logging
|
|
82
|
+
- [`@elinzy/git`](https://github.com/Appleec/e/tree/main/packages/git) — git operations built on this package
|
|
83
|
+
- [`e`](https://github.com/Appleec/e) — the monorepo root
|
package/dist/child_process.cjs
CHANGED
|
@@ -1,67 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let execa = require("execa");
|
|
25
|
+
let ansis = require("ansis");
|
|
26
|
+
ansis = __toESM(ansis, 1);
|
|
27
|
+
//#region src/child_process.ts
|
|
28
|
+
/**
|
|
29
|
+
* Execute a command asynchronously
|
|
30
|
+
* @param {string} cmd
|
|
31
|
+
* @param {string[]} args
|
|
32
|
+
* @param {import("execa").Options} [opts]
|
|
33
|
+
*/
|
|
6
34
|
function exec(cmd, args, opts) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
35
|
+
opts = {
|
|
36
|
+
throwOnError: true,
|
|
37
|
+
...opts
|
|
38
|
+
};
|
|
39
|
+
if (opts.logger || opts.dryRun) console.log(ansis.default.green(`> ${[cmd, ...args].join(" ")}`));
|
|
40
|
+
if (opts.dryRun) return Promise.resolve(void 0);
|
|
41
|
+
return (0, execa.execa)(cmd, args, opts).then((spawned) => opts.abbrev ? spawned.stdout : spawned).catch((e) => {
|
|
42
|
+
if (opts.throwOnError) throw new Error(ansis.default.red(`Running ${ansis.default.bold([cmd, ...args].join(" "))} in ${ansis.default.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
43
|
+
return Promise.resolve(void 0);
|
|
44
|
+
});
|
|
18
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Execute a command synchronously
|
|
48
|
+
* @param {string} cmd
|
|
49
|
+
* @param {string[]} args
|
|
50
|
+
* @param {import("execa").SyncOptions} [opts]
|
|
51
|
+
*/
|
|
19
52
|
function execSync(cmd, args, opts) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
53
|
+
opts = {
|
|
54
|
+
throwOnError: true,
|
|
55
|
+
...opts
|
|
56
|
+
};
|
|
57
|
+
if (opts.logger || opts.dryRun) console.log(ansis.default.green(`> ${[cmd, ...args].join(" ")}`));
|
|
58
|
+
if (opts.dryRun) return void 0;
|
|
59
|
+
try {
|
|
60
|
+
const spawned = (0, execa.execaSync)(cmd, args, opts);
|
|
61
|
+
return opts.abbrev ? spawned.stdout : spawned;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (opts?.throwOnError) throw new Error(ansis.default.red(`Running ${ansis.default.bold([cmd, ...args].join(" "))} in ${ansis.default.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
34
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Execute a command asynchronously (string)
|
|
69
|
+
* @param cmd
|
|
70
|
+
* @param opts
|
|
71
|
+
*/
|
|
35
72
|
function execCommand(cmd, opts) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
73
|
+
opts = {
|
|
74
|
+
throwOnError: true,
|
|
75
|
+
...opts
|
|
76
|
+
};
|
|
77
|
+
if (opts.logger || opts.dryRun) console.log(ansis.default.green(`> ${[cmd].join(" ")}`));
|
|
78
|
+
if (opts.dryRun) return Promise.resolve(void 0);
|
|
79
|
+
return (0, execa.execaCommand)(cmd, opts).then((spawned) => opts.abbrev ? spawned.stdout : spawned).catch((e) => {
|
|
80
|
+
if (opts.throwOnError) throw new Error(ansis.default.red(`Running ${ansis.default.bold([cmd].join(" "))} in ${ansis.default.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
81
|
+
return Promise.resolve(void 0);
|
|
82
|
+
});
|
|
47
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Execute a command synchronously (string)
|
|
86
|
+
* @param cmd
|
|
87
|
+
* @param opts
|
|
88
|
+
*/
|
|
48
89
|
function execCommandSync(cmd, opts) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
90
|
+
opts = {
|
|
91
|
+
throwOnError: true,
|
|
92
|
+
...opts
|
|
93
|
+
};
|
|
94
|
+
if (opts.logger || opts.dryRun) console.log(ansis.default.green(`> ${[cmd].join(" ")}`));
|
|
95
|
+
if (opts.dryRun) return void 0;
|
|
96
|
+
try {
|
|
97
|
+
const spawned = (0, execa.execaCommandSync)(cmd, opts);
|
|
98
|
+
return opts.abbrev ? spawned.stdout : spawned;
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (opts.throwOnError) throw new Error(ansis.default.red(`Running ${ansis.default.bold([cmd].join(" "))} in ${ansis.default.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
63
103
|
}
|
|
64
|
-
|
|
104
|
+
//#endregion
|
|
65
105
|
exports.exec = exec;
|
|
66
106
|
exports.execCommand = execCommand;
|
|
67
107
|
exports.execCommandSync = execCommandSync;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Options, Result, ResultPromise, SyncOptions, SyncResult } from "execa";
|
|
2
|
+
//#region src/child_process.d.ts
|
|
3
|
+
export interface ExecOptions extends Options {
|
|
4
|
+
abbrev?: boolean;
|
|
5
|
+
logger?: boolean;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
throwOnError?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ExecSyncOptions extends SyncOptions {
|
|
10
|
+
abbrev?: boolean;
|
|
11
|
+
logger?: boolean;
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
throwOnError?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type ExecResult = Result;
|
|
16
|
+
export type ExecSyncResult = SyncResult;
|
|
17
|
+
export type ExecResultPromise = ResultPromise;
|
|
18
|
+
/**
|
|
19
|
+
* Execute a command asynchronously
|
|
20
|
+
* @param {string} cmd
|
|
21
|
+
* @param {string[]} args
|
|
22
|
+
* @param {import("execa").Options} [opts]
|
|
23
|
+
*/
|
|
24
|
+
export declare function exec(cmd: string, args: string[], opts?: ExecOptions): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a command synchronously
|
|
27
|
+
* @param {string} cmd
|
|
28
|
+
* @param {string[]} args
|
|
29
|
+
* @param {import("execa").SyncOptions} [opts]
|
|
30
|
+
*/
|
|
31
|
+
export declare function execSync(cmd: string, args: string[], opts?: ExecSyncOptions): string | SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Execute a command asynchronously (string)
|
|
34
|
+
* @param cmd
|
|
35
|
+
* @param opts
|
|
36
|
+
*/
|
|
37
|
+
export declare function execCommand(cmd: string, opts?: ExecOptions): Promise<string | unknown[] | Uint8Array<ArrayBufferLike> | Result<ExecOptions> | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute a command synchronously (string)
|
|
40
|
+
* @param cmd
|
|
41
|
+
* @param opts
|
|
42
|
+
*/
|
|
43
|
+
export declare function execCommandSync(cmd: string, opts?: ExecSyncOptions): string | SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
44
|
+
//#endregion
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Options, Result, ResultPromise, SyncOptions, SyncResult } from "execa";
|
|
2
|
+
//#region src/child_process.d.ts
|
|
3
|
+
export interface ExecOptions extends Options {
|
|
4
|
+
abbrev?: boolean;
|
|
5
|
+
logger?: boolean;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
throwOnError?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ExecSyncOptions extends SyncOptions {
|
|
10
|
+
abbrev?: boolean;
|
|
11
|
+
logger?: boolean;
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
throwOnError?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type ExecResult = Result;
|
|
16
|
+
export type ExecSyncResult = SyncResult;
|
|
17
|
+
export type ExecResultPromise = ResultPromise;
|
|
18
|
+
/**
|
|
19
|
+
* Execute a command asynchronously
|
|
20
|
+
* @param {string} cmd
|
|
21
|
+
* @param {string[]} args
|
|
22
|
+
* @param {import("execa").Options} [opts]
|
|
23
|
+
*/
|
|
24
|
+
export declare function exec(cmd: string, args: string[], opts?: ExecOptions): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a command synchronously
|
|
27
|
+
* @param {string} cmd
|
|
28
|
+
* @param {string[]} args
|
|
29
|
+
* @param {import("execa").SyncOptions} [opts]
|
|
30
|
+
*/
|
|
31
|
+
export declare function execSync(cmd: string, args: string[], opts?: ExecSyncOptions): string | SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Execute a command asynchronously (string)
|
|
34
|
+
* @param cmd
|
|
35
|
+
* @param opts
|
|
36
|
+
*/
|
|
37
|
+
export declare function execCommand(cmd: string, opts?: ExecOptions): Promise<string | unknown[] | Uint8Array<ArrayBufferLike> | Result<ExecOptions> | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute a command synchronously (string)
|
|
40
|
+
* @param cmd
|
|
41
|
+
* @param opts
|
|
42
|
+
*/
|
|
43
|
+
export declare function execCommandSync(cmd: string, opts?: ExecSyncOptions): string | SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
44
|
+
//#endregion
|
package/dist/child_process.mjs
CHANGED
|
@@ -1,63 +1,81 @@
|
|
|
1
|
-
import { execa,
|
|
2
|
-
import c from
|
|
3
|
-
|
|
1
|
+
import { execa, execaCommand, execaCommandSync, execaSync } from "execa";
|
|
2
|
+
import c from "ansis";
|
|
3
|
+
//#region src/child_process.ts
|
|
4
|
+
/**
|
|
5
|
+
* Execute a command asynchronously
|
|
6
|
+
* @param {string} cmd
|
|
7
|
+
* @param {string[]} args
|
|
8
|
+
* @param {import("execa").Options} [opts]
|
|
9
|
+
*/
|
|
4
10
|
function exec(cmd, args, opts) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
11
|
+
opts = {
|
|
12
|
+
throwOnError: true,
|
|
13
|
+
...opts
|
|
14
|
+
};
|
|
15
|
+
if (opts.logger || opts.dryRun) console.log(c.green(`> ${[cmd, ...args].join(" ")}`));
|
|
16
|
+
if (opts.dryRun) return Promise.resolve(void 0);
|
|
17
|
+
return execa(cmd, args, opts).then((spawned) => opts.abbrev ? spawned.stdout : spawned).catch((e) => {
|
|
18
|
+
if (opts.throwOnError) throw new Error(c.red(`Running ${c.bold([cmd, ...args].join(" "))} in ${c.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
19
|
+
return Promise.resolve(void 0);
|
|
20
|
+
});
|
|
16
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Execute a command synchronously
|
|
24
|
+
* @param {string} cmd
|
|
25
|
+
* @param {string[]} args
|
|
26
|
+
* @param {import("execa").SyncOptions} [opts]
|
|
27
|
+
*/
|
|
17
28
|
function execSync(cmd, args, opts) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
29
|
+
opts = {
|
|
30
|
+
throwOnError: true,
|
|
31
|
+
...opts
|
|
32
|
+
};
|
|
33
|
+
if (opts.logger || opts.dryRun) console.log(c.green(`> ${[cmd, ...args].join(" ")}`));
|
|
34
|
+
if (opts.dryRun) return void 0;
|
|
35
|
+
try {
|
|
36
|
+
const spawned = execaSync(cmd, args, opts);
|
|
37
|
+
return opts.abbrev ? spawned.stdout : spawned;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (opts?.throwOnError) throw new Error(c.red(`Running ${c.bold([cmd, ...args].join(" "))} in ${c.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
32
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute a command asynchronously (string)
|
|
45
|
+
* @param cmd
|
|
46
|
+
* @param opts
|
|
47
|
+
*/
|
|
33
48
|
function execCommand(cmd, opts) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
49
|
+
opts = {
|
|
50
|
+
throwOnError: true,
|
|
51
|
+
...opts
|
|
52
|
+
};
|
|
53
|
+
if (opts.logger || opts.dryRun) console.log(c.green(`> ${[cmd].join(" ")}`));
|
|
54
|
+
if (opts.dryRun) return Promise.resolve(void 0);
|
|
55
|
+
return execaCommand(cmd, opts).then((spawned) => opts.abbrev ? spawned.stdout : spawned).catch((e) => {
|
|
56
|
+
if (opts.throwOnError) throw new Error(c.red(`Running ${c.bold([cmd].join(" "))} in ${c.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
57
|
+
return Promise.resolve(void 0);
|
|
58
|
+
});
|
|
45
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Execute a command synchronously (string)
|
|
62
|
+
* @param cmd
|
|
63
|
+
* @param opts
|
|
64
|
+
*/
|
|
46
65
|
function execCommandSync(cmd, opts) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
66
|
+
opts = {
|
|
67
|
+
throwOnError: true,
|
|
68
|
+
...opts
|
|
69
|
+
};
|
|
70
|
+
if (opts.logger || opts.dryRun) console.log(c.green(`> ${[cmd].join(" ")}`));
|
|
71
|
+
if (opts.dryRun) return void 0;
|
|
72
|
+
try {
|
|
73
|
+
const spawned = execaCommandSync(cmd, opts);
|
|
74
|
+
return opts.abbrev ? spawned.stdout : spawned;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (opts.throwOnError) throw new Error(c.red(`Running ${c.bold([cmd].join(" "))} in ${c.underline(opts.cwd || e.cwd || process.cwd())}:`) + (e.stderr || e.stack || e.message));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
61
79
|
}
|
|
62
|
-
|
|
80
|
+
//#endregion
|
|
63
81
|
export { exec, execCommand, execCommandSync, execSync };
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.exec = child_process.exec;
|
|
8
|
-
exports.execCommand = child_process.execCommand;
|
|
9
|
-
exports.execCommandSync = child_process.execCommandSync;
|
|
10
|
-
exports.execSync = child_process.execSync;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_child_process = require("./child_process.cjs");
|
|
3
|
+
exports.exec = require_child_process.exec;
|
|
4
|
+
exports.execCommand = require_child_process.execCommand;
|
|
5
|
+
exports.execCommandSync = require_child_process.execCommandSync;
|
|
6
|
+
exports.execSync = require_child_process.execSync;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ExecOptions, ExecResult, ExecResultPromise, ExecSyncOptions, ExecSyncResult, exec, execCommand, execCommandSync, execSync } from "./child_process.cjs";
|
|
2
|
+
export { type ExecOptions, type ExecResult, type ExecResultPromise, type ExecSyncOptions, type ExecSyncResult, exec, execCommand, execCommandSync, execSync };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ExecOptions, ExecResult, ExecResultPromise, ExecSyncOptions, ExecSyncResult, exec, execCommand, execCommandSync, execSync } from "./child_process.mjs";
|
|
2
|
+
export { type ExecOptions, type ExecResult, type ExecResultPromise, type ExecSyncOptions, type ExecSyncResult, exec, execCommand, execCommandSync, execSync };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { exec, execCommand, execCommandSync, execSync } from
|
|
1
|
+
export { exec, execCommand, execCommandSync, execSync } from "./child_process.mjs";
|
package/package.json
CHANGED
|
@@ -1,68 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elinzy/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "e core implementation module",
|
|
5
|
+
"homepage": "https://github.com/Appleec/e#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Appleec/e/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Appleec <771992522@qq.com>",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Appleec/e.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"e",
|
|
22
|
+
"core"
|
|
23
|
+
],
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
5
27
|
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
6
29
|
"main": "./dist/index.cjs",
|
|
7
|
-
"types": "./dist/index.d.
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
8
32
|
"exports": {
|
|
9
33
|
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
34
|
"import": "./dist/index.mjs",
|
|
12
35
|
"require": "./dist/index.cjs"
|
|
13
36
|
},
|
|
14
37
|
"./child_process": {
|
|
15
|
-
"types": "./dist/child_process.d.ts",
|
|
16
38
|
"import": "./dist/child_process.mjs",
|
|
17
39
|
"require": "./dist/child_process.cjs"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
"publishConfig": {
|
|
21
|
-
"access": "public",
|
|
22
|
-
"registry": "https://registry.npmjs.org/"
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
],
|
|
27
|
-
"repository": {
|
|
28
|
-
"type": "git",
|
|
29
|
-
"url": "git+https://github.com/Appleec/e.git",
|
|
30
|
-
"directory": "packages/core"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
31
42
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"e-core"
|
|
36
|
-
],
|
|
37
|
-
"author": "Appleec <771992522@qq.com>",
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/Appleec/e/issues"
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"ansis": "4.2.0",
|
|
45
|
+
"execa": "^9.5.2"
|
|
41
46
|
},
|
|
42
|
-
"homepage": "https://github.com/Appleec/e#readme",
|
|
43
47
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"@babel/preset-env": "7.26.9",
|
|
46
|
-
"@babel/preset-typescript": "7.26.0",
|
|
47
|
-
"@rollup/plugin-babel": "6.0.4",
|
|
48
|
-
"@rollup/plugin-node-resolve": "16.0.1",
|
|
49
|
-
"rollup": "4.35.0",
|
|
50
|
-
"rollup-plugin-dts": "6.1.1",
|
|
51
|
-
"rollup-plugin-esbuild": "6.2.1",
|
|
52
|
-
"rollup-plugin-node-externals": "8.0.0",
|
|
53
|
-
"tslib": "2.8.1",
|
|
54
|
-
"typescript": "^5.8.2"
|
|
48
|
+
"tsdown": "^0.23.1"
|
|
55
49
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0",
|
|
52
|
+
"npm": "please-use-pnpm",
|
|
53
|
+
"pnpm": ">=10.0.0",
|
|
54
|
+
"yarn": "please-use-pnpm"
|
|
59
55
|
},
|
|
60
56
|
"scripts": {
|
|
61
|
-
"dev": "
|
|
62
|
-
"build": "
|
|
63
|
-
"
|
|
64
|
-
"build:type": "tsc --project tsconfig.build.json --emitDeclarationOnly --preserveWatchOutput",
|
|
65
|
-
"build:clean": "rimraf ./dist",
|
|
57
|
+
"dev": "tsdown --watch",
|
|
58
|
+
"build": "tsdown",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
66
60
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
67
61
|
}
|
|
68
62
|
}
|
package/dist/child_process.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Options as ExecaOptions, type SyncOptions as ExecaSyncOptions } from 'execa';
|
|
2
|
-
export interface ExecOptions extends ExecaOptions {
|
|
3
|
-
abbrev?: boolean;
|
|
4
|
-
logger?: boolean;
|
|
5
|
-
dryRun?: boolean;
|
|
6
|
-
throwOnError?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface ExecSyncOptions extends ExecaSyncOptions {
|
|
9
|
-
abbrev?: boolean;
|
|
10
|
-
logger?: boolean;
|
|
11
|
-
dryRun?: boolean;
|
|
12
|
-
throwOnError?: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Execute a command asynchronously
|
|
16
|
-
* @param {string} cmd
|
|
17
|
-
* @param {string[]} args
|
|
18
|
-
* @param {import("execa").Options} [opts]
|
|
19
|
-
*/
|
|
20
|
-
export declare function exec(cmd: string, args: string[], opts?: ExecOptions): Promise<any>;
|
|
21
|
-
/**
|
|
22
|
-
* Execute a command synchronously
|
|
23
|
-
* @param {string} cmd
|
|
24
|
-
* @param {string[]} args
|
|
25
|
-
* @param {import("execa").SyncOptions} [opts]
|
|
26
|
-
*/
|
|
27
|
-
export declare function execSync(cmd: string, args: string[], opts?: ExecSyncOptions): string | unknown[] | Uint8Array<ArrayBufferLike> | import("execa").SyncResult<ExecSyncOptions> | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Execute a command asynchronously (string)
|
|
30
|
-
* @param cmd
|
|
31
|
-
* @param opts
|
|
32
|
-
*/
|
|
33
|
-
export declare function execCommand(cmd: string, opts?: ExecOptions): Promise<string | unknown[] | import("execa").Result<ExecOptions> | Uint8Array<ArrayBufferLike> | undefined>;
|
|
34
|
-
/**
|
|
35
|
-
* Execute a command synchronously (string)
|
|
36
|
-
* @param cmd
|
|
37
|
-
* @param opts
|
|
38
|
-
*/
|
|
39
|
-
export declare function execCommandSync(cmd: string, opts?: ExecSyncOptions): string | unknown[] | Uint8Array<ArrayBufferLike> | import("execa").SyncResult<ExecSyncOptions> | undefined;
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as execa from 'execa';
|
|
2
|
-
import { Options, SyncOptions } from 'execa';
|
|
3
|
-
|
|
4
|
-
interface ExecOptions extends Options {
|
|
5
|
-
abbrev?: boolean;
|
|
6
|
-
logger?: boolean;
|
|
7
|
-
dryRun?: boolean;
|
|
8
|
-
throwOnError?: boolean;
|
|
9
|
-
}
|
|
10
|
-
interface ExecSyncOptions extends SyncOptions {
|
|
11
|
-
abbrev?: boolean;
|
|
12
|
-
logger?: boolean;
|
|
13
|
-
dryRun?: boolean;
|
|
14
|
-
throwOnError?: boolean;
|
|
15
|
-
}
|
|
16
|
-
declare function exec(cmd: string, args: string[], opts?: ExecOptions): Promise<any>;
|
|
17
|
-
declare function execSync(cmd: string, args: string[], opts?: ExecSyncOptions): string | execa.SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
18
|
-
declare function execCommand(cmd: string, opts?: ExecOptions): Promise<string | unknown[] | Uint8Array<ArrayBufferLike> | execa.Result<ExecOptions> | undefined>;
|
|
19
|
-
declare function execCommandSync(cmd: string, opts?: ExecSyncOptions): string | execa.SyncResult<ExecSyncOptions> | unknown[] | Uint8Array<ArrayBufferLike> | undefined;
|
|
20
|
-
|
|
21
|
-
export { exec, execCommand, execCommandSync, execSync };
|
|
22
|
-
export type { ExecOptions, ExecSyncOptions };
|