@platforma-sdk/tengo-builder 2.4.25 → 2.4.27
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 +8 -8
- 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
package/dist/compiler/source.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createHash } from
|
|
1
|
+
import { fullNameToString } from "./package.js";
|
|
2
|
+
import { createArtifactNameSet } from "./artifactset.js";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
//#region src/compiler/source.ts
|
|
7
7
|
const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
|
|
8
8
|
const functionCallRE = (moduleName, fnName) => {
|
|
9
|
-
|
|
10
|
-
fnName +
|
|
11
|
-
`)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`, "g");
|
|
9
|
+
return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` + fnName + `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`, "g");
|
|
12
10
|
};
|
|
13
11
|
const functionCallLikeRE = (moduleName, fnName) => {
|
|
14
|
-
|
|
12
|
+
return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
|
|
15
13
|
};
|
|
16
14
|
const newGetTemplateIdRE = (moduleName) => functionCallRE(moduleName, "getTemplateId");
|
|
17
15
|
const newGetSoftwareInfoRE = (moduleName) => functionCallRE(moduleName, "getSoftwareInfo");
|
|
@@ -25,323 +23,260 @@ const emptyLineRE = /^\s*$/;
|
|
|
25
23
|
const compilerOptionRE = /^\/\/tengo:[\w]/;
|
|
26
24
|
const wrongCompilerOptionRE = /^\s*\/\/\s*tengo:\s*./;
|
|
27
25
|
const singlelineCommentRE = /^\s*(\/\/)/;
|
|
28
|
-
const singlelineTerminatedCommentRE = /^\s*\/\*.*\*\/\s*$/;
|
|
26
|
+
const singlelineTerminatedCommentRE = /^\s*\/\*.*\*\/\s*$/;
|
|
29
27
|
const multilineCommentStartRE = /^\s*\/\*/;
|
|
30
28
|
const multilineCommentEndRE = /\*\//;
|
|
31
|
-
const multilineStatementRE = /[.,]\s*$/;
|
|
32
|
-
// import could only be an assignment in a statement,
|
|
33
|
-
// other ways could break a compilation.
|
|
29
|
+
const multilineStatementRE = /[.,]\s*$/;
|
|
34
30
|
const importRE = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/;
|
|
35
31
|
const importNameRE = new RegExp(`\\b(?<importName>${namePattern}(\\.${namePattern})*)${importRE.source}`);
|
|
36
|
-
const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
|
|
32
|
+
const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
|
|
37
33
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
* Parse compiler option string representation
|
|
35
|
+
* Compiler option line is a comment starting with '//tengo:', say
|
|
36
|
+
* //tengo:hash_override tralala
|
|
37
|
+
*
|
|
38
|
+
* The common compiler option syntax is:
|
|
39
|
+
* //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
|
|
40
|
+
*/
|
|
45
41
|
const parseComplierOption = (opt) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
const parts = opt.split(" ");
|
|
43
|
+
const namePart = parts[0].split(":");
|
|
44
|
+
if (namePart.length != 2) throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");
|
|
45
|
+
return {
|
|
46
|
+
name: namePart[1],
|
|
47
|
+
args: parts.slice(1)
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var ArtifactSource = class {
|
|
51
|
+
constructor(compileMode, fullName, sourceHash, src, srcName, dependencies, compilerOptions) {
|
|
52
|
+
this.compileMode = compileMode;
|
|
53
|
+
this.fullName = fullName;
|
|
54
|
+
this.sourceHash = sourceHash;
|
|
55
|
+
this.src = src;
|
|
56
|
+
this.srcName = srcName;
|
|
57
|
+
this.dependencies = dependencies;
|
|
58
|
+
this.compilerOptions = compilerOptions;
|
|
59
|
+
}
|
|
56
60
|
};
|
|
57
|
-
class ArtifactSource {
|
|
58
|
-
compileMode;
|
|
59
|
-
fullName;
|
|
60
|
-
sourceHash;
|
|
61
|
-
src;
|
|
62
|
-
srcName;
|
|
63
|
-
dependencies;
|
|
64
|
-
compilerOptions;
|
|
65
|
-
constructor(
|
|
66
|
-
/** The mode this artifact was built (dev or dist) */
|
|
67
|
-
compileMode,
|
|
68
|
-
/** Full artifact id, including package version */
|
|
69
|
-
fullName,
|
|
70
|
-
/** Hash of the source code */
|
|
71
|
-
sourceHash,
|
|
72
|
-
/** Normalized source code */
|
|
73
|
-
src,
|
|
74
|
-
/** Path to source file where artifact came from */
|
|
75
|
-
srcName,
|
|
76
|
-
/** List of dependencies */
|
|
77
|
-
dependencies,
|
|
78
|
-
/** Additional compiler options detected in source code */
|
|
79
|
-
compilerOptions) {
|
|
80
|
-
this.compileMode = compileMode;
|
|
81
|
-
this.fullName = fullName;
|
|
82
|
-
this.sourceHash = sourceHash;
|
|
83
|
-
this.src = src;
|
|
84
|
-
this.srcName = srcName;
|
|
85
|
-
this.dependencies = dependencies;
|
|
86
|
-
this.compilerOptions = compilerOptions;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
61
|
function parseSourceFile(logger, mode, srcFile, fullSourceName, normalize) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return new ArtifactSource(mode, fullSourceName, getSha256(normalized), normalized, srcFile, deps.array, opts);
|
|
62
|
+
const { deps, normalized, opts } = parseSourceData(logger, readFileSync(srcFile).toString(), fullSourceName, normalize);
|
|
63
|
+
return new ArtifactSource(mode, fullSourceName, getSha256(normalized), normalized, srcFile, deps.array, opts);
|
|
93
64
|
}
|
|
94
65
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
66
|
+
* Reads src
|
|
67
|
+
* returns normalized source code,
|
|
68
|
+
* gets dependencies from imports,
|
|
69
|
+
* maps imports to global names if globalizeImports is true,
|
|
70
|
+
* and collects compiler options like hashOverride.
|
|
71
|
+
*/
|
|
101
72
|
function parseSourceData(logger, src, fullSourceName, globalizeImports) {
|
|
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
|
-
catch (error) {
|
|
133
|
-
const err = error;
|
|
134
|
-
throw new Error(`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`, { cause: err });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
normalized: processedLines.join("\n"),
|
|
139
|
-
deps: dependencySet,
|
|
140
|
-
opts: optionList,
|
|
141
|
-
};
|
|
73
|
+
const dependencySet = createArtifactNameSet();
|
|
74
|
+
const optionList = [];
|
|
75
|
+
const lines = src.split("\n");
|
|
76
|
+
const processedLines = [];
|
|
77
|
+
let parserContext = {
|
|
78
|
+
isInCommentBlock: false,
|
|
79
|
+
canDetectOptions: true,
|
|
80
|
+
artifactImportREs: /* @__PURE__ */ new Map(),
|
|
81
|
+
importLikeREs: /* @__PURE__ */ new Map(),
|
|
82
|
+
multilineStatement: "",
|
|
83
|
+
lineNo: 0
|
|
84
|
+
};
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
parserContext.lineNo++;
|
|
87
|
+
try {
|
|
88
|
+
const { line: processedLine, context: newContext, artifacts, option } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
|
|
89
|
+
processedLines.push(processedLine);
|
|
90
|
+
parserContext = newContext;
|
|
91
|
+
for (const artifact of artifacts ?? []) dependencySet.add(artifact);
|
|
92
|
+
if (option) optionList.push(option);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const err = error;
|
|
95
|
+
throw new Error(`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`, { cause: err });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
normalized: processedLines.join("\n"),
|
|
100
|
+
deps: dependencySet,
|
|
101
|
+
opts: optionList
|
|
102
|
+
};
|
|
142
103
|
}
|
|
143
104
|
function parseSingleSourceLine(logger, line, context, localPackageName, globalizeImports) {
|
|
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
|
-
|
|
105
|
+
if (context.isInCommentBlock) {
|
|
106
|
+
if (multilineCommentEndRE.exec(line)) context.isInCommentBlock = false;
|
|
107
|
+
return {
|
|
108
|
+
line: "",
|
|
109
|
+
context,
|
|
110
|
+
artifacts: [],
|
|
111
|
+
option: void 0
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (compilerOptionRE.exec(line)) {
|
|
115
|
+
if (!context.canDetectOptions) {
|
|
116
|
+
logger.error(`[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'`);
|
|
117
|
+
throw new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
line,
|
|
121
|
+
context,
|
|
122
|
+
artifacts: [],
|
|
123
|
+
option: parseComplierOption(line)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {
|
|
127
|
+
logger.warn(`[line ${context.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`);
|
|
128
|
+
return {
|
|
129
|
+
line,
|
|
130
|
+
context,
|
|
131
|
+
artifacts: [],
|
|
132
|
+
option: void 0
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) return {
|
|
136
|
+
line: "",
|
|
137
|
+
context,
|
|
138
|
+
artifacts: [],
|
|
139
|
+
option: void 0
|
|
140
|
+
};
|
|
141
|
+
const canBeInlinedComment = line.includes("*/");
|
|
142
|
+
if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
|
|
143
|
+
context.isInCommentBlock = true;
|
|
144
|
+
return {
|
|
145
|
+
line: "",
|
|
146
|
+
context,
|
|
147
|
+
artifacts: [],
|
|
148
|
+
option: void 0
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const statement = context.multilineStatement + line.trim();
|
|
152
|
+
const mayContainAComment = line.includes("//") || line.includes("/*");
|
|
153
|
+
if (multilineStatementRE.test(line) && !mayContainAComment) {
|
|
154
|
+
const result = processAssetImport(line, statement, context, localPackageName, globalizeImports);
|
|
155
|
+
context.multilineStatement += result.line.trim();
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
context.multilineStatement = "";
|
|
159
|
+
if (emptyLineRE.exec(statement)) return {
|
|
160
|
+
line,
|
|
161
|
+
context,
|
|
162
|
+
artifacts: [],
|
|
163
|
+
option: void 0
|
|
164
|
+
};
|
|
165
|
+
context.canDetectOptions = false;
|
|
166
|
+
return processAssetImport(line, statement, context, localPackageName, globalizeImports);
|
|
205
167
|
}
|
|
206
168
|
function processModuleImport(importInstruction, originalLine, statement, context, localPackageName, globalizeImports) {
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
const artifact = parseArtifactName(iInfo.module, "library", localPackageName);
|
|
250
|
-
if (!artifact) {
|
|
251
|
-
// not a Platforma Tengo library import
|
|
252
|
-
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
253
|
-
}
|
|
254
|
-
{
|
|
255
|
-
originalLine = originalLine.replace(importInstruction[0], ` := import("${artifact.pkg}:${artifact.id}")`);
|
|
256
|
-
}
|
|
257
|
-
return { line: originalLine, context, artifacts: [artifact], option: undefined };
|
|
169
|
+
const iInfo = parseImport(statement);
|
|
170
|
+
if (iInfo.module === "plapi") {
|
|
171
|
+
if (!context.artifactImportREs.has(iInfo.module)) context.artifactImportREs.set(iInfo.module, [["template", newGetTemplateIdRE(iInfo.alias)], ["software", newGetSoftwareInfoRE(iInfo.alias)]]);
|
|
172
|
+
return {
|
|
173
|
+
line: originalLine,
|
|
174
|
+
context,
|
|
175
|
+
artifacts: [],
|
|
176
|
+
option: void 0
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (iInfo.module === "@milaboratory/tengo-sdk:ll" || iInfo.module === "@platforma-sdk/workflow-tengo:ll" || (localPackageName === "@milaboratory/tengo-sdk" || localPackageName === "@platforma-sdk/workflow-tengo") && iInfo.module === ":ll") {
|
|
180
|
+
if (!context.artifactImportREs.has(iInfo.module)) context.artifactImportREs.set(iInfo.module, [["template", newImportTemplateRE(iInfo.alias)], ["software", newImportSoftwareRE(iInfo.alias)]]);
|
|
181
|
+
}
|
|
182
|
+
if (iInfo.module === "@milaboratory/tengo-sdk:assets" || iInfo.module === "@platforma-sdk/workflow-tengo:assets" || (localPackageName === "@milaboratory/tengo-sdk" || localPackageName === "@platforma-sdk/workflow-tengo") && iInfo.module === ":assets") {
|
|
183
|
+
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
184
|
+
context.artifactImportREs.set(iInfo.module, [
|
|
185
|
+
["template", newImportTemplateRE(iInfo.alias)],
|
|
186
|
+
["software", newImportSoftwareRE(iInfo.alias)],
|
|
187
|
+
["asset", newImportAssetRE(iInfo.alias)]
|
|
188
|
+
]);
|
|
189
|
+
context.importLikeREs.set(iInfo.module, [
|
|
190
|
+
["template", newImportTemplateDetector(iInfo.alias)],
|
|
191
|
+
["software", newImportSoftwareDetector(iInfo.alias)],
|
|
192
|
+
["asset", newImportAssetDetector(iInfo.alias)]
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const artifact = parseArtifactName(iInfo.module, "library", localPackageName);
|
|
197
|
+
if (!artifact) return {
|
|
198
|
+
line: originalLine,
|
|
199
|
+
context,
|
|
200
|
+
artifacts: [],
|
|
201
|
+
option: void 0
|
|
202
|
+
};
|
|
203
|
+
if (globalizeImports) originalLine = originalLine.replace(importInstruction[0], ` := import("${artifact.pkg}:${artifact.id}")`);
|
|
204
|
+
return {
|
|
205
|
+
line: originalLine,
|
|
206
|
+
context,
|
|
207
|
+
artifacts: [artifact],
|
|
208
|
+
option: void 0
|
|
209
|
+
};
|
|
258
210
|
}
|
|
259
211
|
function processAssetImport(originalLine, statement, context, localPackageName, globalizeImports) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (context.importLikeREs.size > 0) {
|
|
302
|
-
for (const [_, artifactRE] of context.importLikeREs) {
|
|
303
|
-
for (const [artifactType, re] of artifactRE) {
|
|
304
|
-
const match = re.exec(statement);
|
|
305
|
-
if (!match || !match.groups) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
throw Error(`incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware("sw:main")').`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
212
|
+
if (emptyLineRE.exec(statement)) return {
|
|
213
|
+
line: originalLine,
|
|
214
|
+
context,
|
|
215
|
+
artifacts: [],
|
|
216
|
+
option: void 0
|
|
217
|
+
};
|
|
218
|
+
context.canDetectOptions = false;
|
|
219
|
+
const importInstruction = importRE.exec(statement);
|
|
220
|
+
if (importInstruction) return processModuleImport(importInstruction, originalLine, statement, context, localPackageName, globalizeImports);
|
|
221
|
+
if (context.artifactImportREs.size > 0) for (const [_, artifactRE] of context.artifactImportREs) for (const [artifactType, re] of artifactRE) {
|
|
222
|
+
const matches = Array.from(statement.matchAll(re));
|
|
223
|
+
if (matches.length === 0) continue;
|
|
224
|
+
const artifacts = [];
|
|
225
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
226
|
+
const match = matches[i];
|
|
227
|
+
if (!match || !match.groups) continue;
|
|
228
|
+
const { fnCall, templateName, fnName } = match.groups;
|
|
229
|
+
if (!fnCall || !templateName || !fnName) throw Error(`failed to parse template import statement`);
|
|
230
|
+
const artifact = parseArtifactName(templateName, artifactType, localPackageName);
|
|
231
|
+
if (!artifact) throw Error(`failed to parse artifact name in ${fnName} import statement`);
|
|
232
|
+
artifacts.push(artifact);
|
|
233
|
+
if (globalizeImports) originalLine = originalLine.replaceAll(fnCall, `${fnName}("${artifact.pkg}:${artifact.id}")`);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
line: originalLine,
|
|
237
|
+
context,
|
|
238
|
+
artifacts,
|
|
239
|
+
option: void 0
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (context.importLikeREs.size > 0) for (const [_, artifactRE] of context.importLikeREs) for (const [artifactType, re] of artifactRE) {
|
|
243
|
+
const match = re.exec(statement);
|
|
244
|
+
if (!match || !match.groups) continue;
|
|
245
|
+
throw Error(`incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware("sw:main")').`);
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
line: originalLine,
|
|
249
|
+
context,
|
|
250
|
+
artifacts: [],
|
|
251
|
+
option: void 0
|
|
252
|
+
};
|
|
313
253
|
}
|
|
314
254
|
function parseImport(line) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
module: moduleName, // the module name without wrapping quotes: import("<module>")
|
|
325
|
-
alias: importName, // the name of variable that keeps imported module: <alias> := import("<module>")
|
|
326
|
-
};
|
|
255
|
+
const match = importNameRE.exec(line);
|
|
256
|
+
if (!match || !match.groups) throw Error(`failed to parse 'import' statement`);
|
|
257
|
+
const { importName, moduleName } = match.groups;
|
|
258
|
+
if (!importName || !moduleName) throw Error(`failed to parse 'import' statement`);
|
|
259
|
+
return {
|
|
260
|
+
module: moduleName,
|
|
261
|
+
alias: importName
|
|
262
|
+
};
|
|
327
263
|
}
|
|
328
264
|
function parseArtifactName(moduleName, aType, localPackageName) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
return { type: aType, pkg: pkgName ?? localPackageName, id: depID };
|
|
265
|
+
const depInfo = dependencyRE.exec(moduleName);
|
|
266
|
+
if (!depInfo) return;
|
|
267
|
+
if (!depInfo.groups) throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
|
|
268
|
+
const { pkgName, depID } = depInfo.groups;
|
|
269
|
+
if (!depID) throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
|
|
270
|
+
return {
|
|
271
|
+
type: aType,
|
|
272
|
+
pkg: pkgName ?? localPackageName,
|
|
273
|
+
id: depID
|
|
274
|
+
};
|
|
341
275
|
}
|
|
342
276
|
function getSha256(source) {
|
|
343
|
-
|
|
277
|
+
return createHash("sha256").update(source).digest("hex");
|
|
344
278
|
}
|
|
345
279
|
|
|
346
|
-
|
|
347
|
-
|
|
280
|
+
//#endregion
|
|
281
|
+
export { ArtifactSource, getSha256, parseSourceFile };
|
|
282
|
+
//# sourceMappingURL=source.js.map
|