path-scurry
Advanced tools
Comparing version 1.7.1 to 1.8.0
@@ -102,2 +102,3 @@ /// <reference types="node" /> | ||
}; | ||
declare const setAsCwd: unique symbol; | ||
/** | ||
@@ -443,2 +444,9 @@ * Path objects are sort of like a super-powered | ||
realpathSync(): PathBase | undefined; | ||
/** | ||
* Internal method to mark this Path object as the scurry cwd, | ||
* called by {@link PathScurry#chdir} | ||
* | ||
* @internal | ||
*/ | ||
[setAsCwd](oldCwd: PathBase): void; | ||
} | ||
@@ -952,2 +960,3 @@ /** | ||
streamSync(entry: string | PathBase, opts: WalkOptions): Minipass<string> | Minipass<PathBase>; | ||
chdir(path?: string | Path): void; | ||
} | ||
@@ -954,0 +963,0 @@ /** |
@@ -102,2 +102,3 @@ /// <reference types="node" /> | ||
}; | ||
declare const setAsCwd: unique symbol; | ||
/** | ||
@@ -443,2 +444,9 @@ * Path objects are sort of like a super-powered | ||
realpathSync(): PathBase | undefined; | ||
/** | ||
* Internal method to mark this Path object as the scurry cwd, | ||
* called by {@link PathScurry#chdir} | ||
* | ||
* @internal | ||
*/ | ||
[setAsCwd](oldCwd: PathBase): void; | ||
} | ||
@@ -952,2 +960,3 @@ /** | ||
streamSync(entry: string | PathBase, opts: WalkOptions): Minipass<string> | Minipass<PathBase>; | ||
chdir(path?: string | Path): void; | ||
} | ||
@@ -954,0 +963,0 @@ /** |
@@ -134,2 +134,3 @@ import { LRUCache } from 'lru-cache'; | ||
} | ||
const setAsCwd = Symbol('PathScurry setAsCwd'); | ||
/** | ||
@@ -414,4 +415,3 @@ * Path objects are sort of like a super-powered | ||
const pv = p.relative(); | ||
const rp = pv + (!pv || !p.parent ? '' : this.sep) + name; | ||
return (this.#relative = rp); | ||
return pv + (!pv || !p.parent ? '' : this.sep) + name; | ||
} | ||
@@ -435,4 +435,3 @@ /** | ||
const pv = p.relativePosix(); | ||
const rp = pv + (!pv || !p.parent ? '' : '/') + name; | ||
return (this.#relativePosix = rp); | ||
return pv + (!pv || !p.parent ? '' : '/') + name; | ||
} | ||
@@ -1089,2 +1088,29 @@ /** | ||
} | ||
/** | ||
* Internal method to mark this Path object as the scurry cwd, | ||
* called by {@link PathScurry#chdir} | ||
* | ||
* @internal | ||
*/ | ||
[setAsCwd](oldCwd) { | ||
if (oldCwd === this) | ||
return; | ||
const changed = new Set([]); | ||
let rp = []; | ||
let p = this; | ||
while (p && p.parent) { | ||
changed.add(p); | ||
p.#relative = rp.join(this.sep); | ||
p.#relativePosix = rp.join('/'); | ||
p = p.parent; | ||
rp.push('..'); | ||
} | ||
// now un-memoize parents of old cwd | ||
p = oldCwd; | ||
while (p && p.parent && !changed.has(p)) { | ||
p.#relative = undefined; | ||
p.#relativePosix = undefined; | ||
p = p.parent; | ||
} | ||
} | ||
} | ||
@@ -1814,2 +1840,7 @@ /** | ||
} | ||
chdir(path = this.cwd) { | ||
const oldCwd = this.cwd; | ||
this.cwd = typeof path === 'string' ? this.cwd.resolve(path) : path; | ||
this.cwd[setAsCwd](oldCwd); | ||
} | ||
} | ||
@@ -1816,0 +1847,0 @@ /** |
{ | ||
"name": "path-scurry", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "walk paths fast and efficiently", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Z. Schlueter <i@izs.me> (https://blog.izs.me)", |
@@ -337,2 +337,8 @@ # path-scurry | ||
#### `pw.chdir(path: string)` | ||
Set the new effective current working directory for the scurry | ||
object, so that `path.relative()` and `path.relativePosix()` | ||
return values relative to the new cwd path. | ||
#### `pw.depth(path?: Path | string): number` | ||
@@ -339,0 +345,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
520899
6123
620