Skip to content

Commit 80ce2d8

Browse files
daKmoRmatthieu-foucault
authored andcommitted
fix: allow for same filenames to be added (#401)
Fixes #400
1 parent 2e9720a commit 80ce2d8

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Diff for: lib/karma-webpack.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ function registerExtraWebpackFiles(config, _controller) {
3737
});
3838
}
3939

40+
/**
41+
* Simple hash function by bryc
42+
* https://gist.github.com/iperelivskiy/4110988#gistcomment-2697447
43+
*/
44+
function hash(s) {
45+
let h = 0xdeadbeef;
46+
for (let i = 0; i < s.length; i++) {
47+
h = Math.imul(h ^ s.charCodeAt(i), 2654435761); // eslint-disable-line no-bitwise
48+
}
49+
return (h ^ (h >>> 16)) >>> 0; // eslint-disable-line no-bitwise
50+
}
51+
52+
function getPathKey(filePath, withExtension = false) {
53+
const pathParts = path.parse(filePath);
54+
const key = `${pathParts.name}.${hash(filePath)}`;
55+
return withExtension ? `${key}${pathParts.ext}` : key;
56+
}
57+
4058
function configToWebpackEntries(config) {
4159
const filteredPreprocessorsPatterns = [];
4260
const { preprocessors } = config;
@@ -65,7 +83,7 @@ function configToWebpackEntries(config) {
6583

6684
const webpackEntries = {};
6785
filteredFiles.forEach((filePath) => {
68-
webpackEntries[path.parse(filePath).name] = filePath;
86+
webpackEntries[getPathKey(filePath)] = filePath;
6987
});
7088

7189
return webpackEntries;
@@ -97,7 +115,8 @@ function preprocessorFactory(config, emitter) {
97115

98116
file.path = normalize(transformPath(file.path)); // eslint-disable-line no-param-reassign
99117

100-
const bundleContent = controller.bundlesContent[path.parse(file.path).base];
118+
const bundleContent =
119+
controller.bundlesContent[getPathKey(file.path, true)];
101120
done(null, bundleContent);
102121
};
103122
}

0 commit comments

Comments
 (0)