@platforma-sdk/tengo-builder 2.4.13 → 2.4.15
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/README.md +4 -4
- package/bin/run.js +5 -5
- package/dist/commands/build.cjs +36 -36
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +5 -5
- package/dist/commands/build.js +36 -36
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +5 -5
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +2 -2
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +5 -5
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +4 -6
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +2 -2
- package/dist/commands/dump/artifacts.d.ts.map +1 -1
- package/dist/commands/dump/artifacts.js +4 -6
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +3 -5
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +2 -2
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/software.js +3 -5
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +5 -5
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +5 -5
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +2 -2
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/artifactset.js +2 -2
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +37 -34
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.d.ts +3 -3
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +37 -34
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +12 -12
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.d.ts +2 -2
- package/dist/compiler/compileroptions.js +12 -12
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +58 -58
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.d.ts +6 -6
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/main.js +58 -58
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +5 -2
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.d.ts +6 -6
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/package.js +5 -2
- package/dist/compiler/package.js.map +1 -1
- package/dist/compiler/source.cjs +50 -52
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.d.ts +2 -2
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/source.js +50 -52
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +7 -7
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.d.ts +2 -2
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/template.js +7 -7
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.cjs +12 -12
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.d.ts +2 -2
- package/dist/compiler/util.js +12 -12
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +15 -15
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.js +15 -15
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +28 -28
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.d.ts +2 -2
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/dump.js +28 -28
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +5 -5
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.js +5 -5
- package/dist/shared/proc.js.map +1 -1
- package/package.json +21 -19
- package/src/commands/build.ts +57 -55
- package/src/commands/check.ts +15 -12
- package/src/commands/dump/artifacts.ts +11 -15
- package/src/commands/dump/software.ts +9 -10
- package/src/commands/test.ts +15 -12
- package/src/compiler/artifactset.ts +7 -9
- package/src/compiler/compiler.test.ts +134 -137
- package/src/compiler/compiler.ts +62 -62
- package/src/compiler/compileroptions.ts +15 -15
- package/src/compiler/main.test.ts +23 -23
- package/src/compiler/main.ts +83 -100
- package/src/compiler/package.ts +14 -12
- package/src/compiler/source.test.ts +191 -183
- package/src/compiler/source.ts +106 -79
- package/src/compiler/template.test.ts +50 -49
- package/src/compiler/template.ts +11 -21
- package/src/compiler/test.artifacts.ts +47 -47
- package/src/compiler/util.ts +17 -17
- package/src/index.ts +10 -10
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +49 -70
- package/src/shared/proc.ts +8 -8
package/src/compiler/compiler.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type { ArtifactSource } from
|
|
2
|
-
import type { TemplateWithSource } from
|
|
3
|
-
import { newTemplateWithSource } from
|
|
4
|
-
import type {
|
|
5
|
-
TypedArtifactName, FullArtifactName,
|
|
6
|
-
CompileMode,
|
|
7
|
-
} from './package';
|
|
1
|
+
import type { ArtifactSource } from "./source";
|
|
2
|
+
import type { TemplateWithSource } from "./template";
|
|
3
|
+
import { newTemplateWithSource } from "./template";
|
|
4
|
+
import type { TypedArtifactName, FullArtifactName, CompileMode } from "./package";
|
|
8
5
|
import {
|
|
9
6
|
fullNameToString,
|
|
10
7
|
typedArtifactNameToString,
|
|
11
8
|
artifactNameToString,
|
|
12
|
-
formatArtefactNameAndVersion,
|
|
9
|
+
formatArtefactNameAndVersion,
|
|
10
|
+
typedArtifactNamesEquals,
|
|
13
11
|
fullNameEquals,
|
|
14
|
-
} from
|
|
15
|
-
import { ArtifactStore } from
|
|
16
|
-
import { assertNever } from
|
|
17
|
-
import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from
|
|
18
|
-
import type { CompiledTemplateV3 } from
|
|
12
|
+
} from "./package";
|
|
13
|
+
import { ArtifactStore } from "./artifactset";
|
|
14
|
+
import { assertNever } from "./util";
|
|
15
|
+
import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from "./compileroptions";
|
|
16
|
+
import type { CompiledTemplateV3 } from "@milaboratories/pl-model-backend";
|
|
19
17
|
|
|
20
18
|
/** A compilation result. */
|
|
21
19
|
export interface TemplatesAndLibs {
|
|
@@ -31,9 +29,7 @@ export class TengoTemplateCompiler {
|
|
|
31
29
|
private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);
|
|
32
30
|
private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);
|
|
33
31
|
|
|
34
|
-
constructor(
|
|
35
|
-
private readonly compileMode: CompileMode,
|
|
36
|
-
) { }
|
|
32
|
+
constructor(private readonly compileMode: CompileMode) {}
|
|
37
33
|
|
|
38
34
|
/** Recursively add dependencies to the template. */
|
|
39
35
|
private populateTemplateDataFromDependencies(
|
|
@@ -44,13 +40,14 @@ export class TengoTemplateCompiler {
|
|
|
44
40
|
) {
|
|
45
41
|
for (const dep of deps) {
|
|
46
42
|
switch (dep.type) {
|
|
47
|
-
case
|
|
43
|
+
case "library": {
|
|
48
44
|
const lib = this.getLibOrError(dep);
|
|
49
45
|
|
|
50
46
|
const recursionStart = trace.indexOf(artifactNameToString(dep));
|
|
51
47
|
if (recursionStart >= 0) {
|
|
52
|
-
const errorMessage =
|
|
53
|
-
|
|
48
|
+
const errorMessage =
|
|
49
|
+
`library import recursion detected: ` +
|
|
50
|
+
`${trace.slice(recursionStart).join(" -> ")} -> ${artifactNameToString(dep)}`;
|
|
54
51
|
throw new Error(errorMessage);
|
|
55
52
|
}
|
|
56
53
|
|
|
@@ -64,11 +61,14 @@ export class TengoTemplateCompiler {
|
|
|
64
61
|
data.hashToSource[tplLib.sourceHash] = lib.src;
|
|
65
62
|
|
|
66
63
|
// populate with transient library dependencies
|
|
67
|
-
this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
|
|
64
|
+
this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
|
|
65
|
+
...trace,
|
|
66
|
+
artifactNameToString(dep),
|
|
67
|
+
]);
|
|
68
68
|
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
|
-
case
|
|
71
|
+
case "software": {
|
|
72
72
|
const software = this.getSoftwareOrError(dep);
|
|
73
73
|
data.template.software[artifactNameToString(dep)] = {
|
|
74
74
|
...formatArtefactNameAndVersion(software.fullName),
|
|
@@ -78,7 +78,7 @@ export class TengoTemplateCompiler {
|
|
|
78
78
|
|
|
79
79
|
break;
|
|
80
80
|
}
|
|
81
|
-
case
|
|
81
|
+
case "asset": {
|
|
82
82
|
const asset = this.getAssetOrError(dep);
|
|
83
83
|
// Yes, we temporarily put assets into 'software' section of template, so controller can
|
|
84
84
|
// handle it the right way without updates
|
|
@@ -89,7 +89,7 @@ export class TengoTemplateCompiler {
|
|
|
89
89
|
data.hashToSource[asset.sourceHash] = asset.src;
|
|
90
90
|
break;
|
|
91
91
|
}
|
|
92
|
-
case
|
|
92
|
+
case "template": {
|
|
93
93
|
if (typedArtifactNamesEquals(fullName, dep))
|
|
94
94
|
// skipping self reference
|
|
95
95
|
continue;
|
|
@@ -105,10 +105,10 @@ export class TengoTemplateCompiler {
|
|
|
105
105
|
|
|
106
106
|
break;
|
|
107
107
|
}
|
|
108
|
-
case
|
|
108
|
+
case "test":
|
|
109
109
|
throw new Error(
|
|
110
|
-
`dependencies tree error: tests should never be part of template: `
|
|
111
|
-
|
|
110
|
+
`dependencies tree error: tests should never be part of template: ` +
|
|
111
|
+
`${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,
|
|
112
112
|
);
|
|
113
113
|
default:
|
|
114
114
|
assertNever(dep.type);
|
|
@@ -118,12 +118,11 @@ export class TengoTemplateCompiler {
|
|
|
118
118
|
|
|
119
119
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
120
120
|
private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {
|
|
121
|
-
if (tplSrc.fullName.type !==
|
|
122
|
-
throw new Error('unexpected source type');
|
|
121
|
+
if (tplSrc.fullName.type !== "template") throw new Error("unexpected source type");
|
|
123
122
|
|
|
124
123
|
// creating template with unpopulated dependencies
|
|
125
124
|
const tplData: CompiledTemplateV3 = {
|
|
126
|
-
type:
|
|
125
|
+
type: "pl.tengo-template.v3",
|
|
127
126
|
hashToSource: {
|
|
128
127
|
[tplSrc.sourceHash]: tplSrc.src,
|
|
129
128
|
},
|
|
@@ -158,26 +157,29 @@ export class TengoTemplateCompiler {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
getLib(name: TypedArtifactName): ArtifactSource | undefined {
|
|
161
|
-
if (name.type !==
|
|
160
|
+
if (name.type !== "library")
|
|
162
161
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
|
|
163
162
|
return this.libs.get(this.compileMode, name);
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
getLibOrError(name: TypedArtifactName): ArtifactSource {
|
|
167
166
|
const lib = this.getLib(name);
|
|
168
|
-
if (!lib)
|
|
169
|
-
throw new Error(`library not found: ${artifactNameToString(name)}`);
|
|
167
|
+
if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);
|
|
170
168
|
return lib;
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
checkLibs() {
|
|
174
172
|
this.libs.forEach(this.compileMode, (lib) => {
|
|
175
173
|
for (const dep of lib.dependencies) {
|
|
176
|
-
if (dep.type ===
|
|
177
|
-
throw new Error(
|
|
174
|
+
if (dep.type === "test")
|
|
175
|
+
throw new Error(
|
|
176
|
+
`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,
|
|
177
|
+
);
|
|
178
178
|
|
|
179
179
|
if (!this.getArtefact(dep))
|
|
180
|
-
throw new Error(
|
|
180
|
+
throw new Error(
|
|
181
|
+
`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,
|
|
182
|
+
);
|
|
181
183
|
}
|
|
182
184
|
});
|
|
183
185
|
}
|
|
@@ -195,7 +197,7 @@ export class TengoTemplateCompiler {
|
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
getSoftware(name: TypedArtifactName): ArtifactSource | undefined {
|
|
198
|
-
if (name.type !==
|
|
200
|
+
if (name.type !== "software")
|
|
199
201
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
|
|
200
202
|
|
|
201
203
|
return this.software.get(this.compileMode, name);
|
|
@@ -203,8 +205,7 @@ export class TengoTemplateCompiler {
|
|
|
203
205
|
|
|
204
206
|
getSoftwareOrError(name: TypedArtifactName): ArtifactSource {
|
|
205
207
|
const software = this.getSoftware(name);
|
|
206
|
-
if (!software)
|
|
207
|
-
throw new Error(`software info not found: ${artifactNameToString(name)}`);
|
|
208
|
+
if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);
|
|
208
209
|
return software;
|
|
209
210
|
}
|
|
210
211
|
|
|
@@ -221,7 +222,7 @@ export class TengoTemplateCompiler {
|
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
getAsset(name: TypedArtifactName): ArtifactSource | undefined {
|
|
224
|
-
if (name.type !==
|
|
225
|
+
if (name.type !== "asset")
|
|
225
226
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
|
|
226
227
|
|
|
227
228
|
return this.assets.get(this.compileMode, name);
|
|
@@ -229,8 +230,7 @@ export class TengoTemplateCompiler {
|
|
|
229
230
|
|
|
230
231
|
getAssetOrError(name: TypedArtifactName): ArtifactSource {
|
|
231
232
|
const asset = this.getAsset(name);
|
|
232
|
-
if (!asset)
|
|
233
|
-
throw new Error(`asset info not found: ${artifactNameToString(name)}`);
|
|
233
|
+
if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);
|
|
234
234
|
return asset;
|
|
235
235
|
}
|
|
236
236
|
|
|
@@ -247,29 +247,28 @@ export class TengoTemplateCompiler {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {
|
|
250
|
-
if (name.type !==
|
|
250
|
+
if (name.type !== "template")
|
|
251
251
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
|
|
252
252
|
return this.templates.get(this.compileMode, name);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
getTemplateOrError(name: TypedArtifactName): TemplateWithSource {
|
|
256
256
|
const tpl = this.getTemplate(name);
|
|
257
|
-
if (!tpl)
|
|
258
|
-
throw new Error(`template not found: ${artifactNameToString(name)}`);
|
|
257
|
+
if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);
|
|
259
258
|
return tpl;
|
|
260
259
|
}
|
|
261
260
|
|
|
262
261
|
getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {
|
|
263
262
|
switch (name.type) {
|
|
264
|
-
case
|
|
263
|
+
case "template":
|
|
265
264
|
return this.getTemplate(name);
|
|
266
|
-
case
|
|
265
|
+
case "library":
|
|
267
266
|
return this.getLib(name);
|
|
268
|
-
case
|
|
267
|
+
case "software":
|
|
269
268
|
return this.getSoftware(name);
|
|
270
|
-
case
|
|
269
|
+
case "asset":
|
|
271
270
|
return this.getAsset(name);
|
|
272
|
-
case
|
|
271
|
+
case "test":
|
|
273
272
|
// Tests are ignored by the complier. They should never be compiled into templates or libs and
|
|
274
273
|
// should never be a dependency.
|
|
275
274
|
return undefined;
|
|
@@ -289,15 +288,15 @@ export class TengoTemplateCompiler {
|
|
|
289
288
|
let current: ArtifactSource[] = [];
|
|
290
289
|
|
|
291
290
|
for (const src of sources) {
|
|
292
|
-
if (src.fullName.type ===
|
|
291
|
+
if (src.fullName.type === "library") {
|
|
293
292
|
// add libraries 'as-is' to be able to resolve them as dependencies
|
|
294
293
|
this.addLib(src);
|
|
295
294
|
result.libs.push(src);
|
|
296
|
-
} else if (src.fullName.type ===
|
|
295
|
+
} else if (src.fullName.type === "software") {
|
|
297
296
|
// add software 'as-is' to be able to resolve them as dependencies
|
|
298
297
|
this.addSoftware(src);
|
|
299
298
|
result.software.push(src);
|
|
300
|
-
} else if (src.fullName.type ===
|
|
299
|
+
} else if (src.fullName.type === "asset") {
|
|
301
300
|
// add assets 'as-is' to be able to resolve them as dependencies
|
|
302
301
|
this.addAsset(src);
|
|
303
302
|
result.assets.push(src);
|
|
@@ -317,10 +316,11 @@ export class TengoTemplateCompiler {
|
|
|
317
316
|
//
|
|
318
317
|
// This is equivalent to topological sorting of input sources.
|
|
319
318
|
//
|
|
320
|
-
const unsatisfied = src.dependencies.filter(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
319
|
+
const unsatisfied = src.dependencies.filter(
|
|
320
|
+
(dep) =>
|
|
321
|
+
!this.getArtefact(dep) &&
|
|
322
|
+
// allow self reference for templates
|
|
323
|
+
!(src.fullName.type === "template" && typedArtifactNamesEquals(src.fullName, dep)),
|
|
324
324
|
);
|
|
325
325
|
if (unsatisfied.length > 0) {
|
|
326
326
|
let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
|
|
@@ -334,22 +334,22 @@ export class TengoTemplateCompiler {
|
|
|
334
334
|
|
|
335
335
|
// type specific processing
|
|
336
336
|
switch (src.fullName.type) {
|
|
337
|
-
case
|
|
337
|
+
case "library":
|
|
338
338
|
// libraries are added as is
|
|
339
339
|
this.addLib(src);
|
|
340
340
|
result.libs.push(src);
|
|
341
341
|
break;
|
|
342
|
-
case
|
|
342
|
+
case "software":
|
|
343
343
|
// software dependencies are added as is
|
|
344
344
|
this.addSoftware(src);
|
|
345
345
|
result.software.push(src);
|
|
346
346
|
break;
|
|
347
|
-
case
|
|
347
|
+
case "asset":
|
|
348
348
|
// software dependencies are added as is
|
|
349
349
|
this.addAsset(src);
|
|
350
350
|
result.assets.push(src);
|
|
351
351
|
break;
|
|
352
|
-
case
|
|
352
|
+
case "template":
|
|
353
353
|
// templates are compiled and then added
|
|
354
354
|
try {
|
|
355
355
|
const tpl = this.compileAndAddTemplate(src);
|
|
@@ -364,7 +364,7 @@ export class TengoTemplateCompiler {
|
|
|
364
364
|
unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet
|
|
365
365
|
}
|
|
366
366
|
break;
|
|
367
|
-
case
|
|
367
|
+
case "test":
|
|
368
368
|
// Ignore tests: they never should be part of compiled code or be a dependency.
|
|
369
369
|
break;
|
|
370
370
|
default:
|
|
@@ -375,7 +375,7 @@ export class TengoTemplateCompiler {
|
|
|
375
375
|
// checking that we successfully added at least one source,
|
|
376
376
|
// if not all the source files in unprocessed array have unmet dependencies
|
|
377
377
|
if (current.length === unprocessed.length) {
|
|
378
|
-
let errorMessage =
|
|
378
|
+
let errorMessage = "";
|
|
379
379
|
|
|
380
380
|
for (const u of unprocessed) {
|
|
381
381
|
errorMessage += `\n${u.err.message}`;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { TemplateDataV3, TemplateLibDataV3 } from
|
|
2
|
-
import type { CompilerOption } from
|
|
3
|
-
import * as util from
|
|
1
|
+
import type { TemplateDataV3, TemplateLibDataV3 } from "@milaboratories/pl-model-backend";
|
|
2
|
+
import type { CompilerOption } from "./package";
|
|
3
|
+
import * as util from "./util";
|
|
4
4
|
|
|
5
5
|
export function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {
|
|
6
6
|
for (const opt of opts) {
|
|
7
7
|
switch (opt.name) {
|
|
8
|
-
case
|
|
8
|
+
case "hash_override": {
|
|
9
9
|
tpl.hashOverride = hashOverride(opt.args);
|
|
10
10
|
break;
|
|
11
11
|
}
|
|
@@ -16,12 +16,12 @@ export function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: Templa
|
|
|
16
16
|
export function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {
|
|
17
17
|
for (const opt of opts) {
|
|
18
18
|
switch (opt.name) {
|
|
19
|
-
case
|
|
19
|
+
case "hash_override": {
|
|
20
20
|
throw new Error(
|
|
21
|
-
`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +
|
|
22
|
+
` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +
|
|
23
|
+
` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +
|
|
24
|
+
` we are doomed to never find the ends of a knot if anything goes wrong.`,
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -31,7 +31,7 @@ export function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: Templa
|
|
|
31
31
|
export function hashOverride(args: string[]): string {
|
|
32
32
|
if (args.length != 1) {
|
|
33
33
|
throw new Error(
|
|
34
|
-
|
|
34
|
+
"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.",
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -39,11 +39,11 @@ export function hashOverride(args: string[]): string {
|
|
|
39
39
|
|
|
40
40
|
if (!util.isUUID(override)) {
|
|
41
41
|
throw new Error(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
"hash_override must contain valid UUID as an override. As hash_override affects deduplication," +
|
|
43
|
+
" it becomes completely not possible to distinguish several different templates from each other on backend's side." +
|
|
44
|
+
' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,' +
|
|
45
|
+
" they will be marked as interchangeable on backend's side with unpredictable consequences." +
|
|
46
|
+
" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety",
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { fullNameFromFileName } from
|
|
2
|
-
import { expect, describe, test } from
|
|
1
|
+
import { fullNameFromFileName } from "./main";
|
|
2
|
+
import { expect, describe, test } from "vitest";
|
|
3
3
|
|
|
4
|
-
describe.concurrent(
|
|
4
|
+
describe.concurrent("fullNameFromFileName", () => {
|
|
5
5
|
const defaultPackageId = {
|
|
6
|
-
name:
|
|
7
|
-
version:
|
|
6
|
+
name: "test-package",
|
|
7
|
+
version: "1.0.0",
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
test.each([
|
|
11
11
|
{
|
|
12
|
-
filename:
|
|
13
|
-
expectedType:
|
|
14
|
-
expectedId:
|
|
12
|
+
filename: "myLib.lib.tengo",
|
|
13
|
+
expectedType: "library",
|
|
14
|
+
expectedId: "myLib",
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
filename:
|
|
18
|
-
expectedType:
|
|
19
|
-
expectedId:
|
|
17
|
+
filename: "myTemplate.tpl.tengo",
|
|
18
|
+
expectedType: "template",
|
|
19
|
+
expectedId: "myTemplate",
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
|
-
filename:
|
|
23
|
-
expectedType:
|
|
24
|
-
expectedId:
|
|
22
|
+
filename: "mySoftware.sw.json",
|
|
23
|
+
expectedType: "software",
|
|
24
|
+
expectedId: "mySoftware",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
filename:
|
|
28
|
-
expectedType:
|
|
29
|
-
expectedId:
|
|
27
|
+
filename: "myAsset.as.json",
|
|
28
|
+
expectedType: "asset",
|
|
29
|
+
expectedId: "myAsset",
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
filename:
|
|
33
|
-
expectedType:
|
|
34
|
-
expectedId:
|
|
35
|
-
}
|
|
36
|
-
])(
|
|
32
|
+
filename: "myTest.test.tengo",
|
|
33
|
+
expectedType: "test",
|
|
34
|
+
expectedId: "myTest",
|
|
35
|
+
},
|
|
36
|
+
])("should correctly parse %s as %s with id %s", ({ filename, expectedType, expectedId }) => {
|
|
37
37
|
const result = fullNameFromFileName(defaultPackageId, filename);
|
|
38
38
|
expect(result).toEqual({
|
|
39
39
|
pkg: defaultPackageId.name,
|
|
40
40
|
version: defaultPackageId.version,
|
|
41
41
|
id: expectedId,
|
|
42
|
-
type: expectedType
|
|
42
|
+
type: expectedType,
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
});
|