@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.
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 +8 -8
  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,19 +1,16 @@
1
- 'use strict';
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
- var fs = require('node:fs');
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
- return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` +
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
- return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
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*$/; // matches '^/* ... */$' comment lines as a special case of singleline comments.
27
+ const singlelineTerminatedCommentRE = /^\s*\/\*.*\*\/\s*$/;
31
28
  const multilineCommentStartRE = /^\s*\/\*/;
32
29
  const multilineCommentEndRE = /\*\//;
33
- const multilineStatementRE = /[.,]\s*$/; // it is hard to consistently treat (\n"a"\n) multiline statements, we forbid them for now.
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>[^"]+)/; // use it to parse <moduleName> from importPattern or <templateName> from getTemplateID
33
+ const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
39
34
  /**
40
- * Parse compiler option string representation
41
- * Compiler option line is a comment starting with '//tengo:', say
42
- * //tengo:hash_override tralala
43
- *
44
- * The common compiler option syntax is:
45
- * //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
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
- const parts = opt.split(" ");
49
- const namePart = parts[0].split(":");
50
- if (namePart.length != 2) {
51
- throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");
52
- }
53
- const optName = namePart[1];
54
- return {
55
- name: optName,
56
- args: parts.slice(1),
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
- const src = fs.readFileSync(srcFile).toString();
93
- const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
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
- * Reads src
98
- * returns normalized source code,
99
- * gets dependencies from imports,
100
- * maps imports to global names if globalizeImports is true,
101
- * and collects compiler options like hashOverride.
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
- const dependencySet = artifactset.createArtifactNameSet();
105
- const optionList = [];
106
- // iterating over lines
107
- const lines = src.split("\n");
108
- // processedLines keep all the original lines from <src>.
109
- // If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines
110
- // with Platforma Tengo lib and template usages, resolving local names (":<item>") to
111
- // global ("@milaboratory/pkg:<item>")
112
- const processedLines = [];
113
- let parserContext = {
114
- isInCommentBlock: false,
115
- canDetectOptions: true,
116
- artifactImportREs: new Map(),
117
- importLikeREs: new Map(),
118
- multilineStatement: "",
119
- lineNo: 0,
120
- };
121
- for (const line of lines) {
122
- parserContext.lineNo++;
123
- try {
124
- const { line: processedLine, context: newContext, artifacts, option, } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
125
- processedLines.push(processedLine);
126
- parserContext = newContext;
127
- for (const artifact of artifacts ?? []) {
128
- dependencySet.add(artifact);
129
- }
130
- if (option) {
131
- optionList.push(option);
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
- if (context.isInCommentBlock) {
147
- if (multilineCommentEndRE.exec(line)) {
148
- context.isInCommentBlock = false;
149
- }
150
- return { line: "", context, artifacts: [], option: undefined };
151
- }
152
- if (compilerOptionRE.exec(line)) {
153
- if (!context.canDetectOptions) {
154
- 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'`);
155
- throw new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
156
- }
157
- return { line, context, artifacts: [], option: parseComplierOption(line) };
158
- }
159
- if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {
160
- 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)`);
161
- return { line, context, artifacts: [], option: undefined };
162
- }
163
- if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {
164
- return { line: "", context, artifacts: [], option: undefined };
165
- }
166
- const canBeInlinedComment = line.includes("*/");
167
- if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
168
- context.isInCommentBlock = true;
169
- return { line: "", context, artifacts: [], option: undefined };
170
- }
171
- const statement = context.multilineStatement + line.trim();
172
- const mayContainAComment = line.includes("//") || line.includes("/*");
173
- if (multilineStatementRE.test(line) && !mayContainAComment) {
174
- // We accumulate multiline statements into single line before analyzing them.
175
- // This dramatically simplifies parsing logic: things like
176
- //
177
- // assets.
178
- // importSoftware("a:b");
179
- //
180
- // become simple 'assets.importSoftware("a:b");' for parser checks.
181
- //
182
- // For safety reasons, we never consider anything that 'may look like a comment'
183
- // as a part of multiline statement to prevent joining things like
184
- //
185
- // someFnCall() // looks like multiline statement because of dot in the end of a comment.
186
- //
187
- // This problem also appears in multiline string literals, but I hope this will not
188
- // cause problems in real life.
189
- // We still try to process each line to globalize imports in case of complex constructions, when
190
- // statements are stacked one into another:
191
- // a.
192
- // use(assets.importSoftware(":soft1")).
193
- // use(assets.importSoftware(":soft2")).
194
- // run()
195
- // It is multiline, and it still requires import globalization mid-way, not just for the last line of statement
196
- const result = processAssetImport(line, statement, context, localPackageName);
197
- context.multilineStatement += result.line.trim(); // accumulate the line after imports globalization.
198
- return result;
199
- }
200
- context.multilineStatement = ""; // reset accumulated multiline statement parts once we reach statement end.
201
- if (emptyLineRE.exec(statement)) {
202
- return { line, context, artifacts: [], option: undefined };
203
- }
204
- // options could be only at the top of the file.
205
- context.canDetectOptions = false;
206
- return processAssetImport(line, statement, context, localPackageName);
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
- const iInfo = parseImport(statement);
210
- // If we have plapi, ll or assets, then try to parse
211
- // getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.
212
- if (iInfo.module === "plapi") {
213
- if (!context.artifactImportREs.has(iInfo.module)) {
214
- context.artifactImportREs.set(iInfo.module, [
215
- ["template", newGetTemplateIdRE(iInfo.alias)],
216
- ["software", newGetSoftwareInfoRE(iInfo.alias)],
217
- ]);
218
- }
219
- return { line: originalLine, context, artifacts: [], option: undefined };
220
- }
221
- if (iInfo.module === "@milaboratory/tengo-sdk:ll" ||
222
- iInfo.module === "@platforma-sdk/workflow-tengo:ll" ||
223
- ((localPackageName === "@milaboratory/tengo-sdk" ||
224
- localPackageName === "@platforma-sdk/workflow-tengo") &&
225
- iInfo.module === ":ll")) {
226
- if (!context.artifactImportREs.has(iInfo.module)) {
227
- context.artifactImportREs.set(iInfo.module, [
228
- ["template", newImportTemplateRE(iInfo.alias)],
229
- ["software", newImportSoftwareRE(iInfo.alias)],
230
- ]);
231
- }
232
- }
233
- if (iInfo.module === "@milaboratory/tengo-sdk:assets" ||
234
- iInfo.module === "@platforma-sdk/workflow-tengo:assets" ||
235
- ((localPackageName === "@milaboratory/tengo-sdk" ||
236
- localPackageName === "@platforma-sdk/workflow-tengo") &&
237
- iInfo.module === ":assets")) {
238
- if (!context.artifactImportREs.has(iInfo.module)) {
239
- context.artifactImportREs.set(iInfo.module, [
240
- ["template", newImportTemplateRE(iInfo.alias)],
241
- ["software", newImportSoftwareRE(iInfo.alias)],
242
- ["asset", newImportAssetRE(iInfo.alias)],
243
- ]);
244
- context.importLikeREs.set(iInfo.module, [
245
- ["template", newImportTemplateDetector(iInfo.alias)],
246
- ["software", newImportSoftwareDetector(iInfo.alias)],
247
- ["asset", newImportAssetDetector(iInfo.alias)],
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
- if (emptyLineRE.exec(statement)) {
263
- return { line: originalLine, context, artifacts: [], option: undefined };
264
- }
265
- // options could be only at the top of the file.
266
- context.canDetectOptions = false;
267
- const importInstruction = importRE.exec(statement);
268
- if (importInstruction) {
269
- return processModuleImport(importInstruction, originalLine, statement, context, localPackageName);
270
- }
271
- if (context.artifactImportREs.size > 0) {
272
- for (const [_, artifactRE] of context.artifactImportREs) {
273
- for (const [artifactType, re] of artifactRE) {
274
- // Find all matches in the statement
275
- const matches = Array.from(statement.matchAll(re));
276
- if (matches.length === 0) {
277
- continue;
278
- }
279
- const artifacts = [];
280
- for (let i = matches.length - 1; i >= 0; i--) {
281
- const match = matches[i];
282
- if (!match || !match.groups) {
283
- continue;
284
- }
285
- const { fnCall, templateName, fnName } = match.groups;
286
- if (!fnCall || !templateName || !fnName) {
287
- throw Error(`failed to parse template import statement`);
288
- }
289
- const artifact = parseArtifactName(templateName, artifactType, localPackageName);
290
- if (!artifact) {
291
- throw Error(`failed to parse artifact name in ${fnName} import statement`);
292
- }
293
- artifacts.push(artifact);
294
- {
295
- // Replace all occurrences of this fnCall in originalLine
296
- originalLine = originalLine.replaceAll(fnCall, `${fnName}("${artifact.pkg}:${artifact.id}")`);
297
- }
298
- }
299
- return { line: originalLine, context, artifacts, option: undefined };
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
- const match = importNameRE.exec(line);
318
- if (!match || !match.groups) {
319
- throw Error(`failed to parse 'import' statement`);
320
- }
321
- const { importName, moduleName } = match.groups;
322
- if (!importName || !moduleName) {
323
- throw Error(`failed to parse 'import' statement`);
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
- const depInfo = dependencyRE.exec(moduleName);
332
- if (!depInfo) {
333
- return;
334
- }
335
- if (!depInfo.groups) {
336
- throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
337
- }
338
- const { pkgName, depID } = depInfo.groups;
339
- if (!depID) {
340
- throw Error(`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`);
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
- return node_crypto.createHash("sha256").update(source).digest("hex");
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