@jujulego/jill 2.4.0 → 2.5.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.
@@ -0,0 +1,2083 @@
1
+ import { withTimestamp, LogLevel, quick, qlevelColor, toStderr, Logger, logger$, withLabel } from '@jujulego/logger';
2
+ import { _ } from '@swc/helpers/_/_ts_decorate';
3
+ import { _ as _$1 } from '@swc/helpers/_/_ts_param';
4
+ import { Container, decorate, injectable, inject, ContainerModule } from 'inversify';
5
+ import { AsyncLocalStorage } from 'node:async_hooks';
6
+ import { SpawnTask, GroupTask, TaskSet, TaskManager } from '@jujulego/tasks';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import Ajv from 'ajv';
10
+ import wt, { BroadcastChannel, setEnvironmentData, getEnvironmentData } from 'node:worker_threads';
11
+ import yargs from 'yargs';
12
+ import { hideBin } from 'yargs/helpers';
13
+ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
14
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
+ import { Box, Text, useStderr, render } from 'ink';
16
+ import Spinner from 'ink-spinner';
17
+ import symbols from 'log-symbols';
18
+ import ms from 'pretty-ms';
19
+ import { useState, useLayoutEffect } from 'react';
20
+ import { source$, once$, waitFor$ } from '@jujulego/event-tree';
21
+ import getDecorators from 'inversify-inject-decorators';
22
+ import { flow$, filter$, var$ } from '@jujulego/aegis';
23
+ import { qprop } from '@jujulego/quick-tag';
24
+ import { chalkTemplateStderr } from 'chalk-template';
25
+
26
+ /*! *****************************************************************************
27
+ Copyright (C) Microsoft. All rights reserved.
28
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
29
+ this file except in compliance with the License. You may obtain a copy of the
30
+ License at http://www.apache.org/licenses/LICENSE-2.0
31
+
32
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
33
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
34
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
35
+ MERCHANTABLITY OR NON-INFRINGEMENT.
36
+
37
+ See the Apache Version 2.0 License for specific language governing permissions
38
+ and limitations under the License.
39
+ ***************************************************************************** */ var Reflect$1;
40
+ (function(Reflect) {
41
+ // Metadata Proposal
42
+ // https://rbuckton.github.io/reflect-metadata/
43
+ (function(factory) {
44
+ var root = typeof globalThis === "object" ? globalThis : typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : sloppyModeThis();
45
+ var exporter = makeExporter(Reflect);
46
+ if (typeof root.Reflect !== "undefined") {
47
+ exporter = makeExporter(root.Reflect, exporter);
48
+ }
49
+ factory(exporter, root);
50
+ if (typeof root.Reflect === "undefined") {
51
+ root.Reflect = Reflect;
52
+ }
53
+ function makeExporter(target, previous) {
54
+ return function(key, value) {
55
+ Object.defineProperty(target, key, {
56
+ configurable: true,
57
+ writable: true,
58
+ value: value
59
+ });
60
+ if (previous) previous(key, value);
61
+ };
62
+ }
63
+ function sloppyModeThis() {
64
+ throw new ReferenceError("globalThis could not be found. Please polyfill globalThis before loading this module.");
65
+ }
66
+ })(function(exporter, root) {
67
+ // feature test for Symbol support
68
+ var supportsSymbol = typeof Symbol === "function";
69
+ var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : fail("Symbol.toPrimitive not found.");
70
+ var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : fail("Symbol.iterator not found.");
71
+ // Load global or shim versions of Map, Set, and WeakMap
72
+ var functionPrototype = Object.getPrototypeOf(Function);
73
+ var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : fail("A valid Map constructor could not be found.");
74
+ var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : fail("A valid Set constructor could not be found.");
75
+ var _WeakMap = typeof WeakMap === "function" ? WeakMap : fail("A valid WeakMap constructor could not be found.");
76
+ var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : undefined;
77
+ var metadataRegistry = GetOrCreateMetadataRegistry();
78
+ var metadataProvider = CreateMetadataProvider(metadataRegistry);
79
+ /**
80
+ * Applies a set of decorators to a property of a target object.
81
+ * @param decorators An array of decorators.
82
+ * @param target The target object.
83
+ * @param propertyKey (Optional) The property key to decorate.
84
+ * @param attributes (Optional) The property descriptor for the target key.
85
+ * @remarks Decorators are applied in reverse order.
86
+ * @example
87
+ *
88
+ * class Example {
89
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
90
+ * // static staticProperty;
91
+ * // property;
92
+ *
93
+ * constructor(p) { }
94
+ * static staticMethod(p) { }
95
+ * method(p) { }
96
+ * }
97
+ *
98
+ * // constructor
99
+ * Example = Reflect.decorate(decoratorsArray, Example);
100
+ *
101
+ * // property (on constructor)
102
+ * Reflect.decorate(decoratorsArray, Example, "staticProperty");
103
+ *
104
+ * // property (on prototype)
105
+ * Reflect.decorate(decoratorsArray, Example.prototype, "property");
106
+ *
107
+ * // method (on constructor)
108
+ * Object.defineProperty(Example, "staticMethod",
109
+ * Reflect.decorate(decoratorsArray, Example, "staticMethod",
110
+ * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
111
+ *
112
+ * // method (on prototype)
113
+ * Object.defineProperty(Example.prototype, "method",
114
+ * Reflect.decorate(decoratorsArray, Example.prototype, "method",
115
+ * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
116
+ *
117
+ */ function decorate(decorators, target, propertyKey, attributes) {
118
+ if (!IsUndefined(propertyKey)) {
119
+ if (!IsArray(decorators)) throw new TypeError();
120
+ if (!IsObject(target)) throw new TypeError();
121
+ if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes)) throw new TypeError();
122
+ if (IsNull(attributes)) attributes = undefined;
123
+ propertyKey = ToPropertyKey(propertyKey);
124
+ return DecorateProperty(decorators, target, propertyKey, attributes);
125
+ } else {
126
+ if (!IsArray(decorators)) throw new TypeError();
127
+ if (!IsConstructor(target)) throw new TypeError();
128
+ return DecorateConstructor(decorators, target);
129
+ }
130
+ }
131
+ exporter("decorate", decorate);
132
+ // 4.1.2 Reflect.metadata(metadataKey, metadataValue)
133
+ // https://rbuckton.github.io/reflect-metadata/#reflect.metadata
134
+ /**
135
+ * A default metadata decorator factory that can be used on a class, class member, or parameter.
136
+ * @param metadataKey The key for the metadata entry.
137
+ * @param metadataValue The value for the metadata entry.
138
+ * @returns A decorator function.
139
+ * @remarks
140
+ * If `metadataKey` is already defined for the target and target key, the
141
+ * metadataValue for that key will be overwritten.
142
+ * @example
143
+ *
144
+ * // constructor
145
+ * @Reflect.metadata(key, value)
146
+ * class Example {
147
+ * }
148
+ *
149
+ * // property (on constructor, TypeScript only)
150
+ * class Example {
151
+ * @Reflect.metadata(key, value)
152
+ * static staticProperty;
153
+ * }
154
+ *
155
+ * // property (on prototype, TypeScript only)
156
+ * class Example {
157
+ * @Reflect.metadata(key, value)
158
+ * property;
159
+ * }
160
+ *
161
+ * // method (on constructor)
162
+ * class Example {
163
+ * @Reflect.metadata(key, value)
164
+ * static staticMethod() { }
165
+ * }
166
+ *
167
+ * // method (on prototype)
168
+ * class Example {
169
+ * @Reflect.metadata(key, value)
170
+ * method() { }
171
+ * }
172
+ *
173
+ */ function metadata(metadataKey, metadataValue) {
174
+ function decorator(target, propertyKey) {
175
+ if (!IsObject(target)) throw new TypeError();
176
+ if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey)) throw new TypeError();
177
+ OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
178
+ }
179
+ return decorator;
180
+ }
181
+ exporter("metadata", metadata);
182
+ /**
183
+ * Define a unique metadata entry on the target.
184
+ * @param metadataKey A key used to store and retrieve metadata.
185
+ * @param metadataValue A value that contains attached metadata.
186
+ * @param target The target object on which to define metadata.
187
+ * @param propertyKey (Optional) The property key for the target.
188
+ * @example
189
+ *
190
+ * class Example {
191
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
192
+ * // static staticProperty;
193
+ * // property;
194
+ *
195
+ * constructor(p) { }
196
+ * static staticMethod(p) { }
197
+ * method(p) { }
198
+ * }
199
+ *
200
+ * // constructor
201
+ * Reflect.defineMetadata("custom:annotation", options, Example);
202
+ *
203
+ * // property (on constructor)
204
+ * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
205
+ *
206
+ * // property (on prototype)
207
+ * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
208
+ *
209
+ * // method (on constructor)
210
+ * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
211
+ *
212
+ * // method (on prototype)
213
+ * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
214
+ *
215
+ * // decorator factory as metadata-producing annotation.
216
+ * function MyAnnotation(options): Decorator {
217
+ * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
218
+ * }
219
+ *
220
+ */ function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
221
+ if (!IsObject(target)) throw new TypeError();
222
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
223
+ return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
224
+ }
225
+ exporter("defineMetadata", defineMetadata);
226
+ /**
227
+ * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
228
+ * @param metadataKey A key used to store and retrieve metadata.
229
+ * @param target The target object on which the metadata is defined.
230
+ * @param propertyKey (Optional) The property key for the target.
231
+ * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
232
+ * @example
233
+ *
234
+ * class Example {
235
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
236
+ * // static staticProperty;
237
+ * // property;
238
+ *
239
+ * constructor(p) { }
240
+ * static staticMethod(p) { }
241
+ * method(p) { }
242
+ * }
243
+ *
244
+ * // constructor
245
+ * result = Reflect.hasMetadata("custom:annotation", Example);
246
+ *
247
+ * // property (on constructor)
248
+ * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
249
+ *
250
+ * // property (on prototype)
251
+ * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
252
+ *
253
+ * // method (on constructor)
254
+ * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
255
+ *
256
+ * // method (on prototype)
257
+ * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
258
+ *
259
+ */ function hasMetadata(metadataKey, target, propertyKey) {
260
+ if (!IsObject(target)) throw new TypeError();
261
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
262
+ return OrdinaryHasMetadata(metadataKey, target, propertyKey);
263
+ }
264
+ exporter("hasMetadata", hasMetadata);
265
+ /**
266
+ * Gets a value indicating whether the target object has the provided metadata key defined.
267
+ * @param metadataKey A key used to store and retrieve metadata.
268
+ * @param target The target object on which the metadata is defined.
269
+ * @param propertyKey (Optional) The property key for the target.
270
+ * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
271
+ * @example
272
+ *
273
+ * class Example {
274
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
275
+ * // static staticProperty;
276
+ * // property;
277
+ *
278
+ * constructor(p) { }
279
+ * static staticMethod(p) { }
280
+ * method(p) { }
281
+ * }
282
+ *
283
+ * // constructor
284
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example);
285
+ *
286
+ * // property (on constructor)
287
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
288
+ *
289
+ * // property (on prototype)
290
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
291
+ *
292
+ * // method (on constructor)
293
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
294
+ *
295
+ * // method (on prototype)
296
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
297
+ *
298
+ */ function hasOwnMetadata(metadataKey, target, propertyKey) {
299
+ if (!IsObject(target)) throw new TypeError();
300
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
301
+ return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
302
+ }
303
+ exporter("hasOwnMetadata", hasOwnMetadata);
304
+ /**
305
+ * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
306
+ * @param metadataKey A key used to store and retrieve metadata.
307
+ * @param target The target object on which the metadata is defined.
308
+ * @param propertyKey (Optional) The property key for the target.
309
+ * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
310
+ * @example
311
+ *
312
+ * class Example {
313
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
314
+ * // static staticProperty;
315
+ * // property;
316
+ *
317
+ * constructor(p) { }
318
+ * static staticMethod(p) { }
319
+ * method(p) { }
320
+ * }
321
+ *
322
+ * // constructor
323
+ * result = Reflect.getMetadata("custom:annotation", Example);
324
+ *
325
+ * // property (on constructor)
326
+ * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
327
+ *
328
+ * // property (on prototype)
329
+ * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
330
+ *
331
+ * // method (on constructor)
332
+ * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
333
+ *
334
+ * // method (on prototype)
335
+ * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
336
+ *
337
+ */ function getMetadata(metadataKey, target, propertyKey) {
338
+ if (!IsObject(target)) throw new TypeError();
339
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
340
+ return OrdinaryGetMetadata(metadataKey, target, propertyKey);
341
+ }
342
+ exporter("getMetadata", getMetadata);
343
+ /**
344
+ * Gets the metadata value for the provided metadata key on the target object.
345
+ * @param metadataKey A key used to store and retrieve metadata.
346
+ * @param target The target object on which the metadata is defined.
347
+ * @param propertyKey (Optional) The property key for the target.
348
+ * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
349
+ * @example
350
+ *
351
+ * class Example {
352
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
353
+ * // static staticProperty;
354
+ * // property;
355
+ *
356
+ * constructor(p) { }
357
+ * static staticMethod(p) { }
358
+ * method(p) { }
359
+ * }
360
+ *
361
+ * // constructor
362
+ * result = Reflect.getOwnMetadata("custom:annotation", Example);
363
+ *
364
+ * // property (on constructor)
365
+ * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
366
+ *
367
+ * // property (on prototype)
368
+ * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
369
+ *
370
+ * // method (on constructor)
371
+ * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
372
+ *
373
+ * // method (on prototype)
374
+ * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
375
+ *
376
+ */ function getOwnMetadata(metadataKey, target, propertyKey) {
377
+ if (!IsObject(target)) throw new TypeError();
378
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
379
+ return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
380
+ }
381
+ exporter("getOwnMetadata", getOwnMetadata);
382
+ /**
383
+ * Gets the metadata keys defined on the target object or its prototype chain.
384
+ * @param target The target object on which the metadata is defined.
385
+ * @param propertyKey (Optional) The property key for the target.
386
+ * @returns An array of unique metadata keys.
387
+ * @example
388
+ *
389
+ * class Example {
390
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
391
+ * // static staticProperty;
392
+ * // property;
393
+ *
394
+ * constructor(p) { }
395
+ * static staticMethod(p) { }
396
+ * method(p) { }
397
+ * }
398
+ *
399
+ * // constructor
400
+ * result = Reflect.getMetadataKeys(Example);
401
+ *
402
+ * // property (on constructor)
403
+ * result = Reflect.getMetadataKeys(Example, "staticProperty");
404
+ *
405
+ * // property (on prototype)
406
+ * result = Reflect.getMetadataKeys(Example.prototype, "property");
407
+ *
408
+ * // method (on constructor)
409
+ * result = Reflect.getMetadataKeys(Example, "staticMethod");
410
+ *
411
+ * // method (on prototype)
412
+ * result = Reflect.getMetadataKeys(Example.prototype, "method");
413
+ *
414
+ */ function getMetadataKeys(target, propertyKey) {
415
+ if (!IsObject(target)) throw new TypeError();
416
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
417
+ return OrdinaryMetadataKeys(target, propertyKey);
418
+ }
419
+ exporter("getMetadataKeys", getMetadataKeys);
420
+ /**
421
+ * Gets the unique metadata keys defined on the target object.
422
+ * @param target The target object on which the metadata is defined.
423
+ * @param propertyKey (Optional) The property key for the target.
424
+ * @returns An array of unique metadata keys.
425
+ * @example
426
+ *
427
+ * class Example {
428
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
429
+ * // static staticProperty;
430
+ * // property;
431
+ *
432
+ * constructor(p) { }
433
+ * static staticMethod(p) { }
434
+ * method(p) { }
435
+ * }
436
+ *
437
+ * // constructor
438
+ * result = Reflect.getOwnMetadataKeys(Example);
439
+ *
440
+ * // property (on constructor)
441
+ * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
442
+ *
443
+ * // property (on prototype)
444
+ * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
445
+ *
446
+ * // method (on constructor)
447
+ * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
448
+ *
449
+ * // method (on prototype)
450
+ * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
451
+ *
452
+ */ function getOwnMetadataKeys(target, propertyKey) {
453
+ if (!IsObject(target)) throw new TypeError();
454
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
455
+ return OrdinaryOwnMetadataKeys(target, propertyKey);
456
+ }
457
+ exporter("getOwnMetadataKeys", getOwnMetadataKeys);
458
+ /**
459
+ * Deletes the metadata entry from the target object with the provided key.
460
+ * @param metadataKey A key used to store and retrieve metadata.
461
+ * @param target The target object on which the metadata is defined.
462
+ * @param propertyKey (Optional) The property key for the target.
463
+ * @returns `true` if the metadata entry was found and deleted; otherwise, false.
464
+ * @example
465
+ *
466
+ * class Example {
467
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
468
+ * // static staticProperty;
469
+ * // property;
470
+ *
471
+ * constructor(p) { }
472
+ * static staticMethod(p) { }
473
+ * method(p) { }
474
+ * }
475
+ *
476
+ * // constructor
477
+ * result = Reflect.deleteMetadata("custom:annotation", Example);
478
+ *
479
+ * // property (on constructor)
480
+ * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
481
+ *
482
+ * // property (on prototype)
483
+ * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
484
+ *
485
+ * // method (on constructor)
486
+ * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
487
+ *
488
+ * // method (on prototype)
489
+ * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
490
+ *
491
+ */ function deleteMetadata(metadataKey, target, propertyKey) {
492
+ if (!IsObject(target)) throw new TypeError();
493
+ if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
494
+ var provider = GetMetadataProvider(target, propertyKey, /*Create*/ false);
495
+ if (IsUndefined(provider)) return false;
496
+ return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
497
+ }
498
+ exporter("deleteMetadata", deleteMetadata);
499
+ function DecorateConstructor(decorators, target) {
500
+ for(var i = decorators.length - 1; i >= 0; --i){
501
+ var decorator = decorators[i];
502
+ var decorated = decorator(target);
503
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
504
+ if (!IsConstructor(decorated)) throw new TypeError();
505
+ target = decorated;
506
+ }
507
+ }
508
+ return target;
509
+ }
510
+ function DecorateProperty(decorators, target, propertyKey, descriptor) {
511
+ for(var i = decorators.length - 1; i >= 0; --i){
512
+ var decorator = decorators[i];
513
+ var decorated = decorator(target, propertyKey, descriptor);
514
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
515
+ if (!IsObject(decorated)) throw new TypeError();
516
+ descriptor = decorated;
517
+ }
518
+ }
519
+ return descriptor;
520
+ }
521
+ // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
522
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
523
+ function OrdinaryHasMetadata(MetadataKey, O, P) {
524
+ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
525
+ if (hasOwn) return true;
526
+ var parent = OrdinaryGetPrototypeOf(O);
527
+ if (!IsNull(parent)) return OrdinaryHasMetadata(MetadataKey, parent, P);
528
+ return false;
529
+ }
530
+ // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
531
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
532
+ function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
533
+ var provider = GetMetadataProvider(O, P, /*Create*/ false);
534
+ if (IsUndefined(provider)) return false;
535
+ return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
536
+ }
537
+ // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
538
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
539
+ function OrdinaryGetMetadata(MetadataKey, O, P) {
540
+ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
541
+ if (hasOwn) return OrdinaryGetOwnMetadata(MetadataKey, O, P);
542
+ var parent = OrdinaryGetPrototypeOf(O);
543
+ if (!IsNull(parent)) return OrdinaryGetMetadata(MetadataKey, parent, P);
544
+ return undefined;
545
+ }
546
+ // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
547
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
548
+ function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
549
+ var provider = GetMetadataProvider(O, P, /*Create*/ false);
550
+ if (IsUndefined(provider)) return;
551
+ return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
552
+ }
553
+ // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
554
+ // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
555
+ function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
556
+ var provider = GetMetadataProvider(O, P, /*Create*/ true);
557
+ provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
558
+ }
559
+ // 3.1.6.1 OrdinaryMetadataKeys(O, P)
560
+ // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
561
+ function OrdinaryMetadataKeys(O, P) {
562
+ var ownKeys = OrdinaryOwnMetadataKeys(O, P);
563
+ var parent = OrdinaryGetPrototypeOf(O);
564
+ if (parent === null) return ownKeys;
565
+ var parentKeys = OrdinaryMetadataKeys(parent, P);
566
+ if (parentKeys.length <= 0) return ownKeys;
567
+ if (ownKeys.length <= 0) return parentKeys;
568
+ var set = new _Set();
569
+ var keys = [];
570
+ for(var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++){
571
+ var key = ownKeys_1[_i];
572
+ var hasKey = set.has(key);
573
+ if (!hasKey) {
574
+ set.add(key);
575
+ keys.push(key);
576
+ }
577
+ }
578
+ for(var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++){
579
+ var key = parentKeys_1[_a];
580
+ var hasKey = set.has(key);
581
+ if (!hasKey) {
582
+ set.add(key);
583
+ keys.push(key);
584
+ }
585
+ }
586
+ return keys;
587
+ }
588
+ // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
589
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
590
+ function OrdinaryOwnMetadataKeys(O, P) {
591
+ var provider = GetMetadataProvider(O, P, /*create*/ false);
592
+ if (!provider) {
593
+ return [];
594
+ }
595
+ return provider.OrdinaryOwnMetadataKeys(O, P);
596
+ }
597
+ // 6 ECMAScript Data Typ0es and Values
598
+ // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
599
+ function Type(x) {
600
+ if (x === null) return 1 /* Null */ ;
601
+ switch(typeof x){
602
+ case "undefined":
603
+ return 0 /* Undefined */ ;
604
+ case "boolean":
605
+ return 2 /* Boolean */ ;
606
+ case "string":
607
+ return 3 /* String */ ;
608
+ case "symbol":
609
+ return 4 /* Symbol */ ;
610
+ case "number":
611
+ return 5 /* Number */ ;
612
+ case "object":
613
+ return x === null ? 1 /* Null */ : 6 /* Object */ ;
614
+ default:
615
+ return 6 /* Object */ ;
616
+ }
617
+ }
618
+ // 6.1.1 The Undefined Type
619
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
620
+ function IsUndefined(x) {
621
+ return x === undefined;
622
+ }
623
+ // 6.1.2 The Null Type
624
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
625
+ function IsNull(x) {
626
+ return x === null;
627
+ }
628
+ // 6.1.5 The Symbol Type
629
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
630
+ function IsSymbol(x) {
631
+ return typeof x === "symbol";
632
+ }
633
+ // 6.1.7 The Object Type
634
+ // https://tc39.github.io/ecma262/#sec-object-type
635
+ function IsObject(x) {
636
+ return typeof x === "object" ? x !== null : typeof x === "function";
637
+ }
638
+ // 7.1 Type Conversion
639
+ // https://tc39.github.io/ecma262/#sec-type-conversion
640
+ // 7.1.1 ToPrimitive(input [, PreferredType])
641
+ // https://tc39.github.io/ecma262/#sec-toprimitive
642
+ function ToPrimitive(input, PreferredType) {
643
+ switch(Type(input)){
644
+ case 0 /* Undefined */ :
645
+ return input;
646
+ case 1 /* Null */ :
647
+ return input;
648
+ case 2 /* Boolean */ :
649
+ return input;
650
+ case 3 /* String */ :
651
+ return input;
652
+ case 4 /* Symbol */ :
653
+ return input;
654
+ case 5 /* Number */ :
655
+ return input;
656
+ }
657
+ var hint = PreferredType === 3 /* String */ ? "string" : PreferredType === 5 /* Number */ ? "number" : "default";
658
+ var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
659
+ if (exoticToPrim !== undefined) {
660
+ var result = exoticToPrim.call(input, hint);
661
+ if (IsObject(result)) throw new TypeError();
662
+ return result;
663
+ }
664
+ return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
665
+ }
666
+ // 7.1.1.1 OrdinaryToPrimitive(O, hint)
667
+ // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
668
+ function OrdinaryToPrimitive(O, hint) {
669
+ if (hint === "string") {
670
+ var toString_1 = O.toString;
671
+ if (IsCallable(toString_1)) {
672
+ var result = toString_1.call(O);
673
+ if (!IsObject(result)) return result;
674
+ }
675
+ var valueOf = O.valueOf;
676
+ if (IsCallable(valueOf)) {
677
+ var result = valueOf.call(O);
678
+ if (!IsObject(result)) return result;
679
+ }
680
+ } else {
681
+ var valueOf = O.valueOf;
682
+ if (IsCallable(valueOf)) {
683
+ var result = valueOf.call(O);
684
+ if (!IsObject(result)) return result;
685
+ }
686
+ var toString_2 = O.toString;
687
+ if (IsCallable(toString_2)) {
688
+ var result = toString_2.call(O);
689
+ if (!IsObject(result)) return result;
690
+ }
691
+ }
692
+ throw new TypeError();
693
+ }
694
+ // 7.1.2 ToBoolean(argument)
695
+ // https://tc39.github.io/ecma262/2016/#sec-toboolean
696
+ function ToBoolean(argument) {
697
+ return !!argument;
698
+ }
699
+ // 7.1.12 ToString(argument)
700
+ // https://tc39.github.io/ecma262/#sec-tostring
701
+ function ToString(argument) {
702
+ return "" + argument;
703
+ }
704
+ // 7.1.14 ToPropertyKey(argument)
705
+ // https://tc39.github.io/ecma262/#sec-topropertykey
706
+ function ToPropertyKey(argument) {
707
+ var key = ToPrimitive(argument, 3 /* String */ );
708
+ if (IsSymbol(key)) return key;
709
+ return ToString(key);
710
+ }
711
+ // 7.2 Testing and Comparison Operations
712
+ // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
713
+ // 7.2.2 IsArray(argument)
714
+ // https://tc39.github.io/ecma262/#sec-isarray
715
+ function IsArray(argument) {
716
+ return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
717
+ }
718
+ // 7.2.3 IsCallable(argument)
719
+ // https://tc39.github.io/ecma262/#sec-iscallable
720
+ function IsCallable(argument) {
721
+ // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
722
+ return typeof argument === "function";
723
+ }
724
+ // 7.2.4 IsConstructor(argument)
725
+ // https://tc39.github.io/ecma262/#sec-isconstructor
726
+ function IsConstructor(argument) {
727
+ // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
728
+ return typeof argument === "function";
729
+ }
730
+ // 7.2.7 IsPropertyKey(argument)
731
+ // https://tc39.github.io/ecma262/#sec-ispropertykey
732
+ function IsPropertyKey(argument) {
733
+ switch(Type(argument)){
734
+ case 3 /* String */ :
735
+ return true;
736
+ case 4 /* Symbol */ :
737
+ return true;
738
+ default:
739
+ return false;
740
+ }
741
+ }
742
+ // 7.3 Operations on Objects
743
+ // https://tc39.github.io/ecma262/#sec-operations-on-objects
744
+ // 7.3.9 GetMethod(V, P)
745
+ // https://tc39.github.io/ecma262/#sec-getmethod
746
+ function GetMethod(V, P) {
747
+ var func = V[P];
748
+ if (func === undefined || func === null) return undefined;
749
+ if (!IsCallable(func)) throw new TypeError();
750
+ return func;
751
+ }
752
+ // 7.4 Operations on Iterator Objects
753
+ // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
754
+ function GetIterator(obj) {
755
+ var method = GetMethod(obj, iteratorSymbol);
756
+ if (!IsCallable(method)) throw new TypeError(); // from Call
757
+ var iterator = method.call(obj);
758
+ if (!IsObject(iterator)) throw new TypeError();
759
+ return iterator;
760
+ }
761
+ // 7.4.4 IteratorValue(iterResult)
762
+ // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
763
+ function IteratorValue(iterResult) {
764
+ return iterResult.value;
765
+ }
766
+ // 7.4.5 IteratorStep(iterator)
767
+ // https://tc39.github.io/ecma262/#sec-iteratorstep
768
+ function IteratorStep(iterator) {
769
+ var result = iterator.next();
770
+ return result.done ? false : result;
771
+ }
772
+ // 7.4.6 IteratorClose(iterator, completion)
773
+ // https://tc39.github.io/ecma262/#sec-iteratorclose
774
+ function IteratorClose(iterator) {
775
+ var f = iterator["return"];
776
+ if (f) f.call(iterator);
777
+ }
778
+ // 9.1 Ordinary Object Internal Methods and Internal Slots
779
+ // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
780
+ // 9.1.1.1 OrdinaryGetPrototypeOf(O)
781
+ // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
782
+ function OrdinaryGetPrototypeOf(O) {
783
+ var proto = Object.getPrototypeOf(O);
784
+ if (typeof O !== "function" || O === functionPrototype) return proto;
785
+ // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
786
+ // Try to determine the superclass constructor. Compatible implementations
787
+ // must either set __proto__ on a subclass constructor to the superclass constructor,
788
+ // or ensure each class has a valid `constructor` property on its prototype that
789
+ // points back to the constructor.
790
+ // If this is not the same as Function.[[Prototype]], then this is definately inherited.
791
+ // This is the case when in ES6 or when using __proto__ in a compatible browser.
792
+ if (proto !== functionPrototype) return proto;
793
+ // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
794
+ var prototype = O.prototype;
795
+ var prototypeProto = prototype && Object.getPrototypeOf(prototype);
796
+ if (prototypeProto == null || prototypeProto === Object.prototype) return proto;
797
+ // If the constructor was not a function, then we cannot determine the heritage.
798
+ var constructor = prototypeProto.constructor;
799
+ if (typeof constructor !== "function") return proto;
800
+ // If we have some kind of self-reference, then we cannot determine the heritage.
801
+ if (constructor === O) return proto;
802
+ // we have a pretty good guess at the heritage.
803
+ return constructor;
804
+ }
805
+ function fail(e) {
806
+ throw e;
807
+ }
808
+ // Global metadata registry
809
+ // - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate.
810
+ // - Uses isolated metadata if `Reflect` is frozen before the registry can be installed.
811
+ /**
812
+ * Creates a registry used to allow multiple `reflect-metadata` providers.
813
+ */ function CreateMetadataRegistry() {
814
+ var fallback;
815
+ if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
816
+ // interoperate with older version of `reflect-metadata` that did not support a registry.
817
+ fallback = CreateFallbackProvider(root.Reflect);
818
+ }
819
+ var first;
820
+ var second;
821
+ var rest;
822
+ var targetProviderMap = new _WeakMap();
823
+ var registry = {
824
+ registerProvider: registerProvider,
825
+ getProvider: getProvider,
826
+ setProvider: setProvider
827
+ };
828
+ return registry;
829
+ function registerProvider(provider) {
830
+ if (!Object.isExtensible(registry)) {
831
+ throw new Error("Cannot add provider to a frozen registry.");
832
+ }
833
+ switch(true){
834
+ case fallback === provider:
835
+ break;
836
+ case IsUndefined(first):
837
+ first = provider;
838
+ break;
839
+ case first === provider:
840
+ break;
841
+ case IsUndefined(second):
842
+ second = provider;
843
+ break;
844
+ case second === provider:
845
+ break;
846
+ default:
847
+ if (rest === undefined) rest = new _Set();
848
+ rest.add(provider);
849
+ break;
850
+ }
851
+ }
852
+ function getProviderNoCache(O, P) {
853
+ if (!IsUndefined(first)) {
854
+ if (first.isProviderFor(O, P)) return first;
855
+ if (!IsUndefined(second)) {
856
+ if (second.isProviderFor(O, P)) return first;
857
+ if (!IsUndefined(rest)) {
858
+ var iterator = GetIterator(rest);
859
+ while(true){
860
+ var next = IteratorStep(iterator);
861
+ if (!next) {
862
+ return undefined;
863
+ }
864
+ var provider = IteratorValue(next);
865
+ if (provider.isProviderFor(O, P)) {
866
+ IteratorClose(iterator);
867
+ return provider;
868
+ }
869
+ }
870
+ }
871
+ }
872
+ }
873
+ if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
874
+ return fallback;
875
+ }
876
+ return undefined;
877
+ }
878
+ function getProvider(O, P) {
879
+ var providerMap = targetProviderMap.get(O);
880
+ var provider;
881
+ if (!IsUndefined(providerMap)) {
882
+ provider = providerMap.get(P);
883
+ }
884
+ if (!IsUndefined(provider)) {
885
+ return provider;
886
+ }
887
+ provider = getProviderNoCache(O, P);
888
+ if (!IsUndefined(provider)) {
889
+ if (IsUndefined(providerMap)) {
890
+ providerMap = new _Map();
891
+ targetProviderMap.set(O, providerMap);
892
+ }
893
+ providerMap.set(P, provider);
894
+ }
895
+ return provider;
896
+ }
897
+ function hasProvider(provider) {
898
+ if (IsUndefined(provider)) throw new TypeError();
899
+ return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
900
+ }
901
+ function setProvider(O, P, provider) {
902
+ if (!hasProvider(provider)) {
903
+ throw new Error("Metadata provider not registered.");
904
+ }
905
+ var existingProvider = getProvider(O, P);
906
+ if (existingProvider !== provider) {
907
+ if (!IsUndefined(existingProvider)) {
908
+ return false;
909
+ }
910
+ var providerMap = targetProviderMap.get(O);
911
+ if (IsUndefined(providerMap)) {
912
+ providerMap = new _Map();
913
+ targetProviderMap.set(O, providerMap);
914
+ }
915
+ providerMap.set(P, provider);
916
+ }
917
+ return true;
918
+ }
919
+ }
920
+ /**
921
+ * Gets or creates the shared registry of metadata providers.
922
+ */ function GetOrCreateMetadataRegistry() {
923
+ var metadataRegistry;
924
+ if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
925
+ metadataRegistry = root.Reflect[registrySymbol];
926
+ }
927
+ if (IsUndefined(metadataRegistry)) {
928
+ metadataRegistry = CreateMetadataRegistry();
929
+ }
930
+ if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
931
+ Object.defineProperty(root.Reflect, registrySymbol, {
932
+ enumerable: false,
933
+ configurable: false,
934
+ writable: false,
935
+ value: metadataRegistry
936
+ });
937
+ }
938
+ return metadataRegistry;
939
+ }
940
+ function CreateMetadataProvider(registry) {
941
+ // [[Metadata]] internal slot
942
+ // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
943
+ var metadata = new _WeakMap();
944
+ var provider = {
945
+ isProviderFor: function(O, P) {
946
+ var targetMetadata = metadata.get(O);
947
+ if (IsUndefined(targetMetadata)) return false;
948
+ return targetMetadata.has(P);
949
+ },
950
+ OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata,
951
+ OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata,
952
+ OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata,
953
+ OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys,
954
+ OrdinaryDeleteMetadata: OrdinaryDeleteMetadata
955
+ };
956
+ metadataRegistry.registerProvider(provider);
957
+ return provider;
958
+ function GetOrCreateMetadataMap(O, P, Create) {
959
+ var targetMetadata = metadata.get(O);
960
+ var createdTargetMetadata = false;
961
+ if (IsUndefined(targetMetadata)) {
962
+ if (!Create) return undefined;
963
+ targetMetadata = new _Map();
964
+ metadata.set(O, targetMetadata);
965
+ createdTargetMetadata = true;
966
+ }
967
+ var metadataMap = targetMetadata.get(P);
968
+ if (IsUndefined(metadataMap)) {
969
+ if (!Create) return undefined;
970
+ metadataMap = new _Map();
971
+ targetMetadata.set(P, metadataMap);
972
+ if (!registry.setProvider(O, P, provider)) {
973
+ targetMetadata.delete(P);
974
+ if (createdTargetMetadata) {
975
+ metadata.delete(O);
976
+ }
977
+ throw new Error("Wrong provider for target.");
978
+ }
979
+ }
980
+ return metadataMap;
981
+ }
982
+ // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
983
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
984
+ function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
985
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
986
+ if (IsUndefined(metadataMap)) return false;
987
+ return ToBoolean(metadataMap.has(MetadataKey));
988
+ }
989
+ // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
990
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
991
+ function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
992
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
993
+ if (IsUndefined(metadataMap)) return undefined;
994
+ return metadataMap.get(MetadataKey);
995
+ }
996
+ // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
997
+ // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
998
+ function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
999
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
1000
+ metadataMap.set(MetadataKey, MetadataValue);
1001
+ }
1002
+ // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
1003
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
1004
+ function OrdinaryOwnMetadataKeys(O, P) {
1005
+ var keys = [];
1006
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1007
+ if (IsUndefined(metadataMap)) return keys;
1008
+ var keysObj = metadataMap.keys();
1009
+ var iterator = GetIterator(keysObj);
1010
+ var k = 0;
1011
+ while(true){
1012
+ var next = IteratorStep(iterator);
1013
+ if (!next) {
1014
+ keys.length = k;
1015
+ return keys;
1016
+ }
1017
+ var nextValue = IteratorValue(next);
1018
+ try {
1019
+ keys[k] = nextValue;
1020
+ } catch (e) {
1021
+ try {
1022
+ IteratorClose(iterator);
1023
+ } finally{
1024
+ throw e;
1025
+ }
1026
+ }
1027
+ k++;
1028
+ }
1029
+ }
1030
+ function OrdinaryDeleteMetadata(MetadataKey, O, P) {
1031
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1032
+ if (IsUndefined(metadataMap)) return false;
1033
+ if (!metadataMap.delete(MetadataKey)) return false;
1034
+ if (metadataMap.size === 0) {
1035
+ var targetMetadata = metadata.get(O);
1036
+ if (!IsUndefined(targetMetadata)) {
1037
+ targetMetadata.delete(P);
1038
+ if (targetMetadata.size === 0) {
1039
+ metadata.delete(targetMetadata);
1040
+ }
1041
+ }
1042
+ }
1043
+ return true;
1044
+ }
1045
+ }
1046
+ function CreateFallbackProvider(reflect) {
1047
+ var defineMetadata = reflect.defineMetadata, hasOwnMetadata = reflect.hasOwnMetadata, getOwnMetadata = reflect.getOwnMetadata, getOwnMetadataKeys = reflect.getOwnMetadataKeys, deleteMetadata = reflect.deleteMetadata;
1048
+ var metadataOwner = new _WeakMap();
1049
+ var provider = {
1050
+ isProviderFor: function(O, P) {
1051
+ var metadataPropertySet = metadataOwner.get(O);
1052
+ if (!IsUndefined(metadataPropertySet)) {
1053
+ return metadataPropertySet.has(P);
1054
+ }
1055
+ if (getOwnMetadataKeys(O, P).length) {
1056
+ if (IsUndefined(metadataPropertySet)) {
1057
+ metadataPropertySet = new _Set();
1058
+ metadataOwner.set(O, metadataPropertySet);
1059
+ }
1060
+ metadataPropertySet.add(P);
1061
+ return true;
1062
+ }
1063
+ return false;
1064
+ },
1065
+ OrdinaryDefineOwnMetadata: defineMetadata,
1066
+ OrdinaryHasOwnMetadata: hasOwnMetadata,
1067
+ OrdinaryGetOwnMetadata: getOwnMetadata,
1068
+ OrdinaryOwnMetadataKeys: getOwnMetadataKeys,
1069
+ OrdinaryDeleteMetadata: deleteMetadata
1070
+ };
1071
+ return provider;
1072
+ }
1073
+ /**
1074
+ * Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation,
1075
+ * then this module's metadata provider is assigned to the object.
1076
+ */ function GetMetadataProvider(O, P, Create) {
1077
+ var registeredProvider = metadataRegistry.getProvider(O, P);
1078
+ if (!IsUndefined(registeredProvider)) {
1079
+ return registeredProvider;
1080
+ }
1081
+ if (Create) {
1082
+ if (metadataRegistry.setProvider(O, P, metadataProvider)) {
1083
+ return metadataProvider;
1084
+ }
1085
+ throw new Error("Illegal state.");
1086
+ }
1087
+ return undefined;
1088
+ }
1089
+ });
1090
+ })(Reflect$1 || (Reflect$1 = {}));
1091
+
1092
+ // Utils
1093
+ async function dynamicImport(filepath) {
1094
+ return import(/* webpackIgnore: true */ process.platform === "win32" ? `file://${filepath}` : filepath);
1095
+ }
1096
+ function fixDefaultExport(mod) {
1097
+ return "default" in mod ? mod.default : mod;
1098
+ }
1099
+
1100
+ // Container
1101
+ const container = new Container();
1102
+ // Utilities
1103
+ const { lazyInject, lazyInjectNamed } = fixDefaultExport(getDecorators)(container);
1104
+
1105
+ // Decorators
1106
+ /**
1107
+ * Register class as a service
1108
+ */ function Service() {
1109
+ return (cls)=>{
1110
+ decorate(injectable(), cls);
1111
+ container.bind(cls).toSelf().inSingletonScope().onActivation((ctx, service)=>{
1112
+ if ("onServiceActivate" in service) {
1113
+ service.onServiceActivate(ctx);
1114
+ }
1115
+ return service;
1116
+ });
1117
+ return cls;
1118
+ };
1119
+ }
1120
+
1121
+ // Constants
1122
+ const LOG_BROADCAST_CHANNEL = Symbol.for("jujulego:jill:log-broadcast-channel");
1123
+ // Parameters
1124
+ container.bind(LOG_BROADCAST_CHANNEL).toConstantValue("jujulego:jill:logger");
1125
+
1126
+ class ThreadGateway {
1127
+ // Constructor
1128
+ constructor(channel){
1129
+ this._source = source$();
1130
+ // Methods
1131
+ this.next = (data)=>{
1132
+ this.channel.postMessage(data);
1133
+ };
1134
+ this.subscribe = this._source.subscribe;
1135
+ this.unsubscribe = this._source.unsubscribe;
1136
+ this.clear = this._source.clear;
1137
+ this.channel = new BroadcastChannel(channel);
1138
+ this.channel.unref();
1139
+ this.channel.onmessage = (log)=>{
1140
+ this._source.next(log.data);
1141
+ };
1142
+ this.channel.onmessageerror = (data)=>{
1143
+ this._source.next(withTimestamp()({
1144
+ level: LogLevel.error,
1145
+ message: quick.string`Unable to read message: #!json:${data.data}`
1146
+ }));
1147
+ };
1148
+ }
1149
+ }
1150
+ ThreadGateway = _([
1151
+ Service(),
1152
+ _$1(0, inject(LOG_BROADCAST_CHANNEL))
1153
+ ], ThreadGateway);
1154
+
1155
+ // Utils
1156
+ const jillLogFormat = qlevelColor(quick.wrap(chalkTemplateStderr).function`#?:${qprop("label")}{grey [#$]} ?#${qprop("message")}#?:${qprop("error")}\n#!error$?#`);
1157
+ class LogGateway {
1158
+ // Lifecycle
1159
+ onServiceActivate({ container }) {
1160
+ const threadGtw = container.get(ThreadGateway);
1161
+ if (wt.isMainThread) {
1162
+ // Redirect logs to stderr
1163
+ flow$(this._source, toStderr(jillLogFormat));
1164
+ // Add thread gateway as input
1165
+ this.connect(threadGtw);
1166
+ } else {
1167
+ // Redirect logs to thread gateway
1168
+ flow$(this._source, threadGtw);
1169
+ }
1170
+ }
1171
+ connect(origin) {
1172
+ return flow$(origin, filter$((log)=>log.level >= this.level), this._source);
1173
+ }
1174
+ // Properties
1175
+ get listeners() {
1176
+ return Array.from(this._source.listeners);
1177
+ }
1178
+ get level() {
1179
+ return this.level$.read();
1180
+ }
1181
+ set level(level) {
1182
+ this.level$.mutate(level);
1183
+ }
1184
+ constructor(){
1185
+ // Attributes
1186
+ this.level$ = var$(LogLevel.info);
1187
+ this._source = source$();
1188
+ // Methods
1189
+ this.subscribe = this._source.subscribe;
1190
+ this.unsubscribe = this._source.unsubscribe;
1191
+ this.clear = this._source.clear;
1192
+ }
1193
+ }
1194
+ LogGateway = _([
1195
+ Service()
1196
+ ], LogGateway);
1197
+
1198
+ // Service
1199
+ container.bind(Logger).toDynamicValue(()=>logger$(withTimestamp())).inSingletonScope().onActivation(({ container }, logger)=>{
1200
+ const gateway = container.get(LogGateway);
1201
+ gateway.connect(logger);
1202
+ return logger;
1203
+ });
1204
+
1205
+ class ContextService {
1206
+ // Constructor
1207
+ constructor(logger){
1208
+ this._storage = new AsyncLocalStorage();
1209
+ this._logger = logger.child(withLabel("context"));
1210
+ this.reset();
1211
+ }
1212
+ // Methods
1213
+ reset(context = {}) {
1214
+ this._storage.enterWith(context);
1215
+ }
1216
+ _getContext() {
1217
+ const ctx = this._storage.getStore();
1218
+ if (!ctx) {
1219
+ this._logger.warning("Trying to access uninitialized context");
1220
+ return {};
1221
+ }
1222
+ return ctx;
1223
+ }
1224
+ _updateContext(update) {
1225
+ Object.assign(this._getContext(), update);
1226
+ }
1227
+ // Properties
1228
+ get application() {
1229
+ return this._getContext().application;
1230
+ }
1231
+ set application(application) {
1232
+ this._updateContext({
1233
+ application
1234
+ });
1235
+ }
1236
+ get project() {
1237
+ return this._getContext().project;
1238
+ }
1239
+ set project(project) {
1240
+ this._updateContext({
1241
+ project
1242
+ });
1243
+ }
1244
+ get workspace() {
1245
+ return this._getContext().workspace;
1246
+ }
1247
+ set workspace(workspace) {
1248
+ this._updateContext({
1249
+ workspace
1250
+ });
1251
+ }
1252
+ }
1253
+ ContextService = _([
1254
+ Service(),
1255
+ _$1(0, inject(Logger))
1256
+ ], ContextService);
1257
+
1258
+ // Symbols
1259
+ const CONFIG_OPTIONS = Symbol("jujulego:jill:config-options");
1260
+ // Constants
1261
+ const VERBOSITY_LEVEL = {
1262
+ 1: "verbose",
1263
+ 2: "debug"
1264
+ };
1265
+ // Options
1266
+ function applyConfigOptions(parser) {
1267
+ return parser.option("verbose", {
1268
+ alias: "v",
1269
+ type: "count",
1270
+ description: "Set verbosity level",
1271
+ coerce: (cnt)=>VERBOSITY_LEVEL[Math.min(cnt, 2)]
1272
+ }).option("jobs", {
1273
+ alias: "j",
1274
+ type: "number",
1275
+ description: "Set maximum parallel job number"
1276
+ }).option("hooks", {
1277
+ type: "boolean",
1278
+ description: "Run hook scripts"
1279
+ });
1280
+ }
1281
+ container.bind(CONFIG_OPTIONS).toDynamicValue(()=>{
1282
+ const parser = yargs(hideBin(process.argv)).help(false).version(false);
1283
+ applyConfigOptions(parser);
1284
+ return parser.parse();
1285
+ }).inSingletonScope();
1286
+
1287
+ // Constants
1288
+ const CURRENT = "current";
1289
+
1290
+ // Symbols
1291
+ const MODULE = Symbol("jujulego:jill:module");
1292
+ const REGISTRY = Symbol("jujulego:jill:registry");
1293
+ // Utils
1294
+ function getRegistry(target) {
1295
+ const registry = Reflect.getMetadata(REGISTRY, target);
1296
+ if (typeof registry !== "function") {
1297
+ throw new Error(`No registry found in ${target.name}`);
1298
+ }
1299
+ return registry;
1300
+ }
1301
+ function setRegistry(target, registry) {
1302
+ Reflect.defineMetadata(REGISTRY, registry, target);
1303
+ }
1304
+ function getModule(target, assert = false) {
1305
+ let module = Reflect.getMetadata(MODULE, target);
1306
+ if (!module || !(module instanceof ContainerModule)) {
1307
+ const registry = Reflect.getMetadata(REGISTRY, target);
1308
+ if (typeof registry !== "function") {
1309
+ if (assert) {
1310
+ throw new Error(`No module found in ${target.name}`);
1311
+ }
1312
+ return null;
1313
+ }
1314
+ module = new ContainerModule(registry);
1315
+ setModule(target, module);
1316
+ }
1317
+ return module;
1318
+ }
1319
+ function setModule(target, module) {
1320
+ Reflect.defineMetadata(MODULE, module, target);
1321
+ }
1322
+
1323
+ // Class
1324
+ class ExitException extends Error {
1325
+ // Constructor
1326
+ constructor(code, message){
1327
+ super(message);
1328
+ this.code = code;
1329
+ }
1330
+ }
1331
+
1332
+ // Decorator
1333
+ function Middleware() {
1334
+ return (target)=>{
1335
+ decorate(injectable(), target);
1336
+ container.bind(target).toSelf().inSingletonScope();
1337
+ };
1338
+ }
1339
+ // Utils
1340
+ function applyMiddlewares(parser, middlewares) {
1341
+ let tmp = parser;
1342
+ for (const cls of middlewares){
1343
+ const middleware = container.get(cls);
1344
+ if (middleware.builder) {
1345
+ tmp = middleware.builder(tmp);
1346
+ }
1347
+ tmp.middleware((args)=>middleware.handler(args));
1348
+ }
1349
+ return tmp;
1350
+ }
1351
+
1352
+ // Symbols
1353
+ const COMMAND_OPTS = Symbol("jujulego:jill:command-opts");
1354
+ const COMMAND = Symbol("jujulego:jill:command");
1355
+ const COMMAND_MODULE = Symbol("jujulego:jill:command-module");
1356
+ // Utils
1357
+ function getCommandOpts(target) {
1358
+ const opts = Reflect.getMetadata(COMMAND_OPTS, target);
1359
+ if (typeof opts !== "object") {
1360
+ throw new Error(`No command options found in ${target.name}`);
1361
+ }
1362
+ return opts;
1363
+ }
1364
+ function buildCommandModule(cmd, opts) {
1365
+ return {
1366
+ command: opts.command,
1367
+ aliases: opts.aliases,
1368
+ describe: opts.describe,
1369
+ deprecated: opts.deprecated,
1370
+ builder (parser) {
1371
+ if (opts.middlewares) {
1372
+ parser = applyMiddlewares(parser, opts.middlewares);
1373
+ }
1374
+ if (cmd.builder) {
1375
+ parser = cmd.builder(parser);
1376
+ }
1377
+ return parser;
1378
+ },
1379
+ handler: async (args)=>{
1380
+ try {
1381
+ await cmd.handler(args);
1382
+ } catch (err) {
1383
+ if (err.message) {
1384
+ const logger = container.get(Logger);
1385
+ logger.error("Error while running command:", err);
1386
+ }
1387
+ throw new ExitException(1);
1388
+ }
1389
+ }
1390
+ };
1391
+ }
1392
+ // Decorator
1393
+ function Command(opts) {
1394
+ return (target)=>{
1395
+ decorate(injectable(), target);
1396
+ Reflect.defineMetadata(COMMAND_OPTS, opts, target);
1397
+ const cmd = opts.command.split(" ")[0];
1398
+ setRegistry(target, (bind)=>{
1399
+ bind(target).toSelf();
1400
+ bind(COMMAND).toDynamicValue(({ container })=>container.getAsync(target)).whenTargetNamed(cmd);
1401
+ bind(COMMAND_MODULE).toDynamicValue(async ({ container })=>{
1402
+ const cmd = await container.getAsync(target);
1403
+ return buildCommandModule(cmd, opts);
1404
+ }).whenTargetNamed(cmd);
1405
+ });
1406
+ };
1407
+ }
1408
+
1409
+ // Symbols
1410
+ const AJV = Symbol("jujulego:jill:Ajv");
1411
+ // Setup
1412
+ container.bind(AJV).toDynamicValue(({ container })=>{
1413
+ const logger = container.get(Logger);
1414
+ return new Ajv.default({
1415
+ allErrors: true,
1416
+ logger: logger.child(withLabel("ajv")),
1417
+ strict: process.env.NODE_ENV === "development" ? "log" : true
1418
+ });
1419
+ }).inSingletonScope();
1420
+
1421
+ function isCacheUpdate(msg) {
1422
+ return typeof msg === "object" && msg !== null && "key" in msg && "value" in msg;
1423
+ }
1424
+ // Chanel
1425
+ const channel = new BroadcastChannel("jujulego:jill:worker-cache");
1426
+ channel.unref();
1427
+ channel.onmessage = (arg)=>{
1428
+ const msg = arg;
1429
+ if (isCacheUpdate(msg.data)) {
1430
+ setEnvironmentData(msg.data.key, msg.data.value);
1431
+ }
1432
+ };
1433
+ // Utils
1434
+ async function workerCache(key, compute) {
1435
+ const cache = getEnvironmentData(key);
1436
+ if (cache !== undefined) return cache;
1437
+ // Compute it
1438
+ const result = await compute();
1439
+ setEnvironmentData(key, result);
1440
+ channel.postMessage({
1441
+ key,
1442
+ value: result
1443
+ });
1444
+ return result;
1445
+ }
1446
+
1447
+ var $schema = "http://json-schema.org/draft-07/schema";
1448
+ var type = "object";
1449
+ var additionalProperties = false;
1450
+ var properties = {
1451
+ jobs: {
1452
+ type: "number"
1453
+ },
1454
+ hooks: {
1455
+ type: "boolean",
1456
+ "default": true,
1457
+ description: "Run hook scripts"
1458
+ },
1459
+ plugins: {
1460
+ type: "array",
1461
+ items: {
1462
+ type: "string"
1463
+ }
1464
+ },
1465
+ verbose: {
1466
+ type: "string",
1467
+ "enum": [
1468
+ "info",
1469
+ "verbose",
1470
+ "debug"
1471
+ ]
1472
+ }
1473
+ };
1474
+ var schema = {
1475
+ $schema: $schema,
1476
+ type: type,
1477
+ additionalProperties: additionalProperties,
1478
+ properties: properties
1479
+ };
1480
+
1481
+ // Symbols
1482
+ const CONFIG_EXPLORER = Symbol("jujulego:jill:config-explorer");
1483
+ const CONFIG_VALIDATOR = Symbol("jujulego:jill:config-validator");
1484
+ // Setup
1485
+ container.bind(CONFIG_VALIDATOR).toDynamicValue(({ container })=>{
1486
+ const ajv = container.get(AJV);
1487
+ return ajv.compile(schema);
1488
+ }).inSingletonScope();
1489
+ container.bind(CONFIG_EXPLORER).toDynamicValue(()=>{
1490
+ return cosmiconfig("jill", {
1491
+ searchStrategy: "global",
1492
+ loaders: {
1493
+ ".cjs": (filepath)=>dynamicImport(filepath).then((mod)=>mod.default),
1494
+ ".js": (filepath)=>dynamicImport(filepath).then((mod)=>mod.default),
1495
+ ".json": defaultLoaders[".json"],
1496
+ ".yaml": defaultLoaders[".yaml"],
1497
+ ".yml": defaultLoaders[".yml"],
1498
+ noExt: defaultLoaders.noExt
1499
+ }
1500
+ });
1501
+ }).inSingletonScope();
1502
+
1503
+ // Symbols
1504
+ const CONFIG = Symbol("jujulego:jill:config");
1505
+ // Loader
1506
+ async function configLoader() {
1507
+ const logger = container.get(Logger).child(withLabel("config"));
1508
+ const options = container.get(CONFIG_OPTIONS);
1509
+ const explorer = container.get(CONFIG_EXPLORER);
1510
+ const validator = container.get(CONFIG_VALIDATOR);
1511
+ // Load file
1512
+ const loaded = await explorer.search();
1513
+ const config = loaded?.config ?? {};
1514
+ // Apply options from cli
1515
+ if (options.jobs) config.jobs = options.jobs;
1516
+ if (options.verbose) config.verbose = options.verbose;
1517
+ if (options.hooks !== undefined) config.hooks = options.hooks;
1518
+ // Apply defaults
1519
+ config.jobs ??= os.cpus().length - 1;
1520
+ config.hooks ??= true;
1521
+ // Validate
1522
+ if (!validator(config)) {
1523
+ const ajv = container.get(AJV);
1524
+ const errors = ajv.errorsText(validator.errors, {
1525
+ separator: "\n- ",
1526
+ dataVar: "config"
1527
+ });
1528
+ logger.error(`Errors in config file:\n- ${errors}`);
1529
+ throw new ExitException(1);
1530
+ }
1531
+ // Apply on logger
1532
+ if (config.verbose) {
1533
+ container.get(LogGateway).level = LogLevel[config.verbose];
1534
+ }
1535
+ if (loaded) {
1536
+ // Resolve paths relative to config file
1537
+ const base = path.dirname(loaded.filepath);
1538
+ config.plugins = config.plugins?.map((plugin)=>path.resolve(base, plugin));
1539
+ logger.verbose(`Loaded ${loaded.filepath} config file`);
1540
+ }
1541
+ logger.debug`Loaded config:\n#!json:${config}`;
1542
+ return config;
1543
+ }
1544
+ container.bind(CONFIG).toDynamicValue(async ()=>await workerCache("jujulego:jill:config", configLoader)).inSingletonScope();
1545
+
1546
+ class PluginLoaderService {
1547
+ // Constructor
1548
+ constructor(_config, logger){
1549
+ this._config = _config;
1550
+ this._logger = logger.child(withLabel("plugin"));
1551
+ }
1552
+ // Methods
1553
+ async _importPlugin(filepath) {
1554
+ this._logger.verbose`Loading plugin ${filepath}`;
1555
+ // Load plugin
1556
+ let plugin = await dynamicImport(filepath);
1557
+ while(plugin && typeof plugin === "object" && "default" in plugin){
1558
+ plugin = plugin.default;
1559
+ }
1560
+ if (!plugin) {
1561
+ throw new Error(`Invalid plugin ${filepath}: no plugin class found`);
1562
+ }
1563
+ // Load module from plugin
1564
+ const module = getModule(plugin);
1565
+ if (!module) {
1566
+ throw new Error(`Invalid plugin ${filepath}: invalid plugin class`);
1567
+ }
1568
+ return module;
1569
+ }
1570
+ async loadPlugins(ctn = container) {
1571
+ if (!this._config.plugins) return;
1572
+ for (const path of this._config.plugins){
1573
+ const plugin = await this._importPlugin(path);
1574
+ ctn.load(plugin);
1575
+ }
1576
+ }
1577
+ }
1578
+ PluginLoaderService = _([
1579
+ Service(),
1580
+ _$1(0, inject(CONFIG)),
1581
+ _$1(1, inject(Logger))
1582
+ ], PluginLoaderService);
1583
+
1584
+ // Utils
1585
+ function linesFrom(task, stream) {
1586
+ const inner = source$();
1587
+ if (task.completed) {
1588
+ return inner;
1589
+ }
1590
+ // Listen to stream
1591
+ let current = "";
1592
+ const stop = task.on(`stream.${stream}`, (chunk)=>{
1593
+ const data = current + chunk.data.toString("utf-8");
1594
+ const lines = data.split(/\r?\n/);
1595
+ current = lines.pop() ?? "";
1596
+ for (const line of lines){
1597
+ inner.next(line);
1598
+ }
1599
+ });
1600
+ // Listen to end of task
1601
+ once$(task, "completed", ()=>{
1602
+ stop();
1603
+ if (current) {
1604
+ inner.next(current);
1605
+ }
1606
+ });
1607
+ return inner;
1608
+ }
1609
+
1610
+ // Utils
1611
+ function isCommandCtx(ctx) {
1612
+ return "workspace" in ctx && "command" in ctx;
1613
+ }
1614
+ // Class
1615
+ class CommandTask extends SpawnTask {
1616
+ // Constructor
1617
+ constructor(workspace, command, args, opts = {}){
1618
+ let cmd = command;
1619
+ if (opts.superCommand) {
1620
+ if (typeof opts.superCommand === "string") {
1621
+ opts.superCommand = [
1622
+ opts.superCommand
1623
+ ];
1624
+ }
1625
+ if (opts.superCommand.length > 0) {
1626
+ cmd = opts.superCommand[0];
1627
+ args = [
1628
+ ...opts.superCommand.slice(1),
1629
+ command,
1630
+ ...args
1631
+ ];
1632
+ }
1633
+ }
1634
+ super(cmd, args, {
1635
+ workspace,
1636
+ command
1637
+ }, {
1638
+ ...opts,
1639
+ cwd: workspace.cwd,
1640
+ env: {
1641
+ FORCE_COLOR: "1",
1642
+ ...opts.env
1643
+ }
1644
+ });
1645
+ this.workspace = workspace;
1646
+ this._logStreams();
1647
+ }
1648
+ // Methods
1649
+ _logStreams() {
1650
+ // TODO: clean up this subscriptions
1651
+ linesFrom(this, "stdout").subscribe((line)=>this._logger.info(line));
1652
+ linesFrom(this, "stderr").subscribe((line)=>this._logger.info(line));
1653
+ }
1654
+ }
1655
+
1656
+ // Utils
1657
+ function capitalize(txt) {
1658
+ return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
1659
+ }
1660
+ function splitCommandLine(line) {
1661
+ line = line.trim();
1662
+ const parts = [];
1663
+ let current_cote = "";
1664
+ let last = 0;
1665
+ for(let i = 1; i < line.length; ++i){
1666
+ const c = line[i];
1667
+ if (current_cote) {
1668
+ if (c === current_cote) {
1669
+ current_cote = "";
1670
+ }
1671
+ } else {
1672
+ if ([
1673
+ '"',
1674
+ "'"
1675
+ ].includes(c)) {
1676
+ current_cote = c;
1677
+ } else if (c === " ") {
1678
+ parts.push(line.slice(last, i));
1679
+ last = i + 1;
1680
+ }
1681
+ }
1682
+ }
1683
+ parts.push(line.slice(last));
1684
+ return parts;
1685
+ }
1686
+
1687
+ // Utils
1688
+ function isScriptCtx(ctx) {
1689
+ return "workspace" in ctx && "script" in ctx;
1690
+ }
1691
+ // Class
1692
+ class ScriptTask extends GroupTask {
1693
+ // Constructor
1694
+ constructor(workspace, script, args, opts){
1695
+ super(script, {
1696
+ workspace,
1697
+ script
1698
+ }, opts);
1699
+ this.workspace = workspace;
1700
+ this.script = script;
1701
+ this.args = args;
1702
+ this._preHookTasks = null;
1703
+ this._postHookTasks = null;
1704
+ this._scriptTasks = null;
1705
+ this._runHooks = opts?.runHooks ?? true;
1706
+ }
1707
+ // Methods
1708
+ async _runScript(script, args) {
1709
+ const line = this.workspace.getScript(script);
1710
+ if (!line) {
1711
+ return null;
1712
+ }
1713
+ // Create command task for script
1714
+ const [command, ...commandArgs] = splitCommandLine(line);
1715
+ if (command === "jill") {
1716
+ this._logger.debug(`Interpreting ${line}`);
1717
+ const argv = commandArgs.map((arg)=>arg.replace(/^["'](.+)["']$/, "$1"));
1718
+ const { JillApplication } = await import('./jill.application-CFM4p02J.js').then(function (n) { return n.j; });
1719
+ const app = container.get(JillApplication);
1720
+ const tasks = await app.tasksOf(argv, {
1721
+ project: this.project,
1722
+ workspace: this.workspace
1723
+ });
1724
+ if (tasks.length) {
1725
+ const set = new TaskSet();
1726
+ for (const tsk of tasks){
1727
+ set.add(tsk);
1728
+ }
1729
+ return set;
1730
+ }
1731
+ }
1732
+ const pm = await this.workspace.project.packageManager();
1733
+ const set = new TaskSet();
1734
+ set.add(new CommandTask(this.workspace, command, [
1735
+ ...commandArgs,
1736
+ ...args
1737
+ ], {
1738
+ logger: this._logger,
1739
+ superCommand: pm === "yarn" ? [
1740
+ "yarn",
1741
+ "exec"
1742
+ ] : undefined
1743
+ }));
1744
+ return set;
1745
+ }
1746
+ async prepare() {
1747
+ // Prepare script run
1748
+ this._scriptTasks = await this._runScript(this.script, this.args);
1749
+ if (!this._scriptTasks) {
1750
+ throw new Error(`No script ${this.script} in ${this.workspace.name}`);
1751
+ }
1752
+ // Prepare hooks run
1753
+ if (this._runHooks) {
1754
+ this._preHookTasks = await this._runScript(`pre${this.script}`, []);
1755
+ this._postHookTasks = await this._runScript(`post${this.script}`, []);
1756
+ }
1757
+ // Add tasks to group
1758
+ if (this._preHookTasks) {
1759
+ this._logger.verbose(`Found pre-hook script "pre${this.script}"`);
1760
+ for (const tsk of this._preHookTasks){
1761
+ this.add(tsk);
1762
+ }
1763
+ }
1764
+ for (const tsk of this._scriptTasks){
1765
+ this.add(tsk);
1766
+ }
1767
+ if (this._postHookTasks) {
1768
+ this._logger.verbose(`Found post-hook script "post${this.script}"`);
1769
+ for (const tsk of this._postHookTasks){
1770
+ this.add(tsk);
1771
+ }
1772
+ }
1773
+ }
1774
+ async *_orchestrate() {
1775
+ if (!this._scriptTasks) {
1776
+ throw new Error("ScriptTask needs to be prepared. Call prepare before starting it");
1777
+ }
1778
+ // Run pre-hook
1779
+ if (this._preHookTasks) {
1780
+ yield* this._preHookTasks;
1781
+ if (await this._hasFailed(this._preHookTasks)) {
1782
+ return this.setStatus("failed");
1783
+ }
1784
+ }
1785
+ // Run script
1786
+ yield* this._scriptTasks;
1787
+ if (await this._hasFailed(this._scriptTasks)) {
1788
+ return this.setStatus("failed");
1789
+ }
1790
+ // Run post-hook
1791
+ if (this._postHookTasks) {
1792
+ yield* this._postHookTasks;
1793
+ if (await this._hasFailed(this._postHookTasks)) {
1794
+ return this.setStatus("failed");
1795
+ }
1796
+ }
1797
+ this.setStatus("done");
1798
+ }
1799
+ async _hasFailed(set) {
1800
+ const results = await waitFor$(set, "finished");
1801
+ return results.failed > 0;
1802
+ }
1803
+ _stop() {
1804
+ if (!this._scriptTasks) return;
1805
+ for (const tsk of this._scriptTasks){
1806
+ tsk.stop();
1807
+ }
1808
+ }
1809
+ complexity(cache = new Map()) {
1810
+ let complexity = super.complexity(cache);
1811
+ if (this._scriptTasks) {
1812
+ complexity += this._scriptTasks.tasks.reduce((cpl, tsk)=>cpl + tsk.complexity(cache), 0);
1813
+ }
1814
+ cache.set(this.id, complexity);
1815
+ return complexity;
1816
+ }
1817
+ // Properties
1818
+ get project() {
1819
+ return this.workspace.project;
1820
+ }
1821
+ }
1822
+
1823
+ // Symbols
1824
+ const TASK_MANAGER = Symbol("jujulego:jill:TaskManager");
1825
+ // Service
1826
+ container.bind(TASK_MANAGER).toDynamicValue(({ container })=>{
1827
+ const config = container.get(CONFIG);
1828
+ const logger = container.get(Logger);
1829
+ return new TaskManager({
1830
+ jobs: config.jobs,
1831
+ logger
1832
+ });
1833
+ }).inSingletonScope();
1834
+
1835
+ // Component
1836
+ function List({ items, headers }) {
1837
+ if (items.length === 0) {
1838
+ return null;
1839
+ }
1840
+ return /*#__PURE__*/ jsx(Box, {
1841
+ children: Object.keys(items[0]).map((key)=>/*#__PURE__*/ jsxs(Box, {
1842
+ flexDirection: "column",
1843
+ marginRight: 2,
1844
+ children: [
1845
+ headers && /*#__PURE__*/ jsx(Text, {
1846
+ bold: true,
1847
+ children: capitalize(key)
1848
+ }),
1849
+ items.map((item, idx)=>/*#__PURE__*/ jsx(Text, {
1850
+ children: item[key] || " "
1851
+ }, idx))
1852
+ ]
1853
+ }, key))
1854
+ });
1855
+ }
1856
+
1857
+ // Components
1858
+ function TaskName({ task }) {
1859
+ if (isScriptCtx(task.context)) {
1860
+ return /*#__PURE__*/ jsxs(Text, {
1861
+ children: [
1862
+ "Run ",
1863
+ /*#__PURE__*/ jsx(Text, {
1864
+ bold: true,
1865
+ children: task.context.script
1866
+ }),
1867
+ " in ",
1868
+ task.context.workspace.name
1869
+ ]
1870
+ });
1871
+ } else {
1872
+ return /*#__PURE__*/ jsx(Text, {
1873
+ children: task.name
1874
+ });
1875
+ }
1876
+ }
1877
+
1878
+ // Components
1879
+ function TaskSpinner({ task }) {
1880
+ // State
1881
+ const [status, setStatus] = useState(task.status);
1882
+ const [time, setTime] = useState(task.duration);
1883
+ // Effects
1884
+ useLayoutEffect(()=>{
1885
+ return task.on("status", (event)=>{
1886
+ setStatus(event.status);
1887
+ });
1888
+ }, [
1889
+ task
1890
+ ]);
1891
+ useLayoutEffect(()=>{
1892
+ return task.on("completed", ({ duration })=>{
1893
+ setTime(duration);
1894
+ });
1895
+ }, [
1896
+ task
1897
+ ]);
1898
+ // Render
1899
+ const isScriptChild = isCommandCtx(task.context) && task.group && isScriptCtx(task.group.context);
1900
+ switch(status){
1901
+ case "blocked":
1902
+ case "ready":
1903
+ case "starting":
1904
+ return /*#__PURE__*/ jsxs(Box, {
1905
+ children: [
1906
+ /*#__PURE__*/ jsx(Text, {
1907
+ color: "grey",
1908
+ children: "\xb7"
1909
+ }),
1910
+ /*#__PURE__*/ jsx(Box, {
1911
+ paddingLeft: 1,
1912
+ children: /*#__PURE__*/ jsx(Text, {
1913
+ color: "grey",
1914
+ wrap: "truncate",
1915
+ children: /*#__PURE__*/ jsx(TaskName, {
1916
+ task: task
1917
+ })
1918
+ })
1919
+ })
1920
+ ]
1921
+ });
1922
+ case "running":
1923
+ return /*#__PURE__*/ jsxs(Box, {
1924
+ children: [
1925
+ /*#__PURE__*/ jsx(Text, {
1926
+ color: isScriptChild ? "dim" : undefined,
1927
+ children: /*#__PURE__*/ jsx(Spinner, {})
1928
+ }),
1929
+ /*#__PURE__*/ jsx(Box, {
1930
+ paddingLeft: 1,
1931
+ children: /*#__PURE__*/ jsx(Text, {
1932
+ color: isScriptChild ? "dim" : undefined,
1933
+ wrap: "truncate",
1934
+ children: /*#__PURE__*/ jsx(TaskName, {
1935
+ task: task
1936
+ })
1937
+ })
1938
+ })
1939
+ ]
1940
+ });
1941
+ case "done":
1942
+ return /*#__PURE__*/ jsxs(Box, {
1943
+ children: [
1944
+ /*#__PURE__*/ jsx(Text, {
1945
+ color: "green",
1946
+ children: symbols.success
1947
+ }),
1948
+ /*#__PURE__*/ jsx(Box, {
1949
+ paddingLeft: 1,
1950
+ children: /*#__PURE__*/ jsx(Text, {
1951
+ color: isScriptChild ? "dim" : undefined,
1952
+ wrap: "truncate",
1953
+ children: /*#__PURE__*/ jsx(TaskName, {
1954
+ task: task
1955
+ })
1956
+ })
1957
+ }),
1958
+ /*#__PURE__*/ jsx(Box, {
1959
+ paddingLeft: 1,
1960
+ flexShrink: 0,
1961
+ children: /*#__PURE__*/ jsxs(Text, {
1962
+ color: isScriptChild ? "grey" : "dim",
1963
+ children: [
1964
+ "(took ",
1965
+ ms(time),
1966
+ ")"
1967
+ ]
1968
+ })
1969
+ })
1970
+ ]
1971
+ });
1972
+ case "failed":
1973
+ return /*#__PURE__*/ jsxs(Box, {
1974
+ children: [
1975
+ /*#__PURE__*/ jsx(Text, {
1976
+ color: "red",
1977
+ children: symbols.error
1978
+ }),
1979
+ /*#__PURE__*/ jsx(Box, {
1980
+ paddingLeft: 1,
1981
+ children: /*#__PURE__*/ jsx(Text, {
1982
+ color: isScriptChild ? "dim" : undefined,
1983
+ wrap: "truncate",
1984
+ children: /*#__PURE__*/ jsx(TaskName, {
1985
+ task: task
1986
+ })
1987
+ })
1988
+ }),
1989
+ /*#__PURE__*/ jsx(Box, {
1990
+ paddingLeft: 1,
1991
+ flexShrink: 0,
1992
+ children: /*#__PURE__*/ jsxs(Text, {
1993
+ color: isScriptChild ? "grey" : "dim",
1994
+ children: [
1995
+ "(took ",
1996
+ ms(time),
1997
+ ")"
1998
+ ]
1999
+ })
2000
+ })
2001
+ ]
2002
+ });
2003
+ }
2004
+ }
2005
+
2006
+ // Utils
2007
+ function printJson(data, stream = process.stdout) {
2008
+ if (stream.isTTY) {
2009
+ stream.write(JSON.stringify(data, null, 2));
2010
+ } else {
2011
+ stream.write(JSON.stringify(data));
2012
+ }
2013
+ }
2014
+
2015
+ // Component
2016
+ function StaticLogs() {
2017
+ // State
2018
+ const { write } = useStderr();
2019
+ // Effect
2020
+ useLayoutEffect(()=>{
2021
+ const gateway = container.get(LogGateway);
2022
+ // Remove Console transport
2023
+ const listeners = gateway.listeners;
2024
+ gateway.clear();
2025
+ // Add custom transport
2026
+ const off = gateway.subscribe((log)=>{
2027
+ write(jillLogFormat(log) + "\n");
2028
+ });
2029
+ return ()=>{
2030
+ off();
2031
+ // Restore previous listeners
2032
+ for (const lst of listeners){
2033
+ gateway.subscribe(lst);
2034
+ }
2035
+ };
2036
+ }, [
2037
+ write
2038
+ ]);
2039
+ return null;
2040
+ }
2041
+
2042
+ // Component
2043
+ function Layout({ children }) {
2044
+ return /*#__PURE__*/ jsxs(Fragment, {
2045
+ children: [
2046
+ /*#__PURE__*/ jsx(StaticLogs, {}),
2047
+ children
2048
+ ]
2049
+ });
2050
+ }
2051
+
2052
+ // Constants
2053
+ const INK_APP = Symbol.for("jujulego:jill:ink-app");
2054
+ // Setup
2055
+ container.bind(INK_APP).toDynamicValue(()=>{
2056
+ if (!wt.isMainThread) {
2057
+ throw new Error("Ink should only be used in main thread");
2058
+ }
2059
+ return render(/*#__PURE__*/ jsx(Layout, {}));
2060
+ }).inSingletonScope();
2061
+
2062
+ class InkCommand {
2063
+ builder(parser) {
2064
+ return parser;
2065
+ }
2066
+ async handler(args) {
2067
+ for await (const children of this.render(args)){
2068
+ this.app.rerender(/*#__PURE__*/ jsx(Layout, {
2069
+ children: children
2070
+ }));
2071
+ }
2072
+ await this.app.waitUntilExit();
2073
+ }
2074
+ }
2075
+ _([
2076
+ lazyInject(INK_APP)
2077
+ ], InkCommand.prototype, "app", void 0);
2078
+ InkCommand = _([
2079
+ injectable()
2080
+ ], InkCommand);
2081
+
2082
+ export { splitCommandLine as A, workerCache as B, CONFIG as C, ContextService as D, ExitException as E, applyConfigOptions as F, InkCommand as I, Layout as L, Middleware as M, PluginLoaderService as P, Service as S, TaskName as T, List as a, TaskSpinner as b, COMMAND as c, COMMAND_MODULE as d, buildCommandModule as e, Command as f, getCommandOpts as g, applyMiddlewares as h, getRegistry as i, getModule as j, setModule as k, CURRENT as l, container as m, lazyInject as n, lazyInjectNamed as o, isCommandCtx as p, CommandTask as q, isScriptCtx as r, setRegistry as s, ScriptTask as t, TASK_MANAGER as u, linesFrom as v, dynamicImport as w, fixDefaultExport as x, printJson as y, capitalize as z };
2083
+ //# sourceMappingURL=ink-command-libMC9Gc.js.map