@wrongstack/tools 0.306.2 → 0.306.4

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/exec.js CHANGED
@@ -487,8 +487,9 @@ async function resolveRealInsideRoot(absPath, ctx) {
487
487
  }
488
488
  throw err;
489
489
  }
490
- if (isInsideAny(real, realRoots)) {
491
- return pendingTail.length > 0 ? path2.join(real, ...pendingTail) : real;
490
+ const candidate = pendingTail.length > 0 ? path2.join(real, ...pendingTail) : real;
491
+ if (isInsideAny(candidate, realRoots)) {
492
+ return candidate;
492
493
  }
493
494
  throw new Error(
494
495
  `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`
package/dist/format.js CHANGED
@@ -1041,6 +1041,7 @@ function utf8Prefix(text, maxBytes) {
1041
1041
  }
1042
1042
 
1043
1043
  // src/_util.ts
1044
+ import * as fsp2 from "node:fs/promises";
1044
1045
  import * as path3 from "node:path";
1045
1046
  import * as Core from "@wrongstack/core/utils";
1046
1047
  function resolvePath(input, ctx) {
@@ -1064,6 +1065,40 @@ function ensureInsideRoot(absPath, ctx) {
1064
1065
  function safeResolve(input, ctx) {
1065
1066
  return ensureInsideRoot(resolvePath(input, ctx), ctx);
1066
1067
  }
1068
+ async function resolveRealInsideRoot(absPath, ctx) {
1069
+ if (ctx.allowOutsideProjectRoot) return absPath;
1070
+ const realRoots = await Promise.all(
1071
+ allowedRoots(ctx).map((r) => fsp2.realpath(r).catch(() => path3.resolve(r)))
1072
+ );
1073
+ let probe = absPath;
1074
+ const pendingTail = [];
1075
+ for (; ; ) {
1076
+ let real;
1077
+ try {
1078
+ real = await fsp2.realpath(probe);
1079
+ } catch (err) {
1080
+ if (err.code === "ENOENT") {
1081
+ const parent = path3.dirname(probe);
1082
+ if (parent === probe) return absPath;
1083
+ pendingTail.unshift(path3.basename(probe));
1084
+ probe = parent;
1085
+ continue;
1086
+ }
1087
+ throw err;
1088
+ }
1089
+ const candidate = pendingTail.length > 0 ? path3.join(real, ...pendingTail) : real;
1090
+ if (isInsideAny(candidate, realRoots)) {
1091
+ return candidate;
1092
+ }
1093
+ throw new Error(
1094
+ `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`
1095
+ );
1096
+ }
1097
+ }
1098
+ async function safeResolveReal(input, ctx) {
1099
+ const abs = safeResolve(input, ctx);
1100
+ return await resolveRealInsideRoot(abs, ctx);
1101
+ }
1067
1102
  var COMMAND_OUTPUT_MAX_BYTES = 32768;
1068
1103
  var REPEAT_RUN_THRESHOLD = 3;
1069
1104
  function collapseCarriageReturns(text) {
@@ -3590,7 +3625,7 @@ var formatTool = {
3590
3625
  return final;
3591
3626
  },
3592
3627
  async *executeStream(input, ctx, opts) {
3593
- const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;
3628
+ const cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : ctx.cwd;
3594
3629
  const fixer = input.fixer ?? "auto";
3595
3630
  if (fixer === "auto" && !input.files) {
3596
3631
  const op = input.check ? "format-check" : "format-write";
package/dist/glob.js CHANGED
@@ -125,8 +125,9 @@ async function resolveRealInsideRoot(absPath, ctx) {
125
125
  }
126
126
  throw err;
127
127
  }
128
- if (isInsideAny(real, realRoots)) {
129
- return pendingTail.length > 0 ? path2.join(real, ...pendingTail) : real;
128
+ const candidate = pendingTail.length > 0 ? path2.join(real, ...pendingTail) : real;
129
+ if (isInsideAny(candidate, realRoots)) {
130
+ return candidate;
130
131
  }
131
132
  throw new Error(
132
133
  `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`
package/dist/grep.js CHANGED
@@ -199,8 +199,9 @@ async function resolveRealInsideRoot(absPath, ctx) {
199
199
  }
200
200
  throw err;
201
201
  }
202
- if (isInsideAny(real, realRoots)) {
203
- return pendingTail.length > 0 ? path.join(real, ...pendingTail) : real;
202
+ const candidate = pendingTail.length > 0 ? path.join(real, ...pendingTail) : real;
203
+ if (isInsideAny(candidate, realRoots)) {
204
+ return candidate;
204
205
  }
205
206
  throw new Error(
206
207
  `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`