@platforma-sdk/tengo-builder 2.4.24 → 2.4.26

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 (106) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/commands/build.cjs +106 -150
  3. package/dist/commands/build.cjs.map +1 -1
  4. package/dist/commands/build.d.ts +15 -10
  5. package/dist/commands/build.js +101 -126
  6. package/dist/commands/build.js.map +1 -1
  7. package/dist/commands/check.cjs +32 -36
  8. package/dist/commands/check.cjs.map +1 -1
  9. package/dist/commands/check.d.ts +13 -8
  10. package/dist/commands/check.js +30 -33
  11. package/dist/commands/check.js.map +1 -1
  12. package/dist/commands/dump/artifacts.cjs +22 -22
  13. package/dist/commands/dump/artifacts.cjs.map +1 -1
  14. package/dist/commands/dump/artifacts.d.ts +13 -8
  15. package/dist/commands/dump/artifacts.js +20 -19
  16. package/dist/commands/dump/artifacts.js.map +1 -1
  17. package/dist/commands/dump/software.cjs +19 -21
  18. package/dist/commands/dump/software.cjs.map +1 -1
  19. package/dist/commands/dump/software.d.ts +12 -7
  20. package/dist/commands/dump/software.js +17 -18
  21. package/dist/commands/dump/software.js.map +1 -1
  22. package/dist/commands/test.cjs +32 -33
  23. package/dist/commands/test.cjs.map +1 -1
  24. package/dist/commands/test.d.ts +13 -8
  25. package/dist/commands/test.js +30 -30
  26. package/dist/commands/test.js.map +1 -1
  27. package/dist/compiler/artifactset.cjs +59 -68
  28. package/dist/compiler/artifactset.cjs.map +1 -1
  29. package/dist/compiler/artifactset.js +60 -66
  30. package/dist/compiler/artifactset.js.map +1 -1
  31. package/dist/compiler/compiler.cjs +241 -314
  32. package/dist/compiler/compiler.cjs.map +1 -1
  33. package/dist/compiler/compiler.js +241 -312
  34. package/dist/compiler/compiler.js.map +1 -1
  35. package/dist/compiler/compileroptions.cjs +16 -35
  36. package/dist/compiler/compileroptions.cjs.map +1 -1
  37. package/dist/compiler/compileroptions.js +17 -33
  38. package/dist/compiler/compileroptions.js.map +1 -1
  39. package/dist/compiler/main.cjs +258 -334
  40. package/dist/compiler/main.cjs.map +1 -1
  41. package/dist/compiler/main.js +256 -311
  42. package/dist/compiler/main.js.map +1 -1
  43. package/dist/compiler/package.cjs +21 -35
  44. package/dist/compiler/package.cjs.map +1 -1
  45. package/dist/compiler/package.js +21 -34
  46. package/dist/compiler/package.js.map +1 -1
  47. package/dist/compiler/source.cjs +239 -308
  48. package/dist/compiler/source.cjs.map +1 -1
  49. package/dist/compiler/source.js +239 -304
  50. package/dist/compiler/source.js.map +1 -1
  51. package/dist/compiler/template.cjs +30 -35
  52. package/dist/compiler/template.cjs.map +1 -1
  53. package/dist/compiler/template.js +29 -33
  54. package/dist/compiler/template.js.map +1 -1
  55. package/dist/compiler/util.cjs +40 -61
  56. package/dist/compiler/util.cjs.map +1 -1
  57. package/dist/compiler/util.js +36 -39
  58. package/dist/compiler/util.js.map +1 -1
  59. package/dist/index.cjs +14 -14
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +15 -11
  62. package/dist/index.js +13 -12
  63. package/dist/index.js.map +1 -1
  64. package/dist/shared/basecmd.cjs +42 -33
  65. package/dist/shared/basecmd.cjs.map +1 -1
  66. package/dist/shared/basecmd.js +41 -31
  67. package/dist/shared/basecmd.js.map +1 -1
  68. package/dist/shared/dump.cjs +73 -107
  69. package/dist/shared/dump.cjs.map +1 -1
  70. package/dist/shared/dump.js +73 -105
  71. package/dist/shared/dump.js.map +1 -1
  72. package/dist/shared/proc.cjs +22 -18
  73. package/dist/shared/proc.cjs.map +1 -1
  74. package/dist/shared/proc.js +21 -16
  75. package/dist/shared/proc.js.map +1 -1
  76. package/package.json +10 -10
  77. package/dist/commands/build.d.ts.map +0 -1
  78. package/dist/commands/check.d.ts.map +0 -1
  79. package/dist/commands/dump/artifacts.d.ts.map +0 -1
  80. package/dist/commands/dump/software.d.ts.map +0 -1
  81. package/dist/commands/test.d.ts.map +0 -1
  82. package/dist/compiler/artifactset.d.ts +0 -24
  83. package/dist/compiler/artifactset.d.ts.map +0 -1
  84. package/dist/compiler/compiler.d.ts +0 -42
  85. package/dist/compiler/compiler.d.ts.map +0 -1
  86. package/dist/compiler/compileroptions.d.ts +0 -6
  87. package/dist/compiler/compileroptions.d.ts.map +0 -1
  88. package/dist/compiler/main.d.ts +0 -35
  89. package/dist/compiler/main.d.ts.map +0 -1
  90. package/dist/compiler/package.d.ts +0 -44
  91. package/dist/compiler/package.d.ts.map +0 -1
  92. package/dist/compiler/source.d.ts +0 -54
  93. package/dist/compiler/source.d.ts.map +0 -1
  94. package/dist/compiler/template.d.ts +0 -22
  95. package/dist/compiler/template.d.ts.map +0 -1
  96. package/dist/compiler/test.artifacts.d.ts +0 -47
  97. package/dist/compiler/test.artifacts.d.ts.map +0 -1
  98. package/dist/compiler/util.d.ts +0 -8
  99. package/dist/compiler/util.d.ts.map +0 -1
  100. package/dist/index.d.ts.map +0 -1
  101. package/dist/shared/basecmd.d.ts +0 -12
  102. package/dist/shared/basecmd.d.ts.map +0 -1
  103. package/dist/shared/dump.d.ts +0 -6
  104. package/dist/shared/dump.d.ts.map +0 -1
  105. package/dist/shared/proc.d.ts +0 -5
  106. package/dist/shared/proc.d.ts.map +0 -1
