@lbdudc/linea-core 0.1.1 → 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 (249) hide show
  1. package/README.md +132 -260
  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/transformation.js +17 -5
  81. package/dist/line/templates/pipeline/github-ci.yml +50 -0
  82. package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
  83. package/dist/modules/configuration/configure.d.ts +52 -0
  84. package/dist/modules/configuration/configure.js +101 -0
  85. package/dist/modules/configuration/configure.js.map +1 -0
  86. package/dist/modules/configuration/constants.d.ts +17 -0
  87. package/dist/modules/configuration/constants.js +14 -0
  88. package/dist/modules/configuration/constants.js.map +1 -0
  89. package/dist/modules/configuration/index.d.ts +6 -0
  90. package/dist/modules/configuration/index.js +5 -0
  91. package/dist/modules/configuration/index.js.map +1 -0
  92. package/dist/modules/configuration/names.d.ts +9 -0
  93. package/dist/modules/configuration/names.js +7 -0
  94. package/dist/modules/configuration/names.js.map +1 -0
  95. package/dist/modules/configuration/selection.d.ts +32 -0
  96. package/dist/modules/configuration/selection.js +49 -0
  97. package/dist/modules/configuration/selection.js.map +1 -0
  98. package/dist/modules/diagnostics.d.ts +2 -0
  99. package/dist/modules/diagnostics.js +2 -0
  100. package/dist/modules/diagnostics.js.map +1 -0
  101. package/dist/modules/index.d.ts +18 -0
  102. package/dist/modules/index.js +18 -0
  103. package/dist/modules/index.js.map +1 -0
  104. package/dist/modules/metamodels/engine.d.ts +93 -0
  105. package/dist/modules/metamodels/engine.js +10 -0
  106. package/dist/modules/metamodels/engine.js.map +1 -0
  107. package/dist/modules/metamodels/files.d.ts +40 -0
  108. package/dist/modules/metamodels/files.js +58 -0
  109. package/dist/modules/metamodels/files.js.map +1 -0
  110. package/dist/modules/metamodels/index.d.ts +8 -0
  111. package/dist/modules/metamodels/index.js +5 -0
  112. package/dist/modules/metamodels/index.js.map +1 -0
  113. package/dist/modules/metamodels/layout.d.ts +23 -0
  114. package/dist/modules/metamodels/layout.js +29 -0
  115. package/dist/modules/metamodels/layout.js.map +1 -0
  116. package/dist/modules/metamodels/offered.d.ts +15 -0
  117. package/dist/modules/metamodels/offered.js +14 -0
  118. package/dist/modules/metamodels/offered.js.map +1 -0
  119. package/dist/modules/metamodels/prepare.d.ts +20 -0
  120. package/dist/modules/metamodels/prepare.js +155 -0
  121. package/dist/modules/metamodels/prepare.js.map +1 -0
  122. package/dist/modules/packages/index.d.ts +4 -0
  123. package/dist/modules/packages/index.js +4 -0
  124. package/dist/modules/packages/index.js.map +1 -0
  125. package/dist/modules/packages/location.d.ts +21 -0
  126. package/dist/modules/packages/location.js +34 -0
  127. package/dist/modules/packages/location.js.map +1 -0
  128. package/dist/modules/packages/manifests.d.ts +33 -0
  129. package/dist/modules/packages/manifests.js +231 -0
  130. package/dist/modules/packages/manifests.js.map +1 -0
  131. package/dist/modules/packages/source.d.ts +34 -0
  132. package/dist/modules/packages/source.js +128 -0
  133. package/dist/modules/packages/source.js.map +1 -0
  134. package/dist/modules/products/check.d.ts +28 -0
  135. package/dist/modules/products/check.js +61 -0
  136. package/dist/modules/products/check.js.map +1 -0
  137. package/dist/modules/products/derive.d.ts +30 -0
  138. package/dist/modules/products/derive.js +56 -0
  139. package/dist/modules/products/derive.js.map +1 -0
  140. package/dist/modules/products/index.d.ts +5 -0
  141. package/dist/modules/products/index.js +4 -0
  142. package/dist/modules/products/index.js.map +1 -0
  143. package/dist/modules/products/seed.d.ts +18 -0
  144. package/dist/modules/products/seed.js +23 -0
  145. package/dist/modules/products/seed.js.map +1 -0
  146. package/dist/modules/registry/catalog.d.ts +64 -0
  147. package/dist/modules/registry/catalog.js +91 -0
  148. package/dist/modules/registry/catalog.js.map +1 -0
  149. package/dist/modules/registry/index.d.ts +5 -0
  150. package/dist/modules/registry/index.js +4 -0
  151. package/dist/modules/registry/index.js.map +1 -0
  152. package/dist/modules/registry/registry.d.ts +34 -0
  153. package/dist/modules/registry/registry.js +37 -0
  154. package/dist/modules/registry/registry.js.map +1 -0
  155. package/dist/modules/registry/routing.d.ts +8 -0
  156. package/dist/modules/registry/routing.js +23 -0
  157. package/dist/modules/registry/routing.js.map +1 -0
  158. package/dist/modules/resolution/closure.d.ts +28 -0
  159. package/dist/modules/resolution/closure.js +105 -0
  160. package/dist/modules/resolution/closure.js.map +1 -0
  161. package/dist/modules/resolution/index.d.ts +4 -0
  162. package/dist/modules/resolution/index.js +3 -0
  163. package/dist/modules/resolution/index.js.map +1 -0
  164. package/dist/modules/resolution/resolve.d.ts +33 -0
  165. package/dist/modules/resolution/resolve.js +59 -0
  166. package/dist/modules/resolution/resolve.js.map +1 -0
  167. package/dist/modules/resolution/resolvers.d.ts +23 -0
  168. package/dist/modules/resolution/resolvers.js +34 -0
  169. package/dist/modules/resolution/resolvers.js.map +1 -0
  170. package/dist/modules/spl/check.d.ts +25 -0
  171. package/dist/modules/spl/check.js +21 -0
  172. package/dist/modules/spl/check.js.map +1 -0
  173. package/dist/modules/spl/cip.d.ts +67 -0
  174. package/dist/modules/spl/cip.js +98 -0
  175. package/dist/modules/spl/cip.js.map +1 -0
  176. package/dist/modules/spl/feature-model.d.ts +39 -0
  177. package/dist/modules/spl/feature-model.js +106 -0
  178. package/dist/modules/spl/feature-model.js.map +1 -0
  179. package/dist/modules/spl/index.d.ts +6 -0
  180. package/dist/modules/spl/index.js +4 -0
  181. package/dist/modules/spl/index.js.map +1 -0
  182. package/dist/modules/spl/platform.d.ts +49 -0
  183. package/dist/modules/spl/platform.js +316 -0
  184. package/dist/modules/spl/platform.js.map +1 -0
  185. package/dist/modules/types.d.ts +132 -0
  186. package/dist/modules/types.js +2 -0
  187. package/dist/modules/types.js.map +1 -0
  188. package/dist/product/engine-spec.d.ts +0 -16
  189. package/dist/product/engine-spec.js +4 -50
  190. package/dist/product/engine-spec.js.map +1 -1
  191. package/dist/product/spec.d.ts +0 -82
  192. package/dist/product/spec.js +0 -79
  193. package/dist/product/spec.js.map +1 -1
  194. package/dist/product/version.d.ts +0 -23
  195. package/dist/product/version.js +0 -28
  196. package/dist/product/version.js.map +1 -1
  197. package/dist/products-index/products-index.d.ts +0 -165
  198. package/dist/products-index/products-index.js +0 -176
  199. package/dist/products-index/products-index.js.map +1 -1
  200. package/dist/workspace/context.d.ts +25 -0
  201. package/dist/workspace/context.js +43 -0
  202. package/dist/workspace/context.js.map +1 -0
  203. package/dist/workspace/gitExclude.d.ts +2 -0
  204. package/dist/workspace/gitExclude.js +19 -0
  205. package/dist/workspace/gitExclude.js.map +1 -0
  206. package/dist/workspace/host.d.ts +14 -0
  207. package/dist/workspace/host.js +13 -0
  208. package/dist/workspace/host.js.map +1 -0
  209. package/dist/workspace/index.d.ts +12 -0
  210. package/dist/workspace/index.js +12 -0
  211. package/dist/workspace/index.js.map +1 -0
  212. package/dist/workspace/local.d.ts +81 -0
  213. package/dist/workspace/local.js +287 -0
  214. package/dist/workspace/local.js.map +1 -0
  215. package/dist/workspace/modular.d.ts +95 -0
  216. package/dist/workspace/modular.js +301 -0
  217. package/dist/workspace/modular.js.map +1 -0
  218. package/dist/workspace/operations.d.ts +35 -0
  219. package/dist/workspace/operations.js +57 -0
  220. package/dist/workspace/operations.js.map +1 -0
  221. package/dist/workspace/origin.d.ts +20 -0
  222. package/dist/workspace/origin.js +19 -0
  223. package/dist/workspace/origin.js.map +1 -0
  224. package/package.json +22 -7
  225. package/dist/feature-model/convert.d.ts +0 -35
  226. package/dist/feature-model/convert.js +0 -47
  227. package/dist/feature-model/convert.js.map +0 -1
  228. package/dist/feature-model/engine.d.ts +0 -60
  229. package/dist/feature-model/engine.js +0 -139
  230. package/dist/feature-model/engine.js.map +0 -1
  231. package/dist/feature-model/inspect.d.ts +0 -67
  232. package/dist/feature-model/inspect.js +0 -113
  233. package/dist/feature-model/inspect.js.map +0 -1
  234. package/dist/feature-model/io.d.ts +0 -66
  235. package/dist/feature-model/io.js +0 -92
  236. package/dist/feature-model/io.js.map +0 -1
  237. package/dist/feature-model/parse.d.ts +0 -30
  238. package/dist/feature-model/parse.js +0 -36
  239. package/dist/feature-model/parse.js.map +0 -1
  240. package/dist/feature-model/text.d.ts +0 -54
  241. package/dist/feature-model/text.js +0 -126
  242. package/dist/feature-model/text.js.map +0 -1
  243. package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
  244. package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
  245. package/dist/line/templates/metamodels/sensor/extra.js +0 -36
  246. package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
  247. package/dist/selection/selection.d.ts +0 -126
  248. package/dist/selection/selection.js +0 -152
  249. package/dist/selection/selection.js.map +0 -1
