Skip to content

Commit

Permalink
fix: allow for same filenames to be added (#401)
Browse files Browse the repository at this point in the history
Fixes #400
  • Loading branch information
daKmoR authored and matthieu-foucault committed Mar 7, 2019
1 parent 2e9720a commit 80ce2d8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/karma-webpack.js
Expand Up @@ -37,6 +37,24 @@ function registerExtraWebpackFiles(config, _controller) {
});
}

/**
* Simple hash function by bryc
* https://gist.github.com/iperelivskiy/4110988#gistcomment-2697447
*/
function hash(s) {
let h = 0xdeadbeef;
for (let i = 0; i < s.length; i++) {
h = Math.imul(h ^ s.charCodeAt(i), 2654435761); // eslint-disable-line no-bitwise
}
return (h ^ (h >>> 16)) >>> 0; // eslint-disable-line no-bitwise
}

function getPathKey(filePath, withExtension = false) {
const pathParts = path.parse(filePath);
const key = `${pathParts.name}.${hash(filePath)}`;
return withExtension ? `${key}${pathParts.ext}` : key;
}

function configToWebpackEntries(config) {
const filteredPreprocessorsPatterns = [];
const { preprocessors } = config;
Expand Down Expand Up @@ -65,7 +83,7 @@ function configToWebpackEntries(config) {

const webpackEntries = {};
filteredFiles.forEach((filePath) => {
webpackEntries[path.parse(filePath).name] = filePath;
webpackEntries[getPathKey(filePath)] = filePath;
});

return webpackEntries;
Expand Down Expand Up @@ -97,7 +115,8 @@ function preprocessorFactory(config, emitter) {

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

const bundleContent = controller.bundlesContent[path.parse(file.path).base];
const bundleContent =
controller.bundlesContent[getPathKey(file.path, true)];
done(null, bundleContent);
};
}
Expand Down

0 comments on commit 80ce2d8

Please sign in to comment.