Skip to content

Commit a9efb8c

Browse files
committed
New: Filepath.resolve() now uses the Filepath.base when resolving
1 parent 54ae53d commit a9efb8c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/v1/Filepath/Filepath.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ describe("Filepath()", () => {
547547
];
548548
const expectParamList = [
549549
// from unit.resolve()
550-
[ "/tmp/this/is/an/example", "..", "..", "another/example"],
550+
[ "", "/tmp/this/is/an/example", "..", "..", "another/example"],
551551

552552
// from the retval.constructor
553553
"/tmp/this/is/another/example"

src/v1/Filepath/Filepath.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ import { MakeFilepathOptions } from "./MakeFilepathOptions";
3737
import { mustBeFilepathData } from "./mustBeFilepathData";
3838

3939
/**
40-
* `Filepath` is a safe type.
40+
* `Filepath` is a safe type. It represents a path to an item on
41+
* a (possibly local) filesystem.
42+
*
43+
* It acts as a wrapper around NodeJS's `path` module.
4144
*
4245
* @category Filepath
4346
*/
@@ -305,11 +308,19 @@ export class Filepath extends RefinedString {
305308
* same `pathApi` that this Filepath does.
306309
*
307310
* @returns
308-
* The assembled, normalised path. Always an absolute path.
311+
* The assembled, normalised Filepath. Guaranteed to be an absolute path.
309312
*/
310313
public resolve(...paths: string[]): Filepath {
314+
// resolve() will always return an absolute path
315+
const newAbsPath = this.#_pathApi.resolve(
316+
this.#_base || "",
317+
this._value,
318+
...paths
319+
);
320+
321+
// all done
311322
return new Filepath(
312-
this.#_pathApi.resolve(this._value, ...paths),
323+
newAbsPath,
313324
{
314325
pathApi: this.#_pathApi,
315326
base: this.#_base

0 commit comments

Comments
 (0)