@highstate/cli 0.4.4 → 0.4.6

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.
@@ -0,0 +1,215 @@
1
+ const simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
2
+ function getPrintable(value) {
3
+ if (value === null)
4
+ return `null`;
5
+ if (value === void 0)
6
+ return `undefined`;
7
+ if (value === ``)
8
+ return `an empty string`;
9
+ if (typeof value === "symbol")
10
+ return `<${value.toString()}>`;
11
+ if (Array.isArray(value))
12
+ return `an array`;
13
+ return JSON.stringify(value);
14
+ }
15
+ function computeKey(state, key) {
16
+ var _a, _b, _c;
17
+ if (typeof key === `number`) {
18
+ return `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}[${key}]`;
19
+ } else if (simpleKeyRegExp.test(key)) {
20
+ return `${(_b = state === null || state === void 0 ? void 0 : state.p) !== null && _b !== void 0 ? _b : ``}.${key}`;
21
+ } else {
22
+ return `${(_c = state === null || state === void 0 ? void 0 : state.p) !== null && _c !== void 0 ? _c : `.`}[${JSON.stringify(key)}]`;
23
+ }
24
+ }
25
+ function pushError({ errors, p } = {}, message) {
26
+ errors === null || errors === void 0 ? void 0 : errors.push(`${p !== null && p !== void 0 ? p : `.`}: ${message}`);
27
+ return false;
28
+ }
29
+ function makeCoercionFn(target, key) {
30
+ return (v) => {
31
+ const previous = target[key];
32
+ target[key] = v;
33
+ return makeCoercionFn(target, key).bind(null, previous);
34
+ };
35
+ }
36
+ function isUnknown() {
37
+ return makeValidator({
38
+ test: (value, state) => {
39
+ return true;
40
+ }
41
+ });
42
+ }
43
+ function isString() {
44
+ return makeValidator({
45
+ test: (value, state) => {
46
+ if (typeof value !== `string`)
47
+ return pushError(state, `Expected a string (got ${getPrintable(value)})`);
48
+ return true;
49
+ }
50
+ });
51
+ }
52
+ function isArray(spec, { delimiter } = {}) {
53
+ return makeValidator({
54
+ test: (value, state) => {
55
+ var _a;
56
+ const originalValue = value;
57
+ if (typeof value === `string` && typeof delimiter !== `undefined`) {
58
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
59
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
60
+ return pushError(state, `Unbound coercion result`);
61
+ value = value.split(delimiter);
62
+ }
63
+ }
64
+ if (!Array.isArray(value))
65
+ return pushError(state, `Expected an array (got ${getPrintable(value)})`);
66
+ let valid = true;
67
+ for (let t = 0, T = value.length; t < T; ++t) {
68
+ valid = spec(value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
69
+ if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
70
+ break;
71
+ }
72
+ }
73
+ if (value !== originalValue)
74
+ state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
75
+ return valid;
76
+ }
77
+ });
78
+ }
79
+ function isTuple(spec, { delimiter } = {}) {
80
+ const lengthValidator = hasExactLength(spec.length);
81
+ return makeValidator({
82
+ test: (value, state) => {
83
+ var _a;
84
+ if (typeof value === `string` && typeof delimiter !== `undefined`) {
85
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
86
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
87
+ return pushError(state, `Unbound coercion result`);
88
+ value = value.split(delimiter);
89
+ state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
90
+ }
91
+ }
92
+ if (!Array.isArray(value))
93
+ return pushError(state, `Expected a tuple (got ${getPrintable(value)})`);
94
+ let valid = lengthValidator(value, Object.assign({}, state));
95
+ for (let t = 0, T = value.length; t < T && t < spec.length; ++t) {
96
+ valid = spec[t](value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
97
+ if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
98
+ break;
99
+ }
100
+ }
101
+ return valid;
102
+ }
103
+ });
104
+ }
105
+ function isRecord(spec, { keys: keySpec = null } = {}) {
106
+ const isArrayValidator = isArray(isTuple([keySpec !== null && keySpec !== void 0 ? keySpec : isString(), spec]));
107
+ return makeValidator({
108
+ test: (value, state) => {
109
+ var _a;
110
+ if (Array.isArray(value)) {
111
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
112
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
113
+ return pushError(state, `Unbound coercion result`);
114
+ if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
115
+ return false;
116
+ value = Object.fromEntries(value);
117
+ state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
118
+ return true;
119
+ }
120
+ }
121
+ if (typeof value !== `object` || value === null)
122
+ return pushError(state, `Expected an object (got ${getPrintable(value)})`);
123
+ const keys = Object.keys(value);
124
+ let valid = true;
125
+ for (let t = 0, T = keys.length; t < T && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null); ++t) {
126
+ const key = keys[t];
127
+ const sub = value[key];
128
+ if (key === `__proto__` || key === `constructor`) {
129
+ valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
130
+ continue;
131
+ }
132
+ if (keySpec !== null && !keySpec(key, state)) {
133
+ valid = false;
134
+ continue;
135
+ }
136
+ if (!spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) }))) {
137
+ valid = false;
138
+ continue;
139
+ }
140
+ }
141
+ return valid;
142
+ }
143
+ });
144
+ }
145
+ function isDict(spec, opts = {}) {
146
+ return isRecord(spec, opts);
147
+ }
148
+ function makeTrait(value) {
149
+ return () => {
150
+ return value;
151
+ };
152
+ }
153
+ function makeValidator({ test }) {
154
+ return makeTrait(test)();
155
+ }
156
+ function hasExactLength(length) {
157
+ return makeValidator({
158
+ test: (value, state) => {
159
+ if (!(value.length === length))
160
+ return pushError(state, `Expected to have a length of exactly ${length} elements (got ${value.length})`);
161
+ return true;
162
+ }
163
+ });
164
+ }
165
+ function cascade(spec, ...followups) {
166
+ const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
167
+ return makeValidator({
168
+ test: (value, state) => {
169
+ var _a, _b;
170
+ const context = { value };
171
+ const subCoercion = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? makeCoercionFn(context, `value`) : void 0;
172
+ const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
173
+ if (!spec(value, Object.assign(Object.assign({}, state), { coercion: subCoercion, coercions: subCoercions })))
174
+ return false;
175
+ const reverts = [];
176
+ if (typeof subCoercions !== `undefined`)
177
+ for (const [, coercion] of subCoercions)
178
+ reverts.push(coercion());
179
+ try {
180
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
181
+ if (context.value !== value) {
182
+ if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
183
+ return pushError(state, `Unbound coercion result`);
184
+ state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, context.value)]);
185
+ }
186
+ (_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
187
+ }
188
+ return resolvedFollowups.every((spec2) => {
189
+ return spec2(context.value, state);
190
+ });
191
+ } finally {
192
+ for (const revert of reverts) {
193
+ revert();
194
+ }
195
+ }
196
+ }
197
+ });
198
+ }
199
+ function applyCascade(spec, ...followups) {
200
+ const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
201
+ return cascade(spec, resolvedFollowups);
202
+ }
203
+ var KeyRelationship;
204
+ (function(KeyRelationship2) {
205
+ KeyRelationship2["Forbids"] = "Forbids";
206
+ KeyRelationship2["Requires"] = "Requires";
207
+ })(KeyRelationship || (KeyRelationship = {}));
208
+ ({
209
+ [KeyRelationship.Forbids]: {
210
+ },
211
+ [KeyRelationship.Requires]: {
212
+ }
213
+ });
214
+
215
+ export { KeyRelationship, applyCascade, cascade, hasExactLength, isArray, isDict, isRecord, isString, isTuple, isUnknown, makeTrait, makeValidator };
@@ -32,14 +32,12 @@ var Nt = (t, e, n) => (n = t != null ? St(At(t)) : {}, $t(
32
32
  $(n, "default", { value: t, enumerable: true }) ,
33
33
  t
34
34
  ));
