@camunda8/cli 4.0.0-alpha.1 → 4.0.0-alpha.3
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/PLUGIN-HELP.md +9 -0
- package/dist/commands/jobs.d.ts.map +1 -1
- package/dist/commands/jobs.js +2 -2
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/messages.d.ts.map +1 -1
- package/dist/commands/messages.js +3 -2
- package/dist/commands/messages.js.map +1 -1
- package/dist/commands/process-instances.d.ts.map +1 -1
- package/dist/commands/process-instances.js +4 -14
- package/dist/commands/process-instances.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +2 -6
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/user-tasks.d.ts.map +1 -1
- package/dist/commands/user-tasks.js +2 -2
- package/dist/commands/user-tasks.js.map +1 -1
- package/dist/commands/variables.d.ts.map +1 -1
- package/dist/commands/variables.js +5 -15
- package/dist/commands/variables.js.map +1 -1
- package/dist/core/runtime.d.ts +5 -0
- package/dist/core/runtime.d.ts.map +1 -1
- package/dist/core/runtime.js.map +1 -1
- package/dist/default-plugins/bpmn/c8ctl-plugin.js +7 -2
- package/dist/default-plugins/element-template/c8ctl-plugin.js +12 -3
- package/dist/default-plugins/element-template/package.json +1 -1
- package/dist/framework/command-registry.d.ts +1 -1
- package/dist/framework/command-registry.d.ts.map +1 -1
- package/dist/framework/command-registry.js +25 -7
- package/dist/framework/command-registry.js.map +1 -1
- package/dist/templates/AGENTS.md +7 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/shared/npm-exec.d.ts +18 -2
- package/dist/utils/shared/npm-exec.d.ts.map +1 -1
- package/dist/utils/shared/npm-exec.js +150 -6
- package/dist/utils/shared/npm-exec.js.map +1 -1
- package/dist/utils/shared/variables-input.d.ts +31 -0
- package/dist/utils/shared/variables-input.d.ts.map +1 -0
- package/dist/utils/shared/variables-input.js +177 -0
- package/dist/utils/shared/variables-input.js.map +1 -0
- package/dist/vendor/bpmn-element-templates.cjs +870 -776
- package/dist/vendor/bpmnlint.cjs +581 -572
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared parser for `--variables` JSON input (#528).
|
|
3
|
+
*
|
|
4
|
+
* Passing inline JSON through a shell is quoting-hostile — PowerShell in
|
|
5
|
+
* particular strips the double quotes of a native command argument before
|
|
6
|
+
* the process ever sees it, so `{"a":"b"}` arrives as `{a:b}`.
|
|
7
|
+
*
|
|
8
|
+
* Three defences, in order:
|
|
9
|
+
* 1. Valid JSON is parsed as-is, however large or deeply nested.
|
|
10
|
+
* 2. Inline input that arrived with *every* quote stripped is re-quoted
|
|
11
|
+
* and re-parsed, with a warning naming the repaired payload.
|
|
12
|
+
* 3. Anything still unparseable — e.g. a payload the shell also split on
|
|
13
|
+
* spaces — fails with a hint pointing at the quoting-proof `@file` /
|
|
14
|
+
* `@-` (stdin) forms.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { getLogger, isRecord } from "../../core/index.js";
|
|
18
|
+
const QUOTING_HINT = "Hint: read the JSON from a file instead of quoting it inline: " +
|
|
19
|
+
"--variables @vars.json (or --variables @- to read stdin). " +
|
|
20
|
+
"Some shells (notably PowerShell) strip or re-split the quotes of inline JSON.";
|
|
21
|
+
/**
|
|
22
|
+
* Bare tokens that must stay unquoted when re-quoting a stripped payload:
|
|
23
|
+
* JSON numbers and the three literals.
|
|
24
|
+
*/
|
|
25
|
+
const JSON_LITERAL = /^(?:-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)$/;
|
|
26
|
+
const STRUCTURAL = new Set(["{", "}", "[", "]", ":", ","]);
|
|
27
|
+
/**
|
|
28
|
+
* Normalise a filesystem path to forward slashes so Windows backslashes
|
|
29
|
+
* survive JSON serialisation in error messages without being doubled.
|
|
30
|
+
*/
|
|
31
|
+
export function toDisplayPath(path) {
|
|
32
|
+
return path.replaceAll("\\", "/");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Does this look like a JSON object whose double quotes the shell removed?
|
|
36
|
+
* Requires the object braces to have survived — anything else is a typo or
|
|
37
|
+
* a payload the shell also split on spaces, neither of which is repairable.
|
|
38
|
+
*/
|
|
39
|
+
function looksQuoteStripped(text) {
|
|
40
|
+
const value = text.trim();
|
|
41
|
+
return !value.includes('"') && value.startsWith("{") && value.endsWith("}");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Re-quote a payload whose double quotes were stripped by the shell, e.g.
|
|
45
|
+
* PowerShell turning `{"a":"b"}` into `{a:b}`.
|
|
46
|
+
*
|
|
47
|
+
* Only attempted for an object payload that contains no `"` at all — a
|
|
48
|
+
* payload that kept some of its quotes was mangled some other way, and
|
|
49
|
+
* guessing would be unsafe. Structural characters delimit bare tokens;
|
|
50
|
+
* every token that is not a JSON number/`true`/`false`/`null` is
|
|
51
|
+
* re-quoted. Ambiguous input (a stripped string that itself contained `:`
|
|
52
|
+
* or `,`) reassembles into invalid JSON and is rejected by the caller's
|
|
53
|
+
* re-parse.
|
|
54
|
+
*
|
|
55
|
+
* Returns the repaired text, or `null` when no repair is applicable.
|
|
56
|
+
*/
|
|
57
|
+
function requoteStrippedJson(text) {
|
|
58
|
+
if (!looksQuoteStripped(text))
|
|
59
|
+
return null;
|
|
60
|
+
let out = "";
|
|
61
|
+
let token = "";
|
|
62
|
+
const flushToken = () => {
|
|
63
|
+
const value = token.trim();
|
|
64
|
+
token = "";
|
|
65
|
+
if (!value)
|
|
66
|
+
return;
|
|
67
|
+
out += JSON_LITERAL.test(value) ? value : JSON.stringify(value);
|
|
68
|
+
};
|
|
69
|
+
for (const char of text) {
|
|
70
|
+
if (STRUCTURAL.has(char)) {
|
|
71
|
+
flushToken();
|
|
72
|
+
out += char;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
token += char;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
flushToken();
|
|
79
|
+
return out === text ? null : out;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolve the raw flag value to JSON text, following an `@file` / `@-`
|
|
83
|
+
* reference when present.
|
|
84
|
+
*/
|
|
85
|
+
function readVariablesSource(raw) {
|
|
86
|
+
const value = raw.trim();
|
|
87
|
+
if (!value.startsWith("@"))
|
|
88
|
+
return { text: value };
|
|
89
|
+
const ref = value.slice(1);
|
|
90
|
+
if (ref === "-") {
|
|
91
|
+
if (process.stdin.isTTY) {
|
|
92
|
+
throw new Error("--variables @- expects JSON on stdin, but stdin is a terminal");
|
|
93
|
+
}
|
|
94
|
+
// Blocking read of fd 0 until EOF, the same contract as `cat -`:
|
|
95
|
+
// the producer of the pipe is expected to close it. Reading stdin
|
|
96
|
+
// synchronously here is safe because `--variables` is parsed once
|
|
97
|
+
// per invocation, before any other stdin consumer runs.
|
|
98
|
+
return { text: readFileSync(0, "utf-8"), origin: "stdin" };
|
|
99
|
+
}
|
|
100
|
+
if (!ref) {
|
|
101
|
+
throw new Error("--variables @ requires a file path (e.g. @vars.json)");
|
|
102
|
+
}
|
|
103
|
+
const normalised = toDisplayPath(ref);
|
|
104
|
+
try {
|
|
105
|
+
return { text: readFileSync(ref, "utf-8"), origin: `'${normalised}'` };
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
109
|
+
throw new Error(`Cannot read variables file '${normalised}': ${msg}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse a `--variables` flag value into a JSON object.
|
|
114
|
+
*
|
|
115
|
+
* Accepts inline JSON, `@path/to/file.json`, or `@-` for stdin. Throws an
|
|
116
|
+
* `Error` (never exits) so the framework's error handler owns the exit code.
|
|
117
|
+
*/
|
|
118
|
+
export function parseVariablesFlag({ raw, label = "variables", }) {
|
|
119
|
+
const { text, origin } = readVariablesSource(raw);
|
|
120
|
+
// Name the input source so a bad file or piped payload is not mistaken
|
|
121
|
+
// for a bad inline argument.
|
|
122
|
+
const from = origin ? ` (read from ${origin})` : "";
|
|
123
|
+
let parsed;
|
|
124
|
+
try {
|
|
125
|
+
parsed = JSON.parse(text);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
// Inline input only: an `@file` / `@-` payload never went through
|
|
129
|
+
// shell quoting, so a repair there would be guesswork.
|
|
130
|
+
const repair = origin ? null : tryRequote(text);
|
|
131
|
+
if (!repair) {
|
|
132
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
133
|
+
if (origin) {
|
|
134
|
+
throw new Error(`Invalid JSON for ${label}${from}: ${msg}`);
|
|
135
|
+
}
|
|
136
|
+
// A payload with no quotes left at all reached us stripped; say so
|
|
137
|
+
// rather than leaving the user to decode a parser position.
|
|
138
|
+
const stripped = looksQuoteStripped(text)
|
|
139
|
+
? " The value lost its quotes on the way in and could not be " +
|
|
140
|
+
"restored unambiguously."
|
|
141
|
+
: "";
|
|
142
|
+
throw new Error(`Invalid JSON for ${label}: ${msg}.${stripped} ${QUOTING_HINT}`);
|
|
143
|
+
}
|
|
144
|
+
// Announce the repair: re-quoting cannot recover the original
|
|
145
|
+
// string/number distinction (`{a:1}` could have been `{"a":1}` or
|
|
146
|
+
// `{"a":"1"}`), so the user gets to see what was sent.
|
|
147
|
+
getLogger().warn(`--variables: restored quotes stripped by the shell -> ${repair.json}. ` +
|
|
148
|
+
"Use --variables @file.json or @- to pass JSON verbatim.");
|
|
149
|
+
parsed = repair.value;
|
|
150
|
+
}
|
|
151
|
+
if (!isRecord(parsed)) {
|
|
152
|
+
throw new Error(Array.isArray(parsed)
|
|
153
|
+
? `--variables must be a JSON object (not an array)${from}`
|
|
154
|
+
: `--variables must be a JSON object${from}`);
|
|
155
|
+
}
|
|
156
|
+
return parsed;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Attempt the quote-stripping repair and parse the result.
|
|
160
|
+
*
|
|
161
|
+
* Pure: returns both the repaired JSON text (for the caller's warning) and
|
|
162
|
+
* the value it parsed to, or `null` when the input is not repairable. The
|
|
163
|
+
* wrapper object keeps the "not repairable" sentinel distinct from a
|
|
164
|
+
* payload that legitimately parsed to `null`.
|
|
165
|
+
*/
|
|
166
|
+
function tryRequote(text) {
|
|
167
|
+
const json = requoteStrippedJson(text);
|
|
168
|
+
if (json === null)
|
|
169
|
+
return null;
|
|
170
|
+
try {
|
|
171
|
+
return { json, value: JSON.parse(json) };
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=variables-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables-input.js","sourceRoot":"","sources":["../../../src/utils/shared/variables-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,YAAY,GACjB,gEAAgE;IAChE,4DAA4D;IAC5D,+EAA+E,CAAC;AAEjF;;;GAGG;AACH,MAAM,YAAY,GACjB,mEAAmE,CAAC;AAErE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,IAA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