@bemoje/monorepo 1.1.1 → 1.2.1

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 (127) hide show
  1. package/lib/MonoRepo.cjs +7370 -0
  2. package/lib/MonoRepo.d.cts +10 -0
  3. package/lib/MonoRepo.d.ts +10 -0
  4. package/lib/MonoRepo.js +7361 -0
  5. package/lib/code/AbstractCode.cjs +5568 -0
  6. package/lib/code/AbstractCode.d.cts +30 -0
  7. package/lib/code/AbstractCode.d.ts +30 -0
  8. package/lib/code/AbstractCode.js +5562 -0
  9. package/lib/code/CodeBlock.cjs +5614 -0
  10. package/lib/code/CodeBlock.d.cts +22 -0
  11. package/lib/code/CodeBlock.d.ts +22 -0
  12. package/lib/code/CodeBlock.js +5608 -0
  13. package/lib/code/TsCode.cjs +7370 -0
  14. package/lib/code/TsCode.d.cts +10 -0
  15. package/lib/code/TsCode.d.ts +10 -0
  16. package/lib/code/TsCode.js +7361 -0
  17. package/lib/code/imports/ImportKeywords.cjs +5652 -0
  18. package/lib/code/imports/ImportKeywords.d.cts +10 -0
  19. package/lib/code/imports/ImportKeywords.d.ts +10 -0
  20. package/lib/code/imports/ImportKeywords.js +5646 -0
  21. package/lib/code/imports/ImportSpecifiers.cjs +5708 -0
  22. package/lib/code/imports/ImportSpecifiers.d.cts +10 -0
  23. package/lib/code/imports/ImportSpecifiers.d.ts +10 -0
  24. package/lib/code/imports/ImportSpecifiers.js +5702 -0
  25. package/lib/code/imports/ImportStatement.cjs +7372 -0
  26. package/lib/code/imports/ImportStatement.d.cts +10 -0
  27. package/lib/code/imports/ImportStatement.d.ts +10 -0
  28. package/lib/code/imports/ImportStatement.js +7363 -0
  29. package/lib/code/imports/ModuleSpecifier.cjs +7372 -0
  30. package/lib/code/imports/ModuleSpecifier.d.cts +10 -0
  31. package/lib/code/imports/ModuleSpecifier.d.ts +10 -0
  32. package/lib/code/imports/ModuleSpecifier.js +7363 -0
  33. package/lib/common/AbstractBase.cjs +638 -0
  34. package/lib/common/AbstractBase.d.cts +3 -0
  35. package/lib/common/AbstractBase.d.ts +3 -0
  36. package/lib/common/AbstractBase.js +634 -0
  37. package/lib/file/File.cjs +5496 -0
  38. package/lib/file/File.d.cts +10 -0
  39. package/lib/file/File.d.ts +10 -0
  40. package/lib/file/File.js +5490 -0
  41. package/lib/file/TestFile.cjs +7368 -0
  42. package/lib/file/TestFile.d.cts +10 -0
  43. package/lib/file/TestFile.d.ts +10 -0
  44. package/lib/file/TestFile.js +7359 -0
  45. package/lib/file/TsFile.cjs +7368 -0
  46. package/lib/file/TsFile.d.cts +10 -0
  47. package/lib/file/TsFile.d.ts +10 -0
  48. package/lib/file/TsFile.js +7359 -0
  49. package/lib/index.cjs +7698 -0
  50. package/lib/index.d.cts +26 -0
  51. package/lib/index.d.ts +26 -0
  52. package/lib/index.js +7672 -0
  53. package/lib/methods/findWorkspacePackageName.cjs +86 -0
  54. package/lib/methods/findWorkspacePackageName.d.cts +6 -0
  55. package/lib/methods/findWorkspacePackageName.d.ts +6 -0
  56. package/lib/methods/findWorkspacePackageName.js +78 -0
  57. package/lib/methods/getAllImports.cjs +20 -0
  58. package/lib/methods/getAllImports.d.cts +17 -0
  59. package/lib/methods/getAllImports.d.ts +17 -0
  60. package/lib/methods/getAllImports.js +18 -0
  61. package/lib/methods/getAllWorkspacePackageJsonPaths.cjs +57 -0
  62. package/lib/methods/getAllWorkspacePackageJsonPaths.d.cts +6 -0
  63. package/lib/methods/getAllWorkspacePackageJsonPaths.d.ts +6 -0
  64. package/lib/methods/getAllWorkspacePackageJsonPaths.js +49 -0
  65. package/lib/methods/getAllWorkspacePackageJsons.cjs +66 -0
  66. package/lib/methods/getAllWorkspacePackageJsons.d.cts +6 -0
  67. package/lib/methods/getAllWorkspacePackageJsons.d.ts +6 -0
  68. package/lib/methods/getAllWorkspacePackageJsons.js +58 -0
  69. package/lib/methods/getAllWorkspacePackageNames.cjs +75 -0
  70. package/lib/methods/getAllWorkspacePackageNames.d.cts +6 -0
  71. package/lib/methods/getAllWorkspacePackageNames.d.ts +6 -0
  72. package/lib/methods/getAllWorkspacePackageNames.js +67 -0
  73. package/lib/methods/getAllWorkspacePaths.cjs +50 -0
  74. package/lib/methods/getAllWorkspacePaths.d.cts +6 -0
  75. package/lib/methods/getAllWorkspacePaths.d.ts +6 -0
  76. package/lib/methods/getAllWorkspacePaths.js +42 -0
  77. package/lib/methods/getImportsRecursively.cjs +7577 -0
  78. package/lib/methods/getImportsRecursively.d.cts +37 -0
  79. package/lib/methods/getImportsRecursively.d.ts +37 -0
  80. package/lib/methods/getImportsRecursively.js +7566 -0
  81. package/lib/methods/getRepoPackageJson.cjs +40 -0
  82. package/lib/methods/getRepoPackageJson.d.cts +6 -0
  83. package/lib/methods/getRepoPackageJson.d.ts +6 -0
  84. package/lib/methods/getRepoPackageJson.js +32 -0
  85. package/lib/methods/getRepoPackageJsonPath.cjs +34 -0
  86. package/lib/methods/getRepoPackageJsonPath.d.cts +6 -0
  87. package/lib/methods/getRepoPackageJsonPath.d.ts +6 -0
  88. package/lib/methods/getRepoPackageJsonPath.js +26 -0
  89. package/lib/repo/Workspace.cjs +7370 -0
  90. package/lib/repo/Workspace.d.cts +10 -0
  91. package/lib/repo/Workspace.d.ts +10 -0
  92. package/lib/repo/Workspace.js +7361 -0
  93. package/lib/util/SemanticExtnamePrefix.cjs +13 -0
  94. package/lib/util/SemanticExtnamePrefix.d.cts +14 -0
  95. package/lib/util/SemanticExtnamePrefix.d.ts +14 -0
  96. package/lib/util/SemanticExtnamePrefix.js +11 -0
  97. package/lib/util/SemanticExtnamePrefixDescriptions.cjs +13 -0
  98. package/lib/util/SemanticExtnamePrefixDescriptions.d.cts +15 -0
  99. package/lib/util/SemanticExtnamePrefixDescriptions.d.ts +15 -0
  100. package/lib/util/SemanticExtnamePrefixDescriptions.js +11 -0
  101. package/lib/util/SemanticExtnamePrefixes.cjs +18 -0
  102. package/lib/util/SemanticExtnamePrefixes.d.cts +97 -0
  103. package/lib/util/SemanticExtnamePrefixes.d.ts +97 -0
  104. package/lib/util/SemanticExtnamePrefixes.js +14 -0
  105. package/lib/util/getRepoRootDirpath.cjs +30 -0
  106. package/lib/util/getRepoRootDirpath.d.cts +6 -0
  107. package/lib/util/getRepoRootDirpath.d.ts +6 -0
  108. package/lib/util/getRepoRootDirpath.js +22 -0
  109. package/lib/util/getWorkspaceDirpaths.cjs +42 -0
  110. package/lib/util/getWorkspaceDirpaths.d.cts +6 -0
  111. package/lib/util/getWorkspaceDirpaths.d.ts +6 -0
  112. package/lib/util/getWorkspaceDirpaths.js +34 -0
  113. package/lib/util/hasExtnamePrefix.cjs +27 -0
  114. package/lib/util/hasExtnamePrefix.d.cts +38 -0
  115. package/lib/util/hasExtnamePrefix.d.ts +38 -0
  116. package/lib/util/hasExtnamePrefix.js +25 -0
  117. package/lib/util/resolveModuleImportPath.cjs +51 -0
  118. package/lib/util/resolveModuleImportPath.d.cts +8 -0
  119. package/lib/util/resolveModuleImportPath.d.ts +8 -0
  120. package/lib/util/resolveModuleImportPath.js +42 -0
  121. package/lib/util/semverVersionBump.cjs +30 -0
  122. package/lib/util/semverVersionBump.d.cts +22 -0
  123. package/lib/util/semverVersionBump.d.ts +22 -0
  124. package/lib/util/semverVersionBump.js +28 -0
  125. package/package.json +464 -31
  126. package/index.d.ts +0 -636
  127. package/index.mjs +0 -2321
