@reliverse/rempts 1.7.47 → 1.7.49
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-npm/bin/mod.mjs +160 -72
- package/package.json +1 -1
package/dist-npm/bin/mod.mjs
CHANGED
|
@@ -3123,9 +3123,9 @@ const getCallerDirectory = async () => {
|
|
|
3123
3123
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
3124
3124
|
const cwd = process$1.cwd();
|
|
3125
3125
|
if (process$1.env.NODE_ENV === "development") {
|
|
3126
|
-
relinka("
|
|
3126
|
+
relinka("log", "Stack trace for getCallerDirectory:");
|
|
3127
3127
|
stack.forEach((line, index) => {
|
|
3128
|
-
relinka("
|
|
3128
|
+
relinka("log", ` [${index}]: ${line.trim()}`);
|
|
3129
3129
|
});
|
|
3130
3130
|
}
|
|
3131
3131
|
for (const line of stack) {
|
|
@@ -3133,42 +3133,83 @@ const getCallerDirectory = async () => {
|
|
|
3133
3133
|
if (match?.[1]) {
|
|
3134
3134
|
const filePath = match[1];
|
|
3135
3135
|
if (process$1.env.NODE_ENV === "development") {
|
|
3136
|
-
relinka("
|
|
3136
|
+
relinka("log", `Checking file path: ${filePath}`);
|
|
3137
3137
|
}
|
|
3138
|
-
if (!filePath.includes("node_modules") && !filePath.includes("command-runner") && !filePath.includes("command-typed") && !filePath.includes("launcher-mod") && !filePath.includes("launcher-types") && !filePath.
|
|
3139
|
-
!filePath.
|
|
3140
|
-
!filePath.
|
|
3138
|
+
if (!filePath.includes("node_modules") && !filePath.includes("command-runner") && !filePath.includes("command-typed") && !filePath.includes("launcher-mod") && !filePath.includes("launcher-types") && !filePath.endsWith("mod.mjs") && // Skip compiled output
|
|
3139
|
+
!filePath.endsWith("mod.js") && // Skip compiled output
|
|
3140
|
+
!filePath.endsWith("mod.ts")) {
|
|
3141
3141
|
try {
|
|
3142
3142
|
const fileDir = dirname(filePath);
|
|
3143
|
+
let currentDir2 = fileDir;
|
|
3144
|
+
let packageRoot = null;
|
|
3145
|
+
while (currentDir2 !== dirname(currentDir2)) {
|
|
3146
|
+
try {
|
|
3147
|
+
const packageJsonPath = resolve(currentDir2, "package.json");
|
|
3148
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
3149
|
+
packageRoot = currentDir2;
|
|
3150
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3151
|
+
relinka("log", `Found package.json at: ${packageRoot}`);
|
|
3152
|
+
}
|
|
3153
|
+
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
3154
|
+
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
3155
|
+
try {
|
|
3156
|
+
const callerPackage = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
3157
|
+
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
3158
|
+
if (callerPackage.name !== cwdPackage.name || callerPackage.version !== cwdPackage.version) {
|
|
3159
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3160
|
+
relinka("log", `Using caller package root: ${packageRoot} (${callerPackage.name}@${callerPackage.version})`);
|
|
3161
|
+
}
|
|
3162
|
+
return packageRoot;
|
|
3163
|
+
}
|
|
3164
|
+
} catch {
|
|
3165
|
+
if (resolve(packageRoot) !== resolve(cwd)) {
|
|
3166
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3167
|
+
relinka("log", `Using caller package root (different path): ${packageRoot}`);
|
|
3168
|
+
}
|
|
3169
|
+
return packageRoot;
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
} else {
|
|
3173
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3174
|
+
relinka("log", `Using caller package root (no CWD package.json): ${packageRoot}`);
|
|
3175
|
+
}
|
|
3176
|
+
return packageRoot;
|
|
3177
|
+
}
|
|
3178
|
+
break;
|
|
3179
|
+
}
|
|
3180
|
+
} catch {
|
|
3181
|
+
}
|
|
3182
|
+
currentDir2 = dirname(currentDir2);
|
|
3183
|
+
}
|
|
3143
3184
|
const resolvedFileDir = resolve(fileDir);
|
|
3144
3185
|
const resolvedCwd = resolve(cwd);
|
|
3145
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3146
|
-
relinka("verbose", `File dir: ${fileDir}, resolved: ${resolvedFileDir}, cwd: ${resolvedCwd}`);
|
|
3147
|
-
}
|
|
3148
3186
|
if (resolvedFileDir !== resolvedCwd && !resolvedFileDir.startsWith(resolvedCwd)) {
|
|
3149
|
-
|
|
3150
|
-
|
|
3187
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3188
|
+
relinka("log", `Using caller directory (different from CWD): ${fileDir}`);
|
|
3189
|
+
}
|
|
3190
|
+
return packageRoot || fileDir;
|
|
3151
3191
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3192
|
+
} catch {
|
|
3193
|
+
continue;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
for (const line of stack) {
|
|
3199
|
+
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
3200
|
+
if (match?.[1]) {
|
|
3201
|
+
const filePath = match[1];
|
|
3202
|
+
if (filePath.includes("node_modules")) {
|
|
3203
|
+
try {
|
|
3204
|
+
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/[^\/]+)/);
|
|
3205
|
+
if (nodeModulesMatch?.[1]) {
|
|
3206
|
+
const packageDir = nodeModulesMatch[1];
|
|
3207
|
+
const packageJsonPath = resolve(packageDir, "package.json");
|
|
3208
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
3209
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3210
|
+
relinka("log", `Found command package in node_modules: ${packageDir}`);
|
|
3170
3211
|
}
|
|
3171
|
-
|
|
3212
|
+
return packageDir;
|
|
3172
3213
|
}
|
|
3173
3214
|
}
|
|
3174
3215
|
} catch {
|
|
@@ -3182,34 +3223,40 @@ const getCallerDirectory = async () => {
|
|
|
3182
3223
|
try {
|
|
3183
3224
|
const packageJsonPath = resolve(currentDir, "package.json");
|
|
3184
3225
|
if (await fs.pathExists(packageJsonPath)) {
|
|
3185
|
-
|
|
3226
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3227
|
+
relinka("log", `Found package.json at: ${currentDir}`);
|
|
3228
|
+
}
|
|
3186
3229
|
return currentDir;
|
|
3187
3230
|
}
|
|
3188
3231
|
} catch {
|
|
3189
3232
|
}
|
|
3190
3233
|
currentDir = dirname(currentDir);
|
|
3191
3234
|
}
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
];
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3235
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3236
|
+
relinka("log", `No suitable caller found, using cwd: ${cwd}`);
|
|
3237
|
+
}
|
|
3238
|
+
return process$1.cwd();
|
|
3239
|
+
};
|
|
3240
|
+
const getNodeModulesPackageDirsFromStack = async () => {
|
|
3241
|
+
const stack = new Error().stack?.split("\n") ?? [];
|
|
3242
|
+
const packageDirs = /* @__PURE__ */ new Set();
|
|
3243
|
+
for (const line of stack) {
|
|
3244
|
+
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
3245
|
+
if (!match?.[1]) continue;
|
|
3246
|
+
const filePath = match[1];
|
|
3247
|
+
if (!filePath.includes("node_modules")) continue;
|
|
3248
|
+
try {
|
|
3249
|
+
const nodeModulesMatch = filePath.match(/(.+\\node_modules\\(?:@[^\\/]+\\)?[^\\/]+)|(.+\/node_modules\/(?:@[^\/]+\/)?[^\/]+)/);
|
|
3250
|
+
const packageDir = (nodeModulesMatch?.[1] || nodeModulesMatch?.[2])?.trim();
|
|
3251
|
+
if (!packageDir) continue;
|
|
3252
|
+
const packageJsonPath = resolve(packageDir, "package.json");
|
|
3253
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
3254
|
+
packageDirs.add(packageDir);
|
|
3207
3255
|
}
|
|
3256
|
+
} catch {
|
|
3208
3257
|
}
|
|
3209
|
-
} catch {
|
|
3210
3258
|
}
|
|
3211
|
-
|
|
3212
|
-
return process$1.cwd();
|
|
3259
|
+
return Array.from(packageDirs);
|
|
3213
3260
|
};
|
|
3214
3261
|
const tryLoadCommand = async (path) => {
|
|
3215
3262
|
if (!await fs.pathExists(path)) return null;
|
|
@@ -3217,7 +3264,7 @@ const tryLoadCommand = async (path) => {
|
|
|
3217
3264
|
const cmd = await jiti.import(path, { default: true });
|
|
3218
3265
|
return cmd;
|
|
3219
3266
|
} catch {
|
|
3220
|
-
relinka("
|
|
3267
|
+
relinka("log", `Failed to load ${path} as a command file`);
|
|
3221
3268
|
return null;
|
|
3222
3269
|
}
|
|
3223
3270
|
};
|
|
@@ -3246,15 +3293,45 @@ const generateAlternativePaths = async (cmdPath, callerDir) => {
|
|
|
3246
3293
|
// Command in src subdirectory
|
|
3247
3294
|
resolve(callerDir, "src", normalizedCmdPath, "cmd.ts"),
|
|
3248
3295
|
resolve(callerDir, "src", normalizedCmdPath, "cmd.js"),
|
|
3296
|
+
// Command in src/app subdirectory
|
|
3297
|
+
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.ts"),
|
|
3298
|
+
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.js"),
|
|
3249
3299
|
// Command in src-ts subdirectory
|
|
3250
3300
|
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.ts"),
|
|
3251
3301
|
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.js"),
|
|
3302
|
+
// Command in src-ts/app subdirectory (for dler-like structures)
|
|
3303
|
+
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.ts"),
|
|
3304
|
+
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.js"),
|
|
3305
|
+
// Command in lib subdirectory
|
|
3306
|
+
resolve(callerDir, "lib", normalizedCmdPath, "cmd.ts"),
|
|
3307
|
+
resolve(callerDir, "lib", normalizedCmdPath, "cmd.js"),
|
|
3308
|
+
// Command in lib/app subdirectory
|
|
3309
|
+
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.ts"),
|
|
3310
|
+
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.js"),
|
|
3311
|
+
// Command in dist subdirectory (compiled)
|
|
3312
|
+
resolve(callerDir, "dist", normalizedCmdPath, "cmd.js"),
|
|
3313
|
+
resolve(callerDir, "dist", "app", normalizedCmdPath, "cmd.js"),
|
|
3252
3314
|
// Command in bin subdirectory
|
|
3253
3315
|
resolve(callerDir, "bin", normalizedCmdPath, "cmd.ts"),
|
|
3254
3316
|
resolve(callerDir, "bin", normalizedCmdPath, "cmd.js"),
|
|
3255
3317
|
// Command in bin/app subdirectory (common for CLI tools)
|
|
3256
3318
|
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.ts"),
|
|
3257
|
-
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js")
|
|
3319
|
+
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js"),
|
|
3320
|
+
// Command in commands subdirectory
|
|
3321
|
+
resolve(callerDir, "commands", normalizedCmdPath, "cmd.ts"),
|
|
3322
|
+
resolve(callerDir, "commands", normalizedCmdPath, "cmd.js"),
|
|
3323
|
+
// Command in cli subdirectory
|
|
3324
|
+
resolve(callerDir, "cli", normalizedCmdPath, "cmd.ts"),
|
|
3325
|
+
resolve(callerDir, "cli", normalizedCmdPath, "cmd.js"),
|
|
3326
|
+
// Command in cli/commands subdirectory
|
|
3327
|
+
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.ts"),
|
|
3328
|
+
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.js"),
|
|
3329
|
+
// Command in tools subdirectory
|
|
3330
|
+
resolve(callerDir, "tools", normalizedCmdPath, "cmd.ts"),
|
|
3331
|
+
resolve(callerDir, "tools", normalizedCmdPath, "cmd.js"),
|
|
3332
|
+
// Command in scripts subdirectory
|
|
3333
|
+
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.ts"),
|
|
3334
|
+
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.js")
|
|
3258
3335
|
];
|
|
3259
3336
|
for (const path of commonCommandLocations) {
|
|
3260
3337
|
if (await fs.pathExists(path)) {
|
|
@@ -3288,40 +3365,51 @@ async function loadCommand(cmdPath) {
|
|
|
3288
3365
|
const normalizedPath = cmdPath.replace(/^\.\//, "");
|
|
3289
3366
|
const resolvedPath = resolve(callerDir, normalizedPath);
|
|
3290
3367
|
if (process$1.env.NODE_ENV === "development") {
|
|
3291
|
-
relinka("
|
|
3292
|
-
relinka("
|
|
3293
|
-
relinka("
|
|
3294
|
-
relinka("
|
|
3295
|
-
}
|
|
3296
|
-
const
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3368
|
+
relinka("log", `Loading command: ${cmdPath}`);
|
|
3369
|
+
relinka("log", `Caller directory: ${callerDir}`);
|
|
3370
|
+
relinka("log", `Normalized path: ${normalizedPath}`);
|
|
3371
|
+
relinka("log", `Resolved path: ${resolvedPath}`);
|
|
3372
|
+
}
|
|
3373
|
+
const searchedPaths = [];
|
|
3374
|
+
const baseDirs = [callerDir];
|
|
3375
|
+
const stackPackageDirs = await getNodeModulesPackageDirsFromStack();
|
|
3376
|
+
for (const dir of stackPackageDirs) {
|
|
3377
|
+
if (!baseDirs.includes(dir)) baseDirs.push(dir);
|
|
3378
|
+
}
|
|
3379
|
+
for (const baseDir of baseDirs) {
|
|
3380
|
+
const alternativePaths = await generateAlternativePaths(cmdPath, baseDir);
|
|
3381
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3382
|
+
relinka("log", `Trying alternative paths in base ${baseDir}: ${alternativePaths.join(", ")}`);
|
|
3383
|
+
}
|
|
3384
|
+
searchedPaths.push(...alternativePaths);
|
|
3385
|
+
for (const path of alternativePaths) {
|
|
3386
|
+
const command = await tryLoadCommand(path);
|
|
3387
|
+
if (command) {
|
|
3388
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3389
|
+
relinka("log", `Successfully loaded command from alternative path: ${path}`);
|
|
3390
|
+
}
|
|
3391
|
+
return command;
|
|
3305
3392
|
}
|
|
3306
|
-
return command;
|
|
3307
3393
|
}
|
|
3308
3394
|
}
|
|
3309
|
-
|
|
3310
|
-
|
|
3395
|
+
const looksLikeExplicitPath = /[\\\/]|\.ts$|\.js$/.test(normalizedPath);
|
|
3396
|
+
if (looksLikeExplicitPath) {
|
|
3397
|
+
const candidatePaths = await generateCandidatePaths(resolvedPath);
|
|
3311
3398
|
if (process$1.env.NODE_ENV === "development") {
|
|
3312
|
-
relinka("
|
|
3399
|
+
relinka("log", `Candidate paths: ${candidatePaths.join(", ")}`);
|
|
3313
3400
|
}
|
|
3314
|
-
|
|
3401
|
+
searchedPaths.push(...candidatePaths);
|
|
3402
|
+
for (const path of candidatePaths) {
|
|
3315
3403
|
const command = await tryLoadCommand(path);
|
|
3316
3404
|
if (command) {
|
|
3317
3405
|
if (process$1.env.NODE_ENV === "development") {
|
|
3318
|
-
relinka("
|
|
3406
|
+
relinka("log", `Successfully loaded command from: ${path}`);
|
|
3319
3407
|
}
|
|
3320
3408
|
return command;
|
|
3321
3409
|
}
|
|
3322
3410
|
}
|
|
3323
3411
|
}
|
|
3324
|
-
throw createCommandNotFoundError(cmdPath,
|
|
3412
|
+
throw createCommandNotFoundError(cmdPath, searchedPaths);
|
|
3325
3413
|
} catch (error) {
|
|
3326
3414
|
if (error instanceof Error && error.message.includes("No command file found")) {
|
|
3327
3415
|
throw error;
|