@jujulego/jill 3.0.0-alpha.1 → 3.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.
Files changed (104) hide show
  1. package/README.md +1 -2
  2. package/bin/jill.js +1 -0
  3. package/dist/TaskName.js +33 -0
  4. package/dist/TaskName.js.map +1 -0
  5. package/dist/inked.js +66 -0
  6. package/dist/inked.js.map +1 -0
  7. package/dist/instrument.js +8 -0
  8. package/dist/instrument.js.map +1 -0
  9. package/dist/list.ink.js +50 -0
  10. package/dist/list.ink.js.map +1 -0
  11. package/dist/main.js +44 -35
  12. package/dist/main.js.map +1 -1
  13. package/dist/parser.js +2104 -0
  14. package/dist/parser.js.map +1 -0
  15. package/dist/planner.service.js +58 -0
  16. package/dist/planner.service.js.map +1 -0
  17. package/dist/task-exec.ink.js +539 -0
  18. package/dist/task-exec.ink.js.map +1 -0
  19. package/dist/task-plan.ink.js +114 -0
  20. package/dist/task-plan.ink.js.map +1 -0
  21. package/dist/tree.ink.js +185 -0
  22. package/dist/tree.ink.js.map +1 -0
  23. package/dist/tsconfig.build.tsbuildinfo +1 -1
  24. package/package.json +46 -45
  25. package/dist/ajv.config.d.ts +0 -3
  26. package/dist/commands/each.d.ts +0 -25
  27. package/dist/commands/exec.d.ts +0 -26
  28. package/dist/commands/group.d.ts +0 -16
  29. package/dist/commands/list.d.ts +0 -30
  30. package/dist/commands/run.d.ts +0 -24
  31. package/dist/commands/tree.d.ts +0 -6
  32. package/dist/commons/context.service.d.ts +0 -23
  33. package/dist/commons/git.service.d.ts +0 -62
  34. package/dist/commons/logger/log.gateway.d.ts +0 -18
  35. package/dist/commons/logger/parameters.d.ts +0 -2
  36. package/dist/commons/logger/thread.gateway.d.ts +0 -12
  37. package/dist/commons/logger/types.d.ts +0 -2
  38. package/dist/commons/logger.service.d.ts +0 -1
  39. package/dist/config/config-loader.d.ts +0 -4
  40. package/dist/config/config-options.d.ts +0 -5
  41. package/dist/config/types.d.ts +0 -8
  42. package/dist/config/utils.d.ts +0 -5
  43. package/dist/constants.d.ts +0 -1
  44. package/dist/core.plugin-CxgfxFUI.js +0 -642
  45. package/dist/core.plugin-CxgfxFUI.js.map +0 -1
  46. package/dist/core.plugin.d.ts +0 -2
  47. package/dist/filters/affected.filter.d.ts +0 -12
  48. package/dist/filters/pipeline.d.ts +0 -11
  49. package/dist/filters/private.filter.d.ts +0 -7
  50. package/dist/filters/scripts.filter.d.ts +0 -8
  51. package/dist/index.d.ts +0 -45
  52. package/dist/index.js +0 -35
  53. package/dist/index.js.map +0 -1
  54. package/dist/ink-command-CsbkuRbm.js +0 -2071
  55. package/dist/ink-command-CsbkuRbm.js.map +0 -1
  56. package/dist/ink.config.d.ts +0 -3
  57. package/dist/inversify.config.d.ts +0 -4
  58. package/dist/jill.application-DNJpmnCF.js +0 -637
  59. package/dist/jill.application-DNJpmnCF.js.map +0 -1
  60. package/dist/jill.application.d.ts +0 -19
  61. package/dist/main.d.ts +0 -1
  62. package/dist/middlewares/load-project.d.ts +0 -21
  63. package/dist/middlewares/load-workspace.d.ts +0 -20
  64. package/dist/modules/command.d.ts +0 -20
  65. package/dist/modules/ink-command.d.ts +0 -11
  66. package/dist/modules/middleware.d.ts +0 -8
  67. package/dist/modules/module.d.ts +0 -7
  68. package/dist/modules/plugin-loader.service.d.ts +0 -10
  69. package/dist/modules/plugin.d.ts +0 -14
  70. package/dist/modules/service.d.ts +0 -8
  71. package/dist/modules/task-command.d.ts +0 -14
  72. package/dist/project/project.d.ts +0 -27
  73. package/dist/project/project.repository.d.ts +0 -15
  74. package/dist/project/types.d.ts +0 -1
  75. package/dist/project/workspace.d.ts +0 -41
  76. package/dist/tasks/command-task.d.ts +0 -15
  77. package/dist/tasks/errors.d.ts +0 -4
  78. package/dist/tasks/script-task.d.ts +0 -27
  79. package/dist/tasks/task-expression.service.d.ts +0 -25
  80. package/dist/tasks/task-manager.config.d.ts +0 -3
  81. package/dist/types.d.ts +0 -11
  82. package/dist/ui/hooks/useFlatTaskTree.d.ts +0 -14
  83. package/dist/ui/hooks/useIsVerbose.d.ts +0 -1
  84. package/dist/ui/hooks/useStdoutDimensions.d.ts +0 -4
  85. package/dist/ui/layout.d.ts +0 -5
  86. package/dist/ui/list.d.ts +0 -5
  87. package/dist/ui/static-logs.d.ts +0 -1
  88. package/dist/ui/task-name.d.ts +0 -5
  89. package/dist/ui/task-spinner.d.ts +0 -5
  90. package/dist/ui/task-tree-completed.d.ts +0 -5
  91. package/dist/ui/task-tree-full-spinner.d.ts +0 -5
  92. package/dist/ui/task-tree-scrollable-spinner.d.ts +0 -5
  93. package/dist/ui/task-tree-spinner.d.ts +0 -5
  94. package/dist/ui/task-tree-stats.d.ts +0 -5
  95. package/dist/ui/workspace-tree.d.ts +0 -8
  96. package/dist/utils/events.d.ts +0 -3
  97. package/dist/utils/exit.d.ts +0 -4
  98. package/dist/utils/import.d.ts +0 -4
  99. package/dist/utils/json.d.ts +0 -1
  100. package/dist/utils/streams.d.ts +0 -3
  101. package/dist/utils/string.d.ts +0 -2
  102. package/dist/utils/worker-cache.d.ts +0 -3
  103. package/dist/workspace-tree-VWKE0B6b.js +0 -1120
  104. package/dist/workspace-tree-VWKE0B6b.js.map +0 -1
