@platforma-sdk/tengo-builder 2.5.6 → 2.5.7
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 +7 -13
- package/dist/commands/build.cjs +5 -6
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +5 -5
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +1 -2
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +6 -7
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +2 -2
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +1 -2
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +5 -6
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +3 -3
- package/dist/commands/dump/artifacts.d.ts.map +1 -0
- package/dist/commands/dump/artifacts.js +1 -2
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +5 -6
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +2 -2
- package/dist/commands/dump/software.d.ts.map +1 -0
- package/dist/commands/dump/software.js +1 -2
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +6 -7
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +1 -2
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +3 -4
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.js +1 -2
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +6 -7
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.js +1 -2
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +2 -3
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.js +1 -2
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +7 -8
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.js +1 -2
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +1 -2
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.js +1 -1
- package/dist/compiler/source.cjs +4 -5
- 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 +3 -4
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.js +2 -3
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/util.cjs +2 -3
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.js +1 -2
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +7 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +2 -3
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.js +1 -2
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +3 -4
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.js +1 -2
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +2 -3
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.js +1 -2
- package/dist/shared/proc.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertNever } from "./util.js";
|
|
2
2
|
import { artifactKey } from "./package.js";
|
|
3
|
-
|
|
4
3
|
//#region src/compiler/artifactset.ts
|
|
5
4
|
var ArtifactMap = class {
|
|
6
5
|
map = /* @__PURE__ */ new Map();
|
|
@@ -59,7 +58,7 @@ var ArtifactStore = class {
|
|
|
59
58
|
this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
|
|
63
61
|
//#endregion
|
|
64
62
|
export { ArtifactStore, createArtifactNameSet };
|
|
63
|
+
|
|
65
64
|
//# sourceMappingURL=artifactset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifactset.js","names":[],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"artifactset.js","names":[],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":";;;AAIA,IAAa,cAAb,MAA4B;CAC1B,sBAAuB,IAAI,KAAgB;CAE3C,YAAY,eAA+D;AAA9C,OAAA,gBAAA;;CAE7B,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAM,YAAY,KAAK,cAAc,IAAI,CAAC;EAChD,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI;AAC7B,MAAI,OAAO,CAAC,QAAS,QAAO;AAC5B,OAAK,IAAI,IAAI,KAAK,IAAI;AACtB,SAAO;;CAGT,IAAI,MAAwC;AAC1C,SAAO,KAAK,IAAI,IAAI,YAAY,KAAK,CAAC;;CAGxC,IAAI,QAAa;EACf,MAAM,MAAW,EAAE;AACnB,OAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,IAAI,CAAC;AACxC,SAAO;;CAGT,QAAQ,UAAsD;AAC5D,OAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,EAAE,CAAC,CAAC;;;AAI/D,SAAgB,wBAAwD;AACtE,QAAO,IAAI,aAAgC,QAAQ,IAAI;;;;;;AAOzD,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;AAExD,OAAK,OAAO,IAAI,YAAe,cAAc;;CAG/C,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;AACrE,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK,QAAQ;GAEpC,QACE,aAAY,KAAK;;;CAIvB,IAAI,MAAmB,MAAwC;AAC7D,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK;GAE5B,QACE,aAAY,KAAK;;;CAIvB,MAAM,MAAwB;EAC5B,MAAM,MAAW,EAAE;AACnB,OAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,IAAI,CAAC;AAC1C,SAAO;;CAGT,QAAQ,MAAmB,UAAsD;AAC/E,OAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
const require_util = require(
|
|
2
|
-
const require_package = require(
|
|
3
|
-
const require_template = require(
|
|
4
|
-
const require_artifactset = require(
|
|
5
|
-
const require_compileroptions = require(
|
|
6
|
-
|
|
1
|
+
const require_util = require("./util.cjs");
|
|
2
|
+
const require_package = require("./package.cjs");
|
|
3
|
+
const require_template = require("./template.cjs");
|
|
4
|
+
const require_artifactset = require("./artifactset.cjs");
|
|
5
|
+
const require_compileroptions = require("./compileroptions.cjs");
|
|
7
6
|
//#region src/compiler/compiler.ts
|
|
8
7
|
var TengoTemplateCompiler = class {
|
|
9
8
|
libs = new require_artifactset.ArtifactStore((src) => src.fullName);
|
|
@@ -238,7 +237,7 @@ var TengoTemplateCompiler = class {
|
|
|
238
237
|
return result;
|
|
239
238
|
}
|
|
240
239
|
};
|
|
241
|
-
|
|
242
240
|
//#endregion
|
|
243
241
|
exports.TengoTemplateCompiler = TengoTemplateCompiler;
|
|
242
|
+
|
|
244
243
|
//# sourceMappingURL=compiler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.cjs","names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","typedArtifactNamesEquals","typedArtifactNameToString","fullNameEquals","fullNameToString","newTemplateWithSource"],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case \"library\": {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage =\n `library import recursion detected: ` +\n `${trace.slice(recursionStart).join(\" -> \")} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [\n ...trace,\n artifactNameToString(dep),\n ]);\n\n break;\n }\n case \"software\": {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case \"asset\": {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") throw new Error(\"unexpected source type\");\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: \"pl.tengo-template.v3\",\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"library\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === \"test\")\n throw new Error(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"software\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"asset\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== \"template\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case \"template\":\n return this.getTemplate(name);\n case \"library\":\n return this.getLib(name);\n case \"software\":\n return this.getSoftware(name);\n case \"asset\":\n return this.getAsset(name);\n case \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\n (dep) =>\n !this.getArtefact(dep) &&\n // allow self reference for templates\n !(src.fullName.type === \"template\" && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case \"library\":\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case \"software\":\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case \"asset\":\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"mappings":";;;;;;;AAyBA,IAAa,wBAAb,MAAmC;CACjC,AAAiB,OAAO,IAAIA,mCAA+B,QAAQ,IAAI,SAAS;CAChF,AAAiB,WAAW,IAAIA,mCAA+B,QAAQ,IAAI,SAAS;CACpF,AAAiB,SAAS,IAAIA,mCAA+B,QAAQ,IAAI,SAAS;CAClF,AAAiB,YAAY,IAAIA,mCAAmC,QAAQ,IAAI,SAAS;CAEzF,YAAY,AAAiB,aAA0B;EAA1B;;;CAG7B,AAAQ,qCACN,UACA,MACA,MACA,OACA;AACA,OAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,IAAI;IAEnC,MAAM,iBAAiB,MAAM,QAAQC,qCAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAMA,qCAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,GAAGC,6CAA6B,IAAI,SAAS;KAC7C,YAAY,IAAI;KACjB;AAED,wDAA4B,IAAI,iBAAiB,OAAO;AACxD,SAAK,SAAS,KAAKD,qCAAqB,IAAI,IAAI;AAChD,SAAK,aAAa,OAA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","formatArtefactNameAndVersion","typedArtifactNamesEquals","typedArtifactNameToString","fullNameEquals","fullNameToString","newTemplateWithSource"],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case \"library\": {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage =\n `library import recursion detected: ` +\n `${trace.slice(recursionStart).join(\" -> \")} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [\n ...trace,\n artifactNameToString(dep),\n ]);\n\n break;\n }\n case \"software\": {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case \"asset\": {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") throw new Error(\"unexpected source type\");\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: \"pl.tengo-template.v3\",\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"library\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === \"test\")\n throw new Error(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"software\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"asset\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== \"template\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case \"template\":\n return this.getTemplate(name);\n case \"library\":\n return this.getLib(name);\n case \"software\":\n return this.getSoftware(name);\n case \"asset\":\n return this.getAsset(name);\n case \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\n (dep) =>\n !this.getArtefact(dep) &&\n // allow self reference for templates\n !(src.fullName.type === \"template\" && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case \"library\":\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case \"software\":\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case \"asset\":\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,wBAAb,MAAmC;CACjC,OAAwB,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CAChF,WAA4B,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CACpF,SAA0B,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CAClF,YAA6B,IAAIA,oBAAAA,eAAmC,QAAQ,IAAI,SAAS;CAEzF,YAAY,aAA2C;AAA1B,OAAA,cAAA;;;CAG7B,qCACE,UACA,MACA,MACA,OACA;AACA,OAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,IAAI;IAEnC,MAAM,iBAAiB,MAAM,QAAQC,gBAAAA,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAMA,gBAAAA,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;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MAAM,MAAM;OACZ,IAAI,eAAe,+BAA+BD,gBAAAA,iBAAiB,IAAI,SAAS,CAAC;AACjF,uBAAgB,OAAO,IAAI,QAAQ;AAEnC,mBAAY,KAAK;QAAE;QAAK,KAAK,MAAM,aAAa;QAAE,CAAC;;AAErD;KACF,KAAK,OAEH;KACF,QACE,cAAA,YAAY,IAAI,SAAS,KAAK;;;AAMpC,OAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;AAEnB,SAAK,MAAM,KAAK,YACd,iBAAgB,KAAK,EAAE,IAAI;AAE7B,UAAM,IAAI,MAAM,aAAa;;AAG/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
|
|
@@ -3,7 +3,6 @@ import { artifactNameToString, formatArtefactNameAndVersion, fullNameEquals, ful
|
|
|
3
3
|
import { newTemplateWithSource } from "./template.js";
|
|
4
4
|
import { ArtifactStore } from "./artifactset.js";
|
|
5
5
|
import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from "./compileroptions.js";
|
|
6
|
-
|
|
7
6
|
//#region src/compiler/compiler.ts
|
|
8
7
|
var TengoTemplateCompiler = class {
|
|
9
8
|
libs = new ArtifactStore((src) => src.fullName);
|
|
@@ -238,7 +237,7 @@ var TengoTemplateCompiler = class {
|
|
|
238
237
|
return result;
|
|
239
238
|
}
|
|
240
239
|
};
|
|
241
|
-
|
|
242
240
|
//#endregion
|
|
243
241
|
export { TengoTemplateCompiler };
|
|
242
|
+
|
|
244
243
|
//# sourceMappingURL=compiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","names":[],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case \"library\": {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage =\n `library import recursion detected: ` +\n `${trace.slice(recursionStart).join(\" -> \")} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [\n ...trace,\n artifactNameToString(dep),\n ]);\n\n break;\n }\n case \"software\": {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case \"asset\": {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") throw new Error(\"unexpected source type\");\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: \"pl.tengo-template.v3\",\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"library\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === \"test\")\n throw new Error(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"software\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"asset\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== \"template\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case \"template\":\n return this.getTemplate(name);\n case \"library\":\n return this.getLib(name);\n case \"software\":\n return this.getSoftware(name);\n case \"asset\":\n return this.getAsset(name);\n case \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\n (dep) =>\n !this.getArtefact(dep) &&\n // allow self reference for templates\n !(src.fullName.type === \"template\" && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case \"library\":\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case \"software\":\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case \"asset\":\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"mappings":";;;;;;;AAyBA,IAAa,wBAAb,MAAmC;CACjC,AAAiB,OAAO,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,AAAiB,WAAW,IAAI,eAA+B,QAAQ,IAAI,SAAS;CACpF,AAAiB,SAAS,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAClF,AAAiB,YAAY,IAAI,eAAmC,QAAQ,IAAI,SAAS;CAEzF,YAAY,AAAiB,aAA0B;EAA1B;;;CAG7B,AAAQ,qCACN,UACA,MACA,MACA,OACA;AACA,OAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,IAAI;IAEnC,MAAM,iBAAiB,MAAM,QAAQ,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAM,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,GAAG,6BAA6B,IAAI,SAAS;KAC7C,YAAY,IAAI;KACjB;AAED,gCAA4B,IAAI,iBAAiB,OAAO;AACxD,SAAK,SAAS,KAAK,qBAAqB,IAAI,IAAI;AAChD,SAAK,aAAa,OAAO,cAAc,IAAI;AAG3C,SAAK,qCAAqC,UAAU,MAAM,IAAI,cAAc,CAC1E,GAAG,OACH,qBAAqB,IAAI,CAC1B,CAAC;AAEF;;GAEF,KAAK,YAAY;IACf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,iBAAgB,OAAO,0BAA0B,IAAI,CAAC;AAExD,iBAAY,KAAK;MAAE;MAAK,KAAK,IAAI,MAAM,aAAa;MAAE,CAAC;AAEvD;;AAIF,YAAQ,IAAI,SAAS,MAArB;KACE,KAAK;AAEH,WAAK,OAAO,IAAI;AAChB,aAAO,KAAK,KAAK,IAAI;AACrB;KACF,KAAK;AAEH,WAAK,YAAY,IAAI;AACrB,aAAO,SAAS,KAAK,IAAI;AACzB;KACF,KAAK;AAEH,WAAK,SAAS,IAAI;AAClB,aAAO,OAAO,KAAK,IAAI;AACvB;KACF,KAAK;AAEH,UAAI;OACF,MAAM,MAAM,KAAK,sBAAsB,IAAI;OAC3C,MAAM,aAAa,sBAAsB,IAAI,aAAa,IAAI,UAAU,KAAK,IAAI,IAAI;AACrF,YAAK,YAAY,WAAW;AAC5B,cAAO,UAAU,KAAK,WAAW;eAC1B,OAAgB;OACvB,MAAM,MAAM;OACZ,IAAI,eAAe,+BAA+B,iBAAiB,IAAI,SAAS,CAAC;AACjF,uBAAgB,OAAO,IAAI,QAAQ;AAEnC,mBAAY,KAAK;QAAE;QAAK,KAAK,MAAM,aAAa;QAAE,CAAC;;AAErD;KACF,KAAK,OAEH;KACF,QACE,aAAY,IAAI,SAAS,KAAK;;;AAMpC,OAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;AAEnB,SAAK,MAAM,KAAK,YACd,iBAAgB,KAAK,EAAE,IAAI;AAE7B,UAAM,IAAI,MAAM,aAAa;;AAG/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
|
|
1
|
+
{"version":3,"file":"compiler.js","names":[],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type { CompiledTemplateV3 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case \"library\": {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage =\n `library import recursion detected: ` +\n `${trace.slice(recursionStart).join(\" -> \")} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [\n ...trace,\n artifactNameToString(dep),\n ]);\n\n break;\n }\n case \"software\": {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case \"asset\": {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") throw new Error(\"unexpected source type\");\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: \"pl.tengo-template.v3\",\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"library\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === \"test\")\n throw new Error(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"software\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"asset\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== \"template\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case \"template\":\n return this.getTemplate(name);\n case \"library\":\n return this.getLib(name);\n case \"software\":\n return this.getSoftware(name);\n case \"asset\":\n return this.getAsset(name);\n case \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\n (dep) =>\n !this.getArtefact(dep) &&\n // allow self reference for templates\n !(src.fullName.type === \"template\" && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case \"library\":\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case \"software\":\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case \"asset\":\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,wBAAb,MAAmC;CACjC,OAAwB,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,WAA4B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CACpF,SAA0B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAClF,YAA6B,IAAI,eAAmC,QAAQ,IAAI,SAAS;CAEzF,YAAY,aAA2C;AAA1B,OAAA,cAAA;;;CAG7B,qCACE,UACA,MACA,MACA,OACA;AACA,OAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,IAAI;IAEnC,MAAM,iBAAiB,MAAM,QAAQ,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAM,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,GAAG,6BAA6B,IAAI,SAAS;KAC7C,YAAY,IAAI;KACjB;AAED,gCAA4B,IAAI,iBAAiB,OAAO;AACxD,SAAK,SAAS,KAAK,qBAAqB,IAAI,IAAI;AAChD,SAAK,aAAa,OAAO,cAAc,IAAI;AAG3C,SAAK,qCAAqC,UAAU,MAAM,IAAI,cAAc,CAC1E,GAAG,OACH,qBAAqB,IAAI,CAC1B,CAAC;AAEF;;GAEF,KAAK,YAAY;IACf,MAAM,WAAW,KAAK,m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I,CAAC;AAExD,iBAAY,KAAK;MAAE;MAAK,KAAK,IAAI,MAAM,aAAa;MAAE,CAAC;AAEvD;;AAIF,YAAQ,IAAI,SAAS,MAArB;KACE,KAAK;AAEH,WAAK,OAAO,IAAI;AAChB,aAAO,KAAK,KAAK,IAAI;AACrB;KACF,KAAK;AAEH,WAAK,YAAY,IAAI;AACrB,aAAO,SAAS,KAAK,IAAI;AACzB;KACF,KAAK;AAEH,WAAK,SAAS,IAAI;AAClB,aAAO,OAAO,KAAK,IAAI;AACvB;KACF,KAAK;AAEH,UAAI;OACF,MAAM,MAAM,KAAK,sBAAsB,IAAI;OAC3C,MAAM,aAAa,sBAAsB,IAAI,aAAa,IAAI,UAAU,KAAK,IAAI,IAAI;AACrF,YAAK,YAAY,WAAW;AAC5B,cAAO,UAAU,KAAK,WAAW;eAC1B,OAAgB;OACvB,MAAM,MAAM;OACZ,IAAI,eAAe,+BAA+B,iBAAiB,IAAI,SAAS,CAAC;AACjF,uBAAgB,OAAO,IAAI,QAAQ;AAEnC,mBAAY,KAAK;QAAE;QAAK,KAAK,MAAM,aAAa;QAAE,CAAC;;AAErD;KACF,KAAK,OAEH;KACF,QACE,aAAY,IAAI,SAAS,KAAK;;;AAMpC,OAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;AAEnB,SAAK,MAAM,KAAK,YACd,iBAAgB,KAAK,EAAE,IAAI;AAE7B,UAAM,IAAI,MAAM,aAAa;;AAG/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const require_util = require(
|
|
2
|
-
|
|
1
|
+
const require_util = require("./util.cjs");
|
|
3
2
|
//#region src/compiler/compileroptions.ts
|
|
4
3
|
function applyTemplateCompilerOptions(opts, tpl) {
|
|
5
4
|
for (const opt of opts) switch (opt.name) {
|
|
@@ -19,8 +18,8 @@ function hashOverride(args) {
|
|
|
19
18
|
if (!require_util.isUUID(override)) throw new Error("hash_override must contain valid UUID as an override. As hash_override affects deduplication, it becomes completely not possible to distinguish several different templates from each other on backend's side. This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates, they will be marked as interchangeable on backend's side with unpredictable consequences. UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety");
|
|
20
19
|
return override;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
22
|
exports.applyLibraryCompilerOptions = applyLibraryCompilerOptions;
|
|
25
23
|
exports.applyTemplateCompilerOptions = applyTemplateCompilerOptions;
|
|
24
|
+
|
|
26
25
|
//# sourceMappingURL=compileroptions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileroptions.cjs","names":[],"sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from \"@milaboratories/pl-model-backend\";\nimport type { CompilerOption } from \"./package\";\nimport * as util from \"./util\";\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +\n ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +\n ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +\n ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n \"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.\",\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n \"hash_override must contain valid UUID as an override. As hash_override affects deduplication,\" +\n \" it becomes completely not possible to distinguish several different templates from each other on backend's side.\" +\n ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,' +\n \" they will be marked as interchangeable on backend's side with unpredictable consequences.\" +\n \" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety\",\n );\n }\n\n return override;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compileroptions.cjs","names":[],"sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from \"@milaboratories/pl-model-backend\";\nimport type { CompilerOption } from \"./package\";\nimport * as util from \"./util\";\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +\n ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +\n ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +\n ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n \"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.\",\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n \"hash_override must contain valid UUID as an override. As hash_override affects deduplication,\" +\n \" it becomes completely not possible to distinguish several different templates from each other on backend's side.\" +\n ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,' +\n \" they will be marked as interchangeable on backend's side with unpredictable consequences.\" +\n \" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety\",\n );\n }\n\n return override;\n}\n"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;AACxF,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK;AACH,OAAI,eAAe,aAAa,IAAI,KAAK;AACzC;;;AAMR,SAAgB,4BAA4B,MAAwB,MAAyB;AAC3F,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK,gBACH,OAAM,IAAI,MACR,+YAID;;;AAMT,SAAgB,aAAa,MAAwB;AACnD,KAAI,KAAK,UAAU,EACjB,OAAM,IAAI,MACR,mIACD;CAGH,MAAM,WAAW,KAAK,GAAG,aAAa;AAEtC,KAAI,CAAA,aAAA,OAAa,SAAS,CACxB,OAAM,IAAI,MACR,ggBAKD;AAGH,QAAO"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isUUID } from "./util.js";
|
|
2
|
-
|
|
3
2
|
//#region src/compiler/compileroptions.ts
|
|
4
3
|
function applyTemplateCompilerOptions(opts, tpl) {
|
|
5
4
|
for (const opt of opts) switch (opt.name) {
|
|
@@ -19,7 +18,7 @@ function hashOverride(args) {
|
|
|
19
18
|
if (!isUUID(override)) throw new Error("hash_override must contain valid UUID as an override. As hash_override affects deduplication, it becomes completely not possible to distinguish several different templates from each other on backend's side. This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates, they will be marked as interchangeable on backend's side with unpredictable consequences. UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety");
|
|
20
19
|
return override;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
22
|
export { applyLibraryCompilerOptions, applyTemplateCompilerOptions };
|
|
23
|
+
|
|
25
24
|
//# sourceMappingURL=compileroptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileroptions.js","names":["util.isUUID"],"sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from \"@milaboratories/pl-model-backend\";\nimport type { CompilerOption } from \"./package\";\nimport * as util from \"./util\";\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +\n ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +\n ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +\n ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n \"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.\",\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n \"hash_override must contain valid UUID as an override. As hash_override affects deduplication,\" +\n \" it becomes completely not possible to distinguish several different templates from each other on backend's side.\" +\n ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,' +\n \" they will be marked as interchangeable on backend's side with unpredictable consequences.\" +\n \" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety\",\n );\n }\n\n return override;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compileroptions.js","names":["util.isUUID"],"sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from \"@milaboratories/pl-model-backend\";\nimport type { CompilerOption } from \"./package\";\nimport * as util from \"./util\";\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +\n ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +\n ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +\n ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n \"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.\",\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n \"hash_override must contain valid UUID as an override. As hash_override affects deduplication,\" +\n \" it becomes completely not possible to distinguish several different templates from each other on backend's side.\" +\n ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,' +\n \" they will be marked as interchangeable on backend's side with unpredictable consequences.\" +\n \" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety\",\n );\n }\n\n return override;\n}\n"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;AACxF,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK;AACH,OAAI,eAAe,aAAa,IAAI,KAAK;AACzC;;;AAMR,SAAgB,4BAA4B,MAAwB,MAAyB;AAC3F,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK,gBACH,OAAM,IAAI,MACR,+YAID;;;AAMT,SAAgB,aAAa,MAAwB;AACnD,KAAI,KAAK,UAAU,EACjB,OAAM,IAAI,MACR,mIACD;CAGH,MAAM,WAAW,KAAK,GAAG,aAAa;AAEtC,KAAI,CAACA,OAAY,SAAS,CACxB,OAAM,IAAI,MACR,ggBAKD;AAGH,QAAO"}
|
package/dist/compiler/main.cjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
2
|
-
const require_util = require(
|
|
3
|
-
const require_package = require(
|
|
4
|
-
const require_template = require(
|
|
5
|
-
const require_compiler = require(
|
|
6
|
-
const require_source = require(
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_util = require("./util.cjs");
|
|
3
|
+
const require_package = require("./package.cjs");
|
|
4
|
+
const require_template = require("./template.cjs");
|
|
5
|
+
const require_compiler = require("./compiler.cjs");
|
|
6
|
+
const require_source = require("./source.cjs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_runtime.__toESM(node_path);
|
|
9
9
|
let node_fs = require("node:fs");
|
|
10
10
|
node_fs = require_runtime.__toESM(node_fs);
|
|
11
11
|
let _milaboratories_pl_model_backend = require("@milaboratories/pl-model-backend");
|
|
12
12
|
let _milaboratories_resolve_helper = require("@milaboratories/resolve-helper");
|
|
13
|
-
|
|
14
13
|
//#region src/compiler/main.ts
|
|
15
14
|
const compiledTplSuffix = ".plj.gz";
|
|
16
15
|
const compiledLibSuffix = ".lib.tengo";
|
|
@@ -300,11 +299,11 @@ function savePacks(logger, compiled, mode) {
|
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
}
|
|
303
|
-
|
|
304
302
|
//#endregion
|
|
305
303
|
exports.compile = compile;
|
|
306
304
|
exports.getPackageInfo = getPackageInfo;
|
|
307
305
|
exports.newCompiler = newCompiler;
|
|
308
306
|
exports.parseSources = parseSources;
|
|
309
307
|
exports.savePacks = savePacks;
|
|
308
|
+
|
|
310
309
|
//# sourceMappingURL=main.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","names":["path","pathType","fs","parseSourceFile","fullNameToString","typedArtifactNameToString","newTemplateFromContent","templateToSource","ArtifactSource","getSha256","TengoTemplateCompiler"],"sources":["../../src/compiler/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport { pathType } from \"./util\";\nimport type { TemplatesAndLibs } from \"./compiler\";\nimport { TengoTemplateCompiler } from \"./compiler\";\nimport { getSha256 } from \"./source\";\nimport type { CompileMode, FullArtifactName } from \"./package\";\nimport { fullNameToString, typedArtifactNameToString } from \"./package\";\nimport { ArtifactSource, parseSourceFile } from \"./source\";\nimport { newTemplateFromContent, templateToSource } from \"./template\";\nimport type winston from \"winston\";\nimport { tryResolve, tryResolveOrError } from \"@milaboratories/resolve-helper\";\nimport { serializeTemplate } from \"@milaboratories/pl-model-backend\";\n\ninterface PackageId {\n /** Package name from package.json */\n readonly name: string;\n /** Package version from package.json */\n readonly version: string;\n}\n\ninterface PackageInfo extends PackageId {\n /** Package type from package.json */\n readonly type: string | undefined;\n /** Path to package root */\n readonly root: string;\n /** Context of package info */\n readonly context: PackageInfoContext;\n /** Dependencies */\n readonly dependencies: PackageInfo[];\n}\n\ninterface PackageJson {\n name: string;\n version: string;\n type: string | undefined;\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n}\n\nconst compiledTplSuffix = \".plj.gz\";\nconst compiledLibSuffix = \".lib.tengo\";\nconst compiledSoftwareSuffix = \".sw.json\";\nconst compiledAssetSuffix = \".as.json\";\n\n// We need to keep track of dependencies for correct tgo-test CLI utility configuraiton.\n// It is much simpler to do this here, than duplicate all tle logic regarding dependencies\n// in go code.\nconst srcTestSuffix = \".test.tengo\";\n\nconst srcTplSuffix = \".tpl.tengo\";\nconst srcLibSuffix = \".lib.tengo\";\nconst srcSoftwareSuffix = \".sw.json\";\nconst srcAssetSuffix = \".as.json\";\nconst compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];\n\n/**\n * Resolves path to package.json file of the given dependency package.\n */\nfunction resolvePackageJsonPackage(root: string, depPackageName: string): string | undefined {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n // First approach: resolving package's main entry point and try to find package.json\n // in dir tree upwards.\n let resolved = tryResolve(root, depPackageName);\n if (resolved) {\n let depth = 0;\n do {\n const p = path.join(resolved, \"package.json\");\n if (pathType(p) === \"file\") return p;\n depth++;\n resolved = path.dirname(resolved);\n } while (depth < 7 && path.basename(resolved) !== \"node_modules\");\n }\n\n // Second approach: trying to find package.json in the package dir.\n const resolved2 = tryResolveOrError(root, `${depPackageName}/package.json`);\n if (resolved2.result === undefined) {\n if (resolved2.err === \"ERR_PACKAGE_PATH_NOT_EXPORTED\")\n // tolerating not-exported package.json for dev dependencies\n return undefined;\n throw new Error(\n `Can't resolve package.json for package ${depPackageName ?? \".\"} relative to ${root}`,\n );\n }\n return resolved2.result;\n}\n\nexport function resolvePackageJsonRoot(root: string): string {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n const p = path.join(root, \"package.json\");\n if (pathType(p) === \"file\") return p;\n throw new Error(`Can't resolve package.json in ${root}`);\n}\n\ntype PackageInfoContext = \"root\" | \"dependency\" | \"devDependency\";\n\n/**\n * Get package info from package.json and all dependencies.\n */\nexport function getPackageInfo(\n root: string,\n logger: winston.Logger,\n context: PackageInfoContext = \"root\",\n): PackageInfo {\n const packageJsonPath = resolvePackageJsonRoot(root);\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) as PackageJson;\n\n // resolving dependencies\n const depInfos: PackageInfo[] = [];\n\n if (packageJson.dependencies && context !== \"devDependency\") {\n for (const dep of Object.keys(packageJson.dependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined)\n throw new Error(`Can't resolve package.json for dependency ${dep} of ${root}`);\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, \"dependency\"));\n }\n }\n\n if (packageJson.devDependencies && context === \"root\") {\n for (const dep of Object.keys(packageJson.devDependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined) {\n logger.warn(`Can't resolve package.json for dev dependency ${dep} of ${root}`);\n // tolerating not-exported package.json for dev dependencies\n continue;\n }\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, \"devDependency\"));\n }\n }\n\n return {\n name: packageJson.name,\n version: packageJson.version,\n type: packageJson.type,\n dependencies: depInfos,\n root,\n context,\n };\n}\n\nfunction resolveLibsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"lib\");\n}\n\nfunction resolveTemplatesDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"tpl\");\n}\n\nfunction resolveSoftwareDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"software\");\n}\n\nfunction resolveAssetsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"asset\");\n}\n\nfunction loadDependencies(\n logger: winston.Logger,\n compiler: TengoTemplateCompiler,\n packageInfo: PackageInfo,\n): void {\n for (const dep of packageInfo.dependencies) loadDependencies(logger, compiler, dep);\n\n if (packageInfo.context === \"root\")\n // we are not reading compiled files for root package\n return;\n\n // we are in package folder\n const libDistFolder = resolveLibsDst(\"dist\", packageInfo.root);\n const tplDistFolder = resolveTemplatesDst(\"dist\", packageInfo.root);\n const softwareDistFolder = resolveSoftwareDst(\"dist\", packageInfo.root);\n const assetDistFolder = resolveAssetsDst(\"dist\", packageInfo.root);\n\n const libDistExists = pathType(libDistFolder) === \"dir\";\n const tplDistExists = pathType(tplDistFolder) === \"dir\";\n const softwareDistExists = pathType(softwareDistFolder) === \"dir\";\n const assetDistExists = pathType(assetDistFolder) === \"dir\";\n\n if (!libDistExists && !tplDistExists && !softwareDistExists && !assetDistExists)\n // if neither of tengo-specific folders detected, skipping package\n return;\n\n const packageId = { name: packageInfo.name, version: packageInfo.version };\n\n if (libDistExists) {\n loadLibsFromDir(logger, packageId, \"dist\", libDistFolder, compiler);\n }\n\n if (tplDistExists) {\n loadTemplatesFromDir(logger, packageId, \"dist\", tplDistFolder, compiler);\n }\n\n if (softwareDistExists) {\n loadSoftwareFromDir(logger, packageId, \"dist\", softwareDistFolder, compiler);\n }\n\n if (assetDistExists) {\n loadAssetsFromDir(logger, packageId, \"dist\", assetDistFolder, compiler);\n }\n}\n\nfunction loadLibsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledLibSuffix)) throw new Error(`unexpected file in 'lib' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"library\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledLibSuffix.length),\n version: packageId.version,\n };\n const src = parseSourceFile(logger, mode, file, fullName, true);\n compiler.addLib(src);\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n if (src.dependencies.length > 0) {\n logger.debug(\"Dependencies:\");\n for (const dep of src.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n }\n}\n\nfunction loadTemplatesFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n // adding templates\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledTplSuffix)) throw new Error(`unexpected file in 'tpl' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"template\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledTplSuffix.length),\n version: packageId.version,\n };\n const tpl = newTemplateFromContent(mode, fullName, fs.readFileSync(file));\n compiler.addTemplate(templateToSource(tpl));\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n }\n}\n\nfunction loadSoftwareFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledSoftwareSuffix))\n throw new Error(`unexpected file in 'software' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"software\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledSoftwareSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const software = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addSoftware(software);\n }\n}\n\nfunction loadAssetsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledAssetSuffix))\n throw new Error(`unexpected file in 'asset' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"asset\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledAssetSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const asset = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addAsset(asset);\n }\n}\n\nexport function parseSources(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n root: string,\n subdir: string,\n): ArtifactSource[] {\n const sources: ArtifactSource[] = [];\n\n for (const f of fs.readdirSync(path.join(root, subdir))) {\n const inRootPath = path.join(subdir, f); // path to item inside given <root>\n const fullPath = path.join(root, inRootPath); // full path to item from CWD (or abs path, if <root> is abs path)\n\n if (pathType(fullPath) === \"dir\") {\n const nested = parseSources(logger, packageId, mode, root, inRootPath);\n sources.push(...nested);\n continue;\n }\n\n // Handling index.lib.tengo files: rename them to <package-name>.lib.tengo\n const artifactName =\n f === \"index.lib.tengo\" ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;\n\n const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep, \".\"));\n if (!fullName) {\n logger.info(`Skipping unknown file type: ${artifactName}`);\n continue; // skip unknown file types\n }\n\n // if (subdir != '') {\n // throw new Error(`Templates and libraries should reside only inside '${root}' dir.\n // You are free to have any file and dirs structure inside '${root}' keeping other files where you want,\n // but regarding ${compilableSuffixes.join(', ')}, the flat file structure is mandatory.`);\n // }\n\n const file = path.resolve(root, inRootPath);\n logger.debug(`Parsing ${fullNameToString(fullName)} from ${file}`);\n const newSrc = parseSourceFile(logger, mode, file, fullName, true);\n if (newSrc.dependencies.length > 0) {\n logger.debug(\"Detected dependencies:\");\n for (const dep of newSrc.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n\n sources.push(newSrc);\n }\n\n return sources;\n}\n\nexport function newCompiler(\n logger: winston.Logger,\n packageInfo: PackageInfo,\n mode: CompileMode,\n): TengoTemplateCompiler {\n const compiler = new TengoTemplateCompiler(mode);\n\n // collect all data (templates, libs and software) from dependency tree\n loadDependencies(logger, compiler, packageInfo);\n\n return compiler;\n}\n\nexport function fullNameFromFileName(\n packageId: PackageId,\n artifactName: string,\n): FullArtifactName | null {\n const pkgAndVersion = { pkg: packageId.name, version: packageId.version };\n if (artifactName.endsWith(srcLibSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),\n type: \"library\",\n };\n }\n\n if (artifactName.endsWith(srcTplSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),\n type: \"template\",\n };\n }\n\n if (artifactName.endsWith(srcSoftwareSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),\n type: \"software\",\n };\n }\n\n if (artifactName.endsWith(srcAssetSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),\n type: \"asset\",\n };\n }\n\n if (artifactName.endsWith(srcTestSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),\n type: \"test\",\n };\n }\n\n return null;\n}\n\nexport function compile(\n logger: winston.Logger,\n packageInfo: PackageInfo,\n mode: CompileMode,\n): TemplatesAndLibs {\n const compiler = newCompiler(logger, packageInfo, mode);\n const sources = parseSources(logger, packageInfo, mode, \"src\", \"\");\n\n // checking that we have something to do\n if (sources.length === 0) {\n const lookFor: string[] = [];\n for (const suffix of compilableSuffixes) {\n lookFor.push(`*${suffix}`);\n }\n\n logger.error(`Nothing to compile. Looked for ${lookFor.join(\", \")}`);\n process.exit(1);\n }\n\n // compilation\n logger.info(`Compiling '${mode}'...`);\n const compiled = compiler.compileAndAdd(sources);\n logger.debug(`Done.`);\n\n return compiled;\n}\n\nexport function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode) {\n // writing libs\n if (compiled.libs.length > 0) {\n const libOutput = resolveLibsDst(mode, \".\");\n fs.mkdirSync(libOutput, { recursive: true });\n for (const lib of compiled.libs) {\n const file = path.resolve(libOutput, lib.fullName.id + compiledLibSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, lib.src);\n }\n }\n\n // writing templates\n if (compiled.templates.length > 0) {\n const tplOutput = resolveTemplatesDst(mode, \".\");\n fs.mkdirSync(tplOutput, { recursive: true });\n for (const tpl of compiled.templates) {\n const file = path.resolve(tplOutput, tpl.fullName.id + compiledTplSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, serializeTemplate(tpl.data));\n }\n }\n\n // writing software\n if (compiled.software.length > 0) {\n const swOutput = resolveSoftwareDst(mode, \".\");\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledSoftwareSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, sw.src);\n }\n }\n\n // writing assets\n if (compiled.assets.length > 0) {\n const swOutput = resolveAssetsDst(mode, \".\");\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledAssetSuffix);\n logger.info(` - writing ${file}`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W,iBAAiB,MAAM,IAAI;AAC5C,UAAG,UAAU,UAAU,EAAE,WAAW,MAAM,CAAC;AAC3C,OAAK,MAAM,MAAM,SAAS,UAAU;GAClC,MAAM,OAAOA,UAAK,QAAQ,UAAU,GAAG,SAAS,KAAK,oBAAoB;AACzE,UAAO,KAAK,eAAe,OAAO;AAClC,WAAG,cAAc,MAAM,GAAG,IAAI"}
|
|
1
|
+
{"version":3,"file":"main.cjs","names":["path","pathType","fs","parseSourceFile","fullNameToString","typedArtifactNameToString","newTemplateFromContent","templateToSource","ArtifactSource","getSha256","TengoTemplateCompiler"],"sources":["../../src/compiler/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport { pathType } from \"./util\";\nimport type { TemplatesAndLibs } from \"./compiler\";\nimport { TengoTemplateCompiler } from \"./compiler\";\nimport { getSha256 } from \"./source\";\nimport type { CompileMode, FullArtifactName } from \"./package\";\nimport { fullNameToString, typedArtifactNameToString } from \"./package\";\nimport { ArtifactSource, parseSourceFile } from \"./source\";\nimport { newTemplateFromContent, templateToSource } from \"./template\";\nimport type winston from \"winston\";\nimport { tryResolve, tryResolveOrError } from \"@milaboratories/resolve-helper\";\nimport { serializeTemplate } from \"@milaboratories/pl-model-backend\";\n\ninterface PackageId {\n /** Package name from package.json */\n readonly name: string;\n /** Package version from package.json */\n readonly version: string;\n}\n\ninterface PackageInfo extends PackageId {\n /** Package type from package.json */\n readonly type: string | undefined;\n /** Path to package root */\n readonly root: string;\n /** Context of package info */\n readonly context: PackageInfoContext;\n /** Dependencies */\n readonly dependencies: PackageInfo[];\n}\n\ninterface PackageJson {\n name: string;\n version: string;\n type: string | undefined;\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n}\n\nconst compiledTplSuffix = \".plj.gz\";\nconst compiledLibSuffix = \".lib.tengo\";\nconst compiledSoftwareSuffix = \".sw.json\";\nconst compiledAssetSuffix = \".as.json\";\n\n// We need to keep track of dependencies for correct tgo-test CLI utility configuraiton.\n// It is much simpler to do this here, than duplicate all tle logic regarding dependencies\n// in go code.\nconst srcTestSuffix = \".test.tengo\";\n\nconst srcTplSuffix = \".tpl.tengo\";\nconst srcLibSuffix = \".lib.tengo\";\nconst srcSoftwareSuffix = \".sw.json\";\nconst srcAssetSuffix = \".as.json\";\nconst compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];\n\n/**\n * Resolves path to package.json file of the given dependency package.\n */\nfunction resolvePackageJsonPackage(root: string, depPackageName: string): string | undefined {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n // First approach: resolving package's main entry point and try to find package.json\n // in dir tree upwards.\n let resolved = tryResolve(root, depPackageName);\n if (resolved) {\n let depth = 0;\n do {\n const p = path.join(resolved, \"package.json\");\n if (pathType(p) === \"file\") return p;\n depth++;\n resolved = path.dirname(resolved);\n } while (depth < 7 && path.basename(resolved) !== \"node_modules\");\n }\n\n // Second approach: trying to find package.json in the package dir.\n const resolved2 = tryResolveOrError(root, `${depPackageName}/package.json`);\n if (resolved2.result === undefined) {\n if (resolved2.err === \"ERR_PACKAGE_PATH_NOT_EXPORTED\")\n // tolerating not-exported package.json for dev dependencies\n return undefined;\n throw new Error(\n `Can't resolve package.json for package ${depPackageName ?? \".\"} relative to ${root}`,\n );\n }\n return resolved2.result;\n}\n\nexport function resolvePackageJsonRoot(root: string): string {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n const p = path.join(root, \"package.json\");\n if (pathType(p) === \"file\") return p;\n throw new Error(`Can't resolve package.json in ${root}`);\n}\n\ntype PackageInfoContext = \"root\" | \"dependency\" | \"devDependency\";\n\n/**\n * Get package info from package.json and all dependencies.\n */\nexport function getPackageInfo(\n root: string,\n logger: winston.Logger,\n context: PackageInfoContext = \"root\",\n): PackageInfo {\n const packageJsonPath = resolvePackageJsonRoot(root);\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) as PackageJson;\n\n // resolving dependencies\n const depInfos: PackageInfo[] = [];\n\n if (packageJson.dependencies && context !== \"devDependency\") {\n for (const dep of Object.keys(packageJson.dependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined)\n throw new Error(`Can't resolve package.json for dependency ${dep} of ${root}`);\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, \"dependency\"));\n }\n }\n\n if (packageJson.devDependencies && context === \"root\") {\n for (const dep of Object.keys(packageJson.devDependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined) {\n logger.warn(`Can't resolve package.json for dev dependency ${dep} of ${root}`);\n // tolerating not-exported package.json for dev dependencies\n continue;\n }\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, \"devDependency\"));\n }\n }\n\n return {\n name: packageJson.name,\n version: packageJson.version,\n type: packageJson.type,\n dependencies: depInfos,\n root,\n context,\n };\n}\n\nfunction resolveLibsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"lib\");\n}\n\nfunction resolveTemplatesDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"tpl\");\n}\n\nfunction resolveSoftwareDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"software\");\n}\n\nfunction resolveAssetsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, \"tengo\", \"asset\");\n}\n\nfunction loadDependencies(\n logger: winston.Logger,\n compiler: TengoTemplateCompiler,\n packageInfo: PackageInfo,\n): void {\n for (const dep of packageInfo.dependencies) loadDependencies(logger, compiler, dep);\n\n if (packageInfo.context === \"root\")\n // we are not reading compiled files for root package\n return;\n\n // we are in package folder\n const libDistFolder = resolveLibsDst(\"dist\", packageInfo.root);\n const tplDistFolder = resolveTemplatesDst(\"dist\", packageInfo.root);\n const softwareDistFolder = resolveSoftwareDst(\"dist\", packageInfo.root);\n const assetDistFolder = resolveAssetsDst(\"dist\", packageInfo.root);\n\n const libDistExists = pathType(libDistFolder) === \"dir\";\n const tplDistExists = pathType(tplDistFolder) === \"dir\";\n const softwareDistExists = pathType(softwareDistFolder) === \"dir\";\n const assetDistExists = pathType(assetDistFolder) === \"dir\";\n\n if (!libDistExists && !tplDistExists && !softwareDistExists && !assetDistExists)\n // if neither of tengo-specific folders detected, skipping package\n return;\n\n const packageId = { name: packageInfo.name, version: packageInfo.version };\n\n if (libDistExists) {\n loadLibsFromDir(logger, packageId, \"dist\", libDistFolder, compiler);\n }\n\n if (tplDistExists) {\n loadTemplatesFromDir(logger, packageId, \"dist\", tplDistFolder, compiler);\n }\n\n if (softwareDistExists) {\n loadSoftwareFromDir(logger, packageId, \"dist\", softwareDistFolder, compiler);\n }\n\n if (assetDistExists) {\n loadAssetsFromDir(logger, packageId, \"dist\", assetDistFolder, compiler);\n }\n}\n\nfunction loadLibsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledLibSuffix)) throw new Error(`unexpected file in 'lib' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"library\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledLibSuffix.length),\n version: packageId.version,\n };\n const src = parseSourceFile(logger, mode, file, fullName, true);\n compiler.addLib(src);\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n if (src.dependencies.length > 0) {\n logger.debug(\"Dependencies:\");\n for (const dep of src.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n }\n}\n\nfunction loadTemplatesFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n // adding templates\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledTplSuffix)) throw new Error(`unexpected file in 'tpl' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"template\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledTplSuffix.length),\n version: packageId.version,\n };\n const tpl = newTemplateFromContent(mode, fullName, fs.readFileSync(file));\n compiler.addTemplate(templateToSource(tpl));\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n }\n}\n\nfunction loadSoftwareFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledSoftwareSuffix))\n throw new Error(`unexpected file in 'software' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"software\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledSoftwareSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const software = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addSoftware(software);\n }\n}\n\nfunction loadAssetsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledAssetSuffix))\n throw new Error(`unexpected file in 'asset' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: \"asset\",\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledAssetSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const asset = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addAsset(asset);\n }\n}\n\nexport function parseSources(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n root: string,\n subdir: string,\n): ArtifactSource[] {\n const sources: ArtifactSource[] = [];\n\n for (const f of fs.readdirSync(path.join(root, subdir))) {\n const inRootPath = path.join(subdir, f); // path to item inside given <root>\n const fullPath = path.join(root, inRootPath); // full path to item from CWD (or abs path, if <root> is abs path)\n\n if (pathType(fullPath) === \"dir\") {\n const nested = parseSources(logger, packageId, mode, root, inRootPath);\n sources.push(...nested);\n continue;\n }\n\n // Handling index.lib.tengo files: rename them to <package-name>.lib.tengo\n const artifactName =\n f === \"index.lib.tengo\" ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;\n\n const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep, \".\"));\n if (!fullName) {\n logger.info(`Skipping unknown file type: ${artifactName}`);\n continue; // skip unknown file types\n }\n\n // if (subdir != '') {\n // throw new Error(`Templates and libraries should reside only inside '${root}' dir.\n // You are free to have any file and dirs structure inside '${root}' keeping other files where you want,\n // but regarding ${compilableSuffixes.join(', ')}, the flat file structure is mandatory.`);\n // }\n\n const file = path.resolve(root, inRootPath);\n logger.debug(`Parsing ${fullNameToString(fullName)} from ${file}`);\n const newSrc = parseSourceFile(logger, mode, file, fullName, true);\n if (newSrc.dependencies.length > 0) {\n logger.debug(\"Detected dependencies:\");\n for (const dep of newSrc.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n\n sources.push(newSrc);\n }\n\n return sources;\n}\n\nexport function newCompiler(\n logger: winston.Logger,\n packageInfo: PackageInfo,\n mode: CompileMode,\n): TengoTemplateCompiler {\n const compiler = new TengoTemplateCompiler(mode);\n\n // collect all data (templates, libs and software) from dependency tree\n loadDependencies(logger, compiler, packageInfo);\n\n return compiler;\n}\n\nexport function fullNameFromFileName(\n packageId: PackageId,\n artifactName: string,\n): FullArtifactName | null {\n const pkgAndVersion = { pkg: packageId.name, version: packageId.version };\n if (artifactName.endsWith(srcLibSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),\n type: \"library\",\n };\n }\n\n if (artifactName.endsWith(srcTplSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),\n type: \"template\",\n };\n }\n\n if (artifactName.endsWith(srcSoftwareSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),\n type: \"software\",\n };\n }\n\n if (artifactName.endsWith(srcAssetSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),\n type: \"asset\",\n };\n }\n\n if (artifactName.endsWith(srcTestSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),\n type: \"test\",\n };\n }\n\n return null;\n}\n\nexport function compile(\n logger: winston.Logger,\n packageInfo: PackageInfo,\n mode: CompileMode,\n): TemplatesAndLibs {\n const compiler = newCompiler(logger, packageInfo, mode);\n const sources = parseSources(logger, packageInfo, mode, \"src\", \"\");\n\n // checking that we have something to do\n if (sources.length === 0) {\n const lookFor: string[] = [];\n for (const suffix of compilableSuffixes) {\n lookFor.push(`*${suffix}`);\n }\n\n logger.error(`Nothing to compile. Looked for ${lookFor.join(\", \")}`);\n process.exit(1);\n }\n\n // compilation\n logger.info(`Compiling '${mode}'...`);\n const compiled = compiler.compileAndAdd(sources);\n logger.debug(`Done.`);\n\n return compiled;\n}\n\nexport function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode) {\n // writing libs\n if (compiled.libs.length > 0) {\n const libOutput = resolveLibsDst(mode, \".\");\n fs.mkdirSync(libOutput, { recursive: true });\n for (const lib of compiled.libs) {\n const file = path.resolve(libOutput, lib.fullName.id + compiledLibSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, lib.src);\n }\n }\n\n // writing templates\n if (compiled.templates.length > 0) {\n const tplOutput = resolveTemplatesDst(mode, \".\");\n fs.mkdirSync(tplOutput, { recursive: true });\n for (const tpl of compiled.templates) {\n const file = path.resolve(tplOutput, tpl.fullName.id + compiledTplSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, serializeTemplate(tpl.data));\n }\n }\n\n // writing software\n if (compiled.software.length > 0) {\n const swOutput = resolveSoftwareDst(mode, \".\");\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledSoftwareSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, sw.src);\n }\n }\n\n // writing assets\n if (compiled.assets.length > 0) {\n const swOutput = resolveAssetsDst(mode, \".\");\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledAssetSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, sw.src);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAK5B,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,MAAM,qBAAqB;CAAC;CAAc;CAAc;CAAmB;CAAe;;;;AAK1F,SAAS,0BAA0B,MAAc,gBAA4C;AAC3F,KAAI,CAACA,UAAK,WAAW,KAAK,CACxB,OAAM,IAAI,MAAM,+BAA+B,OAAO;CAKxD,IAAI,YAAA,GAAA,+BAAA,YAAsB,MAAM,eAAe;AAC/C,KAAI,UAAU;EACZ,IAAI,QAAQ;AACZ,KAAG;GACD,MAAM,IAAIA,UAAK,KAAK,UAAU,eAAe;AAC7C,OAAIC,aAAAA,SAAS,EAAE,KAAK,OAAQ,QAAO;AACnC;AACA,cAAWD,UAAK,QAAQ,SAAS;WAC1B,QAAQ,KAAKA,UAAK,SAAS,SAAS,KAAK;;CAIpD,MAAM,aAAA,GAAA,+BAAA,mBAA8B,MAAM,GAAG,eAAe,eAAe;AAC3E,K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AAG,cAAc,MAAM,IAAI,IAAI;;;AAKnC,KAAI,SAAS,UAAU,SAAS,GAAG;EACjC,MAAM,YAAY,oBAAoB,MAAM,IAAI;AAChD,UAAG,UAAU,WAAW,EAAE,WAAW,MAAM,CAAC;AAC5C,OAAK,MAAM,OAAO,SAAS,WAAW;GACpC,MAAM,OAAOA,UAAK,QAAQ,WAAW,IAAI,SAAS,KAAK,kBAAkB;AACzE,UAAO,KAAK,eAAe,OAAO;AAClC,WAAG,cAAc,OAAA,GAAA,iCAAA,mBAAwB,IAAI,KAAK,CAAC;;;AAKvD,KAAI,SAAS,SAAS,SAAS,GAAG;EAChC,MAAM,WAAW,mBAAmB,MAAM,IAAI;AAC9C,UAAG,UAAU,UAAU,EAAE,WAAW,MAAM,CAAC;AAC3C,OAAK,MAAM,MAAM,SAAS,UAAU;GAClC,MAAM,OAAOA,UAAK,QAAQ,UAAU,GAAG,SAAS,KAAK,uBAAuB;AAC5E,UAAO,KAAK,eAAe,OAAO;AAClC,WAAG,cAAc,MAAM,GAAG,IAAI;;;AAKlC,KAAI,SAAS,OAAO,SAAS,GAAG;EAC9B,MAAM,WAAW,iBAAiB,MAAM,IAAI;AAC5C,UAAG,UAAU,UAAU,EAAE,WAAW,MAAM,CAAC;AAC3C,OAAK,MAAM,MAAM,SAAS,UAAU;GAClC,MAAM,OAAOA,UAAK,QAAQ,UAAU,GAAG,SAAS,KAAK,oBAAoB;AACzE,UAAO,KAAK,eAAe,OAAO;AAClC,WAAG,cAAc,MAAM,GAAG,IAAI"}
|
package/dist/compiler/main.js
CHANGED
|
@@ -7,7 +7,6 @@ import * as path from "node:path";
|
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import { serializeTemplate } from "@milaboratories/pl-model-backend";
|
|
9
9
|
import { tryResolve, tryResolveOrError } from "@milaboratories/resolve-helper";
|
|
10
|
-
|
|
11
10
|
//#region src/compiler/main.ts
|
|
12
11
|
const compiledTplSuffix = ".plj.gz";
|
|
13
12
|
const compiledLibSuffix = ".lib.tengo";
|
|
@@ -297,7 +296,7 @@ function savePacks(logger, compiled, mode) {
|
|
|
297
296
|
}
|
|
298
297
|
}
|
|
299
298
|
}
|
|
300
|
-
|
|
301
299
|
//#endregion
|
|
302
300
|
export { compile, getPackageInfo, newCompiler, parseSources, savePacks };
|
|
301
|
+
|
|
303
302
|
//# sourceMappingURL=main.js.map
|