@reliverse/rempts 1.7.13 → 1.7.14

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.
@@ -1,2 +1,2 @@
1
1
  import type { Command } from "./launcher-types.js";
2
- export declare function loadCommand(path: string): Promise<Command>;
2
+ export declare function loadCommand(cmdPath: string): Promise<Command>;
@@ -1,18 +1,50 @@
1
+ import { resolve } from "@reliverse/pathkit";
1
2
  import { relinka } from "@reliverse/relinka";
3
+ import fs from "fs-extra";
2
4
  import { createJiti } from "jiti";
3
5
  const jiti = createJiti(import.meta.url, {
4
6
  debug: process.env.NODE_ENV === "development",
5
7
  fsCache: true,
6
8
  sourceMaps: true
7
9
  });
8
- export async function loadCommand(path) {
10
+ export async function loadCommand(cmdPath) {
9
11
  try {
10
- relinka("verbose", `Loading command from: ${path}`);
11
- const cmd = await jiti.import(path, { default: true });
12
- relinka("verbose", `Successfully loaded command from: ${path}`);
12
+ const resolvedPath = cmdPath.startsWith("./") || cmdPath.startsWith("../") ? resolve(process.cwd(), cmdPath) : cmdPath;
13
+ if (!resolvedPath.endsWith("cmd.ts") && !resolvedPath.endsWith("cmd.js")) {
14
+ const possiblePaths = [
15
+ resolve(resolvedPath, "cmd.ts"),
16
+ resolve(resolvedPath, "cmd.js")
17
+ ];
18
+ for (const path of possiblePaths) {
19
+ if (await fs.pathExists(path)) {
20
+ relinka("verbose", `Loading command from: ${path}`);
21
+ const cmd2 = await jiti.import(path, { default: true });
22
+ relinka("verbose", `Successfully loaded command from: ${path}`);
23
+ return cmd2;
24
+ }
25
+ }
26
+ throw new Error(
27
+ `No command file found in ${resolvedPath}. Expected to find either:
28
+ - ${possiblePaths[0]}
29
+ - ${possiblePaths[1]}
30
+ Please ensure one of these files exists and exports a default command.`
31
+ );
32
+ }
33
+ relinka("verbose", `Loading command from: ${resolvedPath}`);
34
+ const cmd = await jiti.import(resolvedPath, { default: true });
35
+ relinka("verbose", `Successfully loaded command from: ${resolvedPath}`);
13
36
  return cmd;
14
37
  } catch (error) {
15
- relinka("error", `Failed to load command from ${path}:`, error);
16
- throw error;
38
+ if (error instanceof Error && error.message.includes("No command file found")) {
39
+ throw error;
40
+ }
41
+ relinka("error", `Failed to load command from ${cmdPath}:`, error);
42
+ throw new Error(
43
+ `Failed to load command from ${cmdPath}:
44
+ - Make sure the file exists and is accessible
45
+ - Ensure the file exports a default command
46
+ - Check that the file is a valid TypeScript/JavaScript module
47
+ Original error: ${error instanceof Error ? error.message : String(error)}`
48
+ );
17
49
  }
18
50
  }
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "license": "MIT",
30
30
  "name": "@reliverse/rempts",
31
31
  "type": "module",
32
- "version": "1.7.13",
32
+ "version": "1.7.14",
33
33
  "author": "reliverse",
34
34
  "bugs": {
35
35
  "email": "blefnk@gmail.com",