postcss-import
Advanced tools
Comparing version 6.1.1 to 6.2.0
@@ -0,1 +1,6 @@ | ||
# 6.2.0 - 2015-07-21 | ||
- Added: `skipDuplicates` option now allows you to **not** skip duplicated files | ||
([#67](https://github.com/postcss/postcss-import/issues/67)) | ||
# 6.1.1 - 2015-07-07 | ||
@@ -2,0 +7,0 @@ |
69
index.js
@@ -12,3 +12,2 @@ /** | ||
var helpers = require("postcss-message-helpers") | ||
var hash = require("string-hash") | ||
var glob = require("glob") | ||
@@ -32,3 +31,3 @@ | ||
"It looks like you didn't end correctly your @import statement. " + | ||
"Some children nodes are attached to it" | ||
"Some children nodes are attached to it." | ||
@@ -45,2 +44,3 @@ /** | ||
path: [], | ||
skipDuplicates: true, | ||
}, options || {}) | ||
@@ -185,2 +185,3 @@ | ||
: options.root | ||
paths.forEach(function(p) { | ||
@@ -292,16 +293,18 @@ p = path.resolve(dir, p) | ||
// skip files already imported at the same scope | ||
if ( | ||
state.importedFiles[resolvedFilename] && | ||
state.importedFiles[resolvedFilename][media] | ||
) { | ||
detach(atRule) | ||
return resolvedPromise | ||
} | ||
if (options.skipDuplicates) { | ||
// skip files already imported at the same scope | ||
if ( | ||
state.importedFiles[resolvedFilename] && | ||
state.importedFiles[resolvedFilename][media] | ||
) { | ||
detach(atRule) | ||
return resolvedPromise | ||
} | ||
// save imported files to skip them next time | ||
if (!state.importedFiles[resolvedFilename]) { | ||
state.importedFiles[resolvedFilename] = {} | ||
// save imported files to skip them next time | ||
if (!state.importedFiles[resolvedFilename]) { | ||
state.importedFiles[resolvedFilename] = {} | ||
} | ||
state.importedFiles[resolvedFilename][media] = true | ||
} | ||
state.importedFiles[resolvedFilename][media] = true | ||
@@ -361,25 +364,25 @@ return readImportedContent( | ||
// skip files wich only contain @import rules | ||
var newFileContent = fileContent.replace(/@import (.*);/, "") | ||
if (newFileContent.trim() !== "") { | ||
var fileContentHash = hash(fileContent) | ||
// skip previous imported files not containing @import rules | ||
if ( | ||
state.hashFiles[fileContent] && | ||
state.hashFiles[fileContent][media] | ||
) { | ||
detach(atRule) | ||
return resolvedPromise | ||
} | ||
// skip files already imported at the same scope and same hash | ||
if ( | ||
state.hashFiles[fileContentHash] && | ||
state.hashFiles[fileContentHash][media] | ||
) { | ||
detach(atRule) | ||
return resolvedPromise | ||
var newStyles = postcss.parse(fileContent, options) | ||
if (options.skipDuplicates) { | ||
var hasImport = newStyles.some(function(child) { | ||
return child.type === "atrule" && child.name === "import" | ||
}) | ||
if (!hasImport) { | ||
// save hash files to skip them next time | ||
if (!state.hashFiles[fileContent]) { | ||
state.hashFiles[fileContent] = {} | ||
} | ||
state.hashFiles[fileContent][media] = true | ||
} | ||
// save hash files to skip them next time | ||
if (!state.hashFiles[fileContentHash]) { | ||
state.hashFiles[fileContentHash] = {} | ||
} | ||
state.hashFiles[fileContentHash][media] = true | ||
} | ||
var newStyles = postcss.parse(fileContent, options) | ||
// recursion: import @import from imported file | ||
@@ -386,0 +389,0 @@ var parsedResult = parseStyles( |
{ | ||
"name": "postcss-import", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"description": "PostCSS plugin to import CSS files", | ||
@@ -8,3 +8,3 @@ "keywords": [ | ||
"postcss", | ||
"postcss-plugins", | ||
"postcss-plugin", | ||
"import", | ||
@@ -32,4 +32,3 @@ "node modules", | ||
"postcss-message-helpers": "^2.0.0", | ||
"resolve": "^1.0.0", | ||
"string-hash": "^1.1.0" | ||
"resolve": "^1.0.0" | ||
}, | ||
@@ -36,0 +35,0 @@ "devDependencies": { |
@@ -13,3 +13,5 @@ # postcss-import [![Travis Build Status](https://travis-ci.org/postcss/postcss-import.svg)](https://travis-ci.org/postcss/postcss-import) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/u8l6u3lr6s5u5tpi?svg=true)](https://ci.appveyor.com/project/MoOx/postcss-import) | ||
which will allow you to adjust assets `url()` (or even inline them) after inlining imported files. | ||
- In order to optimize output, this plugin will only import a file once on a given scope (root, media query...). Tests are made from the path & the content of imported files (using a hash table). | ||
- In order to optimize output, **this plugin will only import a file once** on a given scope (root, media query...). | ||
Tests are made from the path & the content of imported files (using a hash table). | ||
If this behavior is not what you want, look at `skipDuplicates` option | ||
@@ -152,2 +154,12 @@ ## Installation | ||
#### `skipDuplicates` | ||
Type: `Boolean` | ||
Default: `true` | ||
By default, similar files (based on the same content) are being skipped. | ||
It's to optimize output and skip similar files like `normalize.css` for example. | ||
If this behavior is not what you want, just set this option to `false` to | ||
disable it. | ||
#### Example with some options | ||
@@ -154,0 +166,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25577
7
505
194
- Removedstring-hash@^1.1.0
- Removedstring-hash@1.1.3(transitive)