@fynjs/run 1.1.0 → 1.1.2

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.
Files changed (103) hide show
  1. package/bin/qrun.js +6 -1
  2. package/bin/xrun.js +1 -1
  3. package/dist/cli/check-global.d.ts +1 -0
  4. package/{cli → dist/cli}/check-global.js +3 -3
  5. package/dist/cli/ck.d.ts +1 -0
  6. package/dist/cli/cli-options.d.ts +80 -0
  7. package/dist/cli/cli-options.js +95 -0
  8. package/dist/cli/config.d.ts +7 -0
  9. package/dist/cli/config.js +7 -0
  10. package/dist/cli/env.d.ts +17 -0
  11. package/dist/cli/env.js +31 -0
  12. package/dist/cli/npm-loader.d.ts +2 -0
  13. package/dist/cli/npm-loader.js +43 -0
  14. package/dist/cli/parse-cmd-args.d.ts +34 -0
  15. package/dist/cli/parse-cmd-args.js +199 -0
  16. package/dist/cli/provider-packages.d.ts +28 -0
  17. package/dist/cli/provider-packages.js +62 -0
  18. package/dist/cli/search-up-task-file.d.ts +8 -0
  19. package/dist/cli/search-up-task-file.js +79 -0
  20. package/dist/cli/task-file.d.ts +40 -0
  21. package/dist/cli/task-file.js +177 -0
  22. package/dist/cli/ts-runner.d.ts +2 -0
  23. package/dist/cli/ts-runner.js +60 -0
  24. package/dist/cli/usage.d.ts +2 -0
  25. package/dist/cli/wrap-process.d.ts +10 -0
  26. package/dist/cli/wrap-process.js +26 -0
  27. package/dist/cli/xrun-main.d.ts +119 -0
  28. package/dist/cli/xrun-main.js +417 -0
  29. package/dist/cli/xrun.d.ts +2 -0
  30. package/{cli → dist/cli}/xrun.js +0 -1
  31. package/dist/lib/chalk.d.ts +2 -0
  32. package/{lib → dist/lib}/chalk.js +0 -1
  33. package/dist/lib/cli-context.d.ts +97 -0
  34. package/dist/lib/cli-context.js +129 -0
  35. package/dist/lib/defaults.d.ts +30 -0
  36. package/{lib → dist/lib}/defaults.js +13 -16
  37. package/dist/lib/gen-xqid.d.ts +2 -0
  38. package/dist/lib/gen-xqid.js +8 -0
  39. package/dist/lib/index.d.ts +3 -0
  40. package/{lib → dist/lib}/index.js +0 -3
  41. package/dist/lib/logger.d.ts +2 -0
  42. package/dist/lib/logger.js +95 -0
  43. package/dist/lib/my-pkg.d.ts +4 -0
  44. package/dist/lib/my-pkg.js +42 -0
  45. package/dist/lib/ns-order.d.ts +7 -0
  46. package/dist/lib/ns-order.js +62 -0
  47. package/dist/lib/print-tasks/index.d.ts +2 -0
  48. package/dist/lib/print-tasks/index.js +100 -0
  49. package/dist/lib/reporters/console.d.ts +20 -0
  50. package/dist/lib/reporters/console.js +119 -0
  51. package/dist/lib/stringify.d.ts +2 -0
  52. package/dist/lib/stringify.js +19 -0
  53. package/dist/lib/util/parse-array.d.ts +2 -0
  54. package/dist/lib/util/parse-array.js +5 -0
  55. package/dist/lib/util/task-options.d.ts +37 -0
  56. package/dist/lib/util/task-options.js +115 -0
  57. package/dist/lib/util/update-env.d.ts +1 -0
  58. package/dist/lib/util/update-env.js +18 -0
  59. package/dist/lib/xqitem.d.ts +22 -0
  60. package/dist/lib/xqitem.js +57 -0
  61. package/dist/lib/xqtor.d.ts +57 -0
  62. package/dist/lib/xqtor.js +704 -0
  63. package/dist/lib/xqtree.d.ts +11 -0
  64. package/dist/lib/xqtree.js +33 -0
  65. package/dist/lib/xrun-instance.d.ts +9 -0
  66. package/dist/lib/xrun-instance.js +27 -0
  67. package/dist/lib/xrun.d.ts +55 -0
  68. package/dist/lib/xrun.js +317 -0
  69. package/dist/lib/xtask-spec.d.ts +10 -0
  70. package/dist/lib/xtask-spec.js +57 -0
  71. package/dist/lib/xtasks.d.ts +25 -0
  72. package/dist/lib/xtasks.js +119 -0
  73. package/package.json +39 -15
  74. package/cli/cli-options.js +0 -98
  75. package/cli/config.js +0 -8
  76. package/cli/env.js +0 -33
  77. package/cli/npm-loader.js +0 -56
  78. package/cli/parse-cmd-args.js +0 -156
  79. package/cli/provider-packages.js +0 -73
  80. package/cli/search-up-task-file.js +0 -92
  81. package/cli/task-file.js +0 -192
  82. package/cli/ts-runner.js +0 -62
  83. package/cli/wrap-process.js +0 -27
  84. package/cli/xrun-main.js +0 -425
  85. package/lib/cli-context.js +0 -145
  86. package/lib/gen-xqid.js +0 -10
  87. package/lib/logger.js +0 -105
  88. package/lib/ns-order.js +0 -76
  89. package/lib/print-tasks/index.js +0 -105
  90. package/lib/reporters/console.js +0 -133
  91. package/lib/stringify.js +0 -16
  92. package/lib/util/parse-array.js +0 -5
  93. package/lib/util/update-env.js +0 -16
  94. package/lib/xqitem.js +0 -70
  95. package/lib/xqtor.js +0 -814
  96. package/lib/xqtree.js +0 -41
  97. package/lib/xrun-instance.js +0 -33
  98. package/lib/xrun.d.ts +0 -89
  99. package/lib/xrun.js +0 -344
  100. package/lib/xtask-spec.js +0 -63
  101. package/lib/xtasks.js +0 -137
  102. /package/{cli → dist/cli}/ck.js +0 -0
  103. /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;