Skip to content

Commit fe21d8a

Browse files
authored
fix: Handle [extname] in normalizePath function (#137)
Deal with [extname] being used in user defined filename definitions in their bundler configs.
1 parent eec8353 commit fe21d8a

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.changeset/thirty-cheetahs-teach.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@codecov/bundler-plugin-core": patch
3+
"@codecov/nuxt-plugin": patch
4+
"@codecov/rollup-plugin": patch
5+
"@codecov/sveltekit-plugin": patch
6+
"@codecov/vite-plugin": patch
7+
"@codecov/webpack-plugin": patch
8+
---
9+
10+
Update normalizePath function to handle [hash][extname] case.

packages/bundler-plugin-core/src/utils/__tests__/normalizePath.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ const tests: Test[] = [
6767
},
6868
expected: "test.*.chunk.js",
6969
},
70+
{
71+
name: "handle case where [extname] is used",
72+
input: {
73+
path: "test.12345678.js",
74+
format: "[name].[hash][extname]",
75+
},
76+
expected: "test.*.js",
77+
},
78+
{
79+
name: "input path with no extension present",
80+
input: {
81+
path: "test.12345678",
82+
format: "[name].[hash]",
83+
},
84+
expected: "test.*",
85+
},
7086
];
7187

7288
describe("normalizePath", () => {

packages/bundler-plugin-core/src/utils/normalizePath.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ export const normalizePath = (path: string, format: string): string => {
3434
)})`;
3535

3636
// grab the ending delimiter and create a regex group for it
37-
const endingDelimiter =
37+
let endingDelimiter =
3838
format.at(match.hashIndex + match.hashString.length) ?? "";
39+
40+
// If the ending delimiter is `[extname]` there won't be a
41+
// `.<file-extension>` so we need to replace it with a `.` for the
42+
// handling the actual filename, which will have the `.` in the * string.
43+
44+
if (endingDelimiter === "[") {
45+
endingDelimiter = ".";
46+
}
3947
const endingRegex = `(?<endingDelimiter>${escapeRegex(endingDelimiter)})`;
4048

4149
// create a regex that will match the hash

0 commit comments

Comments
 (0)