@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/source.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
import {
|
|
3
3
|
type TypedArtifactName,
|
|
4
4
|
type FullArtifactName,
|
|
@@ -6,42 +6,42 @@ import {
|
|
|
6
6
|
type CompileMode,
|
|
7
7
|
type CompilerOption,
|
|
8
8
|
fullNameToString,
|
|
9
|
-
} from
|
|
10
|
-
import type { ArtifactMap } from
|
|
11
|
-
import { createArtifactNameSet } from
|
|
12
|
-
import { createHash } from
|
|
13
|
-
import type { MiLogger } from
|
|
9
|
+
} from "./package";
|
|
10
|
+
import type { ArtifactMap } from "./artifactset";
|
|
11
|
+
import { createArtifactNameSet } from "./artifactset";
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import type { MiLogger } from "@milaboratories/ts-helpers";
|
|
14
14
|
|
|
15
15
|
// matches any valid name in tengo. Don't forget to use '\b' when needed to limit the boundaries!
|
|
16
|
-
const namePattern =
|
|
16
|
+
const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
|
|
17
17
|
|
|
18
18
|
const functionCallRE = (moduleName: string, fnName: string) => {
|
|
19
19
|
return new RegExp(
|
|
20
|
-
`\\b${moduleName}\\.(?<fnCall>(?<fnName>`
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
`\\b${moduleName}\\.(?<fnCall>(?<fnName>` +
|
|
21
|
+
fnName +
|
|
22
|
+
`)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`,
|
|
23
|
+
"g",
|
|
24
24
|
);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const functionCallLikeRE = (moduleName: string, fnName: string) => {
|
|
28
|
-
return new RegExp(
|
|
29
|
-
`\\b${moduleName}\\.(?<fnName>`
|
|
30
|
-
+ fnName
|
|
31
|
-
+ `)\\s*\\(`,
|
|
32
|
-
'g',
|
|
33
|
-
);
|
|
28
|
+
return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
|
|
34
29
|
};
|
|
35
30
|
|
|
36
|
-
export const newGetTemplateIdRE = (moduleName: string) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
31
|
+
export const newGetTemplateIdRE = (moduleName: string) =>
|
|
32
|
+
functionCallRE(moduleName, "getTemplateId");
|
|
33
|
+
export const newGetSoftwareInfoRE = (moduleName: string) =>
|
|
34
|
+
functionCallRE(moduleName, "getSoftwareInfo");
|
|
35
|
+
|
|
36
|
+
const newImportTemplateRE = (moduleName: string) => functionCallRE(moduleName, "importTemplate");
|
|
37
|
+
const newImportTemplateDetector = (moduleName: string) =>
|
|
38
|
+
functionCallLikeRE(moduleName, "importTemplate");
|
|
39
|
+
const newImportSoftwareRE = (moduleName: string) => functionCallRE(moduleName, "importSoftware");
|
|
40
|
+
const newImportSoftwareDetector = (moduleName: string) =>
|
|
41
|
+
functionCallLikeRE(moduleName, "importSoftware");
|
|
42
|
+
const newImportAssetRE = (moduleName: string) => functionCallRE(moduleName, "importAsset");
|
|
43
|
+
const newImportAssetDetector = (moduleName: string) =>
|
|
44
|
+
functionCallLikeRE(moduleName, "importAsset");
|
|
45
45
|
|
|
46
46
|
const emptyLineRE = /^\s*$/;
|
|
47
47
|
const compilerOptionRE = /^\/\/tengo:[\w]/;
|
|
@@ -69,11 +69,11 @@ const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <m
|
|
|
69
69
|
* //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
|
|
70
70
|
*/
|
|
71
71
|
const parseComplierOption = (opt: string): CompilerOption => {
|
|
72
|
-
const parts = opt.split(
|
|
73
|
-
const namePart = parts[0].split(
|
|
72
|
+
const parts = opt.split(" ");
|
|
73
|
+
const namePart = parts[0].split(":");
|
|
74
74
|
if (namePart.length != 2) {
|
|
75
75
|
throw new Error(
|
|
76
|
-
|
|
76
|
+
"compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'",
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
const optName = namePart[1];
|
|
@@ -133,7 +133,15 @@ export function parseSource(
|
|
|
133
133
|
): ArtifactSource {
|
|
134
134
|
const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
|
|
135
135
|
|
|
136
|
-
return new ArtifactSource(
|
|
136
|
+
return new ArtifactSource(
|
|
137
|
+
mode,
|
|
138
|
+
fullSourceName,
|
|
139
|
+
getSha256(normalized),
|
|
140
|
+
normalized,
|
|
141
|
+
"",
|
|
142
|
+
deps.array,
|
|
143
|
+
opts,
|
|
144
|
+
);
|
|
137
145
|
}
|
|
138
146
|
|
|
139
147
|
/**
|
|
@@ -149,15 +157,15 @@ function parseSourceData(
|
|
|
149
157
|
fullSourceName: FullArtifactName,
|
|
150
158
|
globalizeImports: boolean,
|
|
151
159
|
): {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
normalized: string;
|
|
161
|
+
deps: ArtifactMap<TypedArtifactName>;
|
|
162
|
+
opts: CompilerOption[];
|
|
163
|
+
} {
|
|
156
164
|
const dependencySet = createArtifactNameSet();
|
|
157
165
|
const optionList: CompilerOption[] = [];
|
|
158
166
|
|
|
159
167
|
// iterating over lines
|
|
160
|
-
const lines = src.split(
|
|
168
|
+
const lines = src.split("\n");
|
|
161
169
|
|
|
162
170
|
// processedLines keep all the original lines from <src>.
|
|
163
171
|
// If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines
|
|
@@ -169,7 +177,7 @@ function parseSourceData(
|
|
|
169
177
|
canDetectOptions: true,
|
|
170
178
|
artifactImportREs: new Map<string, [ArtifactType, RegExp][]>(),
|
|
171
179
|
importLikeREs: new Map<string, [ArtifactType, RegExp][]>(),
|
|
172
|
-
multilineStatement:
|
|
180
|
+
multilineStatement: "",
|
|
173
181
|
lineNo: 0,
|
|
174
182
|
};
|
|
175
183
|
|
|
@@ -177,13 +185,12 @@ function parseSourceData(
|
|
|
177
185
|
parserContext.lineNo++;
|
|
178
186
|
|
|
179
187
|
try {
|
|
180
|
-
const {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
);
|
|
188
|
+
const {
|
|
189
|
+
line: processedLine,
|
|
190
|
+
context: newContext,
|
|
191
|
+
artifacts,
|
|
192
|
+
option,
|
|
193
|
+
} = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
|
|
187
194
|
processedLines.push(processedLine);
|
|
188
195
|
parserContext = newContext;
|
|
189
196
|
|
|
@@ -195,12 +202,15 @@ function parseSourceData(
|
|
|
195
202
|
}
|
|
196
203
|
} catch (error: unknown) {
|
|
197
204
|
const err = error as Error;
|
|
198
|
-
throw new Error(
|
|
205
|
+
throw new Error(
|
|
206
|
+
`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`,
|
|
207
|
+
{ cause: err },
|
|
208
|
+
);
|
|
199
209
|
}
|
|
200
210
|
}
|
|
201
211
|
|
|
202
212
|
return {
|
|
203
|
-
normalized: processedLines.join(
|
|
213
|
+
normalized: processedLines.join("\n"),
|
|
204
214
|
deps: dependencySet,
|
|
205
215
|
opts: optionList,
|
|
206
216
|
};
|
|
@@ -233,7 +243,7 @@ export function parseSingleSourceLine(
|
|
|
233
243
|
if (multilineCommentEndRE.exec(line)) {
|
|
234
244
|
context.isInCommentBlock = false;
|
|
235
245
|
}
|
|
236
|
-
return { line:
|
|
246
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
237
247
|
}
|
|
238
248
|
|
|
239
249
|
if (compilerOptionRE.exec(line)) {
|
|
@@ -241,7 +251,9 @@ export function parseSingleSourceLine(
|
|
|
241
251
|
logger.error(
|
|
242
252
|
`[line ${context.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`,
|
|
243
253
|
);
|
|
244
|
-
throw new Error(
|
|
254
|
+
throw new Error(
|
|
255
|
+
"tengo compiler options ('//tengo:' comments) can be set only in file header",
|
|
256
|
+
);
|
|
245
257
|
}
|
|
246
258
|
return { line, context, artifacts: [], option: parseComplierOption(line) };
|
|
247
259
|
}
|
|
@@ -254,18 +266,18 @@ export function parseSingleSourceLine(
|
|
|
254
266
|
}
|
|
255
267
|
|
|
256
268
|
if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {
|
|
257
|
-
return { line:
|
|
269
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
const canBeInlinedComment = line.includes(
|
|
272
|
+
const canBeInlinedComment = line.includes("*/");
|
|
261
273
|
if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
|
|
262
274
|
context.isInCommentBlock = true;
|
|
263
|
-
return { line:
|
|
275
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
264
276
|
}
|
|
265
277
|
|
|
266
278
|
const statement = context.multilineStatement + line.trim();
|
|
267
279
|
|
|
268
|
-
const mayContainAComment = line.includes(
|
|
280
|
+
const mayContainAComment = line.includes("//") || line.includes("/*");
|
|
269
281
|
if (multilineStatementRE.test(line) && !mayContainAComment) {
|
|
270
282
|
// We accumulate multiline statements into single line before analyzing them.
|
|
271
283
|
// This dramatically simplifies parsing logic: things like
|
|
@@ -295,7 +307,7 @@ export function parseSingleSourceLine(
|
|
|
295
307
|
return result;
|
|
296
308
|
}
|
|
297
309
|
|
|
298
|
-
context.multilineStatement =
|
|
310
|
+
context.multilineStatement = ""; // reset accumulated multiline statement parts once we reach statement end.
|
|
299
311
|
|
|
300
312
|
if (emptyLineRE.exec(statement)) {
|
|
301
313
|
return { line, context, artifacts: [], option: undefined };
|
|
@@ -320,60 +332,63 @@ function processModuleImport(
|
|
|
320
332
|
// If we have plapi, ll or assets, then try to parse
|
|
321
333
|
// getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.
|
|
322
334
|
|
|
323
|
-
if (iInfo.module ===
|
|
335
|
+
if (iInfo.module === "plapi") {
|
|
324
336
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
325
337
|
context.artifactImportREs.set(iInfo.module, [
|
|
326
|
-
[
|
|
327
|
-
[
|
|
338
|
+
["template", newGetTemplateIdRE(iInfo.alias)],
|
|
339
|
+
["software", newGetSoftwareInfoRE(iInfo.alias)],
|
|
328
340
|
]);
|
|
329
341
|
}
|
|
330
342
|
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
331
343
|
}
|
|
332
344
|
|
|
333
345
|
if (
|
|
334
|
-
iInfo.module ===
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
346
|
+
iInfo.module === "@milaboratory/tengo-sdk:ll" ||
|
|
347
|
+
iInfo.module === "@platforma-sdk/workflow-tengo:ll" ||
|
|
348
|
+
((localPackageName === "@milaboratory/tengo-sdk" ||
|
|
349
|
+
localPackageName === "@platforma-sdk/workflow-tengo") &&
|
|
350
|
+
iInfo.module === ":ll")
|
|
339
351
|
) {
|
|
340
352
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
341
353
|
context.artifactImportREs.set(iInfo.module, [
|
|
342
|
-
[
|
|
343
|
-
[
|
|
354
|
+
["template", newImportTemplateRE(iInfo.alias)],
|
|
355
|
+
["software", newImportSoftwareRE(iInfo.alias)],
|
|
344
356
|
]);
|
|
345
357
|
}
|
|
346
358
|
}
|
|
347
359
|
|
|
348
360
|
if (
|
|
349
|
-
iInfo.module ===
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
361
|
+
iInfo.module === "@milaboratory/tengo-sdk:assets" ||
|
|
362
|
+
iInfo.module === "@platforma-sdk/workflow-tengo:assets" ||
|
|
363
|
+
((localPackageName === "@milaboratory/tengo-sdk" ||
|
|
364
|
+
localPackageName === "@platforma-sdk/workflow-tengo") &&
|
|
365
|
+
iInfo.module === ":assets")
|
|
354
366
|
) {
|
|
355
367
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
356
368
|
context.artifactImportREs.set(iInfo.module, [
|
|
357
|
-
[
|
|
358
|
-
[
|
|
359
|
-
[
|
|
369
|
+
["template", newImportTemplateRE(iInfo.alias)],
|
|
370
|
+
["software", newImportSoftwareRE(iInfo.alias)],
|
|
371
|
+
["asset", newImportAssetRE(iInfo.alias)],
|
|
360
372
|
]);
|
|
361
373
|
context.importLikeREs.set(iInfo.module, [
|
|
362
|
-
[
|
|
363
|
-
[
|
|
364
|
-
[
|
|
374
|
+
["template", newImportTemplateDetector(iInfo.alias)],
|
|
375
|
+
["software", newImportSoftwareDetector(iInfo.alias)],
|
|
376
|
+
["asset", newImportAssetDetector(iInfo.alias)],
|
|
365
377
|
]);
|
|
366
378
|
}
|
|
367
379
|
}
|
|
368
380
|
|
|
369
|
-
const artifact = parseArtifactName(iInfo.module,
|
|
381
|
+
const artifact = parseArtifactName(iInfo.module, "library", localPackageName);
|
|
370
382
|
if (!artifact) {
|
|
371
383
|
// not a Platforma Tengo library import
|
|
372
384
|
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
373
385
|
}
|
|
374
386
|
|
|
375
387
|
if (globalizeImports) {
|
|
376
|
-
originalLine = originalLine.replace(
|
|
388
|
+
originalLine = originalLine.replace(
|
|
389
|
+
importInstruction[0],
|
|
390
|
+
` := import("${artifact.pkg}:${artifact.id}")`,
|
|
391
|
+
);
|
|
377
392
|
}
|
|
378
393
|
|
|
379
394
|
return { line: originalLine, context, artifacts: [artifact], option: undefined };
|
|
@@ -396,7 +411,14 @@ function processAssetImport(
|
|
|
396
411
|
const importInstruction = importRE.exec(statement);
|
|
397
412
|
|
|
398
413
|
if (importInstruction) {
|
|
399
|
-
return processModuleImport(
|
|
414
|
+
return processModuleImport(
|
|
415
|
+
importInstruction,
|
|
416
|
+
originalLine,
|
|
417
|
+
statement,
|
|
418
|
+
context,
|
|
419
|
+
localPackageName,
|
|
420
|
+
globalizeImports,
|
|
421
|
+
);
|
|
400
422
|
}
|
|
401
423
|
|
|
402
424
|
if (context.artifactImportREs.size > 0) {
|
|
@@ -429,7 +451,10 @@ function processAssetImport(
|
|
|
429
451
|
|
|
430
452
|
if (globalizeImports) {
|
|
431
453
|
// Replace all occurrences of this fnCall in originalLine
|
|
432
|
-
originalLine = originalLine.replaceAll(
|
|
454
|
+
originalLine = originalLine.replaceAll(
|
|
455
|
+
fnCall,
|
|
456
|
+
`${fnName}("${artifact.pkg}:${artifact.id}")`,
|
|
457
|
+
);
|
|
433
458
|
}
|
|
434
459
|
}
|
|
435
460
|
|
|
@@ -446,7 +471,9 @@ function processAssetImport(
|
|
|
446
471
|
continue;
|
|
447
472
|
}
|
|
448
473
|
|
|
449
|
-
throw Error(
|
|
474
|
+
throw Error(
|
|
475
|
+
`incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware("sw:main")').`,
|
|
476
|
+
);
|
|
450
477
|
}
|
|
451
478
|
}
|
|
452
479
|
}
|
|
@@ -504,5 +531,5 @@ function parseArtifactName(
|
|
|
504
531
|
}
|
|
505
532
|
|
|
506
533
|
export function getSha256(source: string): string {
|
|
507
|
-
return createHash(
|
|
534
|
+
return createHash("sha256").update(source).digest("hex");
|
|
508
535
|
}
|
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
import { newTemplateFromContent, newTemplateFromData
|
|
2
|
-
import { formatArtefactNameAndVersion, FullArtifactName } from
|
|
3
|
-
import { test, expect } from
|
|
1
|
+
import { newTemplateFromContent, newTemplateFromData } from "./template";
|
|
2
|
+
import { formatArtefactNameAndVersion, FullArtifactName } from "./package";
|
|
3
|
+
import { test, expect } from "vitest";
|
|
4
4
|
|
|
5
|
-
test(
|
|
5
|
+
test("template serialization / deserialization", () => {
|
|
6
6
|
const name: FullArtifactName = {
|
|
7
|
-
type:
|
|
8
|
-
pkg:
|
|
9
|
-
id:
|
|
10
|
-
version:
|
|
7
|
+
type: "template",
|
|
8
|
+
pkg: "@milaboratory/some-package",
|
|
9
|
+
id: "the-template",
|
|
10
|
+
version: "1.2.3",
|
|
11
11
|
};
|
|
12
|
-
const template1 = newTemplateFromData(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name: '@milaboratory/some-package:the-library',
|
|
28
|
-
version: '1.2.3',
|
|
29
|
-
sourceHash: 'asdasd'
|
|
30
|
-
}
|
|
12
|
+
const template1 = newTemplateFromData("dist", name, {
|
|
13
|
+
type: "pl.tengo-template.v3",
|
|
14
|
+
hashToSource: {
|
|
15
|
+
asdasd: "src1...",
|
|
16
|
+
asdasd2: "src2...",
|
|
17
|
+
asdasd3: "src3...",
|
|
18
|
+
},
|
|
19
|
+
template: {
|
|
20
|
+
sourceHash: "asdasd3",
|
|
21
|
+
...formatArtefactNameAndVersion(name),
|
|
22
|
+
libs: {
|
|
23
|
+
asdasd: {
|
|
24
|
+
name: "@milaboratory/some-package:the-library",
|
|
25
|
+
version: "1.2.3",
|
|
26
|
+
sourceHash: "asdasd",
|
|
31
27
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
},
|
|
29
|
+
templates: {
|
|
30
|
+
asdasd2: {
|
|
31
|
+
name: "@milaboratory/some-package:the-template-1",
|
|
32
|
+
version: "1.2.3",
|
|
33
|
+
libs: {
|
|
34
|
+
"@milaboratory/some-package:the-library:1.2.4": {
|
|
35
|
+
name: "@milaboratory/some-package:the-library",
|
|
36
|
+
version: "1.2.4",
|
|
37
|
+
sourceHash: "asdasd2",
|
|
42
38
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
},
|
|
40
|
+
templates: {},
|
|
41
|
+
software: {},
|
|
42
|
+
assets: {},
|
|
43
|
+
sourceHash: "src 1...",
|
|
48
44
|
},
|
|
49
|
-
software: {},
|
|
50
|
-
assets: {},
|
|
51
45
|
},
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
software: {},
|
|
47
|
+
assets: {},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
54
50
|
|
|
55
51
|
const template2 = newTemplateFromContent(
|
|
56
|
-
|
|
57
|
-
{ type:
|
|
52
|
+
"dist",
|
|
53
|
+
{ type: "template", pkg: "@milaboratory/some-package", id: "the-template", version: "1.2.3" },
|
|
58
54
|
template1.content,
|
|
59
55
|
);
|
|
60
56
|
|
|
61
|
-
console.log(
|
|
57
|
+
console.log(
|
|
58
|
+
"Size: raw",
|
|
59
|
+
JSON.stringify(template1.data).length,
|
|
60
|
+
"compressed",
|
|
61
|
+
template1.content.byteLength,
|
|
62
|
+
);
|
|
62
63
|
|
|
63
64
|
expect(template2.data).toStrictEqual(template1.data);
|
|
64
65
|
});
|
package/src/compiler/template.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from './package';
|
|
6
|
-
import {
|
|
7
|
-
fullNameWithoutTypeToString,
|
|
8
|
-
parseArtefactNameAndVersion,
|
|
9
|
-
} from './package';
|
|
10
|
-
import type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';
|
|
11
|
-
import {
|
|
12
|
-
parseTemplate,
|
|
13
|
-
serializeTemplate,
|
|
14
|
-
} from '@milaboratories/pl-model-backend';
|
|
1
|
+
import type { CompileMode, FullArtifactName, FullArtifactNameWithoutType } from "./package";
|
|
2
|
+
import { fullNameWithoutTypeToString, parseArtefactNameAndVersion } from "./package";
|
|
3
|
+
import type { CompiledTemplateV3 } from "@milaboratories/pl-model-backend";
|
|
4
|
+
import { parseTemplate, serializeTemplate } from "@milaboratories/pl-model-backend";
|
|
15
5
|
|
|
16
6
|
/** Just a holder for template data, compilation options, full name and source code.
|
|
17
7
|
* It mimics ArtifactSource interface.
|
|
@@ -66,8 +56,8 @@ export function newTemplateFromContent(
|
|
|
66
56
|
content: Uint8Array,
|
|
67
57
|
): Template {
|
|
68
58
|
const data = parseTemplate(content);
|
|
69
|
-
if (data.type !==
|
|
70
|
-
throw new Error(
|
|
59
|
+
if (data.type !== "pl.tengo-template.v3") {
|
|
60
|
+
throw new Error("malformed v3 template");
|
|
71
61
|
}
|
|
72
62
|
|
|
73
63
|
validateTemplateName(fullName, data);
|
|
@@ -91,12 +81,12 @@ function validateTemplateName(fullName: FullArtifactName, data: CompiledTemplate
|
|
|
91
81
|
const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data.template);
|
|
92
82
|
|
|
93
83
|
if (
|
|
94
|
-
nameFromData.pkg !== fullName.pkg
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
nameFromData.pkg !== fullName.pkg ||
|
|
85
|
+
nameFromData.id !== fullName.id ||
|
|
86
|
+
nameFromData.version !== fullName.version
|
|
97
87
|
)
|
|
98
88
|
throw new Error(
|
|
99
|
-
`Compiled template name don't match it's package and file names: `
|
|
100
|
-
|
|
89
|
+
`Compiled template name don't match it's package and file names: ` +
|
|
90
|
+
`${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,
|
|
101
91
|
);
|
|
102
92
|
}
|