@plugjs/plug 0.2.6 → 0.3.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/cli/plug.mjs +3 -15
- package/cli/ts-loader.mjs +1 -1
- package/cli/tsrun.mjs +1104 -36
- package/dist/asserts.cjs +4 -0
- package/dist/asserts.cjs.map +1 -1
- package/dist/asserts.mjs +4 -0
- package/dist/asserts.mjs.map +1 -1
- package/dist/fork.cjs +8 -5
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.mjs +8 -5
- package/dist/fork.mjs.map +1 -1
- package/dist/fs.cjs +1 -1
- package/dist/helpers.cjs +20 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.mjs +20 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +8 -8
- package/dist/logging/emit.cjs +4 -7
- package/dist/logging/emit.cjs.map +1 -1
- package/dist/logging/emit.mjs +4 -7
- package/dist/logging/emit.mjs.map +1 -1
- package/dist/logging/github.cjs +63 -0
- package/dist/logging/github.cjs.map +6 -0
- package/dist/logging/github.d.ts +13 -0
- package/dist/logging/github.mjs +38 -0
- package/dist/logging/github.mjs.map +6 -0
- package/dist/logging/options.cjs +20 -3
- package/dist/logging/options.cjs.map +1 -1
- package/dist/logging/options.d.ts +9 -2
- package/dist/logging/options.mjs +20 -3
- package/dist/logging/options.mjs.map +1 -1
- package/dist/logging/report.cjs +25 -3
- package/dist/logging/report.cjs.map +1 -1
- package/dist/logging/report.mjs +26 -4
- package/dist/logging/report.mjs.map +1 -1
- package/dist/logging.cjs +1 -0
- package/dist/logging.cjs.map +1 -1
- package/dist/logging.d.ts +1 -0
- package/dist/logging.mjs +1 -0
- package/dist/logging.mjs.map +1 -1
- package/dist/plugs/debug.mjs +18 -28
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/plugs/edit.mjs +13 -23
- package/dist/plugs/edit.mjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.cjs +1 -1
- package/dist/plugs/rmf.mjs +14 -24
- package/dist/plugs/rmf.mjs.map +1 -1
- package/dist/utils/exec.cjs +22 -15
- package/dist/utils/exec.cjs.map +2 -2
- package/dist/utils/exec.mjs +21 -14
- package/dist/utils/exec.mjs.map +1 -1
- package/dist/utils/match.cjs +1 -1
- package/extra/plug.mts +6 -3
- package/extra/tsrun.mts +91 -28
- package/extra/utils.ts +0 -18
- package/package.json +4 -5
- package/src/asserts.ts +7 -0
- package/src/fork.ts +10 -5
- package/src/helpers.ts +24 -1
- package/src/logging/emit.ts +2 -7
- package/src/logging/github.ts +71 -0
- package/src/logging/options.ts +29 -4
- package/src/logging/report.ts +40 -6
- package/src/logging.ts +1 -0
- package/src/utils/exec.ts +29 -18
package/dist/utils/exec.cjs
CHANGED
|
@@ -33,8 +33,8 @@ __export(exec_exports, {
|
|
|
33
33
|
execChild: () => execChild
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(exec_exports);
|
|
36
|
-
var import_node_path = __toESM(require("node:path"));
|
|
37
|
-
var import_node_readline = __toESM(require("node:readline"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_node_readline = __toESM(require("node:readline"), 1);
|
|
38
38
|
var import_node_child_process = require("node:child_process");
|
|
39
39
|
var import_asserts = require("../asserts.cjs");
|
|
40
40
|
var import_logging = require("../logging.cjs");
|
|
@@ -67,29 +67,36 @@ async function execChild(cmd, args, options = {}, context) {
|
|
|
67
67
|
if (extraPath)
|
|
68
68
|
childPaths.push(extraPath);
|
|
69
69
|
const PATH = childPaths.join(import_node_path.default.delimiter);
|
|
70
|
-
const logForkEnv = import_logging.logOptions.forkEnv(context.taskName);
|
|
70
|
+
const logForkEnv = import_logging.logOptions.forkEnv(context.taskName, 4);
|
|
71
71
|
const childEnv = { ...process.env, ...env, ...logForkEnv, PATH };
|
|
72
72
|
if (coverageDir)
|
|
73
73
|
childEnv.NODE_V8_COVERAGE = context.resolve(coverageDir);
|
|
74
74
|
const childOptions = {
|
|
75
75
|
...extraOptions,
|
|
76
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
76
|
+
stdio: ["ignore", "pipe", "pipe", "ipc", "pipe"],
|
|
77
77
|
cwd: childCwd,
|
|
78
78
|
env: childEnv,
|
|
79
79
|
shell
|
|
80
80
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
context.log.info("Executing", [cmd, ...args]);
|
|
84
|
-
context.log.info("Execution options", childOptions);
|
|
81
|
+
context.log.info(fork ? "Forking" : "Executing", [cmd, ...args]);
|
|
82
|
+
context.log.debug("Child process options", childOptions);
|
|
85
83
|
const child = fork ? (0, import_node_child_process.fork)(cmd, args, childOptions) : (0, import_node_child_process.spawn)(cmd, args, childOptions);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
try {
|
|
85
|
+
context.log.info("Child process PID", child.pid);
|
|
86
|
+
if (child.stdout) {
|
|
87
|
+
const out = import_node_readline.default.createInterface(child.stdout);
|
|
88
|
+
out.on("line", (line) => context.log.notice(line || "\xA0"));
|
|
89
|
+
}
|
|
90
|
+
if (child.stderr) {
|
|
91
|
+
const err = import_node_readline.default.createInterface(child.stderr);
|
|
92
|
+
err.on("line", (line) => context.log.warn(line || "\xA0"));
|
|
93
|
+
}
|
|
94
|
+
if (child.stdio[4]) {
|
|
95
|
+
child.stdio[4].on("data", (data) => import_logging.logOptions.output.write(data));
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
child.kill();
|
|
99
|
+
throw error;
|
|
93
100
|
}
|
|
94
101
|
return new Promise((resolve, reject) => {
|
|
95
102
|
child.on("error", (error) => reject(error));
|
package/dist/utils/exec.cjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/exec.ts"],
|
|
4
|
-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AO,OAAO,4BAAa,YAAY,kCAAkC,MAAM,CAAC;AAC1F,aAAO,4BAAa,YAAY,4CAA4C,CAAC;AAAA,IAC/E,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
5
|
+
"names": ["path", "forkProcess", "spawnProcess", "readline"]
|
|
6
6
|
}
|
package/dist/utils/exec.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// utils/exec.ts
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import readline from "node:readline";
|
|
4
4
|
import { fork as forkProcess, spawn as spawnProcess } from "node:child_process";
|
|
5
5
|
import { assert, BuildFailure } from "../asserts.mjs";
|
|
6
6
|
import { $p, logOptions } from "../logging.mjs";
|
|
@@ -33,29 +33,36 @@ async function execChild(cmd, args, options = {}, context) {
|
|
|
33
33
|
if (extraPath)
|
|
34
34
|
childPaths.push(extraPath);
|
|
35
35
|
const PATH = childPaths.join(path.delimiter);
|
|
36
|
-
const logForkEnv = logOptions.forkEnv(context.taskName);
|
|
36
|
+
const logForkEnv = logOptions.forkEnv(context.taskName, 4);
|
|
37
37
|
const childEnv = { ...process.env, ...env, ...logForkEnv, PATH };
|
|
38
38
|
if (coverageDir)
|
|
39
39
|
childEnv.NODE_V8_COVERAGE = context.resolve(coverageDir);
|
|
40
40
|
const childOptions = {
|
|
41
41
|
...extraOptions,
|
|
42
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
42
|
+
stdio: ["ignore", "pipe", "pipe", "ipc", "pipe"],
|
|
43
43
|
cwd: childCwd,
|
|
44
44
|
env: childEnv,
|
|
45
45
|
shell
|
|
46
46
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
context.log.info("Executing", [cmd, ...args]);
|
|
50
|
-
context.log.info("Execution options", childOptions);
|
|
47
|
+
context.log.info(fork ? "Forking" : "Executing", [cmd, ...args]);
|
|
48
|
+
context.log.debug("Child process options", childOptions);
|
|
51
49
|
const child = fork ? forkProcess(cmd, args, childOptions) : spawnProcess(cmd, args, childOptions);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
try {
|
|
51
|
+
context.log.info("Child process PID", child.pid);
|
|
52
|
+
if (child.stdout) {
|
|
53
|
+
const out = readline.createInterface(child.stdout);
|
|
54
|
+
out.on("line", (line) => context.log.notice(line || "\xA0"));
|
|
55
|
+
}
|
|
56
|
+
if (child.stderr) {
|
|
57
|
+
const err = readline.createInterface(child.stderr);
|
|
58
|
+
err.on("line", (line) => context.log.warn(line || "\xA0"));
|
|
59
|
+
}
|
|
60
|
+
if (child.stdio[4]) {
|
|
61
|
+
child.stdio[4].on("data", (data) => logOptions.output.write(data));
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
child.kill();
|
|
65
|
+
throw error;
|
|
59
66
|
}
|
|
60
67
|
return new Promise((resolve, reject) => {
|
|
61
68
|
child.on("error", (error) => reject(error));
|
package/dist/utils/exec.mjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/exec.ts"],
|
|
4
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB,OAAO,
|
|
4
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,OAAO,cAAc;AACrB,SAAS,QAAQ,aAAa,SAAS,oBAAoB;AAE3D,SAAS,QAAQ,oBAAoB;AACrC,SAAS,IAAI,kBAAkB;AAC/B,SAAS,4BAA4B,wBAAwB;AAoB7D,eAAsB,UAClB,KACA,MACA,UAA4B,CAAC,GAC7B,SACa;AACf,QAAM;AAAA,IACJ,MAAM,CAAC;AAAA;AAAA,IACP,OAAO;AAAA;AAAA,IACP,QAAQ;AAAA;AAAA,IACR,MAAM;AAAA;AAAA,IACN;AAAA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AAEJ,QAAM,WAAW,MAAM,QAAQ,QAAQ,G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AI,MAAM,QAAQ;AAChB,YAAM,MAAM,SAAS,gBAAgB,MAAM,MAAM;AACjD,UAAI,GAAG,QAAQ,CAAC,SAAS,QAAQ,IAAI,KAAK,QAAO,MAAQ,CAAC;AAAA,IAC5D;AAGA,QAAI,MAAM,MAAM,CAAC,GAAG;AAClB,YAAM,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,WAAW,OAAO,MAAM,IAAI,CAAC;AAAA,IACnE;AAAA,EACF,SAAS,OAAP;AAEA,UAAM,KAAK;AACX,UAAM;AAAA,EACR;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,aAAa,YAAY,oCAAoC,QAAQ,CAAC;AAChG,UAAI;AAAM,eAAO,OAAO,aAAa,YAAY,kCAAkC,MAAM,CAAC;AAC1F,aAAO,aAAa,YAAY,4CAA4C,CAAC;AAAA,IAC/E,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/utils/match.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(match_exports, {
|
|
|
33
33
|
match: () => match
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(match_exports);
|
|
36
|
-
var import_picomatch = __toESM(require("picomatch"));
|
|
36
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
37
37
|
function match(globs, options = {}) {
|
|
38
38
|
return (0, import_picomatch.default)([...globs], {
|
|
39
39
|
basename: false,
|
package/extra/plug.mts
CHANGED
|
@@ -6,11 +6,14 @@ import _path from 'node:path'
|
|
|
6
6
|
|
|
7
7
|
import _yargs from 'yargs-parser'
|
|
8
8
|
|
|
9
|
-
import { $blu, $gry, $rst, $tsk, $und, $wht, isDirectory, isFile, main
|
|
9
|
+
import { $blu, $gry, $rst, $tsk, $und, $wht, isDirectory, isFile, main } from './utils.js'
|
|
10
10
|
|
|
11
11
|
import type { BuildFailure } from '../src/asserts.js'
|
|
12
12
|
import type { Build } from '../src/index.js'
|
|
13
13
|
|
|
14
|
+
/** Version injected by esbuild */
|
|
15
|
+
declare const __version: string
|
|
16
|
+
|
|
14
17
|
/* ========================================================================== *
|
|
15
18
|
* ========================================================================== *
|
|
16
19
|
* BUILD INSPECTION *
|
|
@@ -123,7 +126,7 @@ export function parseCommandLine(args: string[]): CommandLineOptions {
|
|
|
123
126
|
help = !! value
|
|
124
127
|
break
|
|
125
128
|
case 'version':
|
|
126
|
-
console.log(`v${
|
|
129
|
+
console.log(`v${__version}`)
|
|
127
130
|
process.exit(0)
|
|
128
131
|
break
|
|
129
132
|
default:
|
|
@@ -151,7 +154,7 @@ export function parseCommandLine(args: string[]): CommandLineOptions {
|
|
|
151
154
|
${$wht}-c --colors${$rst} Force colorful output (use "--no-colors" to force plain text)
|
|
152
155
|
${$wht}-l --list${$rst} Only list the tasks defined by the build, nothing more!
|
|
153
156
|
${$wht}-h --help${$rst} Help! You're reading it now!
|
|
154
|
-
${$wht} --version${$rst} Version! This one: ${
|
|
157
|
+
${$wht} --version${$rst} Version! This one: ${__version}!
|
|
155
158
|
|
|
156
159
|
${$blu}${$und}Properties:${$rst}
|
|
157
160
|
|
package/extra/tsrun.mts
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
4
|
import _path from 'node:path'
|
|
5
|
+
import _repl from 'node:repl'
|
|
6
|
+
import _module from 'node:module'
|
|
5
7
|
|
|
6
|
-
import
|
|
8
|
+
import _yargs from 'yargs-parser'
|
|
9
|
+
|
|
10
|
+
import { $blu, $gry, $rst, $und, $wht, main } from './utils.js'
|
|
11
|
+
|
|
12
|
+
/** Version injected by esbuild */
|
|
13
|
+
declare const __version: string
|
|
7
14
|
|
|
8
15
|
/** Our minimalistic help */
|
|
9
16
|
function help(): never {
|
|
@@ -13,8 +20,10 @@ function help(): never {
|
|
|
13
20
|
|
|
14
21
|
${$blu}${$und}Options:${$rst}
|
|
15
22
|
|
|
16
|
-
${$wht}-h --help${$rst}
|
|
17
|
-
${$wht}-v --version${$rst}
|
|
23
|
+
${$wht}-h --help ${$rst} Help! You're reading it now!
|
|
24
|
+
${$wht}-v --version ${$rst} Version! This one: ${__version}!
|
|
25
|
+
${$wht}-e --eval ${$rst} Evaluate the script
|
|
26
|
+
${$wht}-p --print ${$rst} Evaluate the script and print the result
|
|
18
27
|
${$wht} --force-esm${$rst} Force transpilation of ".ts" files to EcmaScript modules
|
|
19
28
|
${$wht} --force-cjs${$rst} Force transpilation of ".ts" files to CommonJS modules
|
|
20
29
|
|
|
@@ -31,34 +40,88 @@ function help(): never {
|
|
|
31
40
|
|
|
32
41
|
/** Process the command line */
|
|
33
42
|
main((args: string[]): void => {
|
|
34
|
-
let
|
|
35
|
-
let
|
|
43
|
+
let _script: string | undefined
|
|
44
|
+
let _scriptArgs: string[] = []
|
|
45
|
+
let _print: boolean = false
|
|
46
|
+
let _eval: boolean = false
|
|
47
|
+
|
|
48
|
+
/* Yargs-parse our arguments */
|
|
49
|
+
const parsed = _yargs(args, {
|
|
50
|
+
configuration: {
|
|
51
|
+
'camel-case-expansion': false,
|
|
52
|
+
'strip-aliased': true,
|
|
53
|
+
'strip-dashed': true,
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
alias: {
|
|
57
|
+
'version': [ 'v' ],
|
|
58
|
+
'help': [ 'h' ],
|
|
59
|
+
'eval': [ 'e' ],
|
|
60
|
+
'print': [ 'p' ],
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
boolean: [ 'help', 'eval', 'print', 'force-esm', 'version', 'force-cjs' ],
|
|
64
|
+
})
|
|
36
65
|
|
|
37
66
|
// Parse options, leaving script and scriptArgs with our code to run
|
|
38
|
-
for (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
for (const [ key, value ] of Object.entries(parsed)) {
|
|
68
|
+
switch (key) {
|
|
69
|
+
case '_': // extra arguments
|
|
70
|
+
[ _script, ..._scriptArgs ] = value
|
|
71
|
+
break
|
|
72
|
+
case 'help': // help screen
|
|
73
|
+
help()
|
|
74
|
+
break
|
|
75
|
+
case 'version': // version dump
|
|
76
|
+
console.log(`v${__version}`)
|
|
77
|
+
process.exit(0)
|
|
78
|
+
break
|
|
79
|
+
case 'eval': // eval script
|
|
80
|
+
_eval = value
|
|
81
|
+
break
|
|
82
|
+
case 'print': // eval script and print return value
|
|
83
|
+
_print = true
|
|
84
|
+
_eval = true
|
|
85
|
+
break
|
|
50
86
|
}
|
|
51
|
-
|
|
52
|
-
([ script, ...scriptArgs ] = args.slice(i))
|
|
53
|
-
break
|
|
54
87
|
}
|
|
55
88
|
|
|
56
|
-
//
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
// Start the repl or run the script?
|
|
90
|
+
if (! _script) {
|
|
91
|
+
// No script? Then repl
|
|
92
|
+
console.log(`Welcome to Node.js ${process.version} (tsrun v${__version}).`)
|
|
93
|
+
console.log('Type ".help" for more information.')
|
|
94
|
+
_repl.start()
|
|
95
|
+
} else if (_eval) {
|
|
96
|
+
// If we are evaluating a script, we need to use some node internals to do
|
|
97
|
+
// all the tricks to run this... We a fake script running the code to
|
|
98
|
+
// evaluate, instrumenting "globalThis" with all required vars and modules
|
|
99
|
+
const script = `
|
|
100
|
+
globalThis.module = module;
|
|
101
|
+
globalThis.require = require;
|
|
102
|
+
globalThis.exports = exports;
|
|
103
|
+
globalThis.__dirname = __dirname;
|
|
104
|
+
globalThis.__filename = __filename;
|
|
105
|
+
|
|
106
|
+
for (const module of require('repl').builtinModules) {
|
|
107
|
+
if (module.indexOf('/') >= 0) continue;
|
|
108
|
+
if (Object.hasOwn(globalThis, module)) continue;
|
|
109
|
+
Object.defineProperty(globalThis, module, { get: () => require(module) });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return require('node:vm').runInThisContext(${JSON.stringify(_script)}, '[eval]')
|
|
113
|
+
`
|
|
114
|
+
|
|
115
|
+
// Use the Node internal "Module._compile" to compile and run our script
|
|
116
|
+
const result = (new _module('[eval]') as any)._compile(script, '[eval]')
|
|
117
|
+
|
|
118
|
+
// If we need to print, then let's do it!
|
|
119
|
+
if (_print) console.log(result)
|
|
120
|
+
} else {
|
|
121
|
+
// Resolve the _full_ path of the script, and tweak our process.argv
|
|
122
|
+
// arguments, them simply import the script and let Node do its thing...
|
|
123
|
+
_script = _path.resolve(process.cwd(), _script)
|
|
124
|
+
process.argv = [ process.argv0, _script, ..._scriptArgs ]
|
|
125
|
+
import(_script)
|
|
126
|
+
}
|
|
64
127
|
})
|
package/extra/utils.ts
CHANGED
|
@@ -17,24 +17,6 @@ export const $wht = process.stdout.isTTY ? '\u001b[1;38;5;255m' : '' // full-bri
|
|
|
17
17
|
export const $tsk = process.stdout.isTTY ? '\u001b[38;5;141m' : '' // the color for tasks (purple)
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
/* ========================================================================== *
|
|
21
|
-
* PACKAGE VERSION *
|
|
22
|
-
* ========================================================================== */
|
|
23
|
-
|
|
24
|
-
export function version(): string {
|
|
25
|
-
const debug = _util.debuglog('plug:cli')
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const thisFile = _url.fileURLToPath(import.meta.url)
|
|
29
|
-
const packageFile = _path.resolve(thisFile, '..', '..', 'package.json')
|
|
30
|
-
const packageData = _fs.readFileSync(packageFile, 'utf-8')
|
|
31
|
-
return JSON.parse(packageData).version || '(unknown)'
|
|
32
|
-
} catch (error) {
|
|
33
|
-
debug('Error parsing version:', error)
|
|
34
|
-
return '(error)'
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
20
|
/* ========================================================================== *
|
|
39
21
|
* TS LOADER FORCE TYPE *
|
|
40
22
|
* ========================================================================== */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugjs/plug",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -105,13 +105,12 @@
|
|
|
105
105
|
"license": "Apache-2.0",
|
|
106
106
|
"dependencies": {
|
|
107
107
|
"@types/node": "<19",
|
|
108
|
-
"typescript": "^4.9.5",
|
|
109
108
|
"picomatch": "^2.3.1",
|
|
110
|
-
"esbuild": "^0.17.
|
|
109
|
+
"esbuild": "^0.17.12"
|
|
111
110
|
},
|
|
112
111
|
"devDependencies": {
|
|
113
|
-
"@types/yargs-parser": "^21.0.0",
|
|
114
112
|
"@types/picomatch": "^2.3.0",
|
|
113
|
+
"@types/yargs-parser": "^21.0.0",
|
|
115
114
|
"yargs-parser": "^21.1.1"
|
|
116
115
|
},
|
|
117
116
|
"files": [
|
package/src/asserts.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* BUILD FAILURES *
|
|
3
3
|
* ========================================================================== */
|
|
4
4
|
|
|
5
|
+
import { githubAnnotation } from './logging/github'
|
|
6
|
+
|
|
5
7
|
/** A symbol marking {@link BuildFailure} instances */
|
|
6
8
|
const buildFailure = Symbol.for('plugjs:buildFailure')
|
|
7
9
|
|
|
@@ -18,6 +20,11 @@ export class BuildFailure extends Error {
|
|
|
18
20
|
constructor(message?: string | undefined, errors: any[] = []) {
|
|
19
21
|
super(message || '')
|
|
20
22
|
|
|
23
|
+
// Annotate this build failure in GitHub
|
|
24
|
+
if (message) {
|
|
25
|
+
githubAnnotation({ type: 'error', title: 'Build Failure' }, message)
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
/* Basic error setup: stack and errors */
|
|
22
29
|
Error.captureStackTrace(this, BuildFailure)
|
|
23
30
|
if (errors.length) this.errors = Object.freeze([ ...errors ])
|
package/src/fork.ts
CHANGED
|
@@ -62,10 +62,10 @@ export abstract class ForkingPlug implements Plug<PlugResult> {
|
|
|
62
62
|
|
|
63
63
|
/* Get _this_ filename to spawn */
|
|
64
64
|
const script = requireFilename(__fileurl)
|
|
65
|
-
context.log.debug('About to fork plug from', $p(
|
|
65
|
+
context.log.debug('About to fork plug from', $p(this._scriptFile))
|
|
66
66
|
|
|
67
67
|
/* Environment variables */
|
|
68
|
-
const env = { ...process.env, ...logOptions.forkEnv(context.taskName) }
|
|
68
|
+
const env = { ...process.env, ...logOptions.forkEnv(context.taskName, 4) }
|
|
69
69
|
|
|
70
70
|
/* Check our args (reversed) to see if the last specifies `coverageDir` */
|
|
71
71
|
for (let i = this._arguments.length - 1; i >= 0; i --) {
|
|
@@ -80,10 +80,15 @@ export abstract class ForkingPlug implements Plug<PlugResult> {
|
|
|
80
80
|
|
|
81
81
|
/* Run our script in a _separate_ process */
|
|
82
82
|
const child = fork(script, {
|
|
83
|
-
stdio: [ 'ignore', 'inherit', 'inherit', 'ipc' ],
|
|
83
|
+
stdio: [ 'ignore', 'inherit', 'inherit', 'ipc', 'pipe' ],
|
|
84
84
|
env,
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
+
/* Pipe child logs directly to the writer */
|
|
88
|
+
if (child.stdio[4]) {
|
|
89
|
+
child.stdio[4].on('data', (data) => logOptions.output.write(data))
|
|
90
|
+
}
|
|
91
|
+
|
|
87
92
|
context.log.info('Running', $p(script), $gry(`(pid=${child.pid})`))
|
|
88
93
|
|
|
89
94
|
/* Return a promise from the child process events */
|
|
@@ -97,7 +102,7 @@ export abstract class ForkingPlug implements Plug<PlugResult> {
|
|
|
97
102
|
})
|
|
98
103
|
|
|
99
104
|
child.on('message', (message: ForkResult) => {
|
|
100
|
-
context.log.debug('Message from child process', message)
|
|
105
|
+
context.log.debug('Message from child process with PID', child.pid, message)
|
|
101
106
|
response = message
|
|
102
107
|
})
|
|
103
108
|
|
|
@@ -176,7 +181,7 @@ if ((process.argv[1] === requireFilename(__fileurl)) && (process.send)) {
|
|
|
176
181
|
|
|
177
182
|
/* First of all, our plug context */
|
|
178
183
|
const context = new Context(buildFile, taskName)
|
|
179
|
-
context.log.debug('Message from parent process', message)
|
|
184
|
+
context.log.debug('Message from parent process for PID', process.pid, message)
|
|
180
185
|
|
|
181
186
|
/* Contextualize this run, and go! */
|
|
182
187
|
const result = runAsync(context, taskName, async () => {
|
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdtempSync } from 'node:fs'
|
|
1
|
+
import { mkdtempSync, readFileSync } from 'node:fs'
|
|
2
2
|
import { tmpdir } from 'node:os'
|
|
3
3
|
import { join } from 'node:path'
|
|
4
4
|
|
|
@@ -207,3 +207,26 @@ export function exec(
|
|
|
207
207
|
const { params, options } = parseOptions(args)
|
|
208
208
|
return execChild(cmd, params, options, requireContext())
|
|
209
209
|
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Read and parse a JSON file, throwing an error if not found.
|
|
213
|
+
*
|
|
214
|
+
* @params file The JSON file to parse
|
|
215
|
+
*/
|
|
216
|
+
export function parseJson(file: string): any {
|
|
217
|
+
const jsonFile = requireContext().resolve(file)
|
|
218
|
+
let jsonText: string
|
|
219
|
+
try {
|
|
220
|
+
jsonText = readFileSync(jsonFile, 'utf-8')
|
|
221
|
+
} catch (error: any) {
|
|
222
|
+
if (error.code === 'ENOENT') log.fail(`File ${$p(jsonFile)} not found`)
|
|
223
|
+
if (error.code === 'EACCES') log.fail(`File ${$p(jsonFile)} can not be accessed`)
|
|
224
|
+
log.fail(`Error reading ${$p(jsonFile)}`, error)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
return JSON.parse(jsonText)
|
|
229
|
+
} catch (error) {
|
|
230
|
+
log.fail(`Error parsing ${$p(jsonFile)}`, error)
|
|
231
|
+
}
|
|
232
|
+
}
|
package/src/logging/emit.ts
CHANGED
|
@@ -77,10 +77,7 @@ export const emitColor: LogEmitter = (options: LogEmitterOptions, args: any[]):
|
|
|
77
77
|
|
|
78
78
|
/* Write each individual line out */
|
|
79
79
|
for (const line of message.split('\n')) {
|
|
80
|
-
_output.write(zapSpinner)
|
|
81
|
-
_output.write(linePrefix)
|
|
82
|
-
_output.write(line)
|
|
83
|
-
_output.write('\n')
|
|
80
|
+
_output.write(`${zapSpinner}${linePrefix}${line}\n`)
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
|
|
@@ -120,8 +117,6 @@ export const emitPlain: LogEmitter = (options: LogEmitterOptions, args: any[]):
|
|
|
120
117
|
|
|
121
118
|
/* Write each individual line out */
|
|
122
119
|
for (const line of message.split('\n')) {
|
|
123
|
-
_output.write(linePrefix)
|
|
124
|
-
_output.write(line)
|
|
125
|
-
_output.write('\n')
|
|
120
|
+
_output.write(`${linePrefix}${line}\n`)
|
|
126
121
|
}
|
|
127
122
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EOL } from 'node:os'
|
|
2
|
+
import { formatWithOptions } from 'node:util'
|
|
3
|
+
|
|
4
|
+
import { logOptions } from './options'
|
|
5
|
+
|
|
6
|
+
import type { AbsolutePath } from '../paths'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/* Initial values, and subscribe to changes */
|
|
10
|
+
let _colors = logOptions.colors
|
|
11
|
+
let _output = logOptions.output
|
|
12
|
+
let _inspectOptions = logOptions.inspectOptions
|
|
13
|
+
let _githubAnnotations = logOptions.githubAnnotations
|
|
14
|
+
logOptions.on('changed', (options) => {
|
|
15
|
+
_colors = options.colors
|
|
16
|
+
_output = options.output
|
|
17
|
+
_githubAnnotations = options.githubAnnotations
|
|
18
|
+
_inspectOptions = { ...options.inspectOptions, breakLength: Infinity }
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function escapeData(data: string): string {
|
|
23
|
+
return data
|
|
24
|
+
.replace(/%/g, '%25')
|
|
25
|
+
.replace(/\r/g, '%0D')
|
|
26
|
+
.replace(/\n/g, '%0A')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function escapeProp(prop: string | number): string {
|
|
30
|
+
return `${prop}`
|
|
31
|
+
.replace(/%/g, '%25')
|
|
32
|
+
.replace(/\r/g, '%0D')
|
|
33
|
+
.replace(/\n/g, '%0A')
|
|
34
|
+
.replace(/:/g, '%3A')
|
|
35
|
+
.replace(/,/g, '%2C')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GithubAnnotationType = 'warning' | 'error'
|
|
39
|
+
|
|
40
|
+
export interface GithubAnnotationOptions {
|
|
41
|
+
type: GithubAnnotationType
|
|
42
|
+
title?: string
|
|
43
|
+
file?: AbsolutePath
|
|
44
|
+
line?: number
|
|
45
|
+
endLine?: number
|
|
46
|
+
col?: number
|
|
47
|
+
endColumn?: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function githubAnnotation(type: GithubAnnotationType, message: string, ...args: any[]): void
|
|
51
|
+
export function githubAnnotation(options: GithubAnnotationOptions, message: string, ...args: any[]): void
|
|
52
|
+
|
|
53
|
+
export function githubAnnotation(options: GithubAnnotationType | GithubAnnotationOptions, ...args: any[]): void {
|
|
54
|
+
if (_colors || (! _githubAnnotations)) return
|
|
55
|
+
|
|
56
|
+
if (typeof options === 'string') options = { type: options }
|
|
57
|
+
const { type, ...parameters } = options
|
|
58
|
+
|
|
59
|
+
const attributes = Object.entries(parameters)
|
|
60
|
+
.filter(([ key, value ]) => !!(key && value))
|
|
61
|
+
.map(([ key, value ]) => `${key}=${escapeProp(value)}`)
|
|
62
|
+
.join(',')
|
|
63
|
+
|
|
64
|
+
const msg = escapeData(formatWithOptions(_inspectOptions, ...args))
|
|
65
|
+
|
|
66
|
+
if (attributes) {
|
|
67
|
+
_output.write(`::${type} ${attributes}::${msg}${EOL}`)
|
|
68
|
+
} else {
|
|
69
|
+
_output.write(`::${type}::${msg}${EOL}`)
|
|
70
|
+
}
|
|
71
|
+
}
|