Skip to content

Commit e79741e

Browse files
authored
fix: folder pattern (#36)
Paths computed from node's path modules often do not end in with a slash, this replacement fails if there is no slash... which it was not meant to. (we already know the path points to a directory...
1 parent 19b3699 commit e79741e

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function parseFoldersToGlobs(patterns, extensions) {
4848
/* istanbul ignore else */
4949
if (stats.isDirectory()) {
5050
return pattern.replace(
51-
/[/\\]+?$/u,
51+
/[/\\]*?$/u,
5252
`/**/*.${prefix + extensionsGlob + postfix}`
5353
);
5454
}

test/utils.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { parseFoldersToGlobs } from '../src/utils';
2+
3+
jest.mock('fs', () => {
4+
return {
5+
statSync(pattern) {
6+
return {
7+
isDirectory() {
8+
return pattern.indexOf('/path/') === 0;
9+
},
10+
};
11+
},
12+
};
13+
});
14+
15+
test('parseFoldersToGlobs should return globs for folders', () => {
16+
const withoutSlash = '/path/to/code';
17+
const withSlash = `${withoutSlash}/`;
18+
19+
expect(parseFoldersToGlobs(withoutSlash, 'js')).toMatchInlineSnapshot(`
20+
Array [
21+
"/path/to/code/**/*.js",
22+
]
23+
`);
24+
expect(parseFoldersToGlobs(withSlash, 'js')).toMatchInlineSnapshot(`
25+
Array [
26+
"/path/to/code/**/*.js",
27+
]
28+
`);
29+
30+
expect(
31+
parseFoldersToGlobs(
32+
[withoutSlash, withSlash, '/some/file.js'],
33+
['js', 'cjs', 'mjs']
34+
)
35+
).toMatchInlineSnapshot(`
36+
Array [
37+
"/path/to/code/**/*.{js,cjs,mjs}",
38+
"/path/to/code/**/*.{js,cjs,mjs}",
39+
"/some/file.js",
40+
]
41+
`);
42+
});
43+
44+
test('parseFoldersToGlobs should return unmodified globs for globs (ignoring extensions)', () => {
45+
expect(parseFoldersToGlobs('**.notjs', 'js')).toMatchInlineSnapshot(`
46+
Array [
47+
"**.notjs",
48+
]
49+
`);
50+
});

0 commit comments

Comments
 (0)