@uipath/maestro-builder-sdk 6.105.1 → 6.106.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/README.md CHANGED
@@ -182,7 +182,17 @@ undeclared `$vars` reference (a mistyped variable or step name in a `` js`…` `
182
182
  expression) is `check`'s `EXPR_UNDECLARED_REF`, and `compile` writes the read as
183
183
  authored, so a `.flow` that already has one still decompiles and compiles. An
184
184
  expression that is not valid JavaScript is `EXPR_SYNTAX`: `compile` refuses it
185
- with a `FlowBuildError`, and `check` reports it too. For a COMPILED `.flow`, `uip maestro flow validate` is the authoritative
185
+ with a `FlowBuildError`, and `check` reports it too.
186
+
187
+ `flow build` runs the two in that order: `check` first, then `compile` only
188
+ when `check` found no error. It takes the options of both, including `check`'s
189
+ `--baseline <original.flow>` (or `--baseline-from`, as `merge` spells it), and
190
+ exits with their codes. `build` compiles and does not merge, so with
191
+ `--baseline` it needs `-o`, and refuses an `-o` that is the original: write the
192
+ edit back into the original with `flow merge`. For instance `npx flow-sdk flow build Hello -o
193
+ Hello.flow` prints `check`'s findings and then `compile: wrote Hello.flow`, or
194
+ stops after `check` with `build: check found 1 error(s); not compiling`.
195
+ `compile` itself still does not check. For a COMPILED `.flow`, `uip maestro flow validate` is the authoritative
186
196
  product validator, and `uip maestro flow debug` (or `flow-debug`) runs it. Case and BPMN use the same family-first shape:
187
197
  `uip maestro case compile|check|decompile` and
188
198
  `uip maestro bpmn compile|check|format`.
@@ -213,7 +223,8 @@ and `merge` report the `path` they wrote. A verb whose plain output is the
213
223
  result itself (`registry search`, `registry path`, `bpmn check --graph`) prints it
214
224
  only as that object under `--json`, never a second copy on stderr. `package.json` lists the optional
215
225
  surface a caller may probe for in `cliCapabilities` (`json-result`; `fetch-definitions` when a
216
- connector definition no library carries is fetched through `uip`, so no library has to be pulled).
226
+ connector definition no library carries is fetched through `uip`, so no library has to be pulled;
227
+ `flow-build` when the SDK has `flow build`).
217
228
  `flow-sdk capabilities` prints that list with the installed version (`--json` for one
218
229
  object), and `flowSdk.minVersion` in a project's `package.json` makes the `flow`, `case`
219
230
  and `bpmn` verbs refuse an older SDK (`website/reference/CLI-LOOP.md`).
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { type CliExitCode } from './cli-run.js';
3
+ export declare function run(argv: string[]): Promise<CliExitCode>;
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * build-cli — `flow check`, then `flow compile` only when the check is clean.
4
+ *
5
+ * Usage:
6
+ * node --experimental-strip-types build-cli.js <flow.ts | BaseName> \
7
+ * [-o out.flow] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] \
8
+ * [--resources <file>] [--baseline <original.flow> [--package <name>]]
9
+ *
10
+ * `compile` does not run `check` (docs/CHECK_COMPILE_CONTRACT_DESIGN.md D1, D2):
11
+ * it stops only when it cannot write a correct `.flow`, and a lint finding such
12
+ * as `EMPTY_ARM` is never a reason for it to stop. So the order "check, then
13
+ * compile" was the caller's to remember (#1998). This verb owns it:
14
+ *
15
+ * - It runs `check` with the options `flow check` takes. With `--baseline`
16
+ * (`--baseline-from` is the same option, spelled as `merge` spells it) the
17
+ * findings are scoped to the edit, so a pre-existing finding on a node the
18
+ * edit did not touch is a warning and does not stop the build. `build`
19
+ * compiles, it does not merge, so with `--baseline` it needs `-o`, and
20
+ * refuses an `-o` that is the baseline file (usage error, 2): the
21
+ * write-back into the original is `flow merge`.
22
+ * - An error stops it: nothing is compiled and the exit code is check's (1;
23
+ * 2 for a usage error).
24
+ * - Otherwise it runs `compile` with the options `flow compile` takes, and the
25
+ * exit code is compile's.
26
+ *
27
+ * Exit codes are the two commands' own: 0 written, 1 a finding or refusal, 2 a
28
+ * usage error. `compile` itself is unchanged. Under `--json` the one result
29
+ * object holds both commands' diagnostics, check's first, and `stage` says
30
+ * which command decided the result: `"check"` when it stopped there,
31
+ * `"compile"` otherwise.
32
+ *
33
+ * For instance `flow build Order.flow.ts -o Order.flow` with a step that reads
34
+ * an unknown variable prints check's `✗ [UPDATE_UNKNOWN_VAR] …`, then
35
+ * `build: check found 1 error(s); not compiling`, and exits 1.
36
+ */
37
+ import { realpathSync } from 'node:fs';
38
+ import { resolve } from 'node:path';
39
+ import { reportDiagnostics, reportedFields, reportResult } from './cli-result.js';
40
+ import { runWhenInvokedDirectly } from './cli-run.js';
41
+ import { run as runCheck } from './check-cli.js';
42
+ import { run as runCompile } from './compile-cli.js';
43
+ /** The options that take a value, and which of the two commands each goes to. */
44
+ const VALUE_FLAGS = new Map([
45
+ ['-o', { check: false, compile: true }],
46
+ ['--output', { check: false, compile: true }],
47
+ ['--library', { check: true, compile: true }],
48
+ ['--connectors-local', { check: true, compile: true }],
49
+ ['--bindings', { check: true, compile: true }],
50
+ ['--resources', { check: true, compile: true }],
51
+ ['--baseline', { check: true, compile: false }],
52
+ ['--baseline-from', { check: true, compile: false }],
53
+ ['--package', { check: true, compile: false }],
54
+ ]);
55
+ const USAGE = 'usage: build <flow.ts | BaseName> [-o out.flow] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] '
56
+ + '[--resources <file>] [--baseline <original.flow> [--package <name>]]';
57
+ export async function run(argv) {
58
+ if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
59
+ console.error(USAGE);
60
+ return 2;
61
+ }
62
+ const parsed = parseArgs(argv);
63
+ if (typeof parsed === 'string') {
64
+ console.error(`build: ${parsed}`);
65
+ console.error(USAGE);
66
+ reportResult({ error: parsed });
67
+ return 2;
68
+ }
69
+ const checked = await runCheck(parsed.check);
70
+ const checkDiagnostics = diagnosticsReported();
71
+ if (checked !== 0) {
72
+ const errors = checkDiagnostics.filter((d) => d.level === 'error').length;
73
+ console.error(checked === 2
74
+ ? 'build: check refused its arguments; not compiling.'
75
+ : `build: check found ${errors} error(s); not compiling. Fix them and run build again.`);
76
+ reportResult({ stage: 'check' });
77
+ return checked;
78
+ }
79
+ const compiled = await runCompile(parsed.compile);
80
+ if (compiled !== 0 && parsed.baseline) {
81
+ // check --baseline turns a pre-existing finding into a warning, but compile
82
+ // judges the whole flow (D2), so an untouched node that fails to lower stops it.
83
+ console.error('build: compile refused. A refusal on a node the edit did not touch is written back as saved by '
84
+ + '`flow merge --baseline-from <original.flow>`.');
85
+ }
86
+ // Both commands' findings, check's first; a finding both report is listed once.
87
+ const seen = new Set();
88
+ const all = [...checkDiagnostics, ...diagnosticsReported()].filter((d) => {
89
+ const key = JSON.stringify([d.level, d.code, d.message, d.step]);
90
+ if (seen.has(key))
91
+ return false;
92
+ seen.add(key);
93
+ return true;
94
+ });
95
+ reportDiagnostics(all);
96
+ reportResult({ stage: 'compile' });
97
+ return compiled;
98
+ }
99
+ /** The two commands' argv, or why `argv` is refused. */
100
+ function parseArgs(argv) {
101
+ const check = [];
102
+ const compile = [];
103
+ const positionals = [];
104
+ const baselines = [];
105
+ for (let i = 0; i < argv.length; i++) {
106
+ const arg = argv[i];
107
+ const target = VALUE_FLAGS.get(arg);
108
+ if (target !== undefined) {
109
+ const value = argv[i + 1];
110
+ if (value === undefined)
111
+ return `${arg} takes a value`;
112
+ i++;
113
+ if (arg === '--baseline' || arg === '--baseline-from') {
114
+ baselines.push(value);
115
+ continue;
116
+ }
117
+ const flag = arg === '--output' ? '-o' : arg;
118
+ if (target.check)
119
+ check.push(flag, value);
120
+ if (target.compile)
121
+ compile.push(flag, value);
122
+ continue;
123
+ }
124
+ // `flow check --source` names the mode build always runs in.
125
+ if (arg === '--source')
126
+ continue;
127
+ if (arg.startsWith('-'))
128
+ return `unknown option ${arg}`;
129
+ positionals.push(arg);
130
+ }
131
+ if (positionals.length !== 1) {
132
+ return positionals.length === 0 ? 'missing <flow.ts | BaseName>' : `takes one source, got ${positionals.join(', ')}`;
133
+ }
134
+ if (new Set(baselines).size > 1)
135
+ return `--baseline and --baseline-from name different files: ${baselines.join(', ')}`;
136
+ const [source] = positionals;
137
+ const baseline = baselines[0];
138
+ if (baseline !== undefined) {
139
+ const refused = baselineOutputRefusal(baseline, outputOf(compile));
140
+ if (refused !== undefined)
141
+ return refused;
142
+ }
143
+ return {
144
+ check: [source, ...check, ...(baseline !== undefined ? ['--baseline', baseline] : [])],
145
+ compile: [source, ...compile],
146
+ baseline: baseline !== undefined,
147
+ };
148
+ }
149
+ /** The `-o` value in compile's argv, if any. */
150
+ function outputOf(compile) {
151
+ const i = compile.indexOf('-o');
152
+ return i >= 0 ? compile[i + 1] : undefined;
153
+ }
154
+ /**
155
+ * Why `build --baseline` refuses where it would write, or `undefined`.
156
+ *
157
+ * `build` compiles; it does not merge. A plain compile over the original
158
+ * `.flow` rewrites every node, the untouched ones included, which is the lossy
159
+ * write the brownfield loop avoids: the write-back is `flow merge
160
+ * --baseline-from`, which keeps the untouched nodes as saved. So with
161
+ * `--baseline`, `-o` is required (without it the output is named after the
162
+ * flow, which for a decompiled canvas is the original's own name) and must not
163
+ * be the baseline file. For instance `build Order.flow.ts -o Order.flow
164
+ * --baseline Order.flow` is refused; `-o .flow-sdk/Order.built.flow` is not.
165
+ */
166
+ function baselineOutputRefusal(baseline, output) {
167
+ const merge = `To write the edit back into the original, run \`flow merge <source> --original ${baseline}\` instead.`;
168
+ if (output === undefined) {
169
+ return `--baseline needs -o: without it the .flow is named after the flow, which can be the original ${baseline}. `
170
+ + `build compiles and does not merge, so it never writes over the original. ${merge}`;
171
+ }
172
+ if (realOrResolved(output) === realOrResolved(baseline)) {
173
+ return `-o ${output} is the --baseline file. build compiles and does not merge, so writing there would replace `
174
+ + `every node of the original, the untouched ones included. Pass -o another path. ${merge}`;
175
+ }
176
+ return undefined;
177
+ }
178
+ /** `path` with its symlinks resolved when it exists, else made absolute. */
179
+ function realOrResolved(path) {
180
+ try {
181
+ return realpathSync.native(path);
182
+ }
183
+ catch {
184
+ return resolve(path);
185
+ }
186
+ }
187
+ /** The diagnostics the last command reported. */
188
+ function diagnosticsReported() {
189
+ const diags = reportedFields().diagnostics;
190
+ return Array.isArray(diags) ? diags : [];
191
+ }
192
+ runWhenInvokedDirectly(import.meta.url, 'build', run);
@@ -98,6 +98,35 @@ export function registerFlowCommands(program) {
98
98
  '`uip maestro flow debug` / `flow-debug <file.flow>` to run it. ' +
99
99
  'Authoring-time checks still work on a .flow.ts source (--source).');
