@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.
@@ -1,26 +1,26 @@
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
 
@@ -30,15 +30,15 @@ describe("path functions", () => {
30
30
 
31
31
  //#region norm
32
32
 
33
- describe("pathNorm", () => {
33
+ describe("norm", () => {
34
34
  it("normalizes path and returns NormPath type", () => {
35
- const result: NormPath = pathNorm("./test/../file.txt");
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 = pathNorm(basePath, "sub", "file.txt");
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("pathIsChildPath", () => {
51
+ describe("isChildPath", () => {
52
52
  it("returns true for child path", () => {
53
- const parent = pathNorm("/parent/dir");
54
- const child = pathNorm("/parent/dir/child/file.txt");
55
- 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);
56
56
  });
57
57
 
58
58
  it("returns false for same path", () => {
59
- const parent = pathNorm("/parent/dir");
60
- const child = pathNorm("/parent/dir");
61
- 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);
62
62
  });
63
63
 
64
64
  it("returns false for non-child path", () => {
65
- const parent = pathNorm("/parent/dir");
66
- const child = pathNorm("/other/dir/file.txt");
67
- 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);
68
68
  });
69
69
 
70
70
  it("returns false when only part of parent path matches", () => {
71
- const parent = pathNorm("/parent/dir");
72
- const child = pathNorm("/parent/directory/file.txt");
73
- 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);
74
74
  });
75
75
  });
76
76
 
@@ -78,39 +78,39 @@ describe("path functions", () => {
78
78
 
79
79
  //#region changeFileDirectory
80
80
 
81
- describe("pathChangeFileDirectory", () => {
81
+ describe("changeFileDirectory", () => {
82
82
  it("changes file directory", () => {
83
- const file = pathNorm("/source/sub/file.txt");
84
- const from = pathNorm("/source");
85
- const to = pathNorm("/target");
83
+ const file = norm("/source/sub/file.txt");
84
+ const from = norm("/source");
85
+ const to = norm("/target");
86
86
 
87
- const result = pathChangeFileDirectory(file, from, to);
88
- expect(result).toBe(pathNorm("/target/sub/file.txt"));
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 = pathNorm("/a/b/c/d/file.txt");
93
- const from = pathNorm("/a/b");
94
- 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");
95
95
 
96
- const result = pathChangeFileDirectory(file, from, to);
97
- 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"));
98
98
  });
99
99
 
100
100
  it("throws error when file is not inside fromDirectory", () => {
101
- const file = pathNorm("/other/path/file.txt");
102
- const from = pathNorm("/source");
103
- const to = pathNorm("/target");
101
+ const file = norm("/other/path/file.txt");
102
+ const from = norm("/source");
103
+ const to = norm("/target");
104
104
 
105
- expect(() => pathChangeFileDirectory(file, from, to)).toThrow();
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 = pathNorm("/source");
110
- const from = pathNorm("/source");
111
- const to = pathNorm("/target");
109
+ const file = norm("/source");
110
+ const from = norm("/source");
111
+ const to = norm("/target");
112
112
 
113
- const result = pathChangeFileDirectory(file, from, to);
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("pathBasenameWithoutExt", () => {
122
+ describe("basenameWithoutExt", () => {
123
123
  it("removes single extension (returns basename only)", () => {
124
- const result = pathBasenameWithoutExt("/path/to/file.txt");
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 = pathBasenameWithoutExt("/path/to/file.spec.ts");
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 = pathBasenameWithoutExt("/path/to/file");
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 = pathBasenameWithoutExt("/path/to/.gitignore");
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("pathFilterByTargets", () => {
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 = pathFilterByTargets(files, [], cwd);
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 = pathFilterByTargets(files, ["src"], cwd);
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 = pathFilterByTargets(files, ["src", "tests"], cwd);
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 = pathFilterByTargets(files, ["nonexistent"], cwd);
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 = pathFilterByTargets(files, ["src/a.ts"], cwd);
173
+ const result = filterByTargets(files, ["src/a.ts"], cwd);
174
174
  expect(result).toEqual(["/proj/src/a.ts"]);
175
175
  });
176
176
  });