@reliverse/rempts 1.7.48 → 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 +70 -130
- package/package.json +1 -1
package/dist-npm/bin/mod.mjs
CHANGED
|
@@ -3120,18 +3120,12 @@ const jiti = createJiti(import.meta.url, {
|
|
|
3120
3120
|
const COMMAND_EXTENSIONS = [".ts", ".js"];
|
|
3121
3121
|
const COMMAND_FILENAMES = ["cmd.ts", "cmd.js"];
|
|
3122
3122
|
const getCallerDirectory = async () => {
|
|
3123
|
-
if (process$1.env._REMPTS_CALLER_DIR) {
|
|
3124
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3125
|
-
relinka("verbose", `Using explicit caller directory: ${process$1.env._REMPTS_CALLER_DIR}`);
|
|
3126
|
-
}
|
|
3127
|
-
return process$1.env._REMPTS_CALLER_DIR;
|
|
3128
|
-
}
|
|
3129
3123
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
3130
3124
|
const cwd = process$1.cwd();
|
|
3131
3125
|
if (process$1.env.NODE_ENV === "development") {
|
|
3132
|
-
relinka("
|
|
3126
|
+
relinka("log", "Stack trace for getCallerDirectory:");
|
|
3133
3127
|
stack.forEach((line, index) => {
|
|
3134
|
-
relinka("
|
|
3128
|
+
relinka("log", ` [${index}]: ${line.trim()}`);
|
|
3135
3129
|
});
|
|
3136
3130
|
}
|
|
3137
3131
|
for (const line of stack) {
|
|
@@ -3139,7 +3133,7 @@ const getCallerDirectory = async () => {
|
|
|
3139
3133
|
if (match?.[1]) {
|
|
3140
3134
|
const filePath = match[1];
|
|
3141
3135
|
if (process$1.env.NODE_ENV === "development") {
|
|
3142
|
-
relinka("
|
|
3136
|
+
relinka("log", `Checking file path: ${filePath}`);
|
|
3143
3137
|
}
|
|
3144
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
|
|
3145
3139
|
!filePath.endsWith("mod.js") && // Skip compiled output
|
|
@@ -3154,7 +3148,7 @@ const getCallerDirectory = async () => {
|
|
|
3154
3148
|
if (await fs.pathExists(packageJsonPath)) {
|
|
3155
3149
|
packageRoot = currentDir2;
|
|
3156
3150
|
if (process$1.env.NODE_ENV === "development") {
|
|
3157
|
-
relinka("
|
|
3151
|
+
relinka("log", `Found package.json at: ${packageRoot}`);
|
|
3158
3152
|
}
|
|
3159
3153
|
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
3160
3154
|
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
@@ -3163,21 +3157,21 @@ const getCallerDirectory = async () => {
|
|
|
3163
3157
|
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
3164
3158
|
if (callerPackage.name !== cwdPackage.name || callerPackage.version !== cwdPackage.version) {
|
|
3165
3159
|
if (process$1.env.NODE_ENV === "development") {
|
|
3166
|
-
relinka("
|
|
3160
|
+
relinka("log", `Using caller package root: ${packageRoot} (${callerPackage.name}@${callerPackage.version})`);
|
|
3167
3161
|
}
|
|
3168
3162
|
return packageRoot;
|
|
3169
3163
|
}
|
|
3170
3164
|
} catch {
|
|
3171
3165
|
if (resolve(packageRoot) !== resolve(cwd)) {
|
|
3172
3166
|
if (process$1.env.NODE_ENV === "development") {
|
|
3173
|
-
relinka("
|
|
3167
|
+
relinka("log", `Using caller package root (different path): ${packageRoot}`);
|
|
3174
3168
|
}
|
|
3175
3169
|
return packageRoot;
|
|
3176
3170
|
}
|
|
3177
3171
|
}
|
|
3178
3172
|
} else {
|
|
3179
3173
|
if (process$1.env.NODE_ENV === "development") {
|
|
3180
|
-
relinka("
|
|
3174
|
+
relinka("log", `Using caller package root (no CWD package.json): ${packageRoot}`);
|
|
3181
3175
|
}
|
|
3182
3176
|
return packageRoot;
|
|
3183
3177
|
}
|
|
@@ -3191,7 +3185,7 @@ const getCallerDirectory = async () => {
|
|
|
3191
3185
|
const resolvedCwd = resolve(cwd);
|
|
3192
3186
|
if (resolvedFileDir !== resolvedCwd && !resolvedFileDir.startsWith(resolvedCwd)) {
|
|
3193
3187
|
if (process$1.env.NODE_ENV === "development") {
|
|
3194
|
-
relinka("
|
|
3188
|
+
relinka("log", `Using caller directory (different from CWD): ${fileDir}`);
|
|
3195
3189
|
}
|
|
3196
3190
|
return packageRoot || fileDir;
|
|
3197
3191
|
}
|
|
@@ -3207,13 +3201,13 @@ const getCallerDirectory = async () => {
|
|
|
3207
3201
|
const filePath = match[1];
|
|
3208
3202
|
if (filePath.includes("node_modules")) {
|
|
3209
3203
|
try {
|
|
3210
|
-
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/
|
|
3204
|
+
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/[^\/]+)/);
|
|
3211
3205
|
if (nodeModulesMatch?.[1]) {
|
|
3212
3206
|
const packageDir = nodeModulesMatch[1];
|
|
3213
3207
|
const packageJsonPath = resolve(packageDir, "package.json");
|
|
3214
3208
|
if (await fs.pathExists(packageJsonPath)) {
|
|
3215
3209
|
if (process$1.env.NODE_ENV === "development") {
|
|
3216
|
-
relinka("
|
|
3210
|
+
relinka("log", `Found command package in node_modules: ${packageDir}`);
|
|
3217
3211
|
}
|
|
3218
3212
|
return packageDir;
|
|
3219
3213
|
}
|
|
@@ -3230,7 +3224,7 @@ const getCallerDirectory = async () => {
|
|
|
3230
3224
|
const packageJsonPath = resolve(currentDir, "package.json");
|
|
3231
3225
|
if (await fs.pathExists(packageJsonPath)) {
|
|
3232
3226
|
if (process$1.env.NODE_ENV === "development") {
|
|
3233
|
-
relinka("
|
|
3227
|
+
relinka("log", `Found package.json at: ${currentDir}`);
|
|
3234
3228
|
}
|
|
3235
3229
|
return currentDir;
|
|
3236
3230
|
}
|
|
@@ -3239,17 +3233,38 @@ const getCallerDirectory = async () => {
|
|
|
3239
3233
|
currentDir = dirname(currentDir);
|
|
3240
3234
|
}
|
|
3241
3235
|
if (process$1.env.NODE_ENV === "development") {
|
|
3242
|
-
relinka("
|
|
3236
|
+
relinka("log", `No suitable caller found, using cwd: ${cwd}`);
|
|
3243
3237
|
}
|
|
3244
3238
|
return process$1.cwd();
|
|
3245
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);
|
|
3255
|
+
}
|
|
3256
|
+
} catch {
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
return Array.from(packageDirs);
|
|
3260
|
+
};
|
|
3246
3261
|
const tryLoadCommand = async (path) => {
|
|
3247
3262
|
if (!await fs.pathExists(path)) return null;
|
|
3248
3263
|
try {
|
|
3249
3264
|
const cmd = await jiti.import(path, { default: true });
|
|
3250
3265
|
return cmd;
|
|
3251
3266
|
} catch {
|
|
3252
|
-
relinka("
|
|
3267
|
+
relinka("log", `Failed to load ${path} as a command file`);
|
|
3253
3268
|
return null;
|
|
3254
3269
|
}
|
|
3255
3270
|
};
|
|
@@ -3350,42 +3365,51 @@ async function loadCommand(cmdPath) {
|
|
|
3350
3365
|
const normalizedPath = cmdPath.replace(/^\.\//, "");
|
|
3351
3366
|
const resolvedPath = resolve(callerDir, normalizedPath);
|
|
3352
3367
|
if (process$1.env.NODE_ENV === "development") {
|
|
3353
|
-
relinka("
|
|
3354
|
-
relinka("
|
|
3355
|
-
relinka("
|
|
3356
|
-
relinka("
|
|
3357
|
-
}
|
|
3358
|
-
const
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
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;
|
|
3367
3392
|
}
|
|
3368
|
-
return command;
|
|
3369
3393
|
}
|
|
3370
3394
|
}
|
|
3371
|
-
|
|
3372
|
-
if (
|
|
3373
|
-
const
|
|
3374
|
-
allSearchedPaths.push(...alternativePaths);
|
|
3395
|
+
const looksLikeExplicitPath = /[\\\/]|\.ts$|\.js$/.test(normalizedPath);
|
|
3396
|
+
if (looksLikeExplicitPath) {
|
|
3397
|
+
const candidatePaths = await generateCandidatePaths(resolvedPath);
|
|
3375
3398
|
if (process$1.env.NODE_ENV === "development") {
|
|
3376
|
-
relinka("
|
|
3399
|
+
relinka("log", `Candidate paths: ${candidatePaths.join(", ")}`);
|
|
3377
3400
|
}
|
|
3378
|
-
|
|
3401
|
+
searchedPaths.push(...candidatePaths);
|
|
3402
|
+
for (const path of candidatePaths) {
|
|
3379
3403
|
const command = await tryLoadCommand(path);
|
|
3380
3404
|
if (command) {
|
|
3381
3405
|
if (process$1.env.NODE_ENV === "development") {
|
|
3382
|
-
relinka("
|
|
3406
|
+
relinka("log", `Successfully loaded command from: ${path}`);
|
|
3383
3407
|
}
|
|
3384
3408
|
return command;
|
|
3385
3409
|
}
|
|
3386
3410
|
}
|
|
3387
3411
|
}
|
|
3388
|
-
throw createCommandNotFoundError(cmdPath,
|
|
3412
|
+
throw createCommandNotFoundError(cmdPath, searchedPaths);
|
|
3389
3413
|
} catch (error) {
|
|
3390
3414
|
if (error instanceof Error && error.message.includes("No command file found")) {
|
|
3391
3415
|
throw error;
|
|
@@ -6453,9 +6477,8 @@ function argsToStringArray(args) {
|
|
|
6453
6477
|
}
|
|
6454
6478
|
async function createCallCmd() {
|
|
6455
6479
|
return async function callCmd(cmdName, args) {
|
|
6456
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6457
6480
|
try {
|
|
6458
|
-
const command = await
|
|
6481
|
+
const command = await loadCommand(cmdName);
|
|
6459
6482
|
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6460
6483
|
await runCmd(command, stringArgs);
|
|
6461
6484
|
} catch (error) {
|
|
@@ -6466,8 +6489,7 @@ async function createCallCmd() {
|
|
|
6466
6489
|
}
|
|
6467
6490
|
async function createGetTypedCmd() {
|
|
6468
6491
|
return async function getTypedCmd(cmdName) {
|
|
6469
|
-
const
|
|
6470
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6492
|
+
const command = await loadCommand(cmdName);
|
|
6471
6493
|
return {
|
|
6472
6494
|
command,
|
|
6473
6495
|
run: async (args) => {
|
|
@@ -6478,9 +6500,8 @@ async function createGetTypedCmd() {
|
|
|
6478
6500
|
};
|
|
6479
6501
|
}
|
|
6480
6502
|
async function callCmdImpl(cmdName, args) {
|
|
6481
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6482
6503
|
try {
|
|
6483
|
-
const command = await
|
|
6504
|
+
const command = await loadCommand(cmdName);
|
|
6484
6505
|
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6485
6506
|
await runCmd(command, stringArgs);
|
|
6486
6507
|
} catch (error) {
|
|
@@ -6488,89 +6509,8 @@ async function callCmdImpl(cmdName, args) {
|
|
|
6488
6509
|
throw error;
|
|
6489
6510
|
}
|
|
6490
6511
|
}
|
|
6491
|
-
async function getOriginalCallerDirectory() {
|
|
6492
|
-
const stack = new Error().stack?.split("\n") ?? [];
|
|
6493
|
-
const cwd = process.cwd();
|
|
6494
|
-
for (const line of stack) {
|
|
6495
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
6496
|
-
if (match?.[1]) {
|
|
6497
|
-
const filePath = match[1];
|
|
6498
|
-
if (!filePath.includes("node_modules") && !filePath.includes("command-runner") && !filePath.includes("command-typed") && // Skip this current file
|
|
6499
|
-
!filePath.includes("launcher-mod") && !filePath.includes("launcher-types") && !filePath.endsWith("mod.mjs") && !filePath.endsWith("mod.js") && !filePath.endsWith("mod.ts")) {
|
|
6500
|
-
try {
|
|
6501
|
-
const fileDir = dirname(filePath);
|
|
6502
|
-
let currentDir = fileDir;
|
|
6503
|
-
while (currentDir !== dirname(currentDir)) {
|
|
6504
|
-
try {
|
|
6505
|
-
const packageJsonPath = resolve(currentDir, "package.json");
|
|
6506
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
6507
|
-
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
6508
|
-
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
6509
|
-
try {
|
|
6510
|
-
const callerPackage = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
6511
|
-
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
6512
|
-
if (callerPackage.name !== cwdPackage.name) {
|
|
6513
|
-
return currentDir;
|
|
6514
|
-
}
|
|
6515
|
-
} catch {
|
|
6516
|
-
if (resolve(currentDir) !== resolve(cwd)) {
|
|
6517
|
-
return currentDir;
|
|
6518
|
-
}
|
|
6519
|
-
}
|
|
6520
|
-
} else {
|
|
6521
|
-
return currentDir;
|
|
6522
|
-
}
|
|
6523
|
-
break;
|
|
6524
|
-
}
|
|
6525
|
-
} catch {
|
|
6526
|
-
}
|
|
6527
|
-
currentDir = dirname(currentDir);
|
|
6528
|
-
}
|
|
6529
|
-
} catch {
|
|
6530
|
-
continue;
|
|
6531
|
-
}
|
|
6532
|
-
}
|
|
6533
|
-
}
|
|
6534
|
-
}
|
|
6535
|
-
for (const line of stack) {
|
|
6536
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
6537
|
-
if (match?.[1]) {
|
|
6538
|
-
const filePath = match[1];
|
|
6539
|
-
if (filePath.includes("node_modules")) {
|
|
6540
|
-
try {
|
|
6541
|
-
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+))/);
|
|
6542
|
-
if (nodeModulesMatch?.[1]) {
|
|
6543
|
-
const packageDir = nodeModulesMatch[1];
|
|
6544
|
-
const packageJsonPath = resolve(packageDir, "package.json");
|
|
6545
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
6546
|
-
return packageDir;
|
|
6547
|
-
}
|
|
6548
|
-
}
|
|
6549
|
-
} catch {
|
|
6550
|
-
continue;
|
|
6551
|
-
}
|
|
6552
|
-
}
|
|
6553
|
-
}
|
|
6554
|
-
}
|
|
6555
|
-
return cwd;
|
|
6556
|
-
}
|
|
6557
|
-
async function loadCommandWithCaller(cmdPath, callerDir) {
|
|
6558
|
-
const originalEnvVar = process.env._REMPTS_CALLER_DIR;
|
|
6559
|
-
process.env._REMPTS_CALLER_DIR = callerDir;
|
|
6560
|
-
try {
|
|
6561
|
-
const command = await loadCommand(cmdPath);
|
|
6562
|
-
return command;
|
|
6563
|
-
} finally {
|
|
6564
|
-
if (originalEnvVar !== void 0) {
|
|
6565
|
-
process.env._REMPTS_CALLER_DIR = originalEnvVar;
|
|
6566
|
-
} else {
|
|
6567
|
-
delete process.env._REMPTS_CALLER_DIR;
|
|
6568
|
-
}
|
|
6569
|
-
}
|
|
6570
|
-
}
|
|
6571
6512
|
async function getTypedCmdImpl(cmdName) {
|
|
6572
|
-
const
|
|
6573
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6513
|
+
const command = await loadCommand(cmdName);
|
|
6574
6514
|
return {
|
|
6575
6515
|
command,
|
|
6576
6516
|
run: async (args) => {
|