100
100
  });
101
+ flow.command('build')
102
+ .description('Check authored TypeScript, then compile it to a .flow only when the check finds no error. Same options and exit codes as check and compile; compile itself still does not check.')
103
+ .argument('<source>', 'a .flow.ts path or bare name')
104
+ .option('--source', 'check authored TypeScript (the only kind build takes)')
105
+ .option('-o, --output <file>', 'output .flow path')
106
+ .option('--library <dir>', 'connector library directory')
107
+ .option('--connectors-local <dir>', 'connection-resolved connector overlay')
108
+ .option('--bindings <file>', 'bindings.json path')
109
+ .option('--resources <file>', 'resource ledger that registry prepare writes (default .flow-sdk/resources.json)')
110
+ .option('--baseline <file>', 'the original .flow the source was decompiled from, as for flow check: findings on nodes the edit did not touch, which the original has too, become warnings and do not stop the build. Needs -o, and -o must not be this file: build compiles, it does not merge (use flow merge to write back into the original)')
111
+ .option('--baseline-from <file>', 'the same as --baseline, spelled as flow merge spells it')
112
+ .option('--package <name...>', 'trust and load this node-type package for --baseline (repeatable)')
113
+ .action(async (source, options) => {
114
+ if (emitOnlyEnabled()) {
115
+ refuse('flow-sdk flow build: disabled by emit-only mode, which turns check off; use `flow compile`');
116
+ return;
117
+ }
118
+ const argv = [source];
119
+ addValue(argv, '-o', options.output);
120
+ addValue(argv, '--library', options.library);
121
+ addValue(argv, '--connectors-local', options.connectorsLocal);
122
+ addValue(argv, '--bindings', options.bindings);
123
+ addValue(argv, '--resources', options.resources);
124
+ addValue(argv, '--baseline', options.baseline);
125
+ addValue(argv, '--baseline-from', options.baselineFrom);
126
+ for (const name of options.package ?? [])
127
+ argv.push('--package', name);
128
+ await invoke('flow build', () => import('../../build-cli.js'), argv);
129
+ });
101
130
  flow.command('decompile')
