Skip to content

Commit b53c8a5

Browse files
committed
fix: escape glob path correctly
1 parent f6e5491 commit b53c8a5

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/steps/getFilesToProcess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { resolve } from "path";
2-
import { sync } from "fast-glob";
2+
import { convertPathToPattern, sync } from "fast-glob";
33

44
import { normalizePath } from "~/utils/path";
55

@@ -10,7 +10,7 @@ import { normalizePath } from "~/utils/path";
1010
* @param extensions A list of extensions to match.
1111
*/
1212
export function getFilesToProcess(outPath: string, extensions: string[]) {
13-
const normalizedOutPath = normalizePath(outPath);
13+
const normalizedOutPath = convertPathToPattern(normalizePath(outPath));
1414

1515
let glob = "*";
1616
if (extensions.length === 1) glob = `*.${extensions[0]}`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

test/steps/getFilesToProcess.test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,47 @@ describe("steps/getFilesToProcess", () => {
99
const cwd = process.cwd();
1010
const testDirectory = join(cwd, "test/fixtures/files");
1111
const files = getFilesToProcess(testDirectory, ["js"]);
12-
expect(files).toHaveLength(1);
12+
expect(files.map((path) => path.replace(cwd, ""))).toMatchInlineSnapshot(`
13+
[
14+
"/test/fixtures/files/file.js",
15+
]
16+
`);
1317
});
1418

1519
it("gets files with multiple extensions correctly", () => {
1620
const cwd = process.cwd();
1721
const testDirectory = join(cwd, "test/fixtures/files");
1822
const files = getFilesToProcess(testDirectory, ["js", "ts"]);
19-
expect(files).toHaveLength(2);
23+
expect(files.map((path) => path.replace(cwd, ""))).toMatchInlineSnapshot(`
24+
[
25+
"/test/fixtures/files/file.js",
26+
"/test/fixtures/files/file.ts",
27+
]
28+
`);
29+
});
30+
31+
it("gets files with paths that have special characters correctly", () => {
32+
const cwd = process.cwd();
33+
const testDirectory = join(cwd, "test/fixtures/(special files*)");
34+
const files = getFilesToProcess(testDirectory, ["js", "ts"]);
35+
expect(files.map((path) => path.replace(cwd, ""))).toMatchInlineSnapshot(`
36+
[
37+
"/test/fixtures/(special files*)/file \\slash.js",
38+
"/test/fixtures/(special files*)/file with (parentheses).js",
39+
"/test/fixtures/(special files*)/file with space.js",
40+
]
41+
`);
2042
});
2143

2244
it("gets nested files correctly", () => {
2345
const cwd = process.cwd();
2446
const testDirectory = join(cwd, "test/fixtures/files");
2547
const files = getFilesToProcess(testDirectory, ["tsx"]);
26-
expect(files).toHaveLength(2);
48+
expect(files.map((path) => path.replace(cwd, ""))).toMatchInlineSnapshot(`
49+
[
50+
"/test/fixtures/files/file.tsx",
51+
"/test/fixtures/files/nested/file.tsx",
52+
]
53+
`);
2754
});
2855
});

0 commit comments

Comments
 (0)