@platforma-sdk/tengo-builder 2.0.2 → 2.1.0

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
@@ -1,16 +1,17 @@
1
- var De = Object.defineProperty;
2
- var Oe = (s, e, t) => e in s ? De(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var c = (s, e, t) => Oe(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { spawnSync as xe, spawn as Fe } from "node:child_process";
1
+ var Oe = Object.defineProperty;
2
+ var xe = (s, e, t) => e in s ? Oe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var c = (s, e, t) => xe(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { spawnSync as Fe, spawn as Re } from "node:child_process";
5
5
  import { Flags as F, Command as v } from "@oclif/core";
6
6
  import * as f from "node:path";
7
- import * as m from "node:fs";
8
- import { readFileSync as Re } from "node:fs";
7
+ import * as p from "node:fs";
8
+ import { readFileSync as je } from "node:fs";
9
9
  import * as O from "winston";
10
- import { parseTemplate as je, serializeTemplate as Me } from "@milaboratories/pl-model-backend";
11
- import { tryResolve as Le, tryResolveOrError as Ce } from "@milaboratories/resolve-helper";
10
+ import { parseTemplate as Le, serializeTemplate as Me } from "@milaboratories/pl-model-backend";
11
+ import { createHash as Ce } from "node:crypto";
12
+ import { tryResolve as Ie, tryResolveOrError as Je } from "@milaboratories/resolve-helper";
12
13
  import * as x from "node:fs/promises";
13
- import { TengoTesterBinaryPath as he } from "@milaboratories/tengo-tester";
14
+ import { TengoTesterBinaryPath as we } from "@milaboratories/tengo-tester";
14
15
  import { stdout as D } from "node:process";
15
16
  function R(s) {
16
17
  throw new Error("Unexpected object: " + s);
@@ -21,9 +22,9 @@ function E(s = "debug") {
21
22
  format: O.format.combine(
22
23
  O.format.errors({ stack: !0 }),
23
24
  O.format.printf(({ level: e, message: t, stack: r }) => {
24
- const n = `${e.padStart(6, " ")}: ${t}`;
25
- return r ? `${n}
26
- ${r}` : n;
25
+ const i = `${e.padStart(6, " ")}: ${t}`;
26
+ return r ? `${i}
27
+ ${r}` : i;
27
28
  })
28
29
  ),
29
30
  transports: [
@@ -34,9 +35,9 @@ ${r}` : n;
34
35
  ]
35
36
  });
36
37
  }
37
- function k(s) {
38
+ function S(s) {
38
39
  try {
39
- const e = m.statSync(s);
40
+ const e = p.statSync(s);
40
41
  return e.isDirectory() ? "dir" : e.isFile() ? "file" : e.isSymbolicLink() ? "link" : "unknown";
41
42
  } catch (e) {
42
43
  const t = e;
@@ -44,13 +45,13 @@ function k(s) {
44
45
  throw t;
45
46
  }
46
47
  }
47
- function Ie(s) {
48
+ function Pe(s) {
48
49
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s.toLowerCase());
49
50
  }
50
51
  function le(s) {
51
52
  return `${s.type}||${s.pkg}||${s.id}`;
52
53
  }
53
- function g(s) {
54
+ function u(s) {
54
55
  return `${s.type}:${s.pkg}:${s.id}:${s.version}`;
55
56
  }
56
57
  function h(s) {
@@ -62,50 +63,62 @@ function ce(s, e) {
62
63
  function C(s, e) {
63
64
  return s.type == e.type && s.pkg == e.pkg && s.id == e.id && s.version == e.version;
64
65
  }
65
- function y(s) {
66
+ function w(s) {
66
67
  return `${s.pkg}:${s.id}`;
67
68
  }
68
69
  function I(s) {
69
- return { name: y(s), version: s.version };
70
+ return { name: w(s), version: s.version };
70
71
  }
71
- function Je(s) {
72
+ function Ge(s) {
72
73
  const e = s.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
73
74
  if (!e) throw new Error(`malformed artifact name: ${s.name}`);
74
75
  return { pkg: e.groups.pkg, id: e.groups.id, version: s.version };
75
76
  }
76
- function de(s) {
77
+ function fe(s) {
77
78
  return `${s.pkg}:${s.id}:${s.version}`;
78
79
  }
79
- class we {
80
- constructor(e, t, r) {
81
- c(this, "data");
82
- c(this, "content");
83
- this.compileMode = e, this.fullName = t;
84
- let { data: n, content: o } = r;
85
- if (n === void 0 && o === void 0)
86
- throw new Error("Neither data nor content is provided for template constructor");
87
- if (n !== void 0 && o !== void 0)
88
- throw new Error("Both data and content are provided for template constructor");
89
- n === void 0 && (n = je(o)), o === void 0 && (o = Me(n));
90
- const i = Je(n);
91
- if (i.pkg !== t.pkg || i.id !== t.id || i.version !== t.version)
92
- throw new Error(
93
- `Compiled template name don't match it's package and file names: ${de(i)} != ${de(t)}`
94
- );
95
- this.data = n, this.content = o;
96
- }
97
- toJSON() {
98
- return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
99
- }
80
+ function He(s, e, t, r) {
81
+ return ye(e, t), {
82
+ compileMode: s,
83
+ fullName: e,
84
+ data: t,
85
+ source: r
86
+ };
87
+ }
88
+ function We(s, e, t) {
89
+ const r = Le(t);
90
+ if (r.type !== "pl.tengo-template.v3")
91
+ throw new Error("malformed v3 template");
92
+ return ye(e, r), {
93
+ compileMode: s,
94
+ fullName: e,
95
+ data: r,
96
+ content: t
97
+ };
98
+ }
99
+ function Ue(s) {
100
+ return {
101
+ compileMode: s.compileMode,
102
+ fullName: s.fullName,
103
+ data: s.data,
104
+ source: s.data.hashToSource[s.data.template.sourceHash]
105
+ };
106
+ }
107
+ function ye(s, e) {
108
+ const t = Ge(e.template);
109
+ if (t.pkg !== s.pkg || t.id !== s.id || t.version !== s.version)
110
+ throw new Error(
111
+ `Compiled template name don't match it's package and file names: ${fe(t)} != ${fe(s)}`
112
+ );
100
113
  }
101
- class ye {
114
+ class be {
102
115
  constructor(e) {
103
116
  c(this, "map", /* @__PURE__ */ new Map());
104
117
  this.nameExtractor = e;
105
118
  }
106
119
  add(e, t = !0) {
107
- const r = le(this.nameExtractor(e)), n = this.map.get(r);
108
- return n && !t || this.map.set(r, e), n;
120
+ const r = le(this.nameExtractor(e)), i = this.map.get(r);
121
+ return i && !t || this.map.set(r, e), i;
109
122
  }
110
123
  get(e) {
111
124
  return this.map.get(le(e));
@@ -118,14 +131,14 @@ class ye {
118
131
  this.map.forEach((t) => e(t, this.nameExtractor(t)));
119
132
  }
120
133
  }
121
- function Pe() {
122
- return new ye((s) => s);
134
+ function ze() {
135
+ return new be((s) => s);
123
136
  }
124
137
  class J {
125
138
  constructor(e) {
126
139
  // private readonly dev: ArtifactMap<T>;
127
140
  c(this, "dist");
128
- this.dist = new ye(e);
141
+ this.dist = new be(e);
129
142
  }
130
143
  add(e, t, r = !0) {
131
144
  switch (e) {
@@ -148,19 +161,19 @@ class J {
148
161
  return this.forEach(e, (r) => t.push(r)), t;
149
162
  }
150
163
  forEach(e, t) {
151
- this.dist.forEach((r, n) => t(this.get(e, n) ?? r, n));
164
+ this.dist.forEach((r, i) => t(this.get(e, i) ?? r, i));
152
165
  }
153
166
  }
154
- function Ge(s, e) {
167
+ function _e(s, e) {
155
168
  for (const t of s)
156
169
  switch (t.name) {
157
170
  case "hash_override": {
158
- e.hashOverride = We(t.args);
171
+ e.hashOverride = Be(t.args);
159
172
  break;
160
173
  }
161
174
  }
162
175
  }
163
- function Ue(s, e) {
176
+ function qe(s, e) {
164
177
  for (const t of s)
165
178
  switch (t.name) {
166
179
  case "hash_override":
@@ -169,19 +182,19 @@ function Ue(s, e) {
169
182
  );
170
183
  }
171
184
  }
172
- function We(s) {
185
+ function Be(s) {
173
186
  if (s.length != 1)
174
187
  throw new Error(
175
188
  "hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value."
176
189
  );
177
190
  const e = s[0].toLowerCase();
178
- if (!Ie(e))
191
+ if (!Pe(e))
179
192
  throw new Error(
180
193
  `hash_override must contain valid UUID as an override. As hash_override affects deduplication, it becomes completely not possible to distinguish several different templates from each other on backend's side. This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates, they will be marked as interchangeable on backend's side with unpredictable consequences. UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety`
181
194
  );
182
195
  return e;
183
196
  }
184
- class ze {
197
+ class Ke {
185
198
  constructor(e) {
186
199
  c(this, "libs", new J((e) => e.fullName));
187
200
  c(this, "software", new J((e) => e.fullName));
@@ -189,48 +202,51 @@ class ze {
189
202
  c(this, "templates", new J((e) => e.fullName));
190
203
  this.compileMode = e;
191
204
  }
192
- populateTemplateDataFromDependencies(e, t, r, n) {
205
+ /** Recursively add dependencies to the template. */
206
+ populateTemplateDataFromDependencies(e, t, r, i) {
193
207
  for (const o of r)
194
208
  switch (o.type) {
195
209
  case "library": {
196
- const i = this.getLibOrError(o), a = n.indexOf(y(o));
210
+ const n = this.getLibOrError(o), a = i.indexOf(w(o));
197
211
  if (a >= 0) {
198
- const p = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${y(o)}`;
199
- throw new Error(p);
212
+ const d = `library import recursion detected: ${i.slice(a).join(" -> ")} -> ${w(o)}`;
213
+ throw new Error(d);
200
214
  }
201
215
  const l = {
202
- ...I(i.fullName),
203
- src: i.src
216
+ ...I(n.fullName),
217
+ sourceHash: n.sourceHash
204
218
  };
205
- Ue(i.compilerOptions), t.libs[y(o)] = l, this.populateTemplateDataFromDependencies(e, t, i.dependencies, [...n, y(o)]);
219
+ qe(n.compilerOptions), t.template.libs[w(o)] = l, t.hashToSource[l.sourceHash] = n.src, this.populateTemplateDataFromDependencies(e, t, n.dependencies, [...i, w(o)]);
206
220
  break;
207
221
  }
208
222
  case "software": {
209
- const i = this.getSoftwareOrError(o);
210
- t.software[y(o)] = {
211
- ...I(i.fullName),
212
- src: i.src
213
- };
223
+ const n = this.getSoftwareOrError(o);
224
+ t.template.software[w(o)] = {
225
+ ...I(n.fullName),
226
+ sourceHash: n.sourceHash
227
+ }, t.hashToSource[n.sourceHash] = n.src;
214
228
  break;
215
229
  }
216
230
  case "asset": {
217
- const i = this.getAssetOrError(o);
218
- t.software[y(o)] = {
219
- ...I(i.fullName),
220
- src: i.src
221
- };
231
+ const n = this.getAssetOrError(o);
232
+ t.template.software[w(o)] = {
233
+ ...I(n.fullName),
234
+ sourceHash: n.sourceHash
235
+ }, t.hashToSource[n.sourceHash] = n.src;
222
236
  break;
223
237
  }
224
238
  case "template": {
225
239
  if (ce(e, o))
226
240
  continue;
227
- const i = this.getTemplateOrError(o);
228
- t.templates[y(o)] = i.data;
241
+ const n = this.getTemplateOrError(o);
242
+ t.template.templates[w(o)] = n.data.template, t.hashToSource[n.data.template.sourceHash] = n.source;
243
+ for (const [a, l] of Object.entries(n.data.hashToSource))
244
+ t.hashToSource[a] = l;
229
245
  break;
230
246
  }
231
247
  case "test":
232
248
  throw new Error(
233
- `dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${y(e)}`
249
+ `dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${w(e)}`
234
250
  );
235
251
  default:
236
252
  R(o.type);
@@ -241,23 +257,26 @@ class ze {
241
257
  if (e.fullName.type !== "template")
242
258
  throw new Error("unexpected source type");
243
259
  const t = {
244
- type: "pl.tengo-template.v2",
245
- ...I(e.fullName),
246
- templates: {},
247
- libs: {},
248
- software: {},
249
- assets: {},
250
- src: e.src
260
+ type: "pl.tengo-template.v3",
261
+ hashToSource: {
262
+ [e.sourceHash]: e.src
263
+ },
264
+ template: {
265
+ ...I(e.fullName),
266
+ templates: {},
267
+ libs: {},
268
+ software: {},
269
+ assets: {},
270
+ sourceHash: e.sourceHash
271
+ }
251
272
  };
252
- Ge(e.compilerOptions, t), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []);
253
- const r = new we(e.compileMode, e.fullName, { data: t });
254
- return this.addTemplate(r), r;
273
+ return _e(e.compilerOptions, t.template), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []), t;
255
274
  }
256
275
  addLib(e) {
257
276
  const t = this.libs.add(e.compileMode, e, !1);
258
277
  if (t && !C(e.fullName, t.fullName))
259
278
  throw new Error(
260
- `compiler already contain such library: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
279
+ `compiler already contain such library: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`
261
280
  );
262
281
  }
263
282
  allLibs() {
@@ -271,14 +290,24 @@ class ze {
271
290
  getLibOrError(e) {
272
291
  const t = this.getLib(e);
273
292
  if (!t)
274
- throw new Error(`library not found: ${y(e)}`);
293
+ throw new Error(`library not found: ${w(e)}`);
275
294
  return t;
276
295
  }
296
+ checkLibs() {
297
+ this.libs.forEach(this.compileMode, (e) => {
298
+ for (const t of e.dependencies) {
299
+ if (t.type === "test")
300
+ throw new Error(`test should never be dependency of production code: ${h(t)} test is dependency of ${u(e.fullName)}`);
301
+ if (!this.getArtefact(t))
302
+ throw new Error(`unresolved dependency ${h(t)} for ${u(e.fullName)}`);
303
+ }
304
+ });
305
+ }
277
306
  addSoftware(e) {
278
307
  const t = this.software.add(e.compileMode, e, !1);
279
308
  if (t && !C(e.fullName, t.fullName))
280
309
  throw new Error(
281
- `compiler already contain info for software: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
310
+ `compiler already contain info for software: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`
282
311
  );
283
312
  }
284
313
  allSoftware() {
@@ -292,14 +321,14 @@ class ze {
292
321
  getSoftwareOrError(e) {
293
322
  const t = this.getSoftware(e);
294
323
  if (!t)
295
- throw new Error(`software info not found: ${y(e)}`);
324
+ throw new Error(`software info not found: ${w(e)}`);
296
325
  return t;
297
326
  }
298
327
  addAsset(e) {
299
328
  const t = this.assets.add(e.compileMode, e, !1);
300
329
  if (t && !C(e.fullName, t.fullName))
301
330
  throw new Error(
302
- `compiler already contain info for asset: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
331
+ `compiler already contain info for asset: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`
303
332
  );
304
333
  }
305
334
  allAssets() {
@@ -313,14 +342,14 @@ class ze {
313
342
  getAssetOrError(e) {
314
343
  const t = this.getAsset(e);
315
344
  if (!t)
316
- throw new Error(`asset info not found: ${y(e)}`);
345
+ throw new Error(`asset info not found: ${w(e)}`);
317
346
  return t;
318
347
  }
319
348
  addTemplate(e) {
320
349
  const t = this.templates.add(e.compileMode, e, !1);
321
350
  if (t && !C(e.fullName, t.fullName))
322
351
  throw new Error(
323
- `compiler already contain such template: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
352
+ `compiler already contain such template: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`
324
353
  );
325
354
  }
326
355
  allTemplates() {
@@ -334,7 +363,7 @@ class ze {
334
363
  getTemplateOrError(e) {
335
364
  const t = this.getTemplate(e);
336
365
  if (!t)
337
- throw new Error(`template not found: ${y(e)}`);
366
+ throw new Error(`template not found: ${w(e)}`);
338
367
  return t;
339
368
  }
340
369
  getArtefact(e) {
@@ -353,34 +382,29 @@ class ze {
353
382
  R(e.type);
354
383
  }
355
384
  }
356
- checkLibs() {
357
- this.libs.forEach(this.compileMode, (e) => {
358
- for (const t of e.dependencies) {
359
- if (t.type === "test")
360
- throw new Error(`test should never be dependency of production code: ${h(t)} test is dependency of ${g(e.fullName)}`);
361
- if (!this.getArtefact(t))
362
- throw new Error(`unresolved dependency ${h(t)} for ${g(e.fullName)}`);
363
- }
364
- });
365
- }
366
385
  compileAndAdd(e) {
367
- const t = { templates: [], libs: [], software: [], assets: [] };
386
+ const t = {
387
+ templates: [],
388
+ libs: [],
389
+ software: [],
390
+ assets: []
391
+ };
368
392
  let r = [];
369
- for (const n of e)
370
- n.fullName.type === "library" ? (this.addLib(n), t.libs.push(n)) : n.fullName.type === "software" ? (this.addSoftware(n), t.software.push(n)) : n.fullName.type === "asset" ? (this.addAsset(n), t.assets.push(n)) : r.push(n);
393
+ for (const i of e)
394
+ i.fullName.type === "library" ? (this.addLib(i), t.libs.push(i)) : i.fullName.type === "software" ? (this.addSoftware(i), t.software.push(i)) : i.fullName.type === "asset" ? (this.addAsset(i), t.assets.push(i)) : r.push(i);
371
395
  for (; r.length > 0; ) {
372
- const n = [];
396
+ const i = [];
373
397
  for (const o of r) {
374
- const i = o.dependencies.filter(
398
+ const n = o.dependencies.filter(
375
399
  (a) => !this.getArtefact(a) && !(o.fullName.type === "template" && ce(o.fullName, a))
376
400
  );
377
- if (i.length > 0) {
378
- let a = `Unsatisfied dependencies in ${g(o.fullName)}:
401
+ if (n.length > 0) {
402
+ let a = `Unsatisfied dependencies in ${u(o.fullName)}:
379
403
  `;
380
- for (const l of i)
404
+ for (const l of n)
381
405
  a += ` - ${h(l)}
382
406
  `;
383
- n.push({ src: o, err: new Error(a) });
407
+ i.push({ src: o, err: new Error(a) });
384
408
  continue;
385
409
  }
386
410
  switch (o.fullName.type) {
@@ -395,14 +419,14 @@ class ze {
395
419
  break;
396
420
  case "template":
397
421
  try {
398
- const a = this.compileAndAddTemplate(o);
399
- t.templates.push(a);
422
+ const a = this.compileAndAddTemplate(o), l = He(o.compileMode, o.fullName, a, o.src);
423
+ this.addTemplate(l), t.templates.push(l);
400
424
  } catch (a) {
401
425
  const l = a;
402
- let p = `Unsatisfied dependencies in ${g(o.fullName)}:
426
+ let d = `Unsatisfied dependencies in ${u(o.fullName)}:
403
427
  `;
404
- p += ` - ${l.message}
405
- `, n.push({ src: o, err: Error(p) });
428
+ d += ` - ${l.message}
429
+ `, i.push({ src: o, err: Error(d) });
406
430
  }
407
431
  break;
408
432
  case "test":
@@ -411,23 +435,23 @@ class ze {
411
435
  R(o.fullName.type);
412
436
  }
413
437
  }
414
- if (r.length === n.length) {
438
+ if (r.length === i.length) {
415
439
  let o = "";
416
- for (const i of n)
440
+ for (const n of i)
417
441
  o += `
418
- ${i.err.message}`;
442
+ ${n.err.message}`;
419
443
  throw new Error(o);
420
444
  }
421
- r = n.map(({ src: o }) => o);
445
+ r = i.map(({ src: o }) => o);
422
446
  }
423
447
  return t;
424
448
  }
425
449
  }
426
- const fe = "[_a-zA-Z][_a-zA-Z0-9]*", j = (s, e) => new RegExp(
450
+ const de = "[_a-zA-Z][_a-zA-Z0-9]*", j = (s, e) => new RegExp(
427
451
  `\\b${s}\\.(?<fnCall>(?<fnName>` + e + ')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'
428
- ), _e = (s) => j(s, "getTemplateId"), qe = (s) => j(s, "getSoftwareInfo"), pe = (s) => j(s, "importTemplate"), ue = (s) => j(s, "importSoftware"), Be = (s) => j(s, "importAsset"), Ke = /^\s*$/, Ve = /^\/\/tengo:[\w]/, Xe = /^\s*\/\/\s*tengo:\s*./, Ze = /\/\*.*?\*\//g, He = /^\s*(\/\/)/, Ye = /^\s*\/\*/, Qe = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, et = new RegExp(
429
- `\\b(?<importName>${fe}(\\.${fe})*)${be.source}`
430
- ), tt = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, st = (s) => {
452
+ ), Ve = (s) => j(s, "getTemplateId"), Xe = (s) => j(s, "getSoftwareInfo"), pe = (s) => j(s, "importTemplate"), ue = (s) => j(s, "importSoftware"), Ze = (s) => j(s, "importAsset"), Ye = /^\s*$/, Qe = /^\/\/tengo:[\w]/, et = /^\s*\/\/\s*tengo:\s*./, tt = /\/\*.*?\*\//g, st = /^\s*(\/\/)/, ot = /^\s*\/\*/, rt = /\*\//, ve = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, nt = new RegExp(
453
+ `\\b(?<importName>${de}(\\.${de})*)${ve.source}`
454
+ ), it = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, at = (s) => {
431
455
  const e = s.split(" "), t = e[0].split(":");
432
456
  if (t.length != 2)
433
457
  throw new Error(
@@ -438,17 +462,25 @@ const fe = "[_a-zA-Z][_a-zA-Z0-9]*", j = (s, e) => new RegExp(
438
462
  args: e.slice(1)
439
463
  };
440
464
  };
441
- class re {
442
- constructor(e, t, r, n, o, i) {
443
- this.compileMode = e, this.fullName = t, this.src = r, this.srcName = n, this.dependencies = o, this.compilerOptions = i;
465
+ class oe {
466
+ constructor(e, t, r, i, o, n, a) {
467
+ this.compileMode = e, this.fullName = t, this.sourceHash = r, this.src = i, this.srcName = o, this.dependencies = n, this.compilerOptions = a;
444
468
  }
445
469
  }
446
- function ve(s, e, t, r, n) {
447
- const o = Re(t).toString(), { deps: i, normalized: a, opts: l } = ot(s, o, r, n);
448
- return new re(e, r, a, t, i.array, l);
470
+ function Ee(s, e, t, r, i) {
471
+ const o = je(t).toString(), { deps: n, normalized: a, opts: l } = lt(s, o, r, i);
472
+ return new oe(
473
+ e,
474
+ r,
475
+ re(a),
476
+ a,
477
+ t,
478
+ n.array,
479
+ l
480
+ );
449
481
  }
450
- function ot(s, e, t, r) {
451
- const n = Pe(), o = [], i = e.split(`
482
+ function lt(s, e, t, r) {
483
+ const i = ze(), o = [], n = e.split(`
452
484
  `), a = [];
453
485
  let l = {
454
486
  isInCommentBlock: !1,
@@ -456,90 +488,90 @@ function ot(s, e, t, r) {
456
488
  tplDepREs: /* @__PURE__ */ new Map(),
457
489
  lineNo: 0
458
490
  };
459
- for (const p of i) {
491
+ for (const d of n) {
460
492
  l.lineNo++;
461
493
  try {
462
- const d = rt(
494
+ const { line: g, context: m, artifact: y, option: b } = ct(
463
495
  s,
464
- p,
496
+ d,
465
497
  l,
466
498
  t.pkg,
467
499
  r
468
500
  );
469
- a.push(d.line), l = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
470
- } catch (d) {
471
- const u = d;
472
- throw new Error(`[line ${l.lineNo} in ${g(t)}]: ${u.message}
473
- ${p}`, { cause: u });
501
+ a.push(g), l = m, y && i.add(y), b && o.push(b);
502
+ } catch (g) {
503
+ const m = g;
504
+ throw new Error(`[line ${l.lineNo} in ${u(t)}]: ${m.message}
505
+ ${d}`, { cause: m });
474
506
  }
475
507
  }
476
508
  return {
477
509
  normalized: a.join(`
478
510
  `),
479
- deps: n,
511
+ deps: i,
480
512
  opts: o
481
513
  };
482
514
  }
483
- function rt(s, e, t, r, n) {
484
- if (e = e.replaceAll(Ze, ""), t.isInCommentBlock)
485
- return Qe.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
486
- if (Ve.exec(e)) {
515
+ function ct(s, e, t, r, i) {
516
+ if (e = e.replaceAll(tt, ""), t.isInCommentBlock)
517
+ return rt.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
518
+ if (Qe.exec(e)) {
487
519
  if (!t.canDetectOptions)
488
520
  throw s.error(
489
521
  `[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
522
  ), new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
491
- return { line: e, context: t, artifact: void 0, option: st(e) };
523
+ return { line: e, context: t, artifact: void 0, option: at(e) };
492
524
  }
493
- if (Xe.exec(e) && t.canDetectOptions)
525
+ if (et.exec(e) && t.canDetectOptions)
494
526
  return s.warn(
495
527
  `[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
528
  ), { line: e, context: t, artifact: void 0, option: void 0 };
497
- if (He.test(e))
529
+ if (st.test(e))
498
530
  return { line: "", context: t, artifact: void 0, option: void 0 };
499
- if (Ye.exec(e))
531
+ if (ot.exec(e))
500
532
  return t.isInCommentBlock = !0, { line: "", context: t, artifact: void 0, option: void 0 };
501
533
  if (e.includes("/*"))
502
534
  throw new Error("malformed multiline comment");
503
- if (Ke.exec(e))
535
+ if (Ye.exec(e))
504
536
  return { line: e, context: t, artifact: void 0, option: void 0 };
505
537
  t.canDetectOptions = !1;
506
- const o = be.exec(e);
538
+ const o = ve.exec(e);
507
539
  if (o) {
508
- const i = nt(e);
509
- if (i.module === "plapi")
510
- return t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
511
- ["template", _e(i.alias)],
512
- ["software", qe(i.alias)]
540
+ const n = ft(e);
541
+ if (n.module === "plapi")
542
+ return t.tplDepREs.has(n.module) || t.tplDepREs.set(n.module, [
543
+ ["template", Ve(n.alias)],
544
+ ["software", Xe(n.alias)]
513
545
  ]), { line: e, context: t, artifact: void 0, option: void 0 };
514
- (i.module === "@milaboratory/tengo-sdk:ll" || i.module === "@platforma-sdk/workflow-tengo:ll" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":ll") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
515
- ["template", pe(i.alias)],
516
- ["software", ue(i.alias)]
517
- ])), (i.module === "@milaboratory/tengo-sdk:assets" || i.module === "@platforma-sdk/workflow-tengo:assets" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":assets") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
518
- ["template", pe(i.alias)],
519
- ["software", ue(i.alias)],
520
- ["asset", Be(i.alias)]
546
+ (n.module === "@milaboratory/tengo-sdk:ll" || n.module === "@platforma-sdk/workflow-tengo:ll" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && n.module === ":ll") && (t.tplDepREs.has(n.module) || t.tplDepREs.set(n.module, [
547
+ ["template", pe(n.alias)],
548
+ ["software", ue(n.alias)]
549
+ ])), (n.module === "@milaboratory/tengo-sdk:assets" || n.module === "@platforma-sdk/workflow-tengo:assets" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && n.module === ":assets") && (t.tplDepREs.has(n.module) || t.tplDepREs.set(n.module, [
550
+ ["template", pe(n.alias)],
551
+ ["software", ue(n.alias)],
552
+ ["asset", Ze(n.alias)]
521
553
  ]));
522
- const a = me(i.module, "library", r);
554
+ const a = me(n.module, "library", r);
523
555
  return a ? (e = e.replace(o[0], ` := import("${a.pkg}:${a.id}")`), { line: e, context: t, artifact: a, option: void 0 }) : { line: e, context: t, artifact: void 0, option: void 0 };
524
556
  }
525
557
  if (t.tplDepREs.size > 0)
526
- for (const [i, a] of t.tplDepREs)
527
- for (const [l, p] of a) {
528
- const d = p.exec(e);
529
- if (!d || !d.groups)
558
+ for (const [n, a] of t.tplDepREs)
559
+ for (const [l, d] of a) {
560
+ const g = d.exec(e);
561
+ if (!g || !g.groups)
530
562
  continue;
531
- const { fnCall: u, templateName: w, fnName: b } = d.groups;
532
- if (!u || !w || !b)
563
+ const { fnCall: m, templateName: y, fnName: b } = g.groups;
564
+ if (!m || !y || !b)
533
565
  throw Error("failed to parse template import statement");
534
- const L = me(w, l, r);
535
- if (!L)
566
+ const M = me(y, l, r);
567
+ if (!M)
536
568
  throw Error(`failed to parse artifact name in ${b} import statement`);
537
- return e = e.replace(u, `${b}("${L.pkg}:${L.id}")`), { line: e, context: t, artifact: L, option: void 0 };
569
+ return e = e.replace(m, `${b}("${M.pkg}:${M.id}")`), { line: e, context: t, artifact: M, option: void 0 };
538
570
  }
539
571
  return { line: e, context: t, artifact: void 0, option: void 0 };
540
572
  }
541
- function nt(s) {
542
- const e = et.exec(s);
573
+ function ft(s) {
574
+ const e = nt.exec(s);
543
575
  if (!e || !e.groups)
544
576
  throw Error("failed to parse 'import' statement");
545
577
  const { importName: t, moduleName: r } = e.groups;
@@ -547,45 +579,44 @@ function nt(s) {
547
579
  throw Error("failed to parse 'import' statement");
548
580
  return {
549
581
  module: r,
582
+ // the module name without wrapping quotes: import("<module>")
550
583
  alias: t
584
+ // the name of variable that keeps imported module: <alias> := import("<module>")
551
585
  };
552
586
  }
553
587
  function me(s, e, t) {
554
- const r = tt.exec(s);
588
+ const r = it.exec(s);
555
589
  if (!r)
556
590
  return;
557
591
  if (!r.groups)
558
592
  throw Error(
559
593
  "failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'"
560
594
  );
561
- const { pkgName: n, depID: o } = r.groups;
595
+ const { pkgName: i, depID: o } = r.groups;
562
596
  if (!o)
563
597
  throw Error(
564
598
  "failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'"
565
599
  );
566
- return { type: e, pkg: n ?? t, id: o };
600
+ return { type: e, pkg: i ?? t, id: o };
601
+ }
602
+ function re(s) {
603
+ return Ce("sha256").update(s).digest("hex");
567
604
  }
568
- const U = ".plj.gz", W = ".lib.tengo", z = ".sw.json", _ = ".as.json", ge = ".test.tengo", q = ".tpl.tengo", B = ".lib.tengo", K = ".sw.json", V = ".as.json", it = [B, q, K, V];
569
- function G(s, e) {
605
+ const G = ".plj.gz", H = ".lib.tengo", W = ".sw.json", U = ".as.json", he = ".test.tengo", z = ".tpl.tengo", _ = ".lib.tengo", q = ".sw.json", B = ".as.json", dt = [_, z, q, B];
606
+ function ge(s, e) {
570
607
  if (!f.isAbsolute(s))
571
608
  throw new Error(`Root path must be absolute: ${s}`);
572
- if (!e) {
573
- const n = f.join(s, "package.json");
574
- if (k(n) === "file")
575
- return n;
576
- throw new Error(`Can't resolve package.json in ${s}`);
577
- }
578
- let t = Le(s, e);
609
+ let t = Ie(s, e);
579
610
  if (t) {
580
- let n = 0;
611
+ let i = 0;
581
612
  do {
582
613
  const o = f.join(t, "package.json");
583
- if (k(o) === "file")
614
+ if (S(o) === "file")
584
615
  return o;
585
- n++, t = f.dirname(t);
586
- } while (n < 7 && f.basename(t) !== "node_modules");
616
+ i++, t = f.dirname(t);
617
+ } while (i < 7 && f.basename(t) !== "node_modules");
587
618
  }
588
- const r = Ce(s, `${e}/package.json`);
619
+ const r = Je(s, `${e}/package.json`);
589
620
  if (r.result === void 0) {
590
621
  if (r.err === "ERR_PACKAGE_PATH_NOT_EXPORTED")
591
622
  return;
@@ -593,207 +624,235 @@ function G(s, e) {
593
624
  }
594
625
  return r.result;
595
626
  }
596
- function S(s, e, t = "root") {
597
- const r = G(s);
598
- if (!r)
599
- throw new Error(`Can't resolve package.json for root package ${s}`);
600
- const { name: n, version: o, type: i, dependencies: a, devDependencies: l } = JSON.parse(m.readFileSync(r).toString()), p = [];
601
- if (a && t !== "devDependency")
602
- for (const u of Object.keys(a)) {
603
- const w = G(s, u);
604
- if (w === void 0)
605
- throw new Error(`Can't resolve package.json for dependency ${u} of ${s}`);
606
- const b = f.dirname(w);
607
- p.push(S(b, e, "dependency"));
627
+ function pt(s) {
628
+ if (!f.isAbsolute(s))
629
+ throw new Error(`Root path must be absolute: ${s}`);
630
+ const e = f.join(s, "package.json");
631
+ if (S(e) === "file")
632
+ return e;
633
+ throw new Error(`Can't resolve package.json in ${s}`);
634
+ }
635
+ function A(s, e, t = "root") {
636
+ const r = pt(s), i = JSON.parse(p.readFileSync(r).toString()), o = [];
637
+ if (i.dependencies && t !== "devDependency")
638
+ for (const n of Object.keys(i.dependencies)) {
639
+ const a = ge(s, n);
640
+ if (a === void 0)
641
+ throw new Error(`Can't resolve package.json for dependency ${n} of ${s}`);
642
+ const l = f.dirname(a);
643
+ o.push(A(l, e, "dependency"));
608
644
  }
609
- if (l && t === "root")
610
- for (const u of Object.keys(l)) {
611
- const w = G(s, u);
612
- if (w === void 0) {
613
- e.warn(`Can't resolve package.json for dev dependency ${u} of ${s}`);
645
+ if (i.devDependencies && t === "root")
646
+ for (const n of Object.keys(i.devDependencies)) {
647
+ const a = ge(s, n);
648
+ if (a === void 0) {
649
+ e.warn(`Can't resolve package.json for dev dependency ${n} of ${s}`);
614
650
  continue;
615
651
  }
616
- const b = f.dirname(w);
617
- p.push(S(b, e, "devDependency"));
652
+ const l = f.dirname(a);
653
+ o.push(A(l, e, "devDependency"));
618
654
  }
619
- return { name: n, version: o, type: i, dependencies: p, root: s, context: t };
655
+ return {
656
+ name: i.name,
657
+ version: i.version,
658
+ type: i.type,
659
+ dependencies: o,
660
+ root: s,
661
+ context: t
662
+ };
620
663
  }
621
- function Ee(s, e) {
664
+ function $e(s, e) {
622
665
  return f.resolve(e, s, "tengo", "lib");
623
666
  }
624
- function $e(s, e) {
667
+ function Ne(s, e) {
625
668
  return f.resolve(e, s, "tengo", "tpl");
626
669
  }
627
- function Ne(s, e) {
670
+ function Se(s, e) {
628
671
  return f.resolve(e, s, "tengo", "software");
629
672
  }
630
673
  function ke(s, e) {
631
674
  return f.resolve(e, s, "tengo", "asset");
632
675
  }
633
- function Se(s, e, t) {
634
- for (const w of t.dependencies)
635
- Se(s, e, w);
676
+ function Te(s, e, t) {
677
+ for (const y of t.dependencies)
678
+ Te(s, e, y);
636
679
  if (t.context === "root")
637
680
  return;
638
- const r = Ee("dist", t.root), n = $e("dist", t.root), o = Ne("dist", t.root), i = ke("dist", t.root), a = k(r) === "dir", l = k(n) === "dir", p = k(o) === "dir", d = k(i) === "dir";
639
- if (!a && !l && !p && !d)
681
+ const r = $e("dist", t.root), i = Ne("dist", t.root), o = Se("dist", t.root), n = ke("dist", t.root), a = S(r) === "dir", l = S(i) === "dir", d = S(o) === "dir", g = S(n) === "dir";
682
+ if (!a && !l && !d && !g)
640
683
  return;
641
- const u = { name: t.name, version: t.version };
642
- a && at(s, u, "dist", r, e), l && lt(s, u, "dist", n, e), p && ct(s, u, "dist", o, e), d && dt(s, u, "dist", i, e);
684
+ const m = { name: t.name, version: t.version };
685
+ a && ut(s, m, "dist", r, e), l && mt(s, m, "dist", i, e), d && ht(s, m, "dist", o, e), g && gt(s, m, "dist", n, e);
643
686
  }
644
- function at(s, e, t, r, n) {
645
- for (const o of m.readdirSync(r)) {
646
- const i = f.resolve(r, o);
647
- if (!o.endsWith(W)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
687
+ function ut(s, e, t, r, i) {
688
+ for (const o of p.readdirSync(r)) {
689
+ const n = f.resolve(r, o);
690
+ if (!o.endsWith(H)) throw new Error(`unexpected file in 'lib' folder: ${n}`);
648
691
  const a = {
649
692
  type: "library",
650
693
  pkg: e.name,
651
- id: o.slice(0, o.length - W.length),
694
+ id: o.slice(0, o.length - H.length),
652
695
  version: e.version
653
- }, l = ve(s, t, i, a, !0);
654
- if (n.addLib(l), s.debug(`Adding dependency ${g(a)} from ${i}`), l.dependencies.length > 0) {
696
+ }, l = Ee(s, t, n, a, !0);
697
+ if (i.addLib(l), s.debug(`Adding dependency ${u(a)} from ${n}`), l.dependencies.length > 0) {
655
698
  s.debug("Dependencies:");
656
- for (const p of l.dependencies) s.debug(` - ${h(p)}`);
699
+ for (const d of l.dependencies) s.debug(` - ${h(d)}`);
657
700
  }
658
701
  }
659
702
  }
660
- function lt(s, e, t, r, n) {
661
- for (const o of m.readdirSync(r)) {
662
- const i = f.resolve(r, o);
663
- if (!o.endsWith(U)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
703
+ function mt(s, e, t, r, i) {
704
+ for (const o of p.readdirSync(r)) {
705
+ const n = f.resolve(r, o);
706
+ if (!o.endsWith(G)) throw new Error(`unexpected file in 'tpl' folder: ${n}`);
664
707
  const a = {
665
708
  type: "template",
666
709
  pkg: e.name,
667
- id: o.slice(0, o.length - U.length),
710
+ id: o.slice(0, o.length - G.length),
668
711
  version: e.version
669
- }, l = new we(t, a, { content: m.readFileSync(i) });
670
- n.addTemplate(l), s.debug(`Adding dependency ${g(a)} from ${i}`);
712
+ }, l = We(t, a, p.readFileSync(n));
713
+ i.addTemplate(Ue(l)), s.debug(`Adding dependency ${u(a)} from ${n}`);
671
714
  }
672
715
  }
673
- function ct(s, e, t, r, n) {
674
- for (const o of m.readdirSync(r)) {
675
- const i = f.resolve(r, o);
676
- if (!o.endsWith(z))
677
- throw new Error(`unexpected file in 'software' folder: ${i}`);
716
+ function ht(s, e, t, r, i) {
717
+ for (const o of p.readdirSync(r)) {
718
+ const n = f.resolve(r, o);
719
+ if (!o.endsWith(W))
720
+ throw new Error(`unexpected file in 'software' folder: ${n}`);
678
721
  const a = {
679
722
  type: "software",
680
723
  pkg: e.name,
681
- id: o.slice(0, o.length - z.length),
724
+ id: o.slice(0, o.length - W.length),
682
725
  version: e.version
683
- }, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
684
- s.debug(`Adding dependency ${g(a)} from ${i}`), n.addSoftware(l);
726
+ }, l = p.readFileSync(n).toString(), d = new oe(
727
+ t,
728
+ a,
729
+ re(l),
730
+ l,
731
+ n,
732
+ [],
733
+ []
734
+ );
735
+ s.debug(`Adding dependency ${u(a)} from ${n}`), i.addSoftware(d);
685
736
  }
686
737
  }
687
- function dt(s, e, t, r, n) {
688
- for (const o of m.readdirSync(r)) {
689
- const i = f.resolve(r, o);
690
- if (!o.endsWith(_))
691
- throw new Error(`unexpected file in 'asset' folder: ${i}`);
738
+ function gt(s, e, t, r, i) {
739
+ for (const o of p.readdirSync(r)) {
740
+ const n = f.resolve(r, o);
741
+ if (!o.endsWith(U))
742
+ throw new Error(`unexpected file in 'asset' folder: ${n}`);
692
743
  const a = {
693
744
  type: "asset",
694
745
  pkg: e.name,
695
- id: o.slice(0, o.length - _.length),
746
+ id: o.slice(0, o.length - U.length),
696
747
  version: e.version
697
- }, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
698
- s.debug(`Adding dependency ${g(a)} from ${i}`), n.addAsset(l);
748
+ }, l = p.readFileSync(n).toString(), d = new oe(
749
+ t,
750
+ a,
751
+ re(l),
752
+ l,
753
+ n,
754
+ [],
755
+ []
756
+ );
757
+ s.debug(`Adding dependency ${u(a)} from ${n}`), i.addAsset(d);
699
758
  }
700
759
  }
701
- function M(s, e, t, r, n) {
760
+ function L(s, e, t, r, i) {
702
761
  const o = [];
703
- for (const i of m.readdirSync(f.join(r, n))) {
704
- const a = f.join(n, i), l = f.join(r, a);
705
- if (k(l) === "dir") {
706
- const b = M(s, e, t, r, a);
762
+ for (const n of p.readdirSync(f.join(r, i))) {
763
+ const a = f.join(i, n), l = f.join(r, a);
764
+ if (S(l) === "dir") {
765
+ const b = L(s, e, t, r, a);
707
766
  o.push(...b);
708
767
  continue;
709
768
  }
710
- const p = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = ft(e, p.replaceAll(f.sep, "."));
711
- if (!d) {
712
- s.info(`Skipping unknown file type: ${p}`);
769
+ const d = n === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, g = wt(e, d.replaceAll(f.sep, "."));
770
+ if (!g) {
771
+ s.info(`Skipping unknown file type: ${d}`);
713
772
  continue;
714
773
  }
715
- const u = f.resolve(r, a);
716
- s.debug(`Parsing ${g(d)} from ${u}`);
717
- const w = ve(s, t, u, d, !0);
718
- if (w.dependencies.length > 0) {
774
+ const m = f.resolve(r, a);
775
+ s.debug(`Parsing ${u(g)} from ${m}`);
776
+ const y = Ee(s, t, m, g, !0);
777
+ if (y.dependencies.length > 0) {
719
778
  s.debug("Detected dependencies:");
720
- for (const b of w.dependencies) s.debug(` - ${h(b)}`);
779
+ for (const b of y.dependencies) s.debug(` - ${h(b)}`);
721
780
  }
722
- o.push(w);
781
+ o.push(y);
723
782
  }
724
783
  return o;
725
784
  }
726
785
  function ne(s, e, t) {
727
- const r = new ze(t);
728
- return Se(s, r, e), r;
786
+ const r = new Ke(t);
787
+ return Te(s, r, e), r;
729
788
  }
730
- function ft(s, e) {
789
+ function wt(s, e) {
731
790
  const t = { pkg: s.name, version: s.version };
732
- return e.endsWith(B) ? {
791
+ return e.endsWith(_) ? {
733
792
  ...t,
734
- id: e.substring(0, e.length - B.length),
793
+ id: e.substring(0, e.length - _.length),
735
794
  type: "library"
736
- } : e.endsWith(q) ? {
795
+ } : e.endsWith(z) ? {
737
796
  ...t,
738
- id: e.substring(0, e.length - q.length),
797
+ id: e.substring(0, e.length - z.length),
739
798
  type: "template"
740
- } : e.endsWith(K) ? {
799
+ } : e.endsWith(q) ? {
741
800
  ...t,
742
- id: e.substring(0, e.length - K.length),
801
+ id: e.substring(0, e.length - q.length),
743
802
  type: "software"
744
- } : e.endsWith(V) ? {
803
+ } : e.endsWith(B) ? {
745
804
  ...t,
746
- id: e.substring(0, e.length - V.length),
805
+ id: e.substring(0, e.length - B.length),
747
806
  type: "asset"
748
- } : e.endsWith(ge) ? {
807
+ } : e.endsWith(he) ? {
749
808
  ...t,
750
- id: e.substring(0, e.length - ge.length),
809
+ id: e.substring(0, e.length - he.length),
751
810
  type: "test"
752
811
  } : null;
753
812
  }
754
- function pt(s, e) {
755
- const t = S(process.cwd(), s), r = ne(s, t, e), n = M(s, t, e, "src", "");
756
- if (n.length === 0) {
757
- const i = [];
758
- for (const a of it)
759
- i.push(`*${a}`);
760
- s.error(`Nothing to compile. Looked for ${i.join(", ")}`), process.exit(1);
813
+ function yt(s, e, t) {
814
+ const r = ne(s, e, t), i = L(s, e, t, "src", "");
815
+ if (i.length === 0) {
816
+ const n = [];
817
+ for (const a of dt)
818
+ n.push(`*${a}`);
819
+ s.error(`Nothing to compile. Looked for ${n.join(", ")}`), process.exit(1);
761
820
  }
762
- s.info(`Compiling '${e}'...`);
763
- const o = r.compileAndAdd(n);
821
+ s.info(`Compiling '${t}'...`);
822
+ const o = r.compileAndAdd(i);
764
823
  return s.debug("Done."), o;
765
824
  }
766
- function ut(s, e, t) {
825
+ function bt(s, e, t) {
767
826
  if (e.libs.length > 0) {
768
- const r = Ee(t, ".");
769
- m.mkdirSync(r, { recursive: !0 });
770
- for (const n of e.libs) {
771
- const o = f.resolve(r, n.fullName.id + W);
772
- s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
827
+ const r = $e(t, ".");
828
+ p.mkdirSync(r, { recursive: !0 });
829
+ for (const i of e.libs) {
830
+ const o = f.resolve(r, i.fullName.id + H);
831
+ s.info(` - writing ${o}`), p.writeFileSync(o, i.src);
773
832
  }
774
833
  }
775
834
  if (e.templates.length > 0) {
776
- const r = $e(t, ".");
777
- m.mkdirSync(r, { recursive: !0 });
778
- for (const n of e.templates) {
779
- const o = f.resolve(r, n.fullName.id + U);
780
- s.info(` - writing ${o}`), m.writeFileSync(o, n.content);
835
+ const r = Ne(t, ".");
836
+ p.mkdirSync(r, { recursive: !0 });
837
+ for (const i of e.templates) {
838
+ const o = f.resolve(r, i.fullName.id + G);
839
+ s.info(` - writing ${o}`), p.writeFileSync(o, Me(i.data));
781
840
  }
782
841
  }
783
842
  if (e.software.length > 0) {
784
- const r = Ne(t, ".");
785
- m.mkdirSync(r, { recursive: !0 });
786
- for (const n of e.software) {
787
- const o = f.resolve(r, n.fullName.id + z);
788
- s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
843
+ const r = Se(t, ".");
844
+ p.mkdirSync(r, { recursive: !0 });
845
+ for (const i of e.software) {
846
+ const o = f.resolve(r, i.fullName.id + W);
847
+ s.info(` - writing ${o}`), p.writeFileSync(o, i.src);
789
848
  }
790
849
  }
791
850
  if (e.assets.length > 0) {
792
851
  const r = ke(t, ".");
793
- m.mkdirSync(r, { recursive: !0 });
794
- for (const n of e.software) {
795
- const o = f.resolve(r, n.fullName.id + _);
796
- s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
852
+ p.mkdirSync(r, { recursive: !0 });
853
+ for (const i of e.software) {
854
+ const o = f.resolve(r, i.fullName.id + U);
855
+ s.info(` - writing ${o}`), p.writeFileSync(o, i.src);
797
856
  }
798
857
  }
799
858
  }
@@ -803,7 +862,7 @@ const ie = {
803
862
  default: "info",
804
863
  options: ["error", "warn", "info", "debug"]
805
864
  })
806
- }, mt = {
865
+ }, vt = {
807
866
  "generate-tags": F.boolean({
808
867
  description: "generate tags, default false",
809
868
  default: !1
@@ -819,55 +878,59 @@ const ie = {
819
878
  multiple: !0,
820
879
  delimiter: ","
821
880
  })
822
- }, A = class A extends v {
881
+ }, k = class k extends v {
823
882
  async run() {
824
- const { flags: e } = await this.parse(A), t = E(e["log-level"]), r = S(process.cwd(), t), n = pt(t, "dist");
825
- ut(t, n, "dist"), t.info("");
826
- let o = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
883
+ const { flags: e } = await this.parse(k), t = E(e["log-level"]), r = A(process.cwd(), t), i = yt(t, r, "dist");
884
+ bt(t, i, "dist"), t.info("Template Pack build done.");
885
+ const { dts: o, cjs: n, mjs: a } = Et(i);
886
+ await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", n), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", n), await x.writeFile("dist/index.mjs", a)), $t(e), e["generate-tags"] && Nt(t, e), t.info("Template Pack build done.");
887
+ }
888
+ };
889
+ c(k, "description", "build tengo sources into single distributable pack file"), c(k, "examples", ["<%= config.bin %> <%= command.id %>"]), c(k, "flags", {
890
+ ...ie,
891
+ ...vt
892
+ });
893
+ let K = k;
894
+ function Et(s) {
895
+ let e = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
827
896
  `;
828
- o += `declare type TplName = ${n.templates.map((d) => '"' + d.fullName.id + '"').join(" | ")};
829
- `, o += `declare const Templates: Record<TplName, TemplateFromFile>;
830
- `, o += `export { Templates };
897
+ e += `declare type TplName = ${s.templates.map((n) => '"' + n.fullName.id + '"').join(" | ")};
898
+ `, e += `declare const Templates: Record<TplName, TemplateFromFile>;
899
+ `, e += `export { Templates };
831
900
  `;
832
- let i = `module.exports = { Templates: {
833
- `, a = `import { resolve } from 'node:path';
901
+ let t = `module.exports = { Templates: {
902
+ `, r = `import { resolve } from 'node:path';
834
903
  export const Templates = {
835
904
  `;
836
- const l = n.templates.map(
837
- (d) => ` '${d.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${d.fullName.id}.plj.gz') }`
838
- ).join(`,
839
- `), p = n.templates.map(
840
- (d) => ` '${d.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${d.fullName.id}.plj.gz') }`
841
- ).join(`,
905
+ const i = s.templates.map(
906
+ (n) => ` '${n.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${n.fullName.id}.plj.gz') }`
907
+ ).join(`,
908
+ `), o = s.templates.map(
909
+ (n) => ` '${n.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${n.fullName.id}.plj.gz') }`
910
+ ).join(`,
842
911
  `);
843
- i += l, a += p, i += `
912
+ return t += i, r += o, t += `
844
913
  }};
845
- `, a += `
846
- };
847
- `, 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.");
848
- }
914
+ `, r += `
849
915
  };
850
- c(A, "description", "build tengo sources into single distributable pack file"), c(A, "examples", ["<%= config.bin %> <%= command.id %>"]), c(A, "flags", {
851
- ...ie,
852
- ...mt
853
- });
854
- let X = A;
855
- function gt(s) {
916
+ `, { dts: e, cjs: t, mjs: r };
917
+ }
918
+ function $t(s) {
856
919
  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(","));
857
920
  }
858
- function ht(s, e) {
921
+ function Nt(s, e) {
859
922
  var a;
860
- const t = f.resolve(e["tags-file"]), r = f.dirname(t), n = e["tags-additional-args"], o = wt(r);
923
+ const t = f.resolve(e["tags-file"]), r = f.dirname(t), i = e["tags-additional-args"], o = St(r);
861
924
  s.info(
862
- `Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
925
+ `Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${i.join('" "')}".
863
926
  Found ${o.length} tengo files...`
864
927
  );
865
- const i = xe(
928
+ const n = Fe(
866
929
  "ctags",
867
930
  [
868
931
  "-f",
869
932
  t,
870
- ...n,
933
+ ...i,
871
934
  "--langdef=tengo",
872
935
  "--map-tengo=+.tengo",
873
936
  "--kinddef-tengo=f,function,function",
@@ -883,7 +946,7 @@ Found ${o.length} tengo files...`
883
946
  cwd: r
884
947
  }
885
948
  );
886
- if ((a = i.error) != null && a.message.includes("ENOENT")) {
949
+ if ((a = n.error) != null && a.message.includes("ENOENT")) {
887
950
  console.log(`
888
951
  pl-tengo can create tags for tengo autocompletion,
889
952
  but the program should be installed
@@ -894,25 +957,25 @@ For vscode, you should also install ctags extension:
894
957
  https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
895
958
  return;
896
959
  }
897
- yt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
960
+ kt(n, "failed to generate ctags"), s.info("Generation of tags is done.");
898
961
  }
899
- function wt(s) {
900
- const e = m.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
962
+ function St(s) {
963
+ const e = p.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
901
964
  return e.forEach((r) => {
902
965
  if (!r.isDirectory() && r.name.endsWith(".tengo")) {
903
- const n = f.join(r.parentPath, r.name).replace(s, ".");
904
- t.push(n);
966
+ const i = f.join(r.parentPath, r.name).replace(s, ".");
967
+ t.push(i);
905
968
  }
906
969
  }), t;
907
970
  }
908
- function yt(s, e) {
971
+ function kt(s, e) {
909
972
  s.error && console.log(s.error);
910
973
  const t = e;
911
974
  s.status !== 0 && console.log(`WARN: ${t} the build will continue as-is`);
912
975
  }
913
976
  function ae(s, e) {
914
- const t = S(process.cwd(), s), r = M(s, t, "dist", "src", ""), n = ne(s, t, "dist");
915
- for (const o of n.allLibs())
977
+ const t = A(process.cwd(), s), r = L(s, t, "dist", "src", ""), i = ne(s, t, "dist");
978
+ for (const o of i.allLibs())
916
979
  s.debug(
917
980
  `Dumping to pl-tester: ${h(o.fullName)}`
918
981
  ), e.write(JSON.stringify(o) + `
@@ -922,7 +985,7 @@ function ae(s, e) {
922
985
  `Dumping to pl-tester: ${h(o.fullName)}`
923
986
  ), e.write(JSON.stringify(o) + `
924
987
  `));
925
- for (const o of n.allTemplates())
988
+ for (const o of i.allTemplates())
926
989
  s.debug(
927
990
  `Dumping to pl-tester: ${h(o.fullName)}`
928
991
  ), e.write(JSON.stringify(o) + `
@@ -932,7 +995,7 @@ function ae(s, e) {
932
995
  `Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`
933
996
  ), e.write(JSON.stringify(o) + `
934
997
  `));
935
- for (const o of n.allSoftware())
998
+ for (const o of i.allSoftware())
936
999
  s.debug(
937
1000
  `Dumping to pl-tester: ${h(o.fullName)}`
938
1001
  ), e.write(JSON.stringify(o) + `
@@ -942,7 +1005,7 @@ function ae(s, e) {
942
1005
  `Dumping to pl-tester: ${h(o.fullName)}`
943
1006
  ), e.write(JSON.stringify(o) + `
944
1007
  `));
945
- for (const o of n.allAssets())
1008
+ for (const o of i.allAssets())
946
1009
  s.debug(
947
1010
  `Dumping to pl-tester: ${h(o.fullName)}`
948
1011
  ), e.write(JSON.stringify(o) + `
@@ -958,46 +1021,46 @@ function ae(s, e) {
958
1021
  ), e.write(JSON.stringify(o) + `
959
1022
  `));
960
1023
  }
961
- function bt(s, e, t) {
962
- const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
1024
+ function Tt(s, e, t) {
1025
+ const r = A(process.cwd(), s), i = L(s, r, "dist", "src", "");
963
1026
  if (!e) {
964
- for (const i of n)
965
- i.fullName.type === "library" && t.write(JSON.stringify(i) + `
1027
+ for (const n of i)
1028
+ n.fullName.type === "library" && t.write(JSON.stringify(n) + `
966
1029
  `);
967
1030
  return;
968
1031
  }
969
1032
  const o = ne(s, r, "dist");
970
- for (const i of n)
971
- i.fullName.type === "library" && o.addLib(i);
972
- for (const i of o.allLibs())
973
- t.write(JSON.stringify(i) + `
1033
+ for (const n of i)
1034
+ n.fullName.type === "library" && o.addLib(n);
1035
+ for (const n of o.allLibs())
1036
+ t.write(JSON.stringify(n) + `
974
1037
  `);
975
1038
  }
976
1039
  function P(s, e, t) {
977
- const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
978
- for (const o of n)
1040
+ const r = A(process.cwd(), s), i = L(s, r, "dist", "src", "");
1041
+ for (const o of i)
979
1042
  o.fullName.type === t && e.write(JSON.stringify(o) + `
980
1043
  `);
981
1044
  }
982
- function vt(s, e) {
1045
+ function At(s, e) {
983
1046
  P(s, e, "template");
984
1047
  }
985
- function Et(s, e) {
1048
+ function Dt(s, e) {
986
1049
  P(s, e, "software");
987
1050
  }
988
- function $t(s, e) {
1051
+ function Ot(s, e) {
989
1052
  P(s, e, "asset");
990
1053
  }
991
- function Nt(s, e) {
1054
+ function xt(s, e) {
992
1055
  P(s, e, "test");
993
1056
  }
994
1057
  function Ae(s, ...e) {
995
- const t = Fe(s, e, { stdio: ["pipe", "inherit", "inherit"] });
1058
+ const t = Re(s, e, { stdio: ["pipe", "inherit", "inherit"] });
996
1059
  return t.stdin.on("error", (r) => {
997
1060
  r.code;
998
1061
  }), t;
999
1062
  }
1000
- function Te(s) {
1063
+ function De(s) {
1001
1064
  return new Promise((e, t) => {
1002
1065
  s.on("close", (r) => {
1003
1066
  e(r);
@@ -1008,23 +1071,23 @@ function Te(s) {
1008
1071
  }
1009
1072
  const $ = class $ extends v {
1010
1073
  async run() {
1011
- const { flags: e, argv: t } = await this.parse($), r = E(e["log-level"]), n = t.length == 0 ? ["./src"] : t, o = Ae(
1012
- he,
1074
+ const { flags: e, argv: t } = await this.parse($), r = E(e["log-level"]), i = t.length == 0 ? ["./src"] : t, o = Ae(
1075
+ we,
1013
1076
  "check",
1014
1077
  "--log-level",
1015
1078
  e["log-level"],
1016
1079
  "--artifacts",
1017
1080
  "-",
1018
- ...n
1081
+ ...i
1019
1082
  );
1020
1083
  try {
1021
1084
  ae(r, o.stdin);
1022
- } catch (i) {
1023
- r.error(i);
1085
+ } catch (n) {
1086
+ r.error(n);
1024
1087
  } finally {
1025
1088
  o.stdin.end();
1026
- const i = await Te(o);
1027
- process.exit(i);
1089
+ const n = await De(o);
1090
+ process.exit(n);
1028
1091
  }
1029
1092
  }
1030
1093
  };
@@ -1032,11 +1095,11 @@ c($, "description", "check tengo sources for language processor an"), // static
1032
1095
  // "log-level": Args.string({description: 'logging level'}),
1033
1096
  // }
1034
1097
  c($, "strict", !1), c($, "flags", { ...ie }), c($, "examples", ["<%= config.bin %> <%= command.id %>"]);
1035
- let Z = $;
1098
+ let V = $;
1036
1099
  const N = class N extends v {
1037
1100
  async run() {
1038
- const { flags: e } = await this.parse(N), t = E(e["log-level"]), r = this.argv.length == 0 ? ["./src"] : this.argv, n = Ae(
1039
- he,
1101
+ const { flags: e } = await this.parse(N), t = E(e["log-level"]), r = this.argv.length == 0 ? ["./src"] : this.argv, i = Ae(
1102
+ we,
1040
1103
  "run",
1041
1104
  "--log-level",
1042
1105
  e["log-level"],
@@ -1045,40 +1108,40 @@ const N = class N extends v {
1045
1108
  ...r
1046
1109
  );
1047
1110
  try {
1048
- ae(t, n.stdin);
1111
+ ae(t, i.stdin);
1049
1112
  } catch (o) {
1050
1113
  t.error(o);
1051
1114
  } finally {
1052
- n.stdin.end();
1053
- const o = await Te(n);
1115
+ i.stdin.end();
1116
+ const o = await De(i);
1054
1117
  process.exit(o);
1055
1118
  }
1056
1119
  }
1057
1120
  };
1058
1121
  c(N, "description", "run tengo unit tests (.test.tengo)"), c(N, "strict", !1), c(N, "flags", { ...ie }), c(N, "examples", ["<%= config.bin %> <%= command.id %>"]);
1059
- let H = N;
1060
- class Y extends v {
1122
+ let X = N;
1123
+ class Z extends v {
1061
1124
  async run() {
1062
1125
  const e = E();
1063
1126
  ae(e, D);
1064
1127
  }
1065
1128
  }
1066
- c(Y, "description", "parse sources in current package and dump all found artifacts to stdout"), c(Y, "examples", [
1129
+ c(Z, "description", "parse sources in current package and dump all found artifacts to stdout"), c(Z, "examples", [
1067
1130
  "<%= config.bin %> <%= command.id %>"
1068
1131
  ]);
1069
- class Q extends v {
1132
+ class Y extends v {
1070
1133
  async run() {
1071
1134
  const e = E();
1072
- $t(e, D);
1135
+ Ot(e, D);
1073
1136
  }
1074
1137
  }
1075
- c(Q, "description", "parse sources in current package and dump all found assets to stdout"), c(Q, "examples", [
1138
+ c(Y, "description", "parse sources in current package and dump all found assets to stdout"), c(Y, "examples", [
1076
1139
  "<%= config.bin %> <%= command.id %>"
1077
1140
  ]);
1078
1141
  const T = class T extends v {
1079
1142
  async run() {
1080
1143
  const { flags: e } = await this.parse(T), t = E();
1081
- bt(t, e.deps, D);
1144
+ Tt(t, e.deps, D);
1082
1145
  }
1083
1146
  };
1084
1147
  c(T, "description", "parse sources in current package and dump all found libs to stdout"), c(T, "examples", [
@@ -1086,46 +1149,46 @@ c(T, "description", "parse sources in current package and dump all found libs to
1086
1149
  ]), c(T, "flags", {
1087
1150
  deps: F.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
1088
1151
  });
1089
- let ee = T;
1090
- class te extends v {
1152
+ let Q = T;
1153
+ class ee extends v {
1091
1154
  async run() {
1092
1155
  const e = E();
1093
- Et(e, D);
1156
+ Dt(e, D);
1094
1157
  }
1095
1158
  }
1096
- c(te, "description", "parse sources in current package and dump all found software to stdout"), c(te, "examples", [
1159
+ c(ee, "description", "parse sources in current package and dump all found software to stdout"), c(ee, "examples", [
1097
1160
  "<%= config.bin %> <%= command.id %>"
1098
1161
  ]);
1099
- class se extends v {
1162
+ class te extends v {
1100
1163
  async run() {
1101
1164
  const e = E();
1102
- vt(e, D);
1165
+ At(e, D);
1103
1166
  }
1104
1167
  }
1105
- c(se, "description", "parse sources in current package and dump all found templates to stdout"), c(se, "examples", [
1168
+ c(te, "description", "parse sources in current package and dump all found templates to stdout"), c(te, "examples", [
1106
1169
  "<%= config.bin %> <%= command.id %>"
1107
1170
  ]);
1108
- class oe extends v {
1171
+ class se extends v {
1109
1172
  async run() {
1110
1173
  const e = E();
1111
- Nt(e, D);
1174
+ xt(e, D);
1112
1175
  }
1113
1176
  }
1114
- c(oe, "description", "parse sources in current package and dump all found tests to stdout"), c(oe, "examples", [
1177
+ c(se, "description", "parse sources in current package and dump all found tests to stdout"), c(se, "examples", [
1115
1178
  "<%= config.bin %> <%= command.id %>"
1116
1179
  ]);
1117
- const Rt = {
1118
- build: X,
1119
- check: Z,
1120
- test: H,
1121
- "dump:all": Y,
1122
- "dump:assets": Q,
1123
- "dump:libs": ee,
1124
- "dump:software": te,
1125
- "dump:templates": se,
1126
- "dump:tests": oe
1180
+ const Gt = {
1181
+ build: K,
1182
+ check: V,
1183
+ test: X,
1184
+ "dump:all": Z,
1185
+ "dump:assets": Y,
1186
+ "dump:libs": Q,
1187
+ "dump:software": ee,
1188
+ "dump:templates": te,
1189
+ "dump:tests": se
1127
1190
  };
1128
1191
  export {
1129
- Rt as COMMANDS
1192
+ Gt as COMMANDS
1130
1193
  };
1131
1194
  //# sourceMappingURL=index.mjs.map