@platforma-sdk/tengo-builder 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -425,9 +425,9 @@ ${i.err.message}`;
425
425
  }
426
426
  const pe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (s, e) => new RegExp(
427
427
  `\\b${s}\\.(?<fnCall>(?<fnName>` + e + ')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'
428
- ), _e = (s) => R(s, "getTemplateId"), qe = (s) => R(s, "getSoftwareInfo"), ue = (s) => R(s, "importTemplate"), me = (s) => R(s, "importSoftware"), Be = (s) => R(s, "importAsset"), Ve = /^\s*$/, Ze = /^\/\/tengo:[\w]/, Ke = /^\s*\/\/\s*tengo:\s*./, Xe = /^\s*(\/\/)|(\/\*.*\*\/)/, Ye = /^\s*\/\*/, He = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, Qe = new RegExp(
428
+ ), _e = (s) => R(s, "getTemplateId"), qe = (s) => R(s, "getSoftwareInfo"), ue = (s) => R(s, "importTemplate"), me = (s) => R(s, "importSoftware"), Be = (s) => R(s, "importAsset"), Ve = /^\s*$/, Ze = /^\/\/tengo:[\w]/, Ke = /^\s*\/\/\s*tengo:\s*./, Xe = /\/\*.*?\*\//g, Ye = /^\s*(\/\/)/, He = /^\s*\/\*/, Qe = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, et = new RegExp(
429
429
  `\\b(?<importName>${pe}(\\.${pe})*)${be.source}`
430
- ), et = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, tt = (s) => {
430
+ ), tt = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, st = (s) => {
431
431
  const e = s.split(" "), t = e[0].split(":");
432
432
  if (t.length != 2)
433
433
  throw new Error(
@@ -444,10 +444,10 @@ class oe {
444
444
  }
445
445
  }
446
446
  function ve(s, e, t, r, n) {
447
- const o = Me(t).toString(), { deps: i, normalized: a, opts: c } = st(s, o, r, n);
447
+ const o = Me(t).toString(), { deps: i, normalized: a, opts: c } = ot(s, o, r, n);
448
448
  return new oe(e, r, a, t, i.array, c);
449
449
  }
450
- function st(s, e, t, r) {
450
+ function ot(s, e, t, r) {
451
451
  const n = Ue(), o = [], i = e.split(`
452
452
  `), a = [];
453
453
  let c = {
@@ -459,7 +459,7 @@ function st(s, e, t, r) {
459
459
  for (const u of i) {
460
460
  c.lineNo++;
461
461
  try {
462
- const d = ot(
462
+ const d = rt(
463
463
  s,
464
464
  u,
465
465
  c,
@@ -469,8 +469,8 @@ function st(s, e, t, r) {
469
469
  a.push(d.line), c = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
470
470
  } catch (d) {
471
471
  const w = d;
472
- throw new Error(`[line ${c.lineNo}]: ${w.message}
473
- ${u}`);
472
+ throw new Error(`[line ${c.lineNo} in ${m(t)}]: ${w.message}
473
+ ${u}`, { cause: w });
474
474
  }
475
475
  }
476
476
  return {
@@ -480,30 +480,32 @@ function st(s, e, t, r) {
480
480
  opts: o
481
481
  };
482
482
  }
483
- function ot(s, e, t, r, n) {
484
- if (t.isInCommentBlock)
485
- return He.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
483
+ function rt(s, e, t, r, n) {
484
+ if (e = e.replaceAll(Xe, ""), t.isInCommentBlock)
485
+ return Qe.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
486
486
  if (Ze.exec(e)) {
487
487
  if (!t.canDetectOptions)
488
488
  throw s.error(
489
489
  `[line ${t.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`
490
490
  ), new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
491
- return { line: e, context: t, artifact: void 0, option: tt(e) };
491
+ return { line: e, context: t, artifact: void 0, option: st(e) };
492
492
  }
493
493
  if (Ke.exec(e) && t.canDetectOptions)
494
494
  return s.warn(
495
495
  `[line ${t.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`
496
496
  ), { line: e, context: t, artifact: void 0, option: void 0 };
497
- if (Xe.exec(e))
497
+ if (Ye.test(e))
498
498
  return { line: "", context: t, artifact: void 0, option: void 0 };
499
- if (Ye.exec(e))
499
+ if (He.exec(e))
500
500
  return t.isInCommentBlock = !0, { line: "", context: t, artifact: void 0, option: void 0 };
501
+ if (e.includes("/*"))
502
+ throw new Error("malformed multiline comment");
501
503
  if (Ve.exec(e))
502
504
  return { line: e, context: t, artifact: void 0, option: void 0 };
503
505
  t.canDetectOptions = !1;
504
506
  const o = be.exec(e);
505
507
  if (o) {
506
- const i = rt(e);
508
+ const i = nt(e);
507
509
  if (i.module === "plapi")
508
510
  return t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
509
511
  ["template", _e(i.alias)],
@@ -536,8 +538,8 @@ function ot(s, e, t, r, n) {
536
538
  }
537
539
  return { line: e, context: t, artifact: void 0, option: void 0 };
538
540
  }
539
- function rt(s) {
540
- const e = Qe.exec(s);
541
+ function nt(s) {
542
+ const e = et.exec(s);
541
543
  if (!e || !e.groups)
542
544
  throw Error("failed to parse 'import' statement");
543
545
  const { importName: t, moduleName: r } = e.groups;
@@ -549,7 +551,7 @@ function rt(s) {
549
551
  };
550
552
  }
551
553
  function ge(s, e, t) {
552
- const r = et.exec(s);
554
+ const r = tt.exec(s);
553
555
  if (!r)
554
556
  return;
555
557
  if (!r.groups)
@@ -563,7 +565,7 @@ function ge(s, e, t) {
563
565
  );
564
566
  return { type: e, pkg: n ?? t, id: o };
565
567
  }
566
- const J = ".plj.gz", P = ".lib.tengo", W = ".sw.json", z = ".as.json", he = ".test.tengo", _ = ".tpl.tengo", q = ".lib.tengo", B = ".sw.json", V = ".as.json", nt = [q, _, B, V];
568
+ const J = ".plj.gz", P = ".lib.tengo", W = ".sw.json", z = ".as.json", he = ".test.tengo", _ = ".tpl.tengo", q = ".lib.tengo", B = ".sw.json", V = ".as.json", it = [q, _, B, V];
567
569
  function M() {
568
570
  return JSON.parse(p.readFileSync("package.json").toString());
569
571
  }
@@ -597,10 +599,10 @@ function ke(s, e, t, r, n = !1) {
597
599
  throw new Error(
598
600
  `nested node_modules is a sign of library dependencies version incompatibility in ${r}`
599
601
  );
600
- d && it(s, b, "dist", i, e), w && at(s, b, "dist", a, e), v && lt(s, b, "dist", c, e), y && ct(s, b, "dist", u, e);
602
+ d && at(s, b, "dist", i, e), w && lt(s, b, "dist", a, e), v && ct(s, b, "dist", c, e), y && dt(s, b, "dist", u, e);
601
603
  }
602
604
  }
603
- function it(s, e, t, r, n) {
605
+ function at(s, e, t, r, n) {
604
606
  for (const o of p.readdirSync(r)) {
605
607
  const i = f.resolve(r, o);
606
608
  if (!o.endsWith(P)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
@@ -616,7 +618,7 @@ function it(s, e, t, r, n) {
616
618
  }
617
619
  }
618
620
  }
619
- function at(s, e, t, r, n) {
621
+ function lt(s, e, t, r, n) {
620
622
  for (const o of p.readdirSync(r)) {
621
623
  const i = f.resolve(r, o);
622
624
  if (!o.endsWith(J)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
@@ -629,7 +631,7 @@ function at(s, e, t, r, n) {
629
631
  n.addTemplate(c), s.debug(`Adding dependency ${m(a)} from ${i}`);
630
632
  }
631
633
  }
632
- function lt(s, e, t, r, n) {
634
+ function ct(s, e, t, r, n) {
633
635
  for (const o of p.readdirSync(r)) {
634
636
  const i = f.resolve(r, o);
635
637
  if (!o.endsWith(W))
@@ -643,7 +645,7 @@ function lt(s, e, t, r, n) {
643
645
  s.debug(`Adding dependency ${m(a)} from ${i}`), n.addSoftware(c);
644
646
  }
645
647
  }
646
- function ct(s, e, t, r, n) {
648
+ function dt(s, e, t, r, n) {
647
649
  for (const o of p.readdirSync(r)) {
648
650
  const i = f.resolve(r, o);
649
651
  if (!o.endsWith(z))
@@ -666,7 +668,7 @@ function L(s, e, t, r, n) {
666
668
  o.push(...y);
667
669
  continue;
668
670
  }
669
- const u = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = dt(e, u.replaceAll(f.sep, "."));
671
+ const u = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = ft(e, u.replaceAll(f.sep, "."));
670
672
  if (!d)
671
673
  continue;
672
674
  const w = f.resolve(r, a);
@@ -684,7 +686,7 @@ function re(s, e, t) {
684
686
  const r = new ze(t);
685
687
  return ke(s, r, e, Ie()), r;
686
688
  }
687
- function dt(s, e) {
689
+ function ft(s, e) {
688
690
  const t = { pkg: s.name, version: s.version };
689
691
  return e.endsWith(q) ? {
690
692
  ...t,
@@ -708,11 +710,11 @@ function dt(s, e) {
708
710
  type: "test"
709
711
  } : null;
710
712
  }
711
- function ft(s, e) {
713
+ function pt(s, e) {
712
714
  const t = M(), r = re(s, t, e), n = L(s, t, e, "src", "");
713
715
  if (n.length === 0) {
714
716
  const i = [];
715
- for (const a of nt)
717
+ for (const a of it)
716
718
  i.push(`*${a}`);
717
719
  s.error(`Nothing to compile. Looked for ${i.join(", ")}`), process.exit(1);
718
720
  }
@@ -720,7 +722,7 @@ function ft(s, e) {
720
722
  const o = r.compileAndAdd(n);
721
723
  return s.debug("Done."), o;
722
724
  }
723
- function pt(s, e, t) {
725
+ function ut(s, e, t) {
724
726
  if (e.libs.length > 0) {
725
727
  const r = Ee(t, ".");
726
728
  p.mkdirSync(r, { recursive: !0 });
@@ -760,7 +762,7 @@ const ne = {
760
762
  default: "info",
761
763
  options: ["error", "warn", "info", "debug"]
762
764
  })
763
- }, ut = {
765
+ }, mt = {
764
766
  "generate-tags": F.boolean({
765
767
  description: "generate tags, default false",
766
768
  default: !1
@@ -778,8 +780,8 @@ const ne = {
778
780
  })
779
781
  }, A = class A extends $ {
780
782
  async run() {
781
- const { flags: e } = await this.parse(A), t = N(e["log-level"]), r = M(), n = ft(t, "dist");
782
- pt(t, n, "dist"), t.info("");
783
+ const { flags: e } = await this.parse(A), t = N(e["log-level"]), r = M(), n = pt(t, "dist");
784
+ ut(t, n, "dist"), t.info("");
783
785
  let o = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
784
786
  `;
785
787
  o += `declare type TplName = ${n.templates.map((d) => '"' + d.fullName.id + '"').join(" | ")};
@@ -801,20 +803,20 @@ export const Templates = {
801
803
  }};
802
804
  `, a += `
803
805
  };
804
- `, await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", i), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", i), await x.writeFile("dist/index.mjs", a)), mt(e), e["generate-tags"] && gt(t, e), t.info("Template Pack build done.");
806
+ `, await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", i), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", i), await x.writeFile("dist/index.mjs", a)), gt(e), e["generate-tags"] && ht(t, e), t.info("Template Pack build done.");
805
807
  }
806
808
  };
807
809
  l(A, "description", "build tengo sources into single distributable pack file"), l(A, "examples", ["<%= config.bin %> <%= command.id %>"]), l(A, "flags", {
808
810
  ...ne,
809
- ...ut
811
+ ...mt
810
812
  });
811
813
  let Z = A;
812
- function mt(s) {
814
+ function gt(s) {
813
815
  process.env.GENERATE_TAGS != null && (s["generate-tags"] = process.env.GENERATE_TAGS == "true"), process.env.TAGS_FILE != null && (s["tags-file"] = process.env.TAGS_FILE), process.env.TAGS_ADDITIONAL_ARGS != null && (s["tags-additional-args"] = process.env.TAGS_ADDITIONAL_ARGS.split(","));
814
816
  }
815
- function gt(s, e) {
817
+ function ht(s, e) {
816
818
  var a;
817
- const t = f.resolve(e["tags-file"]), r = f.dirname(t), n = e["tags-additional-args"], o = ht(r);
819
+ const t = f.resolve(e["tags-file"]), r = f.dirname(t), n = e["tags-additional-args"], o = wt(r);
818
820
  s.info(
819
821
  `Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
820
822
  Found ${o.length} tengo files...`
@@ -851,9 +853,9 @@ For vscode, you should also install ctags extension:
851
853
  https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
852
854
  return;
853
855
  }
854
- wt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
856
+ yt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
855
857
  }
856
- function ht(s) {
858
+ function wt(s) {
857
859
  const e = p.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
858
860
  return e.forEach((r) => {
859
861
  if (!r.isDirectory() && r.name.endsWith(".tengo")) {
@@ -862,7 +864,7 @@ function ht(s) {
862
864
  }
863
865
  }), t;
864
866
  }
865
- function wt(s, e) {
867
+ function yt(s, e) {
866
868
  s.error && console.log(s.error);
867
869
  const t = e;
868
870
  s.status !== 0 && console.log(`WARN: ${t} the build will continue as-is`);
@@ -915,7 +917,7 @@ function ie(s, e) {
915
917
  ), e.write(JSON.stringify(o) + `
916
918
  `));
917
919
  }
918
- function yt(s, e, t) {
920
+ function bt(s, e, t) {
919
921
  const r = M(), n = L(s, r, "dist", "src", "");
920
922
  if (!e) {
921
923
  for (const i of n)
@@ -936,16 +938,16 @@ function C(s, e, t) {
936
938
  o.fullName.type === t && e.write(JSON.stringify(o) + `
937
939
  `);
938
940
  }
939
- function bt(s, e) {
941
+ function vt(s, e) {
940
942
  C(s, e, "template");
941
943
  }
942
- function vt(s, e) {
944
+ function Et(s, e) {
943
945
  C(s, e, "software");
944
946
  }
945
- function Et(s, e) {
947
+ function $t(s, e) {
946
948
  C(s, e, "asset");
947
949
  }
948
- function $t(s, e) {
950
+ function Nt(s, e) {
949
951
  C(s, e, "test");
950
952
  }
951
953
  function Ae(s, ...e) {
@@ -1026,7 +1028,7 @@ l(Y, "description", "parse sources in current package and dump all found artifac
1026
1028
  class H extends $ {
1027
1029
  async run() {
1028
1030
  const e = N();
1029
- Et(e, D);
1031
+ $t(e, D);
1030
1032
  }
1031
1033
  }
1032
1034
  l(H, "description", "parse sources in current package and dump all found assets to stdout"), l(H, "examples", [
@@ -1035,7 +1037,7 @@ l(H, "description", "parse sources in current package and dump all found assets
1035
1037
  const T = class T extends $ {
1036
1038
  async run() {
1037
1039
  const { flags: e } = await this.parse(T), t = N();
1038
- yt(t, e.deps, D);
1040
+ bt(t, e.deps, D);
1039
1041
  }
1040
1042
  };
1041
1043
  l(T, "description", "parse sources in current package and dump all found libs to stdout"), l(T, "examples", [
@@ -1047,7 +1049,7 @@ let Q = T;
1047
1049
  class ee extends $ {
1048
1050
  async run() {
1049
1051
  const e = N();
1050
- vt(e, D);
1052
+ Et(e, D);
1051
1053
  }
1052
1054
  }
1053
1055
  l(ee, "description", "parse sources in current package and dump all found software to stdout"), l(ee, "examples", [
@@ -1056,7 +1058,7 @@ l(ee, "description", "parse sources in current package and dump all found softwa
1056
1058
  class te extends $ {
1057
1059
  async run() {
1058
1060
  const e = N();
1059
- bt(e, D);
1061
+ vt(e, D);
1060
1062
  }
1061
1063
  }
1062
1064
  l(te, "description", "parse sources in current package and dump all found templates to stdout"), l(te, "examples", [
@@ -1065,13 +1067,13 @@ l(te, "description", "parse sources in current package and dump all found templa
1065
1067
  class se extends $ {
1066
1068
  async run() {
1067
1069
  const e = N();
1068
- $t(e, D);
1070
+ Nt(e, D);
1069
1071
  }
1070
1072
  }
1071
1073
  l(se, "description", "parse sources in current package and dump all found tests to stdout"), l(se, "examples", [
1072
1074
  "<%= config.bin %> <%= command.id %>"
1073
1075
  ]);
1074
- const Ot = {
1076
+ const Rt = {
1075
1077
  build: Z,
1076
1078
  check: K,
1077
1079
  test: X,
@@ -1083,6 +1085,6 @@ const Ot = {
1083
1085
  "dump:tests": se
1084
1086
  };
1085
1087
  export {
1086
- Ot as COMMANDS
1088
+ Rt as COMMANDS
1087
1089
  };
1088
1090
  //# sourceMappingURL=index.mjs.map