@@ -1,317 +1,244 @@
1
- 'use strict';
1
+ const require_util = require('./util.cjs');
2
+ const require_package = require('./package.cjs');
3
+ const require_template = require('./template.cjs');
4
+ const require_artifactset = require('./artifactset.cjs');
5
+ const require_compileroptions = require('./compileroptions.cjs');
2
6
 
3
- var template = require('./template.cjs');
4
- var _package = require('./package.cjs');
5
- var artifactset = require('./artifactset.cjs');
6
- var util = require('./util.cjs');
7
- var compileroptions = require('./compileroptions.cjs');
8
-
9
- class TengoTemplateCompiler {
10
- compileMode;
11
- libs = new artifactset.ArtifactStore((src) => src.fullName);
12
- software = new artifactset.ArtifactStore((src) => src.fullName);
13
- assets = new artifactset.ArtifactStore((src) => src.fullName);
14
- templates = new artifactset.ArtifactStore((tpl) => tpl.fullName);
15
- constructor(compileMode) {
16
- this.compileMode = compileMode;
17
- }
18
- /** Recursively add dependencies to the template. */
19
- populateTemplateDataFromDependencies(fullName, data, deps, trace) {
20
- for (const dep of deps) {
21
- switch (dep.type) {
22
- case "library": {
23
- const lib = this.getLibOrError(dep);
24
- const recursionStart = trace.indexOf(_package.artifactNameToString(dep));
25
- if (recursionStart >= 0) {
26
- const errorMessage = `library import recursion detected: ` +
27
- `${trace.slice(recursionStart).join(" -> ")} -> ${_package.artifactNameToString(dep)}`;
28
- throw new Error(errorMessage);
29
- }
30
- const tplLib = {
31
- ..._package.formatArtefactNameAndVersion(lib.fullName),
32
- sourceHash: lib.sourceHash,
33
- };
34
- compileroptions.applyLibraryCompilerOptions(lib.compilerOptions);
35
- data.template.libs[_package.artifactNameToString(dep)] = tplLib;
36
- data.hashToSource[tplLib.sourceHash] = lib.src;
37
- // populate with transient library dependencies
38
- this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
39
- ...trace,
40
- _package.artifactNameToString(dep),
41
- ]);
42
- break;
43
- }
44
- case "software": {
45
- const software = this.getSoftwareOrError(dep);
46
- data.template.software[_package.artifactNameToString(dep)] = {
47
- ..._package.formatArtefactNameAndVersion(software.fullName),
48
- sourceHash: software.sourceHash,
49
- };
50
- data.hashToSource[software.sourceHash] = software.src;
51
- break;
52
- }
53
- case "asset": {
54
- const asset = this.getAssetOrError(dep);
55
- // Yes, we temporarily put assets into 'software' section of template, so controller can
56
- // handle it the right way without updates
57
- data.template.software[_package.artifactNameToString(dep)] = {
58
- ..._package.formatArtefactNameAndVersion(asset.fullName),
59
- sourceHash: asset.sourceHash,
60
- };
61
- data.hashToSource[asset.sourceHash] = asset.src;
62
- break;
63
- }
64
- case "template": {
65
- if (_package.typedArtifactNamesEquals(fullName, dep))
66
- // skipping self reference
67
- continue;
68
- const tpl = this.getTemplateOrError(dep);
69
- data.template.templates[_package.artifactNameToString(dep)] = tpl.data.template;
70
- data.hashToSource[tpl.data.template.sourceHash] = tpl.source;
71
- // add all the sources of transitivedependencies to the resulted hashToSource
72
- for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {
73
- data.hashToSource[hash] = src;
74
- }
75
- break;
76
- }
77
- case "test":
78
- throw new Error(`dependencies tree error: tests should never be part of template: ` +
79
- `${_package.typedArtifactNameToString(dep)} is dependency of ${_package.artifactNameToString(fullName)}`);
80
- default:
81
- util.assertNever(dep.type);
82
- }
83
- }
84
- }
85
- /** This method assumes that all dependencies are already added to the compiler's context */
86
- compileAndAddTemplate(tplSrc) {
87
- if (tplSrc.fullName.type !== "template")
88
- throw new Error("unexpected source type");
89
- // creating template with unpopulated dependencies
90
- const tplData = {
91
- type: "pl.tengo-template.v3",
92
- hashToSource: {
93
- [tplSrc.sourceHash]: tplSrc.src,
94
- },
95
- template: {
96
- ..._package.formatArtefactNameAndVersion(tplSrc.fullName),
97
- templates: {},
98
- libs: {},
99
- software: {},
100
- assets: {},
101
- sourceHash: tplSrc.sourceHash,
102
- },
103
- };
104
- compileroptions.applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);
105
- // collecting dependencies in output format
106
- this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);
107
- return tplData;
108
- }
109
- addLib(lib) {
110
- const libFromMap = this.libs.add(lib.compileMode, lib, false);
111
- if (libFromMap && !_package.fullNameEquals(lib.fullName, libFromMap.fullName))
112
- throw new Error(`compiler already contain such library: adding = ${_package.fullNameToString(lib.fullName)}, contains = ${_package.fullNameToString(libFromMap.fullName)}`);
113
- }
114
- allLibs() {
115
- return this.libs.array(this.compileMode);
116
- }
117
- getLib(name) {
118
- if (name.type !== "library")
119
- throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
120
- return this.libs.get(this.compileMode, name);
121
- }
122
- getLibOrError(name) {
123
- const lib = this.getLib(name);
124
- if (!lib)
125
- throw new Error(`library not found: ${_package.artifactNameToString(name)}`);
126
- return lib;
127
- }
128
- checkLibs() {
129
- this.libs.forEach(this.compileMode, (lib) => {
130
- for (const dep of lib.dependencies) {
131
- if (dep.type === "test")
132
- throw new Error(`test should never be dependency of production code: ${_package.typedArtifactNameToString(dep)} test is dependency of ${_package.fullNameToString(lib.fullName)}`);
133
- if (!this.getArtefact(dep))
134
- throw new Error(`unresolved dependency ${_package.typedArtifactNameToString(dep)} for ${_package.fullNameToString(lib.fullName)}`);
135
- }
136
- });
137
- }
138
- addSoftware(software) {
139
- const swFromMap = this.software.add(software.compileMode, software, false);
140
- if (swFromMap && !_package.fullNameEquals(software.fullName, swFromMap.fullName))
141
- throw new Error(`compiler already contain info for software: adding = ${_package.fullNameToString(software.fullName)}, contains = ${_package.fullNameToString(swFromMap.fullName)}`);
142
- }
143
- allSoftware() {
144
- return this.software.array(this.compileMode);
145
- }
146
- getSoftware(name) {
147
- if (name.type !== "software")
148
- throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
149
- return this.software.get(this.compileMode, name);
150
- }
151
- getSoftwareOrError(name) {
152
- const software = this.getSoftware(name);
153
- if (!software)
154
- throw new Error(`software info not found: ${_package.artifactNameToString(name)}`);
155
- return software;
156
- }
157
- addAsset(asset) {
158
- const assetFromMap = this.assets.add(asset.compileMode, asset, false);
159
- if (assetFromMap && !_package.fullNameEquals(asset.fullName, assetFromMap.fullName))
160
- throw new Error(`compiler already contain info for asset: adding = ${_package.fullNameToString(asset.fullName)}, contains = ${_package.fullNameToString(assetFromMap.fullName)}`);
161
- }
162
- allAssets() {
163
- return this.assets.array(this.compileMode);
164
- }
165
- getAsset(name) {
166
- if (name.type !== "asset")
167
- throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
168
- return this.assets.get(this.compileMode, name);
169
- }
170
- getAssetOrError(name) {
171
- const asset = this.getAsset(name);
172
- if (!asset)
173
- throw new Error(`asset info not found: ${_package.artifactNameToString(name)}`);
174
- return asset;
175
- }
176
- addTemplate(tpl) {
177
- const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);
178
- if (tplFromMap && !_package.fullNameEquals(tpl.fullName, tplFromMap.fullName))
179
- throw new Error(`compiler already contain such template: adding = ${_package.fullNameToString(tpl.fullName)}, contains = ${_package.fullNameToString(tplFromMap.fullName)}`);
180
- }
181
- allTemplates() {
182
- return this.templates.array(this.compileMode);
183
- }
184
- getTemplate(name) {
185
- if (name.type !== "template")
186
- throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
187
- return this.templates.get(this.compileMode, name);
188
- }
189
- getTemplateOrError(name) {
190
- const tpl = this.getTemplate(name);
191
- if (!tpl)
192
- throw new Error(`template not found: ${_package.artifactNameToString(name)}`);
193
- return tpl;
194
- }
195
- getArtefact(name) {
196
- switch (name.type) {
197
- case "template":
198
- return this.getTemplate(name);
199
- case "library":
200
- return this.getLib(name);
201
- case "software":
202
- return this.getSoftware(name);
203
- case "asset":
204
- return this.getAsset(name);
205
- case "test":
206
- // Tests are ignored by the complier. They should never be compiled into templates or libs and
207
- // should never be a dependency.
208
- return undefined;
209
- default:
210
- util.assertNever(name.type);
211
- }
212
- }
213
- compileAndAdd(sources) {
214
- const result = {
215
- templates: [],
216
- libs: [],
217
- software: [],
218
- assets: [],
219
- };
220
- let current = [];
221
- for (const src of sources) {
222
- if (src.fullName.type === "library") {
223
- // add libraries 'as-is' to be able to resolve them as dependencies
224
- this.addLib(src);
225
- result.libs.push(src);
226
- }
227
- else if (src.fullName.type === "software") {
228
- // add software 'as-is' to be able to resolve them as dependencies
229
- this.addSoftware(src);
230
- result.software.push(src);
231
- }
232
- else if (src.fullName.type === "asset") {
233
- // add assets 'as-is' to be able to resolve them as dependencies
234
- this.addAsset(src);
235
- result.assets.push(src);
236
- }
237
- else {
238
- current.push(src);
239
- }
240
- }
241
- while (current.length > 0) {
242
- const unprocessed = [];
243
- for (const src of current) {
244
- //
245
- // If one of the dependencies can't be resolved with current compiler context,
246
- // we put aside the source until next iteration, in hope that the dependency
247
- // will be satisfied then.
248
- //
249
- // This is equivalent to topological sorting of input sources.
250
- //
251
- const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep) &&
252
- // allow self reference for templates
253
- !(src.fullName.type === "template" && _package.typedArtifactNamesEquals(src.fullName, dep)));
254
- if (unsatisfied.length > 0) {
255
- let errorMessage = `Unsatisfied dependencies in ${_package.fullNameToString(src.fullName)}:\n`;
256
- for (const dep of unsatisfied) {
257
- errorMessage += ` - ${_package.typedArtifactNameToString(dep)}\n`;
258
- }
259
- unprocessed.push({ src, err: new Error(errorMessage) });
260
- continue;
261
- }
262
- // type specific processing
263
- switch (src.fullName.type) {
264
- case "library":
265
- // libraries are added as is
266
- this.addLib(src);
267
- result.libs.push(src);
268
- break;
269
- case "software":
270
- // software dependencies are added as is
271
- this.addSoftware(src);
272
- result.software.push(src);
273
- break;
274
- case "asset":
275
- // software dependencies are added as is
276
- this.addAsset(src);
277
- result.assets.push(src);
278
- break;
279
- case "template":
280
- // templates are compiled and then added
281
- try {
282
- const tpl = this.compileAndAddTemplate(src);
283
- const tplWithSrc = template.newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);
284
- this.addTemplate(tplWithSrc);
285
- result.templates.push(tplWithSrc);
286
- }
287
- catch (error) {
288
- const err = error;
289
- let errorMessage = `Unsatisfied dependencies in ${_package.fullNameToString(src.fullName)}:\n`;
290
- errorMessage += ` - ${err.message}\n`;
291
- unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet
292
- }
293
- break;
294
- case "test":
295
- // Ignore tests: they never should be part of compiled code or be a dependency.
296
- break;
297
- default:
298
- util.assertNever(src.fullName.type);
299
- }
300
- }
301
- // checking that we successfully added at least one source,
302
- // if not all the source files in unprocessed array have unmet dependencies
303
- if (current.length === unprocessed.length) {
304
- let errorMessage = "";
305
- for (const u of unprocessed) {
306
- errorMessage += `\n${u.err.message}`;
307
- }
308
- throw new Error(errorMessage);
309
- }
310
- current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);
311
- }
312
- return result;
313
- }
314
- }
7
+ //#region src/compiler/compiler.ts
8
+ var TengoTemplateCompiler = class {
9
+ libs = new require_artifactset.ArtifactStore((src) => src.fullName);
10
+ software = new require_artifactset.ArtifactStore((src) => src.fullName);
11
+ assets = new require_artifactset.ArtifactStore((src) => src.fullName);
12
+ templates = new require_artifactset.ArtifactStore((tpl) => tpl.fullName);
13
+ constructor(compileMode) {
14
+ this.compileMode = compileMode;
15
+ }
16
+ /** Recursively add dependencies to the template. */
17
+ populateTemplateDataFromDependencies(fullName, data, deps, trace) {
18
+ for (const dep of deps) switch (dep.type) {
19
+ case "library": {
20
+ const lib = this.getLibOrError(dep);
21
+ const recursionStart = trace.indexOf(require_package.artifactNameToString(dep));
22
+ if (recursionStart >= 0) {
23
+ const errorMessage = `library import recursion detected: ${trace.slice(recursionStart).join(" -> ")} -> ${require_package.artifactNameToString(dep)}`;
24
+ throw new Error(errorMessage);
25
+ }
26
+ const tplLib = {
27
+ ...require_package.formatArtefactNameAndVersion(lib.fullName),
28
+ sourceHash: lib.sourceHash
29
+ };
30
+ require_compileroptions.applyLibraryCompilerOptions(lib.compilerOptions, tplLib);
31
+ data.template.libs[require_package.artifactNameToString(dep)] = tplLib;
32
+ data.hashToSource[tplLib.sourceHash] = lib.src;
33
+ this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [...trace, require_package.artifactNameToString(dep)]);
34
+ break;
35
+ }
36
+ case "software": {
37
+ const software = this.getSoftwareOrError(dep);
38
+ data.template.software[require_package.artifactNameToString(dep)] = {
39
+ ...require_package.formatArtefactNameAndVersion(software.fullName),
40
+ sourceHash: software.sourceHash
41
+ };
42
+ data.hashToSource[software.sourceHash] = software.src;
43
+ break;
44
+ }
45
+ case "asset": {
46
+ const asset = this.getAssetOrError(dep);
47
+ data.template.software[require_package.artifactNameToString(dep)] = {
48
+ ...require_package.formatArtefactNameAndVersion(asset.fullName),
49
+ sourceHash: asset.sourceHash
50
+ };
51
+ data.hashToSource[asset.sourceHash] = asset.src;
52
+ break;
53
+ }
54
+ case "template": {
55
+ if (require_package.typedArtifactNamesEquals(fullName, dep)) continue;
56
+ const tpl = this.getTemplateOrError(dep);
57
+ data.template.templates[require_package.artifactNameToString(dep)] = tpl.data.template;
58
+ data.hashToSource[tpl.data.template.sourceHash] = tpl.source;
59
+ for (const [hash, src] of Object.entries(tpl.data.hashToSource)) data.hashToSource[hash] = src;
60
+ break;
61
+ }
62
+ case "test": throw new Error(`dependencies tree error: tests should never be part of template: ${require_package.typedArtifactNameToString(dep)} is dependency of ${require_package.artifactNameToString(fullName)}`);
63
+ default: require_util.assertNever(dep.type);
64
+ }
65
+ }
66
+ /** This method assumes that all dependencies are already added to the compiler's context */
67
+ compileAndAddTemplate(tplSrc) {
68
+ if (tplSrc.fullName.type !== "template") throw new Error("unexpected source type");
69
+ const tplData = {
70
+ type: "pl.tengo-template.v3",
71
+ hashToSource: { [tplSrc.sourceHash]: tplSrc.src },
72
+ template: {
73
+ ...require_package.formatArtefactNameAndVersion(tplSrc.fullName),
74
+ templates: {},
75
+ libs: {},
76
+ software: {},
77
+ assets: {},
78
+ sourceHash: tplSrc.sourceHash
79
+ }
80
+ };
81
+ require_compileroptions.applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);
82
+ this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);
83
+ return tplData;
84
+ }
85
+ addLib(lib) {
86
+ const libFromMap = this.libs.add(lib.compileMode, lib, false);
87
+ if (libFromMap && !require_package.fullNameEquals(lib.fullName, libFromMap.fullName)) throw new Error(`compiler already contain such library: adding = ${require_package.fullNameToString(lib.fullName)}, contains = ${require_package.fullNameToString(libFromMap.fullName)}`);
88
+ }
89
+ allLibs() {
90
+ return this.libs.array(this.compileMode);
91
+ }
92
+ getLib(name) {
93
+ if (name.type !== "library") throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
94
+ return this.libs.get(this.compileMode, name);
95
+ }
96
+ getLibOrError(name) {
97
+ const lib = this.getLib(name);
98
+ if (!lib) throw new Error(`library not found: ${require_package.artifactNameToString(name)}`);
99
+ return lib;
100
+ }
101
+ checkLibs() {
102
+ this.libs.forEach(this.compileMode, (lib) => {
103
+ for (const dep of lib.dependencies) {
104
+ if (dep.type === "test") throw new Error(`test should never be dependency of production code: ${require_package.typedArtifactNameToString(dep)} test is dependency of ${require_package.fullNameToString(lib.fullName)}`);
105
+ if (!this.getArtefact(dep)) throw new Error(`unresolved dependency ${require_package.typedArtifactNameToString(dep)} for ${require_package.fullNameToString(lib.fullName)}`);
106
+ }
107
+ });
108
+ }
109
+ addSoftware(software) {
110
+ const swFromMap = this.software.add(software.compileMode, software, false);
111
+ if (swFromMap && !require_package.fullNameEquals(software.fullName, swFromMap.fullName)) throw new Error(`compiler already contain info for software: adding = ${require_package.fullNameToString(software.fullName)}, contains = ${require_package.fullNameToString(swFromMap.fullName)}`);
112
+ }
113
+ allSoftware() {
114
+ return this.software.array(this.compileMode);
115
+ }
116
+ getSoftware(name) {
117
+ if (name.type !== "software") throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
118
+ return this.software.get(this.compileMode, name);
119
+ }
120
+ getSoftwareOrError(name) {
121
+ const software = this.getSoftware(name);
122
+ if (!software) throw new Error(`software info not found: ${require_package.artifactNameToString(name)}`);
123
+ return software;
124
+ }
125
+ addAsset(asset) {
126
+ const assetFromMap = this.assets.add(asset.compileMode, asset, false);
127
+ if (assetFromMap && !require_package.fullNameEquals(asset.fullName, assetFromMap.fullName)) throw new Error(`compiler already contain info for asset: adding = ${require_package.fullNameToString(asset.fullName)}, contains = ${require_package.fullNameToString(assetFromMap.fullName)}`);
128
+ }
129
+ allAssets() {
130
+ return this.assets.array(this.compileMode);
131
+ }
132
+ getAsset(name) {
133
+ if (name.type !== "asset") throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
134
+ return this.assets.get(this.compileMode, name);
135
+ }
136
+ getAssetOrError(name) {
137
+ const asset = this.getAsset(name);
138
+ if (!asset) throw new Error(`asset info not found: ${require_package.artifactNameToString(name)}`);
139
+ return asset;
140
+ }
141
+ addTemplate(tpl) {
142
+ const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);
143
+ if (tplFromMap && !require_package.fullNameEquals(tpl.fullName, tplFromMap.fullName)) throw new Error(`compiler already contain such template: adding = ${require_package.fullNameToString(tpl.fullName)}, contains = ${require_package.fullNameToString(tplFromMap.fullName)}`);
144
+ }
145
+ allTemplates() {
146
+ return this.templates.array(this.compileMode);
147
+ }
148
+ getTemplate(name) {
149
+ if (name.type !== "template") throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
150
+ return this.templates.get(this.compileMode, name);
151
+ }
152
+ getTemplateOrError(name) {
153
+ const tpl = this.getTemplate(name);
154
+ if (!tpl) throw new Error(`template not found: ${require_package.artifactNameToString(name)}`);
155
+ return tpl;
156
+ }
157
+ getArtefact(name) {
158
+ switch (name.type) {
159
+ case "template": return this.getTemplate(name);
160
+ case "library": return this.getLib(name);
161
+ case "software": return this.getSoftware(name);
162
+ case "asset": return this.getAsset(name);
163
+ case "test": return;
164
+ default: require_util.assertNever(name.type);
165
+ }
166
+ }
167
+ compileAndAdd(sources) {
168
+ const result = {
169
+ templates: [],
170
+ libs: [],
171
+ software: [],
172
+ assets: []
173
+ };
174
+ let current = [];
175
+ for (const src of sources) if (src.fullName.type === "library") {
176
+ this.addLib(src);
177
+ result.libs.push(src);
178
+ } else if (src.fullName.type === "software") {
179
+ this.addSoftware(src);
180
+ result.software.push(src);
181
+ } else if (src.fullName.type === "asset") {
182
+ this.addAsset(src);
183
+ result.assets.push(src);
184
+ } else current.push(src);
185
+ while (current.length > 0) {
186
+ const unprocessed = [];
187
+ for (const src of current) {
188
+ const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep) && !(src.fullName.type === "template" && require_package.typedArtifactNamesEquals(src.fullName, dep)));
189
+ if (unsatisfied.length > 0) {
190
+ let errorMessage = `Unsatisfied dependencies in ${require_package.fullNameToString(src.fullName)}:\n`;
191
+ for (const dep of unsatisfied) errorMessage += ` - ${require_package.typedArtifactNameToString(dep)}\n`;
192
+ unprocessed.push({
193
+ src,
194
+ err: new Error(errorMessage)
195
+ });
196
+ continue;
197
+ }
198
+ switch (src.fullName.type) {
199
+ case "library":
200
+ this.addLib(src);
201
+ result.libs.push(src);
202
+ break;
203
+ case "software":
204
+ this.addSoftware(src);
205
+ result.software.push(src);
206
+ break;
207
+ case "asset":
208
+ this.addAsset(src);
209
+ result.assets.push(src);
210
+ break;
211
+ case "template":
212
+ try {
213
+ const tpl = this.compileAndAddTemplate(src);
214
+ const tplWithSrc = require_template.newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);
215
+ this.addTemplate(tplWithSrc);
216
+ result.templates.push(tplWithSrc);
217
+ } catch (error) {
218
+ const err = error;
219
+ let errorMessage = `Unsatisfied dependencies in ${require_package.fullNameToString(src.fullName)}:\n`;
220
+ errorMessage += ` - ${err.message}\n`;
221
+ unprocessed.push({
222
+ src,
223
+ err: Error(errorMessage)
224
+ });
225
+ }
226
+ break;
227
+ case "test": break;
228
+ default: require_util.assertNever(src.fullName.type);
229
+ }
230
+ }
231
+ if (current.length === unprocessed.length) {
232
+ let errorMessage = "";
233
+ for (const u of unprocessed) errorMessage += `\n${u.err.message}`;
234
+ throw new Error(errorMessage);
235
+ }
236
+ current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);
237
+ }
238
+ return result;
239
+ }
240
+ };
315
241
 
242
+ //#endregion
316
243
  exports.TengoTemplateCompiler = TengoTemplateCompiler;
317
- //# sourceMappingURL=compiler.cjs.map
244
+ //# sourceMappingURL=compiler.cjs.map