@plugjs/plug 0.0.14 → 0.0.16
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/async.cjs +20 -19
- package/dist/async.cjs.map +1 -1
- package/dist/async.d.ts +9 -9
- package/dist/async.mjs +18 -17
- package/dist/async.mjs.map +1 -1
- package/dist/build.cjs +113 -110
- package/dist/build.cjs.map +2 -2
- package/dist/build.d.ts +14 -56
- package/dist/build.mjs +114 -111
- package/dist/build.mjs.map +2 -2
- package/dist/files.cjs +2 -16
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.ts +3 -10
- package/dist/files.mjs +3 -17
- package/dist/files.mjs.map +1 -1
- package/dist/fork.cjs +28 -40
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.d.ts +6 -27
- package/dist/fork.mjs +29 -40
- package/dist/fork.mjs.map +1 -1
- package/dist/helpers.cjs +27 -61
- package/dist/helpers.cjs.map +2 -2
- package/dist/helpers.d.ts +29 -31
- package/dist/helpers.mjs +27 -62
- package/dist/helpers.mjs.map +2 -2
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -13
- package/dist/index.mjs +7 -2
- package/dist/index.mjs.map +1 -1
- package/dist/log/colors.cjs +3 -1
- package/dist/log/colors.cjs.map +1 -1
- package/dist/log/colors.d.ts +2 -2
- package/dist/log/colors.mjs +3 -1
- package/dist/log/colors.mjs.map +1 -1
- package/dist/log/emit.d.ts +1 -1
- package/dist/log/logger.cjs +4 -0
- package/dist/log/logger.cjs.map +1 -1
- package/dist/log/logger.d.ts +4 -1
- package/dist/log/logger.mjs +4 -0
- package/dist/log/logger.mjs.map +1 -1
- package/dist/log/options.d.ts +1 -1
- package/dist/log/report.cjs +2 -11
- package/dist/log/report.cjs.map +1 -1
- package/dist/log/report.d.ts +36 -4
- package/dist/log/report.mjs +1 -10
- package/dist/log/report.mjs.map +1 -1
- package/dist/log.cjs +1 -1
- package/dist/log.cjs.map +1 -1
- package/dist/log.d.ts +6 -6
- package/dist/log.mjs +2 -2
- package/dist/log.mjs.map +1 -1
- package/dist/pipe.cjs +69 -26
- package/dist/pipe.cjs.map +1 -1
- package/dist/pipe.d.ts +178 -119
- package/dist/pipe.mjs +71 -24
- package/dist/pipe.mjs.map +1 -1
- package/dist/plugs/copy.cjs +15 -25
- package/dist/plugs/copy.cjs.map +2 -2
- package/dist/plugs/copy.d.ts +14 -13
- package/dist/plugs/copy.mjs +15 -17
- package/dist/plugs/copy.mjs.map +2 -2
- package/dist/plugs/coverage/analysis.d.ts +2 -2
- package/dist/plugs/coverage/report.cjs +1 -1
- package/dist/plugs/coverage/report.cjs.map +1 -1
- package/dist/plugs/coverage/report.d.ts +3 -3
- package/dist/plugs/coverage/report.mjs +1 -1
- package/dist/plugs/coverage/report.mjs.map +1 -1
- package/dist/plugs/coverage.cjs +20 -26
- package/dist/plugs/coverage.cjs.map +1 -1
- package/dist/plugs/coverage.d.ts +33 -30
- package/dist/plugs/coverage.mjs +21 -19
- package/dist/plugs/coverage.mjs.map +1 -1
- package/dist/plugs/debug.cjs +12 -36
- package/dist/plugs/debug.cjs.map +1 -1
- package/dist/plugs/debug.d.ts +4 -11
- package/dist/plugs/debug.mjs +30 -21
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
- package/dist/plugs/esbuild.cjs +14 -25
- package/dist/plugs/esbuild.cjs.map +1 -1
- package/dist/plugs/esbuild.d.ts +11 -16
- package/dist/plugs/esbuild.mjs +14 -17
- package/dist/plugs/esbuild.mjs.map +1 -1
- package/dist/plugs/eslint/runner.cjs +5 -6
- package/dist/plugs/eslint/runner.cjs.map +1 -1
- package/dist/plugs/eslint/runner.d.ts +6 -20
- package/dist/plugs/eslint/runner.mjs +6 -7
- package/dist/plugs/eslint/runner.mjs.map +1 -1
- package/dist/{task.cjs → plugs/eslint.cjs} +7 -24
- package/dist/plugs/eslint.cjs.map +6 -0
- package/dist/plugs/eslint.d.ts +34 -0
- package/dist/plugs/eslint.mjs +5 -0
- package/dist/plugs/eslint.mjs.map +6 -0
- package/dist/plugs/exec.cjs +20 -24
- package/dist/plugs/exec.cjs.map +1 -1
- package/dist/plugs/exec.d.ts +53 -53
- package/dist/plugs/exec.mjs +20 -23
- package/dist/plugs/exec.mjs.map +1 -1
- package/dist/plugs/filter.cjs +9 -19
- package/dist/plugs/filter.cjs.map +1 -1
- package/dist/plugs/filter.d.ts +21 -15
- package/dist/plugs/filter.mjs +10 -12
- package/dist/plugs/filter.mjs.map +1 -1
- package/dist/plugs/mocha/reporter.cjs +12 -6
- package/dist/plugs/mocha/reporter.cjs.map +1 -1
- package/dist/plugs/mocha/reporter.d.ts +0 -2
- package/dist/plugs/mocha/reporter.mjs +11 -4
- package/dist/plugs/mocha/reporter.mjs.map +1 -1
- package/dist/plugs/mocha/runner.cjs +4 -5
- package/dist/plugs/mocha/runner.cjs.map +1 -1
- package/dist/plugs/mocha/runner.d.ts +5 -31
- package/dist/plugs/mocha/runner.mjs +5 -6
- package/dist/plugs/mocha/runner.mjs.map +1 -1
- package/dist/plugs/mocha.cjs +22 -0
- package/dist/plugs/mocha.cjs.map +6 -0
- package/dist/plugs/mocha.d.ts +35 -0
- package/dist/plugs/mocha.mjs +5 -0
- package/dist/plugs/mocha.mjs.map +6 -0
- package/dist/plugs/rmf.cjs +4 -32
- package/dist/plugs/rmf.cjs.map +1 -1
- package/dist/plugs/rmf.d.ts +8 -12
- package/dist/plugs/rmf.mjs +25 -20
- package/dist/plugs/rmf.mjs.map +1 -1
- package/dist/plugs/tsc/compiler.d.ts +1 -1
- package/dist/plugs/tsc/options.d.ts +1 -1
- package/dist/plugs/tsc/report.d.ts +2 -2
- package/dist/plugs/tsc/runner.cjs +12 -11
- package/dist/plugs/tsc/runner.cjs.map +1 -1
- package/dist/plugs/tsc/runner.d.ts +4 -9
- package/dist/plugs/tsc/runner.mjs +12 -11
- package/dist/plugs/tsc/runner.mjs.map +1 -1
- package/dist/plugs/tsc.cjs +7 -0
- package/dist/plugs/tsc.cjs.map +6 -0
- package/dist/plugs/tsc.d.ts +36 -0
- package/dist/plugs/tsc.mjs +15 -0
- package/dist/plugs/tsc.mjs.map +6 -0
- package/dist/plugs.cjs +3 -5
- package/dist/plugs.cjs.map +1 -1
- package/dist/plugs.d.ts +10 -17
- package/dist/plugs.mjs +3 -5
- package/dist/plugs.mjs.map +1 -1
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +6 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +6 -0
- package/dist/utils/caller.cjs +8 -11
- package/dist/utils/caller.cjs.map +2 -2
- package/dist/utils/caller.d.ts +2 -7
- package/dist/utils/caller.mjs +8 -11
- package/dist/utils/caller.mjs.map +2 -2
- package/dist/utils/options.cjs +4 -6
- package/dist/utils/options.cjs.map +1 -1
- package/dist/utils/options.d.ts +16 -15
- package/dist/utils/options.mjs +4 -6
- package/dist/utils/options.mjs.map +1 -1
- package/dist/utils/walk.d.ts +2 -2
- package/extra/cli.mjs +31 -20
- package/extra/ts-loader.mjs +6 -5
- package/package.json +8 -9
- package/src/async.ts +27 -19
- package/src/files.ts +6 -30
- package/src/fork.ts +35 -76
- package/src/helpers.ts +66 -99
- package/src/index.ts +10 -15
- package/src/log/colors.ts +4 -3
- package/src/log/emit.ts +4 -4
- package/src/log/logger.ts +12 -4
- package/src/log/options.ts +1 -1
- package/src/log/report.ts +8 -22
- package/src/log/spinner.ts +3 -3
- package/src/log.ts +9 -9
- package/src/paths.ts +1 -1
- package/src/pipe.ts +255 -170
- package/src/plugs/copy.ts +40 -31
- package/src/plugs/coverage/analysis.ts +4 -4
- package/src/plugs/coverage/report.ts +6 -5
- package/src/plugs/coverage.ts +64 -53
- package/src/plugs/debug.ts +28 -26
- package/src/plugs/esbuild/fix-extensions.ts +2 -2
- package/src/plugs/esbuild.ts +42 -46
- package/src/plugs/eslint/runner.ts +16 -31
- package/src/plugs/eslint.ts +42 -0
- package/src/plugs/exec.ts +93 -82
- package/src/plugs/filter.ts +42 -27
- package/src/plugs/mocha/reporter.ts +10 -5
- package/src/plugs/mocha/runner.ts +12 -38
- package/src/plugs/mocha.ts +41 -0
- package/src/plugs/rmf.ts +21 -25
- package/src/plugs/tsc/compiler.ts +1 -1
- package/src/plugs/tsc/options.ts +2 -2
- package/src/plugs/tsc/report.ts +2 -2
- package/src/plugs/tsc/runner.ts +24 -30
- package/src/plugs/tsc.ts +45 -0
- package/src/plugs.ts +10 -25
- package/src/types.ts +116 -0
- package/src/utils/caller.ts +11 -22
- package/src/utils/options.ts +49 -17
- package/src/utils/walk.ts +4 -4
- package/dist/run.cjs +0 -90
- package/dist/run.cjs.map +0 -6
- package/dist/run.d.ts +0 -89
- package/dist/run.mjs +0 -65
- package/dist/run.mjs.map +0 -6
- package/dist/task.cjs.map +0 -6
- package/dist/task.d.ts +0 -15
- package/dist/task.mjs +0 -14
- package/dist/task.mjs.map +0 -6
- package/src/run.ts +0 -159
- package/src/task.ts +0 -26
package/dist/plugs/exec.cjs
CHANGED
|
@@ -26,7 +26,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
26
|
// plugs/exec.ts
|
|
27
27
|
var exec_exports = {};
|
|
28
28
|
__export(exec_exports, {
|
|
29
|
-
Exec: () => Exec,
|
|
30
29
|
exec: () => exec
|
|
31
30
|
});
|
|
32
31
|
module.exports = __toCommonJS(exec_exports);
|
|
@@ -34,60 +33,58 @@ var import_node_path = __toESM(require("node:path"));
|
|
|
34
33
|
var import_node_readline = __toESM(require("node:readline"));
|
|
35
34
|
var import_node_child_process = require("node:child_process");
|
|
36
35
|
var import_assert = require("../assert.cjs");
|
|
37
|
-
var import_async = require("../async.cjs");
|
|
38
36
|
var import_log = require("../log.cjs");
|
|
39
37
|
var import_paths = require("../paths.cjs");
|
|
40
38
|
var import_pipe = require("../pipe.cjs");
|
|
41
39
|
var import_options = require("../utils/options.cjs");
|
|
42
|
-
var
|
|
40
|
+
var import_async = require("../async.cjs");
|
|
41
|
+
(0, import_pipe.install)("exec", class Exec {
|
|
43
42
|
_cmd;
|
|
44
43
|
_args;
|
|
45
44
|
_options;
|
|
46
|
-
constructor(
|
|
45
|
+
constructor(...args) {
|
|
47
46
|
const { params, options } = (0, import_options.parseOptions)(args, {});
|
|
48
|
-
|
|
49
|
-
this.
|
|
47
|
+
const [_cmd, ..._args] = params;
|
|
48
|
+
this._cmd = _cmd;
|
|
49
|
+
this._args = _args;
|
|
50
50
|
this._options = options;
|
|
51
51
|
}
|
|
52
|
-
async pipe(files,
|
|
52
|
+
async pipe(files, context) {
|
|
53
53
|
const { relativePaths = true, ...options } = this._options;
|
|
54
54
|
if (!options.cwd)
|
|
55
55
|
options.cwd = files.directory;
|
|
56
56
|
const params = [...relativePaths ? files : files.absolutePaths()];
|
|
57
57
|
if (options.shell)
|
|
58
58
|
params.forEach((s, i, a) => a[i] = JSON.stringify(s));
|
|
59
|
-
await spawnChild(this._cmd, [...this._args, ...params], options,
|
|
59
|
+
await spawnChild(this._cmd, [...this._args, ...params], options, context);
|
|
60
60
|
return files;
|
|
61
61
|
}
|
|
62
|
-
};
|
|
62
|
+
});
|
|
63
63
|
function exec(cmd, ...args) {
|
|
64
|
-
const
|
|
65
|
-
(
|
|
66
|
-
const { params, options } = (0, import_options.parseOptions)(args, {});
|
|
67
|
-
return spawnChild(cmd, params, options, run);
|
|
64
|
+
const { params, options } = (0, import_options.parseOptions)(args);
|
|
65
|
+
return spawnChild(cmd, params, options, (0, import_async.requireContext)());
|
|
68
66
|
}
|
|
69
|
-
(
|
|
70
|
-
async function spawnChild(cmd, args, options = {}, run) {
|
|
67
|
+
async function spawnChild(cmd, args, options = {}, context) {
|
|
71
68
|
const {
|
|
72
69
|
env = {},
|
|
73
70
|
shell = false,
|
|
74
71
|
cwd = void 0,
|
|
75
72
|
...extraOptions
|
|
76
73
|
} = options;
|
|
77
|
-
const childCwd = cwd ?
|
|
74
|
+
const childCwd = cwd ? context.resolve(cwd) : (0, import_paths.getCurrentWorkingDirectory)();
|
|
78
75
|
(0, import_assert.assert)((0, import_paths.resolveDirectory)(childCwd), `Current working directory ${(0, import_log.$p)(childCwd)} does not exist`);
|
|
79
76
|
const childPaths = [];
|
|
80
|
-
const baseNodePath =
|
|
77
|
+
const baseNodePath = context.resolve("@node_modules", ".bin");
|
|
81
78
|
if ((0, import_paths.resolveDirectory)(baseNodePath))
|
|
82
79
|
childPaths.push(baseNodePath);
|
|
83
|
-
const buildNodePath =
|
|
80
|
+
const buildNodePath = context.resolve("./node_modules", ".bin");
|
|
84
81
|
if ((0, import_paths.resolveDirectory)(buildNodePath))
|
|
85
82
|
childPaths.push(buildNodePath);
|
|
86
83
|
const extraPath = env.PATH || process.env.PATH;
|
|
87
84
|
if (extraPath)
|
|
88
85
|
childPaths.push(extraPath);
|
|
89
86
|
const PATH = childPaths.join(import_node_path.default.delimiter);
|
|
90
|
-
const __LOG_OPTIONS = JSON.stringify(import_log.logOptions.fork(
|
|
87
|
+
const __LOG_OPTIONS = JSON.stringify(import_log.logOptions.fork(context.taskName));
|
|
91
88
|
const childEnv = { ...process.env, ...env, PATH, __LOG_OPTIONS };
|
|
92
89
|
const childOptions = {
|
|
93
90
|
...extraOptions,
|
|
@@ -96,16 +93,16 @@ async function spawnChild(cmd, args, options = {}, run) {
|
|
|
96
93
|
env: childEnv,
|
|
97
94
|
shell
|
|
98
95
|
};
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
context.log.info("Executing", [cmd, ...args]);
|
|
97
|
+
context.log.info("Execution options", childOptions);
|
|
101
98
|
const child = (0, import_node_child_process.spawn)(cmd, args, childOptions);
|
|
102
99
|
if (child.stdout) {
|
|
103
100
|
const out = import_node_readline.default.createInterface(child.stdout);
|
|
104
|
-
out.on("line", (line) => line ?
|
|
101
|
+
out.on("line", (line) => line ? context.log.notice(line) : context.log.notice("\xA0"));
|
|
105
102
|
}
|
|
106
103
|
if (child.stderr) {
|
|
107
104
|
const err = import_node_readline.default.createInterface(child.stderr);
|
|
108
|
-
err.on("line", (line) => line ?
|
|
105
|
+
err.on("line", (line) => line ? context.log.warn(line) : context.log.warn("\xA0"));
|
|
109
106
|
}
|
|
110
107
|
return new Promise((resolve, reject) => {
|
|
111
108
|
child.on("error", (error) => reject(error));
|
|
@@ -122,7 +119,6 @@ async function spawnChild(cmd, args, options = {}, run) {
|
|
|
122
119
|
}
|
|
123
120
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
121
|
0 && (module.exports = {
|
|
125
|
-
Exec,
|
|
126
122
|
exec
|
|
127
123
|
});
|
|
128
124
|
//# sourceMappingURL=exec.cjs.map
|
package/dist/plugs/exec.cjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/plugs/exec.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,2BAAsB;AAEtB,gCAAoC;AACpC,oBAAuB;AAEvB,iBAA+B;AAC/B,mBAA2E;AAC3E,kBAAuD;AACvD,qBAA6B;AAC7B,mBAA+B;AAAA,IA6E/B,qBAAQ,QAAQ,MAAM,KAA4B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,eAAe,MAA8B;AAC3C,UAAM,EAAE,QAAQ,QAAQ,QAAI,6BAAa,MAAM,CAAC,CAAC;AACjD,UAAM,CAAE,SAAS,KAAM,IAAI;AAC3B,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAM,KAAK,OAAc,SAAkC;AACzD,UAAM,EAAE,gBA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'../files.js';
|
|
2
|
-
import { Plug } from '../pipe.js';
|
|
3
|
-
import { Run } from '../run.js';
|
|
4
|
-
import { ParseOptions } from '../utils/options.js';
|
|
5
1
|
/** Options for executing scripts */
|
|
6
2
|
export interface ExecOptions {
|
|
7
3
|
/** Extra environment variables, or overrides for existing ones */
|
|
@@ -21,51 +17,7 @@ export interface ExecOptions {
|
|
|
21
17
|
*/
|
|
22
18
|
relativePaths?: boolean;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
* Execute a shell command, adding to its _arguments_ the list of files from
|
|
26
|
-
* the current pipe (much like `xargs` does on Unix systems).
|
|
27
|
-
*
|
|
28
|
-
* This {@link Plug} returns the same {@link Files} it was given, so that
|
|
29
|
-
* executing a shell command doesn't interrupt a {@link Pipe}.
|
|
30
|
-
*
|
|
31
|
-
* For example:
|
|
32
|
-
*
|
|
33
|
-
* ```
|
|
34
|
-
* import { find, exec } from '@plugjs/plugjs'
|
|
35
|
-
*
|
|
36
|
-
* export default build({
|
|
37
|
-
* async runme() {
|
|
38
|
-
* find('*.ts', { directory: 'src' })
|
|
39
|
-
* .plug(new Exec('chmod', '755' }))
|
|
40
|
-
* .plug(new Exec('chown root:root', { shell: true }))
|
|
41
|
-
* },
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare class Exec implements Plug<Files> {
|
|
46
|
-
private readonly _cmd;
|
|
47
|
-
private readonly _args;
|
|
48
|
-
private readonly _options;
|
|
49
|
-
constructor(cmd: string, ...args: ParseOptions<ExecOptions>);
|
|
50
|
-
pipe(files: Files, run: Run): Promise<Files>;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Execute a command and await for its result from within a task.
|
|
54
|
-
*
|
|
55
|
-
* For example:
|
|
56
|
-
*
|
|
57
|
-
* ```
|
|
58
|
-
* import { exec } from '@plugjs/plugjs'
|
|
59
|
-
*
|
|
60
|
-
* export default build({
|
|
61
|
-
* async runme() {
|
|
62
|
-
* await exec('ls', '-la', '/')
|
|
63
|
-
* },
|
|
64
|
-
* })
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function exec(cmd: string, ...args: ParseOptions<ExecOptions>): Promise<void>;
|
|
68
|
-
declare module '../pipe.js' {
|
|
20
|
+
declare module '../pipe' {
|
|
69
21
|
interface Pipe {
|
|
70
22
|
/**
|
|
71
23
|
* Execute a shell command, adding to its _arguments_ the list of files
|
|
@@ -74,17 +26,65 @@ declare module '../pipe.js' {
|
|
|
74
26
|
* For example:
|
|
75
27
|
*
|
|
76
28
|
* ```
|
|
77
|
-
* import {
|
|
29
|
+
* import { build } from '@plugjs/plugjs'
|
|
30
|
+
*
|
|
31
|
+
* export default build({
|
|
32
|
+
* runme() {
|
|
33
|
+
* this.find('*.ts', { directory: 'src' })
|
|
34
|
+
* .exec('chmod', '755' })
|
|
35
|
+
* .exec('chown root:root', { shell: true })
|
|
36
|
+
* },
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param cmd The command to execute
|
|
41
|
+
* @param args Any additional argument for the command to execute
|
|
42
|
+
*/
|
|
43
|
+
exec(cmd: string, ...args: string[]): Pipe;
|
|
44
|
+
/**
|
|
45
|
+
* Execute a shell command, adding to its _arguments_ the list of files
|
|
46
|
+
* from the current pipe (much like `xargs` does on Unix systems).
|
|
47
|
+
*
|
|
48
|
+
* For example:
|
|
49
|
+
*
|
|
50
|
+
* ```
|
|
51
|
+
* import { build } from '@plugjs/plugjs'
|
|
78
52
|
*
|
|
79
53
|
* export default build({
|
|
80
|
-
*
|
|
81
|
-
* find('*.ts', { directory: 'src' })
|
|
54
|
+
* runme() {
|
|
55
|
+
* this.find('*.ts', { directory: 'src' })
|
|
82
56
|
* .exec('chmod', '755' })
|
|
83
57
|
* .exec('chown root:root', { shell: true })
|
|
84
58
|
* },
|
|
85
59
|
* })
|
|
86
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param cmd The command to execute
|
|
63
|
+
* @param args Any additional argument for the command to execute
|
|
64
|
+
* @param options Extra {@link ExecOptions | options} for process execution
|
|
87
65
|
*/
|
|
88
|
-
exec:
|
|
66
|
+
exec(cmd: string, ...extra: [...args: string[], options: ExecOptions]): Pipe;
|
|
89
67
|
}
|
|
90
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Execute a command and await for its result from within a task.
|
|
71
|
+
*
|
|
72
|
+
* For example:
|
|
73
|
+
*
|
|
74
|
+
* ```
|
|
75
|
+
* import { exec } from '@plugjs/plugjs'
|
|
76
|
+
*
|
|
77
|
+
* export default build({
|
|
78
|
+
* async runme() {
|
|
79
|
+
* await exec('ls', '-la', '/')
|
|
80
|
+
* // or similarly letting the shell interpret the command
|
|
81
|
+
* await exec('ls -la /', { shell: true })
|
|
82
|
+
* },
|
|
83
|
+
* })
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param cmd The command to execute
|
|
87
|
+
* @param args Any additional argument for the command to execute
|
|
88
|
+
* @param options Extra {@link ExecOptions | options} for process execution
|
|
89
|
+
*/
|
|
90
|
+
export declare function exec(cmd: string, ...args: [...args: string[]] | [...args: string[], options: ExecOptions]): Promise<void>;
|
package/dist/plugs/exec.mjs
CHANGED
|
@@ -3,60 +3,58 @@ import path from "node:path";
|
|
|
3
3
|
import reaadline from "node:readline";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { assert } from "../assert.mjs";
|
|
6
|
-
import { currentRun } from "../async.mjs";
|
|
7
6
|
import { $p, logOptions } from "../log.mjs";
|
|
8
7
|
import { getCurrentWorkingDirectory, resolveDirectory } from "../paths.mjs";
|
|
9
8
|
import { install } from "../pipe.mjs";
|
|
10
9
|
import { parseOptions } from "../utils/options.mjs";
|
|
11
|
-
|
|
10
|
+
import { requireContext } from "../async.mjs";
|
|
11
|
+
install("exec", class Exec {
|
|
12
12
|
_cmd;
|
|
13
13
|
_args;
|
|
14
14
|
_options;
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(...args) {
|
|
16
16
|
const { params, options } = parseOptions(args, {});
|
|
17
|
-
|
|
18
|
-
this.
|
|
17
|
+
const [_cmd, ..._args] = params;
|
|
18
|
+
this._cmd = _cmd;
|
|
19
|
+
this._args = _args;
|
|
19
20
|
this._options = options;
|
|
20
21
|
}
|
|
21
|
-
async pipe(files,
|
|
22
|
+
async pipe(files, context) {
|
|
22
23
|
const { relativePaths = true, ...options } = this._options;
|
|
23
24
|
if (!options.cwd)
|
|
24
25
|
options.cwd = files.directory;
|
|
25
26
|
const params = [...relativePaths ? files : files.absolutePaths()];
|
|
26
27
|
if (options.shell)
|
|
27
28
|
params.forEach((s, i, a) => a[i] = JSON.stringify(s));
|
|
28
|
-
await spawnChild(this._cmd, [...this._args, ...params], options,
|
|
29
|
+
await spawnChild(this._cmd, [...this._args, ...params], options, context);
|
|
29
30
|
return files;
|
|
30
31
|
}
|
|
31
|
-
};
|
|
32
|
+
});
|
|
32
33
|
function exec(cmd, ...args) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const { params, options } = parseOptions(args, {});
|
|
36
|
-
return spawnChild(cmd, params, options, run);
|
|
34
|
+
const { params, options } = parseOptions(args);
|
|
35
|
+
return spawnChild(cmd, params, options, requireContext());
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
async function spawnChild(cmd, args, options = {}, run) {
|
|
37
|
+
async function spawnChild(cmd, args, options = {}, context) {
|
|
40
38
|
const {
|
|
41
39
|
env = {},
|
|
42
40
|
shell = false,
|
|
43
41
|
cwd = void 0,
|
|
44
42
|
...extraOptions
|
|
45
43
|
} = options;
|
|
46
|
-
const childCwd = cwd ?
|
|
44
|
+
const childCwd = cwd ? context.resolve(cwd) : getCurrentWorkingDirectory();
|
|
47
45
|
assert(resolveDirectory(childCwd), `Current working directory ${$p(childCwd)} does not exist`);
|
|
48
46
|
const childPaths = [];
|
|
49
|
-
const baseNodePath =
|
|
47
|
+
const baseNodePath = context.resolve("@node_modules", ".bin");
|
|
50
48
|
if (resolveDirectory(baseNodePath))
|
|
51
49
|
childPaths.push(baseNodePath);
|
|
52
|
-
const buildNodePath =
|
|
50
|
+
const buildNodePath = context.resolve("./node_modules", ".bin");
|
|
53
51
|
if (resolveDirectory(buildNodePath))
|
|
54
52
|
childPaths.push(buildNodePath);
|
|
55
53
|
const extraPath = env.PATH || process.env.PATH;
|
|
56
54
|
if (extraPath)
|
|
57
55
|
childPaths.push(extraPath);
|
|
58
56
|
const PATH = childPaths.join(path.delimiter);
|
|
59
|
-
const __LOG_OPTIONS = JSON.stringify(logOptions.fork(
|
|
57
|
+
const __LOG_OPTIONS = JSON.stringify(logOptions.fork(context.taskName));
|
|
60
58
|
const childEnv = { ...process.env, ...env, PATH, __LOG_OPTIONS };
|
|
61
59
|
const childOptions = {
|
|
62
60
|
...extraOptions,
|
|
@@ -65,16 +63,16 @@ async function spawnChild(cmd, args, options = {}, run) {
|
|
|
65
63
|
env: childEnv,
|
|
66
64
|
shell
|
|
67
65
|
};
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
context.log.info("Executing", [cmd, ...args]);
|
|
67
|
+
context.log.info("Execution options", childOptions);
|
|
70
68
|
const child = spawn(cmd, args, childOptions);
|
|
71
69
|
if (child.stdout) {
|
|
72
70
|
const out = reaadline.createInterface(child.stdout);
|
|
73
|
-
out.on("line", (line) => line ?
|
|
71
|
+
out.on("line", (line) => line ? context.log.notice(line) : context.log.notice("\xA0"));
|
|
74
72
|
}
|
|
75
73
|
if (child.stderr) {
|
|
76
74
|
const err = reaadline.createInterface(child.stderr);
|
|
77
|
-
err.on("line", (line) => line ?
|
|
75
|
+
err.on("line", (line) => line ? context.log.warn(line) : context.log.warn("\xA0"));
|
|
78
76
|
}
|
|
79
77
|
return new Promise((resolve, reject) => {
|
|
80
78
|
child.on("error", (error) => reject(error));
|
|
@@ -90,7 +88,6 @@ async function spawnChild(cmd, args, options = {}, run) {
|
|
|
90
88
|
});
|
|
91
89
|
}
|
|
92
90
|
export {
|
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;AAClD,QAAI,GAAG,QAAQ,CAAC,SAAS,OAAO,QAAQ,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,OAAO,MAAQ,CAAC;AAAA,EACzF;AAEA,MAAI,MAAM,QAAQ;AAChB,UAAM,MAAM,UAAU,gBAAgB,MAAM,MAAM;AAClD,QAAI,GAAG,QAAQ,CAAC,SAAS,OAAO,QAAQ,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,MAAQ,CAAC;AAAA,EACrF;AAGA,SAAO,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,UAAM,GAAG,SAAS,CAAC,UAAU,OAAO,KAAK,CAAC;AAC1C,UAAM,GAAG,QAAQ,CAAC,MAAM,WAAW;AACjC,UAAI,SAAS;AAAG,eAAO,QAAQ;AAC/B,UAAI;AAAQ,eAAO,OAAO,IAAI,MAAM,oCAAoC,QAAQ,CAAC;AACjF,UAAI;AAAM,eAAO,OAAO,IAAI,MAAM,kCAAkC,MAAM,CAAC;AAC3E,aAAO,IAAI,MAAM,4CAA4C,CAAC;AAAA,IAChE,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/plugs/filter.cjs
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -19,40 +15,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
15
|
|
|
20
16
|
// plugs/filter.ts
|
|
21
17
|
var filter_exports = {};
|
|
22
|
-
__export(filter_exports, {
|
|
23
|
-
Filter: () => Filter
|
|
24
|
-
});
|
|
25
18
|
module.exports = __toCommonJS(filter_exports);
|
|
19
|
+
var import_files = require("../files.cjs");
|
|
26
20
|
var import_paths = require("../paths.cjs");
|
|
27
21
|
var import_pipe = require("../pipe.cjs");
|
|
28
22
|
var import_match = require("../utils/match.cjs");
|
|
29
23
|
var import_options = require("../utils/options.cjs");
|
|
30
|
-
|
|
24
|
+
(0, import_pipe.install)("filter", class Filter {
|
|
31
25
|
_globs;
|
|
32
26
|
_options;
|
|
33
|
-
constructor(
|
|
27
|
+
constructor(...args) {
|
|
34
28
|
const { params, options } = (0, import_options.parseOptions)(args, {});
|
|
35
|
-
this._globs = [glob, ...params];
|
|
36
29
|
this._options = options;
|
|
30
|
+
this._globs = params;
|
|
37
31
|
}
|
|
38
|
-
pipe(files,
|
|
32
|
+
pipe(files, context) {
|
|
39
33
|
const { directory, ...options } = this._options;
|
|
40
|
-
const
|
|
34
|
+
const dir = directory ? context.resolve(directory) : files.directory;
|
|
35
|
+
const builder = import_files.Files.builder(dir);
|
|
41
36
|
const matcher = (0, import_match.match)(this._globs, options);
|
|
42
37
|
for (const file of files.absolutePaths()) {
|
|
43
38
|
const relative = (0, import_paths.resolveRelativeChildPath)(builder.directory, file);
|
|
44
39
|
if (relative && matcher(relative))
|
|
45
|
-
builder.
|
|
40
|
+
builder.add(relative);
|
|
46
41
|
}
|
|
47
42
|
const result = builder.build();
|
|
48
43
|
const discarded = files.length - result.length;
|
|
49
|
-
|
|
44
|
+
context.log.debug("Filtered", result.length, "files (discarded", discarded, "files)");
|
|
50
45
|
return result;
|
|
51
46
|
}
|
|
52
|
-
};
|
|
53
|
-
(0, import_pipe.install)("filter", Filter);
|
|
54
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
-
0 && (module.exports = {
|
|
56
|
-
Filter
|
|
57
47
|
});
|
|
58
48
|
//# sourceMappingURL=filter.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/plugs/filter.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAAyC;AACzC,kBAAuD;AACvD,mBAAoC;AACpC,qBAA6B;AAAA,IAqC7B,qBAAQ,UAAU,MAAM,OAA8B;AAAA,EACnC;AAAA,EACA;AAAA,EAEjB,eAAe,MAAgC;AAC7C,UAAM,EAAE,QAAQ,QAAQ,QAAI,6BAAa,MAAM,CAAC,CAAC;AACjD,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,KAAK,OAAc,SAAyB;AAC1C,UAAM,EAAE,cAAc,QAAQ,IAAI,KAAK;AAEvC,UAAM,MAAM,YAAY,QAAQ,QAAQ,SAAS,IAAI,MAAM;AAC3D,UAAM,UAAU,mBAAM,QAAQ,GAAG;AACjC,UAAM,cAAU,oBAAM,KAAK,QAAQ,OAAO;AAE1C,eAAW,QAAQ,MAAM,cAAc,GAAG;AACxC,YAAM,eAAW,uCAAyB,QAAQ,WAAW,IAAI;AACjE,UAAI,YAAY,QAAQ,QAAQ;AAAG,gBAAQ,IAAI,QAAQ;AAAA,IACzD;AAEA,UAAM,SAAS,QAAQ,MAAM;AAC7B,UAAM,YAAY,MAAM,SAAS,OAAO;AACxC,YAAQ,IAAI,MAAM,YAAY,OAAO,QAAQ,oBAAoB,WAAW,QAAQ;AAEpF,WAAO;AAAA,EACT;AACF,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/plugs/filter.d.ts
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plug } from '../pipe.js';
|
|
3
|
-
import { Run } from '../run.js';
|
|
4
|
-
import { MatchOptions } from '../utils/match.js';
|
|
5
|
-
import { ParseOptions } from '../utils/options.js';
|
|
1
|
+
import { MatchOptions } from '../utils/match';
|
|
6
2
|
/** Options for filtering {@link Files}. */
|
|
7
3
|
export interface FilterOptions extends MatchOptions {
|
|
8
4
|
/** The base directory for filtering, and relativising the resulting files. */
|
|
9
5
|
directory?: string;
|
|
10
6
|
}
|
|
11
|
-
|
|
12
|
-
export declare class Filter implements Plug<Files> {
|
|
13
|
-
private readonly _globs;
|
|
14
|
-
private readonly _options;
|
|
15
|
-
constructor(glob: string, ...args: ParseOptions<FilterOptions>);
|
|
16
|
-
pipe(files: Files, run: Run): Files;
|
|
17
|
-
}
|
|
18
|
-
declare module '../pipe.js' {
|
|
7
|
+
declare module '../pipe' {
|
|
19
8
|
interface Pipe {
|
|
20
|
-
/**
|
|
21
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Filter the current {@link Files} using globs.
|
|
11
|
+
*
|
|
12
|
+
* @param glob The glob to use for filtering files
|
|
13
|
+
*/
|
|
14
|
+
filter(glob: string): Pipe;
|
|
15
|
+
/**
|
|
16
|
+
* Filter the current {@link Files} using globs.
|
|
17
|
+
*
|
|
18
|
+
* @param globs The globs to use for filtering files (at least one)
|
|
19
|
+
*/
|
|
20
|
+
filter(...globs: [string, ...string[]]): Pipe;
|
|
21
|
+
/**
|
|
22
|
+
* Filter the current {@link Files} using globs.
|
|
23
|
+
*
|
|
24
|
+
* @param globs The globs to use for filtering files (at least one)
|
|
25
|
+
* @param options Additional {@link FilterOptions | options} for filtering
|
|
26
|
+
*/
|
|
27
|
+
filter(...args: [...globs: [string, ...string[]], options: FilterOptions]): Pipe;
|
|
22
28
|
}
|
|
23
29
|
}
|
package/dist/plugs/filter.mjs
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
// plugs/filter.ts
|
|
2
|
+
import { Files } from "../files.mjs";
|
|
2
3
|
import { resolveRelativeChildPath } from "../paths.mjs";
|
|
3
4
|
import { install } from "../pipe.mjs";
|
|
4
5
|
import { match } from "../utils/match.mjs";
|
|
5
6
|
import { parseOptions } from "../utils/options.mjs";
|
|
6
|
-
|
|
7
|
+
install("filter", class Filter {
|
|
7
8
|
_globs;
|
|
8
9
|
_options;
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(...args) {
|
|
10
11
|
const { params, options } = parseOptions(args, {});
|
|
11
|
-
this._globs = [glob, ...params];
|
|
12
12
|
this._options = options;
|
|
13
|
+
this._globs = params;
|
|
13
14
|
}
|
|
14
|
-
pipe(files,
|
|
15
|
+
pipe(files, context) {
|
|
15
16
|
const { directory, ...options } = this._options;
|
|
16
|
-
const
|
|
17
|
+
const dir = directory ? context.resolve(directory) : files.directory;
|
|
18
|
+
const builder = Files.builder(dir);
|
|
17
19
|
const matcher = match(this._globs, options);
|
|
18
20
|
for (const file of files.absolutePaths()) {
|
|
19
21
|
const relative = resolveRelativeChildPath(builder.directory, file);
|
|
20
22
|
if (relative && matcher(relative))
|
|
21
|
-
builder.
|
|
23
|
+
builder.add(relative);
|
|
22
24
|
}
|
|
23
25
|
const result = builder.build();
|
|
24
26
|
const discarded = files.length - result.length;
|
|
25
|
-
|
|
27
|
+
context.log.debug("Filtered", result.length, "files (discarded", discarded, "files)");
|
|
26
28
|
return result;
|
|
27
29
|
}
|
|
28
|
-
};
|
|
29
|
-
install("filter", Filter);
|
|
30
|
-
export {
|
|
31
|
-
Filter
|
|
32
|
-
};
|
|
30
|
+
});
|
|
33
31
|
//# sourceMappingURL=filter.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/plugs/filter.ts"],
|
|
4
|
-
"mappings": ";
|
|
4
|
+
"mappings": ";AAAA,SAAS,aAAa;AACtB,SAAS,gCAAgC;AACzC,SAAkB,eAAqC;AACvD,SAAS,aAA2B;AACpC,SAAS,oBAAoB;AAqC7B,QAAQ,UAAU,MAAM,OAA8B;AAAA,EACnC;AAAA,EACA;AAAA,EAEjB,eAAe,MAAgC;AAC7C,UAAM,EAAE,QAAQ,QAAQ,IAAI,aAAa,MAAM,CAAC,CAAC;AACjD,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,KAAK,OAAc,SAAyB;AAC1C,UAAM,EAAE,cAAc,QAAQ,IAAI,KAAK;AAEvC,UAAM,MAAM,YAAY,QAAQ,QAAQ,SAAS,IAAI,MAAM;AAC3D,UAAM,UAAU,MAAM,QAAQ,GAAG;AACjC,UAAM,UAAU,MAAM,KAAK,QAAQ,OAAO;AAE1C,eAAW,QAAQ,MAAM,cAAc,GAAG;AACxC,YAAM,WAAW,yBAAyB,QAAQ,WAAW,IAAI;AACjE,UAAI,YAAY,QAAQ,QAAQ;AAAG,gBAAQ,IAAI,QAAQ;AAAA,IACzD;AAEA,UAAM,SAAS,QAAQ,MAAM;AAC7B,UAAM,YAAY,MAAM,SAAS,OAAO;AACxC,YAAQ,IAAI,MAAM,YAAY,OAAO,QAAQ,oBAAoB,WAAW,QAAQ;AAEpF,WAAO;AAAA,EACT;AACF,CAAC;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -27,8 +27,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var reporter_exports = {};
|
|
28
28
|
__export(reporter_exports, {
|
|
29
29
|
PlugReporter: () => PlugReporter,
|
|
30
|
-
logSymbol: () => logSymbol
|
|
31
|
-
runSymbol: () => runSymbol
|
|
30
|
+
logSymbol: () => logSymbol
|
|
32
31
|
});
|
|
33
32
|
module.exports = __toCommonJS(reporter_exports);
|
|
34
33
|
var import_mocha = __toESM(require("mocha"));
|
|
@@ -39,7 +38,6 @@ var _success = "\u2714";
|
|
|
39
38
|
var _failure = "\u2718";
|
|
40
39
|
var _details = "\u21B3";
|
|
41
40
|
var logSymbol = Symbol();
|
|
42
|
-
var runSymbol = Symbol();
|
|
43
41
|
var PlugReporter = class extends import_mocha.default.reporters.Base {
|
|
44
42
|
constructor(runner, options) {
|
|
45
43
|
super(runner, options);
|
|
@@ -47,6 +45,7 @@ var PlugReporter = class extends import_mocha.default.reporters.Base {
|
|
|
47
45
|
const log = options.reporterOptions[logSymbol];
|
|
48
46
|
const failures = [];
|
|
49
47
|
const rootSuite = runner.suite;
|
|
48
|
+
let slow = 0;
|
|
50
49
|
runner.on("suite", (suite) => {
|
|
51
50
|
if (suite === rootSuite)
|
|
52
51
|
return;
|
|
@@ -68,7 +67,13 @@ var PlugReporter = class extends import_mocha.default.reporters.Base {
|
|
|
68
67
|
});
|
|
69
68
|
runner.on("test end", (test) => {
|
|
70
69
|
if (test.isPassed()) {
|
|
71
|
-
|
|
70
|
+
const duration = test.duration || 0;
|
|
71
|
+
if (duration < test.slow()) {
|
|
72
|
+
log.leave(import_log.NOTICE, `${(0, import_log.$grn)(_success)} ${test.title}`);
|
|
73
|
+
} else {
|
|
74
|
+
log.leave(import_log.WARN, `${(0, import_log.$ylw)(_success)} ${test.title} ${(0, import_log.$ms)(duration, "slow")}`);
|
|
75
|
+
slow++;
|
|
76
|
+
}
|
|
72
77
|
} else if (test.isPending()) {
|
|
73
78
|
const tag = (0, import_log.$gry)("[") + (0, import_log.$ylw)("skipped") + (0, import_log.$gry)("]");
|
|
74
79
|
log.leave(import_log.WARN, `${(0, import_log.$ylw)(_pending)} ${test.title} ${tag}`);
|
|
@@ -126,6 +131,8 @@ var PlugReporter = class extends import_mocha.default.reporters.Base {
|
|
|
126
131
|
const fmt = (n) => n === 1 ? `${n} test` : `${n} tests`;
|
|
127
132
|
if (passes)
|
|
128
133
|
log.notice((0, import_log.$grn)(fmt(passes)), "passing", (0, import_log.$ms)(duration));
|
|
134
|
+
if (slow)
|
|
135
|
+
log.warn((0, import_log.$ylw)(fmt(slow)), "slow");
|
|
129
136
|
if (pending)
|
|
130
137
|
log.warn((0, import_log.$ylw)(fmt(pending)), "pending");
|
|
131
138
|
if (failures2)
|
|
@@ -141,7 +148,6 @@ var PlugReporter = class extends import_mocha.default.reporters.Base {
|
|
|
141
148
|
// Annotate the CommonJS export names for ESM import in node:
|
|
142
149
|
0 && (module.exports = {
|
|
143
150
|
PlugReporter,
|
|
144
|
-
logSymbol
|
|
145
|
-
runSymbol
|
|
151
|
+
logSymbol
|
|
146
152
|
});
|
|
147
153
|
//# sourceMappingURL=reporter.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugs/mocha/reporter.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAGtB,kBAAyB;AACzB,iBAAqF;AAErF,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AAOV,IAAM,YAAY,OAAO;AAEzB,IAAM,eAAN,cAA2B,aAAAA,QAAU,UAAU,KAAK;AAAA,EACzD,YAAY,QAA0B,SAAiC;AACrE,UAAM,QAAQ,OAAO;AAErB,UAAM,WAAW,CAAC,CAAE,QAAQ;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AACpC,UAAM,WAA6B,CAAC;AACpC,UAAM,YAAY,OAAO;AACzB,QAAI,OAAO;AAGX,WAAO,GAAG,SAAS,CAAC,UAAU;AAC5B,UAAI,UAAU;AAAW;AACzB,UAAI,OAAO,EAAE;AACb,UAAI,MAAM,mBAAQ,OAAG,iBAAK,MAAM,KAAK,GAAG;AAAA,IAC1C,CAAC;AAGD,WAAO,GAAG,aAAa,MAAM;AAC3B,UAAI,MAAM;AAAA,IACZ,CAAC;AAED,WAAO,GAAG,QAAQ,CAAC,SAAS;AAE1B,UAAI,KAAK,SAAgB,QAAQ;AAC/B,cAAM,SAAS,SAAS,KAAK,IAAI;AACjC,cAAM,UA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