@simplysm/core-node 13.0.75 → 13.0.77
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-watcher.spec.ts +0 -53
- package/tests/utils/fs.spec.ts +123 -173
- package/tests/utils/path.spec.ts +55 -68
- package/tests/worker/sd-worker.spec.ts +0 -15
package/tests/utils/path.spec.ts
CHANGED
|
@@ -1,89 +1,76 @@
|
|
|
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
|
|
|
27
|
-
it("keeps already POSIX-style path as is", () => {
|
|
28
|
-
const result = pathPosix("/usr/local/bin");
|
|
29
|
-
expect(result).toBe("/usr/local/bin");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("handles mixed path separators", () => {
|
|
33
|
-
const result = pathPosix("C:/Users\\test/file.txt");
|
|
34
|
-
expect(result).toBe("C:/Users/test/file.txt");
|
|
35
|
-
});
|
|
36
27
|
});
|
|
37
28
|
|
|
38
29
|
//#endregion
|
|
39
30
|
|
|
40
31
|
//#region norm
|
|
41
32
|
|
|
42
|
-
describe("
|
|
33
|
+
describe("norm", () => {
|
|
43
34
|
it("normalizes path and returns NormPath type", () => {
|
|
44
|
-
const result: NormPath =
|
|
35
|
+
const result: NormPath = norm("./test/../file.txt");
|
|
45
36
|
expect(result).toBe(path.resolve("./test/../file.txt"));
|
|
46
37
|
});
|
|
47
38
|
|
|
48
39
|
it("combines multiple path arguments and normalizes", () => {
|
|
49
40
|
const basePath = path.resolve("/base");
|
|
50
|
-
const result =
|
|
41
|
+
const result = norm(basePath, "sub", "file.txt");
|
|
51
42
|
expect(result).toBe(path.resolve(basePath, "sub", "file.txt"));
|
|
52
43
|
});
|
|
53
44
|
|
|
54
|
-
it("converts relative path to absolute path", () => {
|
|
55
|
-
const result = pathNorm("relative/path");
|
|
56
|
-
expect(path.isAbsolute(result)).toBe(true);
|
|
57
|
-
});
|
|
58
45
|
});
|
|
59
46
|
|
|
60
47
|
//#endregion
|
|
61
48
|
|
|
62
49
|
//#region isChildPath
|
|
63
50
|
|
|
64
|
-
describe("
|
|
51
|
+
describe("isChildPath", () => {
|
|
65
52
|
it("returns true for child path", () => {
|
|
66
|
-
const parent =
|
|
67
|
-
const child =
|
|
68
|
-
expect(
|
|
53
|
+
const parent = norm("/parent/dir");
|
|
54
|
+
const child = norm("/parent/dir/child/file.txt");
|
|
55
|
+
expect(isChildPath(child, parent)).toBe(true);
|
|
69
56
|
});
|
|
70
57
|
|
|
71
58
|
it("returns false for same path", () => {
|
|
72
|
-
const parent =
|
|
73
|
-
const child =
|
|
74
|
-
expect(
|
|
59
|
+
const parent = norm("/parent/dir");
|
|
60
|
+
const child = norm("/parent/dir");
|
|
61
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
75
62
|
});
|
|
76
63
|
|
|
77
64
|
it("returns false for non-child path", () => {
|
|
78
|
-
const parent =
|
|
79
|
-
const child =
|
|
80
|
-
expect(
|
|
65
|
+
const parent = norm("/parent/dir");
|
|
66
|
+
const child = norm("/other/dir/file.txt");
|
|
67
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
81
68
|
});
|
|
82
69
|
|
|
83
70
|
it("returns false when only part of parent path matches", () => {
|
|
84
|
-
const parent =
|
|
85
|
-
const child =
|
|
86
|
-
expect(
|
|
71
|
+
const parent = norm("/parent/dir");
|
|
72
|
+
const child = norm("/parent/directory/file.txt");
|
|
73
|
+
expect(isChildPath(child, parent)).toBe(false);
|
|
87
74
|
});
|
|
88
75
|
});
|
|
89
76
|
|
|
@@ -91,39 +78,39 @@ describe("path functions", () => {
|
|
|
91
78
|
|
|
92
79
|
//#region changeFileDirectory
|
|
93
80
|
|
|
94
|
-
describe("
|
|
81
|
+
describe("changeFileDirectory", () => {
|
|
95
82
|
it("changes file directory", () => {
|
|
96
|
-
const file =
|
|
97
|
-
const from =
|
|
98
|
-
const to =
|
|
83
|
+
const file = norm("/source/sub/file.txt");
|
|
84
|
+
const from = norm("/source");
|
|
85
|
+
const to = norm("/target");
|
|
99
86
|
|
|
100
|
-
const result =
|
|
101
|
-
expect(result).toBe(
|
|
87
|
+
const result = changeFileDirectory(file, from, to);
|
|
88
|
+
expect(result).toBe(norm("/target/sub/file.txt"));
|
|
102
89
|
});
|
|
103
90
|
|
|
104
91
|
it("changes directory in nested path", () => {
|
|
105
|
-
const file =
|
|
106
|
-
const from =
|
|
107
|
-
const to =
|
|
92
|
+
const file = norm("/a/b/c/d/file.txt");
|
|
93
|
+
const from = norm("/a/b");
|
|
94
|
+
const to = norm("/x/y");
|
|
108
95
|
|
|
109
|
-
const result =
|
|
110
|
-
expect(result).toBe(
|
|
96
|
+
const result = changeFileDirectory(file, from, to);
|
|
97
|
+
expect(result).toBe(norm("/x/y/c/d/file.txt"));
|
|
111
98
|
});
|
|
112
99
|
|
|
113
100
|
it("throws error when file is not inside fromDirectory", () => {
|
|
114
|
-
const file =
|
|
115
|
-
const from =
|
|
116
|
-
const to =
|
|
101
|
+
const file = norm("/other/path/file.txt");
|
|
102
|
+
const from = norm("/source");
|
|
103
|
+
const to = norm("/target");
|
|
117
104
|
|
|
118
|
-
expect(() =>
|
|
105
|
+
expect(() => changeFileDirectory(file, from, to)).toThrow();
|
|
119
106
|
});
|
|
120
107
|
|
|
121
108
|
it("returns toDirectory when filePath and fromDirectory are the same", () => {
|
|
122
|
-
const file =
|
|
123
|
-
const from =
|
|
124
|
-
const to =
|
|
109
|
+
const file = norm("/source");
|
|
110
|
+
const from = norm("/source");
|
|
111
|
+
const to = norm("/target");
|
|
125
112
|
|
|
126
|
-
const result =
|
|
113
|
+
const result = changeFileDirectory(file, from, to);
|
|
127
114
|
expect(result).toBe(to);
|
|
128
115
|
});
|
|
129
116
|
});
|
|
@@ -132,24 +119,24 @@ describe("path functions", () => {
|
|
|
132
119
|
|
|
133
120
|
//#region basenameWithoutExt
|
|
134
121
|
|
|
135
|
-
describe("
|
|
122
|
+
describe("basenameWithoutExt", () => {
|
|
136
123
|
it("removes single extension (returns basename only)", () => {
|
|
137
|
-
const result =
|
|
124
|
+
const result = basenameWithoutExt("/path/to/file.txt");
|
|
138
125
|
expect(result).toBe("file");
|
|
139
126
|
});
|
|
140
127
|
|
|
141
128
|
it("removes only last extension in multiple extensions", () => {
|
|
142
|
-
const result =
|
|
129
|
+
const result = basenameWithoutExt("/path/to/file.spec.ts");
|
|
143
130
|
expect(result).toBe("file.spec");
|
|
144
131
|
});
|
|
145
132
|
|
|
146
133
|
it("returns basename for file without extension", () => {
|
|
147
|
-
const result =
|
|
134
|
+
const result = basenameWithoutExt("/path/to/file");
|
|
148
135
|
expect(result).toBe("file");
|
|
149
136
|
});
|
|
150
137
|
|
|
151
138
|
it("returns hidden file (starting with dot) as is", () => {
|
|
152
|
-
const result =
|
|
139
|
+
const result = basenameWithoutExt("/path/to/.gitignore");
|
|
153
140
|
expect(result).toBe(".gitignore");
|
|
154
141
|
});
|
|
155
142
|
});
|
|
@@ -158,32 +145,32 @@ describe("path functions", () => {
|
|
|
158
145
|
|
|
159
146
|
//#region filterByTargets
|
|
160
147
|
|
|
161
|
-
describe("
|
|
148
|
+
describe("filterByTargets", () => {
|
|
162
149
|
const cwd = "/proj";
|
|
163
150
|
const files = ["/proj/src/a.ts", "/proj/src/b.ts", "/proj/tests/c.ts", "/proj/lib/d.ts"];
|
|
164
151
|
|
|
165
152
|
it("returns all files if targets array is empty", () => {
|
|
166
|
-
const result =
|
|
153
|
+
const result = filterByTargets(files, [], cwd);
|
|
167
154
|
expect(result).toEqual(files);
|
|
168
155
|
});
|
|
169
156
|
|
|
170
157
|
it("filters by single target", () => {
|
|
171
|
-
const result =
|
|
158
|
+
const result = filterByTargets(files, ["src"], cwd);
|
|
172
159
|
expect(result).toEqual(["/proj/src/a.ts", "/proj/src/b.ts"]);
|
|
173
160
|
});
|
|
174
161
|
|
|
175
162
|
it("filters by multiple targets", () => {
|
|
176
|
-
const result =
|
|
163
|
+
const result = filterByTargets(files, ["src", "tests"], cwd);
|
|
177
164
|
expect(result).toEqual(["/proj/src/a.ts", "/proj/src/b.ts", "/proj/tests/c.ts"]);
|
|
178
165
|
});
|
|
179
166
|
|
|
180
167
|
it("returns empty array when no matching file is found", () => {
|
|
181
|
-
const result =
|
|
168
|
+
const result = filterByTargets(files, ["nonexistent"], cwd);
|
|
182
169
|
expect(result).toEqual([]);
|
|
183
170
|
});
|
|
184
171
|
|
|
185
172
|
it("filters by exact file path", () => {
|
|
186
|
-
const result =
|
|
173
|
+
const result = filterByTargets(files, ["src/a.ts"], cwd);
|
|
187
174
|
expect(result).toEqual(["/proj/src/a.ts"]);
|
|
188
175
|
});
|
|
189
176
|
});
|
|
@@ -154,21 +154,6 @@ describe("SdWorker", () => {
|
|
|
154
154
|
|
|
155
155
|
//#endregion
|
|
156
156
|
|
|
157
|
-
//#region stdout/stderr
|
|
158
|
-
|
|
159
|
-
describe("stdout/stderr", () => {
|
|
160
|
-
it("forwards worker console.log output to main process", async () => {
|
|
161
|
-
worker = Worker.create<typeof TestWorkerModule>(workerPath);
|
|
162
|
-
|
|
163
|
-
const result = await worker.logMessage("test message");
|
|
164
|
-
|
|
165
|
-
// If method returns normally, stdout piping is working
|
|
166
|
-
expect(result).toBe("logged");
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
|
|
172
157
|
//#region env option
|
|
173
158
|
|
|
174
159
|
describe("env option", () => {
|