@lbdudc/linea-core 0.1.0 → 0.1.2

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 (253) hide show
  1. package/README.md +230 -358
  2. package/dist/analysis/analyze.d.ts +0 -54
  3. package/dist/analysis/analyze.js +1 -70
  4. package/dist/analysis/analyze.js.map +1 -1
  5. package/dist/analysis/runtime.d.ts +4 -73
  6. package/dist/analysis/runtime.js +7 -100
  7. package/dist/analysis/runtime.js.map +1 -1
  8. package/dist/analysis/uvl-text.d.ts +8 -0
  9. package/dist/analysis/uvl-text.js +70 -0
  10. package/dist/analysis/uvl-text.js.map +1 -0
  11. package/dist/assets.d.ts +0 -12
  12. package/dist/assets.js +0 -25
  13. package/dist/assets.js.map +1 -1
  14. package/dist/ci/annotations.d.ts +6 -0
  15. package/dist/ci/annotations.js +12 -0
  16. package/dist/ci/annotations.js.map +1 -0
  17. package/dist/ci/leftovers.d.ts +25 -0
  18. package/dist/ci/leftovers.js +50 -0
  19. package/dist/ci/leftovers.js.map +1 -0
  20. package/dist/ci/pairwise.d.ts +11 -0
  21. package/dist/ci/pairwise.js +35 -0
  22. package/dist/ci/pairwise.js.map +1 -0
  23. package/dist/ci/pipeline.d.ts +18 -0
  24. package/dist/ci/pipeline.js +26 -0
  25. package/dist/ci/pipeline.js.map +1 -0
  26. package/dist/ci/select.d.ts +28 -0
  27. package/dist/ci/select.js +43 -0
  28. package/dist/ci/select.js.map +1 -0
  29. package/dist/ci/validate-specs.d.ts +52 -0
  30. package/dist/ci/validate-specs.js +212 -0
  31. package/dist/ci/validate-specs.js.map +1 -0
  32. package/dist/constants.d.ts +1 -60
  33. package/dist/constants.js +1 -58
  34. package/dist/constants.js.map +1 -1
  35. package/dist/derivation/derive.d.ts +0 -56
  36. package/dist/derivation/derive.js +21 -72
  37. package/dist/derivation/derive.js.map +1 -1
  38. package/dist/derivation/engine.d.ts +10 -42
  39. package/dist/derivation/engine.js +37 -68
  40. package/dist/derivation/engine.js.map +1 -1
  41. package/dist/derivation/selection-error.d.ts +7 -0
  42. package/dist/derivation/selection-error.js +13 -0
  43. package/dist/derivation/selection-error.js.map +1 -0
  44. package/dist/errors.d.ts +19 -47
  45. package/dist/errors.js +28 -47
  46. package/dist/errors.js.map +1 -1
  47. package/dist/feature-model/uvl.d.ts +52 -0
  48. package/dist/feature-model/uvl.js +191 -0
  49. package/dist/feature-model/uvl.js.map +1 -0
  50. package/dist/fs/archive.d.ts +0 -16
  51. package/dist/fs/archive.js +0 -36
  52. package/dist/fs/archive.js.map +1 -1
  53. package/dist/fs/diff.d.ts +0 -30
  54. package/dist/fs/diff.js +4 -65
  55. package/dist/fs/diff.js.map +1 -1
  56. package/dist/fs/format.d.ts +0 -16
  57. package/dist/fs/format.js +0 -52
  58. package/dist/fs/format.js.map +1 -1
  59. package/dist/fs/workspace.d.ts +0 -52
  60. package/dist/fs/workspace.js +0 -56
  61. package/dist/fs/workspace.js.map +1 -1
  62. package/dist/index.d.ts +23 -29
  63. package/dist/index.js +15 -35
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/guards.d.ts +0 -13
  66. package/dist/internal/guards.js +0 -13
  67. package/dist/internal/guards.js.map +1 -1
  68. package/dist/line/deletion.d.ts +33 -0
  69. package/dist/line/deletion.js +23 -0
  70. package/dist/line/deletion.js.map +1 -0
  71. package/dist/line/platform-files.d.ts +15 -64
  72. package/dist/line/platform-files.js +18 -94
  73. package/dist/line/platform-files.js.map +1 -1
  74. package/dist/line/restoration.d.ts +27 -0
  75. package/dist/line/restoration.js +27 -0
  76. package/dist/line/restoration.js.map +1 -0
  77. package/dist/line/scaffold.d.ts +26 -57
  78. package/dist/line/scaffold.js +32 -93
  79. package/dist/line/scaffold.js.map +1 -1
  80. package/dist/line/templates/core/extra.js +54 -54
  81. package/dist/line/templates/core/transformation.js +208 -196
  82. package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -51
  83. package/dist/line/templates/pipeline/ci/test-client.sh +16 -16
  84. package/dist/line/templates/pipeline/ci/test-server.sh +16 -16
  85. package/dist/line/templates/pipeline/github-ci.yml +50 -0
  86. package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
  87. package/dist/modules/configuration/configure.d.ts +52 -0
  88. package/dist/modules/configuration/configure.js +101 -0
  89. package/dist/modules/configuration/configure.js.map +1 -0
  90. package/dist/modules/configuration/constants.d.ts +17 -0
  91. package/dist/modules/configuration/constants.js +14 -0
  92. package/dist/modules/configuration/constants.js.map +1 -0
  93. package/dist/modules/configuration/index.d.ts +6 -0
  94. package/dist/modules/configuration/index.js +5 -0
  95. package/dist/modules/configuration/index.js.map +1 -0
  96. package/dist/modules/configuration/names.d.ts +9 -0
  97. package/dist/modules/configuration/names.js +7 -0
  98. package/dist/modules/configuration/names.js.map +1 -0
  99. package/dist/modules/configuration/selection.d.ts +32 -0
  100. package/dist/modules/configuration/selection.js +49 -0
  101. package/dist/modules/configuration/selection.js.map +1 -0
  102. package/dist/modules/diagnostics.d.ts +2 -0
  103. package/dist/modules/diagnostics.js +2 -0
  104. package/dist/modules/diagnostics.js.map +1 -0
  105. package/dist/modules/index.d.ts +18 -0
  106. package/dist/modules/index.js +18 -0
  107. package/dist/modules/index.js.map +1 -0
  108. package/dist/modules/metamodels/engine.d.ts +93 -0
  109. package/dist/modules/metamodels/engine.js +10 -0
  110. package/dist/modules/metamodels/engine.js.map +1 -0
  111. package/dist/modules/metamodels/files.d.ts +40 -0
  112. package/dist/modules/metamodels/files.js +58 -0
  113. package/dist/modules/metamodels/files.js.map +1 -0
  114. package/dist/modules/metamodels/index.d.ts +8 -0
  115. package/dist/modules/metamodels/index.js +5 -0
  116. package/dist/modules/metamodels/index.js.map +1 -0
  117. package/dist/modules/metamodels/layout.d.ts +23 -0
  118. package/dist/modules/metamodels/layout.js +29 -0
  119. package/dist/modules/metamodels/layout.js.map +1 -0
  120. package/dist/modules/metamodels/offered.d.ts +15 -0
  121. package/dist/modules/metamodels/offered.js +14 -0
  122. package/dist/modules/metamodels/offered.js.map +1 -0
  123. package/dist/modules/metamodels/prepare.d.ts +20 -0
  124. package/dist/modules/metamodels/prepare.js +155 -0
  125. package/dist/modules/metamodels/prepare.js.map +1 -0
  126. package/dist/modules/packages/index.d.ts +4 -0
  127. package/dist/modules/packages/index.js +4 -0
  128. package/dist/modules/packages/index.js.map +1 -0
  129. package/dist/modules/packages/location.d.ts +21 -0
  130. package/dist/modules/packages/location.js +34 -0
  131. package/dist/modules/packages/location.js.map +1 -0
  132. package/dist/modules/packages/manifests.d.ts +33 -0
  133. package/dist/modules/packages/manifests.js +231 -0
  134. package/dist/modules/packages/manifests.js.map +1 -0
  135. package/dist/modules/packages/source.d.ts +34 -0
  136. package/dist/modules/packages/source.js +128 -0
  137. package/dist/modules/packages/source.js.map +1 -0
  138. package/dist/modules/products/check.d.ts +28 -0
  139. package/dist/modules/products/check.js +61 -0
  140. package/dist/modules/products/check.js.map +1 -0
  141. package/dist/modules/products/derive.d.ts +30 -0
  142. package/dist/modules/products/derive.js +56 -0
  143. package/dist/modules/products/derive.js.map +1 -0
  144. package/dist/modules/products/index.d.ts +5 -0
  145. package/dist/modules/products/index.js +4 -0
  146. package/dist/modules/products/index.js.map +1 -0
  147. package/dist/modules/products/seed.d.ts +18 -0
  148. package/dist/modules/products/seed.js +23 -0
  149. package/dist/modules/products/seed.js.map +1 -0
  150. package/dist/modules/registry/catalog.d.ts +64 -0
  151. package/dist/modules/registry/catalog.js +91 -0
  152. package/dist/modules/registry/catalog.js.map +1 -0
  153. package/dist/modules/registry/index.d.ts +5 -0
  154. package/dist/modules/registry/index.js +4 -0
  155. package/dist/modules/registry/index.js.map +1 -0
  156. package/dist/modules/registry/registry.d.ts +34 -0
  157. package/dist/modules/registry/registry.js +37 -0
  158. package/dist/modules/registry/registry.js.map +1 -0
  159. package/dist/modules/registry/routing.d.ts +8 -0
  160. package/dist/modules/registry/routing.js +23 -0
  161. package/dist/modules/registry/routing.js.map +1 -0
  162. package/dist/modules/resolution/closure.d.ts +28 -0
  163. package/dist/modules/resolution/closure.js +105 -0
  164. package/dist/modules/resolution/closure.js.map +1 -0
  165. package/dist/modules/resolution/index.d.ts +4 -0
  166. package/dist/modules/resolution/index.js +3 -0
  167. package/dist/modules/resolution/index.js.map +1 -0
  168. package/dist/modules/resolution/resolve.d.ts +33 -0
  169. package/dist/modules/resolution/resolve.js +59 -0
  170. package/dist/modules/resolution/resolve.js.map +1 -0
  171. package/dist/modules/resolution/resolvers.d.ts +23 -0
  172. package/dist/modules/resolution/resolvers.js +34 -0
  173. package/dist/modules/resolution/resolvers.js.map +1 -0
  174. package/dist/modules/spl/check.d.ts +25 -0
  175. package/dist/modules/spl/check.js +21 -0
  176. package/dist/modules/spl/check.js.map +1 -0
  177. package/dist/modules/spl/cip.d.ts +67 -0
  178. package/dist/modules/spl/cip.js +98 -0
  179. package/dist/modules/spl/cip.js.map +1 -0
  180. package/dist/modules/spl/feature-model.d.ts +39 -0
  181. package/dist/modules/spl/feature-model.js +106 -0
  182. package/dist/modules/spl/feature-model.js.map +1 -0
  183. package/dist/modules/spl/index.d.ts +6 -0
  184. package/dist/modules/spl/index.js +4 -0
  185. package/dist/modules/spl/index.js.map +1 -0
  186. package/dist/modules/spl/platform.d.ts +49 -0
  187. package/dist/modules/spl/platform.js +316 -0
  188. package/dist/modules/spl/platform.js.map +1 -0
  189. package/dist/modules/types.d.ts +132 -0
  190. package/dist/modules/types.js +2 -0
  191. package/dist/modules/types.js.map +1 -0
  192. package/dist/product/engine-spec.d.ts +0 -16
  193. package/dist/product/engine-spec.js +4 -50
  194. package/dist/product/engine-spec.js.map +1 -1
  195. package/dist/product/spec.d.ts +0 -82
  196. package/dist/product/spec.js +0 -79
  197. package/dist/product/spec.js.map +1 -1
  198. package/dist/product/version.d.ts +0 -23
  199. package/dist/product/version.js +0 -28
  200. package/dist/product/version.js.map +1 -1
  201. package/dist/products-index/products-index.d.ts +0 -165
  202. package/dist/products-index/products-index.js +0 -176
  203. package/dist/products-index/products-index.js.map +1 -1
  204. package/dist/workspace/context.d.ts +25 -0
  205. package/dist/workspace/context.js +43 -0
  206. package/dist/workspace/context.js.map +1 -0
  207. package/dist/workspace/gitExclude.d.ts +2 -0
  208. package/dist/workspace/gitExclude.js +19 -0
  209. package/dist/workspace/gitExclude.js.map +1 -0
  210. package/dist/workspace/host.d.ts +14 -0
  211. package/dist/workspace/host.js +13 -0
  212. package/dist/workspace/host.js.map +1 -0
  213. package/dist/workspace/index.d.ts +12 -0
  214. package/dist/workspace/index.js +12 -0
  215. package/dist/workspace/index.js.map +1 -0
  216. package/dist/workspace/local.d.ts +81 -0
  217. package/dist/workspace/local.js +287 -0
  218. package/dist/workspace/local.js.map +1 -0
  219. package/dist/workspace/modular.d.ts +95 -0
  220. package/dist/workspace/modular.js +301 -0
  221. package/dist/workspace/modular.js.map +1 -0
  222. package/dist/workspace/operations.d.ts +35 -0
  223. package/dist/workspace/operations.js +57 -0
  224. package/dist/workspace/operations.js.map +1 -0
  225. package/dist/workspace/origin.d.ts +20 -0
  226. package/dist/workspace/origin.js +19 -0
  227. package/dist/workspace/origin.js.map +1 -0
  228. package/package.json +82 -67
  229. package/dist/feature-model/convert.d.ts +0 -35
  230. package/dist/feature-model/convert.js +0 -47
  231. package/dist/feature-model/convert.js.map +0 -1
  232. package/dist/feature-model/engine.d.ts +0 -60
  233. package/dist/feature-model/engine.js +0 -139
  234. package/dist/feature-model/engine.js.map +0 -1
  235. package/dist/feature-model/inspect.d.ts +0 -67
  236. package/dist/feature-model/inspect.js +0 -113
  237. package/dist/feature-model/inspect.js.map +0 -1
  238. package/dist/feature-model/io.d.ts +0 -66
  239. package/dist/feature-model/io.js +0 -92
  240. package/dist/feature-model/io.js.map +0 -1
  241. package/dist/feature-model/parse.d.ts +0 -30
  242. package/dist/feature-model/parse.js +0 -36
  243. package/dist/feature-model/parse.js.map +0 -1
  244. package/dist/feature-model/text.d.ts +0 -54
  245. package/dist/feature-model/text.js +0 -126
  246. package/dist/feature-model/text.js.map +0 -1
  247. package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
  248. package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
  249. package/dist/line/templates/metamodels/sensor/extra.js +0 -36
  250. package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
  251. package/dist/selection/selection.d.ts +0 -126
  252. package/dist/selection/selection.js +0 -152
  253. package/dist/selection/selection.js.map +0 -1
