@platforma-sdk/tengo-builder 2.4.13 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/run.js +5 -5
- package/dist/commands/build.cjs +36 -36
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +5 -5
- package/dist/commands/build.js +36 -36
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +5 -5
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +2 -2
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +5 -5
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +4 -6
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +2 -2
- package/dist/commands/dump/artifacts.d.ts.map +1 -1
- package/dist/commands/dump/artifacts.js +4 -6
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +3 -5
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +2 -2
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/software.js +3 -5
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +5 -5
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +5 -5
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +2 -2
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/artifactset.js +2 -2
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +37 -34
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.d.ts +3 -3
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +37 -34
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +12 -12
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.d.ts +2 -2
- package/dist/compiler/compileroptions.js +12 -12
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +58 -58
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.d.ts +6 -6
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/main.js +58 -58
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +5 -2
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.d.ts +6 -6
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/package.js +5 -2
- package/dist/compiler/package.js.map +1 -1
- package/dist/compiler/source.cjs +50 -52
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.d.ts +2 -2
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/source.js +50 -52
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +7 -7
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.d.ts +2 -2
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/template.js +7 -7
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.cjs +12 -12
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.d.ts +2 -2
- package/dist/compiler/util.js +12 -12
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +15 -15
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.js +15 -15
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +28 -28
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.d.ts +2 -2
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/dump.js +28 -28
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +5 -5
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.js +5 -5
- package/dist/shared/proc.js.map +1 -1
- package/package.json +21 -19
- package/src/commands/build.ts +57 -55
- package/src/commands/check.ts +15 -12
- package/src/commands/dump/artifacts.ts +11 -15
- package/src/commands/dump/software.ts +9 -10
- package/src/commands/test.ts +15 -12
- package/src/compiler/artifactset.ts +7 -9
- package/src/compiler/compiler.test.ts +134 -137
- package/src/compiler/compiler.ts +62 -62
- package/src/compiler/compileroptions.ts +15 -15
- package/src/compiler/main.test.ts +23 -23
- package/src/compiler/main.ts +83 -100
- package/src/compiler/package.ts +14 -12
- package/src/compiler/source.test.ts +191 -183
- package/src/compiler/source.ts +106 -79
- package/src/compiler/template.test.ts +50 -49
- package/src/compiler/template.ts +11 -21
- package/src/compiler/test.artifacts.ts +47 -47
- package/src/compiler/util.ts +17 -17
- package/src/index.ts +10 -10
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +49 -70
- package/src/shared/proc.ts +8 -8
package/dist/compiler/source.js
CHANGED
|
@@ -4,25 +4,23 @@ import { createArtifactNameSet } from './artifactset.js';
|
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
|
|
6
6
|
// matches any valid name in tengo. Don't forget to use '\b' when needed to limit the boundaries!
|
|
7
|
-
const namePattern =
|
|
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
|
-
+
|
|
11
|
-
|
|
9
|
+
return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` +
|
|
10
|
+
fnName +
|
|
11
|
+
`)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`, "g");
|
|
12
12
|
};
|
|
13
13
|
const functionCallLikeRE = (moduleName, fnName) => {
|
|
14
|
-
return new RegExp(`\\b${moduleName}\\.(?<fnName>`
|
|
15
|
-
+ fnName
|
|
16
|
-
+ `)\\s*\\(`, 'g');
|
|
14
|
+
return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
|
|
17
15
|
};
|
|
18
|
-
const newGetTemplateIdRE = (moduleName) => functionCallRE(moduleName,
|
|
19
|
-
const newGetSoftwareInfoRE = (moduleName) => functionCallRE(moduleName,
|
|
20
|
-
const newImportTemplateRE = (moduleName) => functionCallRE(moduleName,
|
|
21
|
-
const newImportTemplateDetector = (moduleName) => functionCallLikeRE(moduleName,
|
|
22
|
-
const newImportSoftwareRE = (moduleName) => functionCallRE(moduleName,
|
|
23
|
-
const newImportSoftwareDetector = (moduleName) => functionCallLikeRE(moduleName,
|
|
24
|
-
const newImportAssetRE = (moduleName) => functionCallRE(moduleName,
|
|
25
|
-
const newImportAssetDetector = (moduleName) => functionCallLikeRE(moduleName,
|
|
16
|
+
const newGetTemplateIdRE = (moduleName) => functionCallRE(moduleName, "getTemplateId");
|
|
17
|
+
const newGetSoftwareInfoRE = (moduleName) => functionCallRE(moduleName, "getSoftwareInfo");
|
|
18
|
+
const newImportTemplateRE = (moduleName) => functionCallRE(moduleName, "importTemplate");
|
|
19
|
+
const newImportTemplateDetector = (moduleName) => functionCallLikeRE(moduleName, "importTemplate");
|
|
20
|
+
const newImportSoftwareRE = (moduleName) => functionCallRE(moduleName, "importSoftware");
|
|
21
|
+
const newImportSoftwareDetector = (moduleName) => functionCallLikeRE(moduleName, "importSoftware");
|
|
22
|
+
const newImportAssetRE = (moduleName) => functionCallRE(moduleName, "importAsset");
|
|
23
|
+
const newImportAssetDetector = (moduleName) => functionCallLikeRE(moduleName, "importAsset");
|
|
26
24
|
const emptyLineRE = /^\s*$/;
|
|
27
25
|
const compilerOptionRE = /^\/\/tengo:[\w]/;
|
|
28
26
|
const wrongCompilerOptionRE = /^\s*\/\/\s*tengo:\s*./;
|
|
@@ -45,10 +43,10 @@ const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <m
|
|
|
45
43
|
* //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
|
|
46
44
|
*/
|
|
47
45
|
const parseComplierOption = (opt) => {
|
|
48
|
-
const parts = opt.split(
|
|
49
|
-
const namePart = parts[0].split(
|
|
46
|
+
const parts = opt.split(" ");
|
|
47
|
+
const namePart = parts[0].split(":");
|
|
50
48
|
if (namePart.length != 2) {
|
|
51
|
-
throw new Error(
|
|
49
|
+
throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");
|
|
52
50
|
}
|
|
53
51
|
const optName = namePart[1];
|
|
54
52
|
return {
|
|
@@ -104,7 +102,7 @@ function parseSourceData(logger, src, fullSourceName, globalizeImports) {
|
|
|
104
102
|
const dependencySet = createArtifactNameSet();
|
|
105
103
|
const optionList = [];
|
|
106
104
|
// iterating over lines
|
|
107
|
-
const lines = src.split(
|
|
105
|
+
const lines = src.split("\n");
|
|
108
106
|
// processedLines keep all the original lines from <src>.
|
|
109
107
|
// If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines
|
|
110
108
|
// with Platforma Tengo lib and template usages, resolving local names (":<item>") to
|
|
@@ -115,13 +113,13 @@ function parseSourceData(logger, src, fullSourceName, globalizeImports) {
|
|
|
115
113
|
canDetectOptions: true,
|
|
116
114
|
artifactImportREs: new Map(),
|
|
117
115
|
importLikeREs: new Map(),
|
|
118
|
-
multilineStatement:
|
|
116
|
+
multilineStatement: "",
|
|
119
117
|
lineNo: 0,
|
|
120
118
|
};
|
|
121
119
|
for (const line of lines) {
|
|
122
120
|
parserContext.lineNo++;
|
|
123
121
|
try {
|
|
124
|
-
const { line: processedLine, context: newContext, artifacts, option } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
|
|
122
|
+
const { line: processedLine, context: newContext, artifacts, option, } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
|
|
125
123
|
processedLines.push(processedLine);
|
|
126
124
|
parserContext = newContext;
|
|
127
125
|
for (const artifact of artifacts ?? []) {
|
|
@@ -137,7 +135,7 @@ function parseSourceData(logger, src, fullSourceName, globalizeImports) {
|
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
return {
|
|
140
|
-
normalized: processedLines.join(
|
|
138
|
+
normalized: processedLines.join("\n"),
|
|
141
139
|
deps: dependencySet,
|
|
142
140
|
opts: optionList,
|
|
143
141
|
};
|
|
@@ -147,12 +145,12 @@ function parseSingleSourceLine(logger, line, context, localPackageName, globaliz
|
|
|
147
145
|
if (multilineCommentEndRE.exec(line)) {
|
|
148
146
|
context.isInCommentBlock = false;
|
|
149
147
|
}
|
|
150
|
-
return { line:
|
|
148
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
151
149
|
}
|
|
152
150
|
if (compilerOptionRE.exec(line)) {
|
|
153
151
|
if (!context.canDetectOptions) {
|
|
154
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'`);
|
|
155
|
-
throw new Error(
|
|
153
|
+
throw new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
|
|
156
154
|
}
|
|
157
155
|
return { line, context, artifacts: [], option: parseComplierOption(line) };
|
|
158
156
|
}
|
|
@@ -161,15 +159,15 @@ function parseSingleSourceLine(logger, line, context, localPackageName, globaliz
|
|
|
161
159
|
return { line, context, artifacts: [], option: undefined };
|
|
162
160
|
}
|
|
163
161
|
if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {
|
|
164
|
-
return { line:
|
|
162
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
165
163
|
}
|
|
166
|
-
const canBeInlinedComment = line.includes(
|
|
164
|
+
const canBeInlinedComment = line.includes("*/");
|
|
167
165
|
if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
|
|
168
166
|
context.isInCommentBlock = true;
|
|
169
|
-
return { line:
|
|
167
|
+
return { line: "", context, artifacts: [], option: undefined };
|
|
170
168
|
}
|
|
171
169
|
const statement = context.multilineStatement + line.trim();
|
|
172
|
-
const mayContainAComment = line.includes(
|
|
170
|
+
const mayContainAComment = line.includes("//") || line.includes("/*");
|
|
173
171
|
if (multilineStatementRE.test(line) && !mayContainAComment) {
|
|
174
172
|
// We accumulate multiline statements into single line before analyzing them.
|
|
175
173
|
// This dramatically simplifies parsing logic: things like
|
|
@@ -197,7 +195,7 @@ function parseSingleSourceLine(logger, line, context, localPackageName, globaliz
|
|
|
197
195
|
context.multilineStatement += result.line.trim(); // accumulate the line after imports globalization.
|
|
198
196
|
return result;
|
|
199
197
|
}
|
|
200
|
-
context.multilineStatement =
|
|
198
|
+
context.multilineStatement = ""; // reset accumulated multiline statement parts once we reach statement end.
|
|
201
199
|
if (emptyLineRE.exec(statement)) {
|
|
202
200
|
return { line, context, artifacts: [], option: undefined };
|
|
203
201
|
}
|
|
@@ -209,46 +207,46 @@ function processModuleImport(importInstruction, originalLine, statement, context
|
|
|
209
207
|
const iInfo = parseImport(statement);
|
|
210
208
|
// If we have plapi, ll or assets, then try to parse
|
|
211
209
|
// getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.
|
|
212
|
-
if (iInfo.module ===
|
|
210
|
+
if (iInfo.module === "plapi") {
|
|
213
211
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
214
212
|
context.artifactImportREs.set(iInfo.module, [
|
|
215
|
-
[
|
|
216
|
-
[
|
|
213
|
+
["template", newGetTemplateIdRE(iInfo.alias)],
|
|
214
|
+
["software", newGetSoftwareInfoRE(iInfo.alias)],
|
|
217
215
|
]);
|
|
218
216
|
}
|
|
219
217
|
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
220
218
|
}
|
|
221
|
-
if (iInfo.module ===
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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")) {
|
|
226
224
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
227
225
|
context.artifactImportREs.set(iInfo.module, [
|
|
228
|
-
[
|
|
229
|
-
[
|
|
226
|
+
["template", newImportTemplateRE(iInfo.alias)],
|
|
227
|
+
["software", newImportSoftwareRE(iInfo.alias)],
|
|
230
228
|
]);
|
|
231
229
|
}
|
|
232
230
|
}
|
|
233
|
-
if (iInfo.module ===
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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")) {
|
|
238
236
|
if (!context.artifactImportREs.has(iInfo.module)) {
|
|
239
237
|
context.artifactImportREs.set(iInfo.module, [
|
|
240
|
-
[
|
|
241
|
-
[
|
|
242
|
-
[
|
|
238
|
+
["template", newImportTemplateRE(iInfo.alias)],
|
|
239
|
+
["software", newImportSoftwareRE(iInfo.alias)],
|
|
240
|
+
["asset", newImportAssetRE(iInfo.alias)],
|
|
243
241
|
]);
|
|
244
242
|
context.importLikeREs.set(iInfo.module, [
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
[
|
|
243
|
+
["template", newImportTemplateDetector(iInfo.alias)],
|
|
244
|
+
["software", newImportSoftwareDetector(iInfo.alias)],
|
|
245
|
+
["asset", newImportAssetDetector(iInfo.alias)],
|
|
248
246
|
]);
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
|
-
const artifact = parseArtifactName(iInfo.module,
|
|
249
|
+
const artifact = parseArtifactName(iInfo.module, "library", localPackageName);
|
|
252
250
|
if (!artifact) {
|
|
253
251
|
// not a Platforma Tengo library import
|
|
254
252
|
return { line: originalLine, context, artifacts: [], option: undefined };
|
|
@@ -342,7 +340,7 @@ function parseArtifactName(moduleName, aType, localPackageName) {
|
|
|
342
340
|
return { type: aType, pkg: pkgName ?? localPackageName, id: depID };
|
|
343
341
|
}
|
|
344
342
|
function getSha256(source) {
|
|
345
|
-
return createHash(
|
|
343
|
+
return createHash("sha256").update(source).digest("hex");
|
|
346
344
|
}
|
|
347
345
|
|
|
348
346
|
export { ArtifactSource, getSha256, newGetSoftwareInfoRE, newGetTemplateIdRE, parseSingleSourceLine, parseSourceFile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sources":["../../src/compiler/source.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport {\n type TypedArtifactName,\n type FullArtifactName,\n type ArtifactType,\n type CompileMode,\n type CompilerOption,\n fullNameToString,\n} from './package';\nimport type { ArtifactMap } from './artifactset';\nimport { createArtifactNameSet } from './artifactset';\nimport { createHash } from 'node:crypto';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\n\n// matches any valid name in tengo. Don't forget to use '\\b' when needed to limit the boundaries!\nconst namePattern = '[_a-zA-Z][_a-zA-Z0-9]*';\n\nconst functionCallRE = (moduleName: string, fnName: string) => {\n return new RegExp(\n `\\\\b${moduleName}\\\\.(?<fnCall>(?<fnName>`\n + fnName\n + `)\\\\s*\\\\(\\\\s*\"(?<templateName>[^\"]+)\"\\\\s*\\\\))`,\n 'g',\n );\n};\n\nconst functionCallLikeRE = (moduleName: string, fnName: string) => {\n return new RegExp(\n `\\\\b${moduleName}\\\\.(?<fnName>`\n + fnName\n + `)\\\\s*\\\\(`,\n 'g',\n );\n};\n\nexport const newGetTemplateIdRE = (moduleName: string) => functionCallRE(moduleName, 'getTemplateId');\nexport const newGetSoftwareInfoRE = (moduleName: string) => functionCallRE(moduleName, 'getSoftwareInfo');\n\nconst newImportTemplateRE = (moduleName: string) => functionCallRE(moduleName, 'importTemplate');\nconst newImportTemplateDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importTemplate');\nconst newImportSoftwareRE = (moduleName: string) => functionCallRE(moduleName, 'importSoftware');\nconst newImportSoftwareDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importSoftware');\nconst newImportAssetRE = (moduleName: string) => functionCallRE(moduleName, 'importAsset');\nconst newImportAssetDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importAsset');\n\nconst emptyLineRE = /^\\s*$/;\nconst compilerOptionRE = /^\\/\\/tengo:[\\w]/;\nconst wrongCompilerOptionRE = /^\\s*\\/\\/\\s*tengo:\\s*./;\nconst singlelineCommentRE = /^\\s*(\\/\\/)/;\nconst singlelineTerminatedCommentRE = /^\\s*\\/\\*.*\\*\\/\\s*$/; // matches '^/* ... */$' comment lines as a special case of singleline comments.\nconst multilineCommentStartRE = /^\\s*\\/\\*/;\nconst multilineCommentEndRE = /\\*\\//;\nconst multilineStatementRE = /[.,]\\s*$/; // it is hard to consistently treat (\\n\"a\"\\n) multiline statements, we forbid them for now.\n\n// import could only be an assignment in a statement,\n// other ways could break a compilation.\nconst importRE = /\\s*:=\\s*import\\s*\\(\\s*\"(?<moduleName>[^\"]+)\"\\s*\\)/;\nconst importNameRE = new RegExp(\n `\\\\b(?<importName>${namePattern}(\\\\.${namePattern})*)${importRE.source}`,\n);\nconst dependencyRE = /(?<pkgName>[^\"]+)?:(?<depID>[^\"]+)/; // use it to parse <moduleName> from importPattern or <templateName> from getTemplateID\n\n/**\n * Parse compiler option string representation\n * Compiler option line is a comment starting with '//tengo:', say\n * //tengo:hash_override tralala\n *\n * The common compiler option syntax is:\n * //tengo:<option name> [<option arg1> [<option arg 2> [...]]]\n */\nconst parseComplierOption = (opt: string): CompilerOption => {\n const parts = opt.split(' ');\n const namePart = parts[0].split(':');\n if (namePart.length != 2) {\n throw new Error(\n 'compiler option format is wrong: expect to have option name after \\'tengo:\\' prefix, like \\'tengo:MyOption\\'',\n );\n }\n const optName = namePart[1];\n\n return {\n name: optName,\n args: parts.slice(1),\n };\n};\n\nexport class ArtifactSource {\n constructor(\n /** The mode this artifact was built (dev or dist) */\n public readonly compileMode: CompileMode,\n /** Full artifact id, including package version */\n public readonly fullName: FullArtifactName,\n /** Hash of the source code */\n public readonly sourceHash: string,\n /** Normalized source code */\n public readonly src: string,\n /** Path to source file where artifact came from */\n public readonly srcName: string,\n /** List of dependencies */\n public readonly dependencies: TypedArtifactName[],\n /** Additional compiler options detected in source code */\n public readonly compilerOptions: CompilerOption[],\n ) {}\n}\n\nexport function parseSourceFile(\n logger: MiLogger,\n mode: CompileMode,\n srcFile: string,\n fullSourceName: FullArtifactName,\n normalize: boolean,\n): ArtifactSource {\n const src = readFileSync(srcFile).toString();\n const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);\n\n return new ArtifactSource(\n mode,\n fullSourceName,\n getSha256(normalized),\n normalized,\n srcFile,\n deps.array,\n opts,\n );\n}\n\nexport function parseSource(\n logger: MiLogger,\n mode: CompileMode,\n src: string,\n fullSourceName: FullArtifactName,\n normalize: boolean,\n): ArtifactSource {\n const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);\n\n return new ArtifactSource(mode, fullSourceName, getSha256(normalized), normalized, '', deps.array, opts);\n}\n\n/**\n * Reads src\n * returns normalized source code,\n * gets dependencies from imports,\n * maps imports to global names if globalizeImports is true,\n * and collects compiler options like hashOverride.\n */\nfunction parseSourceData(\n logger: MiLogger,\n src: string,\n fullSourceName: FullArtifactName,\n globalizeImports: boolean,\n): {\n normalized: string;\n deps: ArtifactMap<TypedArtifactName>;\n opts: CompilerOption[];\n } {\n const dependencySet = createArtifactNameSet();\n const optionList: CompilerOption[] = [];\n\n // iterating over lines\n const lines = src.split('\\n');\n\n // processedLines keep all the original lines from <src>.\n // If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines\n // with Platforma Tengo lib and template usages, resolving local names (\":<item>\") to\n // global (\"@milaboratory/pkg:<item>\")\n const processedLines: string[] = [];\n let parserContext: sourceParserContext = {\n isInCommentBlock: false,\n canDetectOptions: true,\n artifactImportREs: new Map<string, [ArtifactType, RegExp][]>(),\n importLikeREs: new Map<string, [ArtifactType, RegExp][]>(),\n multilineStatement: '',\n lineNo: 0,\n };\n\n for (const line of lines) {\n parserContext.lineNo++;\n\n try {\n const { line: processedLine, context: newContext, artifacts, option } = parseSingleSourceLine(\n logger,\n line,\n parserContext,\n fullSourceName.pkg,\n globalizeImports,\n );\n processedLines.push(processedLine);\n parserContext = newContext;\n\n for (const artifact of artifacts ?? []) {\n dependencySet.add(artifact);\n }\n if (option) {\n optionList.push(option);\n }\n } catch (error: unknown) {\n const err = error as Error;\n throw new Error(`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\\n\\t${line}`, { cause: err });\n }\n }\n\n return {\n normalized: processedLines.join('\\n'),\n deps: dependencySet,\n opts: optionList,\n };\n}\n\nexport type sourceParserContext = {\n isInCommentBlock: boolean;\n canDetectOptions: boolean;\n artifactImportREs: Map<string, [ArtifactType, RegExp][]>;\n importLikeREs: Map<string, [ArtifactType, RegExp][]>;\n multilineStatement: string;\n lineNo: number;\n};\n\nexport type lineProcessingResult = {\n line: string;\n context: sourceParserContext;\n artifacts: TypedArtifactName[];\n option: CompilerOption | undefined;\n};\n\nexport function parseSingleSourceLine(\n logger: MiLogger,\n line: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n if (context.isInCommentBlock) {\n if (multilineCommentEndRE.exec(line)) {\n context.isInCommentBlock = false;\n }\n return { line: '', context, artifacts: [], option: undefined };\n }\n\n if (compilerOptionRE.exec(line)) {\n if (!context.canDetectOptions) {\n logger.error(\n `[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'`,\n );\n throw new Error('tengo compiler options (\\'//tengo:\\' comments) can be set only in file header');\n }\n return { line, context, artifacts: [], option: parseComplierOption(line) };\n }\n\n if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {\n logger.warn(\n `[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)`,\n );\n return { line, context, artifacts: [], option: undefined };\n }\n\n if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {\n return { line: '', context, artifacts: [], option: undefined };\n }\n\n const canBeInlinedComment = line.includes('*/');\n if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {\n context.isInCommentBlock = true;\n return { line: '', context, artifacts: [], option: undefined };\n }\n\n const statement = context.multilineStatement + line.trim();\n\n const mayContainAComment = line.includes('//') || line.includes('/*');\n if (multilineStatementRE.test(line) && !mayContainAComment) {\n // We accumulate multiline statements into single line before analyzing them.\n // This dramatically simplifies parsing logic: things like\n //\n // assets.\n // importSoftware(\"a:b\");\n //\n // become simple 'assets.importSoftware(\"a:b\");' for parser checks.\n //\n // For safety reasons, we never consider anything that 'may look like a comment'\n // as a part of multiline statement to prevent joining things like\n //\n // someFnCall() // looks like multiline statement because of dot in the end of a comment.\n //\n // This problem also appears in multiline string literals, but I hope this will not\n // cause problems in real life.\n\n // We still try to process each line to globalize imports in case of complex constructions, when\n // statements are stacked one into another:\n // a.\n // use(assets.importSoftware(\":soft1\")).\n // use(assets.importSoftware(\":soft2\")).\n // run()\n // It is multiline, and it still requires import globalization mid-way, not just for the last line of statement\n const result = processAssetImport(line, statement, context, localPackageName, globalizeImports);\n context.multilineStatement += result.line.trim(); // accumulate the line after imports globalization.\n return result;\n }\n\n context.multilineStatement = ''; // reset accumulated multiline statement parts once we reach statement end.\n\n if (emptyLineRE.exec(statement)) {\n return { line, context, artifacts: [], option: undefined };\n }\n\n // options could be only at the top of the file.\n context.canDetectOptions = false;\n\n return processAssetImport(line, statement, context, localPackageName, globalizeImports);\n}\n\nfunction processModuleImport(\n importInstruction: RegExpExecArray,\n originalLine: string,\n statement: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n const iInfo = parseImport(statement);\n\n // If we have plapi, ll or assets, then try to parse\n // getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.\n\n if (iInfo.module === 'plapi') {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n ['template', newGetTemplateIdRE(iInfo.alias)],\n ['software', newGetSoftwareInfoRE(iInfo.alias)],\n ]);\n }\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n if (\n iInfo.module === '@milaboratory/tengo-sdk:ll'\n || iInfo.module === '@platforma-sdk/workflow-tengo:ll'\n || ((localPackageName === '@milaboratory/tengo-sdk'\n || localPackageName === '@platforma-sdk/workflow-tengo')\n && iInfo.module === ':ll')\n ) {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n ['template', newImportTemplateRE(iInfo.alias)],\n ['software', newImportSoftwareRE(iInfo.alias)],\n ]);\n }\n }\n\n if (\n iInfo.module === '@milaboratory/tengo-sdk:assets'\n || iInfo.module === '@platforma-sdk/workflow-tengo:assets'\n || ((localPackageName === '@milaboratory/tengo-sdk'\n || localPackageName === '@platforma-sdk/workflow-tengo')\n && iInfo.module === ':assets')\n ) {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n ['template', newImportTemplateRE(iInfo.alias)],\n ['software', newImportSoftwareRE(iInfo.alias)],\n ['asset', newImportAssetRE(iInfo.alias)],\n ]);\n context.importLikeREs.set(iInfo.module, [\n ['template', newImportTemplateDetector(iInfo.alias)],\n ['software', newImportSoftwareDetector(iInfo.alias)],\n ['asset', newImportAssetDetector(iInfo.alias)],\n ]);\n }\n }\n\n const artifact = parseArtifactName(iInfo.module, 'library', localPackageName);\n if (!artifact) {\n // not a Platforma Tengo library import\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(importInstruction[0], ` := import(\"${artifact.pkg}:${artifact.id}\")`);\n }\n\n return { line: originalLine, context, artifacts: [artifact], option: undefined };\n}\n\nfunction processAssetImport(\n originalLine: string,\n statement: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n if (emptyLineRE.exec(statement)) {\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n // options could be only at the top of the file.\n context.canDetectOptions = false;\n\n const importInstruction = importRE.exec(statement);\n\n if (importInstruction) {\n return processModuleImport(importInstruction, originalLine, statement, context, localPackageName, globalizeImports);\n }\n\n if (context.artifactImportREs.size > 0) {\n for (const [_, artifactRE] of context.artifactImportREs) {\n for (const [artifactType, re] of artifactRE) {\n // Find all matches in the statement\n const matches = Array.from(statement.matchAll(re));\n if (matches.length === 0) {\n continue;\n }\n\n const artifacts: TypedArtifactName[] = [];\n for (let i = matches.length - 1; i >= 0; i--) {\n const match = matches[i];\n if (!match || !match.groups) {\n continue;\n }\n\n const { fnCall, templateName, fnName } = match.groups;\n\n if (!fnCall || !templateName || !fnName) {\n throw Error(`failed to parse template import statement`);\n }\n\n const artifact = parseArtifactName(templateName, artifactType, localPackageName);\n if (!artifact) {\n throw Error(`failed to parse artifact name in ${fnName} import statement`);\n }\n artifacts.push(artifact);\n\n if (globalizeImports) {\n // Replace all occurrences of this fnCall in originalLine\n originalLine = originalLine.replaceAll(fnCall, `${fnName}(\"${artifact.pkg}:${artifact.id}\")`);\n }\n }\n\n return { line: originalLine, context, artifacts, option: undefined };\n }\n }\n }\n\n if (context.importLikeREs.size > 0) {\n for (const [_, artifactRE] of context.importLikeREs) {\n for (const [artifactType, re] of artifactRE) {\n const match = re.exec(statement);\n if (!match || !match.groups) {\n continue;\n }\n\n 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\")').`);\n }\n }\n }\n\n return { line: originalLine, context, artifacts: [], option: undefined };\n}\n\ninterface ImportInfo {\n module: string; // the module name without wrapping quotes: import(\"<module>\")\n alias: string; // the name of variable that keeps imported module: <alias> := import(\"<module>\")\n}\n\nfunction parseImport(line: string): ImportInfo {\n const match = importNameRE.exec(line);\n\n if (!match || !match.groups) {\n throw Error(`failed to parse 'import' statement`);\n }\n\n const { importName, moduleName } = match.groups;\n if (!importName || !moduleName) {\n throw Error(`failed to parse 'import' statement`);\n }\n\n return {\n module: moduleName, // the module name without wrapping quotes: import(\"<module>\")\n alias: importName, // the name of variable that keeps imported module: <alias> := import(\"<module>\")\n };\n}\n\nfunction parseArtifactName(\n moduleName: string,\n aType: ArtifactType,\n localPackageName: string,\n): TypedArtifactName | undefined {\n const depInfo = dependencyRE.exec(moduleName);\n if (!depInfo) {\n return;\n }\n\n if (!depInfo.groups) {\n throw Error(\n `failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,\n );\n }\n\n const { pkgName, depID } = depInfo.groups;\n if (!depID) {\n throw Error(\n `failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,\n );\n }\n\n return { type: aType, pkg: pkgName ?? localPackageName, id: depID };\n}\n\nexport function getSha256(source: string): string {\n return createHash('sha256').update(source).digest('hex');\n}\n"],"names":[],"mappings":";;;;;AAcA;AACA,MAAM,WAAW,GAAG,wBAAwB;AAE5C,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAE,MAAc,KAAI;AAC5D,IAAA,OAAO,IAAI,MAAM,CACf,CAAA,GAAA,EAAM,UAA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ACL,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,UAAU;KAClB;AACH;AAEA,SAAS,iBAAiB,CACxB,UAAkB,EAClB,KAAmB,EACnB,gBAAwB,EAAA;IAExB,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE;QACZ;IACF;AAEA,IAAA,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;AACnB,QAAA,MAAM,KAAK,CACT,CAAA,4HAAA,CAA8H,CAC/H;IACH;IAEA,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,MAAM;IACzC,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,MAAM,KAAK,CACT,CAAA,4HAAA,CAA8H,CAC/H;IACH;AAEA,IAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,IAAI,gBAAgB,EAAE,EAAE,EAAE,KAAK,EAAE;AACrE;AAEM,SAAU,SAAS,CAAC,MAAc,EAAA;AACtC,IAAA,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAC1D;;;;"}
|
|
1
|
+
{"version":3,"file":"source.js","sources":["../../src/compiler/source.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport {\n type TypedArtifactName,\n type FullArtifactName,\n type ArtifactType,\n type CompileMode,\n type CompilerOption,\n fullNameToString,\n} from \"./package\";\nimport type { ArtifactMap } from \"./artifactset\";\nimport { createArtifactNameSet } from \"./artifactset\";\nimport { createHash } from \"node:crypto\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\n\n// matches any valid name in tengo. Don't forget to use '\\b' when needed to limit the boundaries!\nconst namePattern = \"[_a-zA-Z][_a-zA-Z0-9]*\";\n\nconst functionCallRE = (moduleName: string, fnName: string) => {\n return new RegExp(\n `\\\\b${moduleName}\\\\.(?<fnCall>(?<fnName>` +\n fnName +\n `)\\\\s*\\\\(\\\\s*\"(?<templateName>[^\"]+)\"\\\\s*\\\\))`,\n \"g\",\n );\n};\n\nconst functionCallLikeRE = (moduleName: string, fnName: string) => {\n return new RegExp(`\\\\b${moduleName}\\\\.(?<fnName>` + fnName + `)\\\\s*\\\\(`, \"g\");\n};\n\nexport const newGetTemplateIdRE = (moduleName: string) =>\n functionCallRE(moduleName, \"getTemplateId\");\nexport const newGetSoftwareInfoRE = (moduleName: string) =>\n functionCallRE(moduleName, \"getSoftwareInfo\");\n\nconst newImportTemplateRE = (moduleName: string) => functionCallRE(moduleName, \"importTemplate\");\nconst newImportTemplateDetector = (moduleName: string) =>\n functionCallLikeRE(moduleName, \"importTemplate\");\nconst newImportSoftwareRE = (moduleName: string) => functionCallRE(moduleName, \"importSoftware\");\nconst newImportSoftwareDetector = (moduleName: string) =>\n functionCallLikeRE(moduleName, \"importSoftware\");\nconst newImportAssetRE = (moduleName: string) => functionCallRE(moduleName, \"importAsset\");\nconst newImportAssetDetector = (moduleName: string) =>\n functionCallLikeRE(moduleName, \"importAsset\");\n\nconst emptyLineRE = /^\\s*$/;\nconst compilerOptionRE = /^\\/\\/tengo:[\\w]/;\nconst wrongCompilerOptionRE = /^\\s*\\/\\/\\s*tengo:\\s*./;\nconst singlelineCommentRE = /^\\s*(\\/\\/)/;\nconst singlelineTerminatedCommentRE = /^\\s*\\/\\*.*\\*\\/\\s*$/; // matches '^/* ... */$' comment lines as a special case of singleline comments.\nconst multilineCommentStartRE = /^\\s*\\/\\*/;\nconst multilineCommentEndRE = /\\*\\//;\nconst multilineStatementRE = /[.,]\\s*$/; // it is hard to consistently treat (\\n\"a\"\\n) multiline statements, we forbid them for now.\n\n// import could only be an assignment in a statement,\n// other ways could break a compilation.\nconst importRE = /\\s*:=\\s*import\\s*\\(\\s*\"(?<moduleName>[^\"]+)\"\\s*\\)/;\nconst importNameRE = new RegExp(\n `\\\\b(?<importName>${namePattern}(\\\\.${namePattern})*)${importRE.source}`,\n);\nconst dependencyRE = /(?<pkgName>[^\"]+)?:(?<depID>[^\"]+)/; // use it to parse <moduleName> from importPattern or <templateName> from getTemplateID\n\n/**\n * Parse compiler option string representation\n * Compiler option line is a comment starting with '//tengo:', say\n * //tengo:hash_override tralala\n *\n * The common compiler option syntax is:\n * //tengo:<option name> [<option arg1> [<option arg 2> [...]]]\n */\nconst parseComplierOption = (opt: string): CompilerOption => {\n const parts = opt.split(\" \");\n const namePart = parts[0].split(\":\");\n if (namePart.length != 2) {\n throw new Error(\n \"compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'\",\n );\n }\n const optName = namePart[1];\n\n return {\n name: optName,\n args: parts.slice(1),\n };\n};\n\nexport class ArtifactSource {\n constructor(\n /** The mode this artifact was built (dev or dist) */\n public readonly compileMode: CompileMode,\n /** Full artifact id, including package version */\n public readonly fullName: FullArtifactName,\n /** Hash of the source code */\n public readonly sourceHash: string,\n /** Normalized source code */\n public readonly src: string,\n /** Path to source file where artifact came from */\n public readonly srcName: string,\n /** List of dependencies */\n public readonly dependencies: TypedArtifactName[],\n /** Additional compiler options detected in source code */\n public readonly compilerOptions: CompilerOption[],\n ) {}\n}\n\nexport function parseSourceFile(\n logger: MiLogger,\n mode: CompileMode,\n srcFile: string,\n fullSourceName: FullArtifactName,\n normalize: boolean,\n): ArtifactSource {\n const src = readFileSync(srcFile).toString();\n const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);\n\n return new ArtifactSource(\n mode,\n fullSourceName,\n getSha256(normalized),\n normalized,\n srcFile,\n deps.array,\n opts,\n );\n}\n\nexport function parseSource(\n logger: MiLogger,\n mode: CompileMode,\n src: string,\n fullSourceName: FullArtifactName,\n normalize: boolean,\n): ArtifactSource {\n const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);\n\n return new ArtifactSource(\n mode,\n fullSourceName,\n getSha256(normalized),\n normalized,\n \"\",\n deps.array,\n opts,\n );\n}\n\n/**\n * Reads src\n * returns normalized source code,\n * gets dependencies from imports,\n * maps imports to global names if globalizeImports is true,\n * and collects compiler options like hashOverride.\n */\nfunction parseSourceData(\n logger: MiLogger,\n src: string,\n fullSourceName: FullArtifactName,\n globalizeImports: boolean,\n): {\n normalized: string;\n deps: ArtifactMap<TypedArtifactName>;\n opts: CompilerOption[];\n} {\n const dependencySet = createArtifactNameSet();\n const optionList: CompilerOption[] = [];\n\n // iterating over lines\n const lines = src.split(\"\\n\");\n\n // processedLines keep all the original lines from <src>.\n // If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines\n // with Platforma Tengo lib and template usages, resolving local names (\":<item>\") to\n // global (\"@milaboratory/pkg:<item>\")\n const processedLines: string[] = [];\n let parserContext: sourceParserContext = {\n isInCommentBlock: false,\n canDetectOptions: true,\n artifactImportREs: new Map<string, [ArtifactType, RegExp][]>(),\n importLikeREs: new Map<string, [ArtifactType, RegExp][]>(),\n multilineStatement: \"\",\n lineNo: 0,\n };\n\n for (const line of lines) {\n parserContext.lineNo++;\n\n try {\n const {\n line: processedLine,\n context: newContext,\n artifacts,\n option,\n } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);\n processedLines.push(processedLine);\n parserContext = newContext;\n\n for (const artifact of artifacts ?? []) {\n dependencySet.add(artifact);\n }\n if (option) {\n optionList.push(option);\n }\n } catch (error: unknown) {\n const err = error as Error;\n throw new Error(\n `[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\\n\\t${line}`,\n { cause: err },\n );\n }\n }\n\n return {\n normalized: processedLines.join(\"\\n\"),\n deps: dependencySet,\n opts: optionList,\n };\n}\n\nexport type sourceParserContext = {\n isInCommentBlock: boolean;\n canDetectOptions: boolean;\n artifactImportREs: Map<string, [ArtifactType, RegExp][]>;\n importLikeREs: Map<string, [ArtifactType, RegExp][]>;\n multilineStatement: string;\n lineNo: number;\n};\n\nexport type lineProcessingResult = {\n line: string;\n context: sourceParserContext;\n artifacts: TypedArtifactName[];\n option: CompilerOption | undefined;\n};\n\nexport function parseSingleSourceLine(\n logger: MiLogger,\n line: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n if (context.isInCommentBlock) {\n if (multilineCommentEndRE.exec(line)) {\n context.isInCommentBlock = false;\n }\n return { line: \"\", context, artifacts: [], option: undefined };\n }\n\n if (compilerOptionRE.exec(line)) {\n if (!context.canDetectOptions) {\n logger.error(\n `[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'`,\n );\n throw new Error(\n \"tengo compiler options ('//tengo:' comments) can be set only in file header\",\n );\n }\n return { line, context, artifacts: [], option: parseComplierOption(line) };\n }\n\n if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {\n logger.warn(\n `[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)`,\n );\n return { line, context, artifacts: [], option: undefined };\n }\n\n if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {\n return { line: \"\", context, artifacts: [], option: undefined };\n }\n\n const canBeInlinedComment = line.includes(\"*/\");\n if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {\n context.isInCommentBlock = true;\n return { line: \"\", context, artifacts: [], option: undefined };\n }\n\n const statement = context.multilineStatement + line.trim();\n\n const mayContainAComment = line.includes(\"//\") || line.includes(\"/*\");\n if (multilineStatementRE.test(line) && !mayContainAComment) {\n // We accumulate multiline statements into single line before analyzing them.\n // This dramatically simplifies parsing logic: things like\n //\n // assets.\n // importSoftware(\"a:b\");\n //\n // become simple 'assets.importSoftware(\"a:b\");' for parser checks.\n //\n // For safety reasons, we never consider anything that 'may look like a comment'\n // as a part of multiline statement to prevent joining things like\n //\n // someFnCall() // looks like multiline statement because of dot in the end of a comment.\n //\n // This problem also appears in multiline string literals, but I hope this will not\n // cause problems in real life.\n\n // We still try to process each line to globalize imports in case of complex constructions, when\n // statements are stacked one into another:\n // a.\n // use(assets.importSoftware(\":soft1\")).\n // use(assets.importSoftware(\":soft2\")).\n // run()\n // It is multiline, and it still requires import globalization mid-way, not just for the last line of statement\n const result = processAssetImport(line, statement, context, localPackageName, globalizeImports);\n context.multilineStatement += result.line.trim(); // accumulate the line after imports globalization.\n return result;\n }\n\n context.multilineStatement = \"\"; // reset accumulated multiline statement parts once we reach statement end.\n\n if (emptyLineRE.exec(statement)) {\n return { line, context, artifacts: [], option: undefined };\n }\n\n // options could be only at the top of the file.\n context.canDetectOptions = false;\n\n return processAssetImport(line, statement, context, localPackageName, globalizeImports);\n}\n\nfunction processModuleImport(\n importInstruction: RegExpExecArray,\n originalLine: string,\n statement: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n const iInfo = parseImport(statement);\n\n // If we have plapi, ll or assets, then try to parse\n // getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.\n\n if (iInfo.module === \"plapi\") {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n [\"template\", newGetTemplateIdRE(iInfo.alias)],\n [\"software\", newGetSoftwareInfoRE(iInfo.alias)],\n ]);\n }\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n if (\n iInfo.module === \"@milaboratory/tengo-sdk:ll\" ||\n iInfo.module === \"@platforma-sdk/workflow-tengo:ll\" ||\n ((localPackageName === \"@milaboratory/tengo-sdk\" ||\n localPackageName === \"@platforma-sdk/workflow-tengo\") &&\n iInfo.module === \":ll\")\n ) {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n [\"template\", newImportTemplateRE(iInfo.alias)],\n [\"software\", newImportSoftwareRE(iInfo.alias)],\n ]);\n }\n }\n\n if (\n iInfo.module === \"@milaboratory/tengo-sdk:assets\" ||\n iInfo.module === \"@platforma-sdk/workflow-tengo:assets\" ||\n ((localPackageName === \"@milaboratory/tengo-sdk\" ||\n localPackageName === \"@platforma-sdk/workflow-tengo\") &&\n iInfo.module === \":assets\")\n ) {\n if (!context.artifactImportREs.has(iInfo.module)) {\n context.artifactImportREs.set(iInfo.module, [\n [\"template\", newImportTemplateRE(iInfo.alias)],\n [\"software\", newImportSoftwareRE(iInfo.alias)],\n [\"asset\", newImportAssetRE(iInfo.alias)],\n ]);\n context.importLikeREs.set(iInfo.module, [\n [\"template\", newImportTemplateDetector(iInfo.alias)],\n [\"software\", newImportSoftwareDetector(iInfo.alias)],\n [\"asset\", newImportAssetDetector(iInfo.alias)],\n ]);\n }\n }\n\n const artifact = parseArtifactName(iInfo.module, \"library\", localPackageName);\n if (!artifact) {\n // not a Platforma Tengo library import\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(\n importInstruction[0],\n ` := import(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n\n return { line: originalLine, context, artifacts: [artifact], option: undefined };\n}\n\nfunction processAssetImport(\n originalLine: string,\n statement: string,\n context: sourceParserContext,\n localPackageName: string,\n globalizeImports?: boolean,\n): lineProcessingResult {\n if (emptyLineRE.exec(statement)) {\n return { line: originalLine, context, artifacts: [], option: undefined };\n }\n\n // options could be only at the top of the file.\n context.canDetectOptions = false;\n\n const importInstruction = importRE.exec(statement);\n\n if (importInstruction) {\n return processModuleImport(\n importInstruction,\n originalLine,\n statement,\n context,\n localPackageName,\n globalizeImports,\n );\n }\n\n if (context.artifactImportREs.size > 0) {\n for (const [_, artifactRE] of context.artifactImportREs) {\n for (const [artifactType, re] of artifactRE) {\n // Find all matches in the statement\n const matches = Array.from(statement.matchAll(re));\n if (matches.length === 0) {\n continue;\n }\n\n const artifacts: TypedArtifactName[] = [];\n for (let i = matches.length - 1; i >= 0; i--) {\n const match = matches[i];\n if (!match || !match.groups) {\n continue;\n }\n\n const { fnCall, templateName, fnName } = match.groups;\n\n if (!fnCall || !templateName || !fnName) {\n throw Error(`failed to parse template import statement`);\n }\n\n const artifact = parseArtifactName(templateName, artifactType, localPackageName);\n if (!artifact) {\n throw Error(`failed to parse artifact name in ${fnName} import statement`);\n }\n artifacts.push(artifact);\n\n if (globalizeImports) {\n // Replace all occurrences of this fnCall in originalLine\n originalLine = originalLine.replaceAll(\n fnCall,\n `${fnName}(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n }\n\n return { line: originalLine, context, artifacts, option: undefined };\n }\n }\n }\n\n if (context.importLikeREs.size > 0) {\n for (const [_, artifactRE] of context.importLikeREs) {\n for (const [artifactType, re] of artifactRE) {\n const match = re.exec(statement);\n if (!match || !match.groups) {\n continue;\n }\n\n throw Error(\n `incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware(\"sw:main\")').`,\n );\n }\n }\n }\n\n return { line: originalLine, context, artifacts: [], option: undefined };\n}\n\ninterface ImportInfo {\n module: string; // the module name without wrapping quotes: import(\"<module>\")\n alias: string; // the name of variable that keeps imported module: <alias> := import(\"<module>\")\n}\n\nfunction parseImport(line: string): ImportInfo {\n const match = importNameRE.exec(line);\n\n if (!match || !match.groups) {\n throw Error(`failed to parse 'import' statement`);\n }\n\n const { importName, moduleName } = match.groups;\n if (!importName || !moduleName) {\n throw Error(`failed to parse 'import' statement`);\n }\n\n return {\n module: moduleName, // the module name without wrapping quotes: import(\"<module>\")\n alias: importName, // the name of variable that keeps imported module: <alias> := import(\"<module>\")\n };\n}\n\nfunction parseArtifactName(\n moduleName: string,\n aType: ArtifactType,\n localPackageName: string,\n): TypedArtifactName | undefined {\n const depInfo = dependencyRE.exec(moduleName);\n if (!depInfo) {\n return;\n }\n\n if (!depInfo.groups) {\n throw Error(\n `failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,\n );\n }\n\n const { pkgName, depID } = depInfo.groups;\n if (!depID) {\n throw Error(\n `failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,\n );\n }\n\n return { type: aType, pkg: pkgName ?? localPackageName, id: depID };\n}\n\nexport function getSha256(source: string): string {\n return createHash(\"sha256\").update(source).digest(\"hex\");\n}\n"],"names":[],"mappings":";;;;;AAcA;AACA,MAAM,WAAW,GAAG,wBAAwB;AAE5C,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAE,MAAc,KAAI;AAC5D,IAAA,OAAO,IAAI,MAAM,CACf,CAAA,GAAA,EAAM,UAAU,CAAA,uBAAA,CAAyB;QACvC,MAAM;QACN,CAAA,4CAAA,CAA8C,EAChD,GAAG,CACJ;AACH,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAE,MAAc,KAAI;AAChE,IAAA,OAAO,IAAI,MAAM,CAAC,CAAA,GAAA,EAAM,UAAU,CAAA,aAAA,CAAe,GAAG,MAAM,GAAG,CAAA,QAAA,CAAU,EAAE,GAAG,CAAC;AAC/E,CAAC;AAEM,MAAM,kBAAkB,GAAG,CAAC,UAAkB,KACnD,cAAc,CAAC,UAAU,EAAE,eAAe;AACrC,MAAM,oBAAoB,GAAG,CAAC,UAAkB,KACrD,cAAc,CAAC,UAAU,EAAE,iBAAiB;AAE9C,MAAM,mBAAmB,GAAG,CAAC,UAAkB,KAAK,cAAc,CAAC,UAAU,EAAE,gBAAgB,CAAC;AAChG,MAAM,yBAAyB,GAAG,CAAC,UAAkB,KACnD,kBAAkB,CAAC,UAAU,EAAE,gBAAgB,CAAC;AAClD,MAAM,mBAAmB,GAAG,CAAC,UAAkB,KAAK,cAAc,CAAC,UAAU,EAAE,gBAAgB,CAAC;AAChG,MAAM,yBAAyB,GAAG,CAAC,UAAkB,KACnD,kBAAkB,CAAC,UAAU,EAAE,gBAAgB,CAAC;AAClD,MAAM,gBAAgB,GAAG,CAAC,UAAkB,KAAK,cAAc,CAAC,UAAU,EAAE,aAAa,CAAC;AAC1F,MAAM,sBAAsB,GAAG,CAAC,UAAkB,KAChD,kBAAkB,CAAC,UAAU,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, fullName, content) {
|
|
16
16
|
const data = plModelBackend.parseTemplate(content);
|
|
17
|
-
if (data.type !==
|
|
18
|
-
throw new Error(
|
|
17
|
+
if (data.type !== "pl.tengo-template.v3") {
|
|
18
|
+
throw new Error("malformed v3 template");
|
|
19
19
|
}
|
|
20
20
|
validateTemplateName(fullName, data);
|
|
21
21
|
return {
|
|
@@ -35,11 +35,11 @@ function templateToSource(tpl) {
|
|
|
35
35
|
}
|
|
36
36
|
function validateTemplateName(fullName, data) {
|
|
37
37
|
const nameFromData = _package.parseArtefactNameAndVersion(data.template);
|
|
38
|
-
if (nameFromData.pkg !== fullName.pkg
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw new Error(`Compiled template name don't match it's package and file names: `
|
|
42
|
-
|
|
38
|
+
if (nameFromData.pkg !== fullName.pkg ||
|
|
39
|
+
nameFromData.id !== fullName.id ||
|
|
40
|
+
nameFromData.version !== fullName.version)
|
|
41
|
+
throw new Error(`Compiled template name don't match it's package and file names: ` +
|
|
42
|
+
`${_package.fullNameWithoutTypeToString(nameFromData)} != ${_package.fullNameWithoutTypeToString(fullName)}`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
exports.newTemplateFromContent = newTemplateFromContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.cjs","sources":["../../src/compiler/template.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"template.cjs","sources":["../../src/compiler/template.ts"],"sourcesContent":["import type { CompileMode, FullArtifactName, FullArtifactNameWithoutType } from \"./package\";\nimport { fullNameWithoutTypeToString, parseArtefactNameAndVersion } from \"./package\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\nimport { parseTemplate, serializeTemplate } from \"@milaboratories/pl-model-backend\";\n\n/** Just a holder for template data, compilation options, full name and source code.\n * It mimics ArtifactSource interface.\n */\nexport type TemplateWithSource = {\n readonly compileMode: CompileMode;\n readonly fullName: FullArtifactName;\n readonly source: string;\n readonly data: CompiledTemplateV3;\n};\n\nexport function newTemplateWithSource(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n source: string,\n): TemplateWithSource {\n validateTemplateName(fullName, data);\n\n return {\n compileMode,\n fullName,\n data,\n source,\n };\n}\n\nexport type Template = {\n readonly compileMode: CompileMode;\n readonly fullName: FullArtifactName;\n readonly data: CompiledTemplateV3;\n readonly content: Uint8Array;\n};\n\nexport function newTemplateFromData(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n): Template {\n validateTemplateName(fullName, data);\n return {\n compileMode,\n fullName,\n data,\n content: serializeTemplate(data),\n };\n}\n\nexport function newTemplateFromContent(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n content: Uint8Array,\n): Template {\n const data = parseTemplate(content);\n if (data.type !== \"pl.tengo-template.v3\") {\n throw new Error(\"malformed v3 template\");\n }\n\n validateTemplateName(fullName, data);\n return {\n compileMode,\n fullName,\n data,\n content,\n };\n}\n\nexport function templateToSource(tpl: Template): TemplateWithSource {\n return {\n compileMode: tpl.compileMode,\n fullName: tpl.fullName,\n data: tpl.data,\n source: tpl.data.hashToSource[tpl.data.template.sourceHash],\n };\n}\nfunction validateTemplateName(fullName: FullArtifactName, data: CompiledTemplateV3) {\n const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data.template);\n\n if (\n nameFromData.pkg !== fullName.pkg ||\n nameFromData.id !== fullName.id ||\n nameFromData.version !== fullName.version\n )\n throw new Error(\n `Compiled template name don't match it's package and file names: ` +\n `${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,\n );\n}\n"],"names":["parseTemplate","parseArtefactNameAndVersion","fullNameWithoutTypeToString"],"mappings":";;;;;AAeM,SAAU,qBAAqB,CACnC,WAAwB,EACxB,QAA0B,EAC1B,IAAwB,EACxB,MAAc,EAAA;AAEd,IAAA,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC;IAEpC,OAAO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
-
import type { CompiledTemplateV3 } from
|
|
1
|
+
import type { CompileMode, FullArtifactName } from "./package";
|
|
2
|
+
import type { CompiledTemplateV3 } from "@milaboratories/pl-model-backend";
|
|
3
3
|
/** Just a holder for template data, compilation options, full name and source code.
|
|
4
4
|
* It mimics ArtifactSource interface.
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/compiler/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/compiler/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAA+B,MAAM,WAAW,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAG3E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;CACnC,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,GACb,kBAAkB,CASpB;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,kBAAkB,GACvB,QAAQ,CAQV;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,UAAU,GAClB,QAAQ,CAaV;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,kBAAkB,CAOlE"}
|
|
@@ -12,8 +12,8 @@ function newTemplateWithSource(compileMode, fullName, data, source) {
|
|
|
12
12
|
}
|
|
13
13
|
function newTemplateFromContent(compileMode, fullName, content) {
|
|
14
14
|
const data = parseTemplate(content);
|
|
15
|
-
if (data.type !==
|
|
16
|
-
throw new Error(
|
|
15
|
+
if (data.type !== "pl.tengo-template.v3") {
|
|
16
|
+
throw new Error("malformed v3 template");
|
|
17
17
|
}
|
|
18
18
|
validateTemplateName(fullName, data);
|
|
19
19
|
return {
|
|
@@ -33,11 +33,11 @@ function templateToSource(tpl) {
|
|
|
33
33
|
}
|
|
34
34
|
function validateTemplateName(fullName, data) {
|
|
35
35
|
const nameFromData = parseArtefactNameAndVersion(data.template);
|
|
36
|
-
if (nameFromData.pkg !== fullName.pkg
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error(`Compiled template name don't match it's package and file names: `
|
|
40
|
-
|
|
36
|
+
if (nameFromData.pkg !== fullName.pkg ||
|
|
37
|
+
nameFromData.id !== fullName.id ||
|
|
38
|
+
nameFromData.version !== fullName.version)
|
|
39
|
+
throw new Error(`Compiled template name don't match it's package and file names: ` +
|
|
40
|
+
`${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export { newTemplateFromContent, newTemplateWithSource, templateToSource };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sources":["../../src/compiler/template.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"template.js","sources":["../../src/compiler/template.ts"],"sourcesContent":["import type { CompileMode, FullArtifactName, FullArtifactNameWithoutType } from \"./package\";\nimport { fullNameWithoutTypeToString, parseArtefactNameAndVersion } from \"./package\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\nimport { parseTemplate, serializeTemplate } from \"@milaboratories/pl-model-backend\";\n\n/** Just a holder for template data, compilation options, full name and source code.\n * It mimics ArtifactSource interface.\n */\nexport type TemplateWithSource = {\n readonly compileMode: CompileMode;\n readonly fullName: FullArtifactName;\n readonly source: string;\n readonly data: CompiledTemplateV3;\n};\n\nexport function newTemplateWithSource(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n source: string,\n): TemplateWithSource {\n validateTemplateName(fullName, data);\n\n return {\n compileMode,\n fullName,\n data,\n source,\n };\n}\n\nexport type Template = {\n readonly compileMode: CompileMode;\n readonly fullName: FullArtifactName;\n readonly data: CompiledTemplateV3;\n readonly content: Uint8Array;\n};\n\nexport function newTemplateFromData(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n): Template {\n validateTemplateName(fullName, data);\n return {\n compileMode,\n fullName,\n data,\n content: serializeTemplate(data),\n };\n}\n\nexport function newTemplateFromContent(\n compileMode: CompileMode,\n fullName: FullArtifactName,\n content: Uint8Array,\n): Template {\n const data = parseTemplate(content);\n if (data.type !== \"pl.tengo-template.v3\") {\n throw new Error(\"malformed v3 template\");\n }\n\n validateTemplateName(fullName, data);\n return {\n compileMode,\n fullName,\n data,\n content,\n };\n}\n\nexport function templateToSource(tpl: Template): TemplateWithSource {\n return {\n compileMode: tpl.compileMode,\n fullName: tpl.fullName,\n data: tpl.data,\n source: tpl.data.hashToSource[tpl.data.template.sourceHash],\n };\n}\nfunction validateTemplateName(fullName: FullArtifactName, data: CompiledTemplateV3) {\n const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data.template);\n\n if (\n nameFromData.pkg !== fullName.pkg ||\n nameFromData.id !== fullName.id ||\n nameFromData.version !== fullName.version\n )\n throw new Error(\n `Compiled template name don't match it's package and file names: ` +\n `${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,\n );\n}\n"],"names":[],"mappings":";;;AAeM,SAAU,qBAAqB,CACnC,WAAwB,EACxB,QAA0B,EAC1B,IAAwB,EACxB,MAAc,EAAA;AAEd,IAAA,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC;IAEpC,OAAO;QACL,WAAW;QACX,QAAQ;QACR,IAAI;QACJ,MAAM;KACP;AACH;SAuBgB,sBAAsB,CACpC,WAAwB,EACxB,QAA0B,EAC1B,OAAmB,EAAA;AAEnB,IAAA,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC;AACnC,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE;AACxC,QAAA,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC;IAC1C;AAEA,IAAA,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC;IACpC,OAAO;QACL,WAAW;QACX,QAAQ;QACR,IAAI;QACJ,OAAO;KACR;AACH;AAEM,SAAU,gBAAgB,CAAC,GAAa,EAAA;IAC5C,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,GAAG,CAAC,IAAI;AACd,QAAA,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;KAC5D;AACH;AACA,SAAS,oBAAoB,CAAC,QAA0B,EAAE,IAAwB,EAAA;IAChF,MAAM,YAAY,GAAgC,2BAA2B,CAAC,IAAI,CAAC,QAAQ,CAAC;AAE5F,IAAA,IACE,YAAY,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG;AACjC,QAAA,YAAY,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE;AAC/B,QAAA,YAAY,CAAC,OAAO,KAAK,QAAQ,CAAC,OA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kBAAkB,EAI5C,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,kBAAkB,EAAmC,CAAC;AAEjF,eAAO,MAAM,sBAAsB,EAAE,kBAAkB,EAMtD,CAAC;AAEF,eAAO,MAAM,kBAAkB,uUAU9B,CAAC;AAEF,eAAO,MAAM,yBAAyB,uVAUrC,CAAC"}
|
package/dist/compiler/util.cjs
CHANGED
|
@@ -25,18 +25,18 @@ var winston__namespace = /*#__PURE__*/_interopNamespaceDefault(winston);
|
|
|
25
25
|
|
|
26
26
|
function assertNever(x) {
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
28
|
-
throw new Error(
|
|
28
|
+
throw new Error("Unexpected object: " + x);
|
|
29
29
|
}
|
|
30
|
-
function createLogger(level =
|
|
30
|
+
function createLogger(level = "debug") {
|
|
31
31
|
return winston__namespace.createLogger({
|
|
32
32
|
level: level,
|
|
33
33
|
format: winston__namespace.format.combine(winston__namespace.format.errors({ stack: true }), winston__namespace.format.printf(({ level, message, stack }) => {
|
|
34
|
-
const baseMessage = `${level.padStart(6,
|
|
34
|
+
const baseMessage = `${level.padStart(6, " ")}: ${message}`;
|
|
35
35
|
return stack ? `${baseMessage}\n${stack}` : baseMessage;
|
|
36
36
|
})),
|
|
37
37
|
transports: [
|
|
38
38
|
new winston__namespace.transports.Console({
|
|
39
|
-
stderrLevels: [
|
|
39
|
+
stderrLevels: ["error", "warn", "info", "debug"],
|
|
40
40
|
handleExceptions: true,
|
|
41
41
|
}),
|
|
42
42
|
],
|
|
@@ -46,19 +46,19 @@ function pathType(path) {
|
|
|
46
46
|
try {
|
|
47
47
|
const s = fs__namespace.statSync(path);
|
|
48
48
|
if (s.isDirectory())
|
|
49
|
-
return
|
|
49
|
+
return "dir";
|
|
50
50
|
if (s.isFile())
|
|
51
|
-
return
|
|
51
|
+
return "file";
|
|
52
52
|
if (s.isSymbolicLink())
|
|
53
|
-
return
|
|
54
|
-
return
|
|
53
|
+
return "link";
|
|
54
|
+
return "unknown";
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
57
|
const err = error;
|
|
58
|
-
if (err.code ==
|
|
59
|
-
return
|
|
60
|
-
if (err.code ==
|
|
61
|
-
return
|
|
58
|
+
if (err.code == "ENOENT")
|
|
59
|
+
return "absent";
|
|
60
|
+
if (err.code == "ENOTDIR")
|
|
61
|
+
return "absent";
|
|
62
62
|
else
|
|
63
63
|
throw err;
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.cjs","sources":["../../src/compiler/util.ts"],"sourcesContent":["import * as fs from
|
|
1
|
+
{"version":3,"file":"util.cjs","sources":["../../src/compiler/util.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as winston from \"winston\";\n\nexport function assertNever(x: never): never {\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function createLogger(level: string = \"debug\"): winston.Logger {\n return winston.createLogger({\n level: level,\n format: winston.format.combine(\n winston.format.errors({ stack: true }),\n winston.format.printf(({ level, message, stack }) => {\n const baseMessage = `${level.padStart(6, \" \")}: ${message as string}`;\n return stack ? `${baseMessage}\\n${stack as string}` : baseMessage;\n }),\n ),\n transports: [\n new winston.transports.Console({\n stderrLevels: [\"error\", \"warn\", \"info\", \"debug\"],\n handleExceptions: true,\n }),\n ],\n });\n}\n\nexport function findNodeModules(): string {\n let currentDir = process.cwd();\n\n while (currentDir) {\n const possibleNodeModulesPath = path.join(currentDir, \"node_modules\");\n\n if (fs.existsSync(possibleNodeModulesPath)) return possibleNodeModulesPath;\n\n const parentDir = path.resolve(currentDir, \"..\");\n if (parentDir === currentDir) break; // reached the root directory\n\n currentDir = parentDir;\n }\n\n throw new Error(\"Unable to find node_modules directory.\");\n}\n\nexport type PathType = \"absent\" | \"file\" | \"dir\" | \"link\" | \"unknown\";\n\nexport function pathType(path: string): PathType {\n try {\n const s = fs.statSync(path);\n if (s.isDirectory()) return \"dir\";\n if (s.isFile()) return \"file\";\n if (s.isSymbolicLink()) return \"link\";\n return \"unknown\";\n } catch (error: unknown) {\n const err = error as NodeJS.ErrnoException;\n if (err.code == \"ENOENT\") return \"absent\";\n if (err.code == \"ENOTDIR\") return \"absent\";\n else throw err;\n }\n}\n\nexport function isUUID(uuid: string): boolean {\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n return uuidRegex.test(uuid.toLowerCase());\n}\n"],"names":["winston","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIM,SAAU,WAAW,CAAC,CAAQ,EAAA;;AAElC,IAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAC,CAAC;AAC5C;AAEM,SAAU,YAAY,CAAC,KAAA,GAAgB,OAAO,EAAA;IAClD,OAAOA,kBAAO,CAAC,YAAY,CAAC;AAC1B,QAAA,KAAK,EAAE,KAAK;AACZ,QAAA,MAAM,EAAEA,kBAAO,CAAC,MAAM,CAAC,OAAO,CAC5BA,kBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtCA,kBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAI;AAClD,YAAA,MAAM,WAAW,GAAG,CAAA,EAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA,EAAA,EAAK,OAAiB,EAAE;AACrE,YAAA,OAAO,KAAK,GAAG,CAAA,EAAG,WAAW,CAAA,EAAA,EAAK,KAAe,CAAA,CAAE,GAAG,WAAW;AACnE,QAAA,CAAC,CAAC,CACH;AACD,QAAA,UAAU,EAAE;AACV,YAAA,IAAIA,kBAAO,CAAC,UAAU,CAAC,OAAO,CAAC;gBAC7B,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;AAChD,gBAAA,gBAAgB,EAAE,IAAI;aACvB,CAAC;AACH,SAAA;AACF,KAAA,CAAC;AACJ;AAqBM,SAAU,QAAQ,CAAC,IAAY,EAAA;AACnC,IAAA,IAAI;QACF,MAAM,CAAC,GAAGC,aAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,CAAC,WAAW,EAAE;AAAE,YAAA,OAAO,KAAK;QACjC,IAAI,CAAC,CAAC,MAAM,EAAE;AAAE,YAAA,OAAO,MAAM;QAC7B,IAAI,CAAC,CAAC,cAAc,EAAE;AAAE,YAAA,OAAO,MAAM;AACrC,QAAA,OAAO,SAAS;IAClB;IAAE,OAAO,KAAc,EAAE;QACvB,MAAM,GAAG,GAAG,KAA8B;AAC1C,QAAA,IAAI,GAAG,CAAC,IAAI,IAAI,QAAQ;AAAE,YAAA,OAAO,QAAQ;AACzC,QAAA,IAAI,GAAG,CAAC,IAAI,IAAI,SAAS;AAAE,YAAA,OAAO,QAAQ;;AACrC,YAAA,MAAM,GAAG;IAChB;AACF;AAEM,SAAU,MAAM,CAAC,IAAY,EAAA;IACjC,MAAM,SAAS,GAAG,4EAA4E;IAC9F,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;AAC3C;;;;;;;"}
|
package/dist/compiler/util.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as winston from
|
|
1
|
+
import * as winston from "winston";
|
|
2
2
|
export declare function assertNever(x: never): never;
|
|
3
3
|
export declare function createLogger(level?: string): winston.Logger;
|
|
4
4
|
export declare function findNodeModules(): string;
|
|
5
|
-
export type PathType =
|
|
5
|
+
export type PathType = "absent" | "file" | "dir" | "link" | "unknown";
|
|
6
6
|
export declare function pathType(path: string): PathType;
|
|
7
7
|
export declare function isUUID(uuid: string): boolean;
|
|
8
8
|
//# sourceMappingURL=util.d.ts.map
|