@platforma-sdk/tengo-builder 4.1.12 → 4.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +2 -3
- package/dist/cli.cjs +1 -2
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -2
- package/dist/commands/build.cjs +1 -2
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.js +1 -2
- package/dist/commands/check.cjs +3 -3
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.js +3 -3
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +3 -3
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.js +3 -3
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +3 -3
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.js +3 -3
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/imports.cjs +1 -2
- package/dist/commands/imports.js +1 -2
- package/dist/commands/test.cjs +3 -3
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.js +3 -3
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +1 -2
- package/dist/compiler/artifactset.js +1 -2
- package/dist/compiler/compiler.cjs +1 -2
- package/dist/compiler/compiler.js +1 -2
- package/dist/compiler/compileroptions.cjs +2 -5
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.js +2 -5
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/imports.cjs +1 -2
- package/dist/compiler/imports.js +1 -2
- package/dist/compiler/main.cjs +3 -3
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.js +3 -3
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/pack_limits.cjs +4 -5
- package/dist/compiler/pack_limits.cjs.map +1 -1
- package/dist/compiler/pack_limits.js +4 -5
- package/dist/compiler/pack_limits.js.map +1 -1
- package/dist/compiler/package.cjs +1 -2
- package/dist/compiler/package.js +1 -2
- package/dist/compiler/source.cjs +1 -2
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.js +1 -2
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +1 -2
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.js +1 -2
- package/dist/compiler/util.cjs +1 -2
- package/dist/compiler/util.js +1 -2
- package/dist/index.js +1 -2
- package/dist/shared/basecmd.cjs +1 -2
- package/dist/shared/basecmd.js +1 -2
- package/dist/shared/dump.cjs +3 -3
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.js +3 -3
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +1 -2
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.js +1 -2
- package/package.json +11 -11
package/dist/compiler/package.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compiler/package.ts
|
|
2
2
|
function artifactKey(name) {
|
|
3
3
|
return `${name.type}||${name.pkg}||${name.id}`;
|
|
4
4
|
}
|
|
@@ -39,7 +39,6 @@ function parseArtefactNameAndVersion(nameAndVersion) {
|
|
|
39
39
|
function fullNameWithoutTypeToString(name) {
|
|
40
40
|
return `${name.pkg}:${name.id}:${name.version}`;
|
|
41
41
|
}
|
|
42
|
-
//#endregion
|
|
43
42
|
export { artifactKey, artifactNameToString, formatArtefactNameAndVersion, fullNameEquals, fullNameToString, fullNameWithoutTypeToString, parseArtefactNameAndVersion, typedArtifactNameToString, typedArtifactNamesEquals };
|
|
44
43
|
|
|
45
44
|
//# sourceMappingURL=package.js.map
|
package/dist/compiler/source.cjs
CHANGED
|
@@ -2,7 +2,7 @@ const require_package = require("./package.cjs");
|
|
|
2
2
|
const require_artifactset = require("./artifactset.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_crypto = require("node:crypto");
|
|
5
|
-
|
|
5
|
+
// src/compiler/source.ts
|
|
6
6
|
const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
|
|
7
7
|
const functionCallRE = (moduleName, fnName) => {
|
|
8
8
|
return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` + fnName + `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*)(?=[,)])`, "g");
|
|
@@ -289,7 +289,6 @@ function parseArtifactName(moduleName, aType, localPackageName) {
|
|
|
289
289
|
function getSha256(source) {
|
|
290
290
|
return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
|
|
291
291
|
}
|
|
292
|
-
//#endregion
|
|
293
292
|
exports.ArtifactSource = ArtifactSource;
|
|
294
293
|
exports.getSha256 = getSha256;
|
|
295
294
|
exports.newGetSoftwareInfoRE = newGetSoftwareInfoRE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.cjs","names":["createArtifactNameSet","fullNameToString"],"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 // `fnCall` captures from the function name through the first string\n // argument (including the closing quote and any trailing whitespace);\n // the closing-paren-or-comma check is a non-consuming lookahead, so\n // any extra args (`assets.importWasm(\"name\", { memoryLimit: ... })`)\n // survive the rewrite in `compiler.ts` — only the literal is\n // build-time material, anything past it is runtime config.\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\");\nconst newImportWasmRE = (moduleName: string) => functionCallRE(moduleName, \"importWasm\");\nconst newImportWasmDetector = (moduleName: string) => functionCallLikeRE(moduleName, \"importWasm\");\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 /** Set when the line is a module import, for every module: Platforma\n * artifacts, `plapi` and the Tengo standard library alike. */\n moduleImport?: ImportInfo;\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, moduleImport: iInfo };\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 [\"wasm\", newImportWasmRE(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 [\"wasm\", newImportWasmDetector(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, moduleImport: iInfo };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(\n importInstruction[0],\n ` := import(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n\n return {\n line: originalLine,\n context,\n artifacts: [artifact],\n option: undefined,\n moduleImport: iInfo,\n };\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 // fnCall ends right after the literal's closing quote + ws;\n // the trailing `)` or `,` is preserved from the original\n // line, so multi-arg calls (`fn(\"name\", opts)`) keep their\n // remaining args intact.\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\nexport interface 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"],"mappings":";;;;;AAeA,MAAM,cAAc;AAEpB,MAAM,kBAAkB,YAAoB,WAAmB;CAO7D,OAAO,IAAI,OACT,MAAM,WAAW,2BACf,SACA,qDACF,GACF;AACF;AAEA,MAAM,sBAAsB,YAAoB,WAAmB;CACjE,OAAO,IAAI,OAAO,MAAM,WAAW,iBAAiB,SAAS,YAAY,GAAG;AAC9E;AAEA,MAAa,sBAAsB,eACjC,eAAe,YAAY,eAAe;AAC5C,MAAa,wBAAwB,eACnC,eAAe,YAAY,iBAAiB;AAE9C,MAAM,uBAAuB,eAAuB,eAAe,YAAY,gBAAgB;AAC/F,MAAM,6BAA6B,eACjC,mBAAmB,YAAY,gBAAgB;AACjD,MAAM,uBAAuB,eAAuB,eAAe,YAAY,gBAAgB;AAC/F,MAAM,6BAA6B,eACjC,mBAAmB,YAAY,gBAAgB;AACjD,MAAM,oBAAoB,eAAuB,eAAe,YAAY,aAAa;AACzF,MAAM,0BAA0B,eAC9B,mBAAmB,YAAY,aAAa;AAC9C,MAAM,mBAAmB,eAAuB,eAAe,YAAY,YAAY;A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,MAAM,CAAC,GAAG,eAAe,QAAQ,eACpC,KAAK,MAAM,CAAC,cAAc,OAAO,YAAY;EAC3C,MAAM,QAAQ,GAAG,KAAK,SAAS;EAC/B,IAAI,CAAC,SAAS,CAAC,MAAM,QACnB;EAGF,MAAM,MACJ,cAAc,aAAa,4IAC7B;CACF;CAIJ,OAAO;EAAE,MAAM;EAAc;EAAS,WAAW,CAAC;EAAG,QAAQ,KAAA;CAAU;AACzE;AAOA,SAAS,YAAY,MAA0B;CAC7C,MAAM,QAAQ,aAAa,KAAK,IAAI;CAEpC,IAAI,CAAC,SAAS,CAAC,MAAM,QACnB,MAAM,MAAM,oCAAoC;CAGlD,MAAM,EAAE,YAAY,eAAe,MAAM;CACzC,IAAI,CAAC,cAAc,CAAC,YAClB,MAAM,MAAM,oCAAoC;CAGlD,OAAO;EACL,QAAQ;EACR,OAAO;CACT;AACF;AAEA,SAAS,kBACP,YACA,OACA,kBAC+B;CAC/B,MAAM,UAAU,aAAa,KAAK,UAAU;CAC5C,IAAI,CAAC,SACH;CAGF,IAAI,CAAC,QAAQ,QACX,MAAM,MACJ,8HACF;CAGF,MAAM,EAAE,SAAS,UAAU,QAAQ;CACnC,IAAI,CAAC,OACH,MAAM,MACJ,8HACF;CAGF,OAAO;EAAE,MAAM;EAAO,KAAK,WAAW;EAAkB,IAAI;CAAM;AACpE;AAEA,SAAgB,UAAU,QAAwB;CAChD,QAAA,GAAA,YAAA,WAAA,CAAkB,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK;AACzD"}
|
|
1
|
+
{"version":3,"file":"source.cjs","names":["readFileSync","createArtifactNameSet","fullNameToString","createHash"],"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 // `fnCall` captures from the function name through the first string\n // argument (including the closing quote and any trailing whitespace);\n // the closing-paren-or-comma check is a non-consuming lookahead, so\n // any extra args (`assets.importWasm(\"name\", { memoryLimit: ... })`)\n // survive the rewrite in `compiler.ts` — only the literal is\n // build-time material, anything past it is runtime config.\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\");\nconst newImportWasmRE = (moduleName: string) => functionCallRE(moduleName, \"importWasm\");\nconst newImportWasmDetector = (moduleName: string) => functionCallLikeRE(moduleName, \"importWasm\");\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 /** Set when the line is a module import, for every module: Platforma\n * artifacts, `plapi` and the Tengo standard library alike. */\n moduleImport?: ImportInfo;\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, moduleImport: iInfo };\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 [\"wasm\", newImportWasmRE(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 [\"wasm\", newImportWasmDetector(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, moduleImport: iInfo };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(\n importInstruction[0],\n ` := import(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n\n return {\n line: originalLine,\n context,\n artifacts: [artifact],\n option: undefined,\n moduleImport: iInfo,\n };\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 // fnCall ends right after the literal's closing quote + ws;\n // the trailing `)` or `,` is preserved from the original\n // line, so multi-arg calls (`fn(\"name\", opts)`) keep their\n // remaining args intact.\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\nexport interface 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"],"mappings":";;;;;AAeA,MAAM,cAAc;AAEpB,MAAM,kBAAkB,YAAoB,WAAmB;CAO7D,OAAO,IAAI,OACT,MAAM,WAAW,2BACf,SACA,qDACF,GACF;AACF;AAEA,MAAM,sBAAsB,YAAoB,WAAmB;CACjE,OAAO,IAAI,OAAO,MAAM,WAAW,iBAAiB,SAAS,YAAY,GAAG;AAC9E;AAEA,MAAa,sBAAsB,eACjC,eAAe,YAAY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AAI;CAAM;AACpE;AAEA,SAAgB,UAAU,QAAwB;CAChD,QAAA,GAAOC,YAAAA,WAAAA,CAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK;AACzD"}
|
package/dist/compiler/source.js
CHANGED
|
@@ -2,7 +2,7 @@ import { fullNameToString } from "./package.js";
|
|
|
2
2
|
import { createArtifactNameSet } from "./artifactset.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
|
-
|
|
5
|
+
// src/compiler/source.ts
|
|
6
6
|
const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
|
|
7
7
|
const functionCallRE = (moduleName, fnName) => {
|
|
8
8
|
return new RegExp(`\\b${moduleName}\\.(?<fnCall>(?<fnName>` + fnName + `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*)(?=[,)])`, "g");
|
|
@@ -289,7 +289,6 @@ function parseArtifactName(moduleName, aType, localPackageName) {
|
|
|
289
289
|
function getSha256(source) {
|
|
290
290
|
return createHash("sha256").update(source).digest("hex");
|
|
291
291
|
}
|
|
292
|
-
//#endregion
|
|
293
292
|
export { ArtifactSource, getSha256, newGetSoftwareInfoRE, newGetTemplateIdRE, parseSingleSourceLine, parseSourceFile };
|
|
294
293
|
|
|
295
294
|
//# sourceMappingURL=source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","names":[],"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 // `fnCall` captures from the function name through the first string\n // argument (including the closing quote and any trailing whitespace);\n // the closing-paren-or-comma check is a non-consuming lookahead, so\n // any extra args (`assets.importWasm(\"name\", { memoryLimit: ... })`)\n // survive the rewrite in `compiler.ts` — only the literal is\n // build-time material, anything past it is runtime config.\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\");\nconst newImportWasmRE = (moduleName: string) => functionCallRE(moduleName, \"importWasm\");\nconst newImportWasmDetector = (moduleName: string) => functionCallLikeRE(moduleName, \"importWasm\");\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 /** Set when the line is a module import, for every module: Platforma\n * artifacts, `plapi` and the Tengo standard library alike. */\n moduleImport?: ImportInfo;\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, moduleImport: iInfo };\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 [\"wasm\", newImportWasmRE(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 [\"wasm\", newImportWasmDetector(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, moduleImport: iInfo };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(\n importInstruction[0],\n ` := import(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n\n return {\n line: originalLine,\n context,\n artifacts: [artifact],\n option: undefined,\n moduleImport: iInfo,\n };\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 // fnCall ends right after the literal's closing quote + ws;\n // the trailing `)` or `,` is preserved from the original\n // line, so multi-arg calls (`fn(\"name\", opts)`) keep their\n // remaining args intact.\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\nexport interface 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"],"mappings":";;;;;AAeA,MAAM,cAAc;AAEpB,MAAM,kBAAkB,YAAoB,WAAmB;CAO7D,OAAO,IAAI,OACT,MAAM,WAAW,2BACf,SACA,qDACF,GACF;AACF;AAEA,MAAM,sBAAsB,YAAoB,WAAmB;CACjE,OAAO,IAAI,OAAO,MAAM,WAAW,iBAAiB,SAAS,YAAY,GAAG;AAC9E;AAEA,MAAa,sBAAsB,eACjC,eAAe,YAAY,eAAe;AAC5C,MAAa,wBAAwB,eACnC,eAAe,YAAY,iBAAiB;AAE9C,MAAM,uBAAuB,eAAuB,eAAe,YAAY,gBAAgB;AAC/F,MAAM,6BAA6B,eACjC,mBAAm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["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 // `fnCall` captures from the function name through the first string\n // argument (including the closing quote and any trailing whitespace);\n // the closing-paren-or-comma check is a non-consuming lookahead, so\n // any extra args (`assets.importWasm(\"name\", { memoryLimit: ... })`)\n // survive the rewrite in `compiler.ts` — only the literal is\n // build-time material, anything past it is runtime config.\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\");\nconst newImportWasmRE = (moduleName: string) => functionCallRE(moduleName, \"importWasm\");\nconst newImportWasmDetector = (moduleName: string) => functionCallLikeRE(moduleName, \"importWasm\");\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 /** Set when the line is a module import, for every module: Platforma\n * artifacts, `plapi` and the Tengo standard library alike. */\n moduleImport?: ImportInfo;\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, moduleImport: iInfo };\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 [\"wasm\", newImportWasmRE(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 [\"wasm\", newImportWasmDetector(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, moduleImport: iInfo };\n }\n\n if (globalizeImports) {\n originalLine = originalLine.replace(\n importInstruction[0],\n ` := import(\"${artifact.pkg}:${artifact.id}\")`,\n );\n }\n\n return {\n line: originalLine,\n context,\n artifacts: [artifact],\n option: undefined,\n moduleImport: iInfo,\n };\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 // fnCall ends right after the literal's closing quote + ws;\n // the trailing `)` or `,` is preserved from the original\n // line, so multi-arg calls (`fn(\"name\", opts)`) keep their\n // remaining args intact.\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\nexport interface 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"],"mappings":";;;;;AAeA,MAAM,cAAc;AAEpB,MAAM,kBAAkB,YAAoB,WAAmB;CAO7D,OAAO,IAAI,OACT,MAAM,WAAW,2BAC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,MAAM,EAAE,SAAS,UAAU,QAAQ;CACnC,IAAI,CAAC,OACH,MAAM,MACJ,8HACF;CAGF,OAAO;EAAE,MAAM;EAAO,KAAK,WAAW;EAAkB,IAAI;CAAM;AACpE;AAEA,SAAgB,UAAU,QAAwB;CAChD,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK;AACzD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_package = require("./package.cjs");
|
|
2
2
|
let _milaboratories_pl_model_backend = require("@milaboratories/pl-model-backend");
|
|
3
|
-
|
|
3
|
+
// src/compiler/template.ts
|
|
4
4
|
function newTemplateWithSource(compileMode, fullName, data, source) {
|
|
5
5
|
validateTemplateName(fullName, data);
|
|
6
6
|
return {
|
|
@@ -33,7 +33,6 @@ function validateTemplateName(fullName, data) {
|
|
|
33
33
|
const nameFromData = require_package.parseArtefactNameAndVersion(data.template);
|
|
34
34
|
if (nameFromData.pkg !== fullName.pkg || nameFromData.id !== fullName.id || nameFromData.version !== fullName.version) throw new Error(`Compiled template name don't match it's package and file names: ${require_package.fullNameWithoutTypeToString(nameFromData)} != ${require_package.fullNameWithoutTypeToString(fullName)}`);
|
|
35
35
|
}
|
|
36
|
-
//#endregion
|
|
37
36
|
exports.newTemplateFromContent = newTemplateFromContent;
|
|
38
37
|
exports.newTemplateWithSource = newTemplateWithSource;
|
|
39
38
|
exports.templateToSource = templateToSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.cjs","names":["parseArtefactNameAndVersion","fullNameWithoutTypeToString"],"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"],"mappings":";;;AAeA,SAAgB,sBACd,aACA,UACA,MACA,QACoB;CACpB,qBAAqB,UAAU,IAAI;CAEnC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAuBA,SAAgB,uBACd,aACA,UACA,SACU;CACV,MAAM,QAAA,
|
|
1
|
+
{"version":3,"file":"template.cjs","names":["parseTemplate","parseArtefactNameAndVersion","fullNameWithoutTypeToString"],"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"],"mappings":";;;AAeA,SAAgB,sBACd,aACA,UACA,MACA,QACoB;CACpB,qBAAqB,UAAU,IAAI;CAEnC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAuBA,SAAgB,uBACd,aACA,UACA,SACU;CACV,MAAM,QAAA,GAAOA,iCAAAA,cAAAA,CAAc,OAAO;CAClC,IAAI,KAAK,SAAS,wBAChB,MAAM,IAAI,MAAM,uBAAuB;CAGzC,qBAAqB,UAAU,IAAI;CACnC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAEA,SAAgB,iBAAiB,KAAmC;CAClE,OAAO;EACL,aAAa,IAAI;EACjB,UAAU,IAAI;EACd,MAAM,IAAI;EACV,QAAQ,IAAI,KAAK,aAAa,IAAI,KAAK,SAAS;CAClD;AACF;AACA,SAAS,qBAAqB,UAA4B,MAA0B;CAClF,MAAM,eAA4CC,gBAAAA,4BAA4B,KAAK,QAAQ;CAE3F,IACE,aAAa,QAAQ,SAAS,OAC9B,aAAa,OAAO,SAAS,MAC7B,aAAa,YAAY,SAAS,SAElC,MAAM,IAAI,MACR,mEACKC,gBAAAA,4BAA4B,YAAY,EAAE,MAAMA,gBAAAA,4BAA4B,QAAQ,GAC3F;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fullNameWithoutTypeToString, parseArtefactNameAndVersion } from "./package.js";
|
|
2
2
|
import { parseTemplate } from "@milaboratories/pl-model-backend";
|
|
3
|
-
|
|
3
|
+
// src/compiler/template.ts
|
|
4
4
|
function newTemplateWithSource(compileMode, fullName, data, source) {
|
|
5
5
|
validateTemplateName(fullName, data);
|
|
6
6
|
return {
|
|
@@ -33,7 +33,6 @@ function validateTemplateName(fullName, data) {
|
|
|
33
33
|
const nameFromData = parseArtefactNameAndVersion(data.template);
|
|
34
34
|
if (nameFromData.pkg !== fullName.pkg || nameFromData.id !== fullName.id || nameFromData.version !== fullName.version) throw new Error(`Compiled template name don't match it's package and file names: ${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`);
|
|
35
35
|
}
|
|
36
|
-
//#endregion
|
|
37
36
|
export { newTemplateFromContent, newTemplateWithSource, templateToSource };
|
|
38
37
|
|
|
39
38
|
//# sourceMappingURL=template.js.map
|
package/dist/compiler/util.cjs
CHANGED
|
@@ -5,7 +5,7 @@ let node_fs = require("node:fs");
|
|
|
5
5
|
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
6
6
|
let winston = require("winston");
|
|
7
7
|
winston = require_runtime.__toESM(winston, 1);
|
|
8
|
-
|
|
8
|
+
// src/compiler/util.ts
|
|
9
9
|
function assertNever(x) {
|
|
10
10
|
throw new Error("Unexpected object: " + x);
|
|
11
11
|
}
|
|
@@ -62,7 +62,6 @@ function getTengoFiles(dir, depth) {
|
|
|
62
62
|
});
|
|
63
63
|
return tengoFiles;
|
|
64
64
|
}
|
|
65
|
-
//#endregion
|
|
66
65
|
exports.assertNever = assertNever;
|
|
67
66
|
exports.createLogger = createLogger;
|
|
68
67
|
exports.getTengoFiles = getTengoFiles;
|
package/dist/compiler/util.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as winston from "winston";
|
|
4
|
-
|
|
4
|
+
// src/compiler/util.ts
|
|
5
5
|
function assertNever(x) {
|
|
6
6
|
throw new Error("Unexpected object: " + x);
|
|
7
7
|
}
|
|
@@ -58,7 +58,6 @@ function getTengoFiles(dir, depth) {
|
|
|
58
58
|
});
|
|
59
59
|
return tengoFiles;
|
|
60
60
|
}
|
|
61
|
-
//#endregion
|
|
62
61
|
export { assertNever, createLogger, getTengoFiles, isUUID, pathType };
|
|
63
62
|
|
|
64
63
|
//# sourceMappingURL=util.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { buildProgram, run };
|
|
1
|
+
export { buildProgram, run } from "./cli.js";
|
package/dist/shared/basecmd.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let commander = require("commander");
|
|
2
|
-
|
|
2
|
+
// src/shared/basecmd.ts
|
|
3
3
|
/** Add one or more groups of options to a command, preserving group order. */
|
|
4
4
|
function addOptions(cmd, ...optionGroups) {
|
|
5
5
|
for (const group of optionGroups) for (const opt of group) cmd.addOption(opt);
|
|
@@ -28,7 +28,6 @@ const ArtifactTypeOptions = () => [new commander.Option("-t, --type <type>", "ar
|
|
|
28
28
|
"asset",
|
|
29
29
|
"wasm"
|
|
30
30
|
]).default("all")];
|
|
31
|
-
//#endregion
|
|
32
31
|
exports.ArtifactTypeOptions = ArtifactTypeOptions;
|
|
33
32
|
exports.CtagsOptions = CtagsOptions;
|
|
34
33
|
exports.GlobalOptions = GlobalOptions;
|
package/dist/shared/basecmd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option } from "commander";
|
|
2
|
-
|
|
2
|
+
// src/shared/basecmd.ts
|
|
3
3
|
/** Add one or more groups of options to a command, preserving group order. */
|
|
4
4
|
function addOptions(cmd, ...optionGroups) {
|
|
5
5
|
for (const group of optionGroups) for (const opt of group) cmd.addOption(opt);
|
|
@@ -28,7 +28,6 @@ const ArtifactTypeOptions = () => [new Option("-t, --type <type>", "artifact typ
|
|
|
28
28
|
"asset",
|
|
29
29
|
"wasm"
|
|
30
30
|
]).default("all")];
|
|
31
|
-
//#endregion
|
|
32
31
|
export { ArtifactTypeOptions, CtagsOptions, GlobalOptions, addOptions };
|
|
33
32
|
|
|
34
33
|
//# sourceMappingURL=basecmd.js.map
|
package/dist/shared/dump.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_package = require("../compiler/package.cjs");
|
|
2
2
|
const require_main = require("../compiler/main.cjs");
|
|
3
|
-
|
|
3
|
+
// src/shared/dump.ts
|
|
4
4
|
function dumpArtifacts(logger, stream, aType) {
|
|
5
5
|
const packageInfo = require_main.getPackageInfo(process.cwd(), logger);
|
|
6
6
|
const sources = require_main.parseSources(logger, packageInfo, "dist", "src", "");
|
|
@@ -57,7 +57,8 @@ function dumpArtifacts(logger, stream, aType) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function dumpSoftware(logger, stream) {
|
|
60
|
-
const
|
|
60
|
+
const packageInfo = require_main.getPackageInfo(process.cwd(), logger);
|
|
61
|
+
const compiled = require_main.compile(logger, packageInfo, "dist");
|
|
61
62
|
const hashes = /* @__PURE__ */ new Set();
|
|
62
63
|
const sourceMap = /* @__PURE__ */ new Map();
|
|
63
64
|
for (const tpl of compiled.templates) {
|
|
@@ -79,7 +80,6 @@ function getTemplateSoftware(tpl) {
|
|
|
79
80
|
for (const subTpl of Object.values(tpl.templates)) getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));
|
|
80
81
|
return new Set(hashes);
|
|
81
82
|
}
|
|
82
|
-
//#endregion
|
|
83
83
|
exports.dumpArtifacts = dumpArtifacts;
|
|
84
84
|
exports.dumpSoftware = dumpSoftware;
|
|
85
85
|
|
package/dist/shared/dump.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dump.cjs","names":["getPackageInfo","parseSources","newCompiler","typedArtifactNameToString","compile"],"sources":["../../src/shared/dump.ts"],"sourcesContent":["import type winston from \"winston\";\nimport { getPackageInfo, newCompiler, compile, parseSources } from \"../compiler/main\";\nimport type { ArtifactType } from \"../compiler/package\";\nimport { typedArtifactNameToString } from \"../compiler/package\";\nimport type { TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\n\nexport function dumpArtifacts(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n aType?: ArtifactType,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n\n // group output by type:\n // - all libs\n // - all templates\n // - all software\n // - all assets\n // - all tests\n\n // Libs\n\n if (!aType || aType === \"library\") {\n for (const lib of compiler.allLibs()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(lib.fullName)}`);\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Templates\n\n if (!aType || aType === \"template\") {\n for (const tpl of compiler.allTemplates()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(tpl.fullName)}`);\n stream.write(JSON.stringify(tpl) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"template\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Software\n\n if (!aType || aType === \"software\") {\n for (const sw of compiler.allSoftware()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(sw.fullName)}`);\n stream.write(JSON.stringify(sw) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"software\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Assets\n\n if (!aType || aType === \"asset\") {\n for (const asset of compiler.allAssets()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(asset.fullName)}`);\n stream.write(JSON.stringify(asset) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"asset\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Wasm\n\n if (!aType || aType === \"wasm\") {\n for (const wasm of compiler.allWasm()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(wasm.fullName)}`);\n stream.write(JSON.stringify(wasm) + \"\\n\");\n }\n }\n\n // Tests\n\n if (!aType || aType === \"test\") {\n for (const src of sources) {\n if (src.fullName.type === \"test\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n}\n\nexport function dumpLibs(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n recursive: boolean,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n if (!recursive) {\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n\n return;\n }\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n compiler.addLib(src);\n }\n }\n\n for (const lib of compiler.allLibs()) {\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n}\n\nexport function dumpSoftware(logger: winston.Logger, stream: NodeJS.WritableStream): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiled = compile(logger, packageInfo, \"dist\");\n\n const hashes = new Set<string>();\n const sourceMap = new Map<string, string>();\n for (const tpl of compiled.templates) {\n Object.entries(tpl.data.hashToSource).forEach(([hash, src]) => sourceMap.set(hash, src));\n getTemplateSoftware(tpl.data.template).forEach((hash) => hashes.add(hash));\n }\n\n for (const hash of hashes) {\n const src = sourceMap.get(hash);\n if (src) {\n if (Object.hasOwn(JSON.parse(src) as object, \"asset\")) {\n // Skip assets. They are kept in templates software because of backward compatibility with backend.\n continue;\n }\n stream.write(src);\n if (!src.endsWith(\"\\n\")) {\n stream.write(\"\\n\");\n }\n } else {\n throw new Error(`Source not found for hash: ${hash}`);\n }\n }\n}\n\nfunction getTemplateSoftware(tpl: TemplateDataV3): Set<string> {\n const hashes = new Set<string>();\n for (const sw of Object.values(tpl.software)) {\n hashes.add(sw.sourceHash);\n }\n for (const subTpl of Object.values(tpl.templates)) {\n getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));\n }\n\n return new Set(hashes);\n}\n"],"mappings":";;;AAMA,SAAgB,cACd,QACA,QACA,OACM;CACN,MAAM,cAAcA,aAAAA,eAAe,QAAQ,IAAI,GAAG,MAAM;CAExD,MAAM,UAAUC,aAAAA,aAAa,QAAQ,aAAa,QAAQ,OAAO,EAAE;CAEnE,MAAM,WAAWC,aAAAA,YAAY,QAAQ,aAAa,MAAM;CAWxD,IAAI,CAAC,SAAS,UAAU,WAAW;EACjC,KAAK,MAAM,OAAO,SAAS,QAAQ,GAAG;GACpC,OAAO,MAAM,yBAAyBC,gBAAAA,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,WAAW;GACnC,OAAO,MAAM,yBAAyBA,gBAAAA,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,YAAY;EAClC,KAAK,MAAM,OAAO,SAAS,aAAa,GAAG;GACzC,OAAO,MAAM,yBAAyBA,gBAAAA,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,YAAY;GACpC,OAA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Content":["import type winston from \"winston\";\nimport { getPackageInfo, newCompiler, compile, parseSources } from \"../compiler/main\";\nimport type { ArtifactType } from \"../compiler/package\";\nimport { typedArtifactNameToString } from \"../compiler/package\";\nimport type { TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\n\nexport function dumpArtifacts(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n aType?: ArtifactType,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n\n // group output by type:\n // - all libs\n // - all templates\n // - all software\n // - all assets\n // - all tests\n\n // Libs\n\n if (!aType || aType === \"library\") {\n for (const lib of compiler.allLibs()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(lib.fullName)}`);\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Templates\n\n if (!aType || aType === \"template\") {\n for (const tpl of compiler.allTemplates()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(tpl.fullName)}`);\n stream.write(JSON.stringify(tpl) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"template\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Software\n\n if (!aType || aType === \"software\") {\n for (const sw of compiler.allSoftware()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(sw.fullName)}`);\n stream.write(JSON.stringify(sw) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"software\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Assets\n\n if (!aType || aType === \"asset\") {\n for (const asset of compiler.allAssets()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(asset.fullName)}`);\n stream.write(JSON.stringify(asset) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"asset\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Wasm\n\n if (!aType || aType === \"wasm\") {\n for (const wasm of compiler.allWasm()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(wasm.fullName)}`);\n stream.write(JSON.stringify(wasm) + \"\\n\");\n }\n }\n\n // Tests\n\n if (!aType || aType === \"test\") {\n for (const src of sources) {\n if (src.fullName.type === \"test\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n}\n\nexport function dumpLibs(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n recursive: boolean,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n if (!recursive) {\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n\n return;\n }\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n compiler.addLib(src);\n }\n }\n\n for (const lib of compiler.allLibs()) {\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n}\n\nexport function dumpSoftware(logger: winston.Logger, stream: NodeJS.WritableStream): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiled = compile(logger, packageInfo, \"dist\");\n\n const hashes = new Set<string>();\n const sourceMap = new Map<string, string>();\n for (const tpl of compiled.templates) {\n Object.entries(tpl.data.hashToSource).forEach(([hash, src]) => sourceMap.set(hash, src));\n getTemplateSoftware(tpl.data.template).forEach((hash) => hashes.add(hash));\n }\n\n for (const hash of hashes) {\n const src = sourceMap.get(hash);\n if (src) {\n if (Object.hasOwn(JSON.parse(src) as object, \"asset\")) {\n // Skip assets. They are kept in templates software because of backward compatibility with backend.\n continue;\n }\n stream.write(src);\n if (!src.endsWith(\"\\n\")) {\n stream.write(\"\\n\");\n }\n } else {\n throw new Error(`Source not found for hash: ${hash}`);\n }\n }\n}\n\nfunction getTemplateSoftware(tpl: TemplateDataV3): Set<string> {\n const hashes = new Set<string>();\n for (const sw of Object.values(tpl.software)) {\n hashes.add(sw.sourceHash);\n }\n for (const subTpl of Object.values(tpl.templates)) {\n getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));\n }\n\n return new Set(hashes);\n}\n"],"mappings":";;;AAMA,SAAgB,cACd,QACA,QACA,OACM;CACN,MAAM,cAAcA,aAAAA,eAAe,QAAQ,IAAI,GAAG,MAAM;CAExD,MAAM,UAAUC,aAAAA,aAAa,QAAQ,aAAa,QAAQ,OAAO,EAAE;CAEnE,MAAM,WAAWC,aAAAA,YAAY,QAAQ,aAAa,MAAM;CAWxD,IAAI,CAAC,SAAS,UAAU,WAAW;EACjC,KAAK,MAAM,OAAO,SAAS,QAAQ,GAAG;GACpC,OAAO,MAAM,yBAAyBC,gBAAAA,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,WAAW;GACnC,OAAO,MAAM,yBAAyBA,gBAAAA,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,YAAY;EAClC,KAAK,MAAM,OAAO,SAAS,aAAa,GAAG;GACzC,OAAO,MAAM,yBAAyBA,gBAAAA,0BAA0B,IAAI,QA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IAAI,IAAI,MAAM;AACvB"}
|
package/dist/shared/dump.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { typedArtifactNameToString } from "../compiler/package.js";
|
|
2
2
|
import { compile, getPackageInfo, newCompiler, parseSources } from "../compiler/main.js";
|
|
3
|
-
|
|
3
|
+
// src/shared/dump.ts
|
|
4
4
|
function dumpArtifacts(logger, stream, aType) {
|
|
5
5
|
const packageInfo = getPackageInfo(process.cwd(), logger);
|
|
6
6
|
const sources = parseSources(logger, packageInfo, "dist", "src", "");
|
|
@@ -57,7 +57,8 @@ function dumpArtifacts(logger, stream, aType) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function dumpSoftware(logger, stream) {
|
|
60
|
-
const
|
|
60
|
+
const packageInfo = getPackageInfo(process.cwd(), logger);
|
|
61
|
+
const compiled = compile(logger, packageInfo, "dist");
|
|
61
62
|
const hashes = /* @__PURE__ */ new Set();
|
|
62
63
|
const sourceMap = /* @__PURE__ */ new Map();
|
|
63
64
|
for (const tpl of compiled.templates) {
|
|
@@ -79,7 +80,6 @@ function getTemplateSoftware(tpl) {
|
|
|
79
80
|
for (const subTpl of Object.values(tpl.templates)) getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));
|
|
80
81
|
return new Set(hashes);
|
|
81
82
|
}
|
|
82
|
-
//#endregion
|
|
83
83
|
export { dumpArtifacts, dumpSoftware };
|
|
84
84
|
|
|
85
85
|
//# sourceMappingURL=dump.js.map
|
package/dist/shared/dump.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dump.js","names":[],"sources":["../../src/shared/dump.ts"],"sourcesContent":["import type winston from \"winston\";\nimport { getPackageInfo, newCompiler, compile, parseSources } from \"../compiler/main\";\nimport type { ArtifactType } from \"../compiler/package\";\nimport { typedArtifactNameToString } from \"../compiler/package\";\nimport type { TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\n\nexport function dumpArtifacts(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n aType?: ArtifactType,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n\n // group output by type:\n // - all libs\n // - all templates\n // - all software\n // - all assets\n // - all tests\n\n // Libs\n\n if (!aType || aType === \"library\") {\n for (const lib of compiler.allLibs()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(lib.fullName)}`);\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Templates\n\n if (!aType || aType === \"template\") {\n for (const tpl of compiler.allTemplates()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(tpl.fullName)}`);\n stream.write(JSON.stringify(tpl) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"template\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Software\n\n if (!aType || aType === \"software\") {\n for (const sw of compiler.allSoftware()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(sw.fullName)}`);\n stream.write(JSON.stringify(sw) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"software\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Assets\n\n if (!aType || aType === \"asset\") {\n for (const asset of compiler.allAssets()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(asset.fullName)}`);\n stream.write(JSON.stringify(asset) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"asset\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Wasm\n\n if (!aType || aType === \"wasm\") {\n for (const wasm of compiler.allWasm()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(wasm.fullName)}`);\n stream.write(JSON.stringify(wasm) + \"\\n\");\n }\n }\n\n // Tests\n\n if (!aType || aType === \"test\") {\n for (const src of sources) {\n if (src.fullName.type === \"test\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n}\n\nexport function dumpLibs(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n recursive: boolean,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n if (!recursive) {\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n\n return;\n }\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n compiler.addLib(src);\n }\n }\n\n for (const lib of compiler.allLibs()) {\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n}\n\nexport function dumpSoftware(logger: winston.Logger, stream: NodeJS.WritableStream): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiled = compile(logger, packageInfo, \"dist\");\n\n const hashes = new Set<string>();\n const sourceMap = new Map<string, string>();\n for (const tpl of compiled.templates) {\n Object.entries(tpl.data.hashToSource).forEach(([hash, src]) => sourceMap.set(hash, src));\n getTemplateSoftware(tpl.data.template).forEach((hash) => hashes.add(hash));\n }\n\n for (const hash of hashes) {\n const src = sourceMap.get(hash);\n if (src) {\n if (Object.hasOwn(JSON.parse(src) as object, \"asset\")) {\n // Skip assets. They are kept in templates software because of backward compatibility with backend.\n continue;\n }\n stream.write(src);\n if (!src.endsWith(\"\\n\")) {\n stream.write(\"\\n\");\n }\n } else {\n throw new Error(`Source not found for hash: ${hash}`);\n }\n }\n}\n\nfunction getTemplateSoftware(tpl: TemplateDataV3): Set<string> {\n const hashes = new Set<string>();\n for (const sw of Object.values(tpl.software)) {\n hashes.add(sw.sourceHash);\n }\n for (const subTpl of Object.values(tpl.templates)) {\n getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));\n }\n\n return new Set(hashes);\n}\n"],"mappings":";;;AAMA,SAAgB,cACd,QACA,QACA,OACM;CACN,MAAM,cAAc,eAAe,QAAQ,IAAI,GAAG,MAAM;CAExD,MAAM,UAAU,aAAa,QAAQ,aAAa,QAAQ,OAAO,EAAE;CAEnE,MAAM,WAAW,YAAY,QAAQ,aAAa,MAAM;CAWxD,IAAI,CAAC,SAAS,UAAU,WAAW;EACjC,KAAK,MAAM,OAAO,SAAS,QAAQ,GAAG;GACpC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,WAAW;GACnC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,YAAY;EAClC,KAAK,MAAM,OAAO,SAAS,aAAa,GAAG;GACzC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,YAAY;GACpC,OAAO,MACL,yBAAyB,0BAA0B,IAAI,QAAQ,EAAE,GAAG,IAAI,SAC1E;GACA,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,YAAY;EAClC,KAAK,MAAM,MAAM,SAAS,YAAY,GAAG;GACvC,OAAO,MAAM,yBAAyB,0BAA0B,GAAG,QAAQ,GAAG;GAC9E,OAAO,MAAM,KAAK,UAAU,EAAE,IAAI,IAAI;EACxC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,YAAY;GACpC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,SAAS;EAC/B,KAAK,MAAM,SAAS,SAAS,UAAU,GAAG;GACxC,OAAO,MAAM,yBAAyB,0BAA0B,MAAM,QAAQ,GAAG;GACjF,OAAO,MAAM,KAAK,UAAU,KAAK,IAAI,IAAI;EAC3C;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,SAAS;GACjC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,QACtB,KAAK,MAAM,QAAQ,SAAS,QAAQ,GAAG;EACrC,OAAO,MAAM,yBAAyB,0BAA0B,KAAK,QAAQ,GAAG;EAChF,OAAO,MAAM,KAAK,UAAU,IAAI,IAAI,IAAI;CAC1C;CAKF,IAAI,CAAC,SAAS,UAAU;
|
|
1
|
+
{"version":3,"file":"dump.js","names":[],"sources":["../../src/shared/dump.ts"],"sourcesContent":["import type winston from \"winston\";\nimport { getPackageInfo, newCompiler, compile, parseSources } from \"../compiler/main\";\nimport type { ArtifactType } from \"../compiler/package\";\nimport { typedArtifactNameToString } from \"../compiler/package\";\nimport type { TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\n\nexport function dumpArtifacts(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n aType?: ArtifactType,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n\n // group output by type:\n // - all libs\n // - all templates\n // - all software\n // - all assets\n // - all tests\n\n // Libs\n\n if (!aType || aType === \"library\") {\n for (const lib of compiler.allLibs()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(lib.fullName)}`);\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Templates\n\n if (!aType || aType === \"template\") {\n for (const tpl of compiler.allTemplates()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(tpl.fullName)}`);\n stream.write(JSON.stringify(tpl) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"template\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Software\n\n if (!aType || aType === \"software\") {\n for (const sw of compiler.allSoftware()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(sw.fullName)}`);\n stream.write(JSON.stringify(sw) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"software\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Assets\n\n if (!aType || aType === \"asset\") {\n for (const asset of compiler.allAssets()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(asset.fullName)}`);\n stream.write(JSON.stringify(asset) + \"\\n\");\n }\n\n for (const src of sources) {\n if (src.fullName.type === \"asset\") {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)}`);\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n\n // Wasm\n\n if (!aType || aType === \"wasm\") {\n for (const wasm of compiler.allWasm()) {\n logger.debug(`Dumping to pl-tester: ${typedArtifactNameToString(wasm.fullName)}`);\n stream.write(JSON.stringify(wasm) + \"\\n\");\n }\n }\n\n // Tests\n\n if (!aType || aType === \"test\") {\n for (const src of sources) {\n if (src.fullName.type === \"test\") {\n logger.debug(\n `Dumping to pl-tester: ${typedArtifactNameToString(src.fullName)} ${src.srcName}`,\n );\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n }\n}\n\nexport function dumpLibs(\n logger: winston.Logger,\n stream: NodeJS.WritableStream,\n recursive: boolean,\n): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n\n const sources = parseSources(logger, packageInfo, \"dist\", \"src\", \"\");\n\n if (!recursive) {\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n stream.write(JSON.stringify(src) + \"\\n\");\n }\n }\n\n return;\n }\n\n const compiler = newCompiler(logger, packageInfo, \"dist\");\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n compiler.addLib(src);\n }\n }\n\n for (const lib of compiler.allLibs()) {\n stream.write(JSON.stringify(lib) + \"\\n\");\n }\n}\n\nexport function dumpSoftware(logger: winston.Logger, stream: NodeJS.WritableStream): void {\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiled = compile(logger, packageInfo, \"dist\");\n\n const hashes = new Set<string>();\n const sourceMap = new Map<string, string>();\n for (const tpl of compiled.templates) {\n Object.entries(tpl.data.hashToSource).forEach(([hash, src]) => sourceMap.set(hash, src));\n getTemplateSoftware(tpl.data.template).forEach((hash) => hashes.add(hash));\n }\n\n for (const hash of hashes) {\n const src = sourceMap.get(hash);\n if (src) {\n if (Object.hasOwn(JSON.parse(src) as object, \"asset\")) {\n // Skip assets. They are kept in templates software because of backward compatibility with backend.\n continue;\n }\n stream.write(src);\n if (!src.endsWith(\"\\n\")) {\n stream.write(\"\\n\");\n }\n } else {\n throw new Error(`Source not found for hash: ${hash}`);\n }\n }\n}\n\nfunction getTemplateSoftware(tpl: TemplateDataV3): Set<string> {\n const hashes = new Set<string>();\n for (const sw of Object.values(tpl.software)) {\n hashes.add(sw.sourceHash);\n }\n for (const subTpl of Object.values(tpl.templates)) {\n getTemplateSoftware(subTpl).forEach((hash) => hashes.add(hash));\n }\n\n return new Set(hashes);\n}\n"],"mappings":";;;AAMA,SAAgB,cACd,QACA,QACA,OACM;CACN,MAAM,cAAc,eAAe,QAAQ,IAAI,GAAG,MAAM;CAExD,MAAM,UAAU,aAAa,QAAQ,aAAa,QAAQ,OAAO,EAAE;CAEnE,MAAM,WAAW,YAAY,QAAQ,aAAa,MAAM;CAWxD,IAAI,CAAC,SAAS,UAAU,WAAW;EACjC,KAAK,MAAM,OAAO,SAAS,QAAQ,GAAG;GACpC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,WAAW;GACnC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAAC,SAAS,UAAU,YAAY;EAClC,KAAK,MAAM,OAAO,SAAS,aAAa,GAAG;GACzC,OAAO,MAAM,yBAAyB,0BAA0B,IAAI,QAAQ,GAAG;GAC/E,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;EAEA,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,SAAS,YAAY;GACpC,OAAO,MACL,yBAAyB,0BAA0B,IAAI,QAAQ,EAAE,GAAG,IAAI,SAC1E;GACA,OAAO,MAAM,KAAK,UAAU,GAAG,IAAI,IAAI;EACzC;CAEJ;CAIA,IAAI,CAA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QAAQ,aAAa,MAAM;CAEpD,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,4BAAY,IAAI,IAAoB;CAC1C,KAAK,MAAM,OAAO,SAAS,WAAW;EACpC,OAAO,QAAQ,IAAI,KAAK,YAAY,CAAC,CAAC,SAAS,CAAC,MAAM,SAAS,UAAU,IAAI,MAAM,GAAG,CAAC;EACvF,oBAAoB,IAAI,KAAK,QAAQ,CAAC,CAAC,SAAS,SAAS,OAAO,IAAI,IAAI,CAAC;CAC3E;CAEA,KAAK,MAAM,QAAQ,QAAQ;EACzB,MAAM,MAAM,UAAU,IAAI,IAAI;EAC9B,IAAI,KAAK;GACP,IAAI,OAAO,OAAO,KAAK,MAAM,GAAG,GAAa,OAAO,GAElD;GAEF,OAAO,MAAM,GAAG;GAChB,IAAI,CAAC,IAAI,SAAS,IAAI,GACpB,OAAO,MAAM,IAAI;EAErB,OACE,MAAM,IAAI,MAAM,8BAA8B,MAAM;CAExD;AACF;AAEA,SAAS,oBAAoB,KAAkC;CAC7D,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,MAAM,OAAO,OAAO,IAAI,QAAQ,GACzC,OAAO,IAAI,GAAG,UAAU;CAE1B,KAAK,MAAM,UAAU,OAAO,OAAO,IAAI,SAAS,GAC9C,oBAAoB,MAAM,CAAC,CAAC,SAAS,SAAS,OAAO,IAAI,IAAI,CAAC;CAGhE,OAAO,IAAI,IAAI,MAAM;AACvB"}
|
package/dist/shared/proc.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let node_child_process = require("node:child_process");
|
|
2
|
-
|
|
2
|
+
// src/shared/proc.ts
|
|
3
3
|
function spawnEmbed(cmd, ...args) {
|
|
4
4
|
const p = (0, node_child_process.spawn)(cmd, args, { stdio: [
|
|
5
5
|
"pipe",
|
|
@@ -21,7 +21,6 @@ function waitFor(p) {
|
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
//#endregion
|
|
25
24
|
exports.spawnEmbed = spawnEmbed;
|
|
26
25
|
exports.waitFor = waitFor;
|
|
27
26
|
|