elrh-cosca 0.3.1 → 0.3.2

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/README.md CHANGED
@@ -147,6 +147,18 @@ By default the function asks for confirmation before attempting to delete the `t
147
147
 
148
148
  ### List of content checkers
149
149
 
150
+ #### `fileExists`
151
+
152
+ ```ts
153
+ function fileExists(
154
+ targetFile: string
155
+ ): boolean
156
+ ```
157
+
158
+ Checks if the specified `targetFile` exists on FS. Path is resolved relatively to `process.cwd()`. Several checks are in place to prevent accidental and malicious paths being passed in. Path traversal outside of CWD or providing absolute paths is disallowed.
159
+
160
+ If the file exists , the function returns true, false otherwise.
161
+
150
162
  #### `hasJsonKey`
151
163
 
152
164
  ```ts
@@ -1,9 +1,9 @@
1
- import { resolve as Ae, sep as Ca, join as Ps, dirname as Ei } from "node:path";
1
+ import { resolve as we, sep as Ca, join as Ps, dirname as Ei } from "node:path";
2
2
  import { existsSync as be, readFileSync as tt, access as Ia, constants as Na, mkdirSync as Ai, copyFileSync as ka, writeFileSync as Ot, rmSync as La, promises as Oa } from "node:fs";
3
3
  import Da from "node:readline";
4
4
  import Ma from "node:https";
5
5
  import "fs";
