@f5-sales-demo/pi-utils 19.87.0 → 19.87.1

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/dirs.ts +22 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5-sales-demo/pi-utils",
4
- "version": "19.87.0",
4
+ "version": "19.87.1",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/f5-sales-demo/xcsh",
7
7
  "author": "Can Boluk",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/bun": "^1.3",
42
- "@f5-sales-demo/pi-natives": "19.87.0"
42
+ "@f5-sales-demo/pi-natives": "19.87.1"
43
43
  },
44
44
  "engines": {
45
45
  "bun": ">=1.3.7"
package/src/dirs.ts CHANGED
@@ -52,7 +52,28 @@ export function resolveEquivalentPath(inputPath: string): string {
52
52
  try {
53
53
  return fs.realpathSync(resolvedPath);
54
54
  } catch {
55
- return resolvedPath;
55
+ // The full path does not exist on disk, so realpath can't resolve it. Canonicalize
56
+ // the deepest existing ancestor (resolving any symlinked prefix — e.g. macOS
57
+ // /tmp -> /private/tmp) and re-append the missing remainder, so comparisons stay
58
+ // symlink-consistent whether or not the leaf exists. Without this, a boundary root
59
+ // that exists gets canonicalized while a not-yet-created target under a symlinked
60
+ // cwd does not, and pathIsWithin() falsely reports it out-of-tree (issue #2312).
61
+ return canonicalizeExistingAncestor(resolvedPath);
62
+ }
63
+ }
64
+
65
+ /** realpath the deepest existing ancestor of an absolute path, re-appending the missing tail. */
66
+ function canonicalizeExistingAncestor(resolvedPath: string): string {
67
+ let ancestor = resolvedPath;
68
+ while (true) {
69
+ const parent = path.dirname(ancestor);
70
+ if (parent === ancestor) return resolvedPath; // reached the root with nothing resolvable
71
+ try {
72
+ const realParent = fs.realpathSync(parent);
73
+ return path.join(realParent, path.relative(parent, resolvedPath));
74
+ } catch {
75
+ ancestor = parent;
76
+ }
56
77
  }
57
78
  }
58
79