@platforma-sdk/tengo-builder 1.19.1 → 2.0.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,96 +1,96 @@
1
- var xe = Object.defineProperty;
2
- var Fe = (s, e, t) => e in s ? xe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var l = (s, e, t) => Fe(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { spawnSync as Oe, spawn as Re } from "node:child_process";
5
- import { Flags as F, Command as $ } from "@oclif/core";
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";
5
+ import { Flags as F, Command as v } from "@oclif/core";
6
6
  import * as f from "node:path";
7
- import * as p from "node:fs";
8
- import { readFileSync as Me } from "node:fs";
9
- import * as G from "winston";
10
- import { parseTemplate as Le, serializeTemplate as je } from "@milaboratories/pl-model-backend";
7
+ import * as m from "node:fs";
8
+ import { readFileSync as Re } from "node:fs";
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";
11
12
  import * as x from "node:fs/promises";
12
- import { TengoTesterBinaryPath as we } from "@milaboratories/tengo-tester";
13
+ import { TengoTesterBinaryPath as he } from "@milaboratories/tengo-tester";
13
14
  import { stdout as D } from "node:process";
14
- function O(s) {
15
+ function R(s) {
15
16
  throw new Error("Unexpected object: " + s);
16
17
  }
17
- function N(s = "debug") {
18
- return G.createLogger({
18
+ function E(s = "debug") {
19
+ return O.createLogger({
19
20
  level: s,
20
- format: G.format.printf(({ level: e, message: t }) => `${e.padStart(6, " ")}: ${t}`),
21
+ format: O.format.combine(
22
+ O.format.errors({ stack: !0 }),
23
+ O.format.printf(({ level: e, message: t, stack: r }) => {
24
+ const n = `${e.padStart(6, " ")}: ${t}`;
25
+ return r ? `${n}
26
+ ${r}` : n;
27
+ })
28
+ ),
21
29
  transports: [
22
- new G.transports.Console({
30
+ new O.transports.Console({
23
31
  stderrLevels: ["error", "warn", "info", "debug"],
24
32
  handleExceptions: !0
25
33
  })
26
34
  ]
27
35
  });
28
36
  }
29
- function Ie() {
30
- let s = process.cwd();
31
- for (; s; ) {
32
- const e = f.join(s, "node_modules");
33
- if (p.existsSync(e)) return e;
34
- const t = f.resolve(s, "..");
35
- if (t === s) break;
36
- s = t;
37
- }
38
- throw new Error("Unable to find node_modules directory.");
39
- }
40
- function E(s) {
37
+ function k(s) {
41
38
  try {
42
- const e = p.statSync(s);
39
+ const e = m.statSync(s);
43
40
  return e.isDirectory() ? "dir" : e.isFile() ? "file" : e.isSymbolicLink() ? "link" : "unknown";
44
41
  } catch (e) {
45
42
  const t = e;
46
- if (t.code == "ENOENT") return "absent";
43
+ if (t.code == "ENOENT" || t.code == "ENOTDIR") return "absent";
47
44
  throw t;
48
45
  }
49
46
  }
50
- function Ce(s) {
47
+ function Ie(s) {
51
48
  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());
52
49
  }
53
- function ce(s) {
50
+ function le(s) {
54
51
  return `${s.type}||${s.pkg}||${s.id}`;
55
52
  }
56
- function m(s) {
53
+ function g(s) {
57
54
  return `${s.type}:${s.pkg}:${s.id}:${s.version}`;
58
55
  }
59
- function g(s) {
56
+ function h(s) {
60
57
  return `${s.type}:${s.pkg}:${s.id}`;
61
58
  }
62
- function de(s, e) {
59
+ function ce(s, e) {
63
60
  return s.type == e.type && s.pkg == e.pkg && s.id == e.id;
64
61
  }
65
- function h(s) {
62
+ function C(s, e) {
63
+ return s.type == e.type && s.pkg == e.pkg && s.id == e.id && s.version == e.version;
64
+ }
65
+ function y(s) {
66
66
  return `${s.pkg}:${s.id}`;
67
67
  }
68
- function j(s) {
69
- return { name: h(s), version: s.version };
68
+ function I(s) {
69
+ return { name: y(s), version: s.version };
70
70
  }
71
- function Ge(s) {
71
+ function Je(s) {
72
72
  const e = s.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
73
73
  if (!e) throw new Error(`malformed artifact name: ${s.name}`);
74
74
  return { pkg: e.groups.pkg, id: e.groups.id, version: s.version };
75
75
  }
76
- function fe(s) {
76
+ function de(s) {
77
77
  return `${s.pkg}:${s.id}:${s.version}`;
78
78
  }
79
- class ye {
79
+ class we {
80
80
  constructor(e, t, r) {
81
- l(this, "data");
82
- l(this, "content");
81
+ c(this, "data");
82
+ c(this, "content");
83
83
  this.compileMode = e, this.fullName = t;
84
84
  let { data: n, content: o } = r;
85
85
  if (n === void 0 && o === void 0)
86
86
  throw new Error("Neither data nor content is provided for template constructor");
87
87
  if (n !== void 0 && o !== void 0)
88
88
  throw new Error("Both data and content are provided for template constructor");
89
- n === void 0 && (n = Le(o)), o === void 0 && (o = je(n));
90
- const i = Ge(n);
89
+ n === void 0 && (n = je(o)), o === void 0 && (o = Me(n));
90
+ const i = Je(n);
91
91
  if (i.pkg !== t.pkg || i.id !== t.id || i.version !== t.version)
92
92
  throw new Error(
93
- `Compiled template name don't match it's package and file names: ${fe(i)} != ${fe(t)}`
93
+ `Compiled template name don't match it's package and file names: ${de(i)} != ${de(t)}`
94
94
  );
95
95
  this.data = n, this.content = o;
96
96
  }
@@ -98,17 +98,17 @@ class ye {
98
98
  return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
99
99
  }
100
100
  }
101
- class U {
101
+ class ye {
102
102
  constructor(e) {
103
- l(this, "map", /* @__PURE__ */ new Map());
103
+ c(this, "map", /* @__PURE__ */ new Map());
104
104
  this.nameExtractor = e;
105
105
  }
106
106
  add(e, t = !0) {
107
- const r = ce(this.nameExtractor(e)), n = this.map.get(r);
107
+ const r = le(this.nameExtractor(e)), n = this.map.get(r);
108
108
  return n && !t || this.map.set(r, e), n;
109
109
  }
110
110
  get(e) {
111
- return this.map.get(ce(e));
111
+ return this.map.get(le(e));
112
112
  }
113
113
  get array() {
114
114
  const e = [];
@@ -118,21 +118,21 @@ class U {
118
118
  this.map.forEach((t) => e(t, this.nameExtractor(t)));
119
119
  }
120
120
  }
121
- function Ue() {
122
- return new U((s) => s);
121
+ function Pe() {
122
+ return new ye((s) => s);
123
123
  }
124
- class I {
124
+ class J {
125
125
  constructor(e) {
126
- l(this, "dev");
127
- l(this, "dist");
128
- this.nameExtractor = e, this.dev = new U(e), this.dist = new U(e);
126
+ // private readonly dev: ArtifactMap<T>;
127
+ c(this, "dist");
128
+ this.dist = new ye(e);
129
129
  }
130
130
  add(e, t, r = !0) {
131
131
  switch (e) {
132
132
  case "dist":
133
133
  return this.dist.add(t, r);
134
134
  default:
135
- O(e);
135
+ R(e);
136
136
  }
137
137
  }
138
138
  get(e, t) {
@@ -140,7 +140,7 @@ class I {
140
140
  case "dist":
141
141
  return this.dist.get(t);
142
142
  default:
143
- O(e);
143
+ R(e);
144
144
  }
145
145
  }
146
146
  array(e) {
@@ -151,7 +151,7 @@ class I {
151
151
  this.dist.forEach((r, n) => t(this.get(e, n) ?? r, n));
152
152
  }
153
153
  }
154
- function Je(s, e) {
154
+ function Ge(s, e) {
155
155
  for (const t of s)
156
156
  switch (t.name) {
157
157
  case "hash_override": {
@@ -160,7 +160,7 @@ function Je(s, e) {
160
160
  }
161
161
  }
162
162
  }
163
- function Pe(s, e) {
163
+ function Ue(s, e) {
164
164
  for (const t of s)
165
165
  switch (t.name) {
166
166
  case "hash_override":
@@ -175,7 +175,7 @@ function We(s) {
175
175
  "hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value."
176
176
  );
177
177
  const e = s[0].toLowerCase();
178
- if (!Ce(e))
178
+ if (!Ie(e))
179
179
  throw new Error(
180
180
  `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
181
  );
@@ -183,57 +183,57 @@ function We(s) {
183
183
  }
184
184
  class ze {
185
185
  constructor(e) {
186
- l(this, "libs", new I((e) => e.fullName));
187
- l(this, "software", new I((e) => e.fullName));
188
- l(this, "assets", new I((e) => e.fullName));
189
- l(this, "templates", new I((e) => e.fullName));
186
+ c(this, "libs", new J((e) => e.fullName));
187
+ c(this, "software", new J((e) => e.fullName));
188
+ c(this, "assets", new J((e) => e.fullName));
189
+ c(this, "templates", new J((e) => e.fullName));
190
190
  this.compileMode = e;
191
191
  }
192
192
  populateTemplateDataFromDependencies(e, t, r, n) {
193
193
  for (const o of r)
194
194
  switch (o.type) {
195
195
  case "library": {
196
- const i = this.getLibOrError(o), a = n.indexOf(h(o));
196
+ const i = this.getLibOrError(o), a = n.indexOf(y(o));
197
197
  if (a >= 0) {
198
- const u = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${h(o)}`;
199
- throw new Error(u);
198
+ const p = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${y(o)}`;
199
+ throw new Error(p);
200
200
  }
201
- const c = {
202
- ...j(i.fullName),
201
+ const l = {
202
+ ...I(i.fullName),
203
203
  src: i.src
204
204
  };
205
- Pe(i.compilerOptions), t.libs[h(o)] = c, this.populateTemplateDataFromDependencies(e, t, i.dependencies, [...n, h(o)]);
205
+ Ue(i.compilerOptions), t.libs[y(o)] = l, this.populateTemplateDataFromDependencies(e, t, i.dependencies, [...n, y(o)]);
206
206
  break;
207
207
  }
208
208
  case "software": {
209
209
  const i = this.getSoftwareOrError(o);
210
- t.software[h(o)] = {
211
- ...j(i.fullName),
210
+ t.software[y(o)] = {
211
+ ...I(i.fullName),
212
212
  src: i.src
213
213
  };
214
214
  break;
215
215
  }
216
216
  case "asset": {
217
217
  const i = this.getAssetOrError(o);
218
- t.software[h(o)] = {
219
- ...j(i.fullName),
218
+ t.software[y(o)] = {
219
+ ...I(i.fullName),
220
220
  src: i.src
221
221
  };
222
222
  break;
223
223
  }
224
224
  case "template": {
225
- if (de(e, o))
225
+ if (ce(e, o))
226
226
  continue;
227
227
  const i = this.getTemplateOrError(o);
228
- t.templates[h(o)] = i.data;
228
+ t.templates[y(o)] = i.data;
229
229
  break;
230
230
  }
231
231
  case "test":
232
232
  throw new Error(
233
- `dependencies tree error: tests should never be part of template: ${g(o)} is dependency of ${h(e)}`
233
+ `dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${y(e)}`
234
234
  );
235
235
  default:
236
- O(o.type);
236
+ R(o.type);
237
237
  }
238
238
  }
239
239
  /** This method assumes that all dependencies are already added to the compiler's context */
@@ -242,22 +242,22 @@ class ze {
242
242
  throw new Error("unexpected source type");
243
243
  const t = {
244
244
  type: "pl.tengo-template.v2",
245
- ...j(e.fullName),
245
+ ...I(e.fullName),
246
246
  templates: {},
247
247
  libs: {},
248
248
  software: {},
249
249
  assets: {},
250
250
  src: e.src
251
251
  };
252
- Je(e.compilerOptions, t), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []);
253
- const r = new ye(e.compileMode, e.fullName, { data: t });
252
+ Ge(e.compilerOptions, t), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []);
253
+ const r = new we(e.compileMode, e.fullName, { data: t });
254
254
  return this.addTemplate(r), r;
255
255
  }
256
256
  addLib(e) {
257
257
  const t = this.libs.add(e.compileMode, e, !1);
258
- if (t)
258
+ if (t && !C(e.fullName, t.fullName))
259
259
  throw new Error(
260
- `compiler already contain such library: adding = ${m(e.fullName)}, contains = ${m(t.fullName)}`
260
+ `compiler already contain such library: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
261
261
  );
262
262
  }
263
263
  allLibs() {
@@ -271,14 +271,14 @@ class ze {
271
271
  getLibOrError(e) {
272
272
  const t = this.getLib(e);
273
273
  if (!t)
274
- throw new Error(`library not found: ${h(e)}`);
274
+ throw new Error(`library not found: ${y(e)}`);
275
275
  return t;
276
276
  }
277
277
  addSoftware(e) {
278
278
  const t = this.software.add(e.compileMode, e, !1);
279
- if (t)
279
+ if (t && !C(e.fullName, t.fullName))
280
280
  throw new Error(
281
- `compiler already contain info for software: adding = ${m(e.fullName)}, contains = ${m(t.fullName)}`
281
+ `compiler already contain info for software: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
282
282
  );
283
283
  }
284
284
  allSoftware() {
@@ -292,14 +292,14 @@ class ze {
292
292
  getSoftwareOrError(e) {
293
293
  const t = this.getSoftware(e);
294
294
  if (!t)
295
- throw new Error(`software info not found: ${h(e)}`);
295
+ throw new Error(`software info not found: ${y(e)}`);
296
296
  return t;
297
297
  }
298
298
  addAsset(e) {
299
299
  const t = this.assets.add(e.compileMode, e, !1);
300
- if (t)
300
+ if (t && !C(e.fullName, t.fullName))
301
301
  throw new Error(
302
- `compiler already contain info for asset: adding = ${m(e.fullName)}, contains = ${m(t.fullName)}`
302
+ `compiler already contain info for asset: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
303
303
  );
304
304
  }
305
305
  allAssets() {
@@ -313,14 +313,14 @@ class ze {
313
313
  getAssetOrError(e) {
314
314
  const t = this.getAsset(e);
315
315
  if (!t)
316
- throw new Error(`asset info not found: ${h(e)}`);
316
+ throw new Error(`asset info not found: ${y(e)}`);
317
317
  return t;
318
318
  }
319
319
  addTemplate(e) {
320
320
  const t = this.templates.add(e.compileMode, e, !1);
321
- if (t)
321
+ if (t && !C(e.fullName, t.fullName))
322
322
  throw new Error(
323
- `compiler already contain such template: adding = ${m(e.fullName)}, contains = ${m(t.fullName)}`
323
+ `compiler already contain such template: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
324
324
  );
325
325
  }
326
326
  allTemplates() {
@@ -334,7 +334,7 @@ class ze {
334
334
  getTemplateOrError(e) {
335
335
  const t = this.getTemplate(e);
336
336
  if (!t)
337
- throw new Error(`template not found: ${h(e)}`);
337
+ throw new Error(`template not found: ${y(e)}`);
338
338
  return t;
339
339
  }
340
340
  getArtefact(e) {
@@ -350,16 +350,16 @@ class ze {
350
350
  case "test":
351
351
  return;
352
352
  default:
353
- O(e.type);
353
+ R(e.type);
354
354
  }
355
355
  }
356
356
  checkLibs() {
357
357
  this.libs.forEach(this.compileMode, (e) => {
358
358
  for (const t of e.dependencies) {
359
359
  if (t.type === "test")
360
- throw new Error(`test should never be dependency of production code: ${g(t)} test is dependency of ${m(e.fullName)}`);
360
+ throw new Error(`test should never be dependency of production code: ${h(t)} test is dependency of ${g(e.fullName)}`);
361
361
  if (!this.getArtefact(t))
362
- throw new Error(`unresolved dependency ${g(t)} for ${m(e.fullName)}`);
362
+ throw new Error(`unresolved dependency ${h(t)} for ${g(e.fullName)}`);
363
363
  }
364
364
  });
365
365
  }
@@ -372,15 +372,15 @@ class ze {
372
372
  const n = [];
373
373
  for (const o of r) {
374
374
  const i = o.dependencies.filter(
375
- (a) => !this.getArtefact(a) && !(o.fullName.type === "template" && de(o.fullName, a))
375
+ (a) => !this.getArtefact(a) && !(o.fullName.type === "template" && ce(o.fullName, a))
376
376
  );
377
377
  if (i.length > 0) {
378
- let a = `Unsatisfied dependencies in ${m(o.fullName)}:
378
+ let a = `Unsatisfied dependencies in ${g(o.fullName)}:
379
379
  `;
380
- for (const c of i)
381
- a += ` - ${g(c)}
380
+ for (const l of i)
381
+ a += ` - ${h(l)}
382
382
  `;
383
- n.push({ src: o, err: Error(a) });
383
+ n.push({ src: o, err: new Error(a) });
384
384
  continue;
385
385
  }
386
386
  switch (o.fullName.type) {
@@ -398,17 +398,17 @@ class ze {
398
398
  const a = this.compileAndAddTemplate(o);
399
399
  t.templates.push(a);
400
400
  } catch (a) {
401
- const c = a;
402
- let u = `Unsatisfied dependencies in ${m(o.fullName)}:
401
+ const l = a;
402
+ let p = `Unsatisfied dependencies in ${g(o.fullName)}:
403
403
  `;
404
- u += ` - ${c.message}
405
- `, n.push({ src: o, err: Error(u) });
404
+ p += ` - ${l.message}
405
+ `, n.push({ src: o, err: Error(p) });
406
406
  }
407
407
  break;
408
408
  case "test":
409
409
  break;
410
410
  default:
411
- O(o.fullName.type);
411
+ R(o.fullName.type);
412
412
  }
413
413
  }
414
414
  if (r.length === n.length) {
@@ -423,10 +423,10 @@ ${i.err.message}`;
423
423
  return t;
424
424
  }
425
425
  }
426
- const pe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (s, e) => new RegExp(
426
+ const fe = "[_a-zA-Z][_a-zA-Z0-9]*", j = (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 = /\/\*.*?\*\//g, Ye = /^\s*(\/\/)/, He = /^\s*\/\*/, Qe = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, et = new RegExp(
429
- `\\b(?<importName>${pe}(\\.${pe})*)${be.source}`
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
430
  ), tt = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, st = (s) => {
431
431
  const e = s.split(" "), t = e[0].split(":");
432
432
  if (t.length != 2)
@@ -438,39 +438,39 @@ const pe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (s, e) => new RegExp(
438
438
  args: e.slice(1)
439
439
  };
440
440
  };
441
- class oe {
441
+ class re {
442
442
  constructor(e, t, r, n, o, i) {
443
443
  this.compileMode = e, this.fullName = t, this.src = r, this.srcName = n, this.dependencies = o, this.compilerOptions = i;
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 } = ot(s, o, r, n);
448
- return new oe(e, r, a, t, i.array, c);
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);
449
449
  }
450
450
  function ot(s, e, t, r) {
451
- const n = Ue(), o = [], i = e.split(`
451
+ const n = Pe(), o = [], i = e.split(`
452
452
  `), a = [];
453
- let c = {
453
+ let l = {
454
454
  isInCommentBlock: !1,
455
455
  canDetectOptions: !0,
456
456
  tplDepREs: /* @__PURE__ */ new Map(),
457
457
  lineNo: 0
458
458
  };
459
- for (const u of i) {
460
- c.lineNo++;
459
+ for (const p of i) {
460
+ l.lineNo++;
461
461
  try {
462
462
  const d = rt(
463
463
  s,
464
- u,
465
- c,
464
+ p,
465
+ l,
466
466
  t.pkg,
467
467
  r
468
468
  );
469
- a.push(d.line), c = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
469
+ a.push(d.line), l = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
470
470
  } catch (d) {
471
- const w = d;
472
- throw new Error(`[line ${c.lineNo} in ${m(t)}]: ${w.message}
473
- ${u}`, { cause: w });
471
+ const u = d;
472
+ throw new Error(`[line ${l.lineNo} in ${g(t)}]: ${u.message}
473
+ ${p}`, { cause: u });
474
474
  }
475
475
  }
476
476
  return {
@@ -481,26 +481,26 @@ function ot(s, e, t, r) {
481
481
  };
482
482
  }
483
483
  function rt(s, e, t, r, n) {
484
- if (e = e.replaceAll(Xe, ""), t.isInCommentBlock)
484
+ if (e = e.replaceAll(Ze, ""), t.isInCommentBlock)
485
485
  return Qe.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
486
- if (Ze.exec(e)) {
486
+ if (Ve.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
491
  return { line: e, context: t, artifact: void 0, option: st(e) };
492
492
  }
493
- if (Ke.exec(e) && t.canDetectOptions)
493
+ if (Xe.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 (Ye.test(e))
497
+ if (He.test(e))
498
498
  return { line: "", context: t, artifact: void 0, option: void 0 };
499
- if (He.exec(e))
499
+ if (Ye.exec(e))
500
500
  return t.isInCommentBlock = !0, { line: "", context: t, artifact: void 0, option: void 0 };
501
501
  if (e.includes("/*"))
502
502
  throw new Error("malformed multiline comment");
503
- if (Ve.exec(e))
503
+ if (Ke.exec(e))
504
504
  return { line: e, context: t, artifact: void 0, option: void 0 };
505
505
  t.canDetectOptions = !1;
506
506
  const o = be.exec(e);
@@ -512,29 +512,29 @@ function rt(s, e, t, r, n) {
512
512
  ["software", qe(i.alias)]
513
513
  ]), { line: e, context: t, artifact: void 0, option: void 0 };
514
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", ue(i.alias)],
516
- ["software", me(i.alias)]
515
+ ["template", pe(i.alias)],
516
+ ["software", ue(i.alias)]
517
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", ue(i.alias)],
519
- ["software", me(i.alias)],
518
+ ["template", pe(i.alias)],
519
+ ["software", ue(i.alias)],
520
520
  ["asset", Be(i.alias)]
521
521
  ]));
522
- const a = ge(i.module, "library", r);
522
+ const a = me(i.module, "library", r);
523
523
  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
524
  }
525
525
  if (t.tplDepREs.size > 0)
526
526
  for (const [i, a] of t.tplDepREs)
527
- for (const [c, u] of a) {
528
- const d = u.exec(e);
527
+ for (const [l, p] of a) {
528
+ const d = p.exec(e);
529
529
  if (!d || !d.groups)
530
530
  continue;
531
- const { fnCall: w, templateName: v, fnName: y } = d.groups;
532
- if (!w || !v || !y)
531
+ const { fnCall: u, templateName: w, fnName: b } = d.groups;
532
+ if (!u || !w || !b)
533
533
  throw Error("failed to parse template import statement");
534
- const b = ge(v, c, r);
535
- if (!b)
536
- throw Error(`failed to parse artifact name in ${y} import statement`);
537
- return e = e.replace(w, `${y}("${b.pkg}:${b.id}")`), { line: e, context: t, artifact: b, option: void 0 };
534
+ const L = me(w, l, r);
535
+ if (!L)
536
+ 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 };
538
538
  }
539
539
  return { line: e, context: t, artifact: void 0, option: void 0 };
540
540
  }
@@ -550,7 +550,7 @@ function nt(s) {
550
550
  alias: t
551
551
  };
552
552
  }
553
- function ge(s, e, t) {
553
+ function me(s, e, t) {
554
554
  const r = tt.exec(s);
555
555
  if (!r)
556
556
  return;
@@ -565,9 +565,58 @@ function ge(s, e, t) {
565
565
  );
566
566
  return { type: e, pkg: n ?? t, id: o };
567
567
  }
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];
569
- function M() {
570
- return JSON.parse(p.readFileSync("package.json").toString());
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) {
570
+ if (!f.isAbsolute(s))
571
+ 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);
579
+ if (t) {
580
+ let n = 0;
581
+ do {
582
+ const o = f.join(t, "package.json");
583
+ if (k(o) === "file")
584
+ return o;
585
+ n++, t = f.dirname(t);
586
+ } while (n < 7 && f.basename(t) !== "node_modules");
587
+ }
588
+ const r = Ce(s, `${e}/package.json`);
589
+ if (r.result === void 0) {
590
+ if (r.err === "ERR_PACKAGE_PATH_NOT_EXPORTED")
591
+ return;
592
+ throw new Error(`Can't resolve package.json for package ${e ?? "."} relative to ${s}`);
593
+ }
594
+ return r.result;
595
+ }
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"));
608
+ }
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}`);
614
+ continue;
615
+ }
616
+ const b = f.dirname(w);
617
+ p.push(S(b, e, "devDependency"));
618
+ }
619
+ return { name: n, version: o, type: i, dependencies: p, root: s, context: t };
571
620
  }
572
621
  function Ee(s, e) {
573
622
  return f.resolve(e, s, "tengo", "lib");
@@ -578,140 +627,132 @@ function $e(s, e) {
578
627
  function Ne(s, e) {
579
628
  return f.resolve(e, s, "tengo", "software");
580
629
  }
581
- function Se(s, e) {
630
+ function ke(s, e) {
582
631
  return f.resolve(e, s, "tengo", "asset");
583
632
  }
584
- function ke(s, e, t, r, n = !1) {
585
- const o = f.resolve(r, "package.json");
586
- if (E(o) !== "file") {
587
- for (const ae of p.readdirSync(r)) {
588
- const De = E(f.join(r, ae)) === "link", le = f.resolve(r, ae);
589
- E(le) === "dir" && ke(s, e, t, le, De);
590
- }
633
+ function Se(s, e, t) {
634
+ for (const w of t.dependencies)
635
+ Se(s, e, w);
636
+ if (t.context === "root")
591
637
  return;
592
- }
593
- const i = Ee("dist", r), a = $e("dist", r), c = Ne("dist", r), u = Se("dist", r), d = E(i) === "dir", w = E(a) === "dir", v = E(c) === "dir", y = E(u) === "dir";
594
- if (!d && !w && !v && !y)
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)
595
640
  return;
596
- const b = JSON.parse(p.readFileSync(o).toString());
597
- if (b.name !== t.name) {
598
- if (E(f.resolve(r, "node_modules")) === "dir" && n)
599
- throw new Error(
600
- `nested node_modules is a sign of library dependencies version incompatibility in ${r}`
601
- );
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);
603
- }
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);
604
643
  }
605
644
  function at(s, e, t, r, n) {
606
- for (const o of p.readdirSync(r)) {
645
+ for (const o of m.readdirSync(r)) {
607
646
  const i = f.resolve(r, o);
608
- if (!o.endsWith(P)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
647
+ if (!o.endsWith(W)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
609
648
  const a = {
610
649
  type: "library",
611
650
  pkg: e.name,
612
- id: o.slice(0, o.length - P.length),
651
+ id: o.slice(0, o.length - W.length),
613
652
  version: e.version
614
- }, c = ve(s, t, i, a, !0);
615
- if (n.addLib(c), s.debug(`Adding dependency ${m(a)} from ${i}`), c.dependencies.length > 0) {
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) {
616
655
  s.debug("Dependencies:");
617
- for (const u of c.dependencies) s.debug(` - ${g(u)}`);
656
+ for (const p of l.dependencies) s.debug(` - ${h(p)}`);
618
657
  }
619
658
  }
620
659
  }
621
660
  function lt(s, e, t, r, n) {
622
- for (const o of p.readdirSync(r)) {
661
+ for (const o of m.readdirSync(r)) {
623
662
  const i = f.resolve(r, o);
624
- if (!o.endsWith(J)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
663
+ if (!o.endsWith(U)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
625
664
  const a = {
626
665
  type: "template",
627
666
  pkg: e.name,
628
- id: o.slice(0, o.length - J.length),
667
+ id: o.slice(0, o.length - U.length),
629
668
  version: e.version
630
- }, c = new ye(t, a, { content: p.readFileSync(i) });
631
- n.addTemplate(c), s.debug(`Adding dependency ${m(a)} from ${i}`);
669
+ }, l = new we(t, a, { content: m.readFileSync(i) });
670
+ n.addTemplate(l), s.debug(`Adding dependency ${g(a)} from ${i}`);
632
671
  }
633
672
  }
634
673
  function ct(s, e, t, r, n) {
635
- for (const o of p.readdirSync(r)) {
674
+ for (const o of m.readdirSync(r)) {
636
675
  const i = f.resolve(r, o);
637
- if (!o.endsWith(W))
676
+ if (!o.endsWith(z))
638
677
  throw new Error(`unexpected file in 'software' folder: ${i}`);
639
678
  const a = {
640
679
  type: "software",
641
680
  pkg: e.name,
642
- id: o.slice(0, o.length - W.length),
681
+ id: o.slice(0, o.length - z.length),
643
682
  version: e.version
644
- }, c = new oe(t, a, p.readFileSync(i).toString(), i, [], []);
645
- s.debug(`Adding dependency ${m(a)} from ${i}`), n.addSoftware(c);
683
+ }, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
684
+ s.debug(`Adding dependency ${g(a)} from ${i}`), n.addSoftware(l);
646
685
  }
647
686
  }
648
687
  function dt(s, e, t, r, n) {
649
- for (const o of p.readdirSync(r)) {
688
+ for (const o of m.readdirSync(r)) {
650
689
  const i = f.resolve(r, o);
651
- if (!o.endsWith(z))
690
+ if (!o.endsWith(_))
652
691
  throw new Error(`unexpected file in 'asset' folder: ${i}`);
653
692
  const a = {
654
693
  type: "asset",
655
694
  pkg: e.name,
656
- id: o.slice(0, o.length - z.length),
695
+ id: o.slice(0, o.length - _.length),
657
696
  version: e.version
658
- }, c = new oe(t, a, p.readFileSync(i).toString(), i, [], []);
659
- s.debug(`Adding dependency ${m(a)} from ${i}`), n.addAsset(c);
697
+ }, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
698
+ s.debug(`Adding dependency ${g(a)} from ${i}`), n.addAsset(l);
660
699
  }
661
700
  }
662
- function L(s, e, t, r, n) {
701
+ function M(s, e, t, r, n) {
663
702
  const o = [];
664
- for (const i of p.readdirSync(f.join(r, n))) {
665
- const a = f.join(n, i), c = f.join(r, a);
666
- if (E(c) === "dir") {
667
- const y = L(s, e, t, r, a);
668
- o.push(...y);
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);
707
+ o.push(...b);
669
708
  continue;
670
709
  }
671
- const u = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = ft(e, u.replaceAll(f.sep, "."));
672
- if (!d)
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}`);
673
713
  continue;
674
- const w = f.resolve(r, a);
675
- s.debug(`Parsing ${m(d)} from ${w}`);
676
- const v = ve(s, t, w, d, !0);
677
- if (v.dependencies.length > 0) {
714
+ }
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) {
678
719
  s.debug("Detected dependencies:");
679
- for (const y of v.dependencies) s.debug(` - ${g(y)}`);
720
+ for (const b of w.dependencies) s.debug(` - ${h(b)}`);
680
721
  }
681
- o.push(v);
722
+ o.push(w);
682
723
  }
683
724
  return o;
684
725
  }
685
- function re(s, e, t) {
726
+ function ne(s, e, t) {
686
727
  const r = new ze(t);
687
- return ke(s, r, e, Ie()), r;
728
+ return Se(s, r, e), r;
688
729
  }
689
730
  function ft(s, e) {
690
731
  const t = { pkg: s.name, version: s.version };
691
- return e.endsWith(q) ? {
732
+ return e.endsWith(B) ? {
692
733
  ...t,
693
- id: e.substring(0, e.length - q.length),
734
+ id: e.substring(0, e.length - B.length),
694
735
  type: "library"
695
- } : e.endsWith(_) ? {
736
+ } : e.endsWith(q) ? {
696
737
  ...t,
697
- id: e.substring(0, e.length - _.length),
738
+ id: e.substring(0, e.length - q.length),
698
739
  type: "template"
699
- } : e.endsWith(B) ? {
740
+ } : e.endsWith(K) ? {
700
741
  ...t,
701
- id: e.substring(0, e.length - B.length),
742
+ id: e.substring(0, e.length - K.length),
702
743
  type: "software"
703
744
  } : e.endsWith(V) ? {
704
745
  ...t,
705
746
  id: e.substring(0, e.length - V.length),
706
747
  type: "asset"
707
- } : e.endsWith(he) ? {
748
+ } : e.endsWith(ge) ? {
708
749
  ...t,
709
- id: e.substring(0, e.length - he.length),
750
+ id: e.substring(0, e.length - ge.length),
710
751
  type: "test"
711
752
  } : null;
712
753
  }
713
754
  function pt(s, e) {
714
- const t = M(), r = re(s, t, e), n = L(s, t, e, "src", "");
755
+ const t = S(process.cwd(), s), r = ne(s, t, e), n = M(s, t, e, "src", "");
715
756
  if (n.length === 0) {
716
757
  const i = [];
717
758
  for (const a of it)
@@ -725,38 +766,38 @@ function pt(s, e) {
725
766
  function ut(s, e, t) {
726
767
  if (e.libs.length > 0) {
727
768
  const r = Ee(t, ".");
728
- p.mkdirSync(r, { recursive: !0 });
769
+ m.mkdirSync(r, { recursive: !0 });
729
770
  for (const n of e.libs) {
730
- const o = f.resolve(r, n.fullName.id + P);
731
- s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
771
+ const o = f.resolve(r, n.fullName.id + W);
772
+ s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
732
773
  }
733
774
  }
734
775
  if (e.templates.length > 0) {
735
776
  const r = $e(t, ".");
736
- p.mkdirSync(r, { recursive: !0 });
777
+ m.mkdirSync(r, { recursive: !0 });
737
778
  for (const n of e.templates) {
738
- const o = f.resolve(r, n.fullName.id + J);
739
- s.info(` - writing ${o}`), p.writeFileSync(o, n.content);
779
+ const o = f.resolve(r, n.fullName.id + U);
780
+ s.info(` - writing ${o}`), m.writeFileSync(o, n.content);
740
781
  }
741
782
  }
742
783
  if (e.software.length > 0) {
743
784
  const r = Ne(t, ".");
744
- p.mkdirSync(r, { recursive: !0 });
785
+ m.mkdirSync(r, { recursive: !0 });
745
786
  for (const n of e.software) {
746
- const o = f.resolve(r, n.fullName.id + W);
747
- s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
787
+ const o = f.resolve(r, n.fullName.id + z);
788
+ s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
748
789
  }
749
790
  }
750
791
  if (e.assets.length > 0) {
751
- const r = Se(t, ".");
752
- p.mkdirSync(r, { recursive: !0 });
792
+ const r = ke(t, ".");
793
+ m.mkdirSync(r, { recursive: !0 });
753
794
  for (const n of e.software) {
754
- const o = f.resolve(r, n.fullName.id + z);
755
- s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
795
+ const o = f.resolve(r, n.fullName.id + _);
796
+ s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
756
797
  }
757
798
  }
758
799
  }
759
- const ne = {
800
+ const ie = {
760
801
  "log-level": F.string({
761
802
  description: "logging level",
762
803
  default: "info",
@@ -778,9 +819,9 @@ const ne = {
778
819
  multiple: !0,
779
820
  delimiter: ","
780
821
  })
781
- }, A = class A extends $ {
822
+ }, A = class A extends v {
782
823
  async run() {
783
- const { flags: e } = await this.parse(A), t = N(e["log-level"]), r = M(), n = pt(t, "dist");
824
+ const { flags: e } = await this.parse(A), t = E(e["log-level"]), r = S(process.cwd(), t), n = pt(t, "dist");
784
825
  ut(t, n, "dist"), t.info("");
785
826
  let o = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
786
827
  `;
@@ -792,25 +833,25 @@ const ne = {
792
833
  `, a = `import { resolve } from 'node:path';
793
834
  export const Templates = {
794
835
  `;
795
- const c = n.templates.map(
836
+ const l = n.templates.map(
796
837
  (d) => ` '${d.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${d.fullName.id}.plj.gz') }`
797
838
  ).join(`,
798
- `), u = n.templates.map(
839
+ `), p = n.templates.map(
799
840
  (d) => ` '${d.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${d.fullName.id}.plj.gz') }`
800
841
  ).join(`,
801
842
  `);
802
- i += c, a += u, i += `
843
+ i += l, a += p, i += `
803
844
  }};
804
845
  `, a += `
805
846
  };
806
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.");
807
848
  }
808
849
  };
809
- l(A, "description", "build tengo sources into single distributable pack file"), l(A, "examples", ["<%= config.bin %> <%= command.id %>"]), l(A, "flags", {
810
- ...ne,
850
+ c(A, "description", "build tengo sources into single distributable pack file"), c(A, "examples", ["<%= config.bin %> <%= command.id %>"]), c(A, "flags", {
851
+ ...ie,
811
852
  ...mt
812
853
  });
813
- let Z = A;
854
+ let X = A;
814
855
  function gt(s) {
815
856
  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(","));
816
857
  }
@@ -821,7 +862,7 @@ function ht(s, e) {
821
862
  `Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
822
863
  Found ${o.length} tengo files...`
823
864
  );
824
- const i = Oe(
865
+ const i = xe(
825
866
  "ctags",
826
867
  [
827
868
  "-f",
@@ -856,7 +897,7 @@ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
856
897
  yt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
857
898
  }
858
899
  function wt(s) {
859
- const e = p.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
900
+ const e = m.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
860
901
  return e.forEach((r) => {
861
902
  if (!r.isDirectory() && r.name.endsWith(".tengo")) {
862
903
  const n = f.join(r.parentPath, r.name).replace(s, ".");
@@ -869,89 +910,89 @@ function yt(s, e) {
869
910
  const t = e;
870
911
  s.status !== 0 && console.log(`WARN: ${t} the build will continue as-is`);
871
912
  }
872
- function ie(s, e) {
873
- const t = M(), r = L(s, t, "dist", "src", ""), n = re(s, t, "dist");
913
+ function ae(s, e) {
914
+ const t = S(process.cwd(), s), r = M(s, t, "dist", "src", ""), n = ne(s, t, "dist");
874
915
  for (const o of n.allLibs())
875
916
  s.debug(
876
- `Dumping to pl-tester: ${g(o.fullName)}`
917
+ `Dumping to pl-tester: ${h(o.fullName)}`
877
918
  ), e.write(JSON.stringify(o) + `
878
919
  `);
879
920
  for (const o of r)
880
921
  o.fullName.type === "library" && (s.debug(
881
- `Dumping to pl-tester: ${g(o.fullName)}`
922
+ `Dumping to pl-tester: ${h(o.fullName)}`
882
923
  ), e.write(JSON.stringify(o) + `
883
924
  `));
884
925
  for (const o of n.allTemplates())
885
926
  s.debug(
886
- `Dumping to pl-tester: ${g(o.fullName)}`
927
+ `Dumping to pl-tester: ${h(o.fullName)}`
887
928
  ), e.write(JSON.stringify(o) + `
888
929
  `);
889
930
  for (const o of r)
890
931
  o.fullName.type === "template" && (s.debug(
891
- `Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`
932
+ `Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`
892
933
  ), e.write(JSON.stringify(o) + `
893
934
  `));
894
935
  for (const o of n.allSoftware())
895
936
  s.debug(
896
- `Dumping to pl-tester: ${g(o.fullName)}`
937
+ `Dumping to pl-tester: ${h(o.fullName)}`
897
938
  ), e.write(JSON.stringify(o) + `
898
939
  `);
899
940
  for (const o of r)
900
941
  o.fullName.type === "software" && (s.debug(
901
- `Dumping to pl-tester: ${g(o.fullName)}`
942
+ `Dumping to pl-tester: ${h(o.fullName)}`
902
943
  ), e.write(JSON.stringify(o) + `
903
944
  `));
904
945
  for (const o of n.allAssets())
905
946
  s.debug(
906
- `Dumping to pl-tester: ${g(o.fullName)}`
947
+ `Dumping to pl-tester: ${h(o.fullName)}`
907
948
  ), e.write(JSON.stringify(o) + `
908
949
  `);
909
950
  for (const o of r)
910
951
  o.fullName.type === "asset" && (s.debug(
911
- `Dumping to pl-tester: ${g(o.fullName)}`
952
+ `Dumping to pl-tester: ${h(o.fullName)}`
912
953
  ), e.write(JSON.stringify(o) + `
913
954
  `));
914
955
  for (const o of r)
915
956
  o.fullName.type === "test" && (s.debug(
916
- `Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`
957
+ `Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`
917
958
  ), e.write(JSON.stringify(o) + `
918
959
  `));
919
960
  }
920
961
  function bt(s, e, t) {
921
- const r = M(), n = L(s, r, "dist", "src", "");
962
+ const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
922
963
  if (!e) {
923
964
  for (const i of n)
924
965
  i.fullName.type === "library" && t.write(JSON.stringify(i) + `
925
966
  `);
926
967
  return;
927
968
  }
928
- const o = re(s, r, "dist");
969
+ const o = ne(s, r, "dist");
929
970
  for (const i of n)
930
971
  i.fullName.type === "library" && o.addLib(i);
931
972
  for (const i of o.allLibs())
932
973
  t.write(JSON.stringify(i) + `
933
974
  `);
934
975
  }
935
- function C(s, e, t) {
936
- const r = M(), n = L(s, r, "dist", "src", "");
976
+ function P(s, e, t) {
977
+ const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
937
978
  for (const o of n)
938
979
  o.fullName.type === t && e.write(JSON.stringify(o) + `
939
980
  `);
940
981
  }
941
982
  function vt(s, e) {
942
- C(s, e, "template");
983
+ P(s, e, "template");
943
984
  }
944
985
  function Et(s, e) {
945
- C(s, e, "software");
986
+ P(s, e, "software");
946
987
  }
947
988
  function $t(s, e) {
948
- C(s, e, "asset");
989
+ P(s, e, "asset");
949
990
  }
950
991
  function Nt(s, e) {
951
- C(s, e, "test");
992
+ P(s, e, "test");
952
993
  }
953
994
  function Ae(s, ...e) {
954
- const t = Re(s, e, { stdio: ["pipe", "inherit", "inherit"] });
995
+ const t = Fe(s, e, { stdio: ["pipe", "inherit", "inherit"] });
955
996
  return t.stdin.on("error", (r) => {
956
997
  r.code;
957
998
  }), t;
@@ -965,10 +1006,10 @@ function Te(s) {
965
1006
  });
966
1007
  });
967
1008
  }
968
- const S = class S extends $ {
1009
+ const $ = class $ extends v {
969
1010
  async run() {
970
- const { flags: e, argv: t } = await this.parse(S), r = N(e["log-level"]), n = t.length == 0 ? ["./src"] : t, o = Ae(
971
- we,
1011
+ const { flags: e, argv: t } = await this.parse($), r = E(e["log-level"]), n = t.length == 0 ? ["./src"] : t, o = Ae(
1012
+ he,
972
1013
  "check",
973
1014
  "--log-level",
974
1015
  e["log-level"],
@@ -977,7 +1018,7 @@ const S = class S extends $ {
977
1018
  ...n
978
1019
  );
979
1020
  try {
980
- ie(r, o.stdin);
1021
+ ae(r, o.stdin);
981
1022
  } catch (i) {
982
1023
  r.error(i);
983
1024
  } finally {
@@ -987,15 +1028,15 @@ const S = class S extends $ {
987
1028
  }
988
1029
  }
989
1030
  };
990
- l(S, "description", "check tengo sources for language processor an"), // static override args = {
1031
+ c($, "description", "check tengo sources for language processor an"), // static override args = {
991
1032
  // "log-level": Args.string({description: 'logging level'}),
992
1033
  // }
993
- l(S, "strict", !1), l(S, "flags", { ...ne }), l(S, "examples", ["<%= config.bin %> <%= command.id %>"]);
994
- let K = S;
995
- const k = class k extends $ {
1034
+ c($, "strict", !1), c($, "flags", { ...ie }), c($, "examples", ["<%= config.bin %> <%= command.id %>"]);
1035
+ let Z = $;
1036
+ const N = class N extends v {
996
1037
  async run() {
997
- const { flags: e } = await this.parse(k), t = N(e["log-level"]), r = this.argv.length == 0 ? ["./src"] : this.argv, n = Ae(
998
- we,
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,
999
1040
  "run",
1000
1041
  "--log-level",
1001
1042
  e["log-level"],
@@ -1004,7 +1045,7 @@ const k = class k extends $ {
1004
1045
  ...r
1005
1046
  );
1006
1047
  try {
1007
- ie(t, n.stdin);
1048
+ ae(t, n.stdin);
1008
1049
  } catch (o) {
1009
1050
  t.error(o);
1010
1051
  } finally {
@@ -1014,75 +1055,75 @@ const k = class k extends $ {
1014
1055
  }
1015
1056
  }
1016
1057
  };
1017
- l(k, "description", "run tengo unit tests (.test.tengo)"), l(k, "strict", !1), l(k, "flags", { ...ne }), l(k, "examples", ["<%= config.bin %> <%= command.id %>"]);
1018
- let X = k;
1019
- class Y extends $ {
1058
+ 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 {
1020
1061
  async run() {
1021
- const e = N();
1022
- ie(e, D);
1062
+ const e = E();
1063
+ ae(e, D);
1023
1064
  }
1024
1065
  }
1025
- l(Y, "description", "parse sources in current package and dump all found artifacts to stdout"), l(Y, "examples", [
1066
+ c(Y, "description", "parse sources in current package and dump all found artifacts to stdout"), c(Y, "examples", [
1026
1067
  "<%= config.bin %> <%= command.id %>"
1027
1068
  ]);
1028
- class H extends $ {
1069
+ class Q extends v {
1029
1070
  async run() {
1030
- const e = N();
1071
+ const e = E();
1031
1072
  $t(e, D);
1032
1073
  }
1033
1074
  }
1034
- l(H, "description", "parse sources in current package and dump all found assets to stdout"), l(H, "examples", [
1075
+ c(Q, "description", "parse sources in current package and dump all found assets to stdout"), c(Q, "examples", [
1035
1076
  "<%= config.bin %> <%= command.id %>"
1036
1077
  ]);
1037
- const T = class T extends $ {
1078
+ const T = class T extends v {
1038
1079
  async run() {
1039
- const { flags: e } = await this.parse(T), t = N();
1080
+ const { flags: e } = await this.parse(T), t = E();
1040
1081
  bt(t, e.deps, D);
1041
1082
  }
1042
1083
  };
1043
- l(T, "description", "parse sources in current package and dump all found libs to stdout"), l(T, "examples", [
1084
+ c(T, "description", "parse sources in current package and dump all found libs to stdout"), c(T, "examples", [
1044
1085
  "<%= config.bin %> <%= command.id %>"
1045
- ]), l(T, "flags", {
1086
+ ]), c(T, "flags", {
1046
1087
  deps: F.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
1047
1088
  });
1048
- let Q = T;
1049
- class ee extends $ {
1089
+ let ee = T;
1090
+ class te extends v {
1050
1091
  async run() {
1051
- const e = N();
1092
+ const e = E();
1052
1093
  Et(e, D);
1053
1094
  }
1054
1095
  }
1055
- l(ee, "description", "parse sources in current package and dump all found software to stdout"), l(ee, "examples", [
1096
+ c(te, "description", "parse sources in current package and dump all found software to stdout"), c(te, "examples", [
1056
1097
  "<%= config.bin %> <%= command.id %>"
1057
1098
  ]);
1058
- class te extends $ {
1099
+ class se extends v {
1059
1100
  async run() {
1060
- const e = N();
1101
+ const e = E();
1061
1102
  vt(e, D);
1062
1103
  }
1063
1104
  }
1064
- l(te, "description", "parse sources in current package and dump all found templates to stdout"), l(te, "examples", [
1105
+ c(se, "description", "parse sources in current package and dump all found templates to stdout"), c(se, "examples", [
1065
1106
  "<%= config.bin %> <%= command.id %>"
1066
1107
  ]);
1067
- class se extends $ {
1108
+ class oe extends v {
1068
1109
  async run() {
1069
- const e = N();
1110
+ const e = E();
1070
1111
  Nt(e, D);
1071
1112
  }
1072
1113
  }
1073
- l(se, "description", "parse sources in current package and dump all found tests to stdout"), l(se, "examples", [
1114
+ c(oe, "description", "parse sources in current package and dump all found tests to stdout"), c(oe, "examples", [
1074
1115
  "<%= config.bin %> <%= command.id %>"
1075
1116
  ]);
1076
1117
  const Rt = {
1077
- build: Z,
1078
- check: K,
1079
- test: X,
1118
+ build: X,
1119
+ check: Z,
1120
+ test: H,
1080
1121
  "dump:all": Y,
1081
- "dump:assets": H,
1082
- "dump:libs": Q,
1083
- "dump:software": ee,
1084
- "dump:templates": te,
1085
- "dump:tests": se
1122
+ "dump:assets": Q,
1123
+ "dump:libs": ee,
1124
+ "dump:software": te,
1125
+ "dump:templates": se,
1126
+ "dump:tests": oe
1086
1127
  };
1087
1128
  export {
1088
1129
  Rt as COMMANDS