@tkeron/tools 0.2.1 → 0.2.2
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/package.json +1 -1
- package/src/getPaths.test.ts +26 -5
- package/src/getPaths.ts +3 -1
package/package.json
CHANGED
package/src/getPaths.test.ts
CHANGED
|
@@ -46,6 +46,10 @@ describe("getPaths Tests", () => {
|
|
|
46
46
|
writeFileSync(join(testDir, "node_modules", "package.json"), "content");
|
|
47
47
|
mkdirSync(join(testDir, "build"), { recursive: true });
|
|
48
48
|
writeFileSync(join(testDir, "build", "output.js"), "content");
|
|
49
|
+
|
|
50
|
+
for (let i = 123; i <= 129; i++) {
|
|
51
|
+
mkdirSync(join(testDir, `build`, `qwerty_${i}.com`), { recursive: true });
|
|
52
|
+
}
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
afterAll(() => {
|
|
@@ -245,25 +249,24 @@ describe("getPaths Tests", () => {
|
|
|
245
249
|
expect(files.some(path => path === ".env")).toBe(true);
|
|
246
250
|
expect(files.some(path => path === "src/index.ts")).toBe(true);
|
|
247
251
|
expect(files.some(path => path === "src/components/Button.tsx")).toBe(true);
|
|
248
|
-
|
|
252
|
+
|
|
249
253
|
const nestedFiles = files.filter(path => path.includes("/"));
|
|
250
254
|
expect(nestedFiles.length).toBeGreaterThan(0);
|
|
251
255
|
|
|
252
256
|
expect(dirs.some(path => path === "src")).toBe(true);
|
|
253
257
|
expect(dirs.some(path => path === ".git")).toBe(true);
|
|
254
|
-
|
|
258
|
+
|
|
255
259
|
expect(dirs.length).toBeGreaterThan(0);
|
|
256
260
|
});
|
|
257
261
|
|
|
258
262
|
test("absolute parameter should work consistently across all function variants", () => {
|
|
259
263
|
const pattern = "src/**";
|
|
260
264
|
|
|
261
|
-
|
|
265
|
+
|
|
262
266
|
const absoluteFiles = getFilePaths(testDir, pattern, true);
|
|
263
267
|
const absoluteDirs = getDirectoryPaths(testDir, pattern, true);
|
|
264
268
|
const absoluteAll = getPaths(testDir, pattern, "yes", true);
|
|
265
269
|
|
|
266
|
-
// Test with absolute = false
|
|
267
270
|
const relativeFiles = getFilePaths(testDir, pattern, false);
|
|
268
271
|
const relativeDirs = getDirectoryPaths(testDir, pattern, false);
|
|
269
272
|
const relativeAll = getPaths(testDir, pattern, "yes", false);
|
|
@@ -440,7 +443,6 @@ describe("getPaths Tests", () => {
|
|
|
440
443
|
expect(files.some(path => path.includes("UPPERCASE.TXT"))).toBe(true);
|
|
441
444
|
expect(files.some(path => path.includes("file1.txt"))).toBe(true);
|
|
442
445
|
|
|
443
|
-
// Should be case sensitive
|
|
444
446
|
const upper = getFilePaths(testDir, "*UPPER*");
|
|
445
447
|
const lower = getFilePaths(testDir, "*upper*");
|
|
446
448
|
expect(upper.length).toBeGreaterThan(0);
|
|
@@ -483,9 +485,28 @@ describe("getPaths Tests", () => {
|
|
|
483
485
|
expect(dir).toMatch(/^[\/\\]|^[a-zA-Z]:[\/\\]/);
|
|
484
486
|
});
|
|
485
487
|
});
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
test("should return the same number of paths with absolute false or true", () => {
|
|
492
|
+
|
|
493
|
+
const absolutes = getDirectoryPaths(testDir, "build/qwerty_*", true);
|
|
494
|
+
const notAbsolutes = getDirectoryPaths(testDir, "build/qwerty_*", false);
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
console.log(JSON.stringify({ absolutes, notAbsolutes }, null, 2));
|
|
498
|
+
|
|
499
|
+
expect(absolutes).toHaveLength(7);
|
|
500
|
+
expect(notAbsolutes).toHaveLength(7);
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
});
|
|
504
|
+
|
|
486
505
|
});
|
|
487
506
|
|
|
488
507
|
|
|
508
|
+
|
|
509
|
+
|
|
489
510
|
})
|
|
490
511
|
|
|
491
512
|
|
package/src/getPaths.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Glob } from "bun";
|
|
2
2
|
import { statSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Gets file paths, directory paths, or both based on the specified parameters
|
|
@@ -94,7 +95,8 @@ export const getDirectoryPaths = (path: string, pattern: string = "**/*", absolu
|
|
|
94
95
|
|
|
95
96
|
const directories = allItems.filter(item => {
|
|
96
97
|
try {
|
|
97
|
-
|
|
98
|
+
const fullPath = absolute ? item : join(path, item);
|
|
99
|
+
return statSync(fullPath).isDirectory();
|
|
98
100
|
} catch {
|
|
99
101
|
return false;
|
|
100
102
|
}
|