Skip to content

Commit 8b05764

Browse files
committed
added failing test case, dedupe sources to make it pass
1 parent f9a2ea2 commit 8b05764

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ function normalizeManifestPaths (tokensByFile, rootDir) {
7474
return output;
7575
}
7676

77+
function dedupeSources (sources) {
78+
var foundHashes = {}
79+
Object.keys(sources).forEach(function (key) {
80+
var hash = stringHash(sources[key]);
81+
if (foundHashes[hash]) {
82+
delete sources[key];
83+
}
84+
else {
85+
foundHashes[hash] = true;
86+
}
87+
})
88+
}
89+
7790
var cssExt = /\.css$/;
7891

7992
// caches
@@ -182,6 +195,10 @@ module.exports = function (browserify, options) {
182195
bundle.emit('css stream', compiledCssStream);
183196

184197
bundle.on('end', function () {
198+
// under certain conditions (eg. with shared libraries) we can end up with
199+
// multiple occurrences of the same rule, so we need to remove duplicates
200+
dedupeSources(loader.sources)
201+
185202
// Combine the collected sources for a single bundle into a single CSS file
186203
var css = loader.finalSource;
187204

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
._shared__shared {
2+
background: #000;
3+
}
4+
._styles_1__foo {
5+
color: #F00;
6+
}
7+
._styles_2__bar {
8+
background: #BAA;
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('./styles-1.css');
2+
require('./styles-2.css');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.shared {
2+
background: #000;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.foo {
2+
composes: shared from "./shared.css";
3+
color: #F00;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.bar {
2+
composes: shared from "./shared.css";
3+
background: #BAA;
4+
}

0 commit comments

Comments
 (0)