@platforma-sdk/tengo-builder 4.0.10 → 4.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/cli.cjs +0 -1
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/build.cjs +3 -3
  6. package/dist/commands/build.cjs.map +1 -1
  7. package/dist/commands/build.js.map +1 -1
  8. package/dist/commands/check.cjs +0 -1
  9. package/dist/commands/check.cjs.map +1 -1
  10. package/dist/commands/check.js.map +1 -1
  11. package/dist/commands/dump/artifacts.cjs +0 -1
  12. package/dist/commands/dump/artifacts.cjs.map +1 -1
  13. package/dist/commands/dump/artifacts.js.map +1 -1
  14. package/dist/commands/dump/software.cjs +0 -1
  15. package/dist/commands/dump/software.cjs.map +1 -1
  16. package/dist/commands/dump/software.js.map +1 -1
  17. package/dist/commands/test.cjs +0 -1
  18. package/dist/commands/test.cjs.map +1 -1
  19. package/dist/commands/test.js.map +1 -1
  20. package/dist/compiler/artifactset.cjs +2 -0
  21. package/dist/compiler/artifactset.cjs.map +1 -1
  22. package/dist/compiler/artifactset.js +2 -1
  23. package/dist/compiler/artifactset.js.map +1 -1
  24. package/dist/compiler/compiler.cjs +1 -0
  25. package/dist/compiler/compiler.cjs.map +1 -1
  26. package/dist/compiler/compiler.js +1 -0
  27. package/dist/compiler/compiler.js.map +1 -1
  28. package/dist/compiler/compileroptions.cjs +1 -0
  29. package/dist/compiler/compileroptions.cjs.map +1 -1
  30. package/dist/compiler/compileroptions.js +1 -1
  31. package/dist/compiler/compileroptions.js.map +1 -1
  32. package/dist/compiler/main.cjs +5 -3
  33. package/dist/compiler/main.cjs.map +1 -1
  34. package/dist/compiler/main.js +1 -1
  35. package/dist/compiler/main.js.map +1 -1
  36. package/dist/compiler/pack_limits.cjs +2 -0
  37. package/dist/compiler/pack_limits.cjs.map +1 -1
  38. package/dist/compiler/pack_limits.js +1 -1
  39. package/dist/compiler/pack_limits.js.map +1 -1
  40. package/dist/compiler/package.cjs.map +1 -1
  41. package/dist/compiler/package.js.map +1 -1
  42. package/dist/compiler/source.cjs +10 -1
  43. package/dist/compiler/source.cjs.map +1 -1
  44. package/dist/compiler/source.js +8 -1
  45. package/dist/compiler/source.js.map +1 -1
  46. package/dist/compiler/template.cjs +0 -1
  47. package/dist/compiler/template.cjs.map +1 -1
  48. package/dist/compiler/template.js.map +1 -1
  49. package/dist/compiler/util.cjs +3 -3
  50. package/dist/compiler/util.cjs.map +1 -1
  51. package/dist/compiler/util.js.map +1 -1
  52. package/dist/shared/basecmd.cjs +0 -1
  53. package/dist/shared/basecmd.cjs.map +1 -1
  54. package/dist/shared/basecmd.js.map +1 -1
  55. package/dist/shared/dump.cjs.map +1 -1
  56. package/dist/shared/dump.js.map +1 -1
  57. package/dist/shared/proc.cjs +0 -1
  58. package/dist/shared/proc.cjs.map +1 -1
  59. package/dist/shared/proc.js.map +1 -1
  60. package/package.json +6 -6
package/dist/cli.cjs CHANGED
@@ -1,4 +1,3 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
1
  const require_build = require("./commands/build.cjs");
3
2
  const require_check = require("./commands/check.cjs");
4
3
  const require_test = require("./commands/test.cjs");
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","names":["Command","buildCommand","checkCommand","testCommand","dumpArtifactsCommand","dumpSoftwareCommand"],"sources":["../src/cli.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport buildCommand from \"./commands/build\";\nimport checkCommand from \"./commands/check\";\nimport testCommand from \"./commands/test\";\nimport dumpArtifactsCommand from \"./commands/dump/artifacts\";\nimport dumpSoftwareCommand from \"./commands/dump/software\";\n\nexport function buildProgram(): Command {\n const program = new Command();\n program.name(\"pl-tengo\").description(\"Pl Tengo Template Builder\");\n\n program.addCommand(buildCommand());\n program.addCommand(checkCommand());\n program.addCommand(testCommand());\n\n // `dump` is a pure topic (no action): `pl-tengo dump` prints help.\n const dump = new Command(\"dump\").description(\"dump parsed artifacts or software descriptors\");\n dump.addCommand(dumpArtifactsCommand());\n dump.addCommand(dumpSoftwareCommand());\n program.addCommand(dump);\n\n return program;\n}\n\nexport async function run(argv: string[] = process.argv): Promise<void> {\n await buildProgram().parseAsync(argv);\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAIA,UAAAA,SAAS;AAC7B,SAAQ,KAAK,WAAW,CAAC,YAAY,4BAA4B;AAEjE,SAAQ,WAAWC,cAAAA,SAAc,CAAC;AAClC,SAAQ,WAAWC,cAAAA,SAAc,CAAC;AAClC,SAAQ,WAAWC,aAAAA,SAAa,CAAC;CAGjC,MAAM,OAAO,IAAIH,UAAAA,QAAQ,OAAO,CAAC,YAAY,gDAAgD;AAC7F,MAAK,WAAWI,kBAAAA,SAAsB,CAAC;AACvC,MAAK,WAAWC,iBAAAA,SAAqB,CAAC;AACtC,SAAQ,WAAW,KAAK;AAExB,QAAO;;AAGT,eAAsB,IAAI,OAAiB,QAAQ,MAAqB;AACtE,OAAM,cAAc,CAAC,WAAW,KAAK"}
1
+ {"version":3,"file":"cli.cjs","names":["Command","buildCommand","checkCommand","testCommand","dumpArtifactsCommand","dumpSoftwareCommand"],"sources":["../src/cli.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport buildCommand from \"./commands/build\";\nimport checkCommand from \"./commands/check\";\nimport testCommand from \"./commands/test\";\nimport dumpArtifactsCommand from \"./commands/dump/artifacts\";\nimport dumpSoftwareCommand from \"./commands/dump/software\";\n\nexport function buildProgram(): Command {\n const program = new Command();\n program.name(\"pl-tengo\").description(\"Pl Tengo Template Builder\");\n\n program.addCommand(buildCommand());\n program.addCommand(checkCommand());\n program.addCommand(testCommand());\n\n // `dump` is a pure topic (no action): `pl-tengo dump` prints help.\n const dump = new Command(\"dump\").description(\"dump parsed artifacts or software descriptors\");\n dump.addCommand(dumpArtifactsCommand());\n dump.addCommand(dumpSoftwareCommand());\n program.addCommand(dump);\n\n return program;\n}\n\nexport async function run(argv: string[] = process.argv): Promise<void> {\n await buildProgram().parseAsync(argv);\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAIA,UAAAA,QAAQ;CAC5B,QAAQ,KAAK,UAAU,CAAC,CAAC,YAAY,2BAA2B;CAEhE,QAAQ,WAAWC,cAAAA,QAAa,CAAC;CACjC,QAAQ,WAAWC,cAAAA,QAAa,CAAC;CACjC,QAAQ,WAAWC,aAAAA,QAAY,CAAC;CAGhC,MAAM,OAAO,IAAIH,UAAAA,QAAQ,MAAM,CAAC,CAAC,YAAY,+CAA+C;CAC5F,KAAK,WAAWI,kBAAAA,QAAqB,CAAC;CACtC,KAAK,WAAWC,iBAAAA,QAAoB,CAAC;CACrC,QAAQ,WAAW,IAAI;CAEvB,OAAO;AACT;AAEA,eAAsB,IAAI,OAAiB,QAAQ,MAAqB;CACtE,MAAM,aAAa,CAAC,CAAC,WAAW,IAAI;AACtC"}
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":";;;iBAOgB,YAAA,CAAA,GAAgB,OAAA;AAAA,iBAiBV,GAAA,CAAI,IAAA,cAAgC,OAAA"}
1
+ {"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":";;;iBAOgB,YAAA,IAAgB,OAAO;AAAA,iBAiBjB,GAAA,CAAI,IAAA,cAAgC,OAAO"}
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport buildCommand from \"./commands/build\";\nimport checkCommand from \"./commands/check\";\nimport testCommand from \"./commands/test\";\nimport dumpArtifactsCommand from \"./commands/dump/artifacts\";\nimport dumpSoftwareCommand from \"./commands/dump/software\";\n\nexport function buildProgram(): Command {\n const program = new Command();\n program.name(\"pl-tengo\").description(\"Pl Tengo Template Builder\");\n\n program.addCommand(buildCommand());\n program.addCommand(checkCommand());\n program.addCommand(testCommand());\n\n // `dump` is a pure topic (no action): `pl-tengo dump` prints help.\n const dump = new Command(\"dump\").description(\"dump parsed artifacts or software descriptors\");\n dump.addCommand(dumpArtifactsCommand());\n dump.addCommand(dumpSoftwareCommand());\n program.addCommand(dump);\n\n return program;\n}\n\nexport async function run(argv: string[] = process.argv): Promise<void> {\n await buildProgram().parseAsync(argv);\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAI,SAAS;AAC7B,SAAQ,KAAK,WAAW,CAAC,YAAY,4BAA4B;AAEjE,SAAQ,WAAW,cAAc,CAAC;AAClC,SAAQ,WAAW,cAAc,CAAC;AAClC,SAAQ,WAAW,aAAa,CAAC;CAGjC,MAAM,OAAO,IAAI,QAAQ,OAAO,CAAC,YAAY,gDAAgD;AAC7F,MAAK,WAAW,sBAAsB,CAAC;AACvC,MAAK,WAAW,qBAAqB,CAAC;AACtC,SAAQ,WAAW,KAAK;AAExB,QAAO;;AAGT,eAAsB,IAAI,OAAiB,QAAQ,MAAqB;AACtE,OAAM,cAAc,CAAC,WAAW,KAAK"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport buildCommand from \"./commands/build\";\nimport checkCommand from \"./commands/check\";\nimport testCommand from \"./commands/test\";\nimport dumpArtifactsCommand from \"./commands/dump/artifacts\";\nimport dumpSoftwareCommand from \"./commands/dump/software\";\n\nexport function buildProgram(): Command {\n const program = new Command();\n program.name(\"pl-tengo\").description(\"Pl Tengo Template Builder\");\n\n program.addCommand(buildCommand());\n program.addCommand(checkCommand());\n program.addCommand(testCommand());\n\n // `dump` is a pure topic (no action): `pl-tengo dump` prints help.\n const dump = new Command(\"dump\").description(\"dump parsed artifacts or software descriptors\");\n dump.addCommand(dumpArtifactsCommand());\n dump.addCommand(dumpSoftwareCommand());\n program.addCommand(dump);\n\n return program;\n}\n\nexport async function run(argv: string[] = process.argv): Promise<void> {\n await buildProgram().parseAsync(argv);\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,KAAK,UAAU,CAAC,CAAC,YAAY,2BAA2B;CAEhE,QAAQ,WAAW,aAAa,CAAC;CACjC,QAAQ,WAAW,aAAa,CAAC;CACjC,QAAQ,WAAW,YAAY,CAAC;CAGhC,MAAM,OAAO,IAAI,QAAQ,MAAM,CAAC,CAAC,YAAY,+CAA+C;CAC5F,KAAK,WAAW,qBAAqB,CAAC;CACtC,KAAK,WAAW,oBAAoB,CAAC;CACrC,QAAQ,WAAW,IAAI;CAEvB,OAAO;AACT;AAEA,eAAsB,IAAI,OAAiB,QAAQ,MAAqB;CACtE,MAAM,aAAa,CAAC,CAAC,WAAW,IAAI;AACtC"}
@@ -5,11 +5,11 @@ const require_basecmd = require("../shared/basecmd.cjs");
5
5
  let commander = require("commander");