@@ -0,0 +1,191 @@
1
+ import { UvlParseError } from '../errors.js';
2
+ const PRECEDENCE = new Map([['<=>', 1], ['=>', 2], ['|', 3], ['&', 4]]);
3
+ // ---------------------------------------------------------------------------------------------------------------- print
4
+ const KEYWORDS = new Set([
5
+ 'include', 'features', 'imports', 'namespace', 'as', 'constraint', 'constraints', 'cardinality', 'String', 'Boolean', 'Integer', 'Real', 'len', 'sum',
6
+ 'avg', 'floor', 'ceil', 'Type', 'Arithmetic', 'group-cardinality', 'feature-cardinality', 'aggregate-function', 'string-constraints',
7
+ 'or', 'alternative', 'optional', 'mandatory', 'true', 'false'
8
+ ]);
9
+ const STRICT_NAME = /^[a-zA-Z][a-zA-Z0-9_#§%?\\'äüöß;]*$/;
10
+ /** A name as UVL writes it: plain when it can be, else between double quotes (which cannot hold a dot, a quote or a line break). */
11
+ export const uvlName = ({ name }) => STRICT_NAME.test(name) && !KEYWORDS.has(name) ? name : `"${name.replace(/[".\r\n]/g, '_')}"`;
12
+ const formulaText = (formula, top) => {
13
+ if ('feature' in formula)
14
+ return uvlName({ name: formula.feature });
15
+ if ('not' in formula)
16
+ return `!${formulaText(formula.not, false)}`;
17
+ const text = `${formulaText(formula.left, false)} ${formula.operator} ${formulaText(formula.right, false)}`;
18
+ return top ? text : `(${text})`;
19
+ };
20
+ const groupText = (group) => group.kind !== 'cardinality'
21
+ ? group.kind
22
+ : `[${group.min ?? 0}${group.max === undefined ? '..*' : group.max === group.min ? '' : `..${group.max}`}]`;
23
+ /** The tree as UVL: tabs, one feature or group to a line, empty groups left out (UVL has none), constraints one to a line. */
24
+ export const printUvl = ({ tree }) => {
25
+ const lines = ['features'];
26
+ const feature = (node, depth) => {
27
+ lines.push(`${'\t'.repeat(depth)}${uvlName({ name: node.name })}${node.abstract === true ? ' {abstract}' : ''}`);
28
+ for (const group of node.groups.filter((candidate) => candidate.features.length > 0)) {
29
+ lines.push(`${'\t'.repeat(depth + 1)}${groupText(group)}`);
30
+ for (const child of group.features)
31
+ feature(child, depth + 2);
32
+ }
33
+ };
34
+ feature(tree.root, 1);
35
+ if (tree.constraints.length > 0)
36
+ lines.push('', 'constraints', ...tree.constraints.map((constraint) => `\t${formulaText(constraint, true)}`));
37
+ return `${lines.join('\n')}\n`;
38
+ };
39
+ // -------------------------------------------------------------------------------------------------------------- parse
40
+ // (the UVL grammar says a plain name starts with a letter, but models published on UVLHub have names that start with `_`: they are read)
41
+ const NAME = /^("[^"\r\n]+"|[a-zA-Z_][a-zA-Z0-9_#§%?\\'äüöß;]*)/;
42
+ const unquote = (text) => (text.startsWith('"') ? text.slice(1, -1) : text);
43
+ /**
44
+ * UVL (Boolean level: features with mandatory, optional, alternative, or and cardinality groups, and `! & | => <=>` constraints) as a tree.
45
+ * `namespace`, `include` and `imports` are skipped. What is not supported (typed features, feature cardinalities, arithmetic) is said, with its line.
46
+ * Throws `UvlParseError`.
47
+ */
48
+ export const parseUvl = ({ content }) => {
49
+ const lines = [];
50
+ // comments go: `//` to the end of the line, and `/* ... */` (keeping the line breaks so line numbers stay)
51
+ content.replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, ' ')).split(/\r?\n/).forEach((raw, index) => {
52
+ const code = raw.replace(/\/\/.*$/, '');
53
+ if (code.trim() !== '')
54
+ lines.push({ no: index + 1, indent: (/^[ \t]*/.exec(code)?.[0] ?? '').replace(/\t/g, ' ').length, text: code.trim() });
55
+ });
56
+ const fail = (line, message) => {
57
+ throw new UvlParseError(`line ${line.no}: ${message}`);
58
+ };
59
+ let at = 0;
60
+ let namespace;
61
+ let root;
62
+ const constraints = [];
63
+ const feature = () => {
64
+ const line = lines[at++];
65
+ const typed = /^(?:(String|Integer|Boolean|Real)\s+)?(.*)$/.exec(line.text);
66
+ if (typed[1] !== undefined)
67
+ fail(line, `typed features (${typed[1]}) are not supported`);
68
+ const rest0 = typed[2] ?? '';
69
+ const named = NAME.exec(rest0);
70
+ if (named === null)
71
+ return fail(line, `expected a feature name, found '${rest0}'`);
72
+ let rest = rest0.slice(named[0].length).trim();
73
+ if (/^cardinality\b/.test(rest))
74
+ fail(line, 'feature cardinalities are not supported');
75
+ let abstract = false;
76
+ if (rest.startsWith('{')) {
77
+ const close = rest.lastIndexOf('}');
78
+ if (close < 0)
79
+ fail(line, "an attribute list is missing its '}'");
80
+ abstract = rest.slice(1, close).split(',').some((attribute) => /^\s*abstract(\s+true)?\s*$/.test(attribute));
81
+ rest = rest.slice(close + 1).trim();
82
+ }
83
+ if (rest !== '')
84
+ fail(line, `unexpected '${rest}' after the feature name`);
85
+ const groups = [];
86
+ while (at < lines.length && lines[at].indent > line.indent) {
87
+ const header = lines[at++];
88
+ const kind = /^(mandatory|optional|alternative|or)$/.exec(header.text);
89
+ const card = /^\[\s*(\d+)\s*(?:\.\.\s*(\d+|\*)\s*)?\]$/.exec(header.text);
90
+ if (kind === null && card === null)
91
+ fail(header, `expected mandatory, optional, alternative, or, or a cardinality like [1..2], found '${header.text}'`);
92
+ const features = [];
93
+ const indent = at < lines.length ? lines[at].indent : 0;
94
+ if (!(indent > header.indent))
95
+ fail(header, 'a group needs its features, indented below it');
96
+ while (at < lines.length && lines[at].indent > header.indent) {
97
+ if (lines[at].indent !== indent)
98
+ fail(lines[at], 'the features of a group must be indented the same');
99
+ features.push(feature());
100
+ }
101
+ if (kind !== null)
102
+ groups.push({ kind: kind[1], features });
103
+ else {
104
+ const min = Number(card[1]);
105
+ groups.push({ kind: 'cardinality', min, ...(card[2] === '*' ? {} : { max: card[2] === undefined ? min : Number(card[2]) }), features });
106
+ }
107
+ }
108
+ return { name: unquote(named[0]), ...(abstract ? { abstract: true } : {}), groups };
109
+ };
110
+ const constraint = (line) => {
111
+ const tokens = [...line.text.matchAll(/\s*(<=>|=>|[()!&|]|"[^"\r\n]+"|[a-zA-Z_][a-zA-Z0-9_#§%?\\'äüöß;]*|\S)/g)].map((match) => match[1]);
112
+ let p = 0;
113
+ const isName = (token) => token !== undefined && (token.startsWith('"') || /^[a-zA-Z_]/.test(token)) && !PRECEDENCE.has(token);
114
+ const operand = () => {
115
+ const token = tokens[p++];
116
+ if (token === '!')
117
+ return { not: operand() };
118
+ if (token === '(') {
119
+ const inner = climb(1);
120
+ if (tokens[p++] !== ')')
121
+ fail(line, "a '(' is not closed");
122
+ return inner;
123
+ }
124
+ if (isName(token)) {
125
+ if (tokens[p] === '(' || tokens[p] === '.')
126
+ fail(line, 'aggregate functions and qualified names are not supported');
127
+ return { feature: unquote(token) };
128
+ }
129
+ return fail(line, token === undefined ? 'the constraint ends too soon' : `unexpected '${String(token)}' (only feature names and ! & | => <=> are supported)`);
130
+ };
131
+ // all the operators group to the left, as in UVL: from the tightest, & | => <=>
132
+ const climb = (least) => {
133
+ let left = operand();
134
+ while (PRECEDENCE.has(tokens[p]) && PRECEDENCE.get(tokens[p]) >= least) {
135
+ const operator = tokens[p++];
136
+ left = { operator, left, right: climb(PRECEDENCE.get(operator) + 1) };
137
+ }
138
+ return left;
139
+ };
140
+ const result = climb(1);
141
+ if (p < tokens.length)
142
+ fail(line, `unexpected '${String(tokens[p])}'`);
143
+ return result;
144
+ };
145
+ while (at < lines.length) {
146
+ const line = lines[at];
147
+ if (line.indent !== 0)
148
+ fail(line, 'unexpected indentation');
149
+ const word = /^\w+/.exec(line.text)?.[0];
150
+ if (word === 'namespace') {
151
+ namespace = line.text.slice(9).trim();
152
+ at++;
153
+ }
154
+ else if (word === 'include' || word === 'imports') {
155
+ at++;
156
+ while (at < lines.length && lines[at].indent > 0)
157
+ at++;
158
+ }
159
+ else if (word === 'features') {
160
+ at++;
161
+ if (!(at < lines.length && lines[at].indent > 0))
162
+ fail(line, "'features' needs its root feature, indented below it");
163
+ const indent = lines[at].indent;
164
+ root = feature();
165
+ if (at < lines.length && lines[at].indent > 0)
166
+ fail(lines[at], indent === lines[at].indent ? 'a feature model has one root feature' : 'unexpected indentation');
167
+ }
168
+ else if (word === 'constraints') {
169
+ at++;
170
+ while (at < lines.length && lines[at].indent > 0)
171
+ constraints.push(constraint(lines[at++]));
172
+ }
173
+ else
174
+ fail(line, `expected 'features' or 'constraints', found '${line.text}'`);
175
+ }
176
+ if (root === undefined)
177
+ throw new UvlParseError("there is no 'features' section");
178
+ return { name: namespace ?? root.name, root, constraints };
179
+ };
180
+ /** Every feature of the tree, parents first. */
181
+ export const featuresOf = ({ tree }) => {
182
+ const out = [];
183
+ const walk = (node) => {
184
+ out.push(node);
185
+ for (const group of node.groups)
186
+ group.features.forEach(walk);
187
+ };
188
+ walk(tree.root);
189
+ return out;
190
+ };
191
+ //# sourceMappingURL=uvl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uvl.js","sourceRoot":"","sources":["../../src/feature-model/uvl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAmC5C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAiB,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvF,yHAAyH;AAEzH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IACrJ,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAA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I,GAAG,CAAC,CAAA;IACjF,CAAC;IACD,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,aAAa,CAAC,gCAAgC,CAAC,CAAA;IACjF,OAAO,EAAE,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;AAC5D,CAAC,CAAA;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAA8B,EAAiB,EAAE;IAChF,MAAM,GAAG,GAAkB,EAAE,CAAA;IAC7B,MAAM,IAAI,GAAG,CAAC,IAAiB,EAAQ,EAAE;QACvC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACd,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM;YAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,CAAC,CAAA;IACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { UvlParseError } from '../errors.js'\n\n/**\n * The feature model as bango's feature metamodel (`featuremodel`) gives it as JSON (its JSON mapping, `featureModel`), and UVL (the\n * Universal Variability Language, Boolean level) as text. The platform's tools speak UVL (flamapy, the derivation engine); the models are\n * bango's. This is the one place where one becomes the other.\n */\n\nexport type GroupKind = 'mandatory' | 'optional' | 'alternative' | 'or' | 'cardinality'\n\nexport interface FeatureNode {\n readonly name: string\n readonly abstract?: boolean\n readonly groups: readonly FeatureGroup[]\n}\n\nexport interface FeatureGroup {\n readonly kind: GroupKind\n /** Only for a `cardinality` group: `[min..max]`; `max` is missing when there is none (`[min..*]`). */\n readonly min?: number\n readonly max?: number\n readonly features: readonly FeatureNode[]\n}\n\nexport type Formula =\n | { readonly feature: string }\n | { readonly not: Formula }\n | { readonly operator: '&' | '|' | '=>' | '<=>', readonly left: Formula, readonly right: Formula }\n\nexport interface FeatureModelTree {\n readonly name: string\n readonly root: FeatureNode\n readonly constraints: readonly Formula[]\n}\n\nconst PRECEDENCE = new Map<string, number>([['<=>', 1], ['=>', 2], ['|', 3], ['&', 4]])\n\n// ---------------------------------------------------------------------------------------------------------------- print\n\nconst KEYWORDS = new Set([\n 'include', 'features', 'imports', 'namespace', 'as', 'constraint', 'constraints', 'cardinality', 'String', 'Boolean', 'Integer', 'Real', 'len', 'sum',\n 'avg', 'floor', 'ceil', 'Type', 'Arithmetic', 'group-cardinality', 'feature-cardinality', 'aggregate-function', 'string-constraints',\n 'or', 'alternative', 'optional', 'mandatory', 'true', 'false'\n])\nconst STRICT_NAME = /^[a-zA-Z][a-zA-Z0-9_#§%?\\\\'äüöß;]*$/\n\n/** A name as UVL writes it: plain when it can be, else between double quotes (which cannot hold a dot, a quote or a line break). */\nexport const uvlName = ({ name }: { name: string }): string =>\n STRICT_NAME.test(name) && !KEYWORDS.has(name) ? name : `\"${name.replace(/[\".\\r\\n]/g, '_')}\"`\n\nconst formulaText = (formula: Formula, top: boolean): string => {\n if ('feature' in formula) return uvlName({ name: formula.feature })\n if ('not' in formula) return `!${formulaText(formula.not, false)}`\n const text = `${formulaText(formula.left, false)} ${formula.operator} ${formulaText(formula.right, false)}`\n return top ? text : `(${text})`\n}\n\nconst groupText = (group: FeatureGroup): string =>\n group.kind !== 'cardinality'\n ? group.kind\n : `[${group.min ?? 0}${group.max === undefined ? '..*' : group.max === group.min ? '' : `..${group.max}`}]`\n\n/** The tree as UVL: tabs, one feature or group to a line, empty groups left out (UVL has none), constraints one to a line. */\nexport const printUvl = ({ tree }: { tree: FeatureModelTree }): string => {\n const lines = ['features']\n const feature = (node: FeatureNode, depth: number): void => {\n lines.push(`${'\\t'.repeat(depth)}${uvlName({ name: node.name })}${node.abstract === true ? ' {abstract}' : ''}`)\n for (const group of node.groups.filter((candidate) => candidate.features.length > 0)) {\n lines.push(`${'\\t'.repeat(depth + 1)}${groupText(group)}`)\n for (const child of group.features) feature(child, depth + 2)\n }\n }\n feature(tree.root, 1)\n if (tree.constraints.length > 0) lines.push('', 'constraints', ...tree.constraints.map((constraint) => `\\t${formulaText(constraint, true)}`))\n return `${lines.join('\\n')}\\n`\n}\n\n// -------------------------------------------------------------------------------------------------------------- parse\n\n// (the UVL grammar says a plain name starts with a letter, but models published on UVLHub have names that start with `_`: they are read)\nconst NAME = /^(\"[^\"\\r\\n]+\"|[a-zA-Z_][a-zA-Z0-9_#§%?\\\\'äüöß;]*)/\nconst unquote = (text: string): string => (text.startsWith('\"') ? text.slice(1, -1) : text)\n\ninterface Line {\n readonly no: number\n readonly indent: number\n readonly text: string\n}\n\n/**\n * UVL (Boolean level: features with mandatory, optional, alternative, or and cardinality groups, and `! & | => <=>` constraints) as a tree.\n * `namespace`, `include` and `imports` are skipped. What is not supported (typed features, feature cardinalities, arithmetic) is said, with its line.\n * Throws `UvlParseError`.\n */\nexport const parseUvl = ({ content }: { content: string }): FeatureModelTree => {\n const lines: Line[] = []\n // comments go: `//` to the end of the line, and `/* ... */` (keeping the line breaks so line numbers stay)\n content.replace(/\\/\\*[\\s\\S]*?\\*\\//g, (comment) => comment.replace(/[^\\n]/g, ' ')).split(/\\r?\\n/).forEach((raw, index) => {\n const code = raw.replace(/\\/\\/.*$/, '')\n if (code.trim() !== '') lines.push({ no: index + 1, indent: (/^[ \\t]*/.exec(code)?.[0] ?? '').replace(/\\t/g, ' ').length, text: code.trim() })\n })\n const fail = (line: Line, message: string): never => {\n throw new UvlParseError(`line ${line.no}: ${message}`)\n }\n let at = 0\n let namespace: string | undefined\n let root: FeatureNode | undefined\n const constraints: Formula[] = []\n\n const feature = (): FeatureNode => {\n const line = lines[at++]!\n const typed = /^(?:(String|Integer|Boolean|Real)\\s+)?(.*)$/.exec(line.text)!\n if (typed[1] !== undefined) fail(line, `typed features (${typed[1]}) are not supported`)\n const rest0 = typed[2] ?? ''\n const named = NAME.exec(rest0)\n if (named === null) return fail(line, `expected a feature name, found '${rest0}'`)\n let rest = rest0.slice(named[0].length).trim()\n if (/^cardinality\\b/.test(rest)) fail(line, 'feature cardinalities are not supported')\n let abstract = false\n if (rest.startsWith('{')) {\n const close = rest.lastIndexOf('}')\n if (close < 0) fail(line, \"an attribute list is missing its '}'\")\n abstract = rest.slice(1, close).split(',').some((attribute) => /^\\s*abstract(\\s+true)?\\s*$/.test(attribute))\n rest = rest.slice(close + 1).trim()\n }\n if (rest !== '') fail(line, `unexpected '${rest}' after the feature name`)\n const groups: FeatureGroup[] = []\n while (at < lines.length && lines[at]!.indent > line.indent) {\n const header = lines[at++]!\n const kind = /^(mandatory|optional|alternative|or)$/.exec(header.text)\n const card = /^\\[\\s*(\\d+)\\s*(?:\\.\\.\\s*(\\d+|\\*)\\s*)?\\]$/.exec(header.text)\n if (kind === null && card === null) fail(header, `expected mandatory, optional, alternative, or, or a cardinality like [1..2], found '${header.text}'`)\n const features: FeatureNode[] = []\n const indent = at < lines.length ? lines[at]!.indent : 0\n if (!(indent > header.indent)) fail(header, 'a group needs its features, indented below it')\n while (at < lines.length && lines[at]!.indent > header.indent) {\n if (lines[at]!.indent !== indent) fail(lines[at]!, 'the features of a group must be indented the same')\n features.push(feature())\n }\n if (kind !== null) groups.push({ kind: kind[1] as GroupKind, features })\n else {\n const min = Number(card![1])\n groups.push({ kind: 'cardinality', min, ...(card![2] === '*' ? {} : { max: card![2] === undefined ? min : Number(card![2]) }), features })\n }\n }\n return { name: unquote(named[0]), ...(abstract ? { abstract: true } : {}), groups }\n }\n\n const constraint = (line: Line): Formula => {\n const tokens = [...line.text.matchAll(/\\s*(<=>|=>|[()!&|]|\"[^\"\\r\\n]+\"|[a-zA-Z_][a-zA-Z0-9_#§%?\\\\'äüöß;]*|\\S)/g)].map((match) => match[1]!)\n let p = 0\n const isName = (token: string | undefined): token is string =>\n token !== undefined && (token.startsWith('\"') || /^[a-zA-Z_]/.test(token)) && !PRECEDENCE.has(token)\n const operand = (): Formula => {\n const token = tokens[p++]\n if (token === '!') return { not: operand() }\n if (token === '(') {\n const inner = climb(1)\n if (tokens[p++] !== ')') fail(line, \"a '(' is not closed\")\n return inner\n }\n if (isName(token)) {\n if (tokens[p] === '(' || tokens[p] === '.') fail(line, 'aggregate functions and qualified names are not supported')\n return { feature: unquote(token) }\n }\n return fail(line, token === undefined ? 'the constraint ends too soon' : `unexpected '${String(token)}' (only feature names and ! & | => <=> are supported)`)\n }\n // all the operators group to the left, as in UVL: from the tightest, & | => <=>\n const climb = (least: number): Formula => {\n let left = operand()\n while (PRECEDENCE.has(tokens[p]!) && PRECEDENCE.get(tokens[p]!)! >= least) {\n const operator = tokens[p++] as '&' | '|' | '=>' | '<=>'\n left = { operator, left, right: climb(PRECEDENCE.get(operator)! + 1) }\n }\n return left\n }\n const result = climb(1)\n if (p < tokens.length) fail(line, `unexpected '${String(tokens[p])}'`)\n return result\n }\n\n while (at < lines.length) {\n const line = lines[at]!\n if (line.indent !== 0) fail(line, 'unexpected indentation')\n const word = /^\\w+/.exec(line.text)?.[0]\n if (word === 'namespace') { namespace = line.text.slice(9).trim(); at++ }\n else if (word === 'include' || word === 'imports') { at++; while (at < lines.length && lines[at]!.indent > 0) at++ }\n else if (word === 'features') {\n at++\n if (!(at < lines.length && lines[at]!.indent > 0)) fail(line, \"'features' needs its root feature, indented below it\")\n const indent = lines[at]!.indent\n root = feature()\n if (at < lines.length && lines[at]!.indent > 0) fail(lines[at]!, indent === lines[at]!.indent ? 'a feature model has one root feature' : 'unexpected indentation')\n } else if (word === 'constraints') {\n at++\n while (at < lines.length && lines[at]!.indent > 0) constraints.push(constraint(lines[at++]!))\n } else fail(line, `expected 'features' or 'constraints', found '${line.text}'`)\n }\n if (root === undefined) throw new UvlParseError(\"there is no 'features' section\")\n return { name: namespace ?? root.name, root, constraints }\n}\n\n/** Every feature of the tree, parents first. */\nexport const featuresOf = ({ tree }: { tree: FeatureModelTree }): FeatureNode[] => {\n const out: FeatureNode[] = []\n const walk = (node: FeatureNode): void => {\n out.push(node)\n for (const group of node.groups) group.features.forEach(walk)\n }\n walk(tree.root)\n return out\n}\n"]}
@@ -1,19 +1,3 @@
1
- /**
2
- * Extracts a zip archive.
3
- *
4
- * GitLab archives wrap everything in a single top-level directory named after
5
- * the project and commit, so the interesting content is one level down. `prefix`
6
- * selects it, reproducing the `srcPath` argument of `unZip`: the first top-level
7
- * directory whose name starts with `prefix`, falling back to the first one.
8
- *
9
- * @param params.source Path to a `.zip` file, or its bytes.
10
- * @param params.destDir Directory to extract into. Created if missing.
11
- * @param params.prefix Optional: pick the top-level directory starting with it
12
- * and return that instead of `destDir`.
13
- * @returns The directory holding the extracted content.
14
- * @throws {InvalidArgumentError} when the arguments are malformed or `source`
15
- * does not exist.
16
- */
17
1
  export declare const extractArchive: ({ source, destDir, prefix }: {
18
2
  source: string | Uint8Array;
19
3
  destDir: string;
@@ -1,40 +1,8 @@
1
- /**
2
- * Archive extraction.
3
- *
4
- * Migrated from `linea/server/src/model/services/utils.js:unZip` (~46-80), which
5
- * downloads a repository archive from GitLab and unpacks it.
6
- *
7
- * HARDENED PORT on two counts (ADR-014):
8
- * - `unZip` created its scratch space itself under the GLOBAL
9
- * `properties.paths.output`, so where the files landed depended on
10
- * configuration the caller could not see. Here `destDir` is a required
11
- * parameter and nothing else is ever touched.
12
- * - It also took the archive as a readable STREAM and wrote it to
13
- * `archive.zip` inside the target directory, leaving that file behind for the
14
- * caller to delete (`PlaygroundService.js:164` does exactly that). Here the
15
- * source is a path or a buffer, and any temporary copy is cleaned up.
16
- */
17
1
  import fs from 'node:fs';
18
2
  import os from 'node:os';
19
3
  import path from 'node:path';
20
4
  import extract from 'extract-zip';
21
5
  import { InvalidArgumentError } from '../errors.js';
22
- /**
23
- * Extracts a zip archive.
24
- *
25
- * GitLab archives wrap everything in a single top-level directory named after
26
- * the project and commit, so the interesting content is one level down. `prefix`
27
- * selects it, reproducing the `srcPath` argument of `unZip`: the first top-level
28
- * directory whose name starts with `prefix`, falling back to the first one.
29
- *
30
- * @param params.source Path to a `.zip` file, or its bytes.
31
- * @param params.destDir Directory to extract into. Created if missing.
32
- * @param params.prefix Optional: pick the top-level directory starting with it
33
- * and return that instead of `destDir`.
34
- * @returns The directory holding the extracted content.
35
- * @throws {InvalidArgumentError} when the arguments are malformed or `source`
36
- * does not exist.
37
- */
38
6
  export const extractArchive = async ({ source, destDir, prefix }) => {
39
7
  if (typeof destDir !== 'string' || destDir.trim() === '') {
40
8
  throw new InvalidArgumentError('"destDir" must be a non-empty path.');
@@ -44,8 +12,6 @@ export const extractArchive = async ({ source, destDir, prefix }) => {
44
12
  }
45
13
  const target = path.resolve(destDir);
46
14
  fs.mkdirSync(target, { recursive: true });
47
- // A buffer has to reach the disk for yauzl to read it; that copy is ours to
48
- // clean up, and it goes to the OS temp dir so it never pollutes `destDir`.
49
15
  let archivePath;
50
16
  let scratchDir = null;
51
17
  if (typeof source === 'string') {
@@ -79,8 +45,6 @@ export const extractArchive = async ({ source, destDir, prefix }) => {
79
45
  .filter((entry) => entry.isDirectory())
80
46
  .map((entry) => entry.name)
81
47
  .sort();
82
- // Same resolution as unZip: first match on the prefix, else the first
83
- // directory, else the extraction root itself.
84
48
  const chosen = directories.find((name) => name.startsWith(prefix)) ?? directories[0];
85
49
  return { dir: chosen === undefined ? target : path.join(target, chosen) };
86
50
  };
@@ -1 +1 @@
1
- {"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/fs/archive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,OAAO,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EAKP,EAA4B,EAAE;IAC7B,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SAAM,CAAC;QACN,MAAM,IAAI,oBAAoB,CAAC,0CAA0C,CAAC,CAAA;IAC5E,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;IAC7C,CAAC;YAAS,CAAC;QACT,IAAI,UAAU,KAAK,IAAI;YAAE,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAClF,CAAC;IAED,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;IAEhD,MAAM,WAAW,GAAG,EAAE;SACnB,WAAW,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAC5C,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACtC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,EAAE,CAAA;IAET,sEAAsE;IACtE,8CAA8C;IAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;IACpF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;AAC3E,CAAC,CAAA","sourcesContent":["/**\r\n * Archive extraction.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:unZip` (~46-80), which\r\n * downloads a repository archive from GitLab and unpacks it.\r\n *\r\n * HARDENED PORT on two counts (ADR-014):\r\n * - `unZip` created its scratch space itself under the GLOBAL\r\n * `properties.paths.output`, so where the files landed depended on\r\n * configuration the caller could not see. Here `destDir` is a required\r\n * parameter and nothing else is ever touched.\r\n * - It also took the archive as a readable STREAM and wrote it to\r\n * `archive.zip` inside the target directory, leaving that file behind for the\r\n * caller to delete (`PlaygroundService.js:164` does exactly that). Here the\r\n * source is a path or a buffer, and any temporary copy is cleaned up.\r\n */\r\nimport fs from 'node:fs'\r\nimport os from 'node:os'\r\nimport path from 'node:path'\r\nimport extract from 'extract-zip'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * Extracts a zip archive.\r\n *\r\n * GitLab archives wrap everything in a single top-level directory named after\r\n * the project and commit, so the interesting content is one level down. `prefix`\r\n * selects it, reproducing the `srcPath` argument of `unZip`: the first top-level\r\n * directory whose name starts with `prefix`, falling back to the first one.\r\n *\r\n * @param params.source Path to a `.zip` file, or its bytes.\r\n * @param params.destDir Directory to extract into. Created if missing.\r\n * @param params.prefix Optional: pick the top-level directory starting with it\r\n * and return that instead of `destDir`.\r\n * @returns The directory holding the extracted content.\r\n * @throws {InvalidArgumentError} when the arguments are malformed or `source`\r\n * does not exist.\r\n */\r\nexport const extractArchive = async ({\r\n source,\r\n destDir,\r\n prefix\r\n}: {\r\n source: string | Uint8Array\r\n destDir: string\r\n prefix?: string\r\n}): Promise<{ dir: string }> => {\r\n if (typeof destDir !== 'string' || destDir.trim() === '') {\r\n throw new InvalidArgumentError('\"destDir\" must be a non-empty path.')\r\n }\r\n if (prefix !== undefined && typeof prefix !== 'string') {\r\n throw new InvalidArgumentError('\"prefix\" must be a string when provided.')\r\n }\r\n\r\n const target = path.resolve(destDir)\r\n fs.mkdirSync(target, { recursive: true })\r\n\r\n // A buffer has to reach the disk for yauzl to read it; that copy is ours to\r\n // clean up, and it goes to the OS temp dir so it never pollutes `destDir`.\r\n let archivePath: string\r\n let scratchDir: string | null = null\r\n if (typeof source === 'string') {\r\n if (source.trim() === '') {\r\n throw new InvalidArgumentError('\"source\" must be a non-empty path.')\r\n }\r\n archivePath = path.resolve(source)\r\n if (!fs.existsSync(archivePath)) {\r\n throw new InvalidArgumentError(`Archive not found: ${archivePath}`)\r\n }\r\n } else if (source instanceof Uint8Array) {\r\n scratchDir = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-core-archive-'))\r\n archivePath = path.join(scratchDir, 'archive.zip')\r\n fs.writeFileSync(archivePath, source)\r\n } else {\r\n throw new InvalidArgumentError('\"source\" must be a path or a Uint8Array.')\r\n }\r\n\r\n try {\r\n await extract(archivePath, { dir: target })\r\n } finally {\r\n if (scratchDir !== null) fs.rmSync(scratchDir, { recursive: true, force: true })\r\n }\r\n\r\n if (prefix === undefined) return { dir: target }\r\n\r\n const directories = fs\r\n .readdirSync(target, { withFileTypes: true })\r\n .filter((entry) => entry.isDirectory())\r\n .map((entry) => entry.name)\r\n .sort()\r\n\r\n // Same resolution as unZip: first match on the prefix, else the first\r\n // directory, else the extraction root itself.\r\n const chosen = directories.find((name) => name.startsWith(prefix)) ?? directories[0]\r\n return { dir: chosen === undefined ? target : path.join(target, chosen) }\r\n}\r\n"]}
1
+ {"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/fs/archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,OAAO,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EAKP,EAA4B,EAAE;IAC7B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,qCAAqC,CAAC,CAAA;IACvE,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,IAAI,O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,IAAI;YAAE,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAClF,CAAC;IAED,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;IAEhD,MAAM,WAAW,GAAG,EAAE;SACnB,WAAW,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAC5C,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACtC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,EAAE,CAAA;IAET,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;IACpF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;AAC3E,CAAC,CAAA","sourcesContent":["import fs from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport extract from 'extract-zip'\nimport { InvalidArgumentError } from '../errors.js'\n\nexport const extractArchive = async ({\n source,\n destDir,\n prefix\n}: {\n source: string | Uint8Array\n destDir: string\n prefix?: string\n}): Promise<{ dir: string }> => {\n if (typeof destDir !== 'string' || destDir.trim() === '') {\n throw new InvalidArgumentError('\"destDir\" must be a non-empty path.')\n }\n if (prefix !== undefined && typeof prefix !== 'string') {\n throw new InvalidArgumentError('\"prefix\" must be a string when provided.')\n }\n\n const target = path.resolve(destDir)\n fs.mkdirSync(target, { recursive: true })\n\n let archivePath: string\n let scratchDir: string | null = null\n if (typeof source === 'string') {\n if (source.trim() === '') {\n throw new InvalidArgumentError('\"source\" must be a non-empty path.')\n }\n archivePath = path.resolve(source)\n if (!fs.existsSync(archivePath)) {\n throw new InvalidArgumentError(`Archive not found: ${archivePath}`)\n }\n } else if (source instanceof Uint8Array) {\n scratchDir = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-core-archive-'))\n archivePath = path.join(scratchDir, 'archive.zip')\n fs.writeFileSync(archivePath, source)\n } else {\n throw new InvalidArgumentError('\"source\" must be a path or a Uint8Array.')\n }\n\n try {\n await extract(archivePath, { dir: target })\n } finally {\n if (scratchDir !== null) fs.rmSync(scratchDir, { recursive: true, force: true })\n }\n\n if (prefix === undefined) return { dir: target }\n\n const directories = fs\n .readdirSync(target, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name)\n .sort()\n\n const chosen = directories.find((name) => name.startsWith(prefix)) ?? directories[0]\n return { dir: chosen === undefined ? target : path.join(target, chosen) }\n}\n"]}
package/dist/fs/diff.d.ts CHANGED
@@ -1,39 +1,9 @@
1
- /**
2
- * A single file change between two directory trees.
3
- *
4
- * NEUTRAL FILE-CHANGE FORMAT. The field names (`action`, `file_path`,
5
- * `content`, `encoding`) are GitLab's commit-action vocabulary, kept on purpose
6
- * so linea-server can hand the array straight to `gitlabSession.commit` with no
7
- * adapter in between. linea-core itself neither knows nor cares about GitLab
8
- * (ADR-003) — this is a data shape, not a dependency.
9
- */
10
1
  export interface FileChange {
11
2
  readonly action: 'create' | 'update' | 'delete';
12
- /** Path relative to the compared directory, ALWAYS POSIX (`/`). */
13
3
  readonly file_path: string;
14
- /** Absent for `delete`. */
15
4
  readonly content?: string;
16
- /** Absent for `delete`. */
17
5
  readonly encoding?: 'text' | 'base64';
18
6
  }
19
- /**
20
- * Compares two directory trees and reports the changes needed to turn the old
21
- * one into the new one.
22
- *
23
- * Preserves the monolith's three rules exactly:
24
- * - present only in `oldDir` -> `delete`, EXCEPT `README.md`, never deleted.
25
- * - present only in `newDir` -> `create`.
26
- * - present in both with different bytes -> `update`.
27
- * - present in both with the same bytes -> nothing.
28
- *
29
- * Binary files are read as base64 with `encoding: 'base64'`; text as UTF-8 with
30
- * `encoding: 'text'`.
31
- *
32
- * @param params.oldDir Directory with the previous state.
33
- * @param params.newDir Directory with the desired state.
34
- * @returns The changes, sorted by `file_path` so the result is deterministic.
35
- * @throws {InvalidArgumentError} when either path is not a non-empty string.
36
- */
37
7
  export declare const diffDirectories: ({ oldDir, newDir }: {
38
8
  oldDir: string;
39
9
  newDir: string;
package/dist/fs/diff.js CHANGED
@@ -1,39 +1,8 @@
1
- /**
2
- * Directory comparison expressed as file changes.
3
- *
4
- * Migrated from `linea/server/src/model/services/utils.js` (~86-128):
5
- * `isFileToDelete`, `isFileToCreate`, `isFileToUpdate`, `generateAction` and
6
- * `generateActions`.
7
- *
8
- * Behaviour is preserved exactly; the IMPLEMENTATION is rebuilt (see below).
9
- */
10
1
  import crypto from 'node:crypto';
11
2
  import fs from 'node:fs';
12
3
  import path from 'node:path';
13
4
  import { InvalidArgumentError } from '../errors.js';
14
- /**
15
- * Files never reported as deleted.
16
- *
17
- * Verbatim from `isFileToDelete`, which excludes `README.md`: a generated
18
- * product's README is written by hand and must survive a regeneration that no
19
- * longer produces one.
20
- */
21
5
  const NEVER_DELETED = new Set(['README.md']);
22
- /**
23
- * Extensions treated as binary.
24
- *
25
- * The monolith delegates to the `is-binary-path` package. Reproduced here as an
26
- * explicit list to avoid a dependency whose only job is a lookup table, and
27
- * because being explicit about what ends up base64-encoded is worth more than
28
- * exhaustiveness. Content sniffing is deliberately avoided: it would make the
29
- * encoding of a file depend on its bytes rather than its name, so the same file
30
- * could change encoding between two runs.
31
- *
32
- * When in doubt, ADD the extension. The two mistakes are not symmetric: a false
33
- * positive only base64-encodes a text file that did not need it, while a false
34
- * negative reads binary content with `utf-8`, turns every invalid sequence into
35
- * U+FFFD and commits a silently corrupted file to GitLab — no error, no warning.
36
- */
37
6
  const BINARY_EXTENSIONS = new Set([
38
7
  '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.webp', '.tif', '.tiff', '.avif',
39
8
  '.svgz',
@@ -46,27 +15,12 @@ const BINARY_EXTENSIONS = new Set([
46
15
  '.bin', '.dat'
47
16
  ]);
48
17
  const isBinaryPath = (filePath) => BINARY_EXTENSIONS.has(path.extname(filePath).toLowerCase());
49
- /**
50
- * Repository-relative POSIX path of `filePath` inside `baseDir`.
51
- *
52
- * HARDENED PORT. `generateAction` derived this by splitting the absolute path on
53
- * the literal `` `tmp${sep}${uuid}${sep}new` `` and keeping the tail — coupled to
54
- * `properties.paths.output`, to the uuid-named temp layout, and silently wrong
55
- * if any of that changed.
56
- *
57
- * It also had a LATENT BUG on Windows: `path.join` produces `\` separators, so
58
- * `file_path` would come out as `src\main\App.java`, which the GitLab API
59
- * rejects. The monolith never hit it because it only ever ran on Linux. Closed
60
- * here by normalising to POSIX unconditionally.
61
- */
62
18
  const toRepositoryPath = (baseDir, filePath) => path.relative(baseDir, filePath).split(path.sep).join('/');
63
- /** Streaming MD5 of a file. Replaces `md5File.sync` from the monolith. */
64
19
  const md5 = (filePath) => {
65
20
  const hash = crypto.createHash('md5');
66
21
  hash.update(fs.readFileSync(filePath));
67
22
  return hash.digest('hex');
68
23
  };
69
- /** Same bytes on both sides? Compared by digest, as the monolith does. */
70
24
  const hasSameContent = (a, b) => md5(a) === md5(b);
71
25
  const readAsChange = (action, baseDir, absolutePath) => {
72
26
  const binary = isBinaryPath(absolutePath);
@@ -77,7 +31,8 @@ const readAsChange = (action, baseDir, absolutePath) => {
77
31
  encoding: binary ? 'base64' : 'text'
78
32
  };
79
33
  };
80
- /** Relative POSIX paths of every file under `dir`, recursively. */
34
+ const JVM_BUILD_FILES = new Set(['build.gradle', 'build.gradle.kts', 'pom.xml']);
35
+ const isBuildOutput = (name, siblings) => name === '.gradle' || (name === 'bin' && siblings.some((sibling) => sibling.isFile() && JVM_BUILD_FILES.has(sibling.name)));
81
36
  const listFiles = (dir) => {
82
37
  const found = [];
83
38
  const walk = (current, prefix) => {
@@ -91,6 +46,8 @@ const listFiles = (dir) => {
91
46
  for (const entry of entries) {
92
47
  const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
93
48
  if (entry.isDirectory()) {
49
+ if (isBuildOutput(entry.name, entries))
50
+ continue;
94
51
  walk(path.join(current, entry.name), relative);
95
52
  }
96
53
  else if (entry.isFile()) {
@@ -107,24 +64,6 @@ const assertDir = (value, parameter) => {
107
64
  }
108
65
  return path.resolve(value);
109
66
  };
110
- /**
111
- * Compares two directory trees and reports the changes needed to turn the old
112
- * one into the new one.
113
- *
114
- * Preserves the monolith's three rules exactly:
115
- * - present only in `oldDir` -> `delete`, EXCEPT `README.md`, never deleted.
116
- * - present only in `newDir` -> `create`.
117
- * - present in both with different bytes -> `update`.
118
- * - present in both with the same bytes -> nothing.
119
- *
120
- * Binary files are read as base64 with `encoding: 'base64'`; text as UTF-8 with
121
- * `encoding: 'text'`.
122
- *
123
- * @param params.oldDir Directory with the previous state.
124
- * @param params.newDir Directory with the desired state.
125
- * @returns The changes, sorted by `file_path` so the result is deterministic.
126
- * @throws {InvalidArgumentError} when either path is not a non-empty string.
127
- */
128
67
  export const diffDirectories = ({ oldDir, newDir }) => {
129
68
  const oldRoot = assertDir(oldDir, 'oldDir');
130
69
  const newRoot = assertDir(newDir, 'newDir');
@@ -1 +1 @@
1
- {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/fs/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAqBnD;;;;;;GAMG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;AAE5C;;;;;;;;;;;;;;GAcG;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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACrG,CAAC,CAAA","sourcesContent":["/**\r\n * Directory comparison expressed as file changes.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js` (~86-128):\r\n * `isFileToDelete`, `isFileToCreate`, `isFileToUpdate`, `generateAction` and\r\n * `generateActions`.\r\n *\r\n * Behaviour is preserved exactly; the IMPLEMENTATION is rebuilt (see below).\r\n */\r\nimport crypto from 'node:crypto'\r\nimport fs from 'node:fs'\r\nimport path from 'node:path'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * A single file change between two directory trees.\r\n *\r\n * NEUTRAL FILE-CHANGE FORMAT. The field names (`action`, `file_path`,\r\n * `content`, `encoding`) are GitLab's commit-action vocabulary, kept on purpose\r\n * so linea-server can hand the array straight to `gitlabSession.commit` with no\r\n * adapter in between. linea-core itself neither knows nor cares about GitLab\r\n * (ADR-003) — this is a data shape, not a dependency.\r\n */\r\nexport interface FileChange {\r\n readonly action: 'create' | 'update' | 'delete'\r\n /** Path relative to the compared directory, ALWAYS POSIX (`/`). */\r\n readonly file_path: string\r\n /** Absent for `delete`. */\r\n readonly content?: string\r\n /** Absent for `delete`. */\r\n readonly encoding?: 'text' | 'base64'\r\n}\r\n\r\n/**\r\n * Files never reported as deleted.\r\n *\r\n * Verbatim from `isFileToDelete`, which excludes `README.md`: a generated\r\n * product's README is written by hand and must survive a regeneration that no\r\n * longer produces one.\r\n */\r\nconst NEVER_DELETED = new Set(['README.md'])\r\n\r\n/**\r\n * Extensions treated as binary.\r\n *\r\n * The monolith delegates to the `is-binary-path` package. Reproduced here as an\r\n * explicit list to avoid a dependency whose only job is a lookup table, and\r\n * because being explicit about what ends up base64-encoded is worth more than\r\n * exhaustiveness. Content sniffing is deliberately avoided: it would make the\r\n * encoding of a file depend on its bytes rather than its name, so the same file\r\n * could change encoding between two runs.\r\n *\r\n * When in doubt, ADD the extension. The two mistakes are not symmetric: a false\r\n * positive only base64-encodes a text file that did not need it, while a false\r\n * negative reads binary content with `utf-8`, turns every invalid sequence into\r\n * U+FFFD and commits a silently corrupted file to GitLab — no error, no warning.\r\n */\r\nconst BINARY_EXTENSIONS = new Set([\r\n '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.webp', '.tif', '.tiff', '.avif',\r\n '.svgz',\r\n '.pdf', '.zip', '.gz', '.tar', '.tgz', '.bz2', '.7z', '.rar', '.jar', '.war',\r\n '.woff', '.woff2', '.ttf', '.otf', '.eot',\r\n '.mp3', '.mp4', '.avi', '.mov', '.webm', '.ogg', '.wav', '.flac',\r\n '.so', '.dll', '.dylib', '.exe', '.class', '.pyc', '.wasm', '.node',\r\n '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.odt', '.ods',\r\n '.db', '.sqlite', '.keystore', '.jks', '.p12', '.pfx',\r\n '.bin', '.dat'\r\n])\r\n\r\nconst isBinaryPath = (filePath: string): boolean =>\r\n BINARY_EXTENSIONS.has(path.extname(filePath).toLowerCase())\r\n\r\n/**\r\n * Repository-relative POSIX path of `filePath` inside `baseDir`.\r\n *\r\n * HARDENED PORT. `generateAction` derived this by splitting the absolute path on\r\n * the literal `` `tmp${sep}${uuid}${sep}new` `` and keeping the tail — coupled to\r\n * `properties.paths.output`, to the uuid-named temp layout, and silently wrong\r\n * if any of that changed.\r\n *\r\n * It also had a LATENT BUG on Windows: `path.join` produces `\\` separators, so\r\n * `file_path` would come out as `src\\main\\App.java`, which the GitLab API\r\n * rejects. The monolith never hit it because it only ever ran on Linux. Closed\r\n * here by normalising to POSIX unconditionally.\r\n */\r\nconst toRepositoryPath = (baseDir: string, filePath: string): string =>\r\n path.relative(baseDir, filePath).split(path.sep).join('/')\r\n\r\n/** Streaming MD5 of a file. Replaces `md5File.sync` from the monolith. */\r\nconst md5 = (filePath: string): string => {\r\n const hash = crypto.createHash('md5')\r\n hash.update(fs.readFileSync(filePath))\r\n return hash.digest('hex')\r\n}\r\n\r\n/** Same bytes on both sides? Compared by digest, as the monolith does. */\r\nconst hasSameContent = (a: string, b: string): boolean => md5(a) === md5(b)\r\n\r\nconst readAsChange = (\r\n action: 'create' | 'update',\r\n baseDir: string,\r\n absolutePath: string\r\n): FileChange => {\r\n const binary = isBinaryPath(absolutePath)\r\n return {\r\n action,\r\n file_path: toRepositoryPath(baseDir, absolutePath),\r\n content: fs.readFileSync(absolutePath, binary ? 'base64' : 'utf-8'),\r\n encoding: binary ? 'base64' : 'text'\r\n }\r\n}\r\n\r\n/** Relative POSIX paths of every file under `dir`, recursively. */\r\nconst listFiles = (dir: string): string[] => {\r\n const found: string[] = []\r\n const walk = (current: string, prefix: string): void => {\r\n let entries: fs.Dirent[]\r\n try {\r\n entries = fs.readdirSync(current, { withFileTypes: true })\r\n } catch {\r\n return\r\n }\r\n for (const entry of entries) {\r\n const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`\r\n if (entry.isDirectory()) {\r\n walk(path.join(current, entry.name), relative)\r\n } else if (entry.isFile()) {\r\n found.push(relative)\r\n }\r\n }\r\n }\r\n walk(dir, '')\r\n return found.sort()\r\n}\r\n\r\nconst assertDir = (value: unknown, parameter: string): string => {\r\n if (typeof value !== 'string' || value.trim() === '') {\r\n throw new InvalidArgumentError(`\"${parameter}\" must be a non-empty path.`)\r\n }\r\n return path.resolve(value)\r\n}\r\n\r\n/**\r\n * Compares two directory trees and reports the changes needed to turn the old\r\n * one into the new one.\r\n *\r\n * Preserves the monolith's three rules exactly:\r\n * - present only in `oldDir` -> `delete`, EXCEPT `README.md`, never deleted.\r\n * - present only in `newDir` -> `create`.\r\n * - present in both with different bytes -> `update`.\r\n * - present in both with the same bytes -> nothing.\r\n *\r\n * Binary files are read as base64 with `encoding: 'base64'`; text as UTF-8 with\r\n * `encoding: 'text'`.\r\n *\r\n * @param params.oldDir Directory with the previous state.\r\n * @param params.newDir Directory with the desired state.\r\n * @returns The changes, sorted by `file_path` so the result is deterministic.\r\n * @throws {InvalidArgumentError} when either path is not a non-empty string.\r\n */\r\nexport const diffDirectories = ({\r\n oldDir,\r\n newDir\r\n}: {\r\n oldDir: string\r\n newDir: string\r\n}): FileChange[] => {\r\n const oldRoot = assertDir(oldDir, 'oldDir')\r\n const newRoot = assertDir(newDir, 'newDir')\r\n\r\n const oldFiles = new Set(listFiles(oldRoot))\r\n const newFiles = listFiles(newRoot)\r\n const changes: FileChange[] = []\r\n\r\n for (const relative of newFiles) {\r\n const newPath = path.join(newRoot, ...relative.split('/'))\r\n if (!oldFiles.has(relative)) {\r\n changes.push(readAsChange('create', newRoot, newPath))\r\n continue\r\n }\r\n const oldPath = path.join(oldRoot, ...relative.split('/'))\r\n if (!hasSameContent(oldPath, newPath)) {\r\n changes.push(readAsChange('update', newRoot, newPath))\r\n }\r\n }\r\n\r\n const newFileSet = new Set(newFiles)\r\n for (const relative of oldFiles) {\r\n if (newFileSet.has(relative)) continue\r\n if (NEVER_DELETED.has(path.posix.basename(relative))) continue\r\n changes.push({ action: 'delete', file_path: relative })\r\n }\r\n\r\n return changes.sort((a, b) => (a.file_path < b.file_path ? -1 : a.file_path > b.file_path ? 1 : 0))\r\n}\r\n"]}
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/fs/diff.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AASnD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;AAE5C,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAClF,OAAO;IACP,MAAM,EAAE,MAAM,EAAE,KA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AC,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACrG,CAAC,CAAA","sourcesContent":["import crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { InvalidArgumentError } from '../errors.js'\n\nexport interface FileChange {\n readonly action: 'create' | 'update' | 'delete'\n readonly file_path: string\n readonly content?: string\n readonly encoding?: 'text' | 'base64'\n}\n\nconst NEVER_DELETED = new Set(['README.md'])\n\nconst BINARY_EXTENSIONS = new Set([\n '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.webp', '.tif', '.tiff', '.avif',\n '.svgz',\n '.pdf', '.zip', '.gz', '.tar', '.tgz', '.bz2', '.7z', '.rar', '.jar', '.war',\n '.woff', '.woff2', '.ttf', '.otf', '.eot',\n '.mp3', '.mp4', '.avi', '.mov', '.webm', '.ogg', '.wav', '.flac',\n '.so', '.dll', '.dylib', '.exe', '.class', '.pyc', '.wasm', '.node',\n '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.odt', '.ods',\n '.db', '.sqlite', '.keystore', '.jks', '.p12', '.pfx',\n '.bin', '.dat'\n])\n\nconst isBinaryPath = (filePath: string): boolean =>\n BINARY_EXTENSIONS.has(path.extname(filePath).toLowerCase())\n\nconst toRepositoryPath = (baseDir: string, filePath: string): string =>\n path.relative(baseDir, filePath).split(path.sep).join('/')\n\nconst md5 = (filePath: string): string => {\n const hash = crypto.createHash('md5')\n hash.update(fs.readFileSync(filePath))\n return hash.digest('hex')\n}\n\nconst hasSameContent = (a: string, b: string): boolean => md5(a) === md5(b)\n\nconst readAsChange = (\n action: 'create' | 'update',\n baseDir: string,\n absolutePath: string\n): FileChange => {\n const binary = isBinaryPath(absolutePath)\n return {\n action,\n file_path: toRepositoryPath(baseDir, absolutePath),\n content: fs.readFileSync(absolutePath, binary ? 'base64' : 'utf-8'),\n encoding: binary ? 'base64' : 'text'\n }\n}\n\nconst JVM_BUILD_FILES = new Set(['build.gradle', 'build.gradle.kts', 'pom.xml'])\n\nconst isBuildOutput = (name: string, siblings: fs.Dirent[]): boolean =>\n name === '.gradle' || (name === 'bin' && siblings.some((sibling) => sibling.isFile() && JVM_BUILD_FILES.has(sibling.name)))\n\nconst listFiles = (dir: string): string[] => {\n const found: string[] = []\n const walk = (current: string, prefix: string): void => {\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(current, { withFileTypes: true })\n } catch {\n return\n }\n for (const entry of entries) {\n const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`\n if (entry.isDirectory()) {\n if (isBuildOutput(entry.name, entries)) continue\n walk(path.join(current, entry.name), relative)\n } else if (entry.isFile()) {\n found.push(relative)\n }\n }\n }\n walk(dir, '')\n return found.sort()\n}\n\nconst assertDir = (value: unknown, parameter: string): string => {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new InvalidArgumentError(`\"${parameter}\" must be a non-empty path.`)\n }\n return path.resolve(value)\n}\n\nexport const diffDirectories = ({\n oldDir,\n newDir\n}: {\n oldDir: string\n newDir: string\n}): FileChange[] => {\n const oldRoot = assertDir(oldDir, 'oldDir')\n const newRoot = assertDir(newDir, 'newDir')\n\n const oldFiles = new Set(listFiles(oldRoot))\n const newFiles = listFiles(newRoot)\n const changes: FileChange[] = []\n\n for (const relative of newFiles) {\n const newPath = path.join(newRoot, ...relative.split('/'))\n if (!oldFiles.has(relative)) {\n changes.push(readAsChange('create', newRoot, newPath))\n continue\n }\n const oldPath = path.join(oldRoot, ...relative.split('/'))\n if (!hasSameContent(oldPath, newPath)) {\n changes.push(readAsChange('update', newRoot, newPath))\n }\n }\n\n const newFileSet = new Set(newFiles)\n for (const relative of oldFiles) {\n if (newFileSet.has(relative)) continue\n if (NEVER_DELETED.has(path.posix.basename(relative))) continue\n changes.push({ action: 'delete', file_path: relative })\n }\n\n return changes.sort((a, b) => (a.file_path < b.file_path ? -1 : a.file_path > b.file_path ? 1 : 0))\n}\n"]}
@@ -1,19 +1,3 @@
1
- /**
2
- * Formats every file prettier understands under a directory, in place.
3
- *
4
- * Files with no inferable parser are skipped, which is what `--ignore-unknown`
5
- * does. Files that prettier cannot parse (a syntax error in generated code, say)
6
- * are skipped too rather than aborting the whole run: formatting is cosmetic and
7
- * must never fail a generation.
8
- *
9
- * Idempotent by construction, since prettier output is a fixed point. A file is
10
- * only rewritten when its content actually changes, so mtimes stay put and the
11
- * directory diff does not gain spurious entries.
12
- *
13
- * @param params.dir Directory to format, in place.
14
- * @returns How many files were rewritten.
15
- * @throws {InvalidArgumentError} when `dir` is not a non-empty existing directory.
16
- */
17
1
  export declare const formatDirectory: ({ dir }: {
18
2
  dir: string;
19
3
  }) => Promise<{