@reliverse/rempts 1.7.46 → 1.7.47

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.
@@ -3143,15 +3143,34 @@ const getCallerDirectory = async () => {
3143
3143
  const resolvedFileDir = resolve(fileDir);
3144
3144
  const resolvedCwd = resolve(cwd);
3145
3145
  if (process$1.env.NODE_ENV === "development") {
3146
- relinka(
3147
- "verbose",
3148
- `File dir: ${fileDir}, resolved: ${resolvedFileDir}, cwd: ${resolvedCwd}`
3149
- );
3146
+ relinka("verbose", `File dir: ${fileDir}, resolved: ${resolvedFileDir}, cwd: ${resolvedCwd}`);
3150
3147
  }
3151
3148
  if (resolvedFileDir !== resolvedCwd && !resolvedFileDir.startsWith(resolvedCwd)) {
3152
3149
  relinka("verbose", `Using caller directory: ${fileDir}`);
3153
3150
  return fileDir;
3154
3151
  }
3152
+ if (resolvedFileDir === resolvedCwd) {
3153
+ let currentDir2 = fileDir;
3154
+ while (currentDir2 !== dirname(currentDir2)) {
3155
+ try {
3156
+ const packageJsonPath = resolve(currentDir2, "package.json");
3157
+ if (await fs.pathExists(packageJsonPath)) {
3158
+ const cwdPackageJsonPath = resolve(cwd, "package.json");
3159
+ if (await fs.pathExists(cwdPackageJsonPath)) {
3160
+ const callerPackageJson = await fs.readFile(packageJsonPath, "utf-8");
3161
+ const cwdPackageJson = await fs.readFile(cwdPackageJsonPath, "utf-8");
3162
+ if (callerPackageJson !== cwdPackageJson) {
3163
+ relinka("verbose", `Found different package.json at: ${currentDir2}, using caller directory: ${fileDir}`);
3164
+ return fileDir;
3165
+ }
3166
+ }
3167
+ break;
3168
+ }
3169
+ } catch {
3170
+ }
3171
+ currentDir2 = dirname(currentDir2);
3172
+ }
3173
+ }
3155
3174
  } catch {
3156
3175
  continue;
3157
3176
  }
@@ -3211,6 +3230,39 @@ const generateCandidatePaths = async (resolvedPath) => {
3211
3230
  }
3212
3231
  return [resolvedPath];
3213
3232
  };
3233
+ const generateAlternativePaths = async (cmdPath, callerDir) => {
3234
+ const normalizedCmdPath = cmdPath.replace(/^\.\//, "");
3235
+ const paths = [];
3236
+ const commonCommandLocations = [
3237
+ // Direct command file
3238
+ resolve(callerDir, `${normalizedCmdPath}.ts`),
3239
+ resolve(callerDir, `${normalizedCmdPath}.js`),
3240
+ // Command in cmd subdirectory
3241
+ resolve(callerDir, normalizedCmdPath, "cmd.ts"),
3242
+ resolve(callerDir, normalizedCmdPath, "cmd.js"),
3243
+ // Command in app subdirectory
3244
+ resolve(callerDir, "app", normalizedCmdPath, "cmd.ts"),
3245
+ resolve(callerDir, "app", normalizedCmdPath, "cmd.js"),
3246
+ // Command in src subdirectory
3247
+ resolve(callerDir, "src", normalizedCmdPath, "cmd.ts"),
3248
+ resolve(callerDir, "src", normalizedCmdPath, "cmd.js"),
3249
+ // Command in src-ts subdirectory
3250
+ resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.ts"),
3251
+ resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.js"),
3252
+ // Command in bin subdirectory
3253
+ resolve(callerDir, "bin", normalizedCmdPath, "cmd.ts"),
3254
+ resolve(callerDir, "bin", normalizedCmdPath, "cmd.js"),
3255
+ // Command in bin/app subdirectory (common for CLI tools)
3256
+ resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.ts"),
3257
+ resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js")
3258
+ ];
3259
+ for (const path of commonCommandLocations) {
3260
+ if (await fs.pathExists(path)) {
3261
+ paths.push(path);
3262
+ }
3263
+ }
3264
+ return paths;
3265
+ };
3214
3266
  const createCommandNotFoundError = (cmdPath, searchedPaths) => new Error(
3215
3267
  `No command file found for "${cmdPath}". Expected to find either:
3216
3268
  - A valid command file at the specified path
@@ -3254,6 +3306,21 @@ async function loadCommand(cmdPath) {
3254
3306
  return command;
3255
3307
  }
3256
3308
  }
3309
+ if (callerDir !== process$1.cwd()) {
3310
+ const alternativePaths = await generateAlternativePaths(cmdPath, callerDir);
3311
+ if (process$1.env.NODE_ENV === "development") {
3312
+ relinka("verbose", `Trying alternative paths: ${alternativePaths.join(", ")}`);
3313
+ }
3314
+ for (const path of alternativePaths) {
3315
+ const command = await tryLoadCommand(path);
3316
+ if (command) {
3317
+ if (process$1.env.NODE_ENV === "development") {
3318
+ relinka("verbose", `Successfully loaded command from alternative path: ${path}`);
3319
+ }
3320
+ return command;
3321
+ }
3322
+ }
3323
+ }
3257
3324
  throw createCommandNotFoundError(cmdPath, candidatePaths);
3258
3325
  } catch (error) {
3259
3326
  if (error instanceof Error && error.message.includes("No command file found")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reliverse/rempts",
3
3
  "author": "reliverse",
4
- "version": "1.7.46",
4
+ "version": "1.7.47",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist-npm/bin/mod.mjs",