@platforma-sdk/tengo-builder 2.4.24 → 2.4.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/commands/build.cjs +106 -150
  3. package/dist/commands/build.cjs.map +1 -1
  4. package/dist/commands/build.d.ts +15 -10
  5. package/dist/commands/build.js +101 -126
  6. package/dist/commands/build.js.map +1 -1
  7. package/dist/commands/check.cjs +32 -36
  8. package/dist/commands/check.cjs.map +1 -1
  9. package/dist/commands/check.d.ts +13 -8
  10. package/dist/commands/check.js +30 -33
  11. package/dist/commands/check.js.map +1 -1
  12. package/dist/commands/dump/artifacts.cjs +22 -22
  13. package/dist/commands/dump/artifacts.cjs.map +1 -1
  14. package/dist/commands/dump/artifacts.d.ts +13 -8
  15. package/dist/commands/dump/artifacts.js +20 -19
  16. package/dist/commands/dump/artifacts.js.map +1 -1
  17. package/dist/commands/dump/software.cjs +19 -21
  18. package/dist/commands/dump/software.cjs.map +1 -1
  19. package/dist/commands/dump/software.d.ts +12 -7
  20. package/dist/commands/dump/software.js +17 -18
  21. package/dist/commands/dump/software.js.map +1 -1
  22. package/dist/commands/test.cjs +32 -33
  23. package/dist/commands/test.cjs.map +1 -1
  24. package/dist/commands/test.d.ts +13 -8
  25. package/dist/commands/test.js +30 -30
  26. package/dist/commands/test.js.map +1 -1
  27. package/dist/compiler/artifactset.cjs +59 -68
  28. package/dist/compiler/artifactset.cjs.map +1 -1
  29. package/dist/compiler/artifactset.js +60 -66
  30. package/dist/compiler/artifactset.js.map +1 -1
  31. package/dist/compiler/compiler.cjs +241 -314
  32. package/dist/compiler/compiler.cjs.map +1 -1
  33. package/dist/compiler/compiler.js +241 -312
  34. package/dist/compiler/compiler.js.map +1 -1
  35. package/dist/compiler/compileroptions.cjs +16 -35
  36. package/dist/compiler/compileroptions.cjs.map +1 -1
  37. package/dist/compiler/compileroptions.js +17 -33
  38. package/dist/compiler/compileroptions.js.map +1 -1
  39. package/dist/compiler/main.cjs +258 -334
  40. package/dist/compiler/main.cjs.map +1 -1
  41. package/dist/compiler/main.js +256 -311
  42. package/dist/compiler/main.js.map +1 -1
  43. package/dist/compiler/package.cjs +21 -35
  44. package/dist/compiler/package.cjs.map +1 -1
  45. package/dist/compiler/package.js +21 -34
  46. package/dist/compiler/package.js.map +1 -1
  47. package/dist/compiler/source.cjs +239 -308
  48. package/dist/compiler/source.cjs.map +1 -1
  49. package/dist/compiler/source.js +239 -304
  50. package/dist/compiler/source.js.map +1 -1
  51. package/dist/compiler/template.cjs +30 -35
  52. package/dist/compiler/template.cjs.map +1 -1
  53. package/dist/compiler/template.js +29 -33
  54. package/dist/compiler/template.js.map +1 -1
  55. package/dist/compiler/util.cjs +40 -61
  56. package/dist/compiler/util.cjs.map +1 -1
  57. package/dist/compiler/util.js +36 -39
  58. package/dist/compiler/util.js.map +1 -1
  59. package/dist/index.cjs +14 -14
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +15 -11
  62. package/dist/index.js +13 -12
  63. package/dist/index.js.map +1 -1
  64. package/dist/shared/basecmd.cjs +42 -33
  65. package/dist/shared/basecmd.cjs.map +1 -1
  66. package/dist/shared/basecmd.js +41 -31
  67. package/dist/shared/basecmd.js.map +1 -1
  68. package/dist/shared/dump.cjs +73 -107
  69. package/dist/shared/dump.cjs.map +1 -1
  70. package/dist/shared/dump.js +73 -105
  71. package/dist/shared/dump.js.map +1 -1
  72. package/dist/shared/proc.cjs +22 -18
  73. package/dist/shared/proc.cjs.map +1 -1
  74. package/dist/shared/proc.js +21 -16
  75. package/dist/shared/proc.js.map +1 -1
  76. package/package.json +10 -10
  77. package/dist/commands/build.d.ts.map +0 -1
  78. package/dist/commands/check.d.ts.map +0 -1
  79. package/dist/commands/dump/artifacts.d.ts.map +0 -1
  80. package/dist/commands/dump/software.d.ts.map +0 -1
  81. package/dist/commands/test.d.ts.map +0 -1
  82. package/dist/compiler/artifactset.d.ts +0 -24
  83. package/dist/compiler/artifactset.d.ts.map +0 -1
  84. package/dist/compiler/compiler.d.ts +0 -42
  85. package/dist/compiler/compiler.d.ts.map +0 -1
  86. package/dist/compiler/compileroptions.d.ts +0 -6
  87. package/dist/compiler/compileroptions.d.ts.map +0 -1
  88. package/dist/compiler/main.d.ts +0 -35
  89. package/dist/compiler/main.d.ts.map +0 -1
  90. package/dist/compiler/package.d.ts +0 -44
  91. package/dist/compiler/package.d.ts.map +0 -1
  92. package/dist/compiler/source.d.ts +0 -54
  93. package/dist/compiler/source.d.ts.map +0 -1
  94. package/dist/compiler/template.d.ts +0 -22
  95. package/dist/compiler/template.d.ts.map +0 -1
  96. package/dist/compiler/test.artifacts.d.ts +0 -47
  97. package/dist/compiler/test.artifacts.d.ts.map +0 -1
  98. package/dist/compiler/util.d.ts +0 -8
  99. package/dist/compiler/util.d.ts.map +0 -1
  100. package/dist/index.d.ts.map +0 -1
  101. package/dist/shared/basecmd.d.ts +0 -12
  102. package/dist/shared/basecmd.d.ts.map +0 -1
  103. package/dist/shared/dump.d.ts +0 -6
  104. package/dist/shared/dump.d.ts.map +0 -1
  105. package/dist/shared/proc.d.ts +0 -5
  106. package/dist/shared/proc.d.ts.map +0 -1