@@ -1,2071 +0,0 @@
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 Types 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 = "string" ;
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);
665
- }
666
- // 7.1.1.1 OrdinaryToPrimitive(O, hint)
667
- // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
668
- function OrdinaryToPrimitive(O, hint) {
669
- var valueOf, result; {
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
- }
681
- throw new TypeError();
682
- }
683
- // 7.1.2 ToBoolean(argument)
684
- // https://tc39.github.io/ecma262/2016/#sec-toboolean
685
- function ToBoolean(argument) {
686
- return !!argument;
687
- }
688
- // 7.1.12 ToString(argument)
689
- // https://tc39.github.io/ecma262/#sec-tostring
690
- function ToString(argument) {
691
- return "" + argument;
692
- }
693
- // 7.1.14 ToPropertyKey(argument)
694
- // https://tc39.github.io/ecma262/#sec-topropertykey
695
- function ToPropertyKey(argument) {
696
- var key = ToPrimitive(argument);
697
- if (IsSymbol(key)) return key;
698
- return ToString(key);
699
- }
700
- // 7.2 Testing and Comparison Operations
701
- // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
702
- // 7.2.2 IsArray(argument)
703
- // https://tc39.github.io/ecma262/#sec-isarray
704
- function IsArray(argument) {
705
- return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
706
- }
707
- // 7.2.3 IsCallable(argument)
708
- // https://tc39.github.io/ecma262/#sec-iscallable
709
- function IsCallable(argument) {
710
- // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
711
- return typeof argument === "function";
712
- }
713
- // 7.2.4 IsConstructor(argument)
714
- // https://tc39.github.io/ecma262/#sec-isconstructor
715
- function IsConstructor(argument) {
716
- // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
717
- return typeof argument === "function";
718
- }
719
- // 7.2.7 IsPropertyKey(argument)
720
- // https://tc39.github.io/ecma262/#sec-ispropertykey
721
- function IsPropertyKey(argument) {
722
- switch(Type(argument)){
723
- case 3 /* String */ :
724
- return true;
725
- case 4 /* Symbol */ :
726
- return true;
727
- default:
728
- return false;
729
- }
730
- }
731
- // 7.3 Operations on Objects
732
- // https://tc39.github.io/ecma262/#sec-operations-on-objects
733
- // 7.3.9 GetMethod(V, P)
734
- // https://tc39.github.io/ecma262/#sec-getmethod
735
- function GetMethod(V, P) {
736
- var func = V[P];
737
- if (func === undefined || func === null) return undefined;
738
- if (!IsCallable(func)) throw new TypeError();
739
- return func;
740
- }
741
- // 7.4 Operations on Iterator Objects
742
- // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
743
- function GetIterator(obj) {
744
- var method = GetMethod(obj, iteratorSymbol);
745
- if (!IsCallable(method)) throw new TypeError(); // from Call
746
- var iterator = method.call(obj);
747
- if (!IsObject(iterator)) throw new TypeError();
748
- return iterator;
749
- }
750
- // 7.4.4 IteratorValue(iterResult)
751
- // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
752
- function IteratorValue(iterResult) {
753
- return iterResult.value;
754
- }
755
- // 7.4.5 IteratorStep(iterator)
756
- // https://tc39.github.io/ecma262/#sec-iteratorstep
757
- function IteratorStep(iterator) {
758
- var result = iterator.next();
759
- return result.done ? false : result;
760
- }
761
- // 7.4.6 IteratorClose(iterator, completion)
762
- // https://tc39.github.io/ecma262/#sec-iteratorclose
763
- function IteratorClose(iterator) {
764
- var f = iterator["return"];
765
- if (f) f.call(iterator);
766
- }
767
- // 9.1 Ordinary Object Internal Methods and Internal Slots
768
- // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
769
- // 9.1.1.1 OrdinaryGetPrototypeOf(O)
770
- // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
771
- function OrdinaryGetPrototypeOf(O) {
772
- var proto = Object.getPrototypeOf(O);
773
- if (typeof O !== "function" || O === functionPrototype) return proto;
774
- // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
775
- // Try to determine the superclass constructor. Compatible implementations
776
- // must either set __proto__ on a subclass constructor to the superclass constructor,
777
- // or ensure each class has a valid `constructor` property on its prototype that
778
- // points back to the constructor.
779
- // If this is not the same as Function.[[Prototype]], then this is definately inherited.
780
- // This is the case when in ES6 or when using __proto__ in a compatible browser.
781
- if (proto !== functionPrototype) return proto;
782
- // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
783
- var prototype = O.prototype;
784
- var prototypeProto = prototype && Object.getPrototypeOf(prototype);
785
- if (prototypeProto == null || prototypeProto === Object.prototype) return proto;
786
- // If the constructor was not a function, then we cannot determine the heritage.
787
- var constructor = prototypeProto.constructor;
788
- if (typeof constructor !== "function") return proto;
789
- // If we have some kind of self-reference, then we cannot determine the heritage.
790
- if (constructor === O) return proto;
791
- // we have a pretty good guess at the heritage.
792
- return constructor;
793
- }
794
- function fail(e) {
795
- throw e;
796
- }
797
- // Global metadata registry
798
- // - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate.
799
- // - Uses isolated metadata if `Reflect` is frozen before the registry can be installed.
800
- /**
801
- * Creates a registry used to allow multiple `reflect-metadata` providers.
802
- */ function CreateMetadataRegistry() {
803
- var fallback;
804
- if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
805
- // interoperate with older version of `reflect-metadata` that did not support a registry.
806
- fallback = CreateFallbackProvider(root.Reflect);
807
- }
808
- var first;
809
- var second;
810
- var rest;
811
- var targetProviderMap = new _WeakMap();
812
- var registry = {
813
- registerProvider: registerProvider,
814
- getProvider: getProvider,
815
- setProvider: setProvider
816
- };
817
- return registry;
818
- function registerProvider(provider) {
819
- if (!Object.isExtensible(registry)) {
820
- throw new Error("Cannot add provider to a frozen registry.");
821
- }
822
- switch(true){
823
- case fallback === provider:
824
- break;
825
- case IsUndefined(first):
826
- first = provider;
827
- break;
828
- case first === provider:
829
- break;
830
- case IsUndefined(second):
831
- second = provider;
832
- break;
833
- case second === provider:
834
- break;
835
- default:
836
- if (rest === undefined) rest = new _Set();
837
- rest.add(provider);
838
- break;
839
- }
840
- }
841
- function getProviderNoCache(O, P) {
842
- if (!IsUndefined(first)) {
843
- if (first.isProviderFor(O, P)) return first;
844
- if (!IsUndefined(second)) {
845
- if (second.isProviderFor(O, P)) return first;
846
- if (!IsUndefined(rest)) {
847
- var iterator = GetIterator(rest);
848
- while(true){
849
- var next = IteratorStep(iterator);
850
- if (!next) {
851
- return undefined;
852
- }
853
- var provider = IteratorValue(next);
854
- if (provider.isProviderFor(O, P)) {
855
- IteratorClose(iterator);
856
- return provider;
857
- }
858
- }
859
- }
860
- }
861
- }
862
- if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
863
- return fallback;
864
- }
865
- return undefined;
866
- }
867
- function getProvider(O, P) {
868
- var providerMap = targetProviderMap.get(O);
869
- var provider;
870
- if (!IsUndefined(providerMap)) {
871
- provider = providerMap.get(P);
872
- }
873
- if (!IsUndefined(provider)) {
874
- return provider;
875
- }
876
- provider = getProviderNoCache(O, P);
877
- if (!IsUndefined(provider)) {
878
- if (IsUndefined(providerMap)) {
879
- providerMap = new _Map();
880
- targetProviderMap.set(O, providerMap);
881
- }
882
- providerMap.set(P, provider);
883
- }
884
- return provider;
885
- }
886
- function hasProvider(provider) {
887
- if (IsUndefined(provider)) throw new TypeError();
888
- return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
889
- }
890
- function setProvider(O, P, provider) {
891
- if (!hasProvider(provider)) {
892
- throw new Error("Metadata provider not registered.");
893
- }
894
- var existingProvider = getProvider(O, P);
895
- if (existingProvider !== provider) {
896
- if (!IsUndefined(existingProvider)) {
897
- return false;
898
- }
899
- var providerMap = targetProviderMap.get(O);
900
- if (IsUndefined(providerMap)) {
901
- providerMap = new _Map();
902
- targetProviderMap.set(O, providerMap);
903
- }
904
- providerMap.set(P, provider);
905
- }
906
- return true;
907
- }
908
- }
909
- /**
910
- * Gets or creates the shared registry of metadata providers.
911
- */ function GetOrCreateMetadataRegistry() {
912
- var metadataRegistry;
913
- if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
914
- metadataRegistry = root.Reflect[registrySymbol];
915
- }
916
- if (IsUndefined(metadataRegistry)) {
917
- metadataRegistry = CreateMetadataRegistry();
918
- }
919
- if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
920
- Object.defineProperty(root.Reflect, registrySymbol, {
921
- enumerable: false,
922
- configurable: false,
923
- writable: false,
924
- value: metadataRegistry
925
- });
926
- }
927
- return metadataRegistry;
928
- }
929
- function CreateMetadataProvider(registry) {
930
- // [[Metadata]] internal slot
931
- // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
932
- var metadata = new _WeakMap();
933
- var provider = {
934
- isProviderFor: function(O, P) {
935
- var targetMetadata = metadata.get(O);
936
- if (IsUndefined(targetMetadata)) return false;
937
- return targetMetadata.has(P);
938
- },
939
- OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata,
940
- OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata,
941
- OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata,
942
- OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys,
943
- OrdinaryDeleteMetadata: OrdinaryDeleteMetadata
944
- };
945
- metadataRegistry.registerProvider(provider);
946
- return provider;
947
- function GetOrCreateMetadataMap(O, P, Create) {
948
- var targetMetadata = metadata.get(O);
949
- var createdTargetMetadata = false;
950
- if (IsUndefined(targetMetadata)) {
951
- if (!Create) return undefined;
952
- targetMetadata = new _Map();
953
- metadata.set(O, targetMetadata);
954
- createdTargetMetadata = true;
955
- }
956
- var metadataMap = targetMetadata.get(P);
957
- if (IsUndefined(metadataMap)) {
958
- if (!Create) return undefined;
959
- metadataMap = new _Map();
960
- targetMetadata.set(P, metadataMap);
961
- if (!registry.setProvider(O, P, provider)) {
962
- targetMetadata.delete(P);
963
- if (createdTargetMetadata) {
964
- metadata.delete(O);
965
- }
966
- throw new Error("Wrong provider for target.");
967
- }
968
- }
969
- return metadataMap;
970
- }
971
- // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
972
- // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
973
- function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
974
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
975
- if (IsUndefined(metadataMap)) return false;
976
- return ToBoolean(metadataMap.has(MetadataKey));
977
- }
978
- // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
979
- // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
980
- function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
981
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
982
- if (IsUndefined(metadataMap)) return undefined;
983
- return metadataMap.get(MetadataKey);
984
- }
985
- // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
986
- // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
987
- function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
988
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
989
- metadataMap.set(MetadataKey, MetadataValue);
990
- }
991
- // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
992
- // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
993
- function OrdinaryOwnMetadataKeys(O, P) {
994
- var keys = [];
995
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
996
- if (IsUndefined(metadataMap)) return keys;
997
- var keysObj = metadataMap.keys();
998
- var iterator = GetIterator(keysObj);
999
- var k = 0;
1000
- while(true){
1001
- var next = IteratorStep(iterator);
1002
- if (!next) {
1003
- keys.length = k;
1004
- return keys;
1005
- }
1006
- var nextValue = IteratorValue(next);
1007
- try {
1008
- keys[k] = nextValue;
1009
- } catch (e) {
1010
- try {
1011
- IteratorClose(iterator);
1012
- } finally{
1013
- throw e;
1014
- }
1015
- }
1016
- k++;
1017
- }
1018
- }
1019
- function OrdinaryDeleteMetadata(MetadataKey, O, P) {
1020
- var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1021
- if (IsUndefined(metadataMap)) return false;
1022
- if (!metadataMap.delete(MetadataKey)) return false;
1023
- if (metadataMap.size === 0) {
1024
- var targetMetadata = metadata.get(O);
1025
- if (!IsUndefined(targetMetadata)) {
1026
- targetMetadata.delete(P);
1027
- if (targetMetadata.size === 0) {
1028
- metadata.delete(targetMetadata);
1029
- }
1030
- }
1031
- }
1032
- return true;
1033
- }
1034
- }
1035
- function CreateFallbackProvider(reflect) {
1036
- var defineMetadata = reflect.defineMetadata, hasOwnMetadata = reflect.hasOwnMetadata, getOwnMetadata = reflect.getOwnMetadata, getOwnMetadataKeys = reflect.getOwnMetadataKeys, deleteMetadata = reflect.deleteMetadata;
1037
- var metadataOwner = new _WeakMap();
1038
- var provider = {
1039
- isProviderFor: function(O, P) {
1040
- var metadataPropertySet = metadataOwner.get(O);
1041
- if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
1042
- return true;
1043
- }
1044
- if (getOwnMetadataKeys(O, P).length) {
1045
- if (IsUndefined(metadataPropertySet)) {
1046
- metadataPropertySet = new _Set();
1047
- metadataOwner.set(O, metadataPropertySet);
1048
- }
1049
- metadataPropertySet.add(P);
1050
- return true;
1051
- }
1052
- return false;
1053
- },
1054
- OrdinaryDefineOwnMetadata: defineMetadata,
1055
- OrdinaryHasOwnMetadata: hasOwnMetadata,
1056
- OrdinaryGetOwnMetadata: getOwnMetadata,
1057
- OrdinaryOwnMetadataKeys: getOwnMetadataKeys,
1058
- OrdinaryDeleteMetadata: deleteMetadata
1059
- };
1060
- return provider;
1061
- }
1062
- /**
1063
- * Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation,
1064
- * then this module's metadata provider is assigned to the object.
1065
- */ function GetMetadataProvider(O, P, Create) {
1066
- var registeredProvider = metadataRegistry.getProvider(O, P);
1067
- if (!IsUndefined(registeredProvider)) {
1068
- return registeredProvider;
1069
- }
1070
- if (Create) {
1071
- if (metadataRegistry.setProvider(O, P, metadataProvider)) {
1072
- return metadataProvider;
1073
- }
1074
- throw new Error("Illegal state.");
1075
- }
1076
- return undefined;
1077
- }
1078
- });
1079
- })(Reflect$1 || (Reflect$1 = {}));
1080
-
1081
- // Utils
1082
- async function dynamicImport(filepath) {
1083
- return import(/* webpackIgnore: true */ process.platform === 'win32' ? `file://${filepath}` : filepath);
1084
- }
1085
- function fixDefaultExport(mod) {
1086
- return 'default' in mod ? mod.default : mod;
1087
- }
1088
-
1089
- // Container
1090
- const container = new Container();
1091
- // Utilities
1092
- const { lazyInject, lazyInjectNamed } = fixDefaultExport(getDecorators)(container);
1093
-
1094
- // Decorators
1095
- /**
1096
- * Register class as a service
1097
- */ function Service() {
1098
- return (cls)=>{
1099
- decorate(injectable(), cls);
1100
- container.bind(cls).toSelf().inSingletonScope().onActivation((ctx, service)=>{
1101
- if ('onServiceActivate' in service) {
1102
- service.onServiceActivate(ctx);
1103
- }
1104
- return service;
1105
- });
1106
- return cls;
1107
- };
1108
- }
1109
-
1110
- // Constants
1111
- const LOG_BROADCAST_CHANNEL = Symbol.for('jujulego:jill:log-broadcast-channel');
1112
- // Parameters
1113
- container.bind(LOG_BROADCAST_CHANNEL).toConstantValue('jujulego:jill:logger');
1114
-
1115
- class ThreadGateway {
1116
- // Constructor
1117
- constructor(channel){
1118
- this._source = source$();
1119
- // Methods
1120
- this.next = (data)=>{
1121
- this.channel.postMessage(data);
1122
- };
1123
- this.subscribe = this._source.subscribe;
1124
- this.unsubscribe = this._source.unsubscribe;
1125
- this.clear = this._source.clear;
1126
- this.channel = new BroadcastChannel(channel);
1127
- this.channel.unref();
1128
- this.channel.onmessage = (log)=>{
1129
- this._source.next(log.data);
1130
- };
1131
- this.channel.onmessageerror = (data)=>{
1132
- this._source.next(withTimestamp()({
1133
- level: LogLevel.error,
1134
- message: quick.string`Unable to read message: #!json:${data.data}`
1135
- }));
1136
- };
1137
- }
1138
- }
1139
- ThreadGateway = _([
1140
- Service(),
1141
- _$1(0, inject(LOG_BROADCAST_CHANNEL))
1142
- ], ThreadGateway);
1143
-
1144
- // Utils
1145
- const jillLogFormat = qlevelColor(quick.wrap(chalkTemplateStderr).function`#?:${qprop('label')}{grey [#$]} ?#${qprop('message')}#?:${qprop('error')}\n#!error$?#`);
1146
- class LogGateway {
1147
- // Lifecycle
1148
- onServiceActivate({ container }) {
1149
- const threadGtw = container.get(ThreadGateway);
1150
- if (wt.isMainThread) {
1151
- // Redirect logs to stderr
1152
- flow$(this._source, toStderr(jillLogFormat));
1153
- // Add thread gateway as input
1154
- this.connect(threadGtw);
1155
- } else {
1156
- // Redirect logs to thread gateway
1157
- flow$(this._source, threadGtw);
1158
- }
1159
- }
1160
- connect(origin) {
1161
- return flow$(origin, filter$((log)=>log.level >= this.level), this._source);
1162
- }
1163
- // Properties
1164
- get listeners() {
1165
- return Array.from(this._source.listeners);
1166
- }
1167
- get level() {
1168
- return this.level$.read();
1169
- }
1170
- set level(level) {
1171
- this.level$.mutate(level);
1172
- }
1173
- constructor(){
1174
- // Attributes
1175
- this.level$ = var$(LogLevel.info);
1176
- this._source = source$();
1177
- // Methods
1178
- this.subscribe = this._source.subscribe;
1179
- this.unsubscribe = this._source.unsubscribe;
1180
- this.clear = this._source.clear;
1181
- }
1182
- }
1183
- LogGateway = _([
1184
- Service()
1185
- ], LogGateway);
1186
-
1187
- // Service
1188
- container.bind(Logger).toDynamicValue(()=>logger$(withTimestamp())).inSingletonScope().onActivation(({ container }, logger)=>{
1189
- const gateway = container.get(LogGateway);
1190
- gateway.connect(logger);
1191
- return logger;
1192
- });
1193
-
1194
- class ContextService {
1195
- // Constructor
1196
- constructor(logger){
1197
- this._storage = new AsyncLocalStorage();
1198
- this._logger = logger.child(withLabel('context'));
1199
- this.reset();
1200
- }
1201
- // Methods
1202
- reset(context = {}) {
1203
- this._storage.enterWith(context);
1204
- }
1205
- _getContext() {
1206
- const ctx = this._storage.getStore();
1207
- if (!ctx) {
1208
- this._logger.warning('Trying to access uninitialized context');
1209
- return {};
1210
- }
1211
- return ctx;
1212
- }
1213
- _updateContext(update) {
1214
- Object.assign(this._getContext(), update);
1215
- }
1216
- // Properties
1217
- get application() {
1218
- return this._getContext().application;
1219
- }
1220
- set application(application) {
1221
- this._updateContext({
1222
- application
1223
- });
1224
- }
1225
- get project() {
1226
- return this._getContext().project;
1227
- }
1228
- set project(project) {
1229
- this._updateContext({
1230
- project
1231
- });
1232
- }
1233
- get workspace() {
1234
- return this._getContext().workspace;
1235
- }
1236
- set workspace(workspace) {
1237
- this._updateContext({
1238
- workspace
1239
- });
1240
- }
1241
- }
1242
- ContextService = _([
1243
- Service(),
1244
- _$1(0, inject(Logger))
1245
- ], ContextService);
1246
-
1247
- // Symbols
1248
- const CONFIG_OPTIONS = Symbol('jujulego:jill:config-options');
1249
- // Constants
1250
- const VERBOSITY_LEVEL = {
1251
- 1: 'verbose',
1252
- 2: 'debug'
1253
- };
1254
- // Options
1255
- function applyConfigOptions(parser) {
1256
- return parser.option('verbose', {
1257
- alias: 'v',
1258
- type: 'count',
1259
- description: 'Set verbosity level',
1260
- coerce: (cnt)=>VERBOSITY_LEVEL[Math.min(cnt, 2)]
1261
- }).option('jobs', {
1262
- alias: 'j',
1263
- type: 'number',
1264
- description: 'Set maximum parallel job number'
1265
- }).option('hooks', {
1266
- type: 'boolean',
1267
- description: 'Run hook scripts'
1268
- });
1269
- }
1270
- container.bind(CONFIG_OPTIONS).toDynamicValue(()=>{
1271
- const parser = yargs(hideBin(process.argv)).help(false).version(false);
1272
- applyConfigOptions(parser);
1273
- return parser.parse();
1274
- }).inSingletonScope();
1275
-
1276
- // Constants
1277
- const CURRENT = 'current';
1278
-
1279
- // Symbols
1280
- const MODULE = Symbol('jujulego:jill:module');
1281
- const REGISTRY = Symbol('jujulego:jill:registry');
1282
- // Utils
1283
- function getRegistry(target) {
1284
- const registry = Reflect.getMetadata(REGISTRY, target);
1285
- if (typeof registry !== 'function') {
1286
- throw new Error(`No registry found in ${target.name}`);
1287
- }
1288
- return registry;
1289
- }
1290
- function setRegistry(target, registry) {
1291
- Reflect.defineMetadata(REGISTRY, registry, target);
1292
- }
1293
- function getModule(target, assert = false) {
1294
- let module = Reflect.getMetadata(MODULE, target);
1295
- if (!module || !(module instanceof ContainerModule)) {
1296
- const registry = Reflect.getMetadata(REGISTRY, target);
1297
- if (typeof registry !== 'function') {
1298
- if (assert) {
1299
- throw new Error(`No module found in ${target.name}`);
1300
- }
1301
- return null;
1302
- }
1303
- module = new ContainerModule(registry);
1304
- setModule(target, module);
1305
- }
1306
- return module;
1307
- }
1308
- function setModule(target, module) {
1309
- Reflect.defineMetadata(MODULE, module, target);
1310
- }
1311
-
1312
- // Class
1313
- class ExitException extends Error {
1314
- // Constructor
1315
- constructor(code, message){
1316
- super(message);
1317
- this.code = code;
1318
- }
1319
- }
1320
-
1321
- // Decorator
1322
- function Middleware() {
1323
- return (target)=>{
1324
- decorate(injectable(), target);
1325
- container.bind(target).toSelf().inSingletonScope();
1326
- };
1327
- }
1328
- // Utils
1329
- function applyMiddlewares(parser, middlewares) {
1330
- let tmp = parser;
1331
- for (const cls of middlewares){
1332
- const middleware = container.get(cls);
1333
- if (middleware.builder) {
1334
- tmp = middleware.builder(tmp);
1335
- }
1336
- tmp.middleware((args)=>middleware.handler(args));
1337
- }
1338
- return tmp;
1339
- }
1340
-
1341
- // Symbols
1342
- const COMMAND_OPTS = Symbol('jujulego:jill:command-opts');
1343
- const COMMAND = Symbol('jujulego:jill:command');
1344
- const COMMAND_MODULE = Symbol('jujulego:jill:command-module');
1345
- // Utils
1346
- function getCommandOpts(target) {
1347
- const opts = Reflect.getMetadata(COMMAND_OPTS, target);
1348
- if (typeof opts !== 'object') {
1349
- throw new Error(`No command options found in ${target.name}`);
1350
- }
1351
- return opts;
1352
- }
1353
- function buildCommandModule(cmd, opts) {
1354
- return {
1355
- command: opts.command,
1356
- aliases: opts.aliases,
1357
- describe: opts.describe,
1358
- deprecated: opts.deprecated,
1359
- builder (parser) {
1360
- if (opts.middlewares) {
1361
- parser = applyMiddlewares(parser, opts.middlewares);
1362
- }
1363
- if (cmd.builder) {
1364
- parser = cmd.builder(parser);
1365
- }
1366
- return parser;
1367
- },
1368
- handler: async (args)=>{
1369
- try {
1370
- await cmd.handler(args);
1371
- } catch (err) {
1372
- if (err.message) {
1373
- const logger = container.get(Logger);
1374
- logger.error('Error while running command:', err);
1375
- }
1376
- throw new ExitException(1);
1377
- }
1378
- }
1379
- };
1380
- }
1381
- // Decorator
1382
- function Command(opts) {
1383
- return (target)=>{
1384
- decorate(injectable(), target);
1385
- Reflect.defineMetadata(COMMAND_OPTS, opts, target);
1386
- const cmd = opts.command.split(' ')[0];
1387
- setRegistry(target, (bind)=>{
1388
- bind(target).toSelf();
1389
- bind(COMMAND).toDynamicValue(({ container })=>container.getAsync(target)).whenTargetNamed(cmd);
1390
- bind(COMMAND_MODULE).toDynamicValue(async ({ container })=>{
1391
- const cmd = await container.getAsync(target);
1392
- return buildCommandModule(cmd, opts);
1393
- }).whenTargetNamed(cmd);
1394
- });
1395
- };
1396
- }
1397
-
1398
- // Symbols
1399
- const AJV = Symbol('jujulego:jill:Ajv');
1400
- // Setup
1401
- container.bind(AJV).toDynamicValue(({ container })=>{
1402
- const logger = container.get(Logger);
1403
- return new Ajv.default({
1404
- allErrors: true,
1405
- logger: logger.child(withLabel('ajv')),
1406
- strict: process.env.NODE_ENV === 'development' ? 'log' : true
1407
- });
1408
- }).inSingletonScope();
1409
-
1410
- function isCacheUpdate(msg) {
1411
- return typeof msg === 'object' && msg !== null && 'key' in msg && 'value' in msg;
1412
- }
1413
- // Chanel
1414
- const channel = new BroadcastChannel('jujulego:jill:worker-cache');
1415
- channel.unref();
1416
- channel.onmessage = (arg)=>{
1417
- const msg = arg;
1418
- if (isCacheUpdate(msg.data)) {
1419
- setEnvironmentData(msg.data.key, msg.data.value);
1420
- }
1421
- };
1422
- // Utils
1423
- async function workerCache(key, compute) {
1424
- const cache = getEnvironmentData(key);
1425
- if (cache !== undefined) return cache;
1426
- // Compute it
1427
- const result = await compute();
1428
- setEnvironmentData(key, result);
1429
- channel.postMessage({
1430
- key,
1431
- value: result
1432
- });
1433
- return result;
1434
- }
1435
-
1436
- var $schema = "http://json-schema.org/draft-07/schema";
1437
- var type = "object";
1438
- var additionalProperties = false;
1439
- var properties = {
1440
- jobs: {
1441
- type: "number"
1442
- },
1443
- hooks: {
1444
- type: "boolean",
1445
- "default": true,
1446
- description: "Run hook scripts"
1447
- },
1448
- plugins: {
1449
- type: "array",
1450
- items: {
1451
- type: "string"
1452
- }
1453
- },
1454
- verbose: {
1455
- type: "string",
1456
- "enum": [
1457
- "info",
1458
- "verbose",
1459
- "debug"
1460
- ]
1461
- }
1462
- };
1463
- var schema = {
1464
- $schema: $schema,
1465
- type: type,
1466
- additionalProperties: additionalProperties,
1467
- properties: properties
1468
- };
1469
-
1470
- // Symbols
1471
- const CONFIG_EXPLORER = Symbol('jujulego:jill:config-explorer');
1472
- const CONFIG_VALIDATOR = Symbol('jujulego:jill:config-validator');
1473
- // Setup
1474
- container.bind(CONFIG_VALIDATOR).toDynamicValue(({ container })=>{
1475
- const ajv = container.get(AJV);
1476
- return ajv.compile(schema);
1477
- }).inSingletonScope();
1478
- container.bind(CONFIG_EXPLORER).toDynamicValue(()=>{
1479
- return cosmiconfig('jill', {
1480
- searchStrategy: 'global',
1481
- loaders: {
1482
- '.cjs': (filepath)=>dynamicImport(filepath).then((mod)=>mod.default),
1483
- '.js': (filepath)=>dynamicImport(filepath).then((mod)=>mod.default),
1484
- '.json': defaultLoaders['.json'],
1485
- '.yaml': defaultLoaders['.yaml'],
1486
- '.yml': defaultLoaders['.yml'],
1487
- noExt: defaultLoaders.noExt
1488
- }
1489
- });
1490
- }).inSingletonScope();
1491
-
1492
- // Symbols
1493
- const CONFIG = Symbol('jujulego:jill:config');
1494
- // Loader
1495
- async function configLoader() {
1496
- const logger = container.get(Logger).child(withLabel('config'));
1497
- const options = container.get(CONFIG_OPTIONS);
1498
- const explorer = container.get(CONFIG_EXPLORER);
1499
- const validator = container.get(CONFIG_VALIDATOR);
1500
- // Load file
1501
- const loaded = await explorer.search();
1502
- const config = loaded?.config ?? {};
1503
- // Apply options from cli
1504
- if (options.jobs) config.jobs = options.jobs;
1505
- if (options.verbose) config.verbose = options.verbose;
1506
- if (options.hooks !== undefined) config.hooks = options.hooks;
1507
- // Apply defaults
1508
- config.jobs ??= os.cpus().length - 1;
1509
- config.hooks ??= true;
1510
- // Validate
1511
- if (!validator(config)) {
1512
- const ajv = container.get(AJV);
1513
- const errors = ajv.errorsText(validator.errors, {
1514
- separator: '\n- ',
1515
- dataVar: 'config'
1516
- });
1517
- logger.error(`Errors in config file:\n- ${errors}`);
1518
- throw new ExitException(1);
1519
- }
1520
- // Apply on logger
1521
- if (config.verbose) {
1522
- container.get(LogGateway).level = LogLevel[config.verbose];
1523
- }
1524
- if (loaded) {
1525
- // Resolve paths relative to config file
1526
- const base = path.dirname(loaded.filepath);
1527
- config.plugins = config.plugins?.map((plugin)=>path.resolve(base, plugin));
1528
- logger.verbose(`Loaded ${loaded.filepath} config file`);
1529
- }
1530
- logger.debug`Loaded config:\n#!json:${config}`;
1531
- return config;
1532
- }
1533
- container.bind(CONFIG).toDynamicValue(async ()=>await workerCache('jujulego:jill:config', configLoader)).inSingletonScope();
1534
-
1535
- class PluginLoaderService {
1536
- // Constructor
1537
- constructor(_config, logger){
1538
- this._config = _config;
1539
- this._logger = logger.child(withLabel('plugin'));
1540
- }
1541
- // Methods
1542
- async _importPlugin(filepath) {
1543
- this._logger.verbose`Loading plugin ${filepath}`;
1544
- // Load plugin
1545
- let plugin = await dynamicImport(filepath);
1546
- while(plugin && typeof plugin === 'object' && 'default' in plugin){
1547
- plugin = plugin.default;
1548
- }
1549
- if (!plugin) {
1550
- throw new Error(`Invalid plugin ${filepath}: no plugin class found`);
1551
- }
1552
- // Load module from plugin
1553
- const module = getModule(plugin);
1554
- if (!module) {
1555
- throw new Error(`Invalid plugin ${filepath}: invalid plugin class`);
1556
- }
1557
- return module;
1558
- }
1559
- async loadPlugins(ctn = container) {
1560
- if (!this._config.plugins) return;
1561
- for (const path of this._config.plugins){
1562
- const plugin = await this._importPlugin(path);
1563
- ctn.load(plugin);
1564
- }
1565
- }
1566
- }
1567
- PluginLoaderService = _([
1568
- Service(),
1569
- _$1(0, inject(CONFIG)),
1570
- _$1(1, inject(Logger))
1571
- ], PluginLoaderService);
1572
-
1573
- // Utils
1574
- function linesFrom(task, stream) {
1575
- const inner = source$();
1576
- if (task.completed) {
1577
- return inner;
1578
- }
1579
- // Listen to stream
1580
- let current = '';
1581
- const stop = task.on(`stream.${stream}`, (chunk)=>{
1582
- const data = current + chunk.data.toString('utf-8');
1583
- const lines = data.split(/\r?\n/);
1584
- current = lines.pop() ?? '';
1585
- for (const line of lines){
1586
- inner.next(line);
1587
- }
1588
- });
1589
- // Listen to end of task
1590
- once$(task, 'completed', ()=>{
1591
- stop();
1592
- if (current) {
1593
- inner.next(current);
1594
- }
1595
- });
1596
- return inner;
1597
- }
1598
-
1599
- // Utils
1600
- function isCommandCtx(ctx) {
1601
- return 'workspace' in ctx && 'command' in ctx;
1602
- }
1603
- // Class
1604
- class CommandTask extends SpawnTask {
1605
- // Constructor
1606
- constructor(workspace, command, args, opts = {}){
1607
- let cmd = command;
1608
- if (opts.superCommand) {
1609
- if (typeof opts.superCommand === 'string') {
1610
- opts.superCommand = [
1611
- opts.superCommand
1612
- ];
1613
- }
1614
- if (opts.superCommand.length > 0) {
1615
- cmd = opts.superCommand[0];
1616
- args = [
1617
- ...opts.superCommand.slice(1),
1618
- command,
1619
- ...args
1620
- ];
1621
- }
1622
- }
1623
- super(cmd, args, {
1624
- workspace,
1625
- command
1626
- }, {
1627
- ...opts,
1628
- cwd: workspace.cwd,
1629
- env: {
1630
- FORCE_COLOR: '1',
1631
- ...opts.env
1632
- }
1633
- });
1634
- this.workspace = workspace;
1635
- this._logStreams();
1636
- }
1637
- // Methods
1638
- _logStreams() {
1639
- // TODO: clean up this subscriptions
1640
- linesFrom(this, 'stdout').subscribe((line)=>this._logger.info(line));
1641
- linesFrom(this, 'stderr').subscribe((line)=>this._logger.info(line));
1642
- }
1643
- }
1644
-
1645
- // Utils
1646
- function capitalize(txt) {
1647
- return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
1648
- }
1649
- function splitCommandLine(line) {
1650
- line = line.trim();
1651
- const parts = [];
1652
- let current_cote = '';
1653
- let last = 0;
1654
- for(let i = 1; i < line.length; ++i){
1655
- const c = line[i];
1656
- if (current_cote) {
1657
- if (c === current_cote) {
1658
- current_cote = '';
1659
- }
1660
- } else {
1661
- if ([
1662
- '"',
1663
- '\''
1664
- ].includes(c)) {
1665
- current_cote = c;
1666
- } else if (c === ' ') {
1667
- parts.push(line.slice(last, i));
1668
- last = i + 1;
1669
- }
1670
- }
1671
- }
1672
- parts.push(line.slice(last));
1673
- return parts;
1674
- }
1675
-
1676
- // Utils
1677
- function isScriptCtx(ctx) {
1678
- return 'workspace' in ctx && 'script' in ctx;
1679
- }
1680
- // Class
1681
- class ScriptTask extends GroupTask {
1682
- // Constructor
1683
- constructor(workspace, script, args, opts){
1684
- super(script, {
1685
- workspace,
1686
- script
1687
- }, opts);
1688
- this.workspace = workspace;
1689
- this.script = script;
1690
- this.args = args;
1691
- this._preHookTasks = null;
1692
- this._postHookTasks = null;
1693
- this._scriptTasks = null;
1694
- this._runHooks = opts?.runHooks ?? true;
1695
- }
1696
- // Methods
1697
- async _runScript(script, args) {
1698
- const line = this.workspace.getScript(script);
1699
- if (!line) {
1700
- return null;
1701
- }
1702
- // Create command task for script
1703
- const [command, ...commandArgs] = splitCommandLine(line);
1704
- if (command === 'jill') {
1705
- this._logger.debug(`Interpreting ${line}`);
1706
- const argv = commandArgs.map((arg)=>arg.replace(/^["'](.+)["']$/, '$1'));
1707
- const { JillApplication } = await import('./jill.application-DNJpmnCF.js').then(function (n) { return n.j; });
1708
- const app = container.get(JillApplication);
1709
- const tasks = await app.tasksOf(argv, {
1710
- project: this.project,
1711
- workspace: this.workspace
1712
- });
1713
- if (tasks.length) {
1714
- const set = new TaskSet();
1715
- for (const tsk of tasks){
1716
- set.add(tsk);
1717
- }
1718
- return set;
1719
- }
1720
- }
1721
- const pm = await this.workspace.project.packageManager();
1722
- const set = new TaskSet();
1723
- set.add(new CommandTask(this.workspace, command, [
1724
- ...commandArgs,
1725
- ...args
1726
- ], {
1727
- logger: this._logger,
1728
- superCommand: pm === 'yarn' ? [
1729
- 'yarn',
1730
- 'exec'
1731
- ] : undefined
1732
- }));
1733
- return set;
1734
- }
1735
- async prepare() {
1736
- // Prepare script run
1737
- this._scriptTasks = await this._runScript(this.script, this.args);
1738
- if (!this._scriptTasks) {
1739
- throw new Error(`No script ${this.script} in ${this.workspace.name}`);
1740
- }
1741
- // Prepare hooks run
1742
- if (this._runHooks) {
1743
- this._preHookTasks = await this._runScript(`pre${this.script}`, []);
1744
- this._postHookTasks = await this._runScript(`post${this.script}`, []);
1745
- }
1746
- // Add tasks to group
1747
- if (this._preHookTasks) {
1748
- this._logger.verbose(`Found pre-hook script "pre${this.script}"`);
1749
- for (const tsk of this._preHookTasks){
1750
- this.add(tsk);
1751
- }
1752
- }
1753
- for (const tsk of this._scriptTasks){
1754
- this.add(tsk);
1755
- }
1756
- if (this._postHookTasks) {
1757
- this._logger.verbose(`Found post-hook script "post${this.script}"`);
1758
- for (const tsk of this._postHookTasks){
1759
- this.add(tsk);
1760
- }
1761
- }
1762
- }
1763
- async *_orchestrate() {
1764
- if (!this._scriptTasks) {
1765
- throw new Error('ScriptTask needs to be prepared. Call prepare before starting it');
1766
- }
1767
- // Run pre-hook
1768
- if (this._preHookTasks) {
1769
- yield* this._preHookTasks;
1770
- if (await this._hasFailed(this._preHookTasks)) {
1771
- return this.setStatus('failed');
1772
- }
1773
- }
1774
- // Run script
1775
- yield* this._scriptTasks;
1776
- if (await this._hasFailed(this._scriptTasks)) {
1777
- return this.setStatus('failed');
1778
- }
1779
- // Run post-hook
1780
- if (this._postHookTasks) {
1781
- yield* this._postHookTasks;
1782
- if (await this._hasFailed(this._postHookTasks)) {
1783
- return this.setStatus('failed');
1784
- }
1785
- }
1786
- this.setStatus('done');
1787
- }
1788
- async _hasFailed(set) {
1789
- const results = await waitFor$(set, 'finished');
1790
- return results.failed > 0;
1791
- }
1792
- _stop() {
1793
- if (!this._scriptTasks) return;
1794
- for (const tsk of this._scriptTasks){
1795
- tsk.stop();
1796
- }
1797
- }
1798
- complexity(cache = new Map()) {
1799
- let complexity = super.complexity(cache);
1800
- if (this._scriptTasks) {
1801
- complexity += this._scriptTasks.tasks.reduce((cpl, tsk)=>cpl + tsk.complexity(cache), 0);
1802
- }
1803
- cache.set(this.id, complexity);
1804
- return complexity;
1805
- }
1806
- // Properties
1807
- get project() {
1808
- return this.workspace.project;
1809
- }
1810
- }
1811
-
1812
- // Symbols
1813
- const TASK_MANAGER = Symbol('jujulego:jill:TaskManager');
1814
- // Service
1815
- container.bind(TASK_MANAGER).toDynamicValue(({ container })=>{
1816
- const config = container.get(CONFIG);
1817
- const logger = container.get(Logger);
1818
- return new TaskManager({
1819
- jobs: config.jobs,
1820
- logger
1821
- });
1822
- }).inSingletonScope();
1823
-
1824
- // Component
1825
- function List({ items, headers }) {
1826
- if (items.length === 0) {
1827
- return null;
1828
- }
1829
- return /*#__PURE__*/ jsx(Box, {
1830
- children: Object.keys(items[0]).map((key)=>/*#__PURE__*/ jsxs(Box, {
1831
- flexDirection: "column",
1832
- marginRight: 2,
1833
- children: [
1834
- headers && /*#__PURE__*/ jsx(Text, {
1835
- bold: true,
1836
- children: capitalize(key)
1837
- }),
1838
- items.map((item, idx)=>/*#__PURE__*/ jsx(Text, {
1839
- children: item[key] || ' '
1840
- }, idx))
1841
- ]
1842
- }, key))
1843
- });
1844
- }
1845
-
1846
- // Components
1847
- function TaskName({ task }) {
1848
- if (isScriptCtx(task.context)) {
1849
- return /*#__PURE__*/ jsxs(Text, {
1850
- children: [
1851
- "Run ",
1852
- /*#__PURE__*/ jsx(Text, {
1853
- bold: true,
1854
- children: task.context.script
1855
- }),
1856
- " in ",
1857
- task.context.workspace.name
1858
- ]
1859
- });
1860
- } else {
1861
- return /*#__PURE__*/ jsx(Text, {
1862
- children: task.name
1863
- });
1864
- }
1865
- }
1866
-
1867
- // Components
1868
- function TaskSpinner({ task }) {
1869
- // State
1870
- const [status, setStatus] = useState(task.status);
1871
- const [time, setTime] = useState(task.duration);
1872
- // Effects
1873
- useLayoutEffect(()=>{
1874
- return task.on('status', (event)=>{
1875
- setStatus(event.status);
1876
- });
1877
- }, [
1878
- task
1879
- ]);
1880
- useLayoutEffect(()=>{
1881
- return task.on('completed', ({ duration })=>{
1882
- setTime(duration);
1883
- });
1884
- }, [
1885
- task
1886
- ]);
1887
- // Render
1888
- const isScriptChild = isCommandCtx(task.context) && task.group && isScriptCtx(task.group.context);
1889
- switch(status){
1890
- case 'blocked':
1891
- case 'ready':
1892
- case 'starting':
1893
- return /*#__PURE__*/ jsxs(Box, {
1894
- children: [
1895
- /*#__PURE__*/ jsx(Text, {
1896
- color: "grey",
1897
- children: '\u00B7'
1898
- }),
1899
- /*#__PURE__*/ jsx(Box, {
1900
- paddingLeft: 1,
1901
- children: /*#__PURE__*/ jsx(Text, {
1902
- color: "grey",
1903
- wrap: "truncate",
1904
- children: /*#__PURE__*/ jsx(TaskName, {
1905
- task: task
1906
- })
1907
- })
1908
- })
1909
- ]
1910
- });
1911
- case 'running':
1912
- return /*#__PURE__*/ jsxs(Box, {
1913
- children: [
1914
- /*#__PURE__*/ jsx(Text, {
1915
- color: isScriptChild ? 'dim' : undefined,
1916
- children: /*#__PURE__*/ jsx(Spinner, {})
1917
- }),
1918
- /*#__PURE__*/ jsx(Box, {
1919
- paddingLeft: 1,
1920
- children: /*#__PURE__*/ jsx(Text, {
1921
- color: isScriptChild ? 'dim' : undefined,
1922
- wrap: "truncate",
1923
- children: /*#__PURE__*/ jsx(TaskName, {
1924
- task: task
1925
- })
1926
- })
1927
- })
1928
- ]
1929
- });
1930
- case 'done':
1931
- return /*#__PURE__*/ jsxs(Box, {
1932
- children: [
1933
- /*#__PURE__*/ jsx(Text, {
1934
- color: "green",
1935
- children: symbols.success
1936
- }),
1937
- /*#__PURE__*/ jsx(Box, {
1938
- paddingLeft: 1,
1939
- children: /*#__PURE__*/ jsx(Text, {
1940
- color: isScriptChild ? 'dim' : undefined,
1941
- wrap: "truncate",
1942
- children: /*#__PURE__*/ jsx(TaskName, {
1943
- task: task
1944
- })
1945
- })
1946
- }),
1947
- /*#__PURE__*/ jsx(Box, {
1948
- paddingLeft: 1,
1949
- flexShrink: 0,
1950
- children: /*#__PURE__*/ jsxs(Text, {
1951
- color: isScriptChild ? 'grey' : 'dim',
1952
- children: [
1953
- "(took ",
1954
- ms(time),
1955
- ")"
1956
- ]
1957
- })
1958
- })
1959
- ]
1960
- });
1961
- case 'failed':
1962
- return /*#__PURE__*/ jsxs(Box, {
1963
- children: [
1964
- /*#__PURE__*/ jsx(Text, {
1965
- color: "red",
1966
- children: symbols.error
1967
- }),
1968
- /*#__PURE__*/ jsx(Box, {
1969
- paddingLeft: 1,
1970
- children: /*#__PURE__*/ jsx(Text, {
1971
- color: isScriptChild ? 'dim' : undefined,
1972
- wrap: "truncate",
1973
- children: /*#__PURE__*/ jsx(TaskName, {
1974
- task: task
1975
- })
1976
- })
1977
- }),
1978
- /*#__PURE__*/ jsx(Box, {
1979
- paddingLeft: 1,
1980
- flexShrink: 0,
1981
- children: /*#__PURE__*/ jsxs(Text, {
1982
- color: isScriptChild ? 'grey' : 'dim',
1983
- children: [
1984
- "(took ",
1985
- ms(time),
1986
- ")"
1987
- ]
1988
- })
1989
- })
1990
- ]
1991
- });
1992
- }
1993
- }
1994
-
1995
- // Utils
1996
- function printJson(data, stream = process.stdout) {
1997
- if (stream.isTTY) {
1998
- stream.write(JSON.stringify(data, null, 2));
1999
- } else {
2000
- stream.write(JSON.stringify(data));
2001
- }
2002
- }
2003
-
2004
- // Component
2005
- function StaticLogs() {
2006
- // State
2007
- const { write } = useStderr();
2008
- // Effect
2009
- useLayoutEffect(()=>{
2010
- const gateway = container.get(LogGateway);
2011
- // Remove Console transport
2012
- const listeners = gateway.listeners;
2013
- gateway.clear();
2014
- // Add custom transport
2015
- const off = gateway.subscribe((log)=>{
2016
- write(jillLogFormat(log) + '\n');
2017
- });
2018
- return ()=>{
2019
- off();
2020
- // Restore previous listeners
2021
- for (const lst of listeners){
2022
- gateway.subscribe(lst);
2023
- }
2024
- };
2025
- }, [
2026
- write
2027
- ]);
2028
- return null;
2029
- }
2030
-
2031
- // Component
2032
- function Layout({ children }) {
2033
- return /*#__PURE__*/ jsxs(Fragment, {
2034
- children: [
2035
- /*#__PURE__*/ jsx(StaticLogs, {}),
2036
- children
2037
- ]
2038
- });
2039
- }
2040
-
2041
- // Constants
2042
- const INK_APP = Symbol.for('jujulego:jill:ink-app');
2043
- // Setup
2044
- container.bind(INK_APP).toDynamicValue(()=>{
2045
- if (!wt.isMainThread) {
2046
- throw new Error('Ink should only be used in main thread');
2047
- }
2048
- return render(/*#__PURE__*/ jsx(Layout, {}));
2049
- }).inSingletonScope();
2050
-
2051
- class InkCommand {
2052
- builder(parser) {
2053
- return parser;
2054
- }
2055
- async handler(args) {
2056
- for await (const children of this.render(args)){
2057
- this.app.rerender(/*#__PURE__*/ jsx(Layout, {
2058
- children: children
2059
- }));
2060
- }
2061
- }
2062
- }
2063
- _([
2064
- lazyInject(INK_APP)
2065
- ], InkCommand.prototype, "app", void 0);
2066
- InkCommand = _([
2067
- injectable()
2068
- ], InkCommand);
2069
-
2070
- 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 };
2071
- //# sourceMappingURL=ink-command-CsbkuRbm.js.map