Skip to content

Commit 3ef3fb9

Browse files
committed
Merge pull request postcss#33 from postcss/hash-proxy
Files which only contain same @import rules were skip
2 parents 9fefc4f + ecf8ce3 commit 3ef3fb9

File tree

9 files changed

+31
-13
lines changed

9 files changed

+31
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 5.1.1 - 2015-04-10
2+
3+
- fixed: regression of 5.1.0: files which only contain same @import rules were skip ([#31](https://github.com/postcss/postcss-import/issues/31))
4+
15
# 5.1.0 - 2015-03-27
26

37
- Added: files with the same content will only be imported once. Previously, only the full path was used to determine if a file has already been imported in a given scope.

index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,23 @@ function readImportedContent(atRule, parsedAtImport, options, resolvedFilename,
191191
return
192192
}
193193

194-
var fileContentHash = hash(fileContent)
195-
196-
// skip files already imported at the same scope and same hash
197-
if (hashFiles[fileContentHash] && hashFiles[fileContentHash][media]) {
198-
detach(atRule)
199-
return
200-
}
194+
// skip files wich only contain @import rules
195+
var newFileContent = fileContent.replace(/@import (.*);/,"")
196+
if (newFileContent.trim() !== "") {
197+
var fileContentHash = hash(fileContent)
198+
199+
// skip files already imported at the same scope and same hash
200+
if (hashFiles[fileContentHash] && hashFiles[fileContentHash][media]) {
201+
detach(atRule)
202+
return
203+
}
201204

202-
// save hash files to skip them next time
203-
if (!hashFiles[fileContentHash]) {
204-
hashFiles[fileContentHash] = {}
205+
// save hash files to skip them next time
206+
if (!hashFiles[fileContentHash]) {
207+
hashFiles[fileContentHash] = {}
208+
}
209+
hashFiles[fileContentHash][media] = true
205210
}
206-
hashFiles[fileContentHash][media] = true
207211

208212
var newStyles = postcss.parse(fileContent, options)
209213

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-import",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "PostCSS plugin to import CSS files",
55
"keywords": [
66
"css",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
proxy {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "../proxy-file.css";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "../proxy-file.css";

test/fixtures/no-duplicate.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
@import "foo.css" screen;
66
@import "foo-duplicate2" screen;
77

8+
@import "proxy-file/index.css";
9+
@import "proxy-file/sub-directory/index.css";
10+
811
content{}

test/fixtures/no-duplicate.expected.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ foo{}
44
foo{}
55
}
66

7-
content{}
7+
proxy {}
8+
import {}
9+
10+
content{}

0 commit comments

Comments
 (0)