6
6
  let node_child_process = require("node:child_process");
7
7
  let node_path = require("node:path");
8
- node_path = require_runtime.__toESM(node_path);
8
+ node_path = require_runtime.__toESM(node_path, 1);
9
9
  let node_fs = require("node:fs");
10
- node_fs = require_runtime.__toESM(node_fs);
10
+ node_fs = require_runtime.__toESM(node_fs, 1);
11
11
  let node_fs_promises = require("node:fs/promises");
12
- node_fs_promises = require_runtime.__toESM(node_fs_promises);
12
+ node_fs_promises = require_runtime.__toESM(node_fs_promises, 1);
13
13
  //#region src/commands/build.ts
14
14
  function buildCommand() {
15
15
  const cmd = new commander.Command("build").description("build tengo sources into single distributable pack file");
@@ -1 +1 @@
1
- {"version":3,"file":"build.cjs","names":["Command","createLogger","getPackageInfo","compile","fsp","path","fs"],"sources":["../../src/commands/build.ts"],"sourcesContent":["import type { SpawnSyncReturns } from \"node:child_process\";\nimport { spawnSync } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport { compile, savePacks, getPackageInfo } from \"../compiler/main\";\nimport { createLogger } from \"../compiler/util\";\nimport * as opts from \"../shared/basecmd\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type * as winston from \"winston\";\nimport type { TemplatesAndLibs } from \"../compiler/compiler\";\n\nexport default function buildCommand(): Command {\n const cmd = new Command(\"build\").description(\n \"build tengo sources into single distributable pack file\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.CtagsOptions());\n\n cmd.action(async (o) => {\n const flags = {\n \"log-level\": o.logLevel as string,\n \"generate-tags\": o.generateTags as boolean,\n \"tags-file\": o.tagsFile as string,\n \"tags-additional-args\": o.tagsAdditionalArgs as string[],\n };\n const logger = createLogger(flags[\"log-level\"]);\n\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiledDist = compile(logger, packageInfo, \"dist\");\n savePacks(logger, compiledDist, \"dist\");\n logger.info(\"Template Pack build done.\");\n\n // Building TS bindings for templates\n const { dts, cjs, mjs } = generateTsBinding(compiledDist);\n await fsp.writeFile(\"dist/index.d.ts\", dts);\n if (packageInfo.type === \"module\") {\n await fsp.writeFile(\"dist/index.cjs\", cjs);\n await fsp.writeFile(\"dist/index.js\", mjs);\n } else {\n await fsp.writeFile(\"dist/index.js\", cjs);\n await fsp.writeFile(\"dist/index.mjs\", mjs);\n }\n\n mergeTagsEnvs(flags);\n if (flags[\"generate-tags\"]) checkAndGenerateCtags(logger, flags);\n\n logger.info(\"Template Pack build done.\");\n });\n\n return cmd;\n}\n\nfunction generateTsBinding(compiledDist: TemplatesAndLibs) {\n let dts = `declare type TemplateFromFile = { readonly type: \"from-file\"; readonly path: string; };\\n`;\n dts += `declare type TplName = ${compiledDist.templates\n .map((tpl) => '\"' + tpl.fullName.id + '\"')\n .join(\" | \")};\\n`;\n dts += `declare const Templates: Record<TplName, TemplateFromFile>;\\n`;\n dts += `export { Templates };\\n`;\n let cjs = `module.exports = { Templates: {\\n`;\n let mjs = `import { resolve } from 'node:path';\\nexport const Templates = {\\n`;\n const recordsCjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n const recordsMjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n cjs += recordsCjs;\n mjs += recordsMjs;\n cjs += `\\n}};\\n`;\n mjs += `\\n};\\n`;\n\n return { dts, cjs, mjs };\n}\n\nfunction mergeTagsEnvs(flags: {\n \"generate-tags\": boolean;\n \"tags-file\": string;\n \"tags-additional-args\": string[] | string;\n}) {\n if (process.env.GENERATE_TAGS != undefined) {\n flags[\"generate-tags\"] = process.env.GENERATE_TAGS == \"true\";\n }\n\n if (process.env.TAGS_FILE != undefined) {\n flags[\"tags-file\"] = process.env.TAGS_FILE;\n }\n\n if (process.env.TAGS_ADDITIONAL_ARGS != undefined) {\n flags[\"tags-additional-args\"] = process.env.TAGS_ADDITIONAL_ARGS.split(\",\");\n }\n}\n\nfunction checkAndGenerateCtags(\n logger: winston.Logger,\n flags: {\n \"tags-file\": string;\n \"tags-additional-args\": string[];\n },\n) {\n const fileName = path.resolve(flags[\"tags-file\"]);\n const rootDir = path.dirname(fileName);\n const additionalArgs = flags[\"tags-additional-args\"];\n\n // all tengo files in dirs and subdirs\n // If we don't limit the depth, it could become unbearably slow\n // and even OOM killed node js.\n // Increase the depth if you need to.\n const tengoFiles = toRelativePath(rootDir, getTengoFiles(rootDir, 9));\n\n logger.info(\n `Generating tags for tengo autocompletion from \"${rootDir}\" \\\nin \"${fileName}\", additional arguments: \"${additionalArgs.join('\" \"')}\".\nFound ${tengoFiles.length} tengo files...`,\n );\n\n // see https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#perl-pod\n const result = spawnSync(\n \"ctags\",\n [\n \"-f\",\n fileName,\n ...additionalArgs,\n \"--langdef=tengo\",\n \"--map-tengo=+.tengo\",\n \"--kinddef-tengo=f,function,function\",\n \"--regex-tengo=/^\\\\s*(.*)(:| :=| =) ?func.*/\\\\1/f/\",\n \"--kinddef-tengo=c,constant,constant\",\n '--regex-tengo=/^\\\\s*(.*) := (\"|\\\\{).*/\\\\1/c/',\n \"-R\",\n ...tengoFiles,\n ],\n {\n env: process.env,\n stdio: \"inherit\",\n cwd: rootDir,\n },\n );\n\n if (result.error?.message.includes(\"ENOENT\")) {\n console.log(`\npl-tengo can create tags for tengo autocompletion,\nbut the program should be installed\nwith \"brew install universal-ctags\" on OSX\nor \"sudo apt install universal-ctags\" on Ubuntu.\n\nFor vscode, you should also install ctags extension:\nhttps://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);\n\n return;\n }\n\n checkRunError(result, \"failed to generate ctags\");\n\n logger.info(\"Generation of tags is done.\");\n}\n\nfunction getTengoFiles(dir: string, depth: number): string[] {\n if (depth === 0) {\n return [];\n }\n\n const files = fs.readdirSync(dir, { withFileTypes: true });\n\n let tengoFiles: string[] = [];\n files.forEach((file) => {\n const absPath = path.join(dir, file.name);\n\n if (file.isDirectory()) {\n tengoFiles = tengoFiles.concat(getTengoFiles(absPath, depth - 1));\n }\n\n if (!file.isDirectory() && file.name.endsWith(\".tengo\")) {\n tengoFiles.push(absPath);\n }\n });\n\n return tengoFiles;\n}\n\nfunction toRelativePath(dir: string, files: string[]): string[] {\n // Note that VS Code extension likes only relatives paths to the root of the opened dir.\n return files.map((file) => file.replace(dir, \".\"));\n}\n\nfunction checkRunError(result: SpawnSyncReturns<Buffer>, message?: string) {\n if (result.error) {\n console.log(result.error);\n }\n\n const msg = message ?? \"failed to run command\";\n\n if (result.status !== 0) {\n console.log(`WARN: ${msg} the build will continue as-is`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAwB,eAAwB;CAC9C,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AS;EACtB,MAAM,UAAUD,UAAK,KAAK,KAAK,KAAK,KAAK;AAEzC,MAAI,KAAK,aAAa,CACpB,cAAa,WAAW,OAAO,cAAc,SAAS,QAAQ,EAAE,CAAC;AAGnE,MAAI,CAAC,KAAK,aAAa,IAAI,KAAK,KAAK,SAAS,SAAS,CACrD,YAAW,KAAK,QAAQ;GAE1B;AAEF,QAAO;;AAGT,SAAS,eAAe,KAAa,OAA2B;AAE9D,QAAO,MAAM,KAAK,SAAS,KAAK,QAAQ,KAAK,IAAI,CAAC;;AAGpD,SAAS,cAAc,QAAkC,SAAkB;AACzE,KAAI,OAAO,MACT,SAAQ,IAAI,OAAO,MAAM;CAG3B,MAAM,MAAM,WAAW;AAEvB,KAAI,OAAO,WAAW,EACpB,SAAQ,IAAI,SAAS,IAAI,gCAAgC"}
1
+ {"version":3,"file":"build.cjs","names":["Command","createLogger","getPackageInfo","compile","fsp","path","fs"],"sources":["../../src/commands/build.ts"],"sourcesContent":["import type { SpawnSyncReturns } from \"node:child_process\";\nimport { spawnSync } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport { compile, savePacks, getPackageInfo } from \"../compiler/main\";\nimport { createLogger } from \"../compiler/util\";\nimport * as opts from \"../shared/basecmd\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type * as winston from \"winston\";\nimport type { TemplatesAndLibs } from \"../compiler/compiler\";\n\nexport default function buildCommand(): Command {\n const cmd = new Command(\"build\").description(\n \"build tengo sources into single distributable pack file\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.CtagsOptions());\n\n cmd.action(async (o) => {\n const flags = {\n \"log-level\": o.logLevel as string,\n \"generate-tags\": o.generateTags as boolean,\n \"tags-file\": o.tagsFile as string,\n \"tags-additional-args\": o.tagsAdditionalArgs as string[],\n };\n const logger = createLogger(flags[\"log-level\"]);\n\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiledDist = compile(logger, packageInfo, \"dist\");\n savePacks(logger, compiledDist, \"dist\");\n logger.info(\"Template Pack build done.\");\n\n // Building TS bindings for templates\n const { dts, cjs, mjs } = generateTsBinding(compiledDist);\n await fsp.writeFile(\"dist/index.d.ts\", dts);\n if (packageInfo.type === \"module\") {\n await fsp.writeFile(\"dist/index.cjs\", cjs);\n await fsp.writeFile(\"dist/index.js\", mjs);\n } else {\n await fsp.writeFile(\"dist/index.js\", cjs);\n await fsp.writeFile(\"dist/index.mjs\", mjs);\n }\n\n mergeTagsEnvs(flags);\n if (flags[\"generate-tags\"]) checkAndGenerateCtags(logger, flags);\n\n logger.info(\"Template Pack build done.\");\n });\n\n return cmd;\n}\n\nfunction generateTsBinding(compiledDist: TemplatesAndLibs) {\n let dts = `declare type TemplateFromFile = { readonly type: \"from-file\"; readonly path: string; };\\n`;\n dts += `declare type TplName = ${compiledDist.templates\n .map((tpl) => '\"' + tpl.fullName.id + '\"')\n .join(\" | \")};\\n`;\n dts += `declare const Templates: Record<TplName, TemplateFromFile>;\\n`;\n dts += `export { Templates };\\n`;\n let cjs = `module.exports = { Templates: {\\n`;\n let mjs = `import { resolve } from 'node:path';\\nexport const Templates = {\\n`;\n const recordsCjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n const recordsMjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n cjs += recordsCjs;\n mjs += recordsMjs;\n cjs += `\\n}};\\n`;\n mjs += `\\n};\\n`;\n\n return { dts, cjs, mjs };\n}\n\nfunction mergeTagsEnvs(flags: {\n \"generate-tags\": boolean;\n \"tags-file\": string;\n \"tags-additional-args\": string[] | string;\n}) {\n if (process.env.GENERATE_TAGS != undefined) {\n flags[\"generate-tags\"] = process.env.GENERATE_TAGS == \"true\";\n }\n\n if (process.env.TAGS_FILE != undefined) {\n flags[\"tags-file\"] = process.env.TAGS_FILE;\n }\n\n if (process.env.TAGS_ADDITIONAL_ARGS != undefined) {\n flags[\"tags-additional-args\"] = process.env.TAGS_ADDITIONAL_ARGS.split(\",\");\n }\n}\n\nfunction checkAndGenerateCtags(\n logger: winston.Logger,\n flags: {\n \"tags-file\": string;\n \"tags-additional-args\": string[];\n },\n) {\n const fileName = path.resolve(flags[\"tags-file\"]);\n const rootDir = path.dirname(fileName);\n const additionalArgs = flags[\"tags-additional-args\"];\n\n // all tengo files in dirs and subdirs\n // If we don't limit the depth, it could become unbearably slow\n // and even OOM killed node js.\n // Increase the depth if you need to.\n const tengoFiles = toRelativePath(rootDir, getTengoFiles(rootDir, 9));\n\n logger.info(\n `Generating tags for tengo autocompletion from \"${rootDir}\" \\\nin \"${fileName}\", additional arguments: \"${additionalArgs.join('\" \"')}\".\nFound ${tengoFiles.length} tengo files...`,\n );\n\n // see https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#perl-pod\n const result = spawnSync(\n \"ctags\",\n [\n \"-f\",\n fileName,\n ...additionalArgs,\n \"--langdef=tengo\",\n \"--map-tengo=+.tengo\",\n \"--kinddef-tengo=f,function,function\",\n \"--regex-tengo=/^\\\\s*(.*)(:| :=| =) ?func.*/\\\\1/f/\",\n \"--kinddef-tengo=c,constant,constant\",\n '--regex-tengo=/^\\\\s*(.*) := (\"|\\\\{).*/\\\\1/c/',\n \"-R\",\n ...tengoFiles,\n ],\n {\n env: process.env,\n stdio: \"inherit\",\n cwd: rootDir,\n },\n );\n\n if (result.error?.message.includes(\"ENOENT\")) {\n console.log(`\npl-tengo can create tags for tengo autocompletion,\nbut the program should be installed\nwith \"brew install universal-ctags\" on OSX\nor \"sudo apt install universal-ctags\" on Ubuntu.\n\nFor vscode, you should also install ctags extension:\nhttps://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);\n\n return;\n }\n\n checkRunError(result, \"failed to generate ctags\");\n\n logger.info(\"Generation of tags is done.\");\n}\n\nfunction getTengoFiles(dir: string, depth: number): string[] {\n if (depth === 0) {\n return [];\n }\n\n const files = fs.readdirSync(dir, { withFileTypes: true });\n\n let tengoFiles: string[] = [];\n files.forEach((file) => {\n const absPath = path.join(dir, file.name);\n\n if (file.isDirectory()) {\n tengoFiles = tengoFiles.concat(getTengoFiles(absPath, depth - 1));\n }\n\n if (!file.isDirectory() && file.name.endsWith(\".tengo\")) {\n tengoFiles.push(absPath);\n }\n });\n\n return tengoFiles;\n}\n\nfunction toRelativePath(dir: string, files: string[]): string[] {\n // Note that VS Code extension likes only relatives paths to the root of the opened dir.\n return files.map((file) => file.replace(dir, \".\"));\n}\n\nfunction checkRunError(result: SpawnSyncReturns<Buffer>, message?: string) {\n if (result.error) {\n console.log(result.error);\n }\n\n const msg = message ?? \"failed to run command\";\n\n if (result.status !== 0) {\n console.log(`WARN: ${msg} the build will continue as-is`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,OAAO,CAAC,CAAC,YAC/B,yDACF;CAEA,gBAAA,WAAgB,KAAA,gBAAA,cAAwB,GAAA,gBAAA,aAAqB,CAAC;CAE9D,IAAI,OAAO,OAAO,MAAM;EACtB,MAAM,QAAQ;GACZ,aAAa,EAAE;GACf,iBAAiB,EAAE;GACnB,aAAa,EAAE;GACf,wBAAwB,EAAE;EAC5B;EACA,MAAM,SAASC,aAAAA,aAAa,MAAM,YAAY;EAE9C,MAAM,cAAcC,aAAAA,eAAe,QAAQ,IAAI,GAAG,MAAM;EACxD,MAAM,eAAeC,aAAAA,QAAQ,QAAQ,aAAa,MAAM;EACxD,aAAA,UAAU,QAAQ,cAAc,MAAM;EACtC,OAAO,KAAK,2BAA2B;EAGvC,MAAM,EAAE,KAAK,KAAK,QAAQ,kBAAkB,YAAY;EACxD,MAAMC,iBAAI,UAAU,mBAAmB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S,IAAI,+BAA+B;AAE5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","names":["opts.GlobalOptions","opts.CtagsOptions"],"sources":["../../src/commands/build.ts"],"sourcesContent":["import type { SpawnSyncReturns } from \"node:child_process\";\nimport { spawnSync } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport { compile, savePacks, getPackageInfo } from \"../compiler/main\";\nimport { createLogger } from \"../compiler/util\";\nimport * as opts from \"../shared/basecmd\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type * as winston from \"winston\";\nimport type { TemplatesAndLibs } from \"../compiler/compiler\";\n\nexport default function buildCommand(): Command {\n const cmd = new Command(\"build\").description(\n \"build tengo sources into single distributable pack file\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.CtagsOptions());\n\n cmd.action(async (o) => {\n const flags = {\n \"log-level\": o.logLevel as string,\n \"generate-tags\": o.generateTags as boolean,\n \"tags-file\": o.tagsFile as string,\n \"tags-additional-args\": o.tagsAdditionalArgs as string[],\n };\n const logger = createLogger(flags[\"log-level\"]);\n\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiledDist = compile(logger, packageInfo, \"dist\");\n savePacks(logger, compiledDist, \"dist\");\n logger.info(\"Template Pack build done.\");\n\n // Building TS bindings for templates\n const { dts, cjs, mjs } = generateTsBinding(compiledDist);\n await fsp.writeFile(\"dist/index.d.ts\", dts);\n if (packageInfo.type === \"module\") {\n await fsp.writeFile(\"dist/index.cjs\", cjs);\n await fsp.writeFile(\"dist/index.js\", mjs);\n } else {\n await fsp.writeFile(\"dist/index.js\", cjs);\n await fsp.writeFile(\"dist/index.mjs\", mjs);\n }\n\n mergeTagsEnvs(flags);\n if (flags[\"generate-tags\"]) checkAndGenerateCtags(logger, flags);\n\n logger.info(\"Template Pack build done.\");\n });\n\n return cmd;\n}\n\nfunction generateTsBinding(compiledDist: TemplatesAndLibs) {\n let dts = `declare type TemplateFromFile = { readonly type: \"from-file\"; readonly path: string; };\\n`;\n dts += `declare type TplName = ${compiledDist.templates\n .map((tpl) => '\"' + tpl.fullName.id + '\"')\n .join(\" | \")};\\n`;\n dts += `declare const Templates: Record<TplName, TemplateFromFile>;\\n`;\n dts += `export { Templates };\\n`;\n let cjs = `module.exports = { Templates: {\\n`;\n let mjs = `import { resolve } from 'node:path';\\nexport const Templates = {\\n`;\n const recordsCjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n const recordsMjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n cjs += recordsCjs;\n mjs += recordsMjs;\n cjs += `\\n}};\\n`;\n mjs += `\\n};\\n`;\n\n return { dts, cjs, mjs };\n}\n\nfunction mergeTagsEnvs(flags: {\n \"generate-tags\": boolean;\n \"tags-file\": string;\n \"tags-additional-args\": string[] | string;\n}) {\n if (process.env.GENERATE_TAGS != undefined) {\n flags[\"generate-tags\"] = process.env.GENERATE_TAGS == \"true\";\n }\n\n if (process.env.TAGS_FILE != undefined) {\n flags[\"tags-file\"] = process.env.TAGS_FILE;\n }\n\n if (process.env.TAGS_ADDITIONAL_ARGS != undefined) {\n flags[\"tags-additional-args\"] = process.env.TAGS_ADDITIONAL_ARGS.split(\",\");\n }\n}\n\nfunction checkAndGenerateCtags(\n logger: winston.Logger,\n flags: {\n \"tags-file\": string;\n \"tags-additional-args\": string[];\n },\n) {\n const fileName = path.resolve(flags[\"tags-file\"]);\n const rootDir = path.dirname(fileName);\n const additionalArgs = flags[\"tags-additional-args\"];\n\n // all tengo files in dirs and subdirs\n // If we don't limit the depth, it could become unbearably slow\n // and even OOM killed node js.\n // Increase the depth if you need to.\n const tengoFiles = toRelativePath(rootDir, getTengoFiles(rootDir, 9));\n\n logger.info(\n `Generating tags for tengo autocompletion from \"${rootDir}\" \\\nin \"${fileName}\", additional arguments: \"${additionalArgs.join('\" \"')}\".\nFound ${tengoFiles.length} tengo files...`,\n );\n\n // see https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#perl-pod\n const result = spawnSync(\n \"ctags\",\n [\n \"-f\",\n fileName,\n ...additionalArgs,\n \"--langdef=tengo\",\n \"--map-tengo=+.tengo\",\n \"--kinddef-tengo=f,function,function\",\n \"--regex-tengo=/^\\\\s*(.*)(:| :=| =) ?func.*/\\\\1/f/\",\n \"--kinddef-tengo=c,constant,constant\",\n '--regex-tengo=/^\\\\s*(.*) := (\"|\\\\{).*/\\\\1/c/',\n \"-R\",\n ...tengoFiles,\n ],\n {\n env: process.env,\n stdio: \"inherit\",\n cwd: rootDir,\n },\n );\n\n if (result.error?.message.includes(\"ENOENT\")) {\n console.log(`\npl-tengo can create tags for tengo autocompletion,\nbut the program should be installed\nwith \"brew install universal-ctags\" on OSX\nor \"sudo apt install universal-ctags\" on Ubuntu.\n\nFor vscode, you should also install ctags extension:\nhttps://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);\n\n return;\n }\n\n checkRunError(result, \"failed to generate ctags\");\n\n logger.info(\"Generation of tags is done.\");\n}\n\nfunction getTengoFiles(dir: string, depth: number): string[] {\n if (depth === 0) {\n return [];\n }\n\n const files = fs.readdirSync(dir, { withFileTypes: true });\n\n let tengoFiles: string[] = [];\n files.forEach((file) => {\n const absPath = path.join(dir, file.name);\n\n if (file.isDirectory()) {\n tengoFiles = tengoFiles.concat(getTengoFiles(absPath, depth - 1));\n }\n\n if (!file.isDirectory() && file.name.endsWith(\".tengo\")) {\n tengoFiles.push(absPath);\n }\n });\n\n return tengoFiles;\n}\n\nfunction toRelativePath(dir: string, files: string[]): string[] {\n // Note that VS Code extension likes only relatives paths to the root of the opened dir.\n return files.map((file) => file.replace(dir, \".\"));\n}\n\nfunction checkRunError(result: SpawnSyncReturns<Buffer>, message?: string) {\n if (result.error) {\n console.log(result.error);\n }\n\n const msg = message ?? \"failed to run command\";\n\n if (result.status !== 0) {\n console.log(`WARN: ${msg} the build will continue as-is`);\n }\n}\n"],"mappings":";;;;;;;;;AAYA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAI,QAAQ,QAAQ,CAAC,YAC/B,0DACD;AAED,YAAgB,KAAKA,eAAoB,EAAEC,cAAmB,CAAC;AAE/D,KAAI,OAAO,OAAO,MAAM;EACtB,MAAM,QAAQ;GACZ,aAAa,EAAE;GACf,iBAAiB,EAAE;GACnB,aAAa,EAAE;GACf,wBAAwB,EAAE;GAC3B;EACD,MAAM,SAAS,aAAa,MAAM,aAAa;EAE/C,MAAM,cAAc,eAAe,QAAQ,KAAK,EAAE,OAAO;EACzD,MAAM,eAAe,QAAQ,QAAQ,aAAa,OAAO;AACzD,YAAU,QAAQ,cAAc,OAAO;AACvC,SAAO,KAAK,4BAA4B;EAGxC,MAAM,EAAE,KAAK,KAAK,QAAQ,kBAAkB,aAAa;AACzD,QAAM,IAAI,UAAU,mBAAmB,IAAI;AAC3C,MAAI,YAAY,SAAS,UAAU;AACjC,SAAM,IAAI,UAAU,kBAAkB,IAAI;AAC1C,SAAM,IAAI,UAAU,iBAAiB,IAAI;SACpC;AACL,SAAM,IAAI,UAAU,iBAAiB,IAAI;AACzC,SAAM,IAAI,UAAU,kBAAkB,IAAI;;AAG5C,gBAAc,MAAM;AACpB,MAAI,MAAM,iBAAkB,uBAAsB,QAAQ,MAAM;AAEhE,SAAO,KAAK,4BAA4B;GACxC;AAEF,QAAO;;AAGT,SAAS,kBAAkB,cAAgC;CACzD,IAAI,MAAM;AACV,QAAO,0BAA0B,aAAa,UAC3C,KAAK,QAAQ,OAAM,IAAI,SAAS,KAAK,KAAI,CACzC,KAAK,MAAM,CAAC;AACf,QAAO;AACP,QAAO;CACP,IAAI,MAAM;CACV,IAAI,MAAM;CACV,MAAM,aAAa,aAAa,UAC7B,KACE,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,GAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC;CAE1D,IAAI,aAAuB,EAAE;AAC7B,OAAM,SAAS,SAAS;EACtB,MAAM,UAAU,KAAK,KAAK,KAAK,KAAK,KAAK;AAEzC,MAAI,KAAK,aAAa,CACpB,cAAa,WAAW,OAAO,cAAc,SAAS,QAAQ,EAAE,CAAC;AAGnE,MAAI,CAAC,KAAK,aAAa,IAAI,KAAK,KAAK,SAAS,SAAS,CACrD,YAAW,KAAK,QAAQ;GAE1B;AAEF,QAAO;;AAGT,SAAS,eAAe,KAAa,OAA2B;AAE9D,QAAO,MAAM,KAAK,SAAS,KAAK,QAAQ,KAAK,IAAI,CAAC;;AAGpD,SAAS,cAAc,QAAkC,SAAkB;AACzE,KAAI,OAAO,MACT,SAAQ,IAAI,OAAO,MAAM;CAG3B,MAAM,MAAM,WAAW;AAEvB,KAAI,OAAO,WAAW,EACpB,SAAQ,IAAI,SAAS,IAAI,gCAAgC"}
1
+ {"version":3,"file":"build.js","names":["opts.GlobalOptions","opts.CtagsOptions"],"sources":["../../src/commands/build.ts"],"sourcesContent":["import type { SpawnSyncReturns } from \"node:child_process\";\nimport { spawnSync } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport { compile, savePacks, getPackageInfo } from \"../compiler/main\";\nimport { createLogger } from \"../compiler/util\";\nimport * as opts from \"../shared/basecmd\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type * as winston from \"winston\";\nimport type { TemplatesAndLibs } from \"../compiler/compiler\";\n\nexport default function buildCommand(): Command {\n const cmd = new Command(\"build\").description(\n \"build tengo sources into single distributable pack file\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.CtagsOptions());\n\n cmd.action(async (o) => {\n const flags = {\n \"log-level\": o.logLevel as string,\n \"generate-tags\": o.generateTags as boolean,\n \"tags-file\": o.tagsFile as string,\n \"tags-additional-args\": o.tagsAdditionalArgs as string[],\n };\n const logger = createLogger(flags[\"log-level\"]);\n\n const packageInfo = getPackageInfo(process.cwd(), logger);\n const compiledDist = compile(logger, packageInfo, \"dist\");\n savePacks(logger, compiledDist, \"dist\");\n logger.info(\"Template Pack build done.\");\n\n // Building TS bindings for templates\n const { dts, cjs, mjs } = generateTsBinding(compiledDist);\n await fsp.writeFile(\"dist/index.d.ts\", dts);\n if (packageInfo.type === \"module\") {\n await fsp.writeFile(\"dist/index.cjs\", cjs);\n await fsp.writeFile(\"dist/index.js\", mjs);\n } else {\n await fsp.writeFile(\"dist/index.js\", cjs);\n await fsp.writeFile(\"dist/index.mjs\", mjs);\n }\n\n mergeTagsEnvs(flags);\n if (flags[\"generate-tags\"]) checkAndGenerateCtags(logger, flags);\n\n logger.info(\"Template Pack build done.\");\n });\n\n return cmd;\n}\n\nfunction generateTsBinding(compiledDist: TemplatesAndLibs) {\n let dts = `declare type TemplateFromFile = { readonly type: \"from-file\"; readonly path: string; };\\n`;\n dts += `declare type TplName = ${compiledDist.templates\n .map((tpl) => '\"' + tpl.fullName.id + '\"')\n .join(\" | \")};\\n`;\n dts += `declare const Templates: Record<TplName, TemplateFromFile>;\\n`;\n dts += `export { Templates };\\n`;\n let cjs = `module.exports = { Templates: {\\n`;\n let mjs = `import { resolve } from 'node:path';\\nexport const Templates = {\\n`;\n const recordsCjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n const recordsMjs = compiledDist.templates\n .map(\n (tpl) =>\n ` '${tpl.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${tpl.fullName.id}.plj.gz') }`,\n )\n .join(\",\\n\");\n cjs += recordsCjs;\n mjs += recordsMjs;\n cjs += `\\n}};\\n`;\n mjs += `\\n};\\n`;\n\n return { dts, cjs, mjs };\n}\n\nfunction mergeTagsEnvs(flags: {\n \"generate-tags\": boolean;\n \"tags-file\": string;\n \"tags-additional-args\": string[] | string;\n}) {\n if (process.env.GENERATE_TAGS != undefined) {\n flags[\"generate-tags\"] = process.env.GENERATE_TAGS == \"true\";\n }\n\n if (process.env.TAGS_FILE != undefined) {\n flags[\"tags-file\"] = process.env.TAGS_FILE;\n }\n\n if (process.env.TAGS_ADDITIONAL_ARGS != undefined) {\n flags[\"tags-additional-args\"] = process.env.TAGS_ADDITIONAL_ARGS.split(\",\");\n }\n}\n\nfunction checkAndGenerateCtags(\n logger: winston.Logger,\n flags: {\n \"tags-file\": string;\n \"tags-additional-args\": string[];\n },\n) {\n const fileName = path.resolve(flags[\"tags-file\"]);\n const rootDir = path.dirname(fileName);\n const additionalArgs = flags[\"tags-additional-args\"];\n\n // all tengo files in dirs and subdirs\n // If we don't limit the depth, it could become unbearably slow\n // and even OOM killed node js.\n // Increase the depth if you need to.\n const tengoFiles = toRelativePath(rootDir, getTengoFiles(rootDir, 9));\n\n logger.info(\n `Generating tags for tengo autocompletion from \"${rootDir}\" \\\nin \"${fileName}\", additional arguments: \"${additionalArgs.join('\" \"')}\".\nFound ${tengoFiles.length} tengo files...`,\n );\n\n // see https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#perl-pod\n const result = spawnSync(\n \"ctags\",\n [\n \"-f\",\n fileName,\n ...additionalArgs,\n \"--langdef=tengo\",\n \"--map-tengo=+.tengo\",\n \"--kinddef-tengo=f,function,function\",\n \"--regex-tengo=/^\\\\s*(.*)(:| :=| =) ?func.*/\\\\1/f/\",\n \"--kinddef-tengo=c,constant,constant\",\n '--regex-tengo=/^\\\\s*(.*) := (\"|\\\\{).*/\\\\1/c/',\n \"-R\",\n ...tengoFiles,\n ],\n {\n env: process.env,\n stdio: \"inherit\",\n cwd: rootDir,\n },\n );\n\n if (result.error?.message.includes(\"ENOENT\")) {\n console.log(`\npl-tengo can create tags for tengo autocompletion,\nbut the program should be installed\nwith \"brew install universal-ctags\" on OSX\nor \"sudo apt install universal-ctags\" on Ubuntu.\n\nFor vscode, you should also install ctags extension:\nhttps://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);\n\n return;\n }\n\n checkRunError(result, \"failed to generate ctags\");\n\n logger.info(\"Generation of tags is done.\");\n}\n\nfunction getTengoFiles(dir: string, depth: number): string[] {\n if (depth === 0) {\n return [];\n }\n\n const files = fs.readdirSync(dir, { withFileTypes: true });\n\n let tengoFiles: string[] = [];\n files.forEach((file) => {\n const absPath = path.join(dir, file.name);\n\n if (file.isDirectory()) {\n tengoFiles = tengoFiles.concat(getTengoFiles(absPath, depth - 1));\n }\n\n if (!file.isDirectory() && file.name.endsWith(\".tengo\")) {\n tengoFiles.push(absPath);\n }\n });\n\n return tengoFiles;\n}\n\nfunction toRelativePath(dir: string, files: string[]): string[] {\n // Note that VS Code extension likes only relatives paths to the root of the opened dir.\n return files.map((file) => file.replace(dir, \".\"));\n}\n\nfunction checkRunError(result: SpawnSyncReturns<Buffer>, message?: string) {\n if (result.error) {\n console.log(result.error);\n }\n\n const msg = message ?? \"failed to run command\";\n\n if (result.status !== 0) {\n console.log(`WARN: ${msg} the build will continue as-is`);\n }\n}\n"],"mappings":";;;;;;;;;AAYA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAI,QAAQ,OAAO,CAAC,CAAC,YAC/B,yDACF;CAEA,WAAgB,KAAKA,cAAmB,GAAGC,aAAkB,CAAC;CAE9D,IAAI,OAAO,OAAO,MAAM;EACtB,MAAM,QAAQ;GACZ,aAAa,EAAE;GACf,iBAAiB,EAAE;GACnB,aAAa,EAAE;GACf,wBAAwB,EAAE;EAC5B;EACA,MAAM,SAAS,aAAa,MAAM,YAAY;EAE9C,MAAM,cAAc,eAAe,QAAQ,IAAI,GAAG,MAAM;EACxD,MAAM,eAAe,QAAQ,QAAQ,aAAa,MAAM;EACxD,UAAU,QAAQ,cAAc,MAAM;EACtC,OAAO,KAAK,2BAA2B;EAGvC,MAAM,EAAE,KAAK,KAAK,QAAQ,kBAAkB,YAAY;EACxD,MAAM,IAA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AE5D"}
@@ -1,4 +1,3 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("../compiler/util.cjs");
3
2
  const require_basecmd = require("../shared/basecmd.cjs");
4
3
  const require_dump = require("../shared/dump.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"check.cjs","names":["Command","GlobalOptions","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/check.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function checkCommand(): Command {\n const cmd = new Command(\"check\").description(\"check tengo sources for language processor an\");\n\n cmd.argument(\"[paths...]\", \"source paths to check (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"check\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;;AAOA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,QAAQ,CAAC,YAAY,gDAAgD;AAE7F,KAAI,SAAS,cAAc,4CAA4C;AACvE,iBAAA,WAAW,KAAKC,gBAAAA,eAAe,CAAC;AAEhC,KAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAASC,aAAAA,aAAa,SAAS;EAIrC,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,SACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,QAAQ,GAAG,MAU5D;AAED,MAAI;AACF,gBAAA,cAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK;;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"check.cjs","names":["Command","GlobalOptions","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/check.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function checkCommand(): Command {\n const cmd = new Command(\"check\").description(\"check tengo sources for language processor an\");\n\n cmd.argument(\"[paths...]\", \"source paths to check (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"check\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,OAAO,CAAC,CAAC,YAAY,+CAA+C;CAE5F,IAAI,SAAS,cAAc,2CAA2C;CACtE,gBAAA,WAAW,KAAKC,gBAAAA,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAASC,aAAAA,aAAa,QAAQ;EAIpC,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,SACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,aAAA,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"check.js","names":[],"sources":["../../src/commands/check.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function checkCommand(): Command {\n const cmd = new Command(\"check\").description(\"check tengo sources for language processor an\");\n\n cmd.argument(\"[paths...]\", \"source paths to check (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"check\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAI,QAAQ,QAAQ,CAAC,YAAY,gDAAgD;AAE7F,KAAI,SAAS,cAAc,4CAA4C;AACvE,YAAW,KAAK,eAAe,CAAC;AAEhC,KAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAAS,aAAa,SAAS;EAIrC,MAAM,SAAS,WACb,uBACA,SACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,QAAQ,GAAG,MAU5D;AAED,MAAI;AACF,iBAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAM,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK;;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"check.js","names":[],"sources":["../../src/commands/check.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function checkCommand(): Command {\n const cmd = new Command(\"check\").description(\"check tengo sources for language processor an\");\n\n cmd.argument(\"[paths...]\", \"source paths to check (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"check\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,eAAwB;CAC9C,MAAM,MAAM,IAAI,QAAQ,OAAO,CAAC,CAAC,YAAY,+CAA+C;CAE5F,IAAI,SAAS,cAAc,2CAA2C;CACtE,WAAW,KAAK,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAAS,aAAa,QAAQ;EAIpC,MAAM,SAAS,WACb,uBACA,SACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAM,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -1,4 +1,3 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("../../compiler/util.cjs");
3
2
  const require_basecmd = require("../../shared/basecmd.cjs");
4
3
  const require_dump = require("../../shared/dump.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"artifacts.cjs","names":["Command","createLogger","stdout"],"sources":["../../../src/commands/dump/artifacts.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpArtifacts } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport type { ArtifactType } from \"../../compiler/package\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpArtifactsCommand(): Command {\n const cmd = new Command(\"artifacts\").description(\n \"parse sources in current package and dump all found artifacts to stdout\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.ArtifactTypeOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpArtifacts(logger, stdout, o.type == \"all\" ? undefined : (o.type as ArtifactType));\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,uBAAgC;CACtD,MAAM,MAAM,IAAIA,UAAAA,QAAQ,YAAY,CAAC,YACnC,0EACD;AAED,iBAAA,WAAgB,KAAA,gBAAA,eAAyB,EAAA,gBAAA,qBAA4B,CAAC;AAEtE,KAAI,OAAO,OAAO,MAAM;AAEtB,eAAA,cADeC,aAAAA,aAAa,EAAE,SAAmB,EAC3BC,aAAAA,QAAQ,EAAE,QAAQ,QAAQ,KAAA,IAAa,EAAE,KAAsB;GACrF;AAEF,QAAO"}
1
+ {"version":3,"file":"artifacts.cjs","names":["Command","createLogger","stdout"],"sources":["../../../src/commands/dump/artifacts.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpArtifacts } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport type { ArtifactType } from \"../../compiler/package\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpArtifactsCommand(): Command {\n const cmd = new Command(\"artifacts\").description(\n \"parse sources in current package and dump all found artifacts to stdout\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.ArtifactTypeOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpArtifacts(logger, stdout, o.type == \"all\" ? undefined : (o.type as ArtifactType));\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAOA,SAAwB,uBAAgC;CACtD,MAAM,MAAM,IAAIA,UAAAA,QAAQ,WAAW,CAAC,CAAC,YACnC,yEACF;CAEA,gBAAA,WAAgB,KAAA,gBAAA,cAAwB,GAAA,gBAAA,oBAA4B,CAAC;CAErE,IAAI,OAAO,OAAO,MAAM;EAEtB,aAAA,cADeC,aAAAA,aAAa,EAAE,QACX,GAAGC,aAAAA,QAAQ,EAAE,QAAQ,QAAQ,KAAA,IAAa,EAAE,IAAqB;CACtF,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"artifacts.js","names":["opts.GlobalOptions","opts.ArtifactTypeOptions"],"sources":["../../../src/commands/dump/artifacts.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpArtifacts } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport type { ArtifactType } from \"../../compiler/package\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpArtifactsCommand(): Command {\n const cmd = new Command(\"artifacts\").description(\n \"parse sources in current package and dump all found artifacts to stdout\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.ArtifactTypeOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpArtifacts(logger, stdout, o.type == \"all\" ? undefined : (o.type as ArtifactType));\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAOA,SAAwB,uBAAgC;CACtD,MAAM,MAAM,IAAI,QAAQ,YAAY,CAAC,YACnC,0EACD;AAED,YAAgB,KAAKA,eAAoB,EAAEC,qBAA0B,CAAC;AAEtE,KAAI,OAAO,OAAO,MAAM;AAEtB,gBADe,aAAa,EAAE,SAAmB,EAC3B,QAAQ,EAAE,QAAQ,QAAQ,KAAA,IAAa,EAAE,KAAsB;GACrF;AAEF,QAAO"}
1
+ {"version":3,"file":"artifacts.js","names":["opts.GlobalOptions","opts.ArtifactTypeOptions"],"sources":["../../../src/commands/dump/artifacts.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpArtifacts } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport type { ArtifactType } from \"../../compiler/package\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpArtifactsCommand(): Command {\n const cmd = new Command(\"artifacts\").description(\n \"parse sources in current package and dump all found artifacts to stdout\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions(), opts.ArtifactTypeOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpArtifacts(logger, stdout, o.type == \"all\" ? undefined : (o.type as ArtifactType));\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAOA,SAAwB,uBAAgC;CACtD,MAAM,MAAM,IAAI,QAAQ,WAAW,CAAC,CAAC,YACnC,yEACF;CAEA,WAAgB,KAAKA,cAAmB,GAAGC,oBAAyB,CAAC;CAErE,IAAI,OAAO,OAAO,MAAM;EAEtB,cADe,aAAa,EAAE,QACX,GAAG,QAAQ,EAAE,QAAQ,QAAQ,KAAA,IAAa,EAAE,IAAqB;CACtF,CAAC;CAED,OAAO;AACT"}
@@ -1,4 +1,3 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("../../compiler/util.cjs");
3
2
  const require_basecmd = require("../../shared/basecmd.cjs");
4
3
  const require_dump = require("../../shared/dump.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"software.cjs","names":["Command","createLogger","stdout"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpSoftwareCommand(): Command {\n const cmd = new Command(\"software\").description(\n \"parse sources in current package and dump all software descriptors used by templates\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpSoftware(logger, stdout);\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAMA,SAAwB,sBAA+B;CACrD,MAAM,MAAM,IAAIA,UAAAA,QAAQ,WAAW,CAAC,YAClC,uFACD;AAED,iBAAA,WAAgB,KAAA,gBAAA,eAAyB,CAAC;AAE1C,KAAI,OAAO,OAAO,MAAM;AAEtB,eAAA,aADeC,aAAAA,aAAa,EAAE,SAAmB,EAC5BC,aAAAA,OAAO;GAC5B;AAEF,QAAO"}
1
+ {"version":3,"file":"software.cjs","names":["Command","createLogger","stdout"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpSoftwareCommand(): Command {\n const cmd = new Command(\"software\").description(\n \"parse sources in current package and dump all software descriptors used by templates\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpSoftware(logger, stdout);\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAMA,SAAwB,sBAA+B;CACrD,MAAM,MAAM,IAAIA,UAAAA,QAAQ,UAAU,CAAC,CAAC,YAClC,sFACF;CAEA,gBAAA,WAAgB,KAAA,gBAAA,cAAwB,CAAC;CAEzC,IAAI,OAAO,OAAO,MAAM;EAEtB,aAAA,aADeC,aAAAA,aAAa,EAAE,QACZ,GAAGC,aAAAA,MAAM;CAC7B,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"software.js","names":["opts.GlobalOptions"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpSoftwareCommand(): Command {\n const cmd = new Command(\"software\").description(\n \"parse sources in current package and dump all software descriptors used by templates\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpSoftware(logger, stdout);\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAMA,SAAwB,sBAA+B;CACrD,MAAM,MAAM,IAAI,QAAQ,WAAW,CAAC,YAClC,uFACD;AAED,YAAgB,KAAKA,eAAoB,CAAC;AAE1C,KAAI,OAAO,OAAO,MAAM;AAEtB,eADe,aAAa,EAAE,SAAmB,EAC5B,OAAO;GAC5B;AAEF,QAAO"}
1
+ {"version":3,"file":"software.js","names":["opts.GlobalOptions"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpSoftwareCommand(): Command {\n const cmd = new Command(\"software\").description(\n \"parse sources in current package and dump all software descriptors used by templates\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpSoftware(logger, stdout);\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAMA,SAAwB,sBAA+B;CACrD,MAAM,MAAM,IAAI,QAAQ,UAAU,CAAC,CAAC,YAClC,sFACF;CAEA,WAAgB,KAAKA,cAAmB,CAAC;CAEzC,IAAI,OAAO,OAAO,MAAM;EAEtB,aADe,aAAa,EAAE,QACZ,GAAG,MAAM;CAC7B,CAAC;CAED,OAAO;AACT"}
@@ -1,4 +1,3 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("../compiler/util.cjs");
3
2
  const require_basecmd = require("../shared/basecmd.cjs");
4
3
  const require_dump = require("../shared/dump.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"test.cjs","names":["Command","GlobalOptions","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,OAAO,CAAC,YAAY,qCAAqC;AAEjF,KAAI,SAAS,cAAc,2CAA2C;AACtE,iBAAA,WAAW,KAAKC,gBAAAA,eAAe,CAAC;AAEhC,KAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAASC,aAAAA,aAAa,SAAS;EAIrC,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,QAAQ,GAAG,MAU5D;AAED,MAAI;AACF,gBAAA,cAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK;;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"test.cjs","names":["Command","GlobalOptions","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,MAAM,CAAC,CAAC,YAAY,oCAAoC;CAEhF,IAAI,SAAS,cAAc,0CAA0C;CACrE,gBAAA,WAAW,KAAKC,gBAAAA,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAASC,aAAAA,aAAa,QAAQ;EAIpC,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,aAAA,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","names":[],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAI,QAAQ,OAAO,CAAC,YAAY,qCAAqC;AAEjF,KAAI,SAAS,cAAc,2CAA2C;AACtE,YAAW,KAAK,eAAe,CAAC;AAEhC,KAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAAS,aAAa,SAAS;EAIrC,MAAM,SAAS,WACb,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,QAAQ,GAAG,MAU5D;AAED,MAAI;AACF,iBAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAM,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK;;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"test.js","names":[],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAI,QAAQ,MAAM,CAAC,CAAC,YAAY,oCAAoC;CAEhF,IAAI,SAAS,cAAc,0CAA0C;CACrE,WAAW,KAAK,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAAS,aAAa,QAAQ;EAIpC,MAAM,SAAS,WACb,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAM,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -2,6 +2,7 @@ const require_util = require("./util.cjs");
2
2
  const require_package = require("./package.cjs");
3
3
  //#region src/compiler/artifactset.ts
4
4
  var ArtifactMap = class {
5
+ nameExtractor;
5
6
  map = /* @__PURE__ */ new Map();
6
7
  constructor(nameExtractor) {
7
8
  this.nameExtractor = nameExtractor;
@@ -59,6 +60,7 @@ var ArtifactStore = class {
59
60
  }
60
61
  };
61
62
  //#endregion
63
+ exports.ArtifactMap = ArtifactMap;
62
64
  exports.ArtifactStore = ArtifactStore;
63
65
  exports.createArtifactNameSet = createArtifactNameSet;
64
66
 
@@ -1 +1 @@
1
- {"version":3,"file":"artifactset.cjs","names":["artifactKey"],"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,MAAMA,gBAAAA,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,IAAIA,gBAAAA,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,cAAA,YAAY,KAAK;;;CAIvB,IAAI,MAAmB,MAAwC;AAC7D,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK;GAE5B,QACE,cAAA,YAAY,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
+ {"version":3,"file":"artifactset.cjs","names":["artifactKey"],"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;CAGG;CAF7B,sBAAuB,IAAI,IAAe;CAE1C,YAAY,eAA+D;EAA9C,KAAA,gBAAA;CAA+C;CAE5E,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAMA,gBAAAA,YAAY,KAAK,cAAc,GAAG,CAAC;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,GAAG;EAC5B,IAAI,OAAO,CAAC,SAAS,OAAO;EAC5B,KAAK,IAAI,IAAI,KAAK,GAAG;EACrB,OAAO;CACT;CAEA,IAAI,MAAwC;EAC1C,OAAO,KAAK,IAAI,IAAIA,gBAAAA,YAAY,IAAI,CAAC;CACvC;CAEA,IAAI,QAAa;EACf,MAAM,MAAW,CAAC;EAClB,KAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,GAAG,CAAC;EACvC,OAAO;CACT;CAEA,QAAQ,UAAsD;EAC5D,KAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC;CAC5D;AACF;AAEA,SAAgB,wBAAwD;CACtE,OAAO,IAAI,aAAgC,QAAQ,GAAG;AACxD;;;;;AAMA,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;EAExD,KAAK,OAAO,IAAI,YAAe,aAAa;CAC9C;CAEA,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;EACrE,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,KAAK,OAAO;GAEnC,SACE,aAAA,YAAY,IAAI;EACpB;CACF;CAEA,IAAI,MAAmB,MAAwC;EAC7D,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,IAAI;GAE3B,SACE,aAAA,YAAY,IAAI;EACpB;CACF;CAEA,MAAM,MAAwB;EAC5B,MAAM,MAAW,CAAC;EAClB,KAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,GAAG,CAAC;EACzC,OAAO;CACT;CAEA,QAAQ,MAAmB,UAAsD;EAC/E,KAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;CACrE;AACF"}
@@ -2,6 +2,7 @@ import { assertNever } from "./util.js";
2
2
  import { artifactKey } from "./package.js";
3
3
  //#region src/compiler/artifactset.ts
4
4
  var ArtifactMap = class {
5
+ nameExtractor;
5
6
  map = /* @__PURE__ */ new Map();
6
7
  constructor(nameExtractor) {
7
8
  this.nameExtractor = nameExtractor;
@@ -59,6 +60,6 @@ var ArtifactStore = class {
59
60
  }
60
61
  };
61
62
  //#endregion
62
- export { ArtifactStore, createArtifactNameSet };
63
+ export { ArtifactMap, ArtifactStore, createArtifactNameSet };
63
64
 
64
65
  //# 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":";;;AAIA,IAAa,cAAb,MAA4B;CAC1B,sBAA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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) ?? ob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EAC/E,KAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;CACrE;AACF"}
@@ -12,6 +12,7 @@ function addRequiredCapability(template, capability) {
12
12
  if (!template.requiredCapabilities.includes(capability)) template.requiredCapabilities.push(capability);
13
13
  }
14
14
  var TengoTemplateCompiler = class {
15
+ compileMode;
15
16
  libs = new require_artifactset.ArtifactStore((src) => src.fullName);
16
17
  software = new require_artifactset.ArtifactStore((src) => src.fullName);
17
18
  assets = new require_artifactset.ArtifactStore((src) => src.fullName);
@@ -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 {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = 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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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 addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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":";;;;;;;;;AAwBA,SAAS,sBAAsB,U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,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
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 {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = 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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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 addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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":";;;;;;;;;AAwBA,SAAS,sBAAsB,UAA0B,YAAqC;CAC5F,SAAS,uBAAuB,SAAS,wBAAwB,CAAC;CAClE,IAAI,CAAC,SAAS,qBAAqB,SAAS,UAAU,GACpD,SAAS,qBAAqB,KAAK,UAAU;AAEjD;AAWA,IAAa,wBAAb,MAAmC;CAOJ;CAN7B,OAAwB,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,QAAQ;CAC/E,WAA4B,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,QAAQ;CACnF,SAA0B,IAAIA,oBAAAA,eAA+B,Q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}
@@ -12,6 +12,7 @@ function addRequiredCapability(template, capability) {
12
12
  if (!template.requiredCapabilities.includes(capability)) template.requiredCapabilities.push(capability);
13
13
  }
14
14
  var TengoTemplateCompiler = class {
15
+ compileMode;
15
16
  libs = new ArtifactStore((src) => src.fullName);
16
17
  software = new ArtifactStore((src) => src.fullName);
17
18
  assets = new ArtifactStore((src) => src.fullName);