102
131
  .description('Convert a .flow artifact to authored TypeScript.')
103
132
  .argument('<input>', 'input .flow path')
@@ -6,6 +6,11 @@
6
6
  * @param fields - JSON-serializable values, e.g. `{ path, nodes, edges }`.
7
7
  */
8
8
  export declare function reportResult(fields: Record<string, unknown>): void;
9
+ /**
10
+ * The fields this run has reported so far, for a verb that runs two tools and
11
+ * reports their results as one (`flow build`: check, then compile).
12
+ */
13
+ export declare function reportedFields(): Readonly<Record<string, unknown>>;
9
14
  /**
10
15
  * Print text that IS the verb's result (a pretty-printed object, a captured
11
16
  * path), as opposed to a status line such as `compile: wrote X`.
@@ -19,6 +19,13 @@ function slot() {
19
19
  export function reportResult(fields) {
20
20
  Object.assign(slot().fields, fields);
21
21
  }
22
+ /**
23
+ * The fields this run has reported so far, for a verb that runs two tools and
24
+ * reports their results as one (`flow build`: check, then compile).
25
+ */
26
+ export function reportedFields() {
27
+ return slot().fields;
28
+ }
22
29
  /**
23
30
  * Print text that IS the verb's result (a pretty-printed object, a captured
24
31
  * path), as opposed to a status line such as `compile: wrote X`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.105.1",
3
+ "version": "6.106.0",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -60,6 +60,7 @@
60
60
  "flow-decompile": "./dist/decompile-cli.js",
61
61
  "flow-merge": "./dist/merge-cli.js",
62
62
  "flow-check": "./dist/check-cli.js",
63
+ "flow-build": "./dist/build-cli.js",
63
64
  "case-compile": "./dist/case/compile-cli.js",
64
65
  "case-check": "./dist/case/check-cli.js",
65
66
  "case-decompile": "./dist/case/decompile-cli.js",
@@ -84,7 +85,8 @@
84
85
  "flow-check-baseline",
85
86
  "flow-decompile-scripts",
86
87
  "flow-script-metadata",
87
- "flow-pipeline-strict"
88
+ "flow-pipeline-strict",
89
+ "flow-build"
88
90
  ],
89
91
  "files": [
90
92
  "dist",
@@ -121,5 +123,5 @@
121
123
  "@types/node": "^22.7.0",
122
124
  "esbuild": "^0.28.1"
123
125
  },
124
- "gitref": "187db960348287f6543d4824b9c5d9f865f86c7a"
126
+ "gitref": "b84c2c90fcc6512f55ef828fb753ba84a698af3d"
125
127
  }