@reliverse/rempts 1.7.47 → 1.7.48
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 +201 -53
- package/package.json +1 -1
package/dist-npm/bin/mod.mjs
CHANGED
|
@@ -3120,6 +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
|
+
}
|
|
3123
3129
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
3124
3130
|
const cwd = process$1.cwd();
|
|
3125
3131
|
if (process$1.env.NODE_ENV === "development") {
|
|
@@ -3135,40 +3141,81 @@ const getCallerDirectory = async () => {
|
|
|
3135
3141
|
if (process$1.env.NODE_ENV === "development") {
|
|
3136
3142
|
relinka("verbose", `Checking file path: ${filePath}`);
|
|
3137
3143
|
}
|
|
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.
|
|
3144
|
+
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
|
+
!filePath.endsWith("mod.js") && // Skip compiled output
|
|
3146
|
+
!filePath.endsWith("mod.ts")) {
|
|
3141
3147
|
try {
|
|
3142
3148
|
const fileDir = dirname(filePath);
|
|
3149
|
+
let currentDir2 = fileDir;
|
|
3150
|
+
let packageRoot = null;
|
|
3151
|
+
while (currentDir2 !== dirname(currentDir2)) {
|
|
3152
|
+
try {
|
|
3153
|
+
const packageJsonPath = resolve(currentDir2, "package.json");
|
|
3154
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
3155
|
+
packageRoot = currentDir2;
|
|
3156
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3157
|
+
relinka("verbose", `Found package.json at: ${packageRoot}`);
|
|
3158
|
+
}
|
|
3159
|
+
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
3160
|
+
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
3161
|
+
try {
|
|
3162
|
+
const callerPackage = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
3163
|
+
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
3164
|
+
if (callerPackage.name !== cwdPackage.name || callerPackage.version !== cwdPackage.version) {
|
|
3165
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3166
|
+
relinka("verbose", `Using caller package root: ${packageRoot} (${callerPackage.name}@${callerPackage.version})`);
|
|
3167
|
+
}
|
|
3168
|
+
return packageRoot;
|
|
3169
|
+
}
|
|
3170
|
+
} catch {
|
|
3171
|
+
if (resolve(packageRoot) !== resolve(cwd)) {
|
|
3172
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3173
|
+
relinka("verbose", `Using caller package root (different path): ${packageRoot}`);
|
|
3174
|
+
}
|
|
3175
|
+
return packageRoot;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
} else {
|
|
3179
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3180
|
+
relinka("verbose", `Using caller package root (no CWD package.json): ${packageRoot}`);
|
|
3181
|
+
}
|
|
3182
|
+
return packageRoot;
|
|
3183
|
+
}
|
|
3184
|
+
break;
|
|
3185
|
+
}
|
|
3186
|
+
} catch {
|
|
3187
|
+
}
|
|
3188
|
+
currentDir2 = dirname(currentDir2);
|
|
3189
|
+
}
|
|
3143
3190
|
const resolvedFileDir = resolve(fileDir);
|
|
3144
3191
|
const resolvedCwd = resolve(cwd);
|
|
3145
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3146
|
-
relinka("verbose", `File dir: ${fileDir}, resolved: ${resolvedFileDir}, cwd: ${resolvedCwd}`);
|
|
3147
|
-
}
|
|
3148
3192
|
if (resolvedFileDir !== resolvedCwd && !resolvedFileDir.startsWith(resolvedCwd)) {
|
|
3149
|
-
|
|
3150
|
-
|
|
3193
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3194
|
+
relinka("verbose", `Using caller directory (different from CWD): ${fileDir}`);
|
|
3195
|
+
}
|
|
3196
|
+
return packageRoot || fileDir;
|
|
3151
3197
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3198
|
+
} catch {
|
|
3199
|
+
continue;
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
for (const line of stack) {
|
|
3205
|
+
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
3206
|
+
if (match?.[1]) {
|
|
3207
|
+
const filePath = match[1];
|
|
3208
|
+
if (filePath.includes("node_modules")) {
|
|
3209
|
+
try {
|
|
3210
|
+
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+))/);
|
|
3211
|
+
if (nodeModulesMatch?.[1]) {
|
|
3212
|
+
const packageDir = nodeModulesMatch[1];
|
|
3213
|
+
const packageJsonPath = resolve(packageDir, "package.json");
|
|
3214
|
+
if (await fs.pathExists(packageJsonPath)) {
|
|
3215
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3216
|
+
relinka("verbose", `Found command package in node_modules: ${packageDir}`);
|
|
3170
3217
|
}
|
|
3171
|
-
|
|
3218
|
+
return packageDir;
|
|
3172
3219
|
}
|
|
3173
3220
|
}
|
|
3174
3221
|
} catch {
|
|
@@ -3182,33 +3229,18 @@ const getCallerDirectory = async () => {
|
|
|
3182
3229
|
try {
|
|
3183
3230
|
const packageJsonPath = resolve(currentDir, "package.json");
|
|
3184
3231
|
if (await fs.pathExists(packageJsonPath)) {
|
|
3185
|
-
|
|
3232
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3233
|
+
relinka("verbose", `Found package.json at: ${currentDir}`);
|
|
3234
|
+
}
|
|
3186
3235
|
return currentDir;
|
|
3187
3236
|
}
|
|
3188
3237
|
} catch {
|
|
3189
3238
|
}
|
|
3190
3239
|
currentDir = dirname(currentDir);
|
|
3191
3240
|
}
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
resolve(cwd, "src", "build", "cmd.ts"),
|
|
3195
|
-
resolve(cwd, "src", "build", "cmd.js"),
|
|
3196
|
-
resolve(cwd, "src-ts", "build", "cmd.ts"),
|
|
3197
|
-
resolve(cwd, "src-ts", "build", "cmd.js"),
|
|
3198
|
-
resolve(cwd, "build", "cmd.ts"),
|
|
3199
|
-
resolve(cwd, "build", "cmd.js"),
|
|
3200
|
-
resolve(cwd, "app", "build", "cmd.ts"),
|
|
3201
|
-
resolve(cwd, "app", "build", "cmd.js")
|
|
3202
|
-
];
|
|
3203
|
-
for (const path of possibleCommandPaths) {
|
|
3204
|
-
if (await fs.pathExists(path)) {
|
|
3205
|
-
relinka("verbose", `Found command file at: ${path}, using cwd: ${cwd}`);
|
|
3206
|
-
return cwd;
|
|
3207
|
-
}
|
|
3208
|
-
}
|
|
3209
|
-
} catch {
|
|
3241
|
+
if (process$1.env.NODE_ENV === "development") {
|
|
3242
|
+
relinka("verbose", `No suitable caller found, using cwd: ${cwd}`);
|
|
3210
3243
|
}
|
|
3211
|
-
relinka("verbose", `No suitable caller found, using cwd: ${cwd}`);
|
|
3212
3244
|
return process$1.cwd();
|
|
3213
3245
|
};
|
|
3214
3246
|
const tryLoadCommand = async (path) => {
|
|
@@ -3246,15 +3278,45 @@ const generateAlternativePaths = async (cmdPath, callerDir) => {
|
|
|
3246
3278
|
// Command in src subdirectory
|
|
3247
3279
|
resolve(callerDir, "src", normalizedCmdPath, "cmd.ts"),
|
|
3248
3280
|
resolve(callerDir, "src", normalizedCmdPath, "cmd.js"),
|
|
3281
|
+
// Command in src/app subdirectory
|
|
3282
|
+
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.ts"),
|
|
3283
|
+
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.js"),
|
|
3249
3284
|
// Command in src-ts subdirectory
|
|
3250
3285
|
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.ts"),
|
|
3251
3286
|
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.js"),
|
|
3287
|
+
// Command in src-ts/app subdirectory (for dler-like structures)
|
|
3288
|
+
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.ts"),
|
|
3289
|
+
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.js"),
|
|
3290
|
+
// Command in lib subdirectory
|
|
3291
|
+
resolve(callerDir, "lib", normalizedCmdPath, "cmd.ts"),
|
|
3292
|
+
resolve(callerDir, "lib", normalizedCmdPath, "cmd.js"),
|
|
3293
|
+
// Command in lib/app subdirectory
|
|
3294
|
+
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.ts"),
|
|
3295
|
+
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.js"),
|
|
3296
|
+
// Command in dist subdirectory (compiled)
|
|
3297
|
+
resolve(callerDir, "dist", normalizedCmdPath, "cmd.js"),
|
|
3298
|
+
resolve(callerDir, "dist", "app", normalizedCmdPath, "cmd.js"),
|
|
3252
3299
|
// Command in bin subdirectory
|
|
3253
3300
|
resolve(callerDir, "bin", normalizedCmdPath, "cmd.ts"),
|
|
3254
3301
|
resolve(callerDir, "bin", normalizedCmdPath, "cmd.js"),
|
|
3255
3302
|
// Command in bin/app subdirectory (common for CLI tools)
|
|
3256
3303
|
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.ts"),
|
|
3257
|
-
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js")
|
|
3304
|
+
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js"),
|
|
3305
|
+
// Command in commands subdirectory
|
|
3306
|
+
resolve(callerDir, "commands", normalizedCmdPath, "cmd.ts"),
|
|
3307
|
+
resolve(callerDir, "commands", normalizedCmdPath, "cmd.js"),
|
|
3308
|
+
// Command in cli subdirectory
|
|
3309
|
+
resolve(callerDir, "cli", normalizedCmdPath, "cmd.ts"),
|
|
3310
|
+
resolve(callerDir, "cli", normalizedCmdPath, "cmd.js"),
|
|
3311
|
+
// Command in cli/commands subdirectory
|
|
3312
|
+
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.ts"),
|
|
3313
|
+
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.js"),
|
|
3314
|
+
// Command in tools subdirectory
|
|
3315
|
+
resolve(callerDir, "tools", normalizedCmdPath, "cmd.ts"),
|
|
3316
|
+
resolve(callerDir, "tools", normalizedCmdPath, "cmd.js"),
|
|
3317
|
+
// Command in scripts subdirectory
|
|
3318
|
+
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.ts"),
|
|
3319
|
+
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.js")
|
|
3258
3320
|
];
|
|
3259
3321
|
for (const path of commonCommandLocations) {
|
|
3260
3322
|
if (await fs.pathExists(path)) {
|
|
@@ -3306,8 +3368,10 @@ async function loadCommand(cmdPath) {
|
|
|
3306
3368
|
return command;
|
|
3307
3369
|
}
|
|
3308
3370
|
}
|
|
3371
|
+
let allSearchedPaths = [...candidatePaths];
|
|
3309
3372
|
if (callerDir !== process$1.cwd()) {
|
|
3310
3373
|
const alternativePaths = await generateAlternativePaths(cmdPath, callerDir);
|
|
3374
|
+
allSearchedPaths.push(...alternativePaths);
|
|
3311
3375
|
if (process$1.env.NODE_ENV === "development") {
|
|
3312
3376
|
relinka("verbose", `Trying alternative paths: ${alternativePaths.join(", ")}`);
|
|
3313
3377
|
}
|
|
@@ -3321,7 +3385,7 @@ async function loadCommand(cmdPath) {
|
|
|
3321
3385
|
}
|
|
3322
3386
|
}
|
|
3323
3387
|
}
|
|
3324
|
-
throw createCommandNotFoundError(cmdPath,
|
|
3388
|
+
throw createCommandNotFoundError(cmdPath, allSearchedPaths);
|
|
3325
3389
|
} catch (error) {
|
|
3326
3390
|
if (error instanceof Error && error.message.includes("No command file found")) {
|
|
3327
3391
|
throw error;
|
|
@@ -6389,8 +6453,9 @@ function argsToStringArray(args) {
|
|
|
6389
6453
|
}
|
|
6390
6454
|
async function createCallCmd() {
|
|
6391
6455
|
return async function callCmd(cmdName, args) {
|
|
6456
|
+
const originalCaller = await getOriginalCallerDirectory();
|
|
6392
6457
|
try {
|
|
6393
|
-
const command = await
|
|
6458
|
+
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6394
6459
|
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6395
6460
|
await runCmd(command, stringArgs);
|
|
6396
6461
|
} catch (error) {
|
|
@@ -6401,7 +6466,8 @@ async function createCallCmd() {
|
|
|
6401
6466
|
}
|
|
6402
6467
|
async function createGetTypedCmd() {
|
|
6403
6468
|
return async function getTypedCmd(cmdName) {
|
|
6404
|
-
const
|
|
6469
|
+
const originalCaller = await getOriginalCallerDirectory();
|
|
6470
|
+
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6405
6471
|
return {
|
|
6406
6472
|
command,
|
|
6407
6473
|
run: async (args) => {
|
|
@@ -6412,8 +6478,9 @@ async function createGetTypedCmd() {
|
|
|
6412
6478
|
};
|
|
6413
6479
|
}
|
|
6414
6480
|
async function callCmdImpl(cmdName, args) {
|
|
6481
|
+
const originalCaller = await getOriginalCallerDirectory();
|
|
6415
6482
|
try {
|
|
6416
|
-
const command = await
|
|
6483
|
+
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6417
6484
|
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6418
6485
|
await runCmd(command, stringArgs);
|
|
6419
6486
|
} catch (error) {
|
|
@@ -6421,8 +6488,89 @@ async function callCmdImpl(cmdName, args) {
|
|
|
6421
6488
|
throw error;
|
|
6422
6489
|
}
|
|
6423
6490
|
}
|
|
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
|
+
}
|
|
6424
6571
|
async function getTypedCmdImpl(cmdName) {
|
|
6425
|
-
const
|
|
6572
|
+
const originalCaller = await getOriginalCallerDirectory();
|
|
6573
|
+
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6426
6574
|
return {
|
|
6427
6575
|
command,
|
|
6428
6576
|
run: async (args) => {
|