6
- function Ve(a) {
6
+ function _e(a) {
7
7
  if (console.warn(a), !a)
8
8
  return { valid: !1, error: "Path cannot be empty" };
9
9
  if (/^[A-Za-z]:/.test(a) || a.startsWith("/"))
@@ -15,14 +15,21 @@ function Ve(a) {
15
15
  return { valid: !1, error: `Path contains mixed separators: '${a}'` };
16
16
  if (/(?:^|[\/\\])\.\.(?:[\/\\]|$)/.test(a))
17
17
  return { valid: !1, error: `Path traversal not allowed: '${a}'` };
18
- const o = Ae(process.cwd(), a), u = Ae(process.cwd());
18
+ const o = we(process.cwd(), a), u = we(process.cwd());
19
19
  return !o.startsWith(u + Ca) && o !== u ? { valid: !1, error: `Path outside of CWD not allowed: '${a}'` } : { valid: !0 };
20
20
  }
21
- function Fl(a, l) {
22
- const r = Ve(a);
21
+ function Fl(a) {
22
+ const l = _e(a);
23
+ if (!l.valid)
24
+ throw new Error(l.error);
25
+ const r = we(process.cwd(), a);
26
+ return be(r);
27
+ }
28
+ function Bl(a, l) {
29
+ const r = _e(a);
23
30
  if (!r.valid)
24
31
  throw new Error(r.error);
25
- const i = Ae(process.cwd(), a);
32
+ const i = we(process.cwd(), a);
26
33
  if (!be(i))
27
34
  throw new Error(`No '${a}' found in project root — cannot check its keys.`);
28
35
  const o = tt(i, "utf8");
@@ -46,16 +53,16 @@ function vi(a, l) {
46
53
  }
47
54
  return !1;
48
55
  }
49
- function Bl(a, l) {
50
- const r = Ve(a);
56
+ function _l(a, l) {
57
+ const r = _e(a);
51
58
  if (!r.valid)
52
59
  throw new Error(r.error);
53
- const i = Ae(process.cwd(), a);
60
+ const i = we(process.cwd(), a);
54
61
  if (!be(i))
55
62
  throw new Error(`No '${a}' found in project root — cannot check its contents.`);
56
63
  return tt(i, "utf8").split(/\r?\n/).map((h) => h.trim()).includes(l.trim());
57
64
  }
58
- async function $e(a, l) {
65
+ async function Ve(a, l) {
59
66
  const r = Da.createInterface({
60
67
  input: l?.input || process.stdin,
61
68
  output: l?.output || process.stdout
@@ -101,17 +108,17 @@ function Ba(a) {
101
108
  }
102
109
  throw new Error(`Cannot find package "${a}" from ${process.cwd()}. Make sure it's installed or linked in this project.`);
103
110
  }
104
- async function _l(a, l, r = !1, i = "") {
105
- if (r || await $e(
111
+ async function jl(a, l, r = !1, i = "") {
112
+ if (r || await Ve(
106
113
  i || `This will create '${l}' file. Continue?`
107
114
  )) {
108
- const { pkg: u, file: h } = Fa(a), d = Ba(u), g = Ae(d, h), x = Ve(l);
115
+ const { pkg: u, file: h } = Fa(a), d = Ba(u), g = we(d, h), x = _e(l);
109
116
  if (!x.valid)
110
117
  throw new Error(x.error);
111
- const S = Ae(process.cwd(), l);
118
+ const S = we(process.cwd(), l);
112
119
  if (!be(g))
113
120
  throw new Error(`Template file not found at ${g}`);
114
- if (be(S) && !(r || await $e(
121
+ if (be(S) && !(r || await Ve(
115
122
  `File '${l}' already exists. Overwrite?`
116
123
  ))) {
117
124
  console.log("Aborted.");
@@ -137,8 +144,8 @@ async function _a(a) {
137
144
  }).on("error", r);
138
145
  });
139
146
  }
140
- async function jl(a, l, r = !1, i = "") {
141
- if (r || await $e(
147
+ async function Rl(a, l, r = !1, i = "") {
148
+ if (r || await Ve(
142
149
  i || `This will create '${l}' file. Continue?`
143
150
  )) {
144
151
  let u;
@@ -148,11 +155,11 @@ async function jl(a, l, r = !1, i = "") {
148
155
  throw new Error(`Failed to fetch template from external source ${a}:
149
156
  ${x}`);
150
157
  }
151
- const h = Ve(l);
158
+ const h = _e(l);
152
159
  if (!h.valid)
153
160
  throw new Error(h.error);
154
- const d = Ae(process.cwd(), l);
155
- if (be(d) && !(r || await $e(
161
+ const d = we(process.cwd(), l);
162
+ if (be(d) && !(r || await Ve(
156
163
  `File '${l}' already exists. Overwrite?`
157
164
  ))) {
158
165
  console.log("Aborted.");
@@ -166,14 +173,14 @@ ${x}`);
166
173
  } else
167
174
  console.log(`Creation of '${l}' skipped.`);
168
175
  }
169
- async function Rl(a, l = !1, r = "") {
170
- if (l || await $e(
176
+ async function Ul(a, l = !1, r = "") {
177
+ if (l || await Ve(
171
178
  r || `This will delete '${a}'. Continue?`
172
179
  )) {
173
- const o = Ve(a);
180
+ const o = _e(a);
174
181
  if (!o.valid)
175
182
  throw new Error(o.error);
176
- const u = Ae(process.cwd(), a);
183
+ const u = we(process.cwd(), a);
177
184
  if (be(u))
178
185
  if (La(u, { recursive: !0, force: !0 }), !be(u))
179
186
  console.log(`'${a}' deleted from project.`);
@@ -184,14 +191,14 @@ async function Rl(a, l = !1, r = "") {
184
191
  } else
185
192
  console.log(`Removing '${a}' skipped.`);
186
193
  }
187
- async function Ul(a, l, r = !1, i = "") {
188
- if (r || await $e(
194
+ async function $l(a, l, r = !1, i = "") {
195
+ if (r || await Ve(
189
196
  i || `This will delete '${l}' from '${a}' file. Continue?`
190
197
  )) {
191
- const u = Ve(a);
198
+ const u = _e(a);
192
199
  if (!u.valid)
193
200
  throw new Error(u.error);
194
- const h = Ae(process.cwd(), a);
201
+ const h = we(process.cwd(), a);
195
202
  if (!be(h))
196
203
  throw new Error(`No '${a}' found in project root — cannot delete its keys.`);
197
204
  const d = tt(h, "utf8");
@@ -325,8 +332,8 @@ function Dt() {
325
332
  } else
326
333
  for (ce.push(_.slice(ye, he)); he < _.length && _[he] === "/"; )
327
334
  he++;
328
- for (var _e, Le = 0, he = ce.length - 1; he >= 0; he--)
329
- _e = ce[he], _e === "." ? ce.splice(he, 1) : _e === ".." ? Le++ : Le > 0 && (_e === "" ? (ce.splice(he + 1, Le), Le = 0) : (ce.splice(he, 2), Le--));
335
+ for (var je, Le = 0, he = ce.length - 1; he >= 0; he--)
336
+ je = ce[he], je === "." ? ce.splice(he, 1) : je === ".." ? Le++ : Le > 0 && (je === "" ? (ce.splice(he + 1, Le), Le = 0) : (ce.splice(he, 2), Le--));
330
337
  return _ = ce.join("/"), _ === "" && (_ = me ? "/" : "."), N ? (N.path = _, u(N)) : _;
331
338
  });
332
339
  a.normalize = g;
@@ -1935,7 +1942,7 @@ function Ha() {
1935
1942
  };
1936
1943
  k.template = new M("`", !0);
1937
1944
  const _ = !0, N = !0, me = !0, ce = !0, ye = !0, he = !0;
1938
- class _e {
1945
+ class je {
1939
1946
  constructor(t, e = {}) {
1940
1947
  this.label = void 0, this.keyword = void 0, this.beforeExpr = void 0, this.startsExpr = void 0, this.rightAssociative = void 0, this.isLoop = void 0, this.isAssign = void 0, this.prefix = void 0, this.postfix = void 0, this.binop = void 0, this.label = t, this.keyword = e.keyword, this.beforeExpr = !!e.beforeExpr, this.startsExpr = !!e.startsExpr, this.rightAssociative = !!e.rightAssociative, this.isLoop = !!e.isLoop, this.isAssign = !!e.isAssign, this.prefix = !!e.prefix, this.postfix = !!e.postfix, this.binop = e.binop != null ? e.binop : null, this.updateContext = null;
1941
1948
  }
@@ -1956,11 +1963,11 @@ function Ha() {
1956
1963
  const V = [], X = [], Y = [], ie = [], ne = [], oe = [];
1957
1964
  function J(p, t = {}) {
1958
1965
  var e, s, n, c;
1959
- return ++z, X.push(p), Y.push((e = t.binop) != null ? e : -1), ie.push((s = t.beforeExpr) != null ? s : !1), ne.push((n = t.startsExpr) != null ? n : !1), oe.push((c = t.prefix) != null ? c : !1), V.push(new _e(p, t)), z;
1966
+ return ++z, X.push(p), Y.push((e = t.binop) != null ? e : -1), ie.push((s = t.beforeExpr) != null ? s : !1), ne.push((n = t.startsExpr) != null ? n : !1), oe.push((c = t.prefix) != null ? c : !1), V.push(new je(p, t)), z;
1960
1967
  }
1961
1968
  function Q(p, t = {}) {
1962
1969
  var e, s, n, c;
1963
- return ++z, Le.set(p, z), X.push(p), Y.push((e = t.binop) != null ? e : -1), ie.push((s = t.beforeExpr) != null ? s : !1), ne.push((n = t.startsExpr) != null ? n : !1), oe.push((c = t.prefix) != null ? c : !1), V.push(new _e("name", t)), z;
1970
+ return ++z, Le.set(p, z), X.push(p), Y.push((e = t.binop) != null ? e : -1), ie.push((s = t.beforeExpr) != null ? s : !1), ne.push((n = t.startsExpr) != null ? n : !1), oe.push((c = t.prefix) != null ? c : !1), V.push(new je("name", t)), z;
1964
1971
  }
1965
1972
  const st = {
1966
1973
  bracketL: J("[", {
@@ -2363,7 +2370,7 @@ function Ha() {
2363
2370
  function Ge(p) {
2364
2371
  return p <= 92;
2365
2372
  }
2366
- function we(p) {
2373
+ function Ee(p) {
2367
2374
  return p >= 58 && p <= 133;
2368
2375
  }
2369
2376
  function _t(p) {
@@ -2414,7 +2421,7 @@ function Ha() {
2414
2421
  function Rt(p) {
2415
2422
  return p >= 24 && p <= 25;
2416
2423
  }
2417
- function je(p) {
2424
+ function Re(p) {
2418
2425
  return V[p];
2419
2426
  }
2420
2427
  V[8].updateContext = (p) => {
@@ -2438,7 +2445,7 @@ function Ha() {
2438
2445
  }
2439
2446
  return !1;
2440
2447
  }
2441
- function Re(p) {
2448
+ function Ue(p) {
2442
2449
  return p < 65 ? p === 36 : p <= 90 ? !0 : p < 97 ? p === 95 : p <= 122 ? !0 : p <= 65535 ? p >= 170 && xn.test(String.fromCharCode(p)) : us(p, Xs);
2443
2450
  }
2444
2451
  function rt(p) {
@@ -2465,7 +2472,7 @@ function Ha() {
2465
2472
  return Pn.has(p);
2466
2473
  }
2467
2474
  function An(p, t, e) {
2468
- return p === 64 && t === 64 && Re(e);
2475
+ return p === 64 && t === 64 && Ue(e);
2469
2476
  }
2470
2477
  const vn = /* @__PURE__ */ new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
2471
2478
  function Cn(p) {
@@ -3257,7 +3264,7 @@ function Ha() {
3257
3264
  parseStatementLike(e) {
3258
3265
  if (this.state.strict && this.isContextual(129)) {
3259
3266
  const n = this.lookahead();
3260
- if (we(n.type)) {
3267
+ if (Ee(n.type)) {
3261
3268
  const c = this.startNode();
3262
3269
  return this.next(), this.flowParseInterface(c);
3263
3270
  }
@@ -3545,9 +3552,9 @@ function Ha() {
3545
3552
  let w = !1;
3546
3553
  if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
3547
3554
  const F = this.parseIdentifier(!0);
3548
- b !== null && !we(this.state.type) ? (e.imported = F, e.importKind = b, e.local = this.cloneIdentifier(F)) : (e.imported = y, e.importKind = null, e.local = this.parseIdentifier());
3555
+ b !== null && !Ee(this.state.type) ? (e.imported = F, e.importKind = b, e.local = this.cloneIdentifier(F)) : (e.imported = y, e.importKind = null, e.local = this.parseIdentifier());
3549
3556
  } else {
3550
- if (b !== null && we(this.state.type))
3557
+ if (b !== null && Ee(this.state.type))
3551
3558
  e.imported = this.parseIdentifier(!0), e.importKind = b;
3552
3559
  else {
3553
3560
  if (s)
@@ -4538,7 +4545,7 @@ function Ha() {
4538
4545
  return;
4539
4546
  }
4540
4547
  if (s === k.j_oTag || s === k.j_cTag) {
4541
- if (Re(e)) {
4548
+ if (Ue(e)) {
4542
4549
  this.jsxReadWord();
4543
4550
  return;
4544
4551
  }
@@ -5373,7 +5380,7 @@ function Ha() {
5373
5380
  if (this.expectPlugin("recordAndTuple"), this.getPluginOption("recordAndTuple", "syntaxType") === "bar")
5374
5381
  throw this.raise(e === 123 ? m.RecordExpressionHashIncorrectStartSyntaxType : m.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
5375
5382
  this.state.pos += 2, e === 123 ? this.finishToken(7) : this.finishToken(1);
5376
- } else Re(e) ? (++this.state.pos, this.finishToken(139, this.readWord1(e))) : e === 92 ? (++this.state.pos, this.finishToken(139, this.readWord1())) : this.finishOp(27, 1);
5383
+ } else Ue(e) ? (++this.state.pos, this.finishToken(139, this.readWord1(e))) : e === 92 ? (++this.state.pos, this.finishToken(139, this.readWord1())) : this.finishOp(27, 1);
5377
5384
  }
5378
5385
  readToken_dot() {
5379
5386
  const t = this.input.charCodeAt(this.state.pos + 1);
@@ -5623,7 +5630,7 @@ function Ha() {
5623
5630
  this.readWord();
5624
5631
  return;
5625
5632
  default:
5626
- if (Re(t)) {
5633
+ if (Ue(t)) {
5627
5634
  this.readWord(t);
5628
5635
  return;
5629
5636
  }
@@ -5698,7 +5705,7 @@ function Ha() {
5698
5705
  ++this.state.pos, n = !0;
5699
5706
  else if (f === 109)
5700
5707
  throw this.raise(m.InvalidDecimal, s);
5701
- if (Re(this.codePointAtPos(this.state.pos)))
5708
+ if (Ue(this.codePointAtPos(this.state.pos)))
5702
5709
  throw this.raise(m.NumberIdentifier, this.state.curPosition());
5703
5710
  if (n) {
5704
5711
  const y = this.input.slice(e, this.state.pos).replace(/[_n]/g, "");
@@ -5725,7 +5732,7 @@ function Ha() {
5725
5732
  this.expectPlugin("decimal", this.state.curPosition()), (f || b) && this.raise(m.InvalidDecimal, s), ++this.state.pos;
5726
5733
  var C = !0;
5727
5734
  }
5728
- if (Re(this.codePointAtPos(this.state.pos)))
5735
+ if (Ue(this.codePointAtPos(this.state.pos)))
5729
5736
  throw this.raise(m.NumberIdentifier, this.state.curPosition());
5730
5737
  const F = this.input.slice(e, this.state.pos).replace(/[_mn]/g, "");
5731
5738
  if (c) {
@@ -5783,7 +5790,7 @@ function Ha() {
5783
5790
  this.state.pos += c <= 65535 ? 1 : 2;
5784
5791
  else if (c === 92) {
5785
5792
  this.state.containsEsc = !0, e += this.input.slice(n, this.state.pos);
5786
- const f = this.state.curPosition(), y = this.state.pos === s ? Re : rt;
5793
+ const f = this.state.curPosition(), y = this.state.pos === s ? Ue : rt;
5787
5794
  if (this.input.charCodeAt(++this.state.pos) !== 117) {
5788
5795
  this.raise(m.MissingUnicodeEscape, this.state.curPosition()), n = this.state.pos - 1;
5789
5796
  continue;
@@ -6932,7 +6939,7 @@ function Ha() {
6932
6939
  startLoc: n
6933
6940
  } = this.state;
6934
6941
  let c, f, y, b;
6935
- const C = we(this.state.type) ? this.lookaheadCharCode() : null;
6942
+ const C = Ee(this.state.type) ? this.lookaheadCharCode() : null;
6936
6943
  if (C === 58)
6937
6944
  c = !0, y = !1, f = this.parseIdentifier(!0), this.expect(14), b = this.tsParseType();
6938
6945
  else if (C === 63) {
@@ -8046,9 +8053,9 @@ function Ha() {
8046
8053
  const W = this.parseIdentifier();
8047
8054
  if (this.isContextual(93)) {
8048
8055
  const K = this.parseIdentifier();
8049
- we(this.state.type) ? (w = !0, y = W, b = s ? this.parseIdentifier() : this.parseModuleExportName(), C = !1) : (b = K, C = !1);
8050
- } else we(this.state.type) ? (C = !1, b = s ? this.parseIdentifier() : this.parseModuleExportName()) : (w = !0, y = W);
8051
- } else we(this.state.type) && (w = !0, s ? (y = this.parseIdentifier(!0), this.isContextual(93) || this.checkReservedWord(y.name, y.loc.start, !0, !0)) : y = this.parseModuleExportName());
8056
+ Ee(this.state.type) ? (w = !0, y = W, b = s ? this.parseIdentifier() : this.parseModuleExportName(), C = !1) : (b = K, C = !1);
8057
+ } else Ee(this.state.type) ? (C = !1, b = s ? this.parseIdentifier() : this.parseModuleExportName()) : (w = !0, y = W);
8058
+ } else Ee(this.state.type) && (w = !0, s ? (y = this.parseIdentifier(!0), this.isContextual(93) || this.checkReservedWord(y.name, y.loc.start, !0, !0)) : y = this.parseModuleExportName());
8052
8059
  w && n && this.raise(s ? H.TypeModifierIsUsedInTypeImports : H.TypeModifierIsUsedInTypeExports, F), e[c] = y, e[f] = b;
8053
8060
  const $ = s ? "importKind" : "exportKind";
8054
8061
  e[$] = w ? "type" : "value", C && this.eatContextual(93) && (e[f] = s ? this.parseIdentifier() : this.parseModuleExportName()), e[f] || (e[f] = this.cloneIdentifier(e[c])), s && this.checkIdentifier(e[f], w ? 4098 : 4096);
@@ -8778,7 +8785,7 @@ function Ha() {
8778
8785
  }
8779
8786
  case 47: {
8780
8787
  const c = this.input.codePointAt(this.nextTokenStart());
8781
- Re(c) || c === 62 ? this.expectOnePlugin(["jsx", "flow", "typescript"]) : this.unexpected();
8788
+ Ue(c) || c === 62 ? this.expectOnePlugin(["jsx", "flow", "typescript"]) : this.unexpected();
8782
8789
  break;
8783
8790
  }
8784
8791
  default:
@@ -9104,7 +9111,7 @@ function Ha() {
9104
9111
  value: n
9105
9112
  } = this.state;
9106
9113
  let c;
9107
- if (we(s))
9114
+ if (Ee(s))
9108
9115
  c = this.parseIdentifier(!0);
9109
9116
  else
9110
9117
  switch (s) {
@@ -9237,7 +9244,7 @@ function Ha() {
9237
9244
  startLoc: s,
9238
9245
  type: n
9239
9246
  } = this.state;
9240
- we(n) ? e = this.state.value : this.unexpected();
9247
+ Ee(n) ? e = this.state.value : this.unexpected();
9241
9248
  const c = Ge(n);
9242
9249
  return t ? c && this.replaceToken(132) : this.checkReservedWord(e, s, c, !1), this.next(), e;
9243
9250
  }
@@ -9482,14 +9489,14 @@ function Ha() {
9482
9489
  end: w
9483
9490
  } = n, C = y + 1, F = i(f.start, 1);
9484
9491
  p.splice(s, 1, new Je({
9485
- type: je(27),
9492
+ type: Re(27),
9486
9493
  value: "#",
9487
9494
  start: y,
9488
9495
  end: C,
9489
9496
  startLoc: f.start,
9490
9497
  endLoc: F
9491
9498
  }), new Je({
9492
- type: je(132),
9499
+ type: Re(132),
9493
9500
  value: b,
9494
9501
  start: C,
9495
9502
  end: w,
@@ -9507,14 +9514,14 @@ function Ha() {
9507
9514
  } = n, C = y + 1, F = i(f.start, 1);
9508
9515
  let $;
9509
9516
  t.charCodeAt(y - e) === 96 ? $ = new Je({
9510
- type: je(22),
9517
+ type: Re(22),
9511
9518
  value: "`",
9512
9519
  start: y,
9513
9520
  end: C,
9514
9521
  startLoc: f.start,
9515
9522
  endLoc: F
9516
9523
  }) : $ = new Je({
9517
- type: je(8),
9524
+ type: Re(8),
9518
9525
  value: "}",
9519
9526
  start: y,
9520
9527
  end: C,
@@ -9523,21 +9530,21 @@ function Ha() {
9523
9530
  });
9524
9531
  let W, K, ee, fe;
9525
9532
  c === 24 ? (K = w - 1, ee = i(f.end, -1), W = b === null ? null : b.slice(1, -1), fe = new Je({
9526
- type: je(22),
9533
+ type: Re(22),
9527
9534
  value: "`",
9528
9535
  start: K,
9529
9536
  end: w,
9530
9537
  startLoc: ee,
9531
9538
  endLoc: f.end
9532
9539
  })) : (K = w - 2, ee = i(f.end, -2), W = b === null ? null : b.slice(1, -2), fe = new Je({
9533
- type: je(23),
9540
+ type: Re(23),
9534
9541
  value: "${",
9535
9542
  start: K,
9536
9543
  end: w,
9537
9544
  startLoc: ee,
9538
9545
  endLoc: f.end
9539
9546
  })), p.splice(s, 1, $, new Je({
9540
- type: je(20),
9547
+ type: Re(20),
9541
9548
  value: W,
9542
9549
  start: C,
9543
9550
  end: K,
@@ -9547,7 +9554,7 @@ function Ha() {
9547
9554
  continue;
9548
9555
  }
9549
9556
  }
9550
- n.type = je(c);
9557
+ n.type = Re(c);
9551
9558
  }
9552
9559
  }
9553
9560
  return p;
@@ -9611,7 +9618,7 @@ function Ha() {
9611
9618
  return !1;
9612
9619
  }
9613
9620
  chStartsBindingIdentifier(t, e) {
9614
- if (Re(t)) {
9621
+ if (Ue(t)) {
9615
9622
  if (Ts.lastIndex = e, Ts.test(this.input)) {
9616
9623
  const s = this.codePointAtPos(Ts.lastIndex);
9617
9624
  if (!rt(s) && s !== 92)
@@ -10407,7 +10414,7 @@ function Ha() {
10407
10414
  const s = this.startNode(), n = this.parseIdentifierName(!0), {
10408
10415
  type: c
10409
10416
  } = this.state;
10410
- return (we(c) ? c !== 98 || this.lookaheadCharCode() === 102 : c !== 12) ? (this.applyImportPhase(t, e, n, s.loc.start), null) : (this.applyImportPhase(t, e, null), this.createIdentifier(s, n));
10417
+ return (Ee(c) ? c !== 98 || this.lookaheadCharCode() === 102 : c !== 12) ? (this.applyImportPhase(t, e, n, s.loc.start), null) : (this.applyImportPhase(t, e, null), this.createIdentifier(s, n));
10411
10418
  }
10412
10419
  isPrecedingIdImportPhase(t) {
10413
10420
  const {
@@ -10479,7 +10486,7 @@ function Ha() {
10479
10486
  if (e) {
10480
10487
  const s = this.startNodeAtNode(e);
10481
10488
  return s.local = e, t.specifiers.push(this.finishImportSpecifier(s, "ImportDefaultSpecifier")), !0;
10482
- } else if (we(this.state.type))
10489
+ } else if (Ee(this.state.type))
10483
10490
  return this.parseImportSpecifierLocal(t, this.startNode(), "ImportDefaultSpecifier"), !0;
10484
10491
  return !1;
10485
10492
  }
@@ -10574,7 +10581,7 @@ function Ha() {
10574
10581
  function Ea(p) {
10575
10582
  const t = {};
10576
10583
  for (const e of Object.keys(p))
10577
- t[e] = je(p[e]);
10584
+ t[e] = Re(p[e]);
10578
10585
  return t;
10579
10586
  }
10580
10587
  const Aa = Ea(st);
@@ -10899,10 +10906,10 @@ function pe(a) {
10899
10906
  else if (st.defaultFn)
10900
10907
  Ge = st.defaultFn.call(ie);
10901
10908
  else {
10902
- var we = "no value or default function given for field " + JSON.stringify(ne) + " of " + this.typeName + "(" + this.buildParams.map(function(_t) {
10909
+ var Ee = "no value or default function given for field " + JSON.stringify(ne) + " of " + this.typeName + "(" + this.buildParams.map(function(_t) {
10903
10910
  return Q[_t];
10904
10911
  }).join(", ") + ")";
10905
- throw new Error(we);
10912
+ throw new Error(Ee);
10906
10913
  }
10907
10914
  if (!se.check(Ge))
10908
10915
  throw new Error(
@@ -10965,7 +10972,7 @@ function pe(a) {
10965
10972
  Object.defineProperty(N, this.typeName, {
10966
10973
  enumerable: !0,
10967
10974
  value: this.type
10968
- }), this.finalized = !0, Le(this.typeName, this.supertypeList), this.buildable && this.supertypeList.lastIndexOf("Expression") >= 0 && _e(this.typeName);
10975
+ }), this.finalized = !0, Le(this.typeName, this.supertypeList), this.buildable && this.supertypeList.lastIndexOf("Expression") >= 0 && je(this.typeName);
10969
10976
  }
10970
10977
  }
10971
10978
  }
@@ -11052,7 +11059,7 @@ function pe(a) {
11052
11059
  return V.call(this, Y, ce(z, Y));
11053
11060
  }, X);
11054
11061
  }
11055
- function _e(z) {
11062
+ function je(z) {
11056
11063
  var V = _(z);
11057
11064
  if (R[V])
11058
11065
  return;
@@ -12771,7 +12778,7 @@ const {
12771
12778
  builders: Bt,
12772
12779
  builtInTypes: Fe,
12773
12780
  getFieldNames: xo,
12774
- getFieldValue: Ue,
12781
+ getFieldValue: $e,
12775
12782
  namedTypes: bo,
12776
12783
  NodePath: To,
12777
12784
  someField: Po
@@ -13617,12 +13624,12 @@ function jo(a, l) {
13617
13624
  return u.push(l(a)), L(u);
13618
13625
  }
13619
13626
  function di(a, l) {
13620
- const r = a.getValue(), i = l(a), o = ft.Node.check(r) && Ue(r, "comments");
13627
+ const r = a.getValue(), i = l(a), o = ft.Node.check(r) && $e(r, "comments");
13621
13628
  if (!o || o.length === 0)
13622
13629
  return i;
13623
13630
  const u = [], h = [i];
13624
13631
  return a.each(function(d) {
13625
- const g = d.getValue(), x = Ue(g, "leading"), S = Ue(g, "trailing");
13632
+ const g = d.getValue(), x = $e(g, "leading"), S = $e(g, "trailing");
13626
13633
  x || S && !(ft.Statement.check(r) || g.type === "Block" || g.type === "CommentBlock") ? u.push(_o(d, l)) : S && h.push(jo(d, l));
13627
13634
  }, "comments"), u.push.apply(u, h), L(u);
13628
13635
  }
@@ -14184,7 +14191,7 @@ function Us(a, l, r) {
14184
14191
  for (let d in u) {
14185
14192
  if (d.charAt(0) === "_")
14186
14193
  continue;
14187
- a.stack.push(d, Ue(i, d)), l.stack.push(d, Ue(o, d));
14194
+ a.stack.push(d, $e(i, d)), l.stack.push(d, $e(o, d));
14188
14195
  const g = tn(a, l, r);
14189
14196
  if (a.stack.length -= 2, l.stack.length -= 2, !g)
14190
14197
  return !1;
@@ -14329,7 +14336,7 @@ function sl(a, l, r) {
14329
14336
  case "MemberExpression":
14330
14337
  case "OptionalMemberExpression": {
14331
14338
  o.push(a.call(r, "object"));
14332
- const u = a.call(r, "property"), h = Ue(i, "optional");
14339
+ const u = a.call(r, "property"), h = $e(i, "optional");
14333
14340
  return i.computed ? o.push(h ? "?.[" : "[", u, "]") : o.push(h ? "?." : ".", u), L(o);
14334
14341
  }
14335
14342
  case "ChainExpression":
@@ -14482,7 +14489,7 @@ function sl(a, l, r) {
14482
14489
  }
14483
14490
  case "CallExpression":
14484
14491
  case "OptionalCallExpression":
14485
- return o.push(a.call(r, "callee")), i.typeParameters && o.push(a.call(r, "typeParameters")), i.typeArguments && o.push(a.call(r, "typeArguments")), Ue(i, "optional") && o.push("?."), o.push(Ti(a, l, r)), L(o);
14492
+ return o.push(a.call(r, "callee")), i.typeParameters && o.push(a.call(r, "typeParameters")), i.typeArguments && o.push(a.call(r, "typeArguments")), $e(i, "optional") && o.push("?."), o.push(Ti(a, l, r)), L(o);
14486
14493
  case "RecordExpression":
14487
14494
  o.push("#");
14488
14495
  case "ObjectExpression":
@@ -15648,7 +15655,7 @@ function Qt(a) {
15648
15655
  return a.replace(/['"]/g, (l) => l === '"' ? "'" : '"');
15649
15656
  }
15650
15657
  function ht(a) {
15651
- const l = Ue(a, "value"), r = Ue(a, "extra");
15658
+ const l = $e(a, "value"), r = $e(a, "extra");
15652
15659
  if (r && typeof r.raw == "string" && l == r.rawValue)
15653
15660
  return r.raw;
15654
15661
  if (a.type === "Literal") {
@@ -15857,7 +15864,7 @@ function ke(a, l, r) {
15857
15864
  }
15858
15865
  );
15859
15866
  }
15860
- const Ee = Bt, ks = /* @__PURE__ */ new WeakMap();
15867
+ const Ae = Bt, ks = /* @__PURE__ */ new WeakMap();
15861
15868
  function dl(a, l, r) {
15862
15869
  if (ks.has(l))
15863
15870
  return ks.get(l);
@@ -15894,9 +15901,9 @@ function dl(a, l, r) {
15894
15901
  (h) => h.type === "ImportDeclaration" && h.source.value === o
15895
15902
  );
15896
15903
  u ? u.specifiers.push(l) : r.body.unshift(
15897
- Ee.importDeclaration(
15904
+ Ae.importDeclaration(
15898
15905
  [l],
15899
- Ee.stringLiteral(o)
15906
+ Ae.stringLiteral(o)
15900
15907
  )
15901
15908
  );
15902
15909
  },
@@ -15928,9 +15935,9 @@ function ml(a, l) {
15928
15935
  const x = r(), S = x.find((P) => P.local === h), A = d.local || h;
15929
15936
  if (S)
15930
15937
  return S.imported = d.imported, S.local = A, S.from = d.from, !0;
15931
- const v = d.imported === "default" ? Ee.importDefaultSpecifier(Ee.identifier(A)) : d.imported === "*" ? Ee.importNamespaceSpecifier(Ee.identifier(A)) : Ee.importSpecifier(
15932
- Ee.identifier(d.imported),
15933
- Ee.identifier(A)
15938
+ const v = d.imported === "default" ? Ae.importDefaultSpecifier(Ae.identifier(A)) : d.imported === "*" ? Ae.importNamespaceSpecifier(Ae.identifier(A)) : Ae.importSpecifier(
15939
+ Ae.identifier(d.imported),
15940
+ Ae.identifier(A)
15934
15941
  ), I = x.find(
15935
15942
  (P) => P.from === d.from
15936
15943
  )?.$declaration;
@@ -15938,14 +15945,14 @@ function ml(a, l) {
15938
15945
  I.specifiers.push(v);
15939
15946
  else if (g === "prepend" || x.length === 0)
15940
15947
  a.body.unshift(
15941
- Ee.importDeclaration([v], Ee.stringLiteral(d.from))
15948
+ Ae.importDeclaration([v], Ae.stringLiteral(d.from))
15942
15949
  );
15943
15950
  else {
15944
15951
  const P = x.at(-1).$declaration, E = a.body.indexOf(P);
15945
15952
  a.body.splice(
15946
15953
  E + 1,
15947
15954
  0,
15948
- Ee.importDeclaration([v], Ee.stringLiteral(d.from))
15955
+ Ae.importDeclaration([v], Ae.stringLiteral(d.from))
15949
15956
  );
15950
15957
  }
15951
15958
  return !0;
@@ -16456,14 +16463,14 @@ function ln(a, l) {
16456
16463
  i && !o ? ln(a[r], l[r]) : o ? a[r] = a[r] ? [.../* @__PURE__ */ new Set([...a[r], ...l[r]])] : l[r] : a[r] = l[r];
16457
16464
  }
16458
16465
  }
16459
- async function Hl(a, l, r = !1, i = "") {
16460
- if (r || await $e(
16466
+ async function Kl(a, l, r = !1, i = "") {
16467
+ if (r || await Ve(
16461
16468
  i || `This will update '${a}' file. Continue?`
16462
16469
  )) {
16463
- const u = Ve(a);
16470
+ const u = _e(a);
16464
16471
  if (!u.valid)
16465
16472
  throw new Error(u.error);
16466
- const h = Ae(process.cwd(), a);
16473
+ const h = we(process.cwd(), a);
16467
16474
  if (!be(h))
16468
16475
  throw new Error(`No '${a}' found in project root — cannot update its contents.`);
16469
16476
  const d = await Nl(h);
@@ -16490,14 +16497,14 @@ async function Hl(a, l, r = !1, i = "") {
16490
16497
  } else
16491
16498
  console.log(`Updating '${a}' skipped.`);
16492
16499
  }
16493
- async function Kl(a, l, r, i = !1, o = "") {
16494
- if (i || await $e(
16500
+ async function Xl(a, l, r, i = !1, o = "") {
16501
+ if (i || await Ve(
16495
16502
  o || `This will update '${a}' file. Continue?`
16496
16503
  )) {
16497
- const h = Ve(a);
16504
+ const h = _e(a);
16498
16505
  if (!h.valid)
16499
16506
  throw new Error(h.error);
16500
- const d = Ae(process.cwd(), a);
16507
+ const d = we(process.cwd(), a);
16501
16508
  if (!be(d))
16502
16509
  throw new Error(`No '${a}' found in project root — cannot update its contents.`);
16503
16510
  const g = tt(d, "utf8");
@@ -16520,14 +16527,14 @@ ${A}`);
16520
16527
  } else
16521
16528
  console.log(`Updating '${a}' skipped.`);
16522
16529
  }
16523
- async function Xl(a, l, r = !1, i = "") {
16524
- if (r || await $e(
16530
+ async function Gl(a, l, r = !1, i = "") {
16531
+ if (r || await Ve(
16525
16532
  i || `This will update '${a}' file. Continue?`
16526
16533
  )) {
16527
- const u = Ve(a);
16534
+ const u = _e(a);
16528
16535
  if (!u.valid)
16529
16536
  throw new Error(u.error);
16530
- const h = Ae(process.cwd(), a);
16537
+ const h = we(process.cwd(), a);
16531
16538
  if (!be(h))
16532
16539
  throw new Error(`No '${a}' found in project root — cannot update its contents.`);
16533
16540
  const g = tt(h, "utf8").split(/\r?\n/);
@@ -16540,19 +16547,19 @@ async function Xl(a, l, r = !1, i = "") {
16540
16547
  } else
16541
16548
  console.log(`Updating '${a}' skipped.`);
16542
16549
  }
16543
- function Gl(a, l = 1) {
16550
+ function Ql(a, l = 1) {
16544
16551
  process.stderr.write(a);
16545
16552
  for (let r = 0; r < l; r++)
16546
16553
  process.stderr.write(`
16547
16554
  `);
16548
16555
  }
16549
- function Ql(a, l = 1) {
16556
+ function Yl(a, l = 1) {
16550
16557
  process.stdout.write(a);
16551
16558
  for (let r = 0; r < l; r++)
16552
16559
  process.stdout.write(`
16553
16560
  `);
16554
16561
  }
16555
- function Yl(a, l = Ae(process.cwd(), ".env")) {
16562
+ function Zl(a, l = we(process.cwd(), ".env")) {
16556
16563
  if (!be(l))
16557
16564
  return;
16558
16565
  const r = tt(l, "utf-8");
@@ -16567,19 +16574,20 @@ function Yl(a, l = Ae(process.cwd(), ".env")) {
16567
16574
  }
16568
16575
  }
16569
16576
  export {
16570
- _l as createFileFromTemplate,
16571
- jl as createFileFromWebTemplate,
16572
- Rl as deletePath,
16573
- Yl as getEnvValue,
16574
- Fl as hasJsonKey,
16575
- Bl as hasText,
16577
+ jl as createFileFromTemplate,
16578
+ Rl as createFileFromWebTemplate,
16579
+ Ul as deletePath,
16580
+ Fl as fileExists,
16581
+ Zl as getEnvValue,
16582
+ Bl as hasJsonKey,
16583
+ _l as hasText,
16576
16584
  Fa as parseQualifiedPath,
16577
- $e as promptUser,
16578
- Ul as removeFromJsonFile,
16585
+ Ve as promptUser,
16586
+ $l as removeFromJsonFile,
16579
16587
  Ba as resolvePackagePath,
16580
- Gl as showError,
16581
- Ql as showMessage,
16582
- Hl as updateConfigFile,
16583
- Kl as updateJsonFile,
16584
- Xl as updateTextFile
16588
+ Ql as showError,
16589
+ Yl as showMessage,
16590
+ Kl as updateConfigFile,
16591
+ Xl as updateJsonFile,
16592
+ Gl as updateTextFile
16585
16593
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks if the specified file exists on FS.
3
+ *
4
+ * @param {string} targetFile - The path to the text file to be checked (relative to CWD).
5
+ * @returns {boolean} True if the file exists, false otherwise.
6
+ * @throws Will throw an error if the path is invalid (can't traverse past CWD).
7
+ */
8
+ export declare function fileExists(targetFile: string): boolean;
@@ -1,3 +1,4 @@
1
+ import { fileExists } from './checks/file-exists';
1
2
  import { hasJsonKey } from './checks/has-json-key';
2
3
  import { hasText } from './checks/has-text';
3
4
  import { createFileFromTemplate } from './functions/create-file-from-template';
@@ -13,4 +14,4 @@ import { showMessage } from './terminal/show-message';
13
14
  import { getEnvValue } from './utils/get-env-value';
14
15
  import { parseQualifiedPath } from './utils/parse-qualified-path';
15
16
  import { resolvePackagePath } from './utils/resolve-package-path';
16
- export { hasJsonKey, hasText, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
17
+ export { fileExists, hasJsonKey, hasText, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elrh-cosca",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"