Skip to content

Commit 0cdf128

Browse files
committed
style: cleanup fs exports
1 parent 035125e commit 0cdf128

File tree

6 files changed

+76
-29
lines changed

6 files changed

+76
-29
lines changed

packages/fs/src/dir.lib.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as fsSync from "fs";
77
import * as fs from "fs/promises";
88
import { dirs } from "./dirs-array.lib.ts";
99
import { FsFile } from "./file.lib.ts";
10-
import { files, filesFromDir } from "./files-array.lib.ts";
10+
import { fsFiles, fsFilesFromDir } from "./files-array.lib.ts";
1111

1212
export class FsDir extends Pipeable<FsDir> {
1313
private readonly _path: AnyPath;
@@ -395,7 +395,7 @@ Trying to access a dir file from an absolute paths:
395395
.cwd(this._path)
396396
.options({ absolute: true })
397397
.find(...patterns)
398-
.then(files);
398+
.then(fsFiles);
399399
}
400400

401401
/**
@@ -416,7 +416,7 @@ Trying to access a dir file from an absolute paths:
416416
* ```
417417
*/
418418
public globSync(...patterns: Array<string> | [Array<string>]) {
419-
return files(
419+
return fsFiles(
420420
glob
421421
.cwd(this._path)
422422
.options({ absolute: true })
@@ -475,7 +475,7 @@ Trying to access a dir file from an absolute paths:
475475
* ```
476476
*/
477477
public async gitLs() {
478-
return git.ls(this._path).then(filesFromDir(this));
478+
return git.ls(this._path).then(fsFilesFromDir(this));
479479
}
480480

481481
/**
@@ -512,4 +512,9 @@ Trying to access a dir file from an absolute paths:
512512
* const existingDir = dir(dir("/path/to/existing"));
513513
* ```
514514
*/
515+
export const fsDir = FsDir.cwd;
516+
517+
/**
518+
* @deprecated Changed to avoid namespacing conflicts. Use {@link fsDir} instead
519+
*/
515520
export const dir = FsDir.cwd;

packages/fs/src/dirs-array.lib.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { enhance, type Enhanced } from "@synstack/enhance";
22
import { type AnyPath } from "@synstack/path";
3-
import { dir as fsDir, FsDir } from "./dir.lib.ts";
3+
import { fsDir, FsDir } from "./dir.lib.ts";
44
import type { FsFile } from "./file.lib.ts";
55

66
/**
@@ -15,7 +15,7 @@ export interface FsDirArrayMethods {
1515

1616
const dirsArrayMethods: FsDirArrayMethods = {
1717
filter(fn) {
18-
return dirs(this.filter(fn));
18+
return fsDirs(this.filter(fn));
1919
},
2020

2121
toPaths() {
@@ -33,5 +33,15 @@ export type FsDirArray = Enhanced<
3333
FsDirArrayMethods
3434
>;
3535

36-
export const dirs = (dirs: Array<FsDir | AnyPath>): FsDirArray =>
36+
/**
37+
* Create a new FsDirArray instance with the provided directories.
38+
* @param dirs - An array of FsDir or AnyPath instances
39+
* @returns A new FsDirArray instance
40+
*/
41+
export const fsDirs = (dirs: Array<FsDir | AnyPath>): FsDirArray =>
3742
enhance("dirs_array", dirs.map(fsDir), dirsArrayMethods);
43+
44+
/**
45+
* @deprecated Changed to avoid namespacing conflicts. Use {@link fsDirs} instead
46+
*/
47+
export const dirs = fsDirs;

packages/fs/src/file.lib.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33
import { z } from "zod";
44
import { assertType } from "../../shared/src/ts.utils.ts";
5-
import { dir } from "./dir.lib.ts";
6-
import { file } from "./file.lib.ts";
5+
import { fsDir } from "./dir.lib.ts";
6+
import { fsFile } from "./file.lib.ts";
77

88
const _typeTests = async () => {
99
const schema = z.object({
1010
id: z.string(),
1111
name: z.string(),
1212
});
13-
const schemaFile = file("").schema(schema);
13+
const schemaFile = fsFile("").schema(schema);
1414
type Output = z.infer<typeof schema>;
1515

1616
assertType<Output>(await schemaFile.read.json());
17-
assertType<[1, 2]>(await file("").read.json<[1, 2]>());
17+
assertType<[1, 2]>(await fsFile("").read.json<[1, 2]>());
1818
assertType<Output>(schemaFile.read.jsonSync());
1919
assertType<Output>(await schemaFile.read.yaml());
2020
assertType<Output>(schemaFile.read.yamlSync());
@@ -30,49 +30,49 @@ const _typeTests = async () => {
3030
describe("File", () => {
3131
describe("file", () => {
3232
it("creates a file from a path", () => {
33-
const testFile = file("/super/path/test.txt");
33+
const testFile = fsFile("/super/path/test.txt");
3434
assert.equal(testFile.path, "/super/path/test.txt");
3535
});
3636
});
3737
describe("toFile", () => {
3838
it("creates a file from a relative path", () => {
39-
const testFile = file("/super/path/test.txt");
39+
const testFile = fsFile("/super/path/test.txt");
4040
assert.equal(testFile.toFile("../other.txt").path, "/super/other.txt");
4141
});
4242
});
4343
describe("toDir", () => {
4444
it("creates a dir from a relative path", () => {
45-
const testFile = file("/super/path/test.txt");
45+
const testFile = fsFile("/super/path/test.txt");
4646
assert.equal(testFile.toDir("../other").path, "/super/other");
4747
});
4848
});
4949
describe("relativePathTo", () => {
5050
it("returns the relative path to another file", () => {
51-
const testFile = file("/super/path/test.txt");
51+
const testFile = fsFile("/super/path/test.txt");
5252
assert.equal(
53-
testFile.relativePathTo(file("/super/other/other.txt")),
53+
testFile.relativePathTo(fsFile("/super/other/other.txt")),
5454
"../other/other.txt",
5555
);
5656
});
5757
it("returns the relative path to another folder", () => {
5858
assert.equal(
59-
file("/super/path/test.txt").relativePathTo(dir("/super/other")),
59+
fsFile("/super/path/test.txt").relativePathTo(fsDir("/super/other")),
6060
"../other",
6161
);
6262
});
6363
});
6464
describe("relativePathFrom", () => {
6565
it("returns the relative path from another file", () => {
66-
const testFile = file("/super/path/test.txt");
66+
const testFile = fsFile("/super/path/test.txt");
6767
assert.equal(
68-
testFile.relativePathFrom(file("/super/other/other.txt")),
68+
testFile.relativePathFrom(fsFile("/super/other/other.txt")),
6969
"../path/test.txt",
7070
);
7171
});
7272
it("returns the relative path from another folder", () => {
73-
const testFile = file("/super/path/test.txt");
73+
const testFile = fsFile("/super/path/test.txt");
7474
assert.equal(
75-
testFile.relativePathFrom(dir("/super/other")),
75+
testFile.relativePathFrom(fsDir("/super/other")),
7676
"../path/test.txt",
7777
);
7878
});

packages/fs/src/file.lib.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,4 +1183,9 @@ class FsFileWrite<
11831183
* const existingFile = file(file("/path/to/existing.txt"));
11841184
* ```
11851185
*/
1186+
export const fsFile = FsFile.from;
1187+
1188+
/**
1189+
* @deprecated Changed to avoid namespacing conflicts. Use {@link fsFile} instead
1190+
*/
11861191
export const file = FsFile.from;

packages/fs/src/files-array.lib.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { enhance, type Enhanced } from "@synstack/enhance";
22
import { type AnyPath } from "@synstack/path";
33
import { FsDir } from "./dir.lib.ts";
4-
import { FsFile, file } from "./file.lib.ts";
4+
import { FsFile, fsFile } from "./file.lib.ts";
55

66
/**
77
* Interface defining chainable methods for arrays of FsFile instances.
@@ -22,7 +22,7 @@ export interface FsFileArrayMethods {
2222

2323
const filesArrayMethods: FsFileArrayMethods = {
2424
filter(fn) {
25-
return files(this.filter(fn));
25+
return fsFiles(this.filter(fn));
2626
},
2727

2828
filterGlobs(...patterns) {
@@ -57,17 +57,33 @@ export type FsFileArray = Enhanced<
5757
FsFileArrayMethods
5858
>;
5959

60-
export const files = (files: Array<FsFile<any> | AnyPath>): FsFileArray =>
60+
/**
61+
* Create a new FsFileArray instance with the provided files.
62+
* @param files - An array of FsFile or paths
63+
* @returns A new FsFileArray instance
64+
*/
65+
export const fsFiles = (files: Array<FsFile<any> | AnyPath>): FsFileArray =>
6166
enhance(
6267
"files_array",
6368
files.map((f) => {
6469
if (f instanceof FsFile) return f;
65-
return file(f);
70+
return fsFile(f);
6671
}),
6772
filesArrayMethods,
6873
);
6974

70-
export const filesFromDir =
75+
/**
76+
* @deprecated Changed to avoid namespacing conflicts. Use {@link fsFiles} instead
77+
*/
78+
export const files = fsFiles;
79+
80+
/**
81+
* Create a new FsFileArray instance with the provided files relative to the cwd directory.
82+
* @param dir - The cwd directory
83+
* @param files - An array of relative paths from the cwd directory
84+
* @returns A new FsFileArray instance
85+
*/
86+
export const fsFilesFromDir =
7187
(dir: FsDir) =>
7288
(files: Array<FsFile<any> | AnyPath>): FsFileArray =>
7389
enhance(
@@ -78,3 +94,8 @@ export const filesFromDir =
7894
}),
7995
filesArrayMethods,
8096
);
97+
98+
/**
99+
* @deprecated Changed to match naming convention. Use {@link fsFilesFromDir} instead
100+
*/
101+
export const filesFromDir = fsFilesFromDir;

packages/fs/src/fs.index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
export { FsDir, dir } from "./dir.lib.ts";
2-
export { FsFile, file } from "./file.lib.ts";
3-
export { files, filesFromDir, type FsFileArray } from "./files-array.lib.ts";
1+
export { dir, FsDir, fsDir } from "./dir.lib.ts";
2+
export { file, FsFile, fsFile } from "./file.lib.ts";
3+
export {
4+
files,
5+
filesFromDir,
6+
fsFiles,
7+
fsFilesFromDir,
8+
type FsFileArray,
9+
} from "./files-array.lib.ts";

0 commit comments

Comments
 (0)