35
-
36
- // node_modules/isexe/windows.js
37
35
  var W = l((Se, H) => {
38
36
  H.exports = z;
39
37
  z.sync = Wt;
40
38
  var j = h("fs");
41
39
  function Ht(t, e) {
42
- var n = e.pathExt !== undefined ? e.pathExt : process.env.PATHEXT;
40
+ var n = e.pathExt !== void 0 ? e.pathExt : process.env.PATHEXT;
43
41
  if (!n || (n = n.split(";"), n.indexOf("") !== -1))
44
42
  return true;
45
43
  for (var r = 0; r < n.length; r++) {
@@ -61,8 +59,6 @@ var W = l((Se, H) => {
61
59
  return F(j.statSync(t), t, e);
62
60
  }
63
61
  });
64
-
65
- // node_modules/isexe/mode.js
66
62
  var X = l((ke, B) => {
67
63
  B.exports = K;
68
64
  K.sync = Dt;
@@ -79,12 +75,10 @@ var X = l((ke, B) => {
79
75
  return t.isFile() && Kt(t, e);
80
76
  }
81
77
  function Kt(t, e) {
82
- var n = t.mode, r = t.uid, s = t.gid, o = e.uid !== undefined ? e.uid : process.getuid && process.getuid(), i = e.gid !== undefined ? e.gid : process.getgid && process.getgid(), a = parseInt("100", 8), c = parseInt("010", 8), u = parseInt("001", 8), f = a | c, p = n & u || n & c && s === i || n & a && r === o || n & f && o === 0;
78
+ var n = t.mode, r = t.uid, s = t.gid, o = e.uid !== void 0 ? e.uid : process.getuid && process.getuid(), i = e.gid !== void 0 ? e.gid : process.getgid && process.getgid(), a = parseInt("100", 8), c = parseInt("010", 8), u = parseInt("001", 8), f = a | c, p = n & u || n & c && s === i || n & a && r === o || n & f && o === 0;
83
79
  return p;
84
80
  }
85
81
  });
86
-
87
- // node_modules/isexe/index.js
88
82
  var U = l((Ae, G) => {
89
83
  h("fs"); var v;
90
84
  process.platform === "win32" || global.TESTING_WINDOWS ? v = W() : v = X();
@@ -114,8 +108,6 @@ var U = l((Ae, G) => {
114
108
  }
115
109
  }
116
110
  });
117
-
118
- // node_modules/which/which.js
119
111
  var et = l((Re, tt) => {
120
112
  var g = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys", Y = h("path"), Bt = g ? ";" : ":", V = U(), J = (t) => Object.assign(new Error(`not found: ${t}`), { code: "ENOENT" }), Q = (t, e) => {
121
113
  let n = e.colon || Bt, r = t.match(/\//) || g && t.match(/\\/) ? [""] : [
@@ -176,8 +168,6 @@ var et = l((Re, tt) => {
176
168
  tt.exports = Z;
177
169
  Z.sync = Xt;
178
170
  });
179
-
180
- // node_modules/path-key/index.js
181
171
  var rt = l(($e, _) => {
182
172
  var nt = (t = {}) => {
183
173
  let e = t.env || process.env;
@@ -186,12 +176,10 @@ var rt = l(($e, _) => {
186
176
  _.exports = nt;
187
177
  _.exports.default = nt;
188
178
  });
189
-
190
- // node_modules/cross-spawn/lib/util/resolveCommand.js
191
179
  var ct = l((Ne, it) => {
192
180
  var st = h("path"), Gt = et(), Ut = rt();
193
181
  function ot(t, e) {
194
- let n = t.options.env || process.env, r = process.cwd(), s = t.options.cwd != null, o = s && process.chdir !== undefined && !process.chdir.disabled;
182
+ let n = t.options.env || process.env, r = process.cwd(), s = t.options.cwd != null, o = s && process.chdir !== void 0 && !process.chdir.disabled;
195
183
  if (o)
196
184
  try {
197
185
  process.chdir(t.options.cwd);
@@ -214,8 +202,6 @@ var ct = l((Ne, it) => {
214
202
  }
215
203
  it.exports = Yt;
216
204
  });
217
-
218
- // node_modules/cross-spawn/lib/util/escape.js
219
205
  var ut = l((qe, P) => {
220
206
  var C = /([()\][%!^"`<>&|;, *?])/g;
221
207
  function Vt(t) {
@@ -227,13 +213,9 @@ var ut = l((qe, P) => {
227
213
  P.exports.command = Vt;
228
214
  P.exports.argument = Jt;
229
215
  });
230
-
231
- // node_modules/shebang-regex/index.js
232
216
  var lt = l((Ie, at) => {
233
217
  at.exports = /^#!(.*)/;
234
218
  });
235
-
236
- // node_modules/shebang-command/index.js
237
219
  var dt = l((Le, pt) => {
238
220
  var Qt = lt();
239
221
  pt.exports = (t = "") => {
@@ -244,8 +226,6 @@ var dt = l((Le, pt) => {
244
226
  return s === "env" ? r : r ? `${s} ${r}` : s;
245
227
  };
246
228
  });
247
-
248
- // node_modules/cross-spawn/lib/util/readShebang.js
249
229
  var ht = l((je, ft) => {
250
230
  var O = h("fs"), Zt = dt();
251
231
  function te(t) {
@@ -258,8 +238,6 @@ var ht = l((je, ft) => {
258
238
  }
259
239
  ft.exports = te;
260
240
  });
261
-
262
- // node_modules/cross-spawn/lib/parse.js
263
241
  var wt = l((Fe, Et) => {
264
242
  var ee = h("path"), mt = ct(), gt = ut(), ne = ht(), re = process.platform === "win32", se = /\.(?:com|exe)$/i, oe = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
265
243
  function ie(t) {
@@ -285,7 +263,7 @@ var wt = l((Fe, Et) => {
285
263
  command: t,
286
264
  args: e,
287
265
  options: n,
288
- file: undefined,
266
+ file: void 0,
289
267
  original: {
290
268
  command: t,
291
269
  args: e
@@ -295,8 +273,6 @@ var wt = l((Fe, Et) => {
295
273
  }
296
274
  Et.exports = ue;
297
275
  });
298
-
299
- // node_modules/cross-spawn/lib/enoent.js
300
276
  var bt = l((ze, vt) => {
301
277
  var S = process.platform === "win32";
302
278
  function k(t, e) {
@@ -334,8 +310,6 @@ var bt = l((ze, vt) => {
334
310
  notFoundError: k
335
311
  };
336
312
  });
337
-
338
- // node_modules/cross-spawn/index.js
339
313
  var Ct = l((He, E) => {
340
314
  var yt = h("child_process"), T = wt(), A = bt();
341
315
  function _t(t, e, n) {
@@ -384,11 +358,7 @@ var L = (t) => {
384
358
  s.pipe(n, { end: false }), s.on("end", r);
385
359
  return n;
386
360
  };
387
-
388
- // src/main.ts
389
361
  var Pt = Nt(Ct());
390
-
391
- // src/non-zero-exit-error.ts
392
362
  var x = class extends Error {
393
363
  result;
394
364
  output;
@@ -400,10 +370,8 @@ var x = class extends Error {
400
370
  super(`Process exited with non-zero status (${e.exitCode})`), this.result = e, this.output = n;
401
371
  }
402
372
  };
403
-
404
- // src/main.ts
405
373
  var ge = {
406
- timeout: undefined,
374
+ timeout: void 0,
407
375
  persist: false
408
376
  }, Ee = {
409
377
  windowsHide: true
@@ -483,7 +451,7 @@ var R = class {
483
451
  yield o.toString();
484
452
  if (await this._processClosed, e.removeAllListeners(), this._thrownError)
485
453
  throw this._thrownError;
486
- if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== undefined)
454
+ if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
487
455
  throw new x(this);
488
456
  }
489
457
  async _waitForOutput() {
@@ -504,7 +472,7 @@ var R = class {
504
472
  stdout: r,
505
473
  exitCode: this.exitCode
506
474
  };
507
- if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== undefined)
475
+ if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0)
508
476
  throw new x(this, s);
509
477
  return s;
510
478
  }
@@ -518,13 +486,13 @@ var R = class {
518
486
  ...Ee,
519
487
  ...n.nodeOptions
520
488
  }, s = [];
521
- this._resetState(), n.timeout !== undefined && s.push(AbortSignal.timeout(n.timeout)), n.signal !== undefined && s.push(n.signal), n.persist === true && (r.detached = true), s.length > 0 && (r.signal = xe(s)), r.env = I(e, r.env);
489
+ this._resetState(), n.timeout !== void 0 && s.push(AbortSignal.timeout(n.timeout)), n.signal !== void 0 && s.push(n.signal), n.persist === true && (r.detached = true), s.length > 0 && (r.signal = xe(s)), r.env = I(e, r.env);
522
490
  let { command: o, args: i } = we(this._command, this._args), a = (0, Pt._parse)(o, i, r), c = spawn(
523
491
  a.command,
524
492
  a.args,
525
493
  a.options
526
494
  );
527
- if (c.stderr && (this._streamErr = c.stderr), c.stdout && (this._streamOut = c.stdout), this._process = c, c.once("error", this._onError), c.once("close", this._onClose), n.stdin !== undefined && c.stdin && n.stdin.process) {
495
+ if (c.stderr && (this._streamErr = c.stderr), c.stdout && (this._streamOut = c.stdout), this._process = c, c.once("error", this._onError), c.once("close", this._onClose), n.stdin !== void 0 && c.stdin && n.stdin.process) {
528
496
  let { stdout: u } = n.stdin.process;
529
497
  u && u.pipe(c.stdin);
530
498
  }
@@ -532,7 +500,7 @@ var R = class {
532
500
  _resetState() {
533
501
  this._aborted = false, this._processClosed = new Promise((e) => {
534
502
  this._resolveClose = e;
535
- }), this._thrownError = undefined;
503
+ }), this._thrownError = void 0;
536
504
  }
537
505
  _onError = (e) => {
538
506
  if (e.name === "AbortError" && (!(e.cause instanceof Error) || e.cause.name !== "TimeoutError")) {