@reliverse/rempts 1.7.62 → 1.7.64

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.
@@ -229,7 +229,7 @@ export declare const mainSymbols: {
229
229
  lineSlash: string;
230
230
  };
231
231
  export declare const fallbackSymbols: Record<string, string>;
232
- export declare const figures: Record<string, string> | {
232
+ export declare const figures: {
233
233
  tick: string;
234
234
  info: string;
235
235
  warning: string;
@@ -458,4 +458,4 @@ export declare const figures: Record<string, string> | {
458
458
  lineCross: string;
459
459
  lineBackslash: string;
460
460
  lineSlash: string;
461
- };
461
+ } | Record<string, string>;
@@ -1,11 +1,11 @@
1
1
  import process from "node:process";
2
- import { relinka } from "@reliverse/relinka";
2
+ import { relinka, relinkaConfig } from "@reliverse/relinka";
3
3
  import { reliArgParser } from "../reliarg/reliarg-mod.js";
4
4
  export async function callCmd(command, input, options = {}) {
5
5
  const { autoExit = false, debug = false, useLifecycleHooks = true, parserOptions = {} } = options;
6
6
  const debugLog = (...args) => {
7
7
  if (debug) {
8
- relinka("log", "[callCmd DEBUG]", ...args);
8
+ void relinkaConfig().then(() => relinka("log", "[callCmd DEBUG]", ...args));
9
9
  }
10
10
  };
11
11
  debugLog("Calling command with input:", input);
@@ -5,14 +5,58 @@ import { relinka, relinkaConfig, relinkaShutdown } from "@reliverse/relinka";
5
5
  import path from "path";
6
6
  import { readPackageJSON } from "pkg-types";
7
7
  import { reliArgParser } from "../reliarg/reliarg-mod.js";
8
- async function pathExists(path2) {
8
+ const isBunRuntime = Boolean(
9
+ // Prefer versions flag to avoid TS type needs
10
+ process?.versions?.bun || typeof globalThis.Bun !== "undefined"
11
+ );
12
+ const _pathExistsCache = /* @__PURE__ */ new Map();
13
+ async function pathExists(p) {
14
+ const cached = _pathExistsCache.get(p);
15
+ if (cached !== void 0) return cached;
9
16
  try {
10
- await stat(path2);
17
+ if (isBunRuntime) {
18
+ const bun = globalThis.Bun;
19
+ if (bun?.file) {
20
+ const exists = await bun.file(p).exists();
21
+ _pathExistsCache.set(p, exists);
22
+ return exists;
23
+ }
24
+ }
25
+ await stat(p);
26
+ _pathExistsCache.set(p, true);
11
27
  return true;
12
- } catch (error) {
28
+ } catch (_error) {
29
+ _pathExistsCache.set(p, false);
13
30
  return false;
14
31
  }
15
32
  }
33
+ async function isDirectory(p) {
34
+ try {
35
+ const s = await stat(p);
36
+ return s.isDirectory();
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+ let _cachedPkgJson;
42
+ async function readPkgJsonCached() {
43
+ if (_cachedPkgJson) return _cachedPkgJson;
44
+ try {
45
+ if (isBunRuntime) {
46
+ const bun = globalThis.Bun;
47
+ if (bun?.file) {
48
+ _cachedPkgJson = await bun.file("package.json").json();
49
+ } else {
50
+ _cachedPkgJson = await readPackageJSON();
51
+ }
52
+ } else {
53
+ _cachedPkgJson = await readPackageJSON();
54
+ }
55
+ } catch (_e) {
56
+ _cachedPkgJson = void 0;
57
+ }
58
+ return _cachedPkgJson;
59
+ }
16
60
  function buildExampleArgs(args) {
17
61
  const parts = [];
18
62
  const positionalKeys = Object.keys(args || {}).filter((k) => args?.[k]?.type === "positional");
@@ -49,9 +93,15 @@ function buildExampleArgs(args) {
49
93
  return parts.join(" ");
50
94
  }
51
95
  const isDebugMode = process.argv.includes("--debug");
96
+ let _relinkaConfigured = false;
97
+ async function ensureRelinkaConfigured() {
98
+ if (_relinkaConfigured) return;
99
+ await relinkaConfig();
100
+ _relinkaConfigured = true;
101
+ }
52
102
  function debugLog(...args) {
53
103
  if (isDebugMode) {
54
- relinka("log", "[DEBUG]", ...args);
104
+ void ensureRelinkaConfigured().then(() => relinka("log", "[DEBUG]", ...args));
55
105
  }
56
106
  }
57
107
  function isFlag(str) {
@@ -90,17 +140,21 @@ export function defineCommand(options) {
90
140
  }
91
141
  let _cachedDefaultCliName;
92
142
  let _cachedDefaultCliVersion;
143
+ let _cachedDefaultCliDescription;
93
144
  async function getDefaultCliNameAndVersion() {
94
145
  if (_cachedDefaultCliName)
95
146
  return { name: _cachedDefaultCliName, version: _cachedDefaultCliVersion };
96
147
  try {
97
- const pkg = await readPackageJSON();
148
+ const pkg = await readPkgJsonCached() ?? {};
98
149
  let name = pkg.name || "cli";
99
150
  if (name.startsWith("@")) {
100
151
  name = name.split("/").pop() || name;
101
152
  }
102
153
  _cachedDefaultCliName = name;
103
154
  _cachedDefaultCliVersion = pkg.version;
155
+ if (pkg.description && !_cachedDefaultCliDescription) {
156
+ _cachedDefaultCliDescription = pkg.description;
157
+ }
104
158
  return { name, version: pkg.version };
105
159
  } catch (_e) {
106
160
  return { name: "cli", version: void 0 };
@@ -154,11 +208,8 @@ export async function showUsage(command, parserOptions = {}, globalCliMeta) {
154
208
  if (parserOptions.metaSettings?.showDescriptionOnMain) {
155
209
  let description = globalCliMeta?.description || command.meta?.description;
156
210
  if (!description) {
157
- try {
158
- const pkg = await readPackageJSON();
159
- if (pkg.description) description = pkg.description;
160
- } catch (_e) {
161
- }
211
+ await getDefaultCliNameAndVersion();
212
+ if (_cachedDefaultCliDescription) description = _cachedDefaultCliDescription;
162
213
  }
163
214
  if (description) {
164
215
  relinka("log", description);
@@ -405,6 +456,7 @@ export function createCli(options, legacyParserOptions) {
405
456
  const rawArgv = process.argv.slice(2);
406
457
  const autoExit = parserOptions.autoExit !== false;
407
458
  if (!(parserOptions.fileBased?.enable || command.commands && Object.keys(command.commands).length > 0 || command.run)) {
459
+ await ensureRelinkaConfigured();
408
460
  relinka(
409
461
  "error",
410
462
  "Invalid CLI configuration: No file-based commands, subCommands, or run() handler are defined. This CLI will not do anything.\n\u2502 To fix: add file-based commands (./app), or provide at least one subCommand, or a run() handler."
@@ -453,6 +505,7 @@ export function createCli(options, legacyParserOptions) {
453
505
  if (autoExit) process.exit(0);
454
506
  return;
455
507
  } catch (err) {
508
+ await ensureRelinkaConfigured();
456
509
  relinka("error", "Error loading file-based subcommand:", err.message);
457
510
  if (autoExit) process.exit(1);
458
511
  throw err;
@@ -508,13 +561,14 @@ export function createCli(options, legacyParserOptions) {
508
561
  if (autoExit) process.exit(0);
509
562
  return;
510
563
  } catch (err) {
564
+ await ensureRelinkaConfigured();
511
565
  relinka("error", "Error running subcommand:", err.message);
512
566
  if (autoExit) process.exit(1);
513
567
  throw err;
514
568
  }
515
569
  }
516
570
  }
517
- await relinkaConfig();
571
+ await ensureRelinkaConfigured();
518
572
  if (rawArgv[0] === "help" || checkHelp(rawArgv)) {
519
573
  await showUsage(command, parserOptions, globalCliMeta);
520
574
  if (autoExit) process.exit(0);
@@ -534,7 +588,7 @@ export function createCli(options, legacyParserOptions) {
534
588
  await runCommandWithArgs(command, rawArgv, parserOptions, globalCliMeta);
535
589
  } finally {
536
590
  }
537
- await relinkaShutdown();
591
+ if (_relinkaConfigured) await relinkaShutdown();
538
592
  } finally {
539
593
  if (typeof command.onLauncherExit === "function") await command.onLauncherExit();
540
594
  }
@@ -600,7 +654,7 @@ Info for this CLI's developer: No valid command file found in ${baseDir}`
600
654
  );
601
655
  }
602
656
  const nextDir = path.join(baseDir, args[0] || "");
603
- if (await pathExists(nextDir) && (await stat(nextDir)).isDirectory()) {
657
+ if (await isDirectory(nextDir)) {
604
658
  return resolveCmdPath(nextDir, args.slice(1));
605
659
  }
606
660
  const possibleFiles = [path.join(baseDir, "cmd.js"), path.join(baseDir, "cmd.ts")];
@@ -616,7 +670,7 @@ Info for this CLI's developer: No valid command file found in ${baseDir}`
616
670
  );
617
671
  }
618
672
  const startDir = path.join(fileCmdOpts.cmdsRootPath, subName);
619
- if (!await pathExists(startDir) || !(await stat(startDir)).isDirectory()) {
673
+ if (!await isDirectory(startDir)) {
620
674
  const attempted = [subName, ...argv].join(" ");
621
675
  const expectedPath = path.relative(
622
676
  process.cwd(),
@@ -930,7 +984,7 @@ async function resolveFileBasedCommandPath(cmdsRoot, argv) {
930
984
  let leftover = [...argv];
931
985
  while (leftover.length > 0 && leftover[0] && !isFlag(leftover[0])) {
932
986
  const nextDir = path.join(currentDir, leftover[0]);
933
- if (await pathExists(nextDir) && (await stat(nextDir)).isDirectory()) {
987
+ if (await isDirectory(nextDir)) {
934
988
  currentDir = nextDir;
935
989
  pathSegments.push(leftover[0]);
936
990
  leftover = leftover.slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@reliverse/relico": "^1.3.9",
3
+ "@reliverse/relico": "^1.4.0",
4
4
  "@reliverse/relinka": "^1.6.1",
5
5
  "@reliverse/reltime": "^1.1.1",
6
6
  "ansi-escapes": "^7.0.0",
@@ -15,7 +15,7 @@
15
15
  "pretty-ms": "^9.2.0",
16
16
  "sisteransi": "^1.0.5",
17
17
  "stdin-discarder": "^0.2.2",
18
- "string-width": "^8.0.0",
18
+ "string-width": "^8.1.0",
19
19
  "strip-ansi": "^7.1.0",
20
20
  "terminal-size": "^4.0.0",
21
21
  "ts-regex-builder": "^1.8.2",
@@ -26,7 +26,7 @@
26
26
  "license": "MIT",
27
27
  "name": "@reliverse/rempts",
28
28
  "type": "module",
29
- "version": "1.7.62",
29
+ "version": "1.7.64",
30
30
  "author": "reliverse",
31
31
  "bugs": {
32
32
  "email": "blefnk@gmail.com",