@fynjs/run 1.0.1 → 1.1.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/bin/qrun.js +6 -1
- package/bin/xrun.js +1 -1
- package/dist/cli/check-global.d.ts +1 -0
- package/{cli → dist/cli}/check-global.js +3 -3
- package/dist/cli/ck.d.ts +1 -0
- package/dist/cli/cli-options.d.ts +80 -0
- package/dist/cli/cli-options.js +95 -0
- package/dist/cli/config.d.ts +7 -0
- package/dist/cli/config.js +7 -0
- package/dist/cli/env.d.ts +17 -0
- package/dist/cli/env.js +31 -0
- package/dist/cli/npm-loader.d.ts +2 -0
- package/dist/cli/npm-loader.js +43 -0
- package/dist/cli/parse-cmd-args.d.ts +34 -0
- package/dist/cli/parse-cmd-args.js +199 -0
- package/dist/cli/provider-packages.d.ts +28 -0
- package/dist/cli/provider-packages.js +62 -0
- package/dist/cli/search-up-task-file.d.ts +8 -0
- package/dist/cli/search-up-task-file.js +79 -0
- package/dist/cli/task-file.d.ts +40 -0
- package/dist/cli/task-file.js +177 -0
- package/dist/cli/ts-runner.d.ts +2 -0
- package/dist/cli/ts-runner.js +60 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/wrap-process.d.ts +10 -0
- package/dist/cli/wrap-process.js +26 -0
- package/dist/cli/xrun-main.d.ts +119 -0
- package/dist/cli/xrun-main.js +417 -0
- package/dist/cli/xrun.d.ts +2 -0
- package/{cli → dist/cli}/xrun.js +0 -1
- package/dist/lib/chalk.d.ts +2 -0
- package/{lib → dist/lib}/chalk.js +0 -1
- package/dist/lib/cli-context.d.ts +97 -0
- package/dist/lib/cli-context.js +129 -0
- package/dist/lib/defaults.d.ts +30 -0
- package/{lib → dist/lib}/defaults.js +13 -16
- package/dist/lib/gen-xqid.d.ts +2 -0
- package/dist/lib/gen-xqid.js +8 -0
- package/dist/lib/index.d.ts +3 -0
- package/{lib → dist/lib}/index.js +0 -3
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +95 -0
- package/dist/lib/my-pkg.d.ts +4 -0
- package/dist/lib/my-pkg.js +42 -0
- package/dist/lib/ns-order.d.ts +7 -0
- package/dist/lib/ns-order.js +62 -0
- package/dist/lib/print-tasks/index.d.ts +2 -0
- package/dist/lib/print-tasks/index.js +100 -0
- package/dist/lib/reporters/console.d.ts +20 -0
- package/dist/lib/reporters/console.js +119 -0
- package/dist/lib/stringify.d.ts +2 -0
- package/dist/lib/stringify.js +19 -0
- package/dist/lib/util/parse-array.d.ts +2 -0
- package/dist/lib/util/parse-array.js +5 -0
- package/dist/lib/util/task-options.d.ts +37 -0
- package/dist/lib/util/task-options.js +115 -0
- package/dist/lib/util/update-env.d.ts +1 -0
- package/dist/lib/util/update-env.js +18 -0
- package/dist/lib/xqitem.d.ts +22 -0
- package/dist/lib/xqitem.js +57 -0
- package/dist/lib/xqtor.d.ts +57 -0
- package/dist/lib/xqtor.js +704 -0
- package/dist/lib/xqtree.d.ts +11 -0
- package/dist/lib/xqtree.js +33 -0
- package/dist/lib/xrun-instance.d.ts +9 -0
- package/dist/lib/xrun-instance.js +27 -0
- package/dist/lib/xrun.d.ts +55 -0
- package/dist/lib/xrun.js +317 -0
- package/dist/lib/xtask-spec.d.ts +10 -0
- package/dist/lib/xtask-spec.js +57 -0
- package/dist/lib/xtasks.d.ts +25 -0
- package/dist/lib/xtasks.js +119 -0
- package/package.json +39 -15
- package/cli/cli-options.js +0 -98
- package/cli/config.js +0 -8
- package/cli/env.js +0 -33
- package/cli/npm-loader.js +0 -56
- package/cli/parse-cmd-args.js +0 -156
- package/cli/provider-packages.js +0 -73
- package/cli/search-up-task-file.js +0 -92
- package/cli/task-file.js +0 -192
- package/cli/ts-runner.js +0 -51
- package/cli/wrap-process.js +0 -27
- package/cli/xrun-main.js +0 -425
- package/lib/cli-context.js +0 -145
- package/lib/gen-xqid.js +0 -10
- package/lib/logger.js +0 -105
- package/lib/ns-order.js +0 -76
- package/lib/print-tasks/index.js +0 -105
- package/lib/reporters/console.js +0 -133
- package/lib/stringify.js +0 -16
- package/lib/util/parse-array.js +0 -5
- package/lib/util/update-env.js +0 -16
- package/lib/xqitem.js +0 -70
- package/lib/xqtor.js +0 -814
- package/lib/xqtree.js +0 -41
- package/lib/xrun-instance.js +0 -33
- package/lib/xrun.d.ts +0 -89
- package/lib/xrun.js +0 -344
- package/lib/xtask-spec.js +0 -63
- package/lib/xtasks.js +0 -137
- /package/{cli → dist/cli}/ck.js +0 -0
- /package/{cli → dist/cli}/usage.js +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const TYPE_NAMES = new Set(["string", "number", "boolean", "float", "int", "integer"]);
|
|
2
|
+
/**
|
|
3
|
+
* Normalize task option specifications into @fynjs/cli-args compatible OptionSpec.
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Native @fynjs/cli-args spec: { required: true, args: "<val string>", alias: "f" }
|
|
6
|
+
* - Shorthand args without value name: { args: "<string>" } -> { args: "<val string>" }
|
|
7
|
+
* - Legacy format: { require: true, type: "string", alias: "f" }
|
|
8
|
+
* - Legacy array format: { type: "array" } -> { args: "[val string..]" }
|
|
9
|
+
* - Legacy count format: { type: "count" } -> { counting: Infinity }
|
|
10
|
+
*
|
|
11
|
+
* @param {Record<string, any>} rawOpts - Raw options dictionary
|
|
12
|
+
* @returns {Record<string, any>} Normalized options dictionary
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeTaskOptions(rawOpts) {
|
|
15
|
+
if (!rawOpts || typeof rawOpts !== "object") {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const normalized = {};
|
|
19
|
+
for (const [name, spec] of Object.entries(rawOpts)) {
|
|
20
|
+
if (!spec || typeof spec !== "object") {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const opt = { ...spec };
|
|
24
|
+
// Support legacy `require: true`
|
|
25
|
+
if (opt.require !== undefined && opt.required === undefined) {
|
|
26
|
+
opt.required = Boolean(opt.require);
|
|
27
|
+
delete opt.require;
|
|
28
|
+
}
|
|
29
|
+
// Support legacy `type: "string"` / `type: "array"` / `type: "count"`
|
|
30
|
+
if (opt.type !== undefined && typeof opt.type === "string" && opt.args === undefined) {
|
|
31
|
+
if (opt.type === "count") {
|
|
32
|
+
opt.counting = opt.counting !== undefined ? opt.counting : Infinity;
|
|
33
|
+
}
|
|
34
|
+
else if (opt.type === "array") {
|
|
35
|
+
opt.args = opt.required ? "<val string..>" : "[val string..]";
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
opt.args = `<val ${opt.type}>`;
|
|
39
|
+
}
|
|
40
|
+
delete opt.type;
|
|
41
|
+
}
|
|
42
|
+
// Normalize type-only angle or square brackets: `<string>` -> `<val string>`, `<array>` -> `<val string..>`
|
|
43
|
+
if (typeof opt.args === "string") {
|
|
44
|
+
opt.args = opt.args
|
|
45
|
+
.replace(/^<([a-zA-Z]+)>$/, (_m, type) => {
|
|
46
|
+
if (type === "array") {
|
|
47
|
+
return "<val string..>";
|
|
48
|
+
}
|
|
49
|
+
return TYPE_NAMES.has(type) ? `<val ${type}>` : `<${type}>`;
|
|
50
|
+
})
|
|
51
|
+
.replace(/^\[([a-zA-Z]+)\]$/, (_m, type) => {
|
|
52
|
+
if (type === "array") {
|
|
53
|
+
return "[val string..]";
|
|
54
|
+
}
|
|
55
|
+
return TYPE_NAMES.has(type) ? `[val ${type}]` : `[${type}]`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
normalized[name] = opt;
|
|
59
|
+
}
|
|
60
|
+
return normalized;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Normalize subcommand definitions so nested options and commands are properly structured.
|
|
64
|
+
*
|
|
65
|
+
* @param {Record<string, any>} rawCmds - Raw commands dictionary
|
|
66
|
+
* @returns {Record<string, any>} Normalized commands dictionary
|
|
67
|
+
*/
|
|
68
|
+
export function normalizeTaskCommands(rawCmds) {
|
|
69
|
+
if (!rawCmds) {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
const normalized = {};
|
|
73
|
+
for (const [cmdName, cmdSpec] of Object.entries(rawCmds)) {
|
|
74
|
+
if (cmdSpec && typeof cmdSpec === "object") {
|
|
75
|
+
const sub = cmdSpec.subCommands || cmdSpec.commands;
|
|
76
|
+
const copy = { ...cmdSpec };
|
|
77
|
+
delete copy.commands;
|
|
78
|
+
if (copy.options) {
|
|
79
|
+
copy.options = normalizeTaskOptions(copy.options);
|
|
80
|
+
}
|
|
81
|
+
if (sub) {
|
|
82
|
+
copy.subCommands = normalizeTaskCommands(sub);
|
|
83
|
+
}
|
|
84
|
+
normalized[cmdName] = copy;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
normalized[cmdName] = cmdSpec;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return normalized;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Extract and normalize option specifications for a given task definition.
|
|
94
|
+
*
|
|
95
|
+
* @param {any} task - Task item or task object
|
|
96
|
+
* @returns {{ options: Record<string, any>, commands: Record<string, any>, allowUnknownOption?: boolean }}
|
|
97
|
+
*/
|
|
98
|
+
export function getTaskOptionSpec(task) {
|
|
99
|
+
const item = task?.item || task || {};
|
|
100
|
+
const cliParser = item.cliParser || task?.cliParser || {};
|
|
101
|
+
const rawOpts = item.argOpts || cliParser.options || task?.argOpts;
|
|
102
|
+
const options = normalizeTaskOptions(rawOpts);
|
|
103
|
+
const commands = normalizeTaskCommands(cliParser.subCommands || cliParser.commands);
|
|
104
|
+
const allowUnknownOption = cliParser.allowUnknownOption !== undefined
|
|
105
|
+
? cliParser.allowUnknownOption
|
|
106
|
+
: item.allowUnknownOption !== undefined
|
|
107
|
+
? item.allowUnknownOption
|
|
108
|
+
: undefined;
|
|
109
|
+
return { options, commands, allowUnknownOption };
|
|
110
|
+
}
|
|
111
|
+
export default {
|
|
112
|
+
normalizeTaskOptions,
|
|
113
|
+
normalizeTaskCommands,
|
|
114
|
+
getTaskOptionSpec
|
|
115
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (env: any, target: any, override?: boolean): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default function (env, target, override = true) {
|
|
2
|
+
target = target || process.env;
|
|
3
|
+
if (env) {
|
|
4
|
+
Object.keys(env).forEach(k => {
|
|
5
|
+
if (override === false && target.hasOwnProperty(k)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (env[k] === undefined || env[k] === null) {
|
|
9
|
+
delete target[k];
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
target[k] = env[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
}
|
|
18
|
+
;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare class XQItem {
|
|
2
|
+
_isFinally: any;
|
|
3
|
+
anon: any;
|
|
4
|
+
argv: any;
|
|
5
|
+
children: any;
|
|
6
|
+
id: any;
|
|
7
|
+
level: any;
|
|
8
|
+
name: any;
|
|
9
|
+
ns: any;
|
|
10
|
+
parentId: any;
|
|
11
|
+
resolved: any;
|
|
12
|
+
type: any;
|
|
13
|
+
constructor(options: any);
|
|
14
|
+
lookup(tasks: any): any;
|
|
15
|
+
value(): any;
|
|
16
|
+
setResolve(value: any): void;
|
|
17
|
+
setNamespace(ns: any): void;
|
|
18
|
+
addChild(x: any): void;
|
|
19
|
+
get isFinally(): any;
|
|
20
|
+
set isFinally(f: any);
|
|
21
|
+
}
|
|
22
|
+
export default XQItem;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import genXqId from "./gen-xqid.js";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
class XQItem {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.id = genXqId();
|
|
6
|
+
this.argv = [];
|
|
7
|
+
this.resolved = [];
|
|
8
|
+
this.children = [];
|
|
9
|
+
this.level = options.level || 0;
|
|
10
|
+
this.ns = options.ns || "";
|
|
11
|
+
let value = options.value;
|
|
12
|
+
if (typeof options.name === "string") {
|
|
13
|
+
this.argv = options.name
|
|
14
|
+
.trim()
|
|
15
|
+
.split(" ")
|
|
16
|
+
.filter(x => x);
|
|
17
|
+
this.name = this.argv[0];
|
|
18
|
+
if (this.name !== options.name && !value) {
|
|
19
|
+
value = options.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
assert(this.name, "xqitem must have a name");
|
|
23
|
+
if (value) {
|
|
24
|
+
this.setResolve(value);
|
|
25
|
+
}
|
|
26
|
+
this.type = options.type;
|
|
27
|
+
if (options.parent) {
|
|
28
|
+
this.parentId = options.parent.id;
|
|
29
|
+
this.isFinally = options.parent.isFinally;
|
|
30
|
+
}
|
|
31
|
+
this.anon = options.anon;
|
|
32
|
+
}
|
|
33
|
+
lookup(tasks) {
|
|
34
|
+
const found = tasks.lookup(this.name);
|
|
35
|
+
this.setResolve({ top: true, item: found.item });
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
value() {
|
|
39
|
+
return this.resolved.length === 0 ? this.name : this.resolved[this.resolved.length - 1];
|
|
40
|
+
}
|
|
41
|
+
setResolve(value) {
|
|
42
|
+
this.resolved.push(value);
|
|
43
|
+
}
|
|
44
|
+
setNamespace(ns) {
|
|
45
|
+
this.ns = ns;
|
|
46
|
+
}
|
|
47
|
+
addChild(x) {
|
|
48
|
+
this.children.push(x);
|
|
49
|
+
}
|
|
50
|
+
get isFinally() {
|
|
51
|
+
return this._isFinally;
|
|
52
|
+
}
|
|
53
|
+
set isFinally(f) {
|
|
54
|
+
this._isFinally = f;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default XQItem;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import XQItem from "./xqitem.js";
|
|
2
|
+
import childProc from "child_process";
|
|
3
|
+
declare class XQtor {
|
|
4
|
+
_done: any;
|
|
5
|
+
_tasks: any;
|
|
6
|
+
_xrun: any;
|
|
7
|
+
xqItems: any;
|
|
8
|
+
constructor(options: any);
|
|
9
|
+
next(err?: any, xqId?: any): void;
|
|
10
|
+
_next(err: any, xqId: any): void;
|
|
11
|
+
execute(): any;
|
|
12
|
+
pushMarkItem(qItem: any, callback?: any): XQItem;
|
|
13
|
+
pushItem(qItem: any): void;
|
|
14
|
+
popItem(): any;
|
|
15
|
+
_isAnonShell(value: any): false | {
|
|
16
|
+
sig: any;
|
|
17
|
+
opt: boolean;
|
|
18
|
+
};
|
|
19
|
+
_parseShellFlags(flags: any, value?: any): any;
|
|
20
|
+
_parseAnonShell(value: any): any;
|
|
21
|
+
_isStrArray(value: any): any;
|
|
22
|
+
_parseStrArray(value: any): import("string-array").StringArray[];
|
|
23
|
+
_processLookup(qItem: any): void;
|
|
24
|
+
_processDep(qItem: any, dep: any): void;
|
|
25
|
+
_processTaskObject(qItem: any): any;
|
|
26
|
+
_processArray(qItem: any, tasks: any, top?: any): void;
|
|
27
|
+
_serialArrayXer(qItem: any, tasks: any): void;
|
|
28
|
+
_resolveValueToQItemOptions(ns: any, name: any, value: any, type: any): {
|
|
29
|
+
ns: any;
|
|
30
|
+
name: any;
|
|
31
|
+
value: any;
|
|
32
|
+
anon: boolean;
|
|
33
|
+
type: any;
|
|
34
|
+
};
|
|
35
|
+
_concurrentArrayXer(qItem: any, tasks: any): void;
|
|
36
|
+
_envXer(qItem: any, cmdVal: any): void;
|
|
37
|
+
_shellXer(qItem: any, cmdVal: any, anon?: any): void;
|
|
38
|
+
_doShellXer({ /*anon,*/ qItem, cmd, flags, /*cmdVal,*/ options, item }: {
|
|
39
|
+
cmd: any;
|
|
40
|
+
flags: any;
|
|
41
|
+
item: any;
|
|
42
|
+
options: any;
|
|
43
|
+
qItem: any;
|
|
44
|
+
}): void;
|
|
45
|
+
_handleChildTask(child: any, cmd: any): childProc.ChildProcess;
|
|
46
|
+
_processMoreFromFn(qItem: any, value: any, callback?: any): void;
|
|
47
|
+
_isChildSigTerm(err: any, child: any): boolean;
|
|
48
|
+
_isChildTerminated(child: any): any;
|
|
49
|
+
_handleStream(val: any): any;
|
|
50
|
+
_functionXer(qItem: any, fn: any): any;
|
|
51
|
+
_watchFailure(watch: any): NodeJS.Timeout;
|
|
52
|
+
_processMark(qItem: any): void;
|
|
53
|
+
_makeXqMarkItem(qItem: any, callback: any): XQItem;
|
|
54
|
+
_emit(event: any, data?: any): void;
|
|
55
|
+
_createQItem(options: any, parent: any): any;
|
|
56
|
+
}
|
|
57
|
+
export default XQtor;
|