package/index.mjs DELETED
@@ -1,2321 +0,0 @@
1
- import { mapValues, cloneDeep } from 'es-toolkit/object';
2
- import colors2 from 'ansi-colors';
3
- import { inspect, promisify } from 'util';
4
- import { isObjectLike, omit } from 'es-toolkit/compat';
5
- import { DefaultMap, MultiSet } from 'mnemonist';
6
- import fs from 'fs';
7
- import { isFunction } from 'es-toolkit/predicate';
8
- import memoizee from 'memoizee';
9
- import { ms } from 'enhanced-ms';
10
- import path2 from 'upath';
11
- import { builtinModules } from 'module';
12
- import strip from 'strip-comments';
13
- import { uniq } from 'es-toolkit';
14
- import { difference, union } from 'es-toolkit/array';
15
- import { exec } from 'child_process';
16
- import fs3, { readJsonSync } from 'fs-extra/esm';
17
- import { resolveModuleName, createCompilerHost } from 'typescript';
18
- import fs2 from 'fs-extra';
19
- import onetime from 'onetime';
20
- import walkdir from 'walkdir';
21
- import { glob, globSync } from 'glob';
22
-
23
- var __defProp = Object.defineProperty;
24
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
-
26
- // ../composition/src/View.ts
27
- var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
28
- var View = class {
29
- static {
30
- __name(this, "View");
31
- }
32
- [TARGET_SYMBOL];
33
- constructor(target) {
34
- this[TARGET_SYMBOL] = target;
35
- }
36
- get [Symbol.toStringTag]() {
37
- return this.constructor.name;
38
- }
39
- get target() {
40
- return this[TARGET_SYMBOL];
41
- }
42
- };
43
-
44
- // ../is/src/isConstructor.ts
45
- function isConstructor(value) {
46
- if (typeof value !== "function") {
47
- return false;
48
- }
49
- if (!value.prototype || value.prototype.constructor !== value) {
50
- return false;
51
- }
52
- return true;
53
- }
54
- __name(isConstructor, "isConstructor");
55
-
56
- // ../object/src/defineGetter.ts
57
- function defineGetter(obj, key, get, des = {}) {
58
- return Object.defineProperty(obj, key, {
59
- configurable: true,
60
- enumerable: false,
61
- get,
62
- ...des
63
- });
64
- }
65
- __name(defineGetter, "defineGetter");
66
-
67
- // ../object/src/defineValue.ts
68
- function defineValue(obj, key, value, des = {}) {
69
- return Object.defineProperty(obj, key, {
70
- configurable: true,
71
- value,
72
- enumerable: true,
73
- ...des
74
- });
75
- }
76
- __name(defineValue, "defineValue");
77
-
78
- // ../object/src/defineLazyProperty.ts
79
- function defineLazyProperty(obj, key, get, des = {}) {
80
- function getter() {
81
- const value = get.call(this);
82
- defineValue(this, key, value);
83
- return value;
84
- }
85
- __name(getter, "getter");
86
- return defineGetter(obj, key, getter, des);
87
- }
88
- __name(defineLazyProperty, "defineLazyProperty");
89
-
90
- // ../object/src/defineMethod.ts
91
- function defineMethod(obj, key, value, des = {}) {
92
- return Object.defineProperty(obj, key, {
93
- value,
94
- configurable: true,
95
- writable: true,
96
- enumerable: false,
97
- ...des
98
- });
99
- }
100
- __name(defineMethod, "defineMethod");
101
-
102
- // ../object/src/getClassChain.ts
103
- function getClassChain(target, options) {
104
- const ctor = isConstructor(target) ? target : target.constructor;
105
- const result = [];
106
- if (options?.includeSelf) {
107
- result.push(ctor);
108
- }
109
- let current = ctor;
110
- while (current = Reflect.getPrototypeOf(current)) {
111
- if (current === Function.prototype || current === Object.prototype) {
112
- result.push(Object);
113
- break;
114
- }
115
- result.push(current);
116
- }
117
- return result;
118
- }
119
- __name(getClassChain, "getClassChain");
120
-
121
- // ../object/src/hasOwnProperty.ts
122
- function hasOwnProperty(object, key) {
123
- return Object.prototype.hasOwnProperty.call(object, key);
124
- }
125
- __name(hasOwnProperty, "hasOwnProperty");
126
-
127
- // ../object/src/hasPrototypeChainProperty.ts
128
- function hasPrototypeChainProperty(object, key) {
129
- return getClassChain(object).some((ctor) => {
130
- return hasOwnProperty(ctor.prototype, key);
131
- });
132
- }
133
- __name(hasPrototypeChainProperty, "hasPrototypeChainProperty");
134
-
135
- // ../object/src/hasProperty.ts
136
- function hasProperty(object, key) {
137
- return hasOwnProperty(object, key) || hasPrototypeChainProperty(object, key);
138
- }
139
- __name(hasProperty, "hasProperty");
140
-
141
- // ../composition/src/inspector/defaults/ignoreValuesFilterDefaults.ts
142
- var ignoreValuesFilterDefaults = {
143
- noFalse: /* @__PURE__ */ __name((value) => {
144
- return value !== false;
145
- }, "noFalse"),
146
- noNull: /* @__PURE__ */ __name((value) => {
147
- return value !== null;
148
- }, "noNull"),
149
- noUndefined: /* @__PURE__ */ __name((value) => {
150
- return value !== void 0;
151
- }, "noUndefined"),
152
- noEmptyArray: /* @__PURE__ */ __name((value) => {
153
- return !Array.isArray(value) || !!value.length;
154
- }, "noEmptyArray"),
155
- noEmptyObject: /* @__PURE__ */ __name((value) => {
156
- return !value || typeof value !== "object" || Array.isArray(value) || !!Object.keys(value).length;
157
- }, "noEmptyObject")
158
- };
159
-
160
- // ../composition/src/inspector/defaults/ignoreValuesDefaults.ts
161
- var ignoreValuesDefaults = {
162
- noEmptyArray: true,
163
- noEmptyObject: true,
164
- noNull: true,
165
- noUndefined: true,
166
- noFalse: false
167
- };
168
- var inspectDefaults = {
169
- ...inspect.defaultOptions,
170
- customInspect: true,
171
- maxStringLength: 500,
172
- maxArrayLength: 200,
173
- breakLength: 100,
174
- colors: true,
175
- depth: 100,
176
- compact: false,
177
- numericSeparator: true
178
- };
179
-
180
- // ../composition/src/inspector/defaults/inspectorDefaults.ts
181
- var inspectorDefaults = {
182
- inspect: inspectDefaults,
183
- ignoreValues: ignoreValuesDefaults,
184
- keys: [],
185
- autoAddBooleanKeys: false,
186
- ignoreKeys: [],
187
- filters: []
188
- };
189
- var Inspector = class _Inspector extends View {
190
- static {
191
- __name(this, "Inspector");
192
- }
193
- /**
194
- * Composes a class with Inspector capabilities by adding inspection methods to its prototype.
195
- * This follows the Composition pattern to extend classes without inheritance.
196
- */
197
- static compose(cls, options = {}) {
198
- if (!hasProperty(cls.prototype, inspect.custom)) {
199
- defineMethod(cls.prototype, inspect.custom, function(depth, options2) {
200
- return this.inspector.inspect(depth, options2);
201
- });
202
- }
203
- if (!hasProperty(cls.prototype, "inspector")) {
204
- defineLazyProperty(cls.prototype, "inspector", /* @__PURE__ */ __name(function get() {
205
- return new _Inspector(this);
206
- }, "get"));
207
- }
208
- if (!hasProperty(cls.prototype, "toJSON")) {
209
- defineMethod(cls.prototype, "toJSON", function() {
210
- return this.inspector.toObject();
211
- });
212
- }
213
- return options;
214
- }
215
- /**
216
- * Compile the target object and return the output as an object.
217
- */
218
- toObject(depth = 0) {
219
- const result = mapValues(this.compile(depth).output, (value) => {
220
- if (!value) {
221
- return value;
222
- }
223
- if (typeof value !== "object") {
224
- return value;
225
- }
226
- if (Array.isArray(value)) {
227
- return value.map((v) => {
228
- if (v.inspector && v.inspector instanceof _Inspector) {
229
- return v.inspector.toObject(depth + 1);
230
- }
231
- return v;
232
- });
233
- }
234
- if (value.inspector && value.inspector instanceof _Inspector) {
235
- return value.inspector.toObject(depth + 1);
236
- }
237
- return value;
238
- });
239
- return {
240
- T: this.target.constructor.name,
241
- ...result
242
- };
243
- }
244
- /**
245
- * Inspect the target object.
246
- */
247
- inspect(depth = 0, options = {}) {
248
- const { output, inspectOptions } = this.compile(depth);
249
- Object.assign(inspectOptions, options);
250
- const result = inspect(output, options);
251
- return result.replaceAll(/Object \[\w+] {/gm, (match) => {
252
- match = match.substring(8, match.length - 3);
253
- return `[${inspectOptions.colors ? colors2.magenta(match) : match}] {`;
254
- });
255
- }
256
- /**
257
- * Compiles the output object and inspect options.
258
- * Merges prototype chain options and applies filters to determine which properties to include.
259
- */
260
- compile(depth = 0) {
261
- const output = Object.defineProperty({}, Symbol.toStringTag, {
262
- value: this.target.constructor.name,
263
- configurable: true
264
- });
265
- const options = this.mergePrototypeOptions();
266
- const keys = new Set(options.keys);
267
- if (options.autoAddBooleanKeys) {
268
- const insBooleanValueKeys = Object.entries(this.target).filter(([_key, value]) => {
269
- return typeof value === "boolean";
270
- }).map(([key]) => {
271
- return key;
272
- });
273
- const protoGetterKeys = getClassChain(this.target, {
274
- includeSelf: false
275
- }).map((cls) => {
276
- return Object.getOwnPropertyNames(cls.prototype).filter((key) => {
277
- return hasOwnProperty(Reflect.getOwnPropertyDescriptor(cls.prototype, key), "get");
278
- });
279
- }).flat(2);
280
- const booleanKeys = insBooleanValueKeys.concat(protoGetterKeys).filter((key) => {
281
- return /^(is|was|has|should)[A-Z]/.test(key);
282
- });
283
- booleanKeys.forEach((key) => {
284
- return keys.add(key);
285
- });
286
- }
287
- const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) => {
288
- return enabled;
289
- }).map(([name]) => {
290
- return ignoreValuesFilterDefaults[name];
291
- });
292
- const objectValues = [];
293
- const arrayValues = [];
294
- for (const key of keys) {
295
- const value = this.target[key];
296
- if (!ignoreFilters.every((filter) => {
297
- return filter(value);
298
- })) {
299
- continue;
300
- }
301
- if (!options.filters.every((filter) => {
302
- return filter.call(this.target, value, key, depth, output);
303
- })) {
304
- continue;
305
- }
306
- if (Array.isArray(value)) {
307
- arrayValues.push(() => {
308
- return defineValue(output, key, value);
309
- });
310
- } else if (isObjectLike(value)) {
311
- objectValues.push(() => {
312
- return defineValue(output, key, value);
313
- });
314
- } else {
315
- defineValue(output, key, value);
316
- }
317
- }
318
- objectValues.forEach((fn) => {
319
- return fn();
320
- });
321
- arrayValues.forEach((fn) => {
322
- return fn();
323
- });
324
- return {
325
- output,
326
- inspectOptions: options.inspect
327
- };
328
- }
329
- /**
330
- * Walks the prototype chain and merges Inspector options from all classes.
331
- * Subclass options override superclass options following inheritance semantics.
332
- */
333
- mergePrototypeOptions() {
334
- const defaults = this.getDefaults();
335
- let inspectOptions = defaults.inspect;
336
- const keys = new Set(defaults.keys);
337
- let autoAddBooleanKeys = defaults.autoAddBooleanKeys;
338
- const ignoreKeys = new Set(defaults.ignoreKeys);
339
- const ignoreValues = defaults.ignoreValues;
340
- const customFilters = defaults.filters;
341
- const prototypeChainOptions = getClassChain(this.target.constructor, {
342
- includeSelf: true
343
- }).reverse().map((cls) => {
344
- return cls.inspector ?? {};
345
- });
346
- for (const options of prototypeChainOptions) {
347
- if (options.inspect) {
348
- inspectOptions = {
349
- ...inspectOptions,
350
- ...options.inspect
351
- };
352
- }
353
- options.keys?.forEach((elem) => {
354
- return keys.add(elem);
355
- });
356
- if (options.autoAddBooleanKeys != null) {
357
- autoAddBooleanKeys = options.autoAddBooleanKeys;
358
- }
359
- keys.forEach((elem) => {
360
- return ignoreKeys.delete(elem);
361
- });
362
- options.ignoreKeys?.forEach((elem) => {
363
- return ignoreKeys.add(elem);
364
- });
365
- ignoreKeys.forEach((elem) => {
366
- return keys.delete(elem);
367
- });
368
- if (options.ignoreValues) {
369
- Object.assign(ignoreValues, options.ignoreValues);
370
- }
371
- options.filters?.forEach((filter) => {
372
- return customFilters.push(filter);
373
- });
374
- }
375
- return {
376
- inspect: inspectOptions,
377
- ignoreValues,
378
- autoAddBooleanKeys,
379
- keys: Array.from(keys),
380
- ignoreKeys: Array.from(ignoreKeys),
381
- filters: customFilters
382
- };
383
- }
384
- /**
385
- * Returns a deep clone of the default Inspector options.
386
- */
387
- getDefaults() {
388
- const filters = inspectorDefaults.filters.slice();
389
- const rest = cloneDeep(omit(inspectorDefaults, "filters"));
390
- return {
391
- ...rest,
392
- filters
393
- };
394
- }
395
- };
396
- var ParentRelationTypes = class _ParentRelationTypes extends View {
397
- static {
398
- __name(this, "ParentRelationTypes");
399
- }
400
- registerParent(parentType) {
401
- _ParentRelationTypes.parentTypesStats.get(this.target).add(parentType);
402
- _ParentRelationTypes.childTypesStats.get(parentType).add(this.target);
403
- }
404
- get hasParent() {
405
- return _ParentRelationTypes.parentTypesStats.has(this.target);
406
- }
407
- get getParentTypes() {
408
- return _ParentRelationTypes.parentTypesStats.get(this.target);
409
- }
410
- get hasChildren() {
411
- return _ParentRelationTypes.childTypesStats.has(this.target);
412
- }
413
- get getChildTypes() {
414
- return _ParentRelationTypes.childTypesStats.get(this.target);
415
- }
416
- get isRoot() {
417
- return !this.hasParent && this.hasChildren;
418
- }
419
- get isLeaf() {
420
- return this.hasParent && !this.hasChildren;
421
- }
422
- get isIsolated() {
423
- return !this.hasParent && !this.hasChildren;
424
- }
425
- static getAllChildTypesStats() {
426
- const res = {};
427
- Array.from(this.childTypesStats.entries()).map(([cls, multimap]) => {
428
- multimap.forEachMultiplicity((count, key) => {
429
- if (!res[cls.name]) {
430
- res[cls.name] = {};
431
- }
432
- if (!res[cls.name][key.name]) {
433
- res[cls.name][key.name] = count;
434
- }
435
- });
436
- });
437
- return res;
438
- }
439
- static getAllParentTypesStats() {
440
- const res = {};
441
- Array.from(this.parentTypesStats.entries()).map(([cls, multimap]) => {
442
- multimap.forEachMultiplicity((count, key) => {
443
- if (!res[cls.name]) {
444
- res[cls.name] = {};
445
- }
446
- if (!res[cls.name][key.name]) {
447
- res[cls.name][key.name] = count;
448
- }
449
- });
450
- });
451
- return res;
452
- }
453
- static getAllStats() {
454
- const classes = /* @__PURE__ */ new Set([
455
- ...Array.from(this.childTypesStats.keys()),
456
- ...Array.from(this.parentTypesStats.keys())
457
- ]);
458
- return Array.from(classes).map((cls) => {
459
- const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
460
- return [
461
- cls2.name,
462
- count
463
- ];
464
- });
465
- const children = Array.from(this.childTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
466
- return [
467
- cls2.name,
468
- count
469
- ];
470
- });
471
- const result = {
472
- class: cls.name
473
- };
474
- if (parents.length) {
475
- result.parents = Object.fromEntries(parents);
476
- }
477
- if (children.length) {
478
- result.children = Object.fromEntries(children);
479
- }
480
- return result;
481
- });
482
- }
483
- static printAllStats() {
484
- console.log();
485
- console.log(colors2.bold.yellow("Parent-Child Relation Stats"));
486
- for (const stats of this.getAllStats()) {
487
- console.log(stats.class);
488
- if (stats.parents) {
489
- let prefix = ` ${colors2.dim("parents : ")}`;
490
- for (const [parent, count] of Object.entries(stats.parents)) {
491
- console.log(`${prefix}${colors2.blue(parent)}: ${colors2.yellow(String(count))}`);
492
- prefix = " ".repeat(12);
493
- }
494
- }
495
- if (stats.children) {
496
- let prefix = ` ${colors2.dim("children : ")}`;
497
- for (const [child, count] of Object.entries(stats.children)) {
498
- console.log(`${prefix}${colors2.green(child)}: ${colors2.yellow(String(count))}`);
499
- prefix = " ".repeat(12);
500
- }
501
- }
502
- console.log();
503
- }
504
- }
505
- static childTypesStats = new DefaultMap(() => {
506
- return new MultiSet();
507
- });
508
- static parentTypesStats = new DefaultMap(() => {
509
- return new MultiSet();
510
- });
511
- };
512
- var Parenting = class _Parenting extends View {
513
- static {
514
- __name(this, "Parenting");
515
- }
516
- /**
517
- * Class decorator to register and correctly initialize a class as a 'parentingTarget'.
518
- */
519
- static compose(cls) {
520
- if (!hasProperty(cls, "parenting")) {
521
- defineLazyProperty(cls, "parenting", function() {
522
- return new ParentRelationTypes(this);
523
- });
524
- }
525
- if (!hasProperty(cls.prototype, "parenting")) {
526
- defineLazyProperty(cls.prototype, "parenting", function() {
527
- return new _Parenting(this);
528
- });
529
- }
530
- }
531
- /**
532
- * Store a weak refences to the target object's parent.
533
- */
534
- onInstance(parent) {
535
- if (!parent) {
536
- return;
537
- }
538
- const targetClass = this.parentingTargetConstructor;
539
- _Parenting.parentWeakRefMap.get(targetClass).set(this.target, parent);
540
- targetClass.parenting?.registerParent(parent.constructor);
541
- }
542
- /**
543
- * Retrieve the parent object of 'target' object.
544
- */
545
- getParent() {
546
- const map = _Parenting.parentWeakRefMap.get(this.parentingTargetConstructor);
547
- const parent = map.get(this.target);
548
- return parent;
549
- }
550
- /**
551
- * Recursively get parent until no parent is found or a circular reference is detected.
552
- */
553
- *iterateAncestors() {
554
- let node = this.target.parenting.getParent();
555
- if (!node) {
556
- return;
557
- }
558
- const seen = /* @__PURE__ */ new Set();
559
- while (node) {
560
- if (seen.has(node)) {
561
- return;
562
- }
563
- seen.add(node);
564
- yield node;
565
- node = node?.parenting?.getParent();
566
- }
567
- }
568
- /**
569
- * The depth of the object in the parent-child hierarchy.
570
- */
571
- get depth() {
572
- return [
573
- ...this.iterateAncestors()
574
- ].length;
575
- }
576
- /**
577
- * The class constructor of the target object.
578
- */
579
- get parentingTargetConstructor() {
580
- return this.target.constructor;
581
- }
582
- /**
583
- * A WeakMap for parent references.
584
- */
585
- static parentWeakRefMap = new DefaultMap(() => {
586
- return /* @__PURE__ */ new WeakMap();
587
- });
588
- };
589
-
590
- // src/common/AbstractBase.ts
591
- function _ts_decorate(decorators, target, key, desc) {
592
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
593
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
594
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
595
- return c > 3 && r && Object.defineProperty(target, key, r), r;
596
- }
597
- __name(_ts_decorate, "_ts_decorate");
598
- function _ts_metadata(k, v) {
599
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
600
- }
601
- __name(_ts_metadata, "_ts_metadata");
602
- var AbstractBase = class _AbstractBase {
603
- static {
604
- __name(this, "AbstractBase");
605
- }
606
- static inspector = Inspector.compose(_AbstractBase, {
607
- keys: [],
608
- autoAddBooleanKeys: true,
609
- ignoreKeys: [],
610
- ignoreValues: {
611
- noEmptyArray: true,
612
- noEmptyObject: true,
613
- noNull: true,
614
- noUndefined: true,
615
- noFalse: true
616
- },
617
- inspect: {
618
- customInspect: true,
619
- maxStringLength: 500,
620
- maxArrayLength: 5,
621
- breakLength: 80,
622
- colors: true,
623
- depth: null,
624
- compact: false,
625
- numericSeparator: true
626
- },
627
- filters: []
628
- });
629
- constructor(parent) {
630
- this.parenting.onInstance(parent);
631
- }
632
- findParentDeep(predicate) {
633
- for (const parent of this.parenting.iterateAncestors()) {
634
- if (predicate(parent)) {
635
- return parent;
636
- }
637
- }
638
- return void 0;
639
- }
640
- get parent() {
641
- return this.parenting.getParent();
642
- }
643
- getParentDeep(instanceOf) {
644
- const parent = this.findParentDeep((p) => {
645
- return p instanceof instanceOf;
646
- });
647
- if (!parent) {
648
- throw new Error(`Parent of type ${instanceOf.name} not found.`);
649
- }
650
- return parent;
651
- }
652
- };
653
- AbstractBase = _ts_decorate([
654
- Parenting.compose,
655
- _ts_metadata("design:type", Function),
656
- _ts_metadata("design:paramtypes", [
657
- typeof P === "undefined" ? Object : P
658
- ])
659
- ], AbstractBase);
660
-
661
- // src/util/SemanticExtnamePrefix.ts
662
- var SemanticExtnamePrefix = {
663
- d: "d",
664
- test: "test",
665
- examples: "examples",
666
- benchmark: "benchmark",
667
- temp: "temp",
668
- wip: "wip"
669
- };
670
-
671
- // ../fn/src/setNameAndLength.ts
672
- function setNameAndLength(source, target, lengthDelta = 0) {
673
- return Object.defineProperties(target, {
674
- name: {
675
- configurable: true,
676
- value: source.name
677
- },
678
- length: {
679
- configurable: true,
680
- value: source.length + lengthDelta
681
- }
682
- });
683
- }
684
- __name(setNameAndLength, "setNameAndLength");
685
-
686
- // ../fn/src/bindArg.ts
687
- function bindArg(fn, boundArgIndex, boundArgValue) {
688
- return setNameAndLength(fn, (...args) => {
689
- return fn(...args.slice(0, boundArgIndex), boundArgValue, ...args.slice(boundArgIndex));
690
- }, -1);
691
- }
692
- __name(bindArg, "bindArg");
693
-
694
- // ../path/src/lib/hasExtname.ts
695
- function hasExtname(tsFilepath, extnames) {
696
- return new RegExp(`[.](${[
697
- extnames
698
- ].flat(2).join("|")})$`).test(tsFilepath);
699
- }
700
- __name(hasExtname, "hasExtname");
701
- hasExtname.js = bindArg(hasExtname, 1, [
702
- "js",
703
- "mjs",
704
- "jsx",
705
- "cjs"
706
- ]);
707
- hasExtname.json = bindArg(hasExtname, 1, [
708
- "json",
709
- "jsonc"
710
- ]);
711
- hasExtname.yaml = bindArg(hasExtname, 1, [
712
- "yaml",
713
- "yml"
714
- ]);
715
- hasExtname.markdown = bindArg(hasExtname, 1, [
716
- "md",
717
- "markdown"
718
- ]);
719
- hasExtname.ts = bindArg(hasExtname, 1, [
720
- "ts",
721
- "mts",
722
- "tsx"
723
- ]);
724
-
725
- // ../path/src/lib/hasParentDirname.ts
726
- function hasParentDirname(fspath, name) {
727
- return new RegExp(`(^|[/\\\\])${name}[/\\\\]`).test(fspath);
728
- }
729
- __name(hasParentDirname, "hasParentDirname");
730
-
731
- // src/util/SemanticExtnamePrefixes.ts
732
- var SemanticExtnamePrefixes_default = Object.values(SemanticExtnamePrefix);
733
-
734
- // src/util/hasExtnamePrefix.ts
735
- function hasExtnamePrefix(tsFilepath, prefixes = SemanticExtnamePrefixes_default) {
736
- return new RegExp(`[.](${[
737
- prefixes
738
- ].flat(2).join("|")})[.][^/\\\\]+$`).test(tsFilepath);
739
- }
740
- __name(hasExtnamePrefix, "hasExtnamePrefix");
741
-
742
- // ../decorators/src/assertDescriptorValueIsFunction.ts
743
- function assertDescriptorValueIsFunction(key, descriptor) {
744
- if (!(typeof descriptor.value === "function" && descriptor.value !== Function.prototype)) {
745
- throw new TypeError(`"value" not a function for ${key} with descriptor: ${JSON.stringify(descriptor)}.`);
746
- }
747
- }
748
- __name(assertDescriptorValueIsFunction, "assertDescriptorValueIsFunction");
749
-
750
- // ../map/src/mapGetOrDefault.ts
751
- function mapGetOrDefault(map, key, factory) {
752
- let value = map.get(key);
753
- if (value !== void 0 || map.has(key)) {
754
- return value;
755
- }
756
- value = factory(key, map);
757
- map.set(key, value);
758
- return value;
759
- }
760
- __name(mapGetOrDefault, "mapGetOrDefault");
761
-
762
- // ../map/src/TimeoutWeakMap.ts
763
- var TimeoutWeakMap = class {
764
- static {
765
- __name(this, "TimeoutWeakMap");
766
- }
767
- timeoutMs;
768
- wmap = /* @__PURE__ */ new WeakMap();
769
- /**
770
- * @param timeoutMs Default timeout in milliseconds for entries
771
- */
772
- constructor(timeoutMs) {
773
- this.timeoutMs = timeoutMs;
774
- }
775
- /**
776
- * Retrieves the value for the given key and refreshes its timeout.
777
- *
778
- * @param key The key to retrieve
779
- * @returns The value if found, undefined otherwise
780
- */
781
- get(key) {
782
- const vt = this.wmap.get(key);
783
- if (!vt) {
784
- return void 0;
785
- }
786
- const [value, timeout] = vt;
787
- timeout.refresh();
788
- return value;
789
- }
790
- /**
791
- * Sets a key-value pair with an optional custom timeout.
792
- *
793
- * @param key The key to set
794
- * @param value The value to associate with the key
795
- * @param timeoutMs Optional timeout override for this entry
796
- * @returns This instance for chaining
797
- */
798
- set(key, value, timeoutMs) {
799
- this.wmap.set(key, [
800
- value,
801
- setTimeout(() => {
802
- this.delete(key);
803
- }, timeoutMs ?? this.timeoutMs).unref()
804
- ]);
805
- return this;
806
- }
807
- /**
808
- * Removes a key-value pair and clears its timeout.
809
- *
810
- * @param key The key to delete
811
- * @returns True if the key existed and was deleted, false otherwise
812
- */
813
- delete(key) {
814
- const vt = this.wmap.get(key);
815
- if (!vt) {
816
- return false;
817
- }
818
- const timeout = vt[1];
819
- clearTimeout(timeout);
820
- return this.wmap.delete(key);
821
- }
822
- /**
823
- * Checks if a key exists in the map.
824
- * Does not refresh the timeout.
825
- *
826
- * @param key The key to check
827
- * @returns True if the key exists, false otherwise
828
- */
829
- has(key) {
830
- return this.wmap.has(key);
831
- }
832
- /**
833
- * Loads multiple key-value pairs into the map.
834
- *
835
- * @param entries Iterable of key-value pairs to load
836
- * @param timeoutMs Optional timeout override for all entries
837
- * @returns This instance for chaining
838
- */
839
- load(entries, timeoutMs) {
840
- for (const [key, value] of entries) {
841
- this.set(key, value, timeoutMs);
842
- }
843
- return this;
844
- }
845
- /**
846
- * Updates an existing value or creates a new one using an update function.
847
- *
848
- * @param key The key to update
849
- * @param update Function that receives the current value and returns the new value
850
- * @returns This instance for chaining
851
- */
852
- update(key, update) {
853
- return this.set(key, update(this.get(key), key, this));
854
- }
855
- /**
856
- * Gets a value or creates it using a factory function if it doesn't exist.
857
- * Refreshes timeout if the value exists.
858
- *
859
- * @param key The key to get or create
860
- * @param factory Function to create the value if it doesn't exist
861
- * @param timeoutMs Optional timeout override for new entries
862
- * @returns The existing or newly created value
863
- */
864
- getOrDefault(key, factory, timeoutMs) {
865
- const vt = this.wmap.get(key);
866
- if (vt) {
867
- const [value, timeout] = vt;
868
- timeout.refresh();
869
- return value;
870
- } else {
871
- const value = factory(key, this);
872
- this.set(key, value, timeoutMs);
873
- return value;
874
- }
875
- }
876
- };
877
- function memoizeSync(arg = {}) {
878
- const opts = typeof arg === "object" ? arg : {
879
- maxAge: typeof arg === "number" ? arg : ms(arg)
880
- };
881
- return /* @__PURE__ */ __name(function decorator(target, key, descriptor) {
882
- if (!descriptor) {
883
- throw new TypeError("descriptor is undefined");
884
- }
885
- const orig = descriptor.value;
886
- assertDescriptorValueIsFunction(key, descriptor);
887
- const options = {
888
- length: false,
889
- ...opts
890
- };
891
- if (opts.instancesShareCache) {
892
- Reflect.deleteProperty(options, "instancesShareCache");
893
- descriptor.value = memoizee(orig, options);
894
- } else {
895
- const wmap = /* @__PURE__ */ new WeakMap();
896
- descriptor.value = function(...args) {
897
- const memoized = mapGetOrDefault(wmap, this, () => {
898
- return memoizee(orig, options);
899
- });
900
- return memoized.apply(this, args);
901
- };
902
- }
903
- return descriptor;
904
- }, "decorator");
905
- }
906
- __name(memoizeSync, "memoizeSync");
907
- function lazyProp(targetOrTimeout, key, descriptor) {
908
- if (typeof targetOrTimeout === "number" || typeof targetOrTimeout === "string") {
909
- const maxAge = typeof targetOrTimeout === "number" ? targetOrTimeout : ms(targetOrTimeout);
910
- return createLazyPropDecorator(new TimeoutWeakMap(maxAge));
911
- } else {
912
- const decorator = createLazyPropDecorator(/* @__PURE__ */ new WeakMap());
913
- return decorator(targetOrTimeout, key, descriptor);
914
- }
915
- }
916
- __name(lazyProp, "lazyProp");
917
- function createLazyPropDecorator(map) {
918
- return function(target, key, descriptor) {
919
- const { get, value } = descriptor;
920
- if (isFunction(get)) {
921
- descriptor.get = function() {
922
- return mapGetOrDefault(map, this, () => {
923
- return get.call(this);
924
- });
925
- };
926
- return descriptor;
927
- }
928
- if (isFunction(value)) {
929
- return memoizeSync()(target, key, descriptor);
930
- }
931
- throw new TypeError('neither "get" nor "value" are functions');
932
- };
933
- }
934
- __name(createLazyPropDecorator, "createLazyPropDecorator");
935
- function _ts_decorate2(decorators, target, key, desc) {
936
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
937
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
938
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
939
- return c > 3 && r && Object.defineProperty(target, key, r), r;
940
- }
941
- __name(_ts_decorate2, "_ts_decorate");
942
- function _ts_metadata2(k, v) {
943
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
944
- }
945
- __name(_ts_metadata2, "_ts_metadata");
946
- var File = class _File extends AbstractBase {
947
- static {
948
- __name(this, "File");
949
- }
950
- static inspector = Inspector.compose(_File, {
951
- keys: [
952
- "relative"
953
- ]
954
- });
955
- path;
956
- constructor(parent, filepath) {
957
- super(parent);
958
- this.path = path2.normalize(filepath);
959
- }
960
- get stats() {
961
- return fs.statSync(this.path);
962
- }
963
- get isTs() {
964
- return hasExtname(this.path, [
965
- "ts",
966
- "mts",
967
- "tsx"
968
- ]);
969
- }
970
- get isDotTs() {
971
- return hasExtname(this.path, "ts");
972
- }
973
- get isDotTsx() {
974
- return hasExtname(this.path, "tsx");
975
- }
976
- get isExample() {
977
- return hasExtnamePrefix(this.path, SemanticExtnamePrefix.examples);
978
- }
979
- get isDeclaration() {
980
- return hasExtnamePrefix(this.path, SemanticExtnamePrefix.d);
981
- }
982
- get isTest() {
983
- return hasExtnamePrefix(this.path, SemanticExtnamePrefix.test);
984
- }
985
- get isIndexFile() {
986
- return path2.parse(this.path).name === "index";
987
- }
988
- get isSourceFile() {
989
- return hasParentDirname(this.path, "src") && !hasExtnamePrefix(this.path);
990
- }
991
- /**
992
- * Read the file contents.
993
- */
994
- readFile() {
995
- if (!fs.existsSync(this.path)) {
996
- throw new Error(`File not found: ${this.path}`);
997
- }
998
- return fs.readFileSync(this.path, "utf8");
999
- }
1000
- };
1001
- _ts_decorate2([
1002
- lazyProp(1e3),
1003
- _ts_metadata2("design:type", typeof Stats === "undefined" ? Object : Stats),
1004
- _ts_metadata2("design:paramtypes", [])
1005
- ], File.prototype, "stats", null);
1006
- File = _ts_decorate2([
1007
- Parenting.compose,
1008
- _ts_metadata2("design:type", Function),
1009
- _ts_metadata2("design:paramtypes", [
1010
- typeof P === "undefined" ? Object : P,
1011
- String
1012
- ])
1013
- ], File);
1014
-
1015
- // src/code/AbstractCode.ts
1016
- function _ts_decorate3(decorators, target, key, desc) {
1017
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1018
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1019
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1020
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1021
- }
1022
- __name(_ts_decorate3, "_ts_decorate");
1023
- function _ts_metadata3(k, v) {
1024
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1025
- }
1026
- __name(_ts_metadata3, "_ts_metadata");
1027
- var AbstractCode = class _AbstractCode extends AbstractBase {
1028
- static {
1029
- __name(this, "AbstractCode");
1030
- }
1031
- static inspector = Inspector.compose(_AbstractCode, {
1032
- keys: []
1033
- });
1034
- static codePreviewOptions = {
1035
- maxLines: 10,
1036
- maxLineLength: 90
1037
- };
1038
- constructor(parent) {
1039
- super(parent);
1040
- }
1041
- get path() {
1042
- return this.getParentDeep(File).path;
1043
- }
1044
- get code() {
1045
- return this.toString();
1046
- }
1047
- get isMultiLine() {
1048
- return this.code.includes("\n");
1049
- }
1050
- get lines() {
1051
- return this.code.split(/\r*\n/);
1052
- }
1053
- get codePreview() {
1054
- const maxLines = _AbstractCode.codePreviewOptions.maxLines;
1055
- const maxLineLength = _AbstractCode.codePreviewOptions.maxLineLength;
1056
- const applyMaxLineLength = /* @__PURE__ */ __name((line) => {
1057
- return line.length > maxLineLength ? `${line.substring(0, maxLineLength - 3)}...` : line;
1058
- }, "applyMaxLineLength");
1059
- return this.isMultiLine ? this.lines.slice(0, maxLines).map(applyMaxLineLength) : applyMaxLineLength(this.code);
1060
- }
1061
- codeIndexRangeOf(code) {
1062
- const index = this.code.indexOf(code);
1063
- if (index === -1) {
1064
- throw new Error(`Code not found: ${code}`);
1065
- }
1066
- const lastIndex = index + code.length;
1067
- return {
1068
- index,
1069
- lastIndex
1070
- };
1071
- }
1072
- getCodeRange(range) {
1073
- return this.code.substring(range.index, range.lastIndex);
1074
- }
1075
- };
1076
- AbstractCode = _ts_decorate3([
1077
- Parenting.compose,
1078
- _ts_metadata3("design:type", Function),
1079
- _ts_metadata3("design:paramtypes", [
1080
- typeof P === "undefined" ? Object : P
1081
- ])
1082
- ], AbstractCode);
1083
-
1084
- // src/code/CodeBlock.ts
1085
- function _ts_decorate4(decorators, target, key, desc) {
1086
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1087
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1088
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1089
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1090
- }
1091
- __name(_ts_decorate4, "_ts_decorate");
1092
- function _ts_metadata4(k, v) {
1093
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1094
- }
1095
- __name(_ts_metadata4, "_ts_metadata");
1096
- var CodeBlock = class _CodeBlock extends AbstractCode {
1097
- static {
1098
- __name(this, "CodeBlock");
1099
- }
1100
- static inspector = Inspector.compose(_CodeBlock, {
1101
- keys: []
1102
- });
1103
- indexRange;
1104
- constructor(parent, indexRange) {
1105
- super(parent);
1106
- this.indexRange = indexRange;
1107
- }
1108
- toString() {
1109
- return this.parenting.getParent().getCodeRange(this.indexRange);
1110
- }
1111
- };
1112
- _ts_decorate4([
1113
- lazyProp(2500),
1114
- _ts_metadata4("design:type", Function),
1115
- _ts_metadata4("design:paramtypes", []),
1116
- _ts_metadata4("design:returntype", String)
1117
- ], CodeBlock.prototype, "toString", null);
1118
- CodeBlock = _ts_decorate4([
1119
- Parenting.compose,
1120
- _ts_metadata4("design:type", Function),
1121
- _ts_metadata4("design:paramtypes", [
1122
- typeof P === "undefined" ? Object : P,
1123
- Object
1124
- ])
1125
- ], CodeBlock);
1126
-
1127
- // src/code/imports/ImportKeywords.ts
1128
- function _ts_decorate5(decorators, target, key, desc) {
1129
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1130
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1131
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1132
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1133
- }
1134
- __name(_ts_decorate5, "_ts_decorate");
1135
- var ImportKeywords = class _ImportKeywords extends CodeBlock {
1136
- static {
1137
- __name(this, "ImportKeywords");
1138
- }
1139
- static inspector = Inspector.compose(_ImportKeywords, {
1140
- keys: [
1141
- "code"
1142
- ]
1143
- });
1144
- get keywords() {
1145
- return this.code.split(/\s+/).map((s) => {
1146
- return s.trim();
1147
- }).filter((s) => {
1148
- return !!s;
1149
- });
1150
- }
1151
- has(kw) {
1152
- return this.keywords.includes(kw);
1153
- }
1154
- get isType() {
1155
- return this.has("type");
1156
- }
1157
- };
1158
- ImportKeywords = _ts_decorate5([
1159
- Parenting.compose
1160
- ], ImportKeywords);
1161
-
1162
- // src/code/imports/ImportSpecifiers.ts
1163
- function _ts_decorate6(decorators, target, key, desc) {
1164
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1165
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1166
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1167
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1168
- }
1169
- __name(_ts_decorate6, "_ts_decorate");
1170
- var ImportSpecifiers = class _ImportSpecifiers extends CodeBlock {
1171
- static {
1172
- __name(this, "ImportSpecifiers");
1173
- }
1174
- static inspector = Inspector.compose(_ImportSpecifiers, {
1175
- keys: [
1176
- "import",
1177
- "type"
1178
- ],
1179
- autoAddBooleanKeys: false
1180
- });
1181
- get codeWithoutTypeKeyword() {
1182
- return this.code.replaceAll(/\s*\btype\b\s*/g, " ");
1183
- }
1184
- get type() {
1185
- if (this.isMixedImport) {
1186
- return "mixed";
1187
- }
1188
- if (this.isNamedImport) {
1189
- return "named";
1190
- }
1191
- if (this.isNamespaceImport) {
1192
- return "namespace";
1193
- }
1194
- return "default";
1195
- }
1196
- get isDefaultImport() {
1197
- return /[$A-Z_a-z][\w$]*/.test(this.codeWithoutTypeKeyword) && !this.isNamespaceImport;
1198
- }
1199
- get isNamedImport() {
1200
- return /{[^}]+}/.test(this.codeWithoutTypeKeyword);
1201
- }
1202
- get isMixedImport() {
1203
- return /([$A-Z_a-z][\w$]*),\s*{[^}]+}/.test(this.codeWithoutTypeKeyword);
1204
- }
1205
- get isNamespaceImport() {
1206
- return /\*\s+as\s+([$A-Z_a-z][\w$]*)/.test(this.codeWithoutTypeKeyword);
1207
- }
1208
- get namedImportsArray() {
1209
- return this.code.replace("\n", " ").match(/{([^}]+)}/)?.[1].split(",").map((specifier) => {
1210
- return specifier.trim();
1211
- }).filter((s) => {
1212
- return !!s;
1213
- }) || [];
1214
- }
1215
- /**
1216
- * Splits the import specifier into an array of specifiers as if to split into individual import statements.
1217
- * @example `{A,B} => {A},{B}`
1218
- */
1219
- splitSpecifiers() {
1220
- return this.isNamedImport ? this.namedImportsArray.map((n) => {
1221
- return this.code.startsWith("type ") ? `type { ${n} }` : `{ ${n} }`;
1222
- }) : [
1223
- this.code
1224
- ];
1225
- }
1226
- /**
1227
- * Returns the keys added to the global namespace by this import specifier.
1228
- */
1229
- get importedNamesArray() {
1230
- return this.codeWithoutTypeKeyword.replace(/[\w*]+ as \w+/, (m) => {
1231
- return m.split(" as ")[1];
1232
- }).replaceAll(/[{}]/g, " ").split(",").map((s) => {
1233
- return s.trim();
1234
- }).filter(Boolean);
1235
- }
1236
- get defaultImport() {
1237
- return this.codeWithoutTypeKeyword.match(/^([$A-Z_a-z][\w$]*)\s*(,|)/)?.[1] || void 0;
1238
- }
1239
- get namespaceImport() {
1240
- return this.codeWithoutTypeKeyword.match(/^\*\s+as\s+([$A-Z_a-z][\w$]*)/)?.[1] || void 0;
1241
- }
1242
- get hasNamedImport() {
1243
- return !!this.namedImportsArray.length;
1244
- }
1245
- get hasDefaultImport() {
1246
- return !!this.defaultImport;
1247
- }
1248
- };
1249
- ImportSpecifiers = _ts_decorate6([
1250
- Parenting.compose
1251
- ], ImportSpecifiers);
1252
- function _ts_decorate7(decorators, target, key, desc) {
1253
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1254
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1255
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1256
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1257
- }
1258
- __name(_ts_decorate7, "_ts_decorate");
1259
- var ModuleSpecifier = class _ModuleSpecifier extends CodeBlock {
1260
- static {
1261
- __name(this, "ModuleSpecifier");
1262
- }
1263
- static inspector = Inspector.compose(_ModuleSpecifier, {
1264
- keys: [
1265
- "from"
1266
- ]
1267
- });
1268
- /**
1269
- * Alias for the `code` property.
1270
- */
1271
- get from() {
1272
- return this.code;
1273
- }
1274
- get dependency() {
1275
- if (!this.isDependency) {
1276
- return void 0;
1277
- }
1278
- return this.code.split("/").slice(0, this.isScoped ? 2 : 1).join("/");
1279
- }
1280
- get isBuiltin() {
1281
- return builtinModules.includes(this.code.replace(/^node:/i, ""));
1282
- }
1283
- get isScoped() {
1284
- return this.code.startsWith("@");
1285
- }
1286
- get isRepoScoped() {
1287
- return this.code.startsWith(`@${this.getParentDeep(MonoRepo).name}/`);
1288
- }
1289
- /**
1290
- * Returns whether import is an other, but local workspace in the monorepo.
1291
- */
1292
- get isOtherRepoWorkspace() {
1293
- return this.getParentDeep(MonoRepo).workspaces.map((ws) => {
1294
- return ws.name;
1295
- }).filter((name) => {
1296
- return name !== this.getParentDeep(Workspace).name;
1297
- }).some((name) => {
1298
- return this.code.includes(name);
1299
- });
1300
- }
1301
- get isRelative() {
1302
- return this.code.startsWith(".");
1303
- }
1304
- get isFromRepoRoot() {
1305
- return this.code.startsWith("/");
1306
- }
1307
- get isExternal() {
1308
- return !this.isBuiltin && !this.isRepoScoped && !this.isRelative;
1309
- }
1310
- get isDependency() {
1311
- return this.isExternal || this.isRepoScoped;
1312
- }
1313
- };
1314
- ModuleSpecifier = _ts_decorate7([
1315
- Parenting.compose
1316
- ], ModuleSpecifier);
1317
-
1318
- // src/file/TsFile.ts
1319
- function _ts_decorate8(decorators, target, key, desc) {
1320
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1321
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1322
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1323
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1324
- }
1325
- __name(_ts_decorate8, "_ts_decorate");
1326
- function _ts_metadata5(k, v) {
1327
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1328
- }
1329
- __name(_ts_metadata5, "_ts_metadata");
1330
- var TsFile = class _TsFile extends File {
1331
- static {
1332
- __name(this, "TsFile");
1333
- }
1334
- static inspector = Inspector.compose(_TsFile, {
1335
- keys: [
1336
- "tsCode"
1337
- ]
1338
- });
1339
- get tsCode() {
1340
- return new TsCode(this, this.readFile());
1341
- }
1342
- get dependencies() {
1343
- return this.tsCode.dependencies;
1344
- }
1345
- };
1346
- _ts_decorate8([
1347
- lazyProp(5e3),
1348
- _ts_metadata5("design:type", typeof TsCode === "undefined" ? Object : TsCode),
1349
- _ts_metadata5("design:paramtypes", [])
1350
- ], TsFile.prototype, "tsCode", null);
1351
- TsFile = _ts_decorate8([
1352
- Parenting.compose
1353
- ], TsFile);
1354
-
1355
- // src/code/imports/ImportStatement.ts
1356
- function _ts_decorate9(decorators, target, key, desc) {
1357
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1358
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1359
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1360
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1361
- }
1362
- __name(_ts_decorate9, "_ts_decorate");
1363
- function _ts_metadata6(k, v) {
1364
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1365
- }
1366
- __name(_ts_metadata6, "_ts_metadata");
1367
- var ImportStatement = class _ImportStatement extends CodeBlock {
1368
- static {
1369
- __name(this, "ImportStatement");
1370
- }
1371
- static inspector = Inspector.compose(_ImportStatement, {
1372
- keys: [
1373
- "keywords",
1374
- "specifiers",
1375
- "module"
1376
- ],
1377
- inspect: {
1378
- compact: true
1379
- }
1380
- });
1381
- toOneLine() {
1382
- return this.code.replaceAll(/\r?\n/g, " ").replaceAll(/\s{2,}/g, " ").replace(/,\s+}/, " }");
1383
- }
1384
- get keywords() {
1385
- const match = this.code.match(/^import\s+(?:type\s+)?/);
1386
- const code = match[0].trim();
1387
- return new ImportKeywords(this, this.codeIndexRangeOf(code));
1388
- }
1389
- get specifiers() {
1390
- const match = this.code.match(/import\s+([^"']+)\s+from\s+/);
1391
- const code = match ? match[1].trim() : "";
1392
- if (!code) {
1393
- return;
1394
- }
1395
- return new ImportSpecifiers(this, this.codeIndexRangeOf(code));
1396
- }
1397
- get module() {
1398
- const match = this.code.match(/(?:from|import)\s+["']([^"']+)["']/);
1399
- const code = match[1].trim();
1400
- return new ModuleSpecifier(this, this.codeIndexRangeOf(code));
1401
- }
1402
- split() {
1403
- return this.specifiers?.splitSpecifiers().map((specifier) => {
1404
- return `import ${specifier} from '${this.module.from}'`;
1405
- }) ?? [
1406
- this.code
1407
- ];
1408
- }
1409
- get filepath() {
1410
- return this.getParentDeep(TsFile).path;
1411
- }
1412
- };
1413
- _ts_decorate9([
1414
- lazyProp,
1415
- _ts_metadata6("design:type", void 0),
1416
- _ts_metadata6("design:paramtypes", [])
1417
- ], ImportStatement.prototype, "keywords", null);
1418
- _ts_decorate9([
1419
- lazyProp,
1420
- _ts_metadata6("design:type", void 0),
1421
- _ts_metadata6("design:paramtypes", [])
1422
- ], ImportStatement.prototype, "specifiers", null);
1423
- _ts_decorate9([
1424
- lazyProp,
1425
- _ts_metadata6("design:type", void 0),
1426
- _ts_metadata6("design:paramtypes", [])
1427
- ], ImportStatement.prototype, "module", null);
1428
- ImportStatement = _ts_decorate9([
1429
- Parenting.compose
1430
- ], ImportStatement);
1431
-
1432
- // ../regex/src/rexec.ts
1433
- function rexec(regex, string) {
1434
- regex = new RegExp(regex.source, regex.flags);
1435
- const result = [];
1436
- let match;
1437
- while ((match = regex.exec(string)) !== null) {
1438
- result.push({
1439
- index: match.index,
1440
- lastIndex: regex.lastIndex,
1441
- location: findLineColumn(string, match.index),
1442
- groups: Object.assign({}, match.groups),
1443
- match: match[0]
1444
- });
1445
- }
1446
- return result;
1447
- }
1448
- __name(rexec, "rexec");
1449
- function findLineColumn(content, index) {
1450
- const lines = content.split("\n");
1451
- const line = content.substring(0, index).split("\n").length;
1452
- lines.splice(line - 1);
1453
- const startOfLineIndex = lines.join("\n").length + (lines.length ? 1 : 0);
1454
- const col = index - startOfLineIndex;
1455
- return [
1456
- line,
1457
- col
1458
- ];
1459
- }
1460
- __name(findLineColumn, "findLineColumn");
1461
- function importStatementToOneLiner(code) {
1462
- return strip(code).replaceAll(/\r*\n/g, " ").replaceAll(/\s+/g, " ").replace(/,\s*}/, " }").replaceAll(/\s*,\s*/g, ", ").replaceAll(/\s+/g, " ").trim();
1463
- }
1464
- __name(importStatementToOneLiner, "importStatementToOneLiner");
1465
-
1466
- // ../tscode/src/tsCrlfToLf.ts
1467
- function tsCrlfToLf(code) {
1468
- return code.replaceAll(/\r+\n/g, "\n");
1469
- }
1470
- __name(tsCrlfToLf, "tsCrlfToLf");
1471
-
1472
- // ../tscode/src/tsExtractImports.ts
1473
- function tsExtractImports(code) {
1474
- code = tsCrlfToLf(code);
1475
- code = replaceImportStatementsInsideLiteralStrings(code);
1476
- code = replaceImportStatementsInsideBlockComments(code);
1477
- const isFirstLine = /^import /;
1478
- const isFirstLineInMulti = /{\s*$/;
1479
- const isLastLineInMulti = /^} from ["']/;
1480
- const result = [];
1481
- let isMulti = false;
1482
- let impLines = [];
1483
- const lines = code.split(/\r?\n/);
1484
- for (const [l, line] of lines.entries()) {
1485
- if (isFirstLine.test(line)) {
1486
- if (isFirstLineInMulti.test(line)) {
1487
- impLines.push(line);
1488
- isMulti = true;
1489
- } else {
1490
- const match = line;
1491
- const matchOneLine = importStatementToOneLiner(match);
1492
- result.push({
1493
- start: l,
1494
- end: l + 1,
1495
- match,
1496
- matchOneLine
1497
- });
1498
- }
1499
- } else if (isMulti) {
1500
- impLines.push(line);
1501
- if (isLastLineInMulti.test(line)) {
1502
- const match = impLines.join("\n");
1503
- const matchOneLine = importStatementToOneLiner(match);
1504
- result.push({
1505
- start: l - impLines.length + 1,
1506
- end: l + 1,
1507
- match,
1508
- matchOneLine
1509
- });
1510
- impLines = [];
1511
- isMulti = false;
1512
- }
1513
- }
1514
- }
1515
- return result;
1516
- }
1517
- __name(tsExtractImports, "tsExtractImports");
1518
- function replaceImportStatementsInsideLiteralStrings(code) {
1519
- return code.replaceAll(/(["'`])(.*?)\1/gs, (match) => {
1520
- return match.replaceAll(/\nimport /gs, "\nIMPORT ");
1521
- });
1522
- }
1523
- __name(replaceImportStatementsInsideLiteralStrings, "replaceImportStatementsInsideLiteralStrings");
1524
- function replaceImportStatementsInsideBlockComments(code) {
1525
- return code.replaceAll(/\/\*(.*?)\*\//gs, (match) => {
1526
- return match.replaceAll(/\nimport /gs, "\nIMPORT ");
1527
- });
1528
- }
1529
- __name(replaceImportStatementsInsideBlockComments, "replaceImportStatementsInsideBlockComments");
1530
- function _ts_decorate10(decorators, target, key, desc) {
1531
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1532
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1533
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1534
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1535
- }
1536
- __name(_ts_decorate10, "_ts_decorate");
1537
- function _ts_metadata7(k, v) {
1538
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1539
- }
1540
- __name(_ts_metadata7, "_ts_metadata");
1541
- var TsCode = class _TsCode extends AbstractCode {
1542
- static {
1543
- __name(this, "TsCode");
1544
- }
1545
- static inspector = Inspector.compose(_TsCode, {
1546
- keys: [
1547
- "imports"
1548
- ]
1549
- });
1550
- #code;
1551
- get code() {
1552
- return this.#code;
1553
- }
1554
- constructor(parent, code) {
1555
- super(parent);
1556
- this.#code = code;
1557
- }
1558
- toString() {
1559
- return this.code;
1560
- }
1561
- requires(format = "modules") {
1562
- if (format === "lines") {
1563
- return this.code.split(/\r*\n/).filter((line) => {
1564
- return this.requireRegex.test(line);
1565
- });
1566
- }
1567
- return uniq(Array.from(this.code.matchAll(this.requireRegex)).map((o) => {
1568
- return o[1];
1569
- }));
1570
- }
1571
- get imports() {
1572
- const statements = tsExtractImports(this.code).map((o) => {
1573
- return o.match;
1574
- });
1575
- return statements.map((line) => {
1576
- return new ImportStatement(this, this.codeIndexRangeOf(line));
1577
- });
1578
- }
1579
- get exportedClassNames() {
1580
- return rexec(/^export (abstract )?class (?<name>\w+)/gm, this.code).map((o) => {
1581
- return o.groups?.name;
1582
- }).filter(Boolean);
1583
- }
1584
- get dependencies() {
1585
- return this.imports.map((imp) => {
1586
- return imp.module.dependency;
1587
- }).filter(Boolean).sort();
1588
- }
1589
- get requireRegex() {
1590
- return /require\(["'](.+)["']\)/g;
1591
- }
1592
- };
1593
- _ts_decorate10([
1594
- lazyProp,
1595
- _ts_metadata7("design:type", Array),
1596
- _ts_metadata7("design:paramtypes", [])
1597
- ], TsCode.prototype, "imports", null);
1598
- TsCode = _ts_decorate10([
1599
- Parenting.compose,
1600
- _ts_metadata7("design:type", Function),
1601
- _ts_metadata7("design:paramtypes", [
1602
- typeof P === "undefined" ? Object : P,
1603
- String
1604
- ])
1605
- ], TsCode);
1606
-
1607
- // src/file/TestFile.ts
1608
- function _ts_decorate11(decorators, target, key, desc) {
1609
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1610
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1611
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1612
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1613
- }
1614
- __name(_ts_decorate11, "_ts_decorate");
1615
- function _ts_metadata8(k, v) {
1616
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1617
- }
1618
- __name(_ts_metadata8, "_ts_metadata");
1619
- var TestFile = class extends TsFile {
1620
- static {
1621
- __name(this, "TestFile");
1622
- }
1623
- static inspector = Inspector.compose(TsFile, {});
1624
- get tsCode() {
1625
- return new TsCode(this, this.readFile());
1626
- }
1627
- get dependencies() {
1628
- return this.tsCode.dependencies;
1629
- }
1630
- };
1631
- _ts_decorate11([
1632
- lazyProp(5e3),
1633
- _ts_metadata8("design:type", typeof TsCode === "undefined" ? Object : TsCode),
1634
- _ts_metadata8("design:paramtypes", [])
1635
- ], TestFile.prototype, "tsCode", null);
1636
- TestFile = _ts_decorate11([
1637
- Parenting.compose
1638
- ], TestFile);
1639
- var getRepoRootDirpath = onetime(/* @__PURE__ */ __name(function getRepoRootDirpath2() {
1640
- return (/* @__PURE__ */ __name(function recurse(dirpath = process.cwd()) {
1641
- dirpath = path2.normalizeSafe(dirpath);
1642
- const pkgpath = path2.joinSafe(dirpath, "package.json");
1643
- if (fs2.existsSync(pkgpath) && fs2.readJsonSync(pkgpath)?.workspaces) {
1644
- return dirpath;
1645
- }
1646
- const parent = path2.dirname(dirpath);
1647
- if (parent !== dirpath) {
1648
- return recurse(parent);
1649
- }
1650
- throw new Error(`Could not find repo root from process.cwd(): ${process.cwd()}`);
1651
- }, "recurse"))();
1652
- }, "getRepoRootDirpath"));
1653
- function resolveModuleImportPath(filepath, importFrom) {
1654
- const rootdir = getRepoRootDirpath();
1655
- const result = resolveModuleName(importFrom, filepath, {
1656
- paths: fs3.readJsonSync(path2.joinSafe(rootdir, "tsconfig.paths.json")).compilerOptions.paths,
1657
- allowJs: true,
1658
- allowArbitraryExtensions: true,
1659
- allowImportingTsExtensions: true,
1660
- allowSyntheticDefaultImports: true,
1661
- esModuleInterop: true,
1662
- strict: false
1663
- }, createCompilerHost({}, true));
1664
- const f = result.resolvedModule?.resolvedFileName;
1665
- if (f) {
1666
- result.resolvedModule.resolvedFileName = path2.relative(rootdir, f);
1667
- }
1668
- return result.resolvedModule;
1669
- }
1670
- __name(resolveModuleImportPath, "resolveModuleImportPath");
1671
- function walkDirectory(dirpath, options) {
1672
- dirpath = path2.normalizeSafe(dirpath);
1673
- if (!options.stats && !options.only) {
1674
- return walkdir.sync(dirpath, {
1675
- ...convertToWalkdirOptions(options),
1676
- return_object: false
1677
- }).map((fspath) => {
1678
- return path2.normalizeSafe(fspath);
1679
- });
1680
- }
1681
- let entries = Object.entries(walkdir.sync(dirpath, convertToWalkdirOptions(options)));
1682
- if (options.only === "files") {
1683
- entries = entries.filter(([_, stats]) => {
1684
- return stats.isFile();
1685
- });
1686
- } else if (options.only === "directories") {
1687
- entries = entries.filter(([_, stats]) => {
1688
- return stats.isDirectory();
1689
- });
1690
- }
1691
- entries = entries.map(([fspath, stats]) => {
1692
- return [
1693
- path2.normalizeSafe(fspath),
1694
- stats
1695
- ];
1696
- });
1697
- return options.stats ? entries : entries.map(([fspath]) => {
1698
- return fspath;
1699
- });
1700
- }
1701
- __name(walkDirectory, "walkDirectory");
1702
- function convertToWalkdirOptions(options) {
1703
- const result = {
1704
- fs: fs2,
1705
- sync: true,
1706
- return_object: true
1707
- };
1708
- if (options.maxDepth !== void 0) {
1709
- result.max_depth = options.maxDepth;
1710
- }
1711
- if (options.followSymlinks !== void 0) {
1712
- result.follow_symlinks = options.followSymlinks;
1713
- }
1714
- if (options.ignoreInodes !== void 0) {
1715
- result.track_inodes = !options.ignoreInodes;
1716
- }
1717
- if (options.filter) {
1718
- const filter = options.filter;
1719
- result.filter = (dirpath, files) => {
1720
- return filter(path2.normalizeSafe(dirpath), path2.basename(dirpath)) ? files : [];
1721
- };
1722
- }
1723
- return result;
1724
- }
1725
- __name(convertToWalkdirOptions, "convertToWalkdirOptions");
1726
-
1727
- // src/repo/Workspace.ts
1728
- function _ts_decorate12(decorators, target, key, desc) {
1729
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1730
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1731
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1732
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1733
- }
1734
- __name(_ts_decorate12, "_ts_decorate");
1735
- function _ts_metadata9(k, v) {
1736
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1737
- }
1738
- __name(_ts_metadata9, "_ts_metadata");
1739
- var Workspace = class _Workspace extends AbstractBase {
1740
- static {
1741
- __name(this, "Workspace");
1742
- }
1743
- static inspector = Inspector.compose(_Workspace, {
1744
- keys: [
1745
- "name",
1746
- "tsFiles",
1747
- "testFiles"
1748
- ]
1749
- });
1750
- /**
1751
- * The workspace's origin directory name, eg. 'libs', 'apps', etc.
1752
- */
1753
- origin;
1754
- /**
1755
- * The workspace's root directory path.
1756
- */
1757
- path;
1758
- constructor(parent, dirpath) {
1759
- super(parent);
1760
- this.path = path2.normalize(dirpath);
1761
- this.origin = path2.basename(path2.dirname(this.path));
1762
- }
1763
- /**
1764
- * The workspace's package.json filepath.
1765
- */
1766
- get packageJsonPath() {
1767
- return path2.join(this.path, "package.json");
1768
- }
1769
- /**
1770
- * The workspace's package.json file as an object.
1771
- */
1772
- get packageJson() {
1773
- return readJsonSync(this.packageJsonPath);
1774
- }
1775
- /**
1776
- * The workspace's name from the package.json file.
1777
- */
1778
- get name() {
1779
- if (!this.packageJson.name) {
1780
- throw new Error(`Workspace package.json missing 'name' field: ${this.packageJsonPath}`);
1781
- }
1782
- return this.packageJson.name;
1783
- }
1784
- /**
1785
- * Reads the workspace's package.json file and returns the 'dependencies' field as a sorted array of strings.
1786
- */
1787
- get installedDependencies() {
1788
- const deps = this.packageJson.dependencies ?? {};
1789
- return Object.keys(deps).sort();
1790
- }
1791
- /**
1792
- * Reads the workspace's package.json file and returns the 'devDependencies' field as a sorted array of strings.
1793
- */
1794
- get installedDevDependencies() {
1795
- const deps = this.packageJson.devDependencies ?? {};
1796
- return Object.keys(deps).sort();
1797
- }
1798
- /**
1799
- * Get all unique file-level dependencies of the workspace, including transitive dependencies through other local workspaces.
1800
- *
1801
- * This method recursively traverses the dependency graph of the workspace, collecting all unique dependencies. It distinguishes between internal dependencies (other local workspaces) and external dependencies (npm packages).
1802
- *
1803
- * @returns An object containing two arrays: `internal` for internal workspace dependencies and `external` for npm package dependencies.
1804
- */
1805
- get importedDependenciesRecursive() {
1806
- const repo = this.parent;
1807
- const wsNames = new Set(repo.workspaces.map((w) => {
1808
- return w.name;
1809
- }));
1810
- const allDeps = recurse(this.tsFiles.filter((f) => {
1811
- return f.isSourceFile;
1812
- }));
1813
- const internal = [
1814
- ...allDeps
1815
- ].filter((d) => {
1816
- return wsNames.has(d);
1817
- }).sort();
1818
- const external = [
1819
- ...allDeps
1820
- ].filter((d) => {
1821
- return !wsNames.has(d);
1822
- }).sort();
1823
- function recurse(files, allDeps2 = /* @__PURE__ */ new Set(), visited = /* @__PURE__ */ new Set(), depth = 0) {
1824
- for (const file of files) {
1825
- if (visited.has(file.path)) {
1826
- continue;
1827
- }
1828
- visited.add(file.path);
1829
- for (const dep of file.dependencies) {
1830
- allDeps2.add(dep);
1831
- const depWs = repo.workspaces.find((w) => {
1832
- return w.name === dep;
1833
- });
1834
- if (depWs) {
1835
- recurse(depWs.tsFiles.filter((f) => {
1836
- return f.isSourceFile;
1837
- }), allDeps2, visited, depth + 1).forEach((d) => {
1838
- return allDeps2.add(d);
1839
- });
1840
- }
1841
- }
1842
- }
1843
- return allDeps2;
1844
- }
1845
- __name(recurse, "recurse");
1846
- return {
1847
- internal,
1848
- external
1849
- };
1850
- }
1851
- /**
1852
- * Get the source files in the workspace's 'src' directory.
1853
- * Test files are not included.
1854
- */
1855
- get tsFiles() {
1856
- return walkDirectory(this.path, {
1857
- stats: true,
1858
- only: "files",
1859
- filter: /* @__PURE__ */ __name((_dirpath, basename) => {
1860
- if (basename === "node_modules") {
1861
- return false;
1862
- }
1863
- if (basename === "coverage") {
1864
- return false;
1865
- }
1866
- if (basename.startsWith(".")) {
1867
- return false;
1868
- }
1869
- return true;
1870
- }, "filter")
1871
- }).filter(([fspath]) => {
1872
- return hasParentDirname(fspath, "src") && !hasExtnamePrefix(fspath);
1873
- }).map(([fspath]) => {
1874
- return new TsFile(this, fspath);
1875
- });
1876
- }
1877
- /**
1878
- * Get the test files in the workspace's 'src' directory.
1879
- */
1880
- get testFiles() {
1881
- return walkDirectory(this.path, {
1882
- stats: true,
1883
- only: "files",
1884
- filter: /* @__PURE__ */ __name((_dirpath, basename) => {
1885
- if (basename === "node_modules") {
1886
- return false;
1887
- }
1888
- if (basename === "coverage") {
1889
- return false;
1890
- }
1891
- if (basename.startsWith(".")) {
1892
- return false;
1893
- }
1894
- return true;
1895
- }, "filter")
1896
- }).filter(([fspath]) => {
1897
- return hasParentDirname(fspath, "src") && !hasExtnamePrefix(fspath, SemanticExtnamePrefix.test);
1898
- }).map(([fspath]) => {
1899
- return new TestFile(this, fspath);
1900
- });
1901
- }
1902
- get files() {
1903
- return [
1904
- ...this.tsFiles,
1905
- ...this.testFiles
1906
- ];
1907
- }
1908
- /**
1909
- * Get imported non-relative dependencies for each source file in the workspace, grouped by file.
1910
- */
1911
- get importedDependenciesByFile() {
1912
- return new Map(this.tsFiles.map((file) => {
1913
- return [
1914
- path2.relative(process.cwd(), file.path),
1915
- file.dependencies
1916
- ];
1917
- }));
1918
- }
1919
- /**
1920
- * Get imported non-relative dependencies for each test file in the workspace, grouped by file.
1921
- */
1922
- get importedTestDependenciesByFile() {
1923
- return new Map(this.testFiles.map((file) => {
1924
- return [
1925
- path2.relative(process.cwd(), file.path),
1926
- file.dependencies
1927
- ];
1928
- }));
1929
- }
1930
- /**
1931
- * Get imported non-relative dependencies for each source file in the workspace in a flat array.
1932
- */
1933
- get importedDependencies() {
1934
- return uniq(Array.from(this.importedDependenciesByFile.values()).flat());
1935
- }
1936
- /**
1937
- * Get imported non-relative dependencies for each test file in the workspace in a flat array.
1938
- */
1939
- get importedTestDependencies() {
1940
- return uniq(Array.from(this.importedTestDependenciesByFile.values()).flat());
1941
- }
1942
- /**
1943
- * Get dependencies that are imported but not listed in the workspace's package.json under 'dependencies'.
1944
- */
1945
- get missingDependencies() {
1946
- return difference(this.importedDependencies, this.installedDependencies).filter((dep) => {
1947
- return !this.parent.packageJson.dependencies?.[dep];
1948
- }).filter((dep) => {
1949
- return !this.parent.tsconfigBasePaths?.[dep];
1950
- });
1951
- }
1952
- /**
1953
- * Get dependencies that are imported but not listed in the workspace's package.json under 'devDependencies'.
1954
- */
1955
- get missingDevDependencies() {
1956
- return difference(this.importedTestDependencies, union(this.installedDependencies, this.installedDevDependencies)).filter((dep) => {
1957
- return !this.parent.packageJson.devDependencies?.[dep];
1958
- }).filter((dep) => {
1959
- return !this.parent.packageJson.dependencies?.[dep];
1960
- }).filter((dep) => {
1961
- return !this.parent.tsconfigBasePaths?.[dep];
1962
- });
1963
- }
1964
- /**
1965
- * Get dependencies that are listed in the workspace's package.json but not imported in any source file (excl. test files).
1966
- */
1967
- get unusedDependencies() {
1968
- return difference(this.installedDependencies, this.importedDependencies);
1969
- }
1970
- /**
1971
- *
1972
- */
1973
- get incorrectlyImportedRepoWorkspaces() {
1974
- const results = [];
1975
- for (const file of this.files) {
1976
- for (const imp of file.tsCode.imports) {
1977
- if (imp.module.from === this.name) {
1978
- const resolvedFileName = resolveModuleImportPath(file.path, imp.module.from)?.resolvedFileName;
1979
- if (resolvedFileName) {
1980
- results.push({
1981
- filepath: file.path,
1982
- replaceValue: imp.module.from,
1983
- withValue: resolvedFileName.endsWith("index.ts") ? `./${imp.specifiers?.importedNamesArray[0]}` : `./${path2.relative(path2.dirname(file.path), resolvedFileName)}`
1984
- });
1985
- }
1986
- }
1987
- }
1988
- }
1989
- return results;
1990
- }
1991
- /**
1992
- * Returns an object with found dependency problems for the workspace or undefined if no problems were found.
1993
- * @see WorkspaceDependencyProblems
1994
- */
1995
- get dependencyProblems() {
1996
- const result = {
1997
- origin: this.origin,
1998
- workspace: this.name,
1999
- unused: this.unusedDependencies,
2000
- missing: this.missingDependencies,
2001
- missingDev: this.missingDevDependencies,
2002
- imports: this.incorrectlyImportedRepoWorkspaces
2003
- };
2004
- if (!result.unused.length && !result.missing.length && !result.missingDev.length) {
2005
- return void 0;
2006
- }
2007
- for (const [key, value] of Object.entries(result)) {
2008
- if (!value.length) {
2009
- delete result[key];
2010
- }
2011
- }
2012
- return result;
2013
- }
2014
- async depcheck() {
2015
- try {
2016
- const rootPkg = this.parent.packageJson;
2017
- const dependencies = rootPkg.dependencies || {};
2018
- const devDependencies = rootPkg.devDependencies || {};
2019
- const ignores = Object.keys({
2020
- ...devDependencies,
2021
- ...dependencies
2022
- }).concat("@mono/*");
2023
- const ignoresFlag = `--ignores "${ignores.join(",")}"`;
2024
- const cmd = `yarn depcheck ${this.path} ${ignoresFlag} --json`;
2025
- const execPromise = promisify(exec);
2026
- const res = await execPromise(cmd);
2027
- return JSON.parse(res.stdout.toString());
2028
- } catch (error) {
2029
- const res = error;
2030
- if (res.stdout) {
2031
- return JSON.parse(res.stdout.toString());
2032
- }
2033
- console.error(error);
2034
- return {
2035
- dependencies: [],
2036
- devDependencies: [],
2037
- using: {},
2038
- missing: {},
2039
- invalidFiles: {},
2040
- invalidDirs: {}
2041
- };
2042
- }
2043
- }
2044
- /**
2045
- * Returns the workspace's cwd-relative path.
2046
- */
2047
- toString() {
2048
- return path2.relative(process.cwd(), this.path);
2049
- }
2050
- };
2051
- _ts_decorate12([
2052
- lazyProp(1e3),
2053
- _ts_metadata9("design:type", typeof PackageJson === "undefined" ? Object : PackageJson),
2054
- _ts_metadata9("design:paramtypes", [])
2055
- ], Workspace.prototype, "packageJson", null);
2056
- _ts_decorate12([
2057
- lazyProp(5e3),
2058
- _ts_metadata9("design:type", Array),
2059
- _ts_metadata9("design:paramtypes", [])
2060
- ], Workspace.prototype, "tsFiles", null);
2061
- _ts_decorate12([
2062
- lazyProp(5e3),
2063
- _ts_metadata9("design:type", Array),
2064
- _ts_metadata9("design:paramtypes", [])
2065
- ], Workspace.prototype, "testFiles", null);
2066
- _ts_decorate12([
2067
- lazyProp(1e3),
2068
- _ts_metadata9("design:type", typeof Map === "undefined" ? Object : Map),
2069
- _ts_metadata9("design:paramtypes", [])
2070
- ], Workspace.prototype, "importedDependenciesByFile", null);
2071
- _ts_decorate12([
2072
- lazyProp(1e3),
2073
- _ts_metadata9("design:type", typeof Map === "undefined" ? Object : Map),
2074
- _ts_metadata9("design:paramtypes", [])
2075
- ], Workspace.prototype, "importedTestDependenciesByFile", null);
2076
- Workspace = _ts_decorate12([
2077
- Parenting.compose,
2078
- _ts_metadata9("design:type", Function),
2079
- _ts_metadata9("design:paramtypes", [
2080
- typeof P === "undefined" ? Object : P,
2081
- String
2082
- ])
2083
- ], Workspace);
2084
- function _ts_decorate13(decorators, target, key, desc) {
2085
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2086
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2087
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2088
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2089
- }
2090
- __name(_ts_decorate13, "_ts_decorate");
2091
- function _ts_metadata10(k, v) {
2092
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2093
- }
2094
- __name(_ts_metadata10, "_ts_metadata");
2095
- var MonoRepo = class _MonoRepo extends AbstractBase {
2096
- static {
2097
- __name(this, "MonoRepo");
2098
- }
2099
- static inspector = Inspector.compose(_MonoRepo, {
2100
- keys: [
2101
- "name",
2102
- "workspaces"
2103
- ]
2104
- });
2105
- static instances = /* @__PURE__ */ new Map();
2106
- path;
2107
- constructor() {
2108
- const oPath = getRepoRootDirpath();
2109
- if (_MonoRepo.instances.has(oPath)) {
2110
- return _MonoRepo.instances.get(oPath);
2111
- }
2112
- super(null);
2113
- this.path = oPath;
2114
- _MonoRepo.instances.set(this.path, this);
2115
- }
2116
- get monoRepo() {
2117
- return this;
2118
- }
2119
- get packageJsonPath() {
2120
- return path2.join(this.path, "package.json");
2121
- }
2122
- get tsconfigBaseJsonPath() {
2123
- return path2.join(this.path, "tsconfig.json");
2124
- }
2125
- get tsconfigBase() {
2126
- const o = readJsonSync(this.tsconfigBaseJsonPath);
2127
- if (!o.compilerOptions) {
2128
- o.compilerOptions = {};
2129
- }
2130
- o.compilerOptions.paths = o.compilerOptions.paths || this.tsconfigBasePaths;
2131
- return o;
2132
- }
2133
- get tsconfigBasePathsJsonPath() {
2134
- return path2.join(this.path, "tsconfig.paths.json");
2135
- }
2136
- get tsconfigBasePaths() {
2137
- if (!fs.existsSync(this.tsconfigBasePathsJsonPath)) {
2138
- return {};
2139
- }
2140
- return readJsonSync(this.tsconfigBasePathsJsonPath).compilerOptions?.paths ?? {};
2141
- }
2142
- get packageJson() {
2143
- return readJsonSync(this.packageJsonPath);
2144
- }
2145
- get name() {
2146
- if (!this.packageJson.name) {
2147
- throw new Error(`MonoRepo package.json missing 'name' field: ${this.packageJsonPath}`);
2148
- }
2149
- return this.packageJson.name;
2150
- }
2151
- get workspacesRootPaths() {
2152
- if (!this.packageJson.workspaces) {
2153
- throw new Error(`MonoRepo package.json missing 'workspaces' field: ${this.packageJsonPath}`);
2154
- }
2155
- return this.packageJson.workspaces.map((workspacePath) => {
2156
- return path2.join(this.path, workspacePath.replace(/\*$/, ""));
2157
- });
2158
- }
2159
- get workspacePaths() {
2160
- return this.workspacesRootPaths.flatMap((workspacePath) => {
2161
- return fs.readdirSync(workspacePath, {
2162
- withFileTypes: true
2163
- }).filter((dirent) => {
2164
- return dirent.isDirectory();
2165
- }).map((dirent) => {
2166
- return path2.join(workspacePath, dirent.name);
2167
- });
2168
- });
2169
- }
2170
- get workspaces() {
2171
- return this.workspacePaths.map((dirpath) => {
2172
- return new Workspace(this, dirpath);
2173
- });
2174
- }
2175
- };
2176
- _ts_decorate13([
2177
- lazyProp(5e3),
2178
- _ts_metadata10("design:type", void 0),
2179
- _ts_metadata10("design:paramtypes", [])
2180
- ], MonoRepo.prototype, "tsconfigBase", null);
2181
- _ts_decorate13([
2182
- lazyProp(5e3),
2183
- _ts_metadata10("design:type", typeof Record === "undefined" ? Object : Record),
2184
- _ts_metadata10("design:paramtypes", [])
2185
- ], MonoRepo.prototype, "tsconfigBasePaths", null);
2186
- _ts_decorate13([
2187
- lazyProp(5e3),
2188
- _ts_metadata10("design:type", typeof PackageJson === "undefined" ? Object : PackageJson),
2189
- _ts_metadata10("design:paramtypes", [])
2190
- ], MonoRepo.prototype, "packageJson", null);
2191
- _ts_decorate13([
2192
- lazyProp(5e3),
2193
- _ts_metadata10("design:type", void 0),
2194
- _ts_metadata10("design:paramtypes", [])
2195
- ], MonoRepo.prototype, "workspacePaths", null);
2196
- _ts_decorate13([
2197
- lazyProp,
2198
- _ts_metadata10("design:type", Array),
2199
- _ts_metadata10("design:paramtypes", [])
2200
- ], MonoRepo.prototype, "workspaces", null);
2201
- MonoRepo = _ts_decorate13([
2202
- Parenting.compose,
2203
- _ts_metadata10("design:type", Function),
2204
- _ts_metadata10("design:paramtypes", [])
2205
- ], MonoRepo);
2206
- function getRepoPackageJsonPath() {
2207
- return path2.joinSafe(getRepoRootDirpath(), "package.json");
2208
- }
2209
- __name(getRepoPackageJsonPath, "getRepoPackageJsonPath");
2210
-
2211
- // src/methods/getRepoPackageJson.ts
2212
- async function getRepoPackageJson() {
2213
- return await fs2.readJson(getRepoPackageJsonPath());
2214
- }
2215
- __name(getRepoPackageJson, "getRepoPackageJson");
2216
- async function getAllWorkspacePaths() {
2217
- const pkg = await getRepoPackageJson();
2218
- return (await Promise.all(pkg.workspaces.map((pattern) => {
2219
- return glob(pattern);
2220
- }))).flat().map((fp) => {
2221
- return path2.normalizeSafe(fp);
2222
- });
2223
- }
2224
- __name(getAllWorkspacePaths, "getAllWorkspacePaths");
2225
- async function getAllWorkspacePackageJsonPaths() {
2226
- const paths = await getAllWorkspacePaths();
2227
- return paths.map((p) => {
2228
- return path2.join(p, "package.json");
2229
- });
2230
- }
2231
- __name(getAllWorkspacePackageJsonPaths, "getAllWorkspacePackageJsonPaths");
2232
-
2233
- // src/methods/getAllWorkspacePackageJsons.ts
2234
- async function getAllWorkspacePackageJsons() {
2235
- const paths = await getAllWorkspacePackageJsonPaths();
2236
- return paths.map((p) => {
2237
- return fs2.readJsonSync(p);
2238
- });
2239
- }
2240
- __name(getAllWorkspacePackageJsons, "getAllWorkspacePackageJsons");
2241
-
2242
- // src/methods/getAllWorkspacePackageNames.ts
2243
- async function getAllWorkspacePackageNames() {
2244
- const pkgs = await getAllWorkspacePackageJsons();
2245
- return pkgs.map((p) => {
2246
- return p.name;
2247
- });
2248
- }
2249
- __name(getAllWorkspacePackageNames, "getAllWorkspacePackageNames");
2250
-
2251
- // src/methods/findWorkspacePackageName.ts
2252
- async function findWorkspacePackageName(name) {
2253
- const wsPkgNames = await getAllWorkspacePackageNames();
2254
- return wsPkgNames.find((n) => {
2255
- return n === name;
2256
- }) || wsPkgNames.find((n) => {
2257
- return n === `@mono/${name}`;
2258
- });
2259
- }
2260
- __name(findWorkspacePackageName, "findWorkspacePackageName");
2261
-
2262
- // src/methods/getAllImports.ts
2263
- function getAllImports(repo) {
2264
- return repo.workspaces.flatMap((ws) => {
2265
- return ws.tsFiles.filter((ts) => {
2266
- return ts.isSourceFile;
2267
- }).flatMap((ts) => {
2268
- return ts.tsCode.imports.flatMap((imp) => {
2269
- return imp;
2270
- });
2271
- });
2272
- });
2273
- }
2274
- __name(getAllImports, "getAllImports");
2275
-
2276
- // src/util/SemanticExtnamePrefixDescriptions.ts
2277
- var SemanticExtnamePrefixDescriptions = {
2278
- d: "declarations",
2279
- test: "vitest test suite",
2280
- examples: "contains working and tested example usage code. Included in git, but ignored by most repo tools",
2281
- benchmark: "benchmark files, included in git, but ignored by most repo tools.",
2282
- temp: "temporary files, ignored by git, build, tests, etc.",
2283
- wip: "work in progress, ignored by git, build, tests, etc."
2284
- };
2285
- function getWorkspaceDirpaths() {
2286
- const rootDirpath = getRepoRootDirpath();
2287
- const pkg = fs2.readJsonSync(path2.joinSafe(rootDirpath, "package.json"));
2288
- if (!pkg.workspaces) {
2289
- throw new Error(`No workspaces found in package.json at ${rootDirpath}`);
2290
- }
2291
- return pkg.workspaces.flatMap((workspace) => {
2292
- return globSync(workspace);
2293
- }).map(path2.normalizeSafe);
2294
- }
2295
- __name(getWorkspaceDirpaths, "getWorkspaceDirpaths");
2296
-
2297
- // src/util/semverVersionBump.ts
2298
- function semverVersionBump(version, level) {
2299
- const arr = (typeof version === "string" ? version.split(".") : version).map(Number);
2300
- switch (level) {
2301
- case "major": {
2302
- arr[0] += 1;
2303
- arr[1] = 0;
2304
- arr[2] = 0;
2305
- break;
2306
- }
2307
- case "minor": {
2308
- arr[1] += 1;
2309
- arr[2] = 0;
2310
- break;
2311
- }
2312
- case "patch": {
2313
- arr[2] += 1;
2314
- break;
2315
- }
2316
- }
2317
- return arr.join(".");
2318
- }
2319
- __name(semverVersionBump, "semverVersionBump");
2320
-
2321
- export { AbstractBase, AbstractCode, CodeBlock, File, ImportKeywords, ImportSpecifiers, ImportStatement, ModuleSpecifier, MonoRepo, SemanticExtnamePrefix, SemanticExtnamePrefixDescriptions, TestFile, TsCode, TsFile, Workspace, findWorkspacePackageName, getAllImports, getAllWorkspacePackageJsonPaths, getAllWorkspacePackageJsons, getAllWorkspacePackageNames, getAllWorkspacePaths, getRepoPackageJson, getRepoPackageJsonPath, getRepoRootDirpath, getWorkspaceDirpaths, hasExtnamePrefix, resolveModuleImportPath, semverVersionBump };