@lowgular/code-graph 0.0.1 → 0.1.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 (179) hide show
  1. package/bin/cli.js +10 -0
  2. package/code-graph-v2/code.graph.js +37 -0
  3. package/code-graph-v2/config-from-query.js +131 -0
  4. package/code-graph-v2/extractors/extractor.js +27 -0
  5. package/code-graph-v2/extractors/index.js +1 -0
  6. package/code-graph-v2/graph-builder/code-graph.builder.js +49 -0
  7. package/code-graph-v2/graph-builder/index.js +1 -0
  8. package/code-graph-v2/graph-builder/node.processor.js +22 -0
  9. package/{libs/cli/code-graph/src/lib/v2 → code-graph-v2}/graph-builder/relationship.processor.js +11 -35
  10. package/code-graph-v2/graph-builder/type.processor.js +21 -0
  11. package/code-graph-v2/index.js +4 -0
  12. package/code-graph-v2/tools/build-code-graph.tool.js +19 -0
  13. package/code-graph-v2/utils.js +34 -0
  14. package/codegular/index.js +5 -0
  15. package/codegular/node.js +71 -0
  16. package/codegular/program.js +100 -0
  17. package/{libs/core/codegular/src/lib → codegular}/string.js +6 -53
  18. package/{libs/core/codegular/src/lib → codegular}/type-checker.js +3 -40
  19. package/codegular/type.js +356 -0
  20. package/{libs/core/codegular/src/lib → codegular}/utils.js +50 -62
  21. package/cypher/index.js +1 -0
  22. package/{libs/cli/cypher/src → cypher}/lib/executor/condition-evaluator.js +2 -25
  23. package/cypher/lib/executor/executor.js +60 -0
  24. package/cypher/lib/executor/graph.js +0 -0
  25. package/{libs/cli/cypher/src → cypher}/lib/executor/match-engine.js +4 -27
  26. package/{libs/cli/cypher/src → cypher}/lib/executor/pattern-matcher.js +2 -25
  27. package/{libs/cli/cypher/src → cypher}/lib/executor/relationship-navigator.js +2 -25
  28. package/{libs/cli/cypher/src → cypher}/lib/executor/result-formatter.js +37 -31
  29. package/{libs/cli/cypher/src → cypher}/lib/executor/traverse-engine.js +4 -27
  30. package/cypher/lib/executor/utils.js +14 -0
  31. package/cypher/lib/graph.stub.js +38 -0
  32. package/cypher/lib/index.js +32 -0
  33. package/{libs/cli/cypher/src → cypher}/lib/lexer.js +4 -26
  34. package/{libs/cli/cypher/src → cypher}/lib/parser.js +119 -135
  35. package/{libs/cli/cypher/src → cypher}/lib/validator/query-validator.js +12 -32
  36. package/{libs/cli/cypher/src → cypher}/lib/validator/supported-features.config.js +2 -30
  37. package/{libs/cli/cypher/src → cypher}/lib/validator/unsupported-features.config.js +8 -34
  38. package/cypher-cli.js +41 -0
  39. package/infra/code-graph.js +147 -0
  40. package/main.js +0 -43
  41. package/package.json +25 -7
  42. package/resources-cli.js +75 -0
  43. package/run-cli.js +43 -0
  44. package/apps/code-graph/src/main.js +0 -50
  45. package/libs/cli/code-graph/src/index.js +0 -39
  46. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  47. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  48. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  49. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  50. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  51. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  52. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  53. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  54. package/libs/cli/code-graph/src/lib/core.js +0 -85
  55. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  56. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  57. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  58. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  59. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  60. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  61. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  62. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  63. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  64. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  65. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  66. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  67. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  68. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  69. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  70. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  71. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  72. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  73. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  74. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  75. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  76. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  77. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  78. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  79. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  80. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  81. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  82. package/libs/cli/cypher/src/index.js +0 -25
  83. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  84. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  85. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  86. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  87. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  88. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  89. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  90. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  91. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  92. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  93. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  94. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  95. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  96. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  97. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  98. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  99. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  100. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  101. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  102. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  103. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  104. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  105. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  106. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  107. package/libs/cli/cypher/src/lib/index.js +0 -74
  108. package/libs/cli/shared/src/index.js +0 -53
  109. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  110. package/libs/cli/shared/src/lib/config.js +0 -49
  111. package/libs/cli/shared/src/lib/consts.js +0 -57
  112. package/libs/cli/shared/src/lib/core.js +0 -46
  113. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  114. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  115. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  116. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  117. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  118. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  119. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  120. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  121. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  122. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  123. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  124. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  125. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  126. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  127. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  128. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  129. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  130. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  131. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  132. package/libs/cli/shared/src/lib/token.js +0 -135
  133. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  134. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  135. package/libs/cli/typescript/src/index.js +0 -21
  136. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  137. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  138. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  139. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  140. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  141. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  142. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  143. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  144. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  145. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  146. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  147. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  148. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  149. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  150. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  151. package/libs/cli/typescript/src/lib/index.js +0 -57
  152. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  153. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  154. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  155. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  156. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  157. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  158. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  159. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  160. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  161. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  162. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  163. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  164. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  165. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  166. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  167. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  168. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  169. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  170. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  171. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  172. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  173. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  174. package/libs/cli/typescript/src/lib/utils.js +0 -39
  175. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  176. package/libs/core/codegular/src/index.js +0 -21
  177. package/libs/core/codegular/src/lib/index.js +0 -29
  178. package/libs/core/codegular/src/lib/node.js +0 -112
  179. package/libs/core/codegular/src/lib/program.js +0 -92