@@ -1,17 +1,15 @@
1
- import { readFileSync } from 'node:fs';
2
- import { fullNameToString } from './package.js';
3
- import { createArtifactNameSet } from './artifactset.js';
4
- import { createHash } from 'node:crypto';
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
- // matches any valid name in tengo. Don't forget to use '\b' when needed to limit the boundaries!
6
+ //#region src/compiler/source.ts
7
7
  const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
8
8
  const functionCallRE = (moduleName, fnName) => {
9
- return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` +
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
- return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
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*$/; // matches '^/* ... */$' comment lines as a special case of singleline comments.
26
+ const singlelineTerminatedCommentRE = /^\s*\/\*.*\*\/\s*$/;
29
27
  const multilineCommentStartRE = /^\s*\/\*/;
30
28
  const multilineCommentEndRE = /\*\//;
31
- const multilineStatementRE = /[.,]\s*$/; // it is hard to consistently treat (\n"a"\n) multiline statements, we forbid them for now.
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>[^"]+)/; // use it to parse <moduleName> from importPattern or <templateName> from getTemplateID
32
+ const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
37
33
  /**
38
- * Parse compiler option string representation
39
- * Compiler option line is a comment starting with '//tengo:', say
40
- * //tengo:hash_override tralala
41
- *
42
- * The common compiler option syntax is:
43
- * //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
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
- const parts = opt.split(" ");
47
- const namePart = parts[0].split(":");
48
- if (namePart.length != 2) {
49
- throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");
50
- }
51
- const optName = namePart[1];
52
- return {
53
- name: optName,
54
- args: parts.slice(1),
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
- const src = readFileSync(srcFile).toString();
91
- const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
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
- * Reads src
96
- * returns normalized source code,
97
- * gets dependencies from imports,
98
- * maps imports to global names if globalizeImports is true,
99
- * and collects compiler options like hashOverride.
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
- const dependencySet = createArtifactNameSet();
103
- const optionList = [];
104
- // iterating over lines
105
- const lines = src.split("\n");
106
- // processedLines keep all the original lines from <src>.
107
- // If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines
108
- // with Platforma Tengo lib and template usages, resolving local names (":<item>") to
109
- // global ("@milaboratory/pkg:<item>")
110
- const processedLines = [];
111
- let parserContext = {
112
- isInCommentBlock: false,
113
- canDetectOptions: true,
114
- artifactImportREs: new Map(),
115
- importLikeREs: new Map(),
116
- multilineStatement: "",
117
- lineNo: 0,
118
- };
119
- for (const line of lines) {
120
- parserContext.lineNo++;
121
- try {
122
- const { line: processedLine, context: newContext, artifacts, option, } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
123
- processedLines.push(processedLine);
124
- parserContext = newContext;
125
- for (const artifact of artifacts ?? []) {
126
- dependencySet.add(artifact);
127
- }
128
- if (option) {
129
- optionList.push(option);
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
- if (context.isInCommentBlock) {
145
- if (multilineCommentEndRE.exec(line)) {
146
- context.isInCommentBlock = false;
147
- }
148
- return { line: "", context, artifacts: [], option: undefined };
149
- }
150
- if (compilerOptionRE.exec(line)) {
151
- if (!context.canDetectOptions) {
152
- 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'`);
153
- throw new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
154
- }
155
- return { line, context, artifacts: [], option: parseComplierOption(line) };
156
- }
157
- if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {
158
- 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)`);
159
- return { line, context, artifacts: [], option: undefined };
160
- }
161
- if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {
162
- return { line: "", context, artifacts: [], option: undefined };
163
- }
164
- const canBeInlinedComment = line.includes("*/");
165
- if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
166
- context.isInCommentBlock = true;
167
- return { line: "", context, artifacts: [], option: undefined };
168
- }
169
- const statement = context.multilineStatement + line.trim();
170
- const mayContainAComment = line.includes("//") || line.includes("/*");
171
- if (multilineStatementRE.test(line) && !mayContainAComment) {
172
- // We accumulate multiline statements into single line before analyzing them.
173
- // This dramatically simplifies parsing logic: things like
174
- //
175
- // assets.
176
- // importSoftware("a:b");
177
- //
178
- // become simple 'assets.importSoftware("a:b");' for parser checks.
179
- //
180
- // For safety reasons, we never consider anything that 'may look like a comment'
181
- // as a part of multiline statement to prevent joining things like
182
- //
183
- // someFnCall() // looks like multiline statement because of dot in the end of a comment.
184
- //
185
- // This problem also appears in multiline string literals, but I hope this will not
186
- // cause problems in real life.
187
- // We still try to process each line to globalize imports in case of complex constructions, when
188
- // statements are stacked one into another:
189
- // a.
190
- // use(assets.importSoftware(":soft1")).
191
- // use(assets.importSoftware(":soft2")).
192
- // run()
193
- // It is multiline, and it still requires import globalization mid-way, not just for the last line of statement
194
- const result = processAssetImport(line, statement, context, localPackageName);
195
- context.multilineStatement += result.line.trim(); // accumulate the line after imports globalization.
196
- return result;
197
- }
198
- context.multilineStatement = ""; // reset accumulated multiline statement parts once we reach statement end.
199
- if (emptyLineRE.exec(statement)) {
200
- return { line, context, artifacts: [], option: undefined };
201
- }
202
- // options could be only at the top of the file.
203
- context.canDetectOptions = false;
204
- return processAssetImport(line, statement, context, localPackageName);
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
- const iInfo = parseImport(statement);
208
- // If we have plapi, ll or assets, then try to parse
209
- // getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.
210
- if (iInfo.module === "plapi") {
211
- if (!context.artifactImportREs.has(iInfo.module)) {
212
- context.artifactImportREs.set(iInfo.module, [
213
- ["template", newGetTemplateIdRE(iInfo.alias)],
214
- ["software", newGetSoftwareInfoRE(iInfo.alias)],
215
- ]);
216
- }
217
- return { line: originalLine, context, artifacts: [], option: undefined };
218
- }
219
- if (iInfo.module === "@milaboratory/tengo-sdk:ll" ||
220
- iInfo.module === "@platforma-sdk/workflow-tengo:ll" ||
221
- ((localPackageName === "@milaboratory/tengo-sdk" ||
222
- localPackageName === "@platforma-sdk/workflow-tengo") &&
223
- iInfo.module === ":ll")) {
224
- if (!context.artifactImportREs.has(iInfo.module)) {
225
- context.artifactImportREs.set(iInfo.module, [
226
- ["template", newImportTemplateRE(iInfo.alias)],
227
- ["software", newImportSoftwareRE(iInfo.alias)],
228
- ]);
229
- }
230
- }
231
- if (iInfo.module === "@milaboratory/tengo-sdk:assets" ||
232
- iInfo.module === "@platforma-sdk/workflow-tengo:assets" ||
233
- ((localPackageName === "@milaboratory/tengo-sdk" ||
234
- localPackageName === "@platforma-sdk/workflow-tengo") &&
235
- iInfo.module === ":assets")) {
236
- if (!context.artifactImportREs.has(iInfo.module)) {
237
- context.artifactImportREs.set(iInfo.module, [
238
- ["template", newImportTemplateRE(iInfo.alias)],
239
- ["software", newImportSoftwareRE(iInfo.alias)],
240
- ["asset", newImportAssetRE(iInfo.alias)],
241
- ]);
242
- context.importLikeREs.set(iInfo.module, [
243
- ["template", newImportTemplateDetector(iInfo.alias)],
244
- ["software", newImportSoftwareDetector(iInfo.alias)],
245
- ["asset", newImportAssetDetector(iInfo.alias)],
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
- if (emptyLineRE.exec(statement)) {
261
- return { line: originalLine, context, artifacts: [], option: undefined };
262
- }
263
- // options could be only at the top of the file.
264
- context.canDetectOptions = false;
265
- const importInstruction = importRE.exec(statement);
266
- if (importInstruction) {
267
- return processModuleImport(importInstruction, originalLine, statement, context, localPackageName);
268
- }
269
- if (context.artifactImportREs.size > 0) {
270
- for (const [_, artifactRE] of context.artifactImportREs) {
271
- for (const [artifactType, re] of artifactRE) {
272
- // Find all matches in the statement
273
- const matches = Array.from(statement.matchAll(re));
274
- if (matches.length === 0) {
275
- continue;
276
- }
277
- const artifacts = [];
278
- for (let i = matches.length - 1; i >= 0; i--) {
279
- const match = matches[i];
280
- if (!match || !match.groups) {
281
- continue;
282
- }
283
- const { fnCall, templateName, fnName } = match.groups;
284
- if (!fnCall || !templateName || !fnName) {
285
- throw Error(`failed to parse template import statement`);
286
- }
287
- const artifact = parseArtifactName(templateName, artifactType, localPackageName);
288
- if (!artifact) {
289
- throw Error(`failed to parse artifact name in ${fnName} import statement`);
290
- }
291
- artifacts.push(artifact);
292
- {
293
- // Replace all occurrences of this fnCall in originalLine
294
- originalLine = originalLine.replaceAll(fnCall, `${fnName}("${artifact.pkg}:${artifact.id}")`);
295
- }
296
- }
297
- return { line: originalLine, context, artifacts, option: undefined };
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
- const match = importNameRE.exec(line);
316
- if (!match || !match.groups) {
317
- throw Error(`failed to parse 'import' statement`);
318
- }
319
- const { importName, moduleName } = match.groups;
320
- if (!importName || !moduleName) {
321
- throw Error(`failed to parse 'import' statement`);
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
- const depInfo = dependencyRE.exec(moduleName);
330
- if (!depInfo) {
331
- return;
332
- }
333
- if (!depInfo.groups) {
334
- throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
335
- }
336
- const { pkgName, depID } = depInfo.groups;
337
- if (!depID) {
338
- throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
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
- return createHash("sha256").update(source).digest("hex");
277
+ return createHash("sha256").update(source).digest("hex");
344
278
  }
345
279
 
346
- export { ArtifactSource, getSha256, newGetSoftwareInfoRE, newGetTemplateIdRE, parseSingleSourceLine, parseSourceFile };
347
- //# sourceMappingURL=source.js.map
280
+ //#endregion
281
+ export { ArtifactSource, getSha256, parseSourceFile };
282
+ //# sourceMappingURL=source.js.map