@@ -0,0 +1,155 @@
1
+ import { absoluteRequires } from '../packages/location.js';
2
+ import { readPackageText } from '../packages/source.js';
3
+ import { toDiagnostics } from './engine.js';
4
+ import { readMetamodelFiles } from './files.js';
5
+ import { metamodelPath } from './layout.js';
6
+ const loadMetamodelPackage = async ({ engine, pkg, providers, levels, diagnostics }) => {
7
+ const files = await readMetamodelFiles({ pkg });
8
+ if (!files.some(({ grammar }) => grammar === pkg.manifest.name)) {
9
+ diagnostics.push({
10
+ severity: 'error',
11
+ package: pkg.location,
12
+ message: `The metamodel "${pkg.manifest.name}" has no ${metamodelPath({ kind: 'grammar', grammar: pkg.manifest.name })}.`
13
+ });
14
+ }
15
+ for (const { grammar, file, text, level, scripts } of files) {
16
+ const other = providers.get(grammar);
17
+ if (other !== undefined) {
18
+ diagnostics.push({ severity: 'error', package: pkg.location, file, message: `The grammar "${grammar}" is also provided by ${other}.` });
19
+ continue;
20
+ }
21
+ providers.set(grammar, pkg.location);
22
+ levels.set(grammar, level);
23
+ await engine.setGrammar(grammar, text);
24
+ if (scripts.constraints !== undefined)
25
+ await engine.setConstraints(grammar, scripts.constraints);
26
+ if (scripts.spec !== undefined)
27
+ await engine.setSpec(grammar, scripts.spec);
28
+ if (scripts.import !== undefined)
29
+ await engine.setImport(grammar, scripts.import);
30
+ if (scripts.scope !== undefined)
31
+ await engine.setScope(grammar, scripts.scope);
32
+ }
33
+ };
34
+ /** The metamodels (grammars with an entry rule) that the packages in `closure` provide. */
35
+ const grammarsOf = (closure, providers, infos) => new Set(infos.filter((info) => info.extension !== undefined && closure.has(providers.get(info.name) ?? '')).map((info) => info.name));
36
+ /** The packages a module needs, as locations: the metamodels it requires directly and everything those require. */
37
+ const metamodelClosure = (module, metamodels) => {
38
+ const byLocation = new Map(metamodels.map((pkg) => [pkg.location, pkg]));
39
+ const closure = new Set();
40
+ const add = (location) => {
41
+ if (closure.has(location))
42
+ return;
43
+ closure.add(location);
44
+ const pkg = byLocation.get(location);
45
+ if (pkg !== undefined)
46
+ for (const other of Object.keys(absoluteRequires({ kind: 'metamodel', location, manifest: pkg.manifest }).metamodels))
47
+ add(other);
48
+ };
49
+ for (const location of Object.keys(absoluteRequires({ kind: 'module', location: module.location, manifest: module.manifest }).metamodels))
50
+ add(location);
51
+ return closure;
52
+ };
53
+ /**
54
+ * Loads the metamodels of an SPL into a fresh engine and composes them, then gives it the models the modules offer (read-only).
55
+ * What is wrong with any of it is returned as diagnostics.
56
+ */
57
+ export const prepareEngine = async ({ resolved, createEngine }) => {
58
+ const engine = createEngine();
59
+ const diagnostics = [];
60
+ const providers = new Map();
61
+ const levels = new Map();
62
+ for (const pkg of resolved.metamodels)
63
+ await loadMetamodelPackage({ engine, pkg, providers, levels, diagnostics });
64
+ const infos = await engine.listMetamodels();
65
+ const packageOf = new Map(resolved.metamodels.map((pkg) => [pkg.location, pkg]));
66
+ for (const info of infos) {
67
+ const owner = providers.get(info.name) ?? '';
68
+ diagnostics.push(...toDiagnostics(info.problems, { package: owner, file: metamodelPath({ kind: 'grammar', grammar: info.name }) }));
69
+ const ownerPackage = packageOf.get(owner);
70
+ const declared = ownerPackage === undefined ? [] : Object.keys(absoluteRequires({ kind: 'metamodel', location: owner, manifest: ownerPackage.manifest }).metamodels);
71
+ for (const imported of info.imports) {
72
+ const from = providers.get(imported);
73
+ if (from !== undefined && from !== owner && !declared.includes(from)) {
74
+ diagnostics.push({
75
+ severity: 'error',
76
+ package: owner,
77
+ file: metamodelPath({ kind: 'grammar', grammar: info.name }),
78
+ message: `It imports "${imported}", which ${from} provides, but ${from} is not in its "requires".`
79
+ });
80
+ }
81
+ }
82
+ }
83
+ const entries = infos.filter((info) => info.extension !== undefined);
84
+ const composition = await engine.compose(entries.map((info) => info.name));
85
+ // what only composing shows: the scripts of a metamodel (constraints, JSON mappings...) are compiled with it
86
+ const seen = new Set(diagnostics.map(({ package: from, file, message }) => `${from}|${file ?? ''}|${message}`));
87
+ for (const info of composition.grammars) {
88
+ const owner = providers.get(info.name) ?? '';
89
+ for (const diagnostic of toDiagnostics(info.problems, { package: owner, file: metamodelPath({ kind: 'grammar', grammar: info.name }) })) {
90
+ const key = `${diagnostic.package}|${diagnostic.file ?? ''}|${diagnostic.message}`;
91
+ if (!seen.has(key)) {
92
+ seen.add(key);
93
+ diagnostics.push(diagnostic);
94
+ }
95
+ }
96
+ }
97
+ for (const problem of composition.problems)
98
+ diagnostics.push({ severity: 'error', package: 'spl', message: problem.message });
99
+ for (const rename of composition.renames) {
100
+ diagnostics.push({
101
+ severity: 'warning',
102
+ package: providers.get(rename.file) ?? 'spl',
103
+ file: metamodelPath({ kind: 'grammar', grammar: rename.file }),
104
+ message: `The type "${rename.original}" clashes with the one of ${rename.keeper}: it is called "${rename.renamed}" when they are used together.`
105
+ });
106
+ }
107
+ // what each module offers
108
+ const items = [];
109
+ const where_ = new Map();
110
+ const origins = new Map();
111
+ for (const module of resolved.modules) {
112
+ const origin = module.manifest.name;
113
+ const earlier = origins.get(origin);
114
+ if (earlier !== undefined) {
115
+ diagnostics.push({ severity: 'error', package: module.location, message: `The module name "${origin}" is also used by ${earlier}.` });
116
+ continue;
117
+ }
118
+ origins.set(origin, module.location);
119
+ const allowed = grammarsOf(metamodelClosure(module, resolved.metamodels), providers, infos);
120
+ for (const [metamodel, file] of Object.entries(module.manifest.offers)) {
121
+ if (!allowed.has(metamodel)) {
122
+ diagnostics.push({
123
+ severity: 'error',
124
+ package: module.location,
125
+ file: '.linea/module.json',
126
+ message: `It offers a model of "${metamodel}", but none of the metamodels it requires provides it.`
127
+ });
128
+ continue;
129
+ }
130
+ const text = await readPackageText({ files: module.files, path: file });
131
+ if (text === undefined) {
132
+ diagnostics.push({ severity: 'error', package: module.location, file, message: `The offered model ${file} does not exist.` });
133
+ continue;
134
+ }
135
+ items.push({ origin, metamodel, text });
136
+ where_.set(`${origin}/${metamodel}`, { location: module.location, file });
137
+ }
138
+ }
139
+ if (items.length > 0) {
140
+ for (const state of await engine.setContributed(items)) {
141
+ const source = where_.get(`${state.origin}/${state.metamodel}`);
142
+ diagnostics.push(...toDiagnostics(state.problems, { package: source?.location ?? state.origin, ...(source === undefined ? {} : { file: source.file }) }));
143
+ }
144
+ }
145
+ const metamodels = entries.map((info) => ({
146
+ name: info.name,
147
+ extension: info.extension,
148
+ level: levels.get(info.name) ?? 0,
149
+ ...(info.description === undefined ? {} : { description: info.description }),
150
+ requires: info.requires,
151
+ package: providers.get(info.name) ?? ''
152
+ }));
153
+ return { engine, metamodels, diagnostics, contributed: items };
154
+ };
155
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../../src/modules/metamodels/prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAoE,MAAM,aAAa,CAAA;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAClC,MAAM,EACN,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EAOZ,EAAiB,EAAE;IAClB,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IAC/C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,KAAK,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAChE,WAAW,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,GAAG,CAAC,QAAQ;YACrB,OAAO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CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAC3J,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,SAAS,EAAE,IAAI,CAAC,SAAU;QAC1B,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5E,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;KACxC,CAAC,CAAC,CAAA;IACH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;AAChE,CAAC,CAAA","sourcesContent":["import { absoluteRequires } from '../packages/location.js'\nimport { readPackageText } from '../packages/source.js'\nimport type { Diagnostic, ResolvedMetamodel, ResolvedSpl, ResolvedModule } from '../types.js'\nimport { toDiagnostics, type EngineGrammarInfo, type MetamodelEngine, type MetamodelInfo } from './engine.js'\nimport { readMetamodelFiles } from './files.js'\nimport { metamodelPath } from './layout.js'\n\nconst loadMetamodelPackage = async ({\n engine,\n pkg,\n providers,\n levels,\n diagnostics\n}: {\n engine: MetamodelEngine\n pkg: ResolvedMetamodel\n providers: Map<string, string>\n levels: Map<string, number>\n diagnostics: Diagnostic[]\n}): Promise<void> => {\n const files = await readMetamodelFiles({ pkg })\n if (!files.some(({ grammar }) => grammar === pkg.manifest.name)) {\n diagnostics.push({\n severity: 'error',\n package: pkg.location,\n message: `The metamodel \"${pkg.manifest.name}\" has no ${metamodelPath({ kind: 'grammar', grammar: pkg.manifest.name })}.`\n })\n }\n for (const { grammar, file, text, level, scripts } of files) {\n const other = providers.get(grammar)\n if (other !== undefined) {\n diagnostics.push({ severity: 'error', package: pkg.location, file, message: `The grammar \"${grammar}\" is also provided by ${other}.` })\n continue\n }\n providers.set(grammar, pkg.location)\n levels.set(grammar, level)\n await engine.setGrammar(grammar, text)\n if (scripts.constraints !== undefined) await engine.setConstraints(grammar, scripts.constraints)\n if (scripts.spec !== undefined) await engine.setSpec(grammar, scripts.spec)\n if (scripts.import !== undefined) await engine.setImport(grammar, scripts.import)\n if (scripts.scope !== undefined) await engine.setScope(grammar, scripts.scope)\n }\n}\n\n/** The metamodels (grammars with an entry rule) that the packages in `closure` provide. */\nconst grammarsOf = (closure: ReadonlySet<string>, providers: ReadonlyMap<string, string>, infos: readonly EngineGrammarInfo[]): Set<string> =>\n new Set(infos.filter((info) => info.extension !== undefined && closure.has(providers.get(info.name) ?? '')).map((info) => info.name))\n\n/** The packages a module needs, as locations: the metamodels it requires directly and everything those require. */\nconst metamodelClosure = (module: ResolvedModule, metamodels: readonly ResolvedMetamodel[]): Set<string> => {\n const byLocation = new Map(metamodels.map((pkg) => [pkg.location, pkg]))\n const closure = new Set<string>()\n const add = (location: string): void => {\n if (closure.has(location)) return\n closure.add(location)\n const pkg = byLocation.get(location)\n if (pkg !== undefined) for (const other of Object.keys(absoluteRequires({ kind: 'metamodel', location, manifest: pkg.manifest }).metamodels)) add(other)\n }\n for (const location of Object.keys(absoluteRequires({ kind: 'module', location: module.location, manifest: module.manifest }).metamodels)) add(location)\n return closure\n}\n\n/**\n * Loads the metamodels of an SPL into a fresh engine and composes them, then gives it the models the modules offer (read-only).\n * What is wrong with any of it is returned as diagnostics.\n */\nexport const prepareEngine = async ({\n resolved,\n createEngine\n}: {\n resolved: ResolvedSpl\n createEngine: () => MetamodelEngine\n}): Promise<{\n engine: MetamodelEngine\n metamodels: MetamodelInfo[]\n diagnostics: Diagnostic[]\n /** What the engine was given to offer, read-only: the models of the modules. The models of the SPL's levels are added to these. */\n contributed: { origin: string, metamodel: string, text: string }[]\n}> => {\n const engine = createEngine()\n const diagnostics: Diagnostic[] = []\n const providers = new Map<string, string>()\n const levels = new Map<string, number>()\n for (const pkg of resolved.metamodels) await loadMetamodelPackage({ engine, pkg, providers, levels, diagnostics })\n\n const infos = await engine.listMetamodels()\n const packageOf = new Map(resolved.metamodels.map((pkg) => [pkg.location, pkg]))\n for (const info of infos) {\n const owner = providers.get(info.name) ?? ''\n diagnostics.push(...toDiagnostics(info.problems, { package: owner, file: metamodelPath({ kind: 'grammar', grammar: info.name }) }))\n const ownerPackage = packageOf.get(owner)\n const declared = ownerPackage === undefined ? [] : Object.keys(absoluteRequires({ kind: 'metamodel', location: owner, manifest: ownerPackage.manifest }).metamodels)\n for (const imported of info.imports) {\n const from = providers.get(imported)\n if (from !== undefined && from !== owner && !declared.includes(from)) {\n diagnostics.push({\n severity: 'error',\n package: owner,\n file: metamodelPath({ kind: 'grammar', grammar: info.name }),\n message: `It imports \"${imported}\", which ${from} provides, but ${from} is not in its \"requires\".`\n })\n }\n }\n }\n\n const entries = infos.filter((info) => info.extension !== undefined)\n const composition = await engine.compose(entries.map((info) => info.name))\n // what only composing shows: the scripts of a metamodel (constraints, JSON mappings...) are compiled with it\n const seen = new Set(diagnostics.map(({ package: from, file, message }) => `${from}|${file ?? ''}|${message}`))\n for (const info of composition.grammars) {\n const owner = providers.get(info.name) ?? ''\n for (const diagnostic of toDiagnostics(info.problems, { package: owner, file: metamodelPath({ kind: 'grammar', grammar: info.name }) })) {\n const key = `${diagnostic.package}|${diagnostic.file ?? ''}|${diagnostic.message}`\n if (!seen.has(key)) {\n seen.add(key)\n diagnostics.push(diagnostic)\n }\n }\n }\n for (const problem of composition.problems) diagnostics.push({ severity: 'error', package: 'spl', message: problem.message })\n for (const rename of composition.renames) {\n diagnostics.push({\n severity: 'warning',\n package: providers.get(rename.file) ?? 'spl',\n file: metamodelPath({ kind: 'grammar', grammar: rename.file }),\n message: `The type \"${rename.original}\" clashes with the one of ${rename.keeper}: it is called \"${rename.renamed}\" when they are used together.`\n })\n }\n\n // what each module offers\n const items: { origin: string, metamodel: string, text: string }[] = []\n const where_ = new Map<string, { location: string, file: string }>()\n const origins = new Map<string, string>()\n for (const module of resolved.modules) {\n const origin = module.manifest.name\n const earlier = origins.get(origin)\n if (earlier !== undefined) {\n diagnostics.push({ severity: 'error', package: module.location, message: `The module name \"${origin}\" is also used by ${earlier}.` })\n continue\n }\n origins.set(origin, module.location)\n const allowed = grammarsOf(metamodelClosure(module, resolved.metamodels), providers, infos)\n for (const [metamodel, file] of Object.entries(module.manifest.offers)) {\n if (!allowed.has(metamodel)) {\n diagnostics.push({\n severity: 'error',\n package: module.location,\n file: '.linea/module.json',\n message: `It offers a model of \"${metamodel}\", but none of the metamodels it requires provides it.`\n })\n continue\n }\n const text = await readPackageText({ files: module.files, path: file })\n if (text === undefined) {\n diagnostics.push({ severity: 'error', package: module.location, file, message: `The offered model ${file} does not exist.` })\n continue\n }\n items.push({ origin, metamodel, text })\n where_.set(`${origin}/${metamodel}`, { location: module.location, file })\n }\n }\n if (items.length > 0) {\n for (const state of await engine.setContributed(items)) {\n const source = where_.get(`${state.origin}/${state.metamodel}`)\n diagnostics.push(...toDiagnostics(state.problems, { package: source?.location ?? state.origin, ...(source === undefined ? {} : { file: source.file }) }))\n }\n }\n\n const metamodels = entries.map((info) => ({\n name: info.name,\n extension: info.extension!,\n level: levels.get(info.name) ?? 0,\n ...(info.description === undefined ? {} : { description: info.description }),\n requires: info.requires,\n package: providers.get(info.name) ?? ''\n }))\n return { engine, metamodels, diagnostics, contributed: items }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH, SPL_MANIFEST_PATH, LOCK_PATH, REGISTRY_INDEX_PATH, parseMetamodelManifest, parseModuleManifest, parseSplManifest, serializeSplManifest, parseLock, serializeLock, emptyRegistryIndex, parseRegistryIndex, serializeRegistryIndex } from './manifests.js';
2
+ export { readPackageText, createFsFiles, createFsPackageSource, createMemoryPackageSource, withOverlay } from './source.js';
3
+ export type { MemoryPackages } from './source.js';
4
+ export { resolveReference, absoluteRequires } from './location.js';
@@ -0,0 +1,4 @@
1
+ export { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH, SPL_MANIFEST_PATH, LOCK_PATH, REGISTRY_INDEX_PATH, parseMetamodelManifest, parseModuleManifest, parseSplManifest, serializeSplManifest, parseLock, serializeLock, emptyRegistryIndex, parseRegistryIndex, serializeRegistryIndex } from './manifests.js';
2
+ export { readPackageText, createFsFiles, createFsPackageSource, createMemoryPackageSource, withOverlay } from './source.js';
3
+ export { resolveReference, absoluteRequires } from './location.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/packages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE3H,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA","sourcesContent":["export {\n METAMODEL_MANIFEST_PATH,\n MODULE_MANIFEST_PATH,\n SPL_MANIFEST_PATH,\n LOCK_PATH,\n REGISTRY_INDEX_PATH,\n parseMetamodelManifest,\n parseModuleManifest,\n parseSplManifest,\n serializeSplManifest,\n parseLock,\n serializeLock,\n emptyRegistryIndex,\n parseRegistryIndex,\n serializeRegistryIndex\n} from './manifests.js'\nexport { readPackageText, createFsFiles, createFsPackageSource, createMemoryPackageSource, withOverlay } from './source.js'\nexport type { MemoryPackages } from './source.js'\nexport { resolveReference, absoluteRequires } from './location.js'\n"]}
@@ -0,0 +1,21 @@
1
+ import type { MetamodelManifest, ModuleManifest, PackageKind } from '../types.js';
2
+ /**
3
+ * What a manifest says another package is, as the location it denotes.
4
+ *
5
+ * An absolute location (`gitlab:group/project`, `file:modules/core`) stands for itself. A reference that starts with `../` (or `./`) is
6
+ * relative to the package that makes it, taken as a folder: `../common` in `gitlab:registry/basic` is `gitlab:registry/common`. That is
7
+ * what lets a set of packages that need each other be published in any group (or kept in any folder) without editing their manifests.
8
+ */
9
+ export declare const resolveReference: ({ from, reference }: {
10
+ from: string;
11
+ reference: string;
12
+ }) => string;
13
+ /** The packages a package requires, each as an absolute location with the range that is asked for. */
14
+ export declare const absoluteRequires: ({ kind, location, manifest }: {
15
+ kind: PackageKind;
16
+ location: string;
17
+ manifest: ModuleManifest | MetamodelManifest;
18
+ }) => {
19
+ modules: Record<string, string>;
20
+ metamodels: Record<string, string>;
21
+ };
@@ -0,0 +1,34 @@
1
+ import path from 'node:path';
2
+ import { ModuleManifestError } from '../../errors.js';
3
+ const SCHEME = /^([a-z][a-z0-9+.-]*):(.*)$/i;
4
+ /**
5
+ * What a manifest says another package is, as the location it denotes.
6
+ *
7
+ * An absolute location (`gitlab:group/project`, `file:modules/core`) stands for itself. A reference that starts with `../` (or `./`) is
8
+ * relative to the package that makes it, taken as a folder: `../common` in `gitlab:registry/basic` is `gitlab:registry/common`. That is
9
+ * what lets a set of packages that need each other be published in any group (or kept in any folder) without editing their manifests.
10
+ */
11
+ export const resolveReference = ({ from, reference }) => {
12
+ if (!reference.startsWith('./') && !reference.startsWith('../'))
13
+ return reference;
14
+ const match = SCHEME.exec(from);
15
+ if (match === null) {
16
+ throw new ModuleManifestError(`"${from}" is not a location, so "${reference}" cannot be relative to it.`);
17
+ }
18
+ const [, scheme, base] = match;
19
+ const resolved = path.posix.join(base, reference).replace(/\/+$/, '');
20
+ if (resolved.startsWith('..') || resolved === '.' || resolved === '') {
21
+ throw new ModuleManifestError(`"${reference}" in ${from} points outside the place its packages live.`);
22
+ }
23
+ return `${scheme}:${resolved}`;
24
+ };
25
+ /** The packages a package requires, each as an absolute location with the range that is asked for. */
26
+ export const absoluteRequires = ({ kind, location, manifest }) => {
27
+ const absolute = (record) => Object.fromEntries(Object.entries(record).map(([reference, range]) => [resolveReference({ from: location, reference }), range]));
28
+ if (kind === 'module') {
29
+ const { requires } = manifest;
30
+ return { modules: absolute(requires.modules), metamodels: absolute(requires.metamodels) };
31
+ }
32
+ return { modules: {}, metamodels: absolute(manifest.requires) };
33
+ };
34
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.js","sourceRoot":"","sources":["../../../src/modules/packages/location.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAGrD,MAAM,MAAM,GAAG,6BAA6B,CAAA;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAuC,EAAU,EAAE;IACnG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACjF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,mBAAmB,CAAC,IAAI,IAAI,4BAA4B,SAAS,6BAA6B,CAAC,CAAA;IAC3G,CAAC;IACD,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GA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ifestError } from '../../errors.js'\nimport type { MetamodelManifest, ModuleManifest, PackageKind } from '../types.js'\n\nconst SCHEME = /^([a-z][a-z0-9+.-]*):(.*)$/i\n\n/**\n * What a manifest says another package is, as the location it denotes.\n *\n * An absolute location (`gitlab:group/project`, `file:modules/core`) stands for itself. A reference that starts with `../` (or `./`) is\n * relative to the package that makes it, taken as a folder: `../common` in `gitlab:registry/basic` is `gitlab:registry/common`. That is\n * what lets a set of packages that need each other be published in any group (or kept in any folder) without editing their manifests.\n */\nexport const resolveReference = ({ from, reference }: { from: string, reference: string }): string => {\n if (!reference.startsWith('./') && !reference.startsWith('../')) return reference\n const match = SCHEME.exec(from)\n if (match === null) {\n throw new ModuleManifestError(`\"${from}\" is not a location, so \"${reference}\" cannot be relative to it.`)\n }\n const [, scheme, base] = match as unknown as [string, string, string]\n const resolved = path.posix.join(base, reference).replace(/\\/+$/, '')\n if (resolved.startsWith('..') || resolved === '.' || resolved === '') {\n throw new ModuleManifestError(`\"${reference}\" in ${from} points outside the place its packages live.`)\n }\n return `${scheme}:${resolved}`\n}\n\n/** The packages a package requires, each as an absolute location with the range that is asked for. */\nexport const absoluteRequires = ({\n kind,\n location,\n manifest\n}: {\n kind: PackageKind\n location: string\n manifest: ModuleManifest | MetamodelManifest\n}): { modules: Record<string, string>, metamodels: Record<string, string> } => {\n const absolute = (record: Readonly<Record<string, string>>): Record<string, string> =>\n Object.fromEntries(Object.entries(record).map(([reference, range]) => [resolveReference({ from: location, reference }), range]))\n if (kind === 'module') {\n const { requires } = manifest as ModuleManifest\n return { modules: absolute(requires.modules), metamodels: absolute(requires.metamodels) }\n }\n return { modules: {}, metamodels: absolute((manifest as MetamodelManifest).requires) }\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import type { Lock, MetamodelManifest, ModuleManifest, RegistryIndex, SplManifest } from '../types.js';
2
+ export declare const METAMODEL_MANIFEST_PATH = "metamodel.json";
3
+ export declare const MODULE_MANIFEST_PATH = ".linea/module.json";
4
+ export declare const SPL_MANIFEST_PATH = "spl.json";
5
+ export declare const LOCK_PATH = "linea.lock.json";
6
+ export declare const REGISTRY_INDEX_PATH = "registry.json";
7
+ export declare const parseMetamodelManifest: ({ content }: {
8
+ content: string;
9
+ }) => MetamodelManifest;
10
+ export declare const parseModuleManifest: ({ content }: {
11
+ content: string;
12
+ }) => ModuleManifest;
13
+ export declare const parseSplManifest: ({ content }: {
14
+ content: string;
15
+ }) => SplManifest;
16
+ export declare const serializeSplManifest: ({ spl }: {
17
+ spl: SplManifest;
18
+ }) => string;
19
+ export declare const parseLock: ({ content }: {
20
+ content: string;
21
+ }) => Lock;
22
+ /** Sorted, so two resolutions of the same closure give the same bytes (and the same git diff). */
23
+ export declare const serializeLock: ({ lock }: {
24
+ lock: Lock;
25
+ }) => string;
26
+ export declare const emptyRegistryIndex: () => RegistryIndex;
27
+ export declare const parseRegistryIndex: ({ content }: {
28
+ content: string;
29
+ }) => RegistryIndex;
30
+ /** Sorted by location, so the same catalog always gives the same bytes (and a small git diff). */
31
+ export declare const serializeRegistryIndex: ({ index }: {
32
+ index: RegistryIndex;
33
+ }) => string;
@@ -0,0 +1,231 @@
1
+ import semver from 'semver';
2
+ import { NAME_PATTERN, VERSION_PATTERN } from '../../constants.js';
3
+ import { ModuleManifestError } from '../../errors.js';
4
+ import { isPlainObject } from '../../internal/guards.js';
5
+ export const METAMODEL_MANIFEST_PATH = 'metamodel.json';
6
+ export const MODULE_MANIFEST_PATH = '.linea/module.json';
7
+ export const SPL_MANIFEST_PATH = 'spl.json';
8
+ export const LOCK_PATH = 'linea.lock.json';
9
+ export const REGISTRY_INDEX_PATH = 'registry.json';
10
+ const LOCATION_PATTERN = /^[^\s]+$/;
11
+ const parseJson = (content, label) => {
12
+ let value;
13
+ try {
14
+ value = JSON.parse(content);
15
+ }
16
+ catch (error) {
17
+ throw new ModuleManifestError(`${label} is not valid JSON: ${error.message}`, { cause: error });
18
+ }
19
+ if (!isPlainObject(value))
20
+ throw new ModuleManifestError(`${label} must be a JSON object.`);
21
+ return value;
22
+ };
23
+ const fail = (label, problems) => {
24
+ throw new ModuleManifestError(`${label} is not valid:\n- ${problems.join('\n- ')}`);
25
+ };
26
+ const readName = (raw, problems) => {
27
+ const { name } = raw;
28
+ if (typeof name !== 'string' || !NAME_PATTERN.test(name)) {
29
+ problems.push('"name" must be a string of letters, digits, "_", "-" or "."');
30
+ return '';
31
+ }
32
+ return name;
33
+ };
34
+ const readVersion = (raw, problems) => {
35
+ const { version } = raw;
36
+ if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {
37
+ problems.push('"version" must look like 1.2.3');
38
+ return '';
39
+ }
40
+ return version;
41
+ };
42
+ const readDescription = (raw, problems) => {
43
+ const { description } = raw;
44
+ if (description === undefined)
45
+ return undefined;
46
+ if (typeof description !== 'string') {
47
+ problems.push('"description" must be a string');
48
+ return undefined;
49
+ }
50
+ return description;
51
+ };
52
+ /** `{ location: range }`, validated. `where` names it in the messages. */
53
+ const readRanges = (value, where, problems) => {
54
+ if (value === undefined)
55
+ return {};
56
+ if (!isPlainObject(value)) {
57
+ problems.push(`${where} must be an object of location -> version range`);
58
+ return {};
59
+ }
60
+ const ranges = {};
61
+ for (const [location, range] of Object.entries(value)) {
62
+ if (!LOCATION_PATTERN.test(location))
63
+ problems.push(`${where}: "${location}" is not a valid location`);
64
+ else if (typeof range !== 'string' || semver.validRange(range) === null) {
65
+ problems.push(`${where}: the range of "${location}" must be a semver range such as "^1.0.0"`);
66
+ }
67
+ else
68
+ ranges[location] = range;
69
+ }
70
+ return ranges;
71
+ };
72
+ const isSafeRelativePath = (value) => value !== '' && !value.startsWith('/') && !value.includes('\\') && !value.split('/').some((part) => part === '..' || part === '');
73
+ const readOffers = (value, problems) => {
74
+ if (value === undefined)
75
+ return {};
76
+ if (!isPlainObject(value)) {
77
+ problems.push('"offers" must be an object of metamodel -> path');
78
+ return {};
79
+ }
80
+ const offers = {};
81
+ for (const [metamodel, path] of Object.entries(value)) {
82
+ if (!NAME_PATTERN.test(metamodel))
83
+ problems.push(`"offers": "${metamodel}" is not a valid metamodel name`);
84
+ else if (typeof path !== 'string' || !isSafeRelativePath(path)) {
85
+ problems.push(`"offers": the path of "${metamodel}" must be a relative path inside the module`);
86
+ }
87
+ else
88
+ offers[metamodel] = path;
89
+ }
90
+ return offers;
91
+ };
92
+ export const parseMetamodelManifest = ({ content }) => {
93
+ const label = METAMODEL_MANIFEST_PATH;
94
+ const raw = parseJson(content, label);
95
+ const problems = [];
96
+ const name = readName(raw, problems);
97
+ const version = readVersion(raw, problems);
98
+ const description = readDescription(raw, problems);
99
+ const requires = readRanges(raw.requires, '"requires"', problems);
100
+ if (problems.length > 0)
101
+ return fail(label, problems);
102
+ return { name, version, ...(description === undefined ? {} : { description }), requires };
103
+ };
104
+ export const parseModuleManifest = ({ content }) => {
105
+ const label = MODULE_MANIFEST_PATH;
106
+ const raw = parseJson(content, label);
107
+ const problems = [];
108
+ const name = readName(raw, problems);
109
+ const version = readVersion(raw, problems);
110
+ const description = readDescription(raw, problems);
111
+ const requiresRaw = raw.requires;
112
+ let modules = {};
113
+ let metamodels = {};
114
+ if (requiresRaw !== undefined) {
115
+ if (!isPlainObject(requiresRaw))
116
+ problems.push('"requires" must be an object with "modules" and "metamodels"');
117
+ else {
118
+ modules = readRanges(requiresRaw.modules, '"requires.modules"', problems);
119
+ metamodels = readRanges(requiresRaw.metamodels, '"requires.metamodels"', problems);
120
+ }
121
+ }
122
+ const offers = readOffers(raw.offers, problems);
123
+ if (problems.length > 0)
124
+ return fail(label, problems);
125
+ return { name, version, ...(description === undefined ? {} : { description }), requires: { modules, metamodels }, offers };
126
+ };
127
+ const SPL_KINDS = ['plain', 'project', 'modular'];
128
+ export const parseSplManifest = ({ content }) => {
129
+ const label = SPL_MANIFEST_PATH;
130
+ const raw = parseJson(content, label);
131
+ const problems = [];
132
+ const name = readName(raw, problems);
133
+ let version;
134
+ if (raw.version !== undefined)
135
+ version = readVersion(raw, problems);
136
+ const modules = readRanges(raw.modules, '"modules"', problems);
137
+ const metamodels = readRanges(raw.metamodels, '"metamodels"', problems);
138
+ // a manifest that does not say what it is, is what its modules say
139
+ let kind = Object.keys(modules).length > 0 ? 'modular' : 'plain';
140
+ if (raw.kind !== undefined) {
141
+ if (!SPL_KINDS.includes(raw.kind))
142
+ problems.push(`"kind" must be one of ${SPL_KINDS.join(', ')}`);
143
+ else
144
+ kind = raw.kind;
145
+ }
146
+ if (kind !== 'modular' && Object.keys(modules).length > 0)
147
+ problems.push(`"modules" must be empty in a ${kind} SPL: only a modular one is made of modules`);
148
+ if (problems.length > 0)
149
+ return fail(label, problems);
150
+ return { name, ...(version === undefined ? {} : { version }), kind, metamodels, modules };
151
+ };
152
+ const sortedEntries = (record) => Object.entries(record).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
153
+ const sortedObject = (record) => Object.fromEntries(sortedEntries(record));
154
+ export const serializeSplManifest = ({ spl }) => JSON.stringify({
155
+ name: spl.name,
156
+ ...(spl.version === undefined ? {} : { version: spl.version }),
157
+ kind: spl.kind,
158
+ metamodels: sortedObject(spl.metamodels),
159
+ modules: sortedObject(spl.modules)
160
+ }, null, 2) + '\n';
161
+ const isKind = (value) => value === 'module' || value === 'metamodel';
162
+ export const parseLock = ({ content }) => {
163
+ const label = LOCK_PATH;
164
+ const raw = parseJson(content, label);
165
+ const problems = [];
166
+ if (raw.lockVersion !== 1)
167
+ problems.push('"lockVersion" must be 1');
168
+ const packages = {};
169
+ if (!isPlainObject(raw.packages))
170
+ problems.push('"packages" must be an object');
171
+ else {
172
+ for (const [location, entry] of Object.entries(raw.packages)) {
173
+ if (!isPlainObject(entry) || !isKind(entry.kind) || typeof entry.version !== 'string' || !VERSION_PATTERN.test(entry.version)) {
174
+ problems.push(`"packages.${location}" needs a "kind" (module or metamodel) and a "version" like 1.2.3`);
175
+ }
176
+ else if (entry.revision !== undefined && typeof entry.revision !== 'string') {
177
+ problems.push(`"packages.${location}": "revision" must be a string`);
178
+ }
179
+ else {
180
+ packages[location] = {
181
+ kind: entry.kind,
182
+ version: entry.version,
183
+ ...(entry.revision === undefined ? {} : { revision: entry.revision })
184
+ };
185
+ }
186
+ }
187
+ }
188
+ if (problems.length > 0)
189
+ return fail(label, problems);
190
+ return { lockVersion: 1, packages };
191
+ };
192
+ /** Sorted, so two resolutions of the same closure give the same bytes (and the same git diff). */
193
+ export const serializeLock = ({ lock }) => JSON.stringify({ lockVersion: 1, packages: sortedObject(lock.packages) }, null, 2) + '\n';
194
+ export const emptyRegistryIndex = () => ({ registryVersion: 1, packages: {} });
195
+ export const parseRegistryIndex = ({ content }) => {
196
+ const label = REGISTRY_INDEX_PATH;
197
+ const raw = parseJson(content, label);
198
+ const problems = [];
199
+ if (raw.registryVersion !== 1)
200
+ problems.push('"registryVersion" must be 1');
201
+ const packages = {};
202
+ if (!isPlainObject(raw.packages))
203
+ problems.push('"packages" must be an object');
204
+ else {
205
+ for (const [location, entry] of Object.entries(raw.packages)) {
206
+ if (!LOCATION_PATTERN.test(location))
207
+ problems.push(`"packages": "${location}" is not a valid location`);
208
+ else if (!isPlainObject(entry) || !isKind(entry.kind) || typeof entry.name !== 'string' || !NAME_PATTERN.test(entry.name) || typeof entry.addedAt !== 'string') {
209
+ problems.push(`"packages.${location}" needs a "kind" (module or metamodel), a valid "name" and an "addedAt" date`);
210
+ }
211
+ else if ((entry.description !== undefined && typeof entry.description !== 'string') || (entry.addedBy !== undefined && typeof entry.addedBy !== 'string')) {
212
+ problems.push(`"packages.${location}": "description" and "addedBy" must be strings`);
213
+ }
214
+ else {
215
+ packages[location] = {
216
+ kind: entry.kind,
217
+ name: entry.name,
218
+ ...(entry.description === undefined ? {} : { description: entry.description }),
219
+ addedAt: entry.addedAt,
220
+ ...(entry.addedBy === undefined ? {} : { addedBy: entry.addedBy })
221
+ };
222
+ }
223
+ }
224
+ }
225
+ if (problems.length > 0)
226
+ return fail(label, problems);
227
+ return { registryVersion: 1, packages };
228
+ };
229
+ /** Sorted by location, so the same catalog always gives the same bytes (and a small git diff). */
230
+ export const serializeRegistryIndex = ({ index }) => JSON.stringify({ registryVersion: 1, packages: sortedObject(index.packages) }, null, 2) + '\n';
231
+ //# sourceMappingURL=manifests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifests.js","sourceRoot":"","sources":["../../../src/modules/packages/manifests.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAaxD,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAA;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAA;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAA;AAC3C,MAAM,CAAC,MAAM,SAAS,GAAG,iBAAiB,CAAA;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAA;AAElD,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAEnC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,KAAa,EAA2B,EAAE;IAC5E,IAAI,KAAc,CAAA;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,mBAAmB,CAAC,GAAG,KAAK,uBAAwB,KAAe,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC5G,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,mBAAmB,CAAC,GAAG,KAAK,yBAAyB,CAAC,CAAA;IAC3F,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,IAA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AAQ,gDAAgD,CAAC,CAAA;YACtF,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,QAAQ,CAAC,GAAG;oBACnB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;oBAC9E,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;iBACnE,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACrD,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAA;AACzC,CAAC,CAAA;AAED,kGAAkG;AAClG,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAE,KAAK,EAA4B,EAAU,EAAE,CACpF,IAAI,CAAC,SAAS,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAA","sourcesContent":["import semver from 'semver'\nimport { NAME_PATTERN, VERSION_PATTERN } from '../../constants.js'\nimport { ModuleManifestError } from '../../errors.js'\nimport { isPlainObject } from '../../internal/guards.js'\nimport type {\n Lock,\n LockEntry,\n MetamodelManifest,\n ModuleManifest,\n PackageKind,\n RegistryEntry,\n RegistryIndex,\n SplKind,\n SplManifest\n} from '../types.js'\n\nexport const METAMODEL_MANIFEST_PATH = 'metamodel.json'\nexport const MODULE_MANIFEST_PATH = '.linea/module.json'\nexport const SPL_MANIFEST_PATH = 'spl.json'\nexport const LOCK_PATH = 'linea.lock.json'\nexport const REGISTRY_INDEX_PATH = 'registry.json'\n\nconst LOCATION_PATTERN = /^[^\\s]+$/\n\nconst parseJson = (content: string, label: string): Record<string, unknown> => {\n let value: unknown\n try {\n value = JSON.parse(content)\n } catch (error) {\n throw new ModuleManifestError(`${label} is not valid JSON: ${(error as Error).message}`, { cause: error })\n }\n if (!isPlainObject(value)) throw new ModuleManifestError(`${label} must be a JSON object.`)\n return value\n}\n\nconst fail = (label: string, problems: string[]): never => {\n throw new ModuleManifestError(`${label} is not valid:\\n- ${problems.join('\\n- ')}`)\n}\n\nconst readName = (raw: Record<string, unknown>, problems: string[]): string => {\n const { name } = raw\n if (typeof name !== 'string' || !NAME_PATTERN.test(name)) {\n problems.push('\"name\" must be a string of letters, digits, \"_\", \"-\" or \".\"')\n return ''\n }\n return name\n}\n\nconst readVersion = (raw: Record<string, unknown>, problems: string[]): string => {\n const { version } = raw\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\n problems.push('\"version\" must look like 1.2.3')\n return ''\n }\n return version\n}\n\nconst readDescription = (raw: Record<string, unknown>, problems: string[]): string | undefined => {\n const { description } = raw\n if (description === undefined) return undefined\n if (typeof description !== 'string') {\n problems.push('\"description\" must be a string')\n return undefined\n }\n return description\n}\n\n/** `{ location: range }`, validated. `where` names it in the messages. */\nconst readRanges = (value: unknown, where: string, problems: string[]): Record<string, string> => {\n if (value === undefined) return {}\n if (!isPlainObject(value)) {\n problems.push(`${where} must be an object of location -> version range`)\n return {}\n }\n const ranges: Record<string, string> = {}\n for (const [location, range] of Object.entries(value)) {\n if (!LOCATION_PATTERN.test(location)) problems.push(`${where}: \"${location}\" is not a valid location`)\n else if (typeof range !== 'string' || semver.validRange(range) === null) {\n problems.push(`${where}: the range of \"${location}\" must be a semver range such as \"^1.0.0\"`)\n } else ranges[location] = range\n }\n return ranges\n}\n\nconst isSafeRelativePath = (value: string): boolean =>\n value !== '' && !value.startsWith('/') && !value.includes('\\\\') && !value.split('/').some((part) => part === '..' || part === '')\n\nconst readOffers = (value: unknown, problems: string[]): Record<string, string> => {\n if (value === undefined) return {}\n if (!isPlainObject(value)) {\n problems.push('\"offers\" must be an object of metamodel -> path')\n return {}\n }\n const offers: Record<string, string> = {}\n for (const [metamodel, path] of Object.entries(value)) {\n if (!NAME_PATTERN.test(metamodel)) problems.push(`\"offers\": \"${metamodel}\" is not a valid metamodel name`)\n else if (typeof path !== 'string' || !isSafeRelativePath(path)) {\n problems.push(`\"offers\": the path of \"${metamodel}\" must be a relative path inside the module`)\n } else offers[metamodel] = path\n }\n return offers\n}\n\nexport const parseMetamodelManifest = ({ content }: { content: string }): MetamodelManifest => {\n const label = METAMODEL_MANIFEST_PATH\n const raw = parseJson(content, label)\n const problems: string[] = []\n const name = readName(raw, problems)\n const version = readVersion(raw, problems)\n const description = readDescription(raw, problems)\n const requires = readRanges(raw.requires, '\"requires\"', problems)\n if (problems.length > 0) return fail(label, problems)\n return { name, version, ...(description === undefined ? {} : { description }), requires }\n}\n\nexport const parseModuleManifest = ({ content }: { content: string }): ModuleManifest => {\n const label = MODULE_MANIFEST_PATH\n const raw = parseJson(content, label)\n const problems: string[] = []\n const name = readName(raw, problems)\n const version = readVersion(raw, problems)\n const description = readDescription(raw, problems)\n const requiresRaw = raw.requires\n let modules: Record<string, string> = {}\n let metamodels: Record<string, string> = {}\n if (requiresRaw !== undefined) {\n if (!isPlainObject(requiresRaw)) problems.push('\"requires\" must be an object with \"modules\" and \"metamodels\"')\n else {\n modules = readRanges(requiresRaw.modules, '\"requires.modules\"', problems)\n metamodels = readRanges(requiresRaw.metamodels, '\"requires.metamodels\"', problems)\n }\n }\n const offers = readOffers(raw.offers, problems)\n if (problems.length > 0) return fail(label, problems)\n return { name, version, ...(description === undefined ? {} : { description }), requires: { modules, metamodels }, offers }\n}\n\nconst SPL_KINDS: readonly SplKind[] = ['plain', 'project', 'modular']\n\nexport const parseSplManifest = ({ content }: { content: string }): SplManifest => {\n const label = SPL_MANIFEST_PATH\n const raw = parseJson(content, label)\n const problems: string[] = []\n const name = readName(raw, problems)\n let version: string | undefined\n if (raw.version !== undefined) version = readVersion(raw, problems)\n const modules = readRanges(raw.modules, '\"modules\"', problems)\n const metamodels = readRanges(raw.metamodels, '\"metamodels\"', problems)\n // a manifest that does not say what it is, is what its modules say\n let kind: SplKind = Object.keys(modules).length > 0 ? 'modular' : 'plain'\n if (raw.kind !== undefined) {\n if (!SPL_KINDS.includes(raw.kind as SplKind)) problems.push(`\"kind\" must be one of ${SPL_KINDS.join(', ')}`)\n else kind = raw.kind as SplKind\n }\n if (kind !== 'modular' && Object.keys(modules).length > 0) problems.push(`\"modules\" must be empty in a ${kind} SPL: only a modular one is made of modules`)\n if (problems.length > 0) return fail(label, problems)\n return { name, ...(version === undefined ? {} : { version }), kind, metamodels, modules }\n}\n\nconst sortedEntries = <T>(record: Readonly<Record<string, T>>): [string, T][] =>\n Object.entries(record).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\nconst sortedObject = <T>(record: Readonly<Record<string, T>>): Record<string, T> =>\n Object.fromEntries(sortedEntries(record))\n\nexport const serializeSplManifest = ({ spl }: { spl: SplManifest }): string =>\n JSON.stringify({\n name: spl.name,\n ...(spl.version === undefined ? {} : { version: spl.version }),\n kind: spl.kind,\n metamodels: sortedObject(spl.metamodels),\n modules: sortedObject(spl.modules)\n }, null, 2) + '\\n'\n\nconst isKind = (value: unknown): value is PackageKind => value === 'module' || value === 'metamodel'\n\nexport const parseLock = ({ content }: { content: string }): Lock => {\n const label = LOCK_PATH\n const raw = parseJson(content, label)\n const problems: string[] = []\n if (raw.lockVersion !== 1) problems.push('\"lockVersion\" must be 1')\n const packages: Record<string, LockEntry> = {}\n if (!isPlainObject(raw.packages)) problems.push('\"packages\" must be an object')\n else {\n for (const [location, entry] of Object.entries(raw.packages)) {\n if (!isPlainObject(entry) || !isKind(entry.kind) || typeof entry.version !== 'string' || !VERSION_PATTERN.test(entry.version)) {\n problems.push(`\"packages.${location}\" needs a \"kind\" (module or metamodel) and a \"version\" like 1.2.3`)\n } else if (entry.revision !== undefined && typeof entry.revision !== 'string') {\n problems.push(`\"packages.${location}\": \"revision\" must be a string`)\n } else {\n packages[location] = {\n kind: entry.kind,\n version: entry.version,\n ...(entry.revision === undefined ? {} : { revision: entry.revision })\n }\n }\n }\n }\n if (problems.length > 0) return fail(label, problems)\n return { lockVersion: 1, packages }\n}\n\n/** Sorted, so two resolutions of the same closure give the same bytes (and the same git diff). */\nexport const serializeLock = ({ lock }: { lock: Lock }): string =>\n JSON.stringify({ lockVersion: 1, packages: sortedObject(lock.packages) }, null, 2) + '\\n'\n\nexport const emptyRegistryIndex = (): RegistryIndex => ({ registryVersion: 1, packages: {} })\n\nexport const parseRegistryIndex = ({ content }: { content: string }): RegistryIndex => {\n const label = REGISTRY_INDEX_PATH\n const raw = parseJson(content, label)\n const problems: string[] = []\n if (raw.registryVersion !== 1) problems.push('\"registryVersion\" must be 1')\n const packages: Record<string, Omit<RegistryEntry, 'location'>> = {}\n if (!isPlainObject(raw.packages)) problems.push('\"packages\" must be an object')\n else {\n for (const [location, entry] of Object.entries(raw.packages)) {\n if (!LOCATION_PATTERN.test(location)) problems.push(`\"packages\": \"${location}\" is not a valid location`)\n else if (!isPlainObject(entry) || !isKind(entry.kind) || typeof entry.name !== 'string' || !NAME_PATTERN.test(entry.name) || typeof entry.addedAt !== 'string') {\n problems.push(`\"packages.${location}\" needs a \"kind\" (module or metamodel), a valid \"name\" and an \"addedAt\" date`)\n } else if ((entry.description !== undefined && typeof entry.description !== 'string') || (entry.addedBy !== undefined && typeof entry.addedBy !== 'string')) {\n problems.push(`\"packages.${location}\": \"description\" and \"addedBy\" must be strings`)\n } else {\n packages[location] = {\n kind: entry.kind,\n name: entry.name,\n ...(entry.description === undefined ? {} : { description: entry.description }),\n addedAt: entry.addedAt,\n ...(entry.addedBy === undefined ? {} : { addedBy: entry.addedBy })\n }\n }\n }\n }\n if (problems.length > 0) return fail(label, problems)\n return { registryVersion: 1, packages }\n}\n\n/** Sorted by location, so the same catalog always gives the same bytes (and a small git diff). */\nexport const serializeRegistryIndex = ({ index }: { index: RegistryIndex }): string =>\n JSON.stringify({ registryVersion: 1, packages: sortedObject(index.packages) }, null, 2) + '\\n'\n"]}
@@ -0,0 +1,34 @@
1
+ import type { PackageFiles, PackageSource } from '../types.js';
2
+ /** A file of a package as text; `undefined` when it does not exist. */
3
+ export declare const readPackageText: ({ files, path: filePath }: {
4
+ files: PackageFiles;
5
+ path: string;
6
+ }) => Promise<string | undefined>;
7
+ /** The files of a directory on disk, as `PackageFiles`. `.git` and `node_modules` are not part of a package. */
8
+ export declare const createFsFiles: ({ dir }: {
9
+ dir: string;
10
+ }) => PackageFiles;
11
+ /** location -> version -> path -> content */
12
+ export type MemoryPackages = Record<string, Record<string, Record<string, string | Uint8Array>>>;
13
+ /** A fixed set of packages held in memory: for tests, and for a server that has already fetched what it needs. */
14
+ export declare const createMemoryPackageSource: ({ packages, revisions }: {
15
+ packages: MemoryPackages;
16
+ /** location -> version -> revision */
17
+ revisions?: Record<string, Record<string, string>>;
18
+ }) => PackageSource;
19
+ /**
20
+ * Packages in folders on disk: the location `file:<folder>` is a folder under `root`. A folder is one working copy, so it has exactly one
21
+ * version, the one its manifest (`module.json` or `metamodel.json`) declares. This is what a local workspace (and the CLI) uses.
22
+ */
23
+ export declare const createFsPackageSource: ({ root }: {
24
+ root: string;
25
+ }) => PackageSource;
26
+ /**
27
+ * A source that answers for a few locations itself (a package made up on the spot, to check one on its own)
28
+ * and leaves every other to `base`.
29
+ */
30
+ export declare const withOverlay: ({ base, overlay, locations }: {
31
+ base: PackageSource;
32
+ overlay: PackageSource;
33
+ locations: ReadonlySet<string>;
34
+ }) => PackageSource;