@@ -1,210 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var similarity_exports = {};
19
- __export(similarity_exports, {
20
- calcSimilarity: () => calcSimilarity,
21
- calcSimilarityForEach: () => calcSimilarityForEach,
22
- findSimilarWords: () => findSimilarWords,
23
- stringSimilarity: () => stringSimilarity
24
- });
25
- module.exports = __toCommonJS(similarity_exports);
26
- var import_transformers = require("../transformers");
27
- const mean = (vecs) => {
28
- if (!vecs.length)
29
- throw new Error("mean([])");
30
- if (!vecs[0])
31
- throw new Error("mean: vecs[0] is undefined");
32
- const d = vecs[0].length;
33
- if (!d)
34
- throw new Error("mean: vecs[0].length is 0");
35
- const out = new Float32Array(d);
36
- for (const v of vecs) {
37
- if (!v)
38
- throw new Error("mean: found undefined vector");
39
- if (v.length !== d)
40
- throw new Error(
41
- `mean: dimension mismatch - expected ${d}, got ${v.length}`
42
- );
43
- for (let i = 0; i < d; i++)
44
- out[i] += v[i];
45
- }
46
- for (let i = 0; i < d; i++)
47
- out[i] /= vecs.length;
48
- return out;
49
- };
50
- const cos = (a, b) => {
51
- if (!a || !b) {
52
- throw new Error(`cos: invalid inputs - a: ${!!a}, b: ${!!b}`);
53
- }
54
- if (a.length !== b.length) {
55
- throw new Error(`cos: dimension mismatch - a: ${a.length}, b: ${b.length}`);
56
- }
57
- let s = 0;
58
- for (let i = 0; i < a.length; i++)
59
- s += a[i] * b[i];
60
- return s;
61
- };
62
- async function calcSimilarity(SEEDS, tokens) {
63
- if (!SEEDS?.length)
64
- throw new Error("SEEDS empty");
65
- if (!tokens?.length)
66
- tokens = [""];
67
- const seedVecs = await (0, import_transformers.embedTexts)(SEEDS);
68
- if (seedVecs.length !== SEEDS.length) {
69
- throw new Error(
70
- `seedVecs length mismatch: expected ${SEEDS.length}, got ${seedVecs.length}`
71
- );
72
- }
73
- if (seedVecs.some((v) => !v)) {
74
- throw new Error("seedVecs contains undefined/null values");
75
- }
76
- const seedCentroid = mean(seedVecs);
77
- const tokVecs = await (0, import_transformers.embedTexts)(tokens);
78
- if (!tokVecs.length) {
79
- throw new Error("tokVecs is empty");
80
- }
81
- const nameVec = mean(tokVecs);
82
- const perSeed = SEEDS.map((w, i) => {
83
- const vec = seedVecs[i];
84
- if (!vec) {
85
- throw new Error(`seedVecs[${i}] is undefined for seed "${w}"`);
86
- }
87
- return {
88
- word: w,
89
- sim: cos(nameVec, vec)
90
- };
91
- }).sort((a, b) => b.sim - a.sim);
92
- const centroidSim = cos(nameVec, seedCentroid);
93
- const best = Math.max(centroidSim, perSeed[0]?.sim ?? -1);
94
- return { best, centroidSim, perSeed };
95
- }
96
- async function calcSimilarityForEach(SEEDS, tokens) {
97
- if (!SEEDS?.length)
98
- throw new Error("SEEDS empty");
99
- if (!tokens?.length)
100
- throw new Error("tokens empty");
101
- const seedVecs = await (0, import_transformers.embedTexts)(SEEDS);
102
- if (seedVecs.length !== SEEDS.length) {
103
- throw new Error(
104
- `seedVecs length mismatch: expected ${SEEDS.length}, got ${seedVecs.length}`
105
- );
106
- }
107
- if (seedVecs.some((v) => !v)) {
108
- throw new Error("seedVecs contains undefined/null values");
109
- }
110
- const tokVecs = await (0, import_transformers.embedTexts)(tokens);
111
- if (tokVecs.length !== tokens.length) {
112
- throw new Error(
113
- `tokVecs length mismatch: expected ${tokens.length}, got ${tokVecs.length}`
114
- );
115
- }
116
- if (tokVecs.some((v) => !v)) {
117
- throw new Error("tokVecs contains undefined/null values");
118
- }
119
- const result = {};
120
- for (let i = 0; i < SEEDS.length; i++) {
121
- const seedWord = SEEDS[i];
122
- const seedVec = seedVecs[i];
123
- if (!seedVec) {
124
- throw new Error(`seedVecs[${i}] is undefined for seed "${seedWord}"`);
125
- }
126
- const similarities = [];
127
- for (let j = 0; j < tokens.length; j++) {
128
- const token = tokens[j];
129
- const tokenVec = tokVecs[j];
130
- if (!tokenVec) {
131
- throw new Error(`tokVecs[${j}] is undefined for token "${token}"`);
132
- }
133
- similarities.push({
134
- key: token,
135
- value: cos(seedVec, tokenVec)
136
- });
137
- }
138
- result[seedWord] = similarities;
139
- }
140
- return result;
141
- }
142
- async function findSimilarWords(context, vocabulary, topK = 5) {
143
- if (!context?.trim())
144
- throw new Error("context is empty");
145
- if (!vocabulary?.length)
146
- throw new Error("vocabulary is empty");
147
- const [contextVec] = await (0, import_transformers.embedTexts)([context]);
148
- const vocabVecs = await (0, import_transformers.embedTexts)(vocabulary);
149
- if (vocabVecs.length !== vocabulary.length) {
150
- throw new Error(
151
- `vocabVecs length mismatch: expected ${vocabulary.length}, got ${vocabVecs.length}`
152
- );
153
- }
154
- const similarities = [];
155
- for (let i = 0; i < vocabulary.length; i++) {
156
- const word = vocabulary[i];
157
- const wordVec = vocabVecs[i];
158
- if (!wordVec) {
159
- throw new Error(`vocabVecs[${i}] is undefined for word "${word}"`);
160
- }
161
- similarities.push({
162
- word,
163
- similarity: cos(contextVec, wordVec)
164
- });
165
- }
166
- return similarities.sort((a, b) => b.similarity - a.similarity).slice(0, topK);
167
- }
168
- function stringSimilarity(a, b) {
169
- const maxLen = Math.max(a.length, b.length);
170
- if (maxLen === 0)
171
- return 1;
172
- const normalizedA = a.toLowerCase();
173
- const normalizedB = b.toLowerCase();
174
- const distance = levenshteinDistance(normalizedA, normalizedB);
175
- return 1 - distance / maxLen;
176
- }
177
- function levenshteinDistance(a, b) {
178
- if (a.length === 0)
179
- return b.length;
180
- if (b.length === 0)
181
- return a.length;
182
- const matrix = [];
183
- for (let i = 0; i <= b.length; i++) {
184
- matrix[i] = [i];
185
- }
186
- for (let j = 0; j <= a.length; j++) {
187
- matrix[0][j] = j;
188
- }
189
- for (let i = 1; i <= b.length; i++) {
190
- for (let j = 1; j <= a.length; j++) {
191
- if (b.charAt(i - 1) === a.charAt(j - 1)) {
192
- matrix[i][j] = matrix[i - 1][j - 1];
193
- } else {
194
- matrix[i][j] = Math.min(
195
- matrix[i - 1][j - 1] + 1,
196
- matrix[i][j - 1] + 1,
197
- matrix[i - 1][j] + 1
198
- );
199
- }
200
- }
201
- }
202
- return matrix[b.length][a.length];
203
- }
204
- // Annotate the CommonJS export names for ESM import in node:
205
- 0 && (module.exports = {
206
- calcSimilarity,
207
- calcSimilarityForEach,
208
- findSimilarWords,
209
- stringSimilarity
210
- });
@@ -1,297 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var workspace_exports = {};
29
- __export(workspace_exports, {
30
- cleanupWorkspace: () => cleanupWorkspace,
31
- clearLeadingRelativePath: () => clearLeadingRelativePath,
32
- copyFile: () => copyFile,
33
- createFiles: () => createFiles,
34
- createWorkspace: () => createWorkspace,
35
- deepFindFile: () => deepFindFile,
36
- filterOutByGitIgnore: () => filterOutByGitIgnore,
37
- filterOutFolders: () => filterOutFolders,
38
- findAllTestsInSubfolder: () => findAllTestsInSubfolder,
39
- findFilesInSubfolder: () => findFilesInSubfolder,
40
- findTests: () => findTests,
41
- getDiffReport: () => getDiffReport,
42
- getLatestModifiedFile: () => getLatestModifiedFile,
43
- getSubfolders: () => getSubfolders,
44
- listDirectories: () => listDirectories,
45
- readAllSnapshots: () => readAllSnapshots,
46
- readGitIgnore: () => readGitIgnore,
47
- readPaths: () => readPaths,
48
- readWorkspace: () => readWorkspace,
49
- recreateSubFolder: () => recreateSubFolder,
50
- recreateWorkspace: () => recreateWorkspace,
51
- removeAllFiles: () => removeAllFiles
52
- });
53
- module.exports = __toCommonJS(workspace_exports);
54
- var fs = __toESM(require("fs"));
55
- var path = __toESM(require("path"));
56
- var import_utils = require("../utils/utils.js");
57
- var import_git = require("./git.js");
58
- function deepFindFile(dir, fileName, fileList = []) {
59
- const files = fs.readdirSync(dir, { withFileTypes: true });
60
- for (const file of files) {
61
- const filePath = path.join(dir, file.name);
62
- if (file.isDirectory()) {
63
- deepFindFile(filePath, fileName, fileList);
64
- } else if (file.name === fileName) {
65
- const stats = fs.statSync(filePath);
66
- fileList.push({
67
- path: filePath,
68
- mtime: stats.mtime
69
- });
70
- }
71
- }
72
- return fileList;
73
- }
74
- function getLatestModifiedFile(files) {
75
- if (files.length === 0) {
76
- (0, import_utils.verboseLog)("No assessment.json files found in report directory");
77
- return null;
78
- }
79
- files.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
80
- (0, import_utils.verboseLog)(`Found ${files.length} assessment file(s), using latest: ${files[0].path}`);
81
- return files[0].path;
82
- }
83
- function cleanupWorkspace(folderName) {
84
- const files = readWorkspace(folderName);
85
- (0, import_utils.verboseLog)("Cleaning up the files...", Object.keys(files));
86
- Object.keys(files).forEach((filePath) => {
87
- fs.unlinkSync(filePath);
88
- });
89
- }
90
- function findTests(fs2) {
91
- return Object.keys(fs2).reduce(
92
- (a, f) => f.match(new RegExp(`.spec.ts$`)) ? { ...a, [f]: fs2[f] } : a,
93
- {}
94
- );
95
- }
96
- function findFilesInSubfolder(folderPath, fs2) {
97
- const folder = (0, import_utils.escapeRegExp)(
98
- folderPath.endsWith("/") ? folderPath : folderPath + "/"
99
- );
100
- return Object.keys(fs2).reduce(
101
- (a, f) => f.match(new RegExp(`^${folder}`)) ? { ...a, [f]: fs2[f] } : a,
102
- {}
103
- );
104
- }
105
- function findAllTestsInSubfolder(folderPath, files) {
106
- return Object.keys(findTests(findFilesInSubfolder(folderPath, files)));
107
- }
108
- function removeAllFiles(paths) {
109
- paths.forEach((p) => fs.unlinkSync(p));
110
- }
111
- function copyFile(src, dest) {
112
- fs.copyFileSync(src, dest);
113
- }
114
- function filterOutFolders(files, folders) {
115
- return Object.fromEntries(
116
- Object.entries(files).filter(
117
- ([k]) => !folders.some((f) => k.startsWith(f))
118
- )
119
- );
120
- }
121
- function filterOutByGitIgnore(files) {
122
- const allRules = (0, import_git.collectAllGitIgnoreRules)(files);
123
- if (allRules.length === 0) {
124
- return files;
125
- }
126
- return Object.fromEntries(
127
- Object.entries(files).filter(([filePath]) => {
128
- return !(0, import_git.isIgnored)(filePath, allRules);
129
- })
130
- );
131
- }
132
- function recreateSubFolder(folderName) {
133
- if (fs.existsSync(`${folderName}`)) {
134
- fs.rmSync(`${folderName}`, { recursive: true, force: true });
135
- }
136
- fs.mkdirSync(`${folderName}`, { recursive: true });
137
- }
138
- function createFiles(filesJson) {
139
- Object.keys(filesJson).forEach((filePath) => {
140
- const dirname = path.dirname(filePath);
141
- if (!fs.existsSync(`${dirname}`)) {
142
- fs.mkdirSync(`${dirname}`, { recursive: true });
143
- }
144
- fs.writeFileSync(`${filePath}`, filesJson[filePath], {
145
- flag: "w"
146
- });
147
- });
148
- }
149
- function createWorkspace(folderName, filesJson) {
150
- const cleanFolderName = folderName.endsWith("/") ? folderName : folderName + "/";
151
- (0, import_utils.verboseLog)("Creating workspace...", cleanFolderName, Object.keys(filesJson));
152
- Object.keys(filesJson).forEach((filePath) => {
153
- const dirname = path.dirname(filePath);
154
- if (!fs.existsSync(`${cleanFolderName}${dirname}`)) {
155
- fs.mkdirSync(`${cleanFolderName}${dirname}`, { recursive: true });
156
- }
157
- fs.writeFileSync(`${cleanFolderName}${filePath}`, filesJson[filePath], {
158
- flag: "w"
159
- });
160
- });
161
- }
162
- function getDiffReport(currentFiles, newFiles) {
163
- const currentFilePaths = Object.keys(currentFiles);
164
- const newFilePaths = Object.keys(newFiles);
165
- const changes = [];
166
- newFilePaths.forEach((filePath) => {
167
- if (!(filePath in currentFiles)) {
168
- changes.push({ path: filePath, status: "added" });
169
- } else if (currentFiles[filePath] !== newFiles[filePath]) {
170
- changes.push({ path: filePath, status: "modified" });
171
- }
172
- });
173
- currentFilePaths.forEach((filePath) => {
174
- if (!(filePath in newFiles)) {
175
- changes.push({ path: filePath, status: "deleted" });
176
- }
177
- });
178
- return changes.sort((a, b) => a.path.localeCompare(b.path));
179
- }
180
- function recreateWorkspace(folderName, newFiles, foldersToKeep) {
181
- const foldersToKeepRegexp = new RegExp(`^(${foldersToKeep.join("|")})`);
182
- console.log("foldersToKeepRegexp", foldersToKeepRegexp);
183
- const files = fs.readdirSync(folderName);
184
- files.forEach((file) => {
185
- console.log("file", file);
186
- if (file.match(foldersToKeepRegexp) !== null) {
187
- console.log("keeping", file);
188
- return;
189
- }
190
- const filePath = path.join(folderName, file);
191
- fs.rmSync(filePath, { recursive: true, force: true });
192
- });
193
- createWorkspace(folderName, newFiles);
194
- }
195
- function getSubfolders(dir) {
196
- const entries = fs.readdirSync(dir, { withFileTypes: true });
197
- return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
198
- }
199
- const clearLeadingRelativePath = (path2) => {
200
- return path2.replace(/^\.\//, "");
201
- };
202
- function readWorkspace(folderName, globalIgnore = []) {
203
- if (!fs.existsSync(folderName)) {
204
- throw new Error(`Folder ${folderName} does not exist.`);
205
- }
206
- const ignore = readGitIgnore(folderName);
207
- const filePaths = readPaths(folderName, [...ignore, ...globalIgnore]);
208
- const files = filePaths.reduce((a, c) => {
209
- try {
210
- return {
211
- ...a,
212
- [c.replace(folderName + "/", "")]: fs.readFileSync(c, "utf-8")
213
- };
214
- } catch (e) {
215
- console.log("reading error", e);
216
- }
217
- return a;
218
- }, {});
219
- return files;
220
- }
221
- function readAllSnapshots(folder) {
222
- return fs.readdirSync(folder, { withFileTypes: true }).reduce((a, c) => {
223
- if (c.isFile()) {
224
- a[c.name] = fs.readFileSync(`${c.path}/${c.name}`).toString("base64");
225
- }
226
- return a;
227
- }, {});
228
- }
229
- function listDirectories(root) {
230
- const entries = fs.readdirSync(root, { withFileTypes: true });
231
- return entries.filter((e) => e.isDirectory()).map((e) => e.name);
232
- }
233
- function readPaths(folderName, ignore) {
234
- return fs.readdirSync(folderName, { withFileTypes: true }).reduce((acc, p) => {
235
- const path2 = p.parentPath ? `${p.parentPath}/${p.name}` : `${folderName}/${p.name}`;
236
- if (ignore.some((i) => path2.includes(i))) {
237
- return acc;
238
- }
239
- if (p.isFile()) {
240
- return [
241
- ...acc,
242
- p.parentPath ? `${p.parentPath}/${p.name}` : `${folderName}/${p.name}`
243
- ];
244
- }
245
- return [...acc, ...readPaths(`${folderName}/${p.name}`, ignore)];
246
- }, []);
247
- }
248
- const DEFAULT_IGNORE = [
249
- "node_modules/",
250
- "package-lock.json",
251
- ".angular/",
252
- "__MAC/",
253
- ".git/",
254
- ".vscode/",
255
- ".DS_Store/"
256
- ];
257
- function readGitIgnore(folderName) {
258
- try {
259
- const gitIgnoreFile = fs.readFileSync(`${folderName}/.gitignore`, "utf-8");
260
- if (!gitIgnoreFile) {
261
- return DEFAULT_IGNORE;
262
- }
263
- return [
264
- .../* @__PURE__ */ new Set([
265
- ...DEFAULT_IGNORE,
266
- ...gitIgnoreFile.split(/\r?\n/).filter((i) => !!i)
267
- ])
268
- ];
269
- } catch (e) {
270
- return DEFAULT_IGNORE;
271
- }
272
- }
273
- // Annotate the CommonJS export names for ESM import in node:
274
- 0 && (module.exports = {
275
- cleanupWorkspace,
276
- clearLeadingRelativePath,
277
- copyFile,
278
- createFiles,
279
- createWorkspace,
280
- deepFindFile,
281
- filterOutByGitIgnore,
282
- filterOutFolders,
283
- findAllTestsInSubfolder,
284
- findFilesInSubfolder,
285
- findTests,
286
- getDiffReport,
287
- getLatestModifiedFile,
288
- getSubfolders,
289
- listDirectories,
290
- readAllSnapshots,
291
- readGitIgnore,
292
- readPaths,
293
- readWorkspace,
294
- recreateSubFolder,
295
- recreateWorkspace,
296
- removeAllFiles
297
- });