@simplysm/core-node 13.0.76 → 13.0.78
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/README.md +353 -44
- package/dist/features/fs-watcher.d.ts.map +1 -1
- package/dist/features/fs-watcher.js +2 -2
- package/dist/features/fs-watcher.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/fs.d.ts +30 -30
- package/dist/utils/fs.d.ts.map +1 -1
- package/dist/utils/fs.js +101 -99
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/path.d.ts +19 -19
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +17 -17
- package/dist/utils/path.js.map +1 -1
- package/dist/worker/create-worker.d.ts +1 -1
- package/dist/worker/create-worker.d.ts.map +1 -1
- package/dist/worker/create-worker.js +8 -8
- package/dist/worker/create-worker.js.map +1 -1
- package/dist/worker/types.d.ts +2 -2
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker.js +4 -4
- package/dist/worker/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/features/fs-watcher.ts +2 -2
- package/src/index.ts +2 -2
- package/src/utils/fs.ts +570 -562
- package/src/utils/path.ts +24 -24
- package/src/worker/create-worker.ts +9 -9
- package/src/worker/types.ts +6 -6
- package/src/worker/worker.ts +4 -4
- package/tests/utils/fs.spec.ts +123 -123
- package/tests/utils/path.spec.ts +55 -55
package/tests/utils/path.spec.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
posix,
|
|
5
|
+
norm,
|
|
6
|
+
isChildPath,
|
|
7
|
+
changeFileDirectory,
|
|
8
|
+
basenameWithoutExt,
|
|
9
|
+
filterByTargets,
|
|
10
10
|
type NormPath,
|
|
11
11
|
} from "../../src/utils/path";
|
|
12
12
|
|
|
13
13
|
describe("path functions", () => {
|
|
14
14
|
//#region posix
|
|
15
15
|
|
|
16
|
-
describe("
|
|
16
|
+
describe("posix", () => {
|
|
17
17
|
it("converts single path argument to POSIX style", () => {
|
|
18
|
-
const result =
|
|
18
|
+
const result = posix("C:\\Users\\test\\file.txt");
|
|
19
19
|
expect(result).toBe("C:/Users/test/file.txt");
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("combines multiple path arguments and converts to POSIX style", () => {
|
|
23
|
-
const result =
|
|
23
|
+
const result = posix("C:\\Users", "test", "file.txt");
|
|
24
24
|
expect(result).toBe("C:/Users/test/file.txt");
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -30,15 +30,15 @@ describe("path functions", () => {
|
|
|
30
30
|
|
|
31
31
|
//#region norm
|
|
32
32
|
|
|
33
|
-
describe("
|
|
33
|
+
describe("norm", () => {
|
|
34
34
|
it("normalizes path and returns NormPath type", () => {
|
|
35
|
-
const result: NormPath =
|
|
35
|
+
const result: NormPath = norm("./test/../file.txt");
|
|
36
36
|
expect(result).toBe(path.resolve("./test/../file.txt"));
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it("combines multiple path arguments and normalizes", () => {
|
|
40
40
|
const basePath = path.resolve("/base");
|
|
41
|
-
const result =
|
|
41
|
+
const result = norm(basePath, "sub", "file.txt");
|
|
42
42
|
expect(result).toBe(path.resolve(basePath, "sub", "file.txt"));
|
|
43
43
|
});
|
|
44
44
|
|
|
@@ -48,29 +48,29 @@ describe("path functions", () => {
|
|
|
48
48
|
|
|
49
49
|
//#region isChildPath
|
|
50
50
|
|
|
51
|
-
describe("
|
|
51
|
+
describe("isChildPath", () => {
|
|
52
52
|
it("returns true for child path", () => {
|
|
53
|
-
const parent =
|
|
54
|
-
const child =
|
|
55
|
-
expect(
|
|
53
|
+
const parent = norm("/parent/dir");
|
|
54
|
+
const child = norm("/parent/dir/child/file.txt");
|
|
55
|
+
expect(isChildPath(child, parent)).toBe(true);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("returns false for same path", () => {
|
|
59
|
-
const parent =
|
|
60
|
-
const child =
|
|
61
|
-
expect(
|
|
59
|
+
const parent = norm("/parent/dir");
|
|
60
|
+
const child = norm("/parent/dir");
|
|
61
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it("returns false for non-child path", () => {
|
|
65
|
-
const parent =
|
|
66
|
-
const child =
|
|
67
|
-
expect(
|
|
65
|
+
const parent = norm("/parent/dir");
|
|
66
|
+
const child = norm("/other/dir/file.txt");
|
|
67
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it("returns false when only part of parent path matches", () => {
|
|
71
|
-
const parent =
|
|
72
|
-
const child =
|
|
73
|
-
expect(
|
|
71
|
+
const parent = norm("/parent/dir");
|
|
72
|
+
const child = norm("/parent/directory/file.txt");
|
|
73
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -78,39 +78,39 @@ describe("path functions", () => {
|
|
|
78
78
|
|
|
79
79
|
//#region changeFileDirectory
|
|
80
80
|
|
|
81
|
-
describe("
|
|
81
|
+
describe("changeFileDirectory", () => {
|
|
82
82
|
it("changes file directory", () => {
|
|
83
|
-
const file =
|
|
84
|
-
const from =
|
|
85
|
-
const to =
|
|
83
|
+
const file = norm("/source/sub/file.txt");
|
|
84
|
+
const from = norm("/source");
|
|
85
|
+
const to = norm("/target");
|
|
86
86
|
|
|
87
|
-
const result =
|
|
88
|
-
expect(result).toBe(
|
|
87
|
+
const result = changeFileDirectory(file, from, to);
|
|
88
|
+
expect(result).toBe(norm("/target/sub/file.txt"));
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
it("changes directory in nested path", () => {
|
|
92
|
-
const file =
|
|
93
|
-
const from =
|
|
94
|
-
const to =
|
|
92
|
+
const file = norm("/a/b/c/d/file.txt");
|
|
93
|
+
const from = norm("/a/b");
|
|
94
|
+
const to = norm("/x/y");
|
|
95
95
|
|
|
96
|
-
const result =
|
|
97
|
-
expect(result).toBe(
|
|
96
|
+
const result = changeFileDirectory(file, from, to);
|
|
97
|
+
expect(result).toBe(norm("/x/y/c/d/file.txt"));
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it("throws error when file is not inside fromDirectory", () => {
|
|
101
|
-
const file =
|
|
102
|
-
const from =
|
|
103
|
-
const to =
|
|
101
|
+
const file = norm("/other/path/file.txt");
|
|
102
|
+
const from = norm("/source");
|
|
103
|
+
const to = norm("/target");
|
|
104
104
|
|
|
105
|
-
expect(() =>
|
|
105
|
+
expect(() => changeFileDirectory(file, from, to)).toThrow();
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it("returns toDirectory when filePath and fromDirectory are the same", () => {
|
|
109
|
-
const file =
|
|
110
|
-
const from =
|
|
111
|
-
const to =
|
|
109
|
+
const file = norm("/source");
|
|
110
|
+
const from = norm("/source");
|
|
111
|
+
const to = norm("/target");
|
|
112
112
|
|
|
113
|
-
const result =
|
|
113
|
+
const result = changeFileDirectory(file, from, to);
|
|
114
114
|
expect(result).toBe(to);
|
|
115
115
|
});
|
|
116
116
|
});
|
|
@@ -119,24 +119,24 @@ describe("path functions", () => {
|
|
|
119
119
|
|
|
120
120
|
//#region basenameWithoutExt
|
|
121
121
|
|
|
122
|
-
describe("
|
|
122
|
+
describe("basenameWithoutExt", () => {
|
|
123
123
|
it("removes single extension (returns basename only)", () => {
|
|
124
|
-
const result =
|
|
124
|
+
const result = basenameWithoutExt("/path/to/file.txt");
|
|
125
125
|
expect(result).toBe("file");
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it("removes only last extension in multiple extensions", () => {
|
|
129
|
-
const result =
|
|
129
|
+
const result = basenameWithoutExt("/path/to/file.spec.ts");
|
|
130
130
|
expect(result).toBe("file.spec");
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it("returns basename for file without extension", () => {
|
|
134
|
-
const result =
|
|
134
|
+
const result = basenameWithoutExt("/path/to/file");
|
|
135
135
|
expect(result).toBe("file");
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it("returns hidden file (starting with dot) as is", () => {
|
|
139
|
-
const result =
|
|
139
|
+
const result = basenameWithoutExt("/path/to/.gitignore");
|
|
140
140
|
expect(result).toBe(".gitignore");
|
|
141
141
|
});
|
|
142
142
|
});
|
|
@@ -145,32 +145,32 @@ describe("path functions", () => {
|
|
|
145
145
|
|
|
146
146
|
//#region filterByTargets
|
|
147
147
|
|
|
148
|
-
describe("
|
|
148
|
+
describe("filterByTargets", () => {
|
|
149
149
|
const cwd = "/proj";
|
|
150
150
|
const files = ["/proj/src/a.ts", "/proj/src/b.ts", "/proj/tests/c.ts", "/proj/lib/d.ts"];
|
|
151
151
|
|
|
152
152
|
it("returns all files if targets array is empty", () => {
|
|
153
|
-
const result =
|
|
153
|
+
const result = filterByTargets(files, [], cwd);
|
|
154
154
|
expect(result).toEqual(files);
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
it("filters by single target", () => {
|
|
158
|
-
const result =
|
|
158
|
+
const result = filterByTargets(files, ["src"], cwd);
|
|
159
159
|
expect(result).toEqual(["/proj/src/a.ts", "/proj/src/b.ts"]);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
it("filters by multiple targets", () => {
|
|
163
|
-
const result =
|
|
163
|
+
const result = filterByTargets(files, ["src", "tests"], cwd);
|
|
164
164
|
expect(result).toEqual(["/proj/src/a.ts", "/proj/src/b.ts", "/proj/tests/c.ts"]);
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
it("returns empty array when no matching file is found", () => {
|
|
168
|
-
const result =
|
|
168
|
+
const result = filterByTargets(files, ["nonexistent"], cwd);
|
|
169
169
|
expect(result).toEqual([]);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it("filters by exact file path", () => {
|
|
173
|
-
const result =
|
|
173
|
+
const result = filterByTargets(files, ["src/a.ts"], cwd);
|
|
174
174
|
expect(result).toEqual(["/proj/src/a.ts"]);
|
|
175
175
|
});
|
|
176
176
|
});
|