@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.
@@ -1,89 +1,76 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import path from "path";
3
3
  import {
4
- pathPosix,
5
- pathNorm,
6
- pathIsChildPath,
7
- pathChangeFileDirectory,
8
- pathBasenameWithoutExt,
9
- pathFilterByTargets,
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("pathPosix", () => {
16
+ describe("posix", () => {
17
17
  it("converts single path argument to POSIX style", () => {
18
- const result = pathPosix("C:\\Users\\test\\file.txt");
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 = pathPosix("C:\\Users", "test", "file.txt");
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("pathNorm", () => {
33
+ describe("norm", () => {
43
34
  it("normalizes path and returns NormPath type", () => {
44
- const result: NormPath = pathNorm("./test/../file.txt");
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 = pathNorm(basePath, "sub", "file.txt");
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("pathIsChildPath", () => {
51
+ describe("isChildPath", () => {
65
52
  it("returns true for child path", () => {
66
- const parent = pathNorm("/parent/dir");
67
- const child = pathNorm("/parent/dir/child/file.txt");
68
- expect(pathIsChildPath(child, parent)).toBe(true);
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 = pathNorm("/parent/dir");
73
- const child = pathNorm("/parent/dir");
74
- expect(pathIsChildPath(child, parent)).toBe(false);
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 = pathNorm("/parent/dir");
79
- const child = pathNorm("/other/dir/file.txt");
80
- expect(pathIsChildPath(child, parent)).toBe(false);
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 = pathNorm("/parent/dir");
85
- const child = pathNorm("/parent/directory/file.txt");
86
- expect(pathIsChildPath(child, parent)).toBe(false);
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("pathChangeFileDirectory", () => {
81
+ describe("changeFileDirectory", () => {
95
82
  it("changes file directory", () => {
96
- const file = pathNorm("/source/sub/file.txt");
97
- const from = pathNorm("/source");
98
- const to = pathNorm("/target");
83
+ const file = norm("/source/sub/file.txt");
84
+ const from = norm("/source");
85
+ const to = norm("/target");
99
86
 
100
- const result = pathChangeFileDirectory(file, from, to);
101
- expect(result).toBe(pathNorm("/target/sub/file.txt"));
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 = pathNorm("/a/b/c/d/file.txt");
106
- const from = pathNorm("/a/b");
107
- const to = pathNorm("/x/y");
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 = pathChangeFileDirectory(file, from, to);
110
- expect(result).toBe(pathNorm("/x/y/c/d/file.txt"));
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 = pathNorm("/other/path/file.txt");
115
- const from = pathNorm("/source");
116
- const to = pathNorm("/target");
101
+ const file = norm("/other/path/file.txt");
102
+ const from = norm("/source");
103
+ const to = norm("/target");
117
104
 
118
- expect(() => pathChangeFileDirectory(file, from, to)).toThrow();
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 = pathNorm("/source");
123
- const from = pathNorm("/source");
124
- const to = pathNorm("/target");
109
+ const file = norm("/source");
110
+ const from = norm("/source");
111
+ const to = norm("/target");
125
112
 
126
- const result = pathChangeFileDirectory(file, from, to);
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("pathBasenameWithoutExt", () => {
122
+ describe("basenameWithoutExt", () => {
136
123
  it("removes single extension (returns basename only)", () => {
137
- const result = pathBasenameWithoutExt("/path/to/file.txt");
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 = pathBasenameWithoutExt("/path/to/file.spec.ts");
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 = pathBasenameWithoutExt("/path/to/file");
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 = pathBasenameWithoutExt("/path/to/.gitignore");
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("pathFilterByTargets", () => {
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 = pathFilterByTargets(files, [], cwd);
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 = pathFilterByTargets(files, ["src"], cwd);
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 = pathFilterByTargets(files, ["src", "tests"], cwd);
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 = pathFilterByTargets(files, ["nonexistent"], cwd);
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 = pathFilterByTargets(files, ["src/a.ts"], cwd);
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", () => {