@plugjs/plug 0.6.117 → 0.7.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/dist/asserts.d.ts +1 -0
- package/dist/asserts.d.ts.map +1 -0
- package/dist/asserts.js +68 -0
- package/dist/asserts.js.map +1 -0
- package/dist/async.d.ts +2 -1
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +52 -0
- package/dist/async.js.map +1 -0
- package/dist/build.d.ts +2 -1
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +236 -0
- package/dist/build.js.map +1 -0
- package/dist/{cli.d.mts → cli.d.ts} +3 -1
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +330 -0
- package/dist/cli.js.map +1 -0
- package/dist/files.d.ts +2 -1
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +93 -0
- package/dist/files.js.map +1 -0
- package/dist/fork.d.ts +5 -4
- package/dist/fork.d.ts.map +1 -0
- package/dist/fork.js +259 -0
- package/dist/fork.js.map +1 -0
- package/dist/fs.d.ts +1 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +72 -0
- package/dist/fs.js.map +1 -0
- package/dist/globals.d.ts +4 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +2 -0
- package/dist/globals.js.map +1 -0
- package/dist/helpers.d.ts +8 -7
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +231 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +22 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/colors.d.ts +2 -1
- package/dist/logging/colors.d.ts.map +1 -0
- package/dist/logging/colors.js +121 -0
- package/dist/logging/colors.js.map +1 -0
- package/dist/logging/emit.d.ts +2 -1
- package/dist/logging/emit.d.ts.map +1 -0
- package/dist/logging/emit.js +137 -0
- package/dist/logging/emit.js.map +1 -0
- package/dist/logging/github.d.ts +2 -1
- package/dist/logging/github.d.ts.map +1 -0
- package/dist/logging/github.js +46 -0
- package/dist/logging/github.js.map +1 -0
- package/dist/logging/levels.d.ts +1 -0
- package/dist/logging/levels.d.ts.map +1 -0
- package/dist/logging/levels.js +50 -0
- package/dist/logging/levels.js.map +1 -0
- package/dist/logging/logger.d.ts +4 -3
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +161 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/options.d.ts +2 -1
- package/dist/logging/options.d.ts.map +1 -0
- package/dist/logging/options.js +182 -0
- package/dist/logging/options.js.map +1 -0
- package/dist/logging/report.d.ts +4 -3
- package/dist/logging/report.d.ts.map +1 -0
- package/dist/logging/report.js +346 -0
- package/dist/logging/report.js.map +1 -0
- package/dist/logging/spinner.d.ts +1 -0
- package/dist/logging/spinner.d.ts.map +1 -0
- package/dist/logging/spinner.js +70 -0
- package/dist/logging/spinner.js.map +1 -0
- package/dist/logging.d.ts +8 -7
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +66 -0
- package/dist/logging.js.map +1 -0
- package/dist/paths.d.ts +33 -13
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +223 -0
- package/dist/paths.js.map +1 -0
- package/dist/pipe.d.ts +8 -5
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +205 -0
- package/dist/pipe.js.map +1 -0
- package/dist/plugs/build.d.ts +5 -4
- package/dist/plugs/build.d.ts.map +1 -0
- package/dist/plugs/build.js +56 -0
- package/dist/plugs/build.js.map +1 -0
- package/dist/plugs/copy.d.ts +1 -0
- package/dist/plugs/copy.d.ts.map +1 -0
- package/dist/plugs/copy.js +92 -0
- package/dist/plugs/copy.js.map +1 -0
- package/dist/plugs/debug.d.ts +1 -0
- package/dist/plugs/debug.d.ts.map +1 -0
- package/dist/plugs/debug.js +25 -0
- package/dist/plugs/debug.js.map +1 -0
- package/dist/plugs/edit.d.ts +2 -1
- package/dist/plugs/edit.d.ts.map +1 -0
- package/dist/plugs/edit.js +22 -0
- package/dist/plugs/edit.js.map +1 -0
- package/dist/plugs/esbuild/bundle-locals.d.ts +1 -0
- package/dist/plugs/esbuild/bundle-locals.d.ts.map +1 -0
- package/dist/plugs/esbuild/bundle-locals.js +29 -0
- package/dist/plugs/esbuild/bundle-locals.js.map +1 -0
- package/dist/plugs/esbuild/fix-extensions.d.ts +1 -0
- package/dist/plugs/esbuild/fix-extensions.d.ts.map +1 -0
- package/dist/plugs/esbuild/fix-extensions.js +98 -0
- package/dist/plugs/esbuild/fix-extensions.js.map +1 -0
- package/dist/plugs/esbuild.d.ts +21 -2
- package/dist/plugs/esbuild.d.ts.map +1 -0
- package/dist/plugs/esbuild.js +193 -0
- package/dist/plugs/esbuild.js.map +1 -0
- package/dist/plugs/exec.d.ts +2 -1
- package/dist/plugs/exec.d.ts.map +1 -0
- package/dist/plugs/exec.js +33 -0
- package/dist/plugs/exec.js.map +1 -0
- package/dist/plugs/exports.d.ts +1 -0
- package/dist/plugs/exports.d.ts.map +1 -0
- package/dist/plugs/exports.js +110 -0
- package/dist/plugs/exports.js.map +1 -0
- package/dist/plugs/filter.d.ts +2 -1
- package/dist/plugs/filter.d.ts.map +1 -0
- package/dist/plugs/filter.js +34 -0
- package/dist/plugs/filter.js.map +1 -0
- package/dist/plugs/rmf.d.ts +1 -0
- package/dist/plugs/rmf.d.ts.map +1 -0
- package/dist/plugs/rmf.js +24 -0
- package/dist/plugs/rmf.js.map +1 -0
- package/dist/plugs.d.ts +9 -8
- package/dist/plugs.d.ts.map +1 -0
- package/dist/plugs.js +9 -0
- package/dist/plugs.js.map +1 -0
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/ansi.d.ts +1 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +10 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/caller.d.ts +2 -1
- package/dist/utils/caller.d.ts.map +1 -0
- package/dist/utils/caller.js +33 -0
- package/dist/utils/caller.js.map +1 -0
- package/dist/utils/diff.d.ts +1 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +278 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/exec.d.ts +2 -1
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +84 -0
- package/dist/utils/exec.js.map +1 -0
- package/dist/utils/jsonc.d.ts +1 -0
- package/dist/utils/jsonc.d.ts.map +1 -0
- package/dist/utils/jsonc.js +46 -0
- package/dist/utils/jsonc.js.map +1 -0
- package/dist/utils/match.d.ts +1 -0
- package/dist/utils/match.d.ts.map +1 -0
- package/dist/utils/match.js +40 -0
- package/dist/utils/match.js.map +1 -0
- package/dist/utils/options.d.ts +1 -0
- package/dist/utils/options.d.ts.map +1 -0
- package/dist/utils/options.js +17 -0
- package/dist/utils/options.js.map +1 -0
- package/dist/utils/singleton.d.ts +1 -0
- package/dist/utils/singleton.d.ts.map +1 -0
- package/dist/utils/singleton.js +20 -0
- package/dist/utils/singleton.js.map +1 -0
- package/dist/utils/walk.d.ts +3 -2
- package/dist/utils/walk.d.ts.map +1 -0
- package/dist/utils/walk.js +84 -0
- package/dist/utils/walk.js.map +1 -0
- package/dist/utils.d.ts +9 -8
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -0
- package/package.json +28 -88
- package/src/asserts.ts +2 -2
- package/src/async.ts +3 -3
- package/src/build.ts +10 -10
- package/src/{cli.mts → cli.ts} +27 -16
- package/src/files.ts +4 -4
- package/src/fork.ts +17 -17
- package/src/globals.ts +3 -0
- package/src/helpers.ts +20 -20
- package/src/index.ts +21 -21
- package/src/logging/colors.ts +4 -4
- package/src/logging/emit.ts +6 -6
- package/src/logging/github.ts +3 -3
- package/src/logging/logger.ts +12 -12
- package/src/logging/options.ts +10 -10
- package/src/logging/report.ts +10 -10
- package/src/logging/spinner.ts +3 -3
- package/src/logging.ts +14 -14
- package/src/paths.ts +42 -23
- package/src/pipe.ts +13 -8
- package/src/plugs/build.ts +8 -8
- package/src/plugs/copy.ts +8 -8
- package/src/plugs/debug.ts +4 -4
- package/src/plugs/edit.ts +5 -5
- package/src/plugs/esbuild/fix-extensions.ts +8 -10
- package/src/plugs/esbuild.ts +88 -27
- package/src/plugs/exec.ts +6 -6
- package/src/plugs/exports.ts +32 -35
- package/src/plugs/filter.ts +7 -7
- package/src/plugs/rmf.ts +5 -5
- package/src/plugs.ts +8 -8
- package/src/types.ts +3 -3
- package/src/utils/caller.ts +4 -4
- package/src/utils/diff.ts +2 -2
- package/src/utils/exec.ts +7 -7
- package/src/utils/jsonc.ts +1 -1
- package/src/utils/walk.ts +6 -6
- package/src/utils.ts +8 -8
- package/dist/asserts.cjs +0 -86
- package/dist/asserts.cjs.map +0 -6
- package/dist/asserts.mjs +0 -58
- package/dist/asserts.mjs.map +0 -6
- package/dist/async.cjs +0 -64
- package/dist/async.cjs.map +0 -6
- package/dist/async.mjs +0 -36
- package/dist/async.mjs.map +0 -6
- package/dist/build.cjs +0 -222
- package/dist/build.cjs.map +0 -6
- package/dist/build.mjs +0 -192
- package/dist/build.mjs.map +0 -6
- package/dist/cli.mjs +0 -258
- package/dist/cli.mjs.map +0 -6
- package/dist/files.cjs +0 -113
- package/dist/files.cjs.map +0 -6
- package/dist/files.mjs +0 -93
- package/dist/files.mjs.map +0 -6
- package/dist/fork.cjs +0 -224
- package/dist/fork.cjs.map +0 -6
- package/dist/fork.mjs +0 -198
- package/dist/fork.mjs.map +0 -6
- package/dist/fs.cjs +0 -146
- package/dist/fs.cjs.map +0 -6
- package/dist/fs.mjs +0 -82
- package/dist/fs.mjs.map +0 -6
- package/dist/globals.cjs +0 -2
- package/dist/globals.cjs.map +0 -6
- package/dist/globals.mjs +0 -1
- package/dist/globals.mjs.map +0 -6
- package/dist/helpers.cjs +0 -182
- package/dist/helpers.cjs.map +0 -6
- package/dist/helpers.mjs +0 -151
- package/dist/helpers.mjs.map +0 -6
- package/dist/index.cjs +0 -114
- package/dist/index.cjs.map +0 -6
- package/dist/index.mjs +0 -48
- package/dist/index.mjs.map +0 -6
- package/dist/logging/colors.cjs +0 -136
- package/dist/logging/colors.cjs.map +0 -6
- package/dist/logging/colors.mjs +0 -99
- package/dist/logging/colors.mjs.map +0 -6
- package/dist/logging/emit.cjs +0 -134
- package/dist/logging/emit.cjs.map +0 -6
- package/dist/logging/emit.mjs +0 -106
- package/dist/logging/emit.mjs.map +0 -6
- package/dist/logging/github.cjs +0 -60
- package/dist/logging/github.cjs.map +0 -6
- package/dist/logging/github.mjs +0 -35
- package/dist/logging/github.mjs.map +0 -6
- package/dist/logging/levels.cjs +0 -69
- package/dist/logging/levels.cjs.map +0 -6
- package/dist/logging/levels.mjs +0 -35
- package/dist/logging/levels.mjs.map +0 -6
- package/dist/logging/logger.cjs +0 -165
- package/dist/logging/logger.cjs.map +0 -6
- package/dist/logging/logger.mjs +0 -139
- package/dist/logging/logger.mjs.map +0 -6
- package/dist/logging/options.cjs +0 -192
- package/dist/logging/options.cjs.map +0 -6
- package/dist/logging/options.mjs +0 -167
- package/dist/logging/options.mjs.map +0 -6
- package/dist/logging/report.cjs +0 -298
- package/dist/logging/report.cjs.map +0 -6
- package/dist/logging/report.mjs +0 -273
- package/dist/logging/report.mjs.map +0 -6
- package/dist/logging/spinner.cjs +0 -100
- package/dist/logging/spinner.cjs.map +0 -6
- package/dist/logging/spinner.mjs +0 -72
- package/dist/logging/spinner.mjs.map +0 -6
- package/dist/logging.cjs +0 -91
- package/dist/logging.cjs.map +0 -6
- package/dist/logging.mjs +0 -58
- package/dist/logging.mjs.map +0 -6
- package/dist/paths.cjs +0 -170
- package/dist/paths.cjs.map +0 -6
- package/dist/paths.mjs +0 -132
- package/dist/paths.mjs.map +0 -6
- package/dist/pipe.cjs +0 -163
- package/dist/pipe.cjs.map +0 -6
- package/dist/pipe.mjs +0 -135
- package/dist/pipe.mjs.map +0 -6
- package/dist/plugs/build.cjs +0 -73
- package/dist/plugs/build.cjs.map +0 -6
- package/dist/plugs/build.mjs +0 -47
- package/dist/plugs/build.mjs.map +0 -6
- package/dist/plugs/copy.cjs +0 -86
- package/dist/plugs/copy.cjs.map +0 -6
- package/dist/plugs/copy.mjs +0 -69
- package/dist/plugs/copy.mjs.map +0 -6
- package/dist/plugs/debug.cjs +0 -24
- package/dist/plugs/debug.cjs.map +0 -6
- package/dist/plugs/debug.mjs +0 -22
- package/dist/plugs/debug.mjs.map +0 -6
- package/dist/plugs/edit.cjs +0 -20
- package/dist/plugs/edit.cjs.map +0 -6
- package/dist/plugs/edit.mjs +0 -18
- package/dist/plugs/edit.mjs.map +0 -6
- package/dist/plugs/esbuild/bundle-locals.cjs +0 -48
- package/dist/plugs/esbuild/bundle-locals.cjs.map +0 -6
- package/dist/plugs/esbuild/bundle-locals.mjs +0 -23
- package/dist/plugs/esbuild/bundle-locals.mjs.map +0 -6
- package/dist/plugs/esbuild/fix-extensions.cjs +0 -89
- package/dist/plugs/esbuild/fix-extensions.cjs.map +0 -6
- package/dist/plugs/esbuild/fix-extensions.mjs +0 -54
- package/dist/plugs/esbuild/fix-extensions.mjs.map +0 -6
- package/dist/plugs/esbuild.cjs +0 -139
- package/dist/plugs/esbuild.cjs.map +0 -6
- package/dist/plugs/esbuild.mjs +0 -116
- package/dist/plugs/esbuild.mjs.map +0 -6
- package/dist/plugs/exec.cjs +0 -42
- package/dist/plugs/exec.cjs.map +0 -6
- package/dist/plugs/exec.mjs +0 -25
- package/dist/plugs/exec.mjs.map +0 -6
- package/dist/plugs/exports.cjs +0 -117
- package/dist/plugs/exports.cjs.map +0 -6
- package/dist/plugs/exports.mjs +0 -100
- package/dist/plugs/exports.mjs.map +0 -6
- package/dist/plugs/filter.cjs +0 -47
- package/dist/plugs/filter.cjs.map +0 -6
- package/dist/plugs/filter.mjs +0 -30
- package/dist/plugs/filter.mjs.map +0 -6
- package/dist/plugs/rmf.cjs +0 -25
- package/dist/plugs/rmf.cjs.map +0 -6
- package/dist/plugs/rmf.mjs +0 -23
- package/dist/plugs/rmf.mjs.map +0 -6
- package/dist/plugs.cjs +0 -39
- package/dist/plugs.cjs.map +0 -6
- package/dist/plugs.mjs +0 -10
- package/dist/plugs.mjs.map +0 -6
- package/dist/types.cjs +0 -19
- package/dist/types.cjs.map +0 -6
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +0 -6
- package/dist/utils/ansi.cjs +0 -39
- package/dist/utils/ansi.cjs.map +0 -6
- package/dist/utils/ansi.mjs +0 -13
- package/dist/utils/ansi.mjs.map +0 -6
- package/dist/utils/caller.cjs +0 -57
- package/dist/utils/caller.cjs.map +0 -6
- package/dist/utils/caller.mjs +0 -32
- package/dist/utils/caller.mjs.map +0 -6
- package/dist/utils/diff.cjs +0 -282
- package/dist/utils/diff.cjs.map +0 -6
- package/dist/utils/diff.mjs +0 -256
- package/dist/utils/diff.mjs.map +0 -6
- package/dist/utils/exec.cjs +0 -113
- package/dist/utils/exec.cjs.map +0 -6
- package/dist/utils/exec.mjs +0 -78
- package/dist/utils/exec.mjs.map +0 -6
- package/dist/utils/jsonc.cjs +0 -74
- package/dist/utils/jsonc.cjs.map +0 -6
- package/dist/utils/jsonc.mjs +0 -48
- package/dist/utils/jsonc.mjs.map +0 -6
- package/dist/utils/match.cjs +0 -74
- package/dist/utils/match.cjs.map +0 -6
- package/dist/utils/match.mjs +0 -39
- package/dist/utils/match.mjs.map +0 -6
- package/dist/utils/options.cjs +0 -39
- package/dist/utils/options.cjs.map +0 -6
- package/dist/utils/options.mjs +0 -14
- package/dist/utils/options.mjs.map +0 -6
- package/dist/utils/singleton.cjs +0 -37
- package/dist/utils/singleton.cjs.map +0 -6
- package/dist/utils/singleton.mjs +0 -12
- package/dist/utils/singleton.mjs.map +0 -6
- package/dist/utils/walk.cjs +0 -98
- package/dist/utils/walk.cjs.map +0 -6
- package/dist/utils/walk.mjs +0 -73
- package/dist/utils/walk.mjs.map +0 -6
- package/dist/utils.cjs +0 -39
- package/dist/utils.cjs.map +0 -6
- package/dist/utils.mjs +0 -10
- package/dist/utils.mjs.map +0 -6
package/dist/fork.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { fork } from 'node:child_process';
|
|
10
|
+
import { Console } from 'node:console';
|
|
11
|
+
import { Writable } from 'node:stream';
|
|
12
|
+
import { assert, BuildFailure } from "./asserts.js";
|
|
13
|
+
import { runAsync } from "./async.js";
|
|
14
|
+
import { Files } from "./files.js";
|
|
15
|
+
import { $gry, $p, $red, logOptions, NOTICE, WARN } from "./logging.js";
|
|
16
|
+
import { emit, emitForked } from "./logging/emit.js";
|
|
17
|
+
import { requireFilename, resolveFile } from "./paths.js";
|
|
18
|
+
import { Context, install } from "./pipe.js";
|
|
19
|
+
/* ========================================================================== *
|
|
20
|
+
* PARENT PROCESS SIDE OF THE FORKING PLUG IMPLEMENTATION *
|
|
21
|
+
* ========================================================================== */
|
|
22
|
+
export class ForkingPlug {
|
|
23
|
+
_scriptFile;
|
|
24
|
+
_arguments;
|
|
25
|
+
_exportName;
|
|
26
|
+
constructor(_scriptFile, _arguments, _exportName) {
|
|
27
|
+
this._scriptFile = _scriptFile;
|
|
28
|
+
this._arguments = _arguments;
|
|
29
|
+
this._exportName = _exportName;
|
|
30
|
+
}
|
|
31
|
+
pipe(files, context) {
|
|
32
|
+
const request = {
|
|
33
|
+
scriptFile: this._scriptFile,
|
|
34
|
+
exportName: this._exportName,
|
|
35
|
+
constructorArgs: this._arguments,
|
|
36
|
+
taskName: context.taskName,
|
|
37
|
+
buildFile: context.buildFile,
|
|
38
|
+
filesDir: files.directory,
|
|
39
|
+
filesList: [...files.absolutePaths()],
|
|
40
|
+
logIndent: context.log.indent,
|
|
41
|
+
};
|
|
42
|
+
/* Get _this_ filename to spawn */
|
|
43
|
+
const script = requireFilename(import.meta.filename);
|
|
44
|
+
context.log.debug('About to fork plug from', $p(this._scriptFile));
|
|
45
|
+
/* Environment variables */
|
|
46
|
+
const env = { ...process.env, ...logOptions.forkEnv(context.taskName) };
|
|
47
|
+
/* Check our args (reversed) to see if the last specifies `coverageDir` */
|
|
48
|
+
for (let i = this._arguments.length - 1; i >= 0; i--) {
|
|
49
|
+
if (this._arguments[i] == null)
|
|
50
|
+
continue; // null or undefined... optionals
|
|
51
|
+
if (typeof this._arguments[i] === 'object') {
|
|
52
|
+
if (typeof this._arguments[i].coverageDir === 'string') {
|
|
53
|
+
const dir = env['NODE_V8_COVERAGE'] = context.resolve(this._arguments[i].coverageDir);
|
|
54
|
+
context.log.debug('Forked process will produce coverage in', $p(dir));
|
|
55
|
+
}
|
|
56
|
+
if (typeof this._arguments[i].forceModule === 'string') {
|
|
57
|
+
const force = env['__TS_LOADER_FORCE_TYPE'] = this._arguments[i].forceModule;
|
|
58
|
+
context.log.debug('Forked process will force module type as', $p(force));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/* Run our script in a _separate_ process */
|
|
63
|
+
const child = fork(script, {
|
|
64
|
+
stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
|
|
65
|
+
serialization: 'advanced',
|
|
66
|
+
env,
|
|
67
|
+
});
|
|
68
|
+
/* Do some logging... */
|
|
69
|
+
context.log.info('Running', $p(script), $gry(`(pid=${child.pid})`));
|
|
70
|
+
/* Return a promise from the child process events */
|
|
71
|
+
let done = false; // this will be fixed up in "finally" below
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
let response = undefined;
|
|
74
|
+
child.on('error', (error) => {
|
|
75
|
+
context.log.error('Forked plug process error', error);
|
|
76
|
+
return done || reject(BuildFailure.fail());
|
|
77
|
+
});
|
|
78
|
+
child.on('message', (message) => {
|
|
79
|
+
if ('logLevel' in message) {
|
|
80
|
+
const { logLevel, taskName, lines } = message;
|
|
81
|
+
lines.forEach((line) => {
|
|
82
|
+
// this is _a hack_, as we want to reuse the indent and prefix of
|
|
83
|
+
// the current log, but the task name from the forked plug!!!
|
|
84
|
+
context.log._emit(logLevel, [line], taskName);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
context.log.debug('Message from forked plug process with PID', child.pid, message);
|
|
89
|
+
response = message;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
child.on('exit', (code, signal) => {
|
|
93
|
+
if (signal) {
|
|
94
|
+
context.log.error(`Forked plug process exited with signal ${signal}`, $gry(`(pid=${child.pid})`));
|
|
95
|
+
return done || reject(BuildFailure.fail());
|
|
96
|
+
}
|
|
97
|
+
else if (code !== 0) {
|
|
98
|
+
context.log.error(`Forked plug process exited with code ${code}`, $gry(`(pid=${child.pid})`));
|
|
99
|
+
return done || reject(BuildFailure.fail());
|
|
100
|
+
}
|
|
101
|
+
else if (!response) {
|
|
102
|
+
context.log.error('Forked plug process exited with no result', $gry(`(pid=${child.pid})`));
|
|
103
|
+
return done || reject(BuildFailure.fail());
|
|
104
|
+
}
|
|
105
|
+
else if (response.failed) {
|
|
106
|
+
// definitely logged on the child side
|
|
107
|
+
return done || reject(BuildFailure.fail());
|
|
108
|
+
}
|
|
109
|
+
/* We definitely have a successful result! */
|
|
110
|
+
return done || resolve(response.filesDir && response.filesList ?
|
|
111
|
+
Files.builder(response.filesDir).add(...response.filesList).build() :
|
|
112
|
+
undefined);
|
|
113
|
+
});
|
|
114
|
+
/* After the handlers have been setup, send the message */
|
|
115
|
+
child.on('spawn', () => {
|
|
116
|
+
try {
|
|
117
|
+
/* Ignore the return value from `child.send(...)` here. The docs allow
|
|
118
|
+
* it to return `false` _when the backlog of unsent messages exceeds a
|
|
119
|
+
* threshold that makes it unwise to send more_. Bascially, on large
|
|
120
|
+
* file lists, this returns `false`... The only thing we can do is to
|
|
121
|
+
* handle any callback error, and hope for the best!
|
|
122
|
+
*/
|
|
123
|
+
child.send(request, (error) => {
|
|
124
|
+
if (error) {
|
|
125
|
+
context.log.error('Error sending message to forked plug process (callback failure)', error);
|
|
126
|
+
reject(BuildFailure.fail());
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
context.log.error('Error sending message to forked plug process (exception caught)', error);
|
|
132
|
+
reject(BuildFailure.fail());
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}).finally(() => done = true);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/* ========================================================================== *
|
|
139
|
+
* CHILD PROCESS SIDE OF THE FORKING PLUG IMPLEMENTATION *
|
|
140
|
+
* ========================================================================== */
|
|
141
|
+
/*
|
|
142
|
+
* If we were started as ourselves (fork.js) and we have an IPC channel to the
|
|
143
|
+
* parent process, we can safely assume we need to run our plug... So we wait
|
|
144
|
+
* for the message and respond once the plug returns _something_!
|
|
145
|
+
*/
|
|
146
|
+
if ((process.argv[1] === requireFilename(import.meta.filename)) && (process.send)) {
|
|
147
|
+
/* Save the original console, we'll replace it on "message" */
|
|
148
|
+
const originalConsole = globalThis.console;
|
|
149
|
+
/* Unhandled exceptions and graceful termination */
|
|
150
|
+
process.on('uncaughtException', (error, origin) => {
|
|
151
|
+
originalConsole.error($red('\n= UNCAUGHT EXCEPTION ========================================='), `\nError (${origin}):`, error, `\nNode.js ${process.version} (pid=${process.pid})\n`);
|
|
152
|
+
process.nextTick(() => process.exit(3));
|
|
153
|
+
});
|
|
154
|
+
/* If we haven't processed our message in 5 seconds, fail _badly_ */
|
|
155
|
+
const timeout = setTimeout(() => {
|
|
156
|
+
originalConsole.error('Fork not initialized in 5 seconds');
|
|
157
|
+
process.exit(2);
|
|
158
|
+
}, 5000).unref();
|
|
159
|
+
/* Await our message to initialize and run the plug */
|
|
160
|
+
process.on('message', (message) => {
|
|
161
|
+
clearTimeout(timeout);
|
|
162
|
+
const { scriptFile, exportName, constructorArgs, taskName, buildFile, filesDir, filesList, logIndent, } = message;
|
|
163
|
+
/* Before anything else, capture logs! */
|
|
164
|
+
emit.emitter = emitForked; // replace the log emitter...
|
|
165
|
+
/* Create a couple of writers for our fake "stdout" and "stderr" */
|
|
166
|
+
const makeWritable = (level) => new class extends Writable {
|
|
167
|
+
_write(chunk, _, callback) {
|
|
168
|
+
const string = chunk.toString();
|
|
169
|
+
const message = string.endsWith('\n') ? string.slice(0, -1) : string;
|
|
170
|
+
emit.emitter({ level, taskName }, [message]);
|
|
171
|
+
callback();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/* Replace the console with our own sending messages as logs */
|
|
175
|
+
globalThis.console = new Console(makeWritable(NOTICE), makeWritable(WARN));
|
|
176
|
+
/* First of all, our plug context */
|
|
177
|
+
const context = new Context(buildFile, taskName);
|
|
178
|
+
context.log.indent = logIndent;
|
|
179
|
+
context.log.debug('Message from parent process for PID', process.pid, message);
|
|
180
|
+
/* Contextualize this run, and go! */
|
|
181
|
+
process.exitCode = 0;
|
|
182
|
+
const result = runAsync(context, async () => {
|
|
183
|
+
/* Check that we have a proper script file name */
|
|
184
|
+
assert(resolveFile(scriptFile), `Script file ${$p(scriptFile)} not found`);
|
|
185
|
+
const script = await import(__rewriteRelativeImportExtension(scriptFile));
|
|
186
|
+
/* Figure out the constructor, in the "default" chain */
|
|
187
|
+
let Ctor;
|
|
188
|
+
if (exportName === 'default') {
|
|
189
|
+
Ctor = script;
|
|
190
|
+
while (Ctor && (typeof Ctor !== 'function'))
|
|
191
|
+
Ctor = Ctor.default;
|
|
192
|
+
assert(typeof Ctor === 'function', `Script ${$p(scriptFile)} does not export a default constructor`);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
Ctor = script[exportName];
|
|
196
|
+
if ((!Ctor) && (script.default))
|
|
197
|
+
Ctor = script.default[exportName];
|
|
198
|
+
assert(typeof Ctor === 'function', `Script ${$p(scriptFile)} does not export "${exportName}"`);
|
|
199
|
+
}
|
|
200
|
+
/* Create the Plug instance and our Files instance */
|
|
201
|
+
const plug = new Ctor(...constructorArgs);
|
|
202
|
+
const files = Files.builder(filesDir).add(...filesList).build();
|
|
203
|
+
/* Run and return the result */
|
|
204
|
+
return plug.pipe(files, context);
|
|
205
|
+
});
|
|
206
|
+
/* The result promise generates a message back to the parent process */
|
|
207
|
+
const promise = result.then((result) => {
|
|
208
|
+
const message = result ?
|
|
209
|
+
{ failed: false, filesDir: result.directory, filesList: [...result.absolutePaths()] } :
|
|
210
|
+
{ failed: false };
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
process.send(message, (err) => err ? reject(err) : resolve());
|
|
213
|
+
});
|
|
214
|
+
}, (error) => {
|
|
215
|
+
context.log.error(error);
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
process.send({ failed: true }, (err) => err ? reject(err) : resolve());
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
/* The promise generated by `process.send()` simply triggers process exit */
|
|
221
|
+
promise.then(() => {
|
|
222
|
+
context.log.debug('Forked plug with pid', process.pid, 'exiting');
|
|
223
|
+
}, (error) => {
|
|
224
|
+
originalConsole.error('\n\nError sending message back to parent process', error);
|
|
225
|
+
process.exitCode = 1;
|
|
226
|
+
}).finally(() => {
|
|
227
|
+
process.disconnect();
|
|
228
|
+
process.exit(process.exitCode);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Install a _forking_ {@link Plug} in the {@link Pipe}, in other words
|
|
234
|
+
* execute the plug in a separate process.
|
|
235
|
+
*
|
|
236
|
+
* As a contract, if the _last non-null_ parameter of the constructor is an
|
|
237
|
+
* object and contains the key `coverageDir`, the process will be forked with
|
|
238
|
+
* the approptiately resolved `NODE_V8_COVERAGE` environment variable.
|
|
239
|
+
*
|
|
240
|
+
* Also, forking plugs require some special attention:
|
|
241
|
+
*
|
|
242
|
+
* * plug functions are not supported, only classes implementing the
|
|
243
|
+
* {@link Plug} interface can be used with this.
|
|
244
|
+
*
|
|
245
|
+
* * the class itself _MUST_ be exported as the _default_ export for the
|
|
246
|
+
* `scriptFile` specified below. This is to simplify interoperability between
|
|
247
|
+
* CommonJS and ESM modules as we use dynamic `import(...)` statements.
|
|
248
|
+
*/
|
|
249
|
+
export function installForking(plugName, scriptFile, exportName = 'default') {
|
|
250
|
+
/** Extend out our ForkingPlug below */
|
|
251
|
+
const ctor = class extends ForkingPlug {
|
|
252
|
+
constructor(...args) {
|
|
253
|
+
super(scriptFile, args, exportName);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
/** Install the plug in */
|
|
257
|
+
install(plugName, ctor);
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=fork.js.map
|
package/dist/fork.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork.js","sourceRoot":"","sources":["../src/fork.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,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AAM,mBAAY,CAAA;AAC/B,eAAO,MAAM,QAAQ,qBAAc,CAAA;AACnC,eAAO,MAAM,EAAE,eAAQ,CAAA;AACvB,eAAO,MAAM,KAAK,kBAAW,CAAA;AAC7B,eAAO,MAAM,KAAK,kBAAW,CAAA;AAC7B,eAAO,MAAM,OAAO,oBAAa,CAAA;AACjC,eAAO,MAAM,QAAQ,qBAAc,CAAA;AACnC,eAAO,MAAM,OAAO,oBAAa,CAAA;AACjC,eAAO,MAAM,KAAK,kBAAW,CAAA;AAC7B,eAAO,MAAM,IAAI,iBAAU,CAAA;AAC3B,eAAO,MAAM,IAAI,iBAAU,CAAA;AAC3B,eAAO,MAAM,MAAM,mBAAY,CAAA;AAC/B,eAAO,MAAM,KAAK,kBAAW,CAAA;AAC7B,eAAO,MAAM,MAAM,mBAAY,CAAA;AAC/B,eAAO,MAAM,MAAM,mBAAY,CAAA;AAC/B,eAAO,MAAM,KAAK,kBAAW,CAAA;AAC7B,eAAO,MAAM,MAAM,mBAAY,CAAA;AAC/B,eAAO,MAAM,OAAO,oBAAa,CAAA;AACjC,eAAO,MAAM,QAAQ,qBAAc,CAAA;AACnC,eAAO,MAAM,OAAO,oBAAa,CAAA;AACjC,eAAO,MAAM,SAAS,sBAAe,CAAA;AACrC,eAAO,MAAM,UAAU,uBAAgB,CAAA;AACvC,eAAO,MAAM,QAAQ,qBAAc,CAAA;AACnC,eAAO,MAAM,KAAK,kBAAW,CAAA;AAG7B,eAAO,MAAM,WAAW,kBAAY,CAAA"}
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import fsp from 'node:fs/promises';
|
|
3
|
+
/*
|
|
4
|
+
* I have no idea why sometimes stacks don't have a trace when coming out of
|
|
5
|
+
* the "node:fs/promises" api... There is a _stack_ property on the object
|
|
6
|
+
* but it simply includes the first line (if so), no thing further...
|
|
7
|
+
*
|
|
8
|
+
* Upon further inspection, it _seems_ this is related to some issues with the
|
|
9
|
+
* Error.captureStackTrace(...) function. If we pass a function to it as
|
|
10
|
+
* second parameter in our functions below, we end up with no stacks as well!
|
|
11
|
+
*
|
|
12
|
+
* So, for now, let's catch all errors, invoke `Error.captureStackTrace`
|
|
13
|
+
* manually without any parameter (besides the error itself), and fail with
|
|
14
|
+
* this.
|
|
15
|
+
*
|
|
16
|
+
* Hopefully, it'll get fixed, eventually, but for now let's keep this wrapper
|
|
17
|
+
* around!
|
|
18
|
+
*/
|
|
19
|
+
/* Process every entry in "node:fs/promises" */
|
|
20
|
+
const fs = Object.entries(fsp).reduce((fs, [key, val]) => {
|
|
21
|
+
if (typeof val === 'function') {
|
|
22
|
+
/* If the value is a function, wrap it! */
|
|
23
|
+
const f = function (...args) {
|
|
24
|
+
/* Call the function, and _catch_ any error */
|
|
25
|
+
return val.apply(fsp, args)
|
|
26
|
+
.catch(/* coverage ignore next*/ (error) => {
|
|
27
|
+
/* For any error caught, we fill in the stack trace */
|
|
28
|
+
Error.captureStackTrace(error);
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/* Make sure that the functions are called correctly */
|
|
33
|
+
Object.defineProperty(f, 'name', { value: key });
|
|
34
|
+
/* Assign the wrapper to our exports */
|
|
35
|
+
fs[key] = f;
|
|
36
|
+
}
|
|
37
|
+
/* Return the "reduced" exports */
|
|
38
|
+
return fs;
|
|
39
|
+
}, {});
|
|
40
|
+
/* Export all the wrappers to "node:fs/promises" individually */
|
|
41
|
+
export const access = fs.access;
|
|
42
|
+
export const copyFile = fs.copyFile;
|
|
43
|
+
export const cp = fs.cp;
|
|
44
|
+
export const open = fs.open;
|
|
45
|
+
export const opendir = fs.opendir;
|
|
46
|
+
export const rename = fs.rename;
|
|
47
|
+
export const truncate = fs.truncate;
|
|
48
|
+
export const rm = fs.rm;
|
|
49
|
+
export const rmdir = fs.rmdir;
|
|
50
|
+
export const mkdir = fs.mkdir;
|
|
51
|
+
export const readdir = fs.readdir;
|
|
52
|
+
export const readlink = fs.readlink;
|
|
53
|
+
export const symlink = fs.symlink;
|
|
54
|
+
export const lstat = fs.lstat;
|
|
55
|
+
export const stat = fs.stat;
|
|
56
|
+
export const link = fs.link;
|
|
57
|
+
export const unlink = fs.unlink;
|
|
58
|
+
export const chmod = fs.chmod;
|
|
59
|
+
export const lchmod = fs.lchmod;
|
|
60
|
+
export const lchown = fs.lchown;
|
|
61
|
+
export const chown = fs.chown;
|
|
62
|
+
export const utimes = fs.utimes;
|
|
63
|
+
export const lutimes = fs.lutimes;
|
|
64
|
+
export const realpath = fs.realpath;
|
|
65
|
+
export const mkdtemp = fs.mkdtemp;
|
|
66
|
+
export const writeFile = fs.writeFile;
|
|
67
|
+
export const appendFile = fs.appendFile;
|
|
68
|
+
export const readFile = fs.readFile;
|
|
69
|
+
export const watch = fs.watch;
|
|
70
|
+
/* Export constants from "node:fs" */
|
|
71
|
+
export const fsConstants = constants;
|
|
72
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,GAAG,MAAM,kBAAkB,CAAA;AAQlC;;;;;;;;;;;;;;;GAeG;AAEH,+CAA+C;AAC/C,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAU,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAE,GAAG,EAAE,GAAG,CAAE,EAAE,EAAE;IAChE,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,0CAA0C;QAC1C,MAAM,CAAC,GAAG,UAAS,GAAG,IAAW;YAC/B,8CAA8C;YAC9C,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC;iBACtB,KAAK,CAAC,yBAAyB,CAAC,CAAC,KAAU,EAA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,KAAK,GAAG,EAAE,CAAC,KAAK,CAAA;AAC7B,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,CAAA;AAC3B,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,CAAA;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAA;AAC/B,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAA;AAC7B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAA;AAC/B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAA;AAC/B,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAA;AAC7B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAA;AAC/B,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAA;AACjC,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAA;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAA;AACjC,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC,SAAS,CAAA;AACrC,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAA;AACvC,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAA;AACnC,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAA;AAE7B,qCAAqC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAA"}
|
package/dist/globals.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A pseudo-variable replaced by `ESBuild` resolving to either `__filename`
|
|
3
3
|
* in CJS modules, or to `import.meta.url` in ESM modules.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated As we are moving to ESM-only, this will be removed in the future.
|
|
6
|
+
* Use `import.meta.url` or `import.meta.filename` instead.
|
|
4
7
|
*/
|
|
5
8
|
declare const __fileurl: string;
|
|
9
|
+
//# sourceMappingURL=globals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,CAAC,MAAM,SAAS,EAAE,MAAM,CAAA"}
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":""}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Files } from './files';
|
|
2
|
-
import type { Pipe } from './index';
|
|
3
|
-
import type { AbsolutePath } from './paths';
|
|
4
|
-
import type { Context } from './pipe';
|
|
5
|
-
import type { RunBuildOptions } from './plugs/build';
|
|
6
|
-
import type { ExecChildOptions } from './utils/exec';
|
|
7
|
-
import type { WalkOptions } from './utils/walk';
|
|
1
|
+
import { Files } from './files.ts';
|
|
2
|
+
import type { Pipe } from './index.ts';
|
|
3
|
+
import type { AbsolutePath } from './paths.ts';
|
|
4
|
+
import type { Context } from './pipe.ts';
|
|
5
|
+
import type { RunBuildOptions } from './plugs/build.ts';
|
|
6
|
+
import type { ExecChildOptions } from './utils/exec.ts';
|
|
7
|
+
import type { WalkOptions } from './utils/walk.ts';
|
|
8
8
|
/**
|
|
9
9
|
* The {@link UsingOptions} interface defines the options for building
|
|
10
10
|
* {@link Files} instances from a static list of paths.
|
|
@@ -140,3 +140,4 @@ export declare function exec(cmd: string, ...args: [...args: string[]] | [...arg
|
|
|
140
140
|
* @params file The JSON file to parse
|
|
141
141
|
*/
|
|
142
142
|
export declare function parseJson(file: string, strict?: boolean): any;
|
|
143
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,CAAE,GAAG,MAAM,EAAE,CAAE,GAAG,IAAI,CAAA;AACrD,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,CAAE,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,CAAE,GAAG,IAAI,CAAA;AAW5E;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,KAAK,EAAE,CAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAE,GAAG,YAAY,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,CAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAE,GAAG,YAAY,GAAG,SAAS,CAGlF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,CAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAE,GAAG,YAAY,GAAG,SAAS,CAGvF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,YAAY,CAItC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAChB,GAAG,EAAE,MAAM,EACX,GAAG,IAAI,EAAE,CAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAE,GAAG,CAAE,GAAG,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,gBAAgB,CAAE,GAClF,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe,GAAG,GAAG,CA2BpE"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { BuildFailure, assert, assertPromises } from "./asserts.js";
|
|
5
|
+
import { requireContext } from "./async.js";
|
|
6
|
+
import { Files } from "./files.js";
|
|
7
|
+
import { rm } from "./fs.js";
|
|
8
|
+
import { $gry, $p, $plur, $wht, $ylw, log } from "./logging.js";
|
|
9
|
+
import { commonPath, getAbsoluteParent, getCurrentWorkingDirectory, resolveDirectory, resolveFile, } from "./paths.js";
|
|
10
|
+
import { PipeImpl } from "./pipe.js";
|
|
11
|
+
import { RunBuild } from "./plugs/build.js";
|
|
12
|
+
import { JsoncError, parseJsonc } from "./utils.js";
|
|
13
|
+
import { execChild } from "./utils/exec.js";
|
|
14
|
+
import { parseOptions } from "./utils/options.js";
|
|
15
|
+
import { walk } from "./utils/walk.js";
|
|
16
|
+
/** Return the current execution {@link Context} */
|
|
17
|
+
export function context() {
|
|
18
|
+
return requireContext();
|
|
19
|
+
}
|
|
20
|
+
/* Overload */
|
|
21
|
+
export function find(...args) {
|
|
22
|
+
const { params: globs, options } = parseOptions(args, {});
|
|
23
|
+
const context = requireContext();
|
|
24
|
+
return new PipeImpl(context, Promise.resolve().then(async () => {
|
|
25
|
+
const directory = options.directory ?
|
|
26
|
+
context.resolve(options.directory) :
|
|
27
|
+
getCurrentWorkingDirectory();
|
|
28
|
+
const builder = Files.builder(directory);
|
|
29
|
+
for await (const file of walk(directory, globs, options)) {
|
|
30
|
+
builder.add(file);
|
|
31
|
+
}
|
|
32
|
+
return builder.build();
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
export async function invokeBuild(buildFile, tasksOrOptions, maybeOptions) {
|
|
36
|
+
const [tasks, options = {}] = typeof tasksOrOptions === 'string' ?
|
|
37
|
+
[[tasksOrOptions], maybeOptions] :
|
|
38
|
+
Array.isArray(tasksOrOptions) ?
|
|
39
|
+
[tasksOrOptions, maybeOptions] :
|
|
40
|
+
typeof tasksOrOptions === 'object' ?
|
|
41
|
+
[['default'], tasksOrOptions] :
|
|
42
|
+
[['default'], {}];
|
|
43
|
+
if (tasks.length === 0)
|
|
44
|
+
tasks.push('default');
|
|
45
|
+
const { coverageDir, forceModule, ...props } = options;
|
|
46
|
+
const forkOptions = { coverageDir, forceModule };
|
|
47
|
+
const context = requireContext();
|
|
48
|
+
const file = context.resolve(buildFile);
|
|
49
|
+
const dir = getAbsoluteParent(file);
|
|
50
|
+
const files = Files.builder(dir).add(file).build();
|
|
51
|
+
return new RunBuild(tasks, props, forkOptions)
|
|
52
|
+
.pipe(files, context)
|
|
53
|
+
.then(() => void 0);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Recursively remove the specified directory _**(use with care)**_.
|
|
57
|
+
*/
|
|
58
|
+
export async function rmrf(directory) {
|
|
59
|
+
const context = requireContext();
|
|
60
|
+
const dir = context.resolve(directory);
|
|
61
|
+
assert(dir !== getCurrentWorkingDirectory(), `Cowardly refusing to wipe current working directory ${$p(dir)}`);
|
|
62
|
+
assert(dir !== context.resolve('@'), `Cowardly refusing to wipe build file directory ${$p(dir)}`);
|
|
63
|
+
/* coverage ignore if */
|
|
64
|
+
if (!resolveDirectory(dir)) {
|
|
65
|
+
log.info('Directory', $p(dir), 'not found');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
log.notice('Removing directory', $p(dir), 'recursively');
|
|
69
|
+
await rm(dir, { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Merge the results of several {@link Pipe}s into a single one.
|
|
73
|
+
*
|
|
74
|
+
* Merging is performed _in parallel_. When serial execution is to be desired,
|
|
75
|
+
* we can merge the awaited _result_ of the {@link Pipe}.
|
|
76
|
+
*
|
|
77
|
+
* For example:
|
|
78
|
+
*
|
|
79
|
+
* ```
|
|
80
|
+
* const pipe: Pipe = merge([
|
|
81
|
+
* await this.anotherTask1(),
|
|
82
|
+
* await this.anotherTask2(),
|
|
83
|
+
* ])
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function merge(pipes) {
|
|
87
|
+
const context = requireContext();
|
|
88
|
+
return new PipeImpl(context, Promise.resolve().then(async () => {
|
|
89
|
+
// No pipes? Just send off an empty pipe...
|
|
90
|
+
if (pipes.length === 0)
|
|
91
|
+
return new Files();
|
|
92
|
+
// Await for all pipes / files / files promises
|
|
93
|
+
const awaited = await assertPromises(pipes);
|
|
94
|
+
const results = awaited.filter((result) => result.length);
|
|
95
|
+
// No files in anything to be merged? Again send off an empty pipe...
|
|
96
|
+
if (results.length === 0)
|
|
97
|
+
return new Files();
|
|
98
|
+
// Find the common directory between all the Files instances
|
|
99
|
+
const [firstDir, ...otherDirs] = results.map((f) => f.directory);
|
|
100
|
+
const directory = commonPath(firstDir, ...otherDirs);
|
|
101
|
+
// Build our new files instance merging all the results
|
|
102
|
+
return Files.builder(directory).merge(...results).build();
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create an empty _no-op_ {@link Pipe}.
|
|
107
|
+
*
|
|
108
|
+
* This is useful when creating tasks with conditional pipes and returning the
|
|
109
|
+
* correct type, for example:
|
|
110
|
+
*
|
|
111
|
+
* ```
|
|
112
|
+
* if (someCondition) {
|
|
113
|
+
* return find(...).pipe(...)
|
|
114
|
+
* } else {
|
|
115
|
+
* return noop()
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export function noop() {
|
|
120
|
+
const context = requireContext();
|
|
121
|
+
return new PipeImpl(context, Promise.resolve(new Files()));
|
|
122
|
+
}
|
|
123
|
+
export function using(...args) {
|
|
124
|
+
const { options, params } = parseOptions(args, { directory: '.' });
|
|
125
|
+
const context = requireContext();
|
|
126
|
+
const directory = context.resolve(options.directory);
|
|
127
|
+
const files = Files.builder(directory).add(...params).build();
|
|
128
|
+
return new PipeImpl(context, Promise.resolve(files));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Resolve a (set of) path(s) into an {@link AbsolutePath}.
|
|
132
|
+
*
|
|
133
|
+
* If the path (or first component thereof) starts with `@...`, then the
|
|
134
|
+
* resolved path will be relative to the directory containing the build file
|
|
135
|
+
* where the current task was defined, otherwise it will be relative to the
|
|
136
|
+
* current working directory.
|
|
137
|
+
*/
|
|
138
|
+
export function resolve(...paths) {
|
|
139
|
+
return requireContext().resolve(...paths);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Return an absolute path of the file if it exist on disk.
|
|
143
|
+
*
|
|
144
|
+
* See the comments on {@link resolve} to understand how paths are resolved.
|
|
145
|
+
*/
|
|
146
|
+
export function isFile(...paths) {
|
|
147
|
+
const path = requireContext().resolve(...paths);
|
|
148
|
+
return resolveFile(path);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Return an absolute path of the directory if it exist on disk.
|
|
152
|
+
*
|
|
153
|
+
* See the comments on {@link resolve} to understand how paths are resolved.
|
|
154
|
+
*/
|
|
155
|
+
export function isDirectory(...paths) {
|
|
156
|
+
const path = requireContext().resolve(...paths);
|
|
157
|
+
return resolveDirectory(path);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a temporary directory and return its {@link AbsolutePath}.
|
|
161
|
+
*
|
|
162
|
+
* The directory will be rooted in `/tmp` or wherever `os.tmpdir()` decides.
|
|
163
|
+
*/
|
|
164
|
+
export function mkdtemp() {
|
|
165
|
+
const prefix = join(tmpdir(), 'plugjs-');
|
|
166
|
+
const path = mkdtempSync(prefix);
|
|
167
|
+
return resolve(path);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Execute a command and await for its result from within a task.
|
|
171
|
+
*
|
|
172
|
+
* For example:
|
|
173
|
+
*
|
|
174
|
+
* ```
|
|
175
|
+
* import { exec } from '@plugjs/plugjs'
|
|
176
|
+
*
|
|
177
|
+
* export default build({
|
|
178
|
+
* async runme() {
|
|
179
|
+
* await exec('ls', '-la', '/')
|
|
180
|
+
* // or similarly letting the shell interpret the command
|
|
181
|
+
* await exec('ls -la /', { shell: true })
|
|
182
|
+
* },
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @param cmd The command to execute
|
|
187
|
+
* @param args Any additional argument for the command to execute
|
|
188
|
+
* @param options Extra {@link ExecChildOptions | options} for process execution
|
|
189
|
+
*/
|
|
190
|
+
export function exec(cmd, ...args) {
|
|
191
|
+
const { params, options } = parseOptions(args);
|
|
192
|
+
return execChild(cmd, params, options, requireContext());
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Read and parse a JSON/JSONC file, throwing an error if not found.
|
|
196
|
+
*
|
|
197
|
+
* @params file The JSON file to parse
|
|
198
|
+
*/
|
|
199
|
+
export function parseJson(file, strict = false) {
|
|
200
|
+
const jsonFile = requireContext().resolve(file);
|
|
201
|
+
let jsonText;
|
|
202
|
+
try {
|
|
203
|
+
jsonText = readFileSync(jsonFile, 'utf-8');
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (error.code === 'ENOENT')
|
|
207
|
+
log.fail(`File ${$p(jsonFile)} not found`);
|
|
208
|
+
if (error.code === 'EACCES')
|
|
209
|
+
log.fail(`File ${$p(jsonFile)} can not be accessed`);
|
|
210
|
+
log.fail(`Error reading ${$p(jsonFile)}`, error);
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
return parseJsonc(jsonText, {
|
|
214
|
+
disallowComments: strict,
|
|
215
|
+
allowTrailingComma: !strict,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (error instanceof JsoncError) {
|
|
220
|
+
const errors = error.errors;
|
|
221
|
+
log.error(`Found ${$plur(errors.length, 'error', 'errors')} parsing ${$p(jsonFile)}`);
|
|
222
|
+
for (const e of errors) {
|
|
223
|
+
log.error(` ${$wht(e.code)} ${$gry('at line')} ${$ylw(e.line)}${$gry(', column')} ${$ylw(e.column)}`);
|
|
224
|
+
}
|
|
225
|
+
throw new BuildFailure();
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=helpers.js.map
|