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