@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.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/commands/build.cjs +106 -150
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +15 -10
- package/dist/commands/build.js +101 -126
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +32 -36
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +13 -8
- package/dist/commands/check.js +30 -33
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +22 -22
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +13 -8
- package/dist/commands/dump/artifacts.js +20 -19
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +19 -21
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +12 -7
- package/dist/commands/dump/software.js +17 -18
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +32 -33
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +13 -8
- package/dist/commands/test.js +30 -30
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +59 -68
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.js +60 -66
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +241 -314
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.js +241 -312
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +16 -35
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.js +17 -33
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +258 -334
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.js +256 -311
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +21 -35
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.js +21 -34
- package/dist/compiler/package.js.map +1 -1
- package/dist/compiler/source.cjs +239 -308
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.js +239 -304
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +30 -35
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.js +29 -33
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/util.cjs +40 -61
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.js +36 -39
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.js +13 -12
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +42 -33
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.js +41 -31
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +73 -107
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.js +73 -105
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +22 -18
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.js +21 -16
- package/dist/shared/proc.js.map +1 -1
- package/package.json +10 -10
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/check.d.ts.map +0 -1
- package/dist/commands/dump/artifacts.d.ts.map +0 -1
- package/dist/commands/dump/software.d.ts.map +0 -1
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/compiler/artifactset.d.ts +0 -24
- package/dist/compiler/artifactset.d.ts.map +0 -1
- package/dist/compiler/compiler.d.ts +0 -42
- package/dist/compiler/compiler.d.ts.map +0 -1
- package/dist/compiler/compileroptions.d.ts +0 -6
- package/dist/compiler/compileroptions.d.ts.map +0 -1
- package/dist/compiler/main.d.ts +0 -35
- package/dist/compiler/main.d.ts.map +0 -1
- package/dist/compiler/package.d.ts +0 -44
- package/dist/compiler/package.d.ts.map +0 -1
- package/dist/compiler/source.d.ts +0 -54
- package/dist/compiler/source.d.ts.map +0 -1
- package/dist/compiler/template.d.ts +0 -22
- package/dist/compiler/template.d.ts.map +0 -1
- package/dist/compiler/test.artifacts.d.ts +0 -47
- package/dist/compiler/test.artifacts.d.ts.map +0 -1
- package/dist/compiler/util.d.ts +0 -8
- package/dist/compiler/util.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/shared/basecmd.d.ts +0 -12
- package/dist/shared/basecmd.d.ts.map +0 -1
- package/dist/shared/dump.d.ts +0 -6
- package/dist/shared/dump.d.ts.map +0 -1
- package/dist/shared/proc.d.ts +0 -5
- package/dist/shared/proc.d.ts.map +0 -1
|
@@ -1,317 +1,244 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|