Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-import

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-import - npm Package Compare versions

Comparing version 5.0.3 to 5.1.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 5.1.0 - 2015-02-17
- 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.
Now, we also test create a hash with the content of the file to check if a file with the same content has not already been imported.
This might be usefull if some modules you import are importing the same library from different places (eg: normalize might be as dep for several modules located in different places in `node_modules`)
([#29](https://github.com/postcss/postcss-import/pull/28))
# 5.0.3 - 2015-02-16

@@ -2,0 +9,0 @@

31

index.js

@@ -13,2 +13,3 @@ "use strict";

var helpers = require("postcss-message-helpers")
var hash = require("string-hash")

@@ -65,3 +66,5 @@ /**

parseStyles(styles, options, insertRules, importedFiles, ignoredAtRules)
var hashFiles = {}
parseStyles(styles, options, insertRules, importedFiles, ignoredAtRules, null, hashFiles)
addIgnoredAtRulesOnTop(styles, ignoredAtRules)

@@ -81,3 +84,3 @@

*/
function parseStyles(styles, options, cb, importedFiles, ignoredAtRules, media) {
function parseStyles(styles, options, cb, importedFiles, ignoredAtRules, media, hashFiles) {
var imports = []

@@ -87,3 +90,3 @@ styles.eachAtRule("import", function checkAtRule(atRule) {imports.push(atRule)})

helpers.try(function transformAtImport() {
readAtImport(atRule, options, cb, importedFiles, ignoredAtRules, media)
readAtImport(atRule, options, cb, importedFiles, ignoredAtRules, media, hashFiles)
}, atRule.source)

@@ -128,3 +131,3 @@ })

*/
function readAtImport(atRule, options, cb, importedFiles, ignoredAtRules, media) {
function readAtImport(atRule, options, cb, importedFiles, ignoredAtRules, media, hashFiles) {
// parse-import module parse entire line

@@ -166,3 +169,3 @@ // @todo extract what can be interesting from this one

readImportedContent(atRule, parsedAtImport, clone(options), resolvedFilename, cb, importedFiles, ignoredAtRules)
readImportedContent(atRule, parsedAtImport, clone(options), resolvedFilename, cb, importedFiles, ignoredAtRules, media, hashFiles)
}

@@ -179,3 +182,3 @@

*/
function readImportedContent(atRule, parsedAtImport, options, resolvedFilename, cb, importedFiles, ignoredAtRules) {
function readImportedContent(atRule, parsedAtImport, options, resolvedFilename, cb, importedFiles, ignoredAtRules, media, hashFiles) {
// add directory containing the @imported file in the paths

@@ -198,6 +201,20 @@ // to allow local import from this file

var fileContentHash = hash(fileContent)
// skip files already imported at the same scope and same hash
if (hashFiles[fileContentHash] && hashFiles[fileContentHash][media]) {
detach(atRule)
return
}
// save hash files to skip them next time
if (!hashFiles[fileContentHash]) {
hashFiles[fileContentHash] = {}
}
hashFiles[fileContentHash][media] = true
var newStyles = postcss.parse(fileContent, options)
// recursion: import @import from imported file
parseStyles(newStyles, options, cb, importedFiles, ignoredAtRules, parsedAtImport.media)
parseStyles(newStyles, options, cb, importedFiles, ignoredAtRules, parsedAtImport.media, hashFiles)

@@ -204,0 +221,0 @@ cb(atRule, parsedAtImport, newStyles, resolvedFilename)

{
"name": "postcss-import",
"version": "5.0.3",
"version": "5.1.0",
"description": "PostCSS plugin to import CSS files",

@@ -28,3 +28,4 @@ "keywords": [

"postcss-message-helpers": "^2.0.0",
"resolve": "^1.0.0"
"resolve": "^1.0.0",
"string-hash": "^1.1.0"
},

@@ -31,0 +32,0 @@ "devDependencies": {

@@ -5,6 +5,12 @@ # 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)

This plugin can consume local files or node modules. To resolve path of an `@import` rule, it can look into root directory (by default `process.cwd()`), `node_modules`, `web_modules` or local modules. You can also provide manually multiples paths where to look at.
This plugin can consume local files or node modules.
To resolve path of an `@import` rule, it can look into root directory (by default `process.cwd()`), `node_modules`, `web_modules` or local modules.
You can also provide manually multiples paths where to look at.
_Note: This plugin works great with [postcss-url](https://github.com/postcss/postcss-url) plugin, which will allow you to adjust assets `url()` (or even inline them) after inlining imported files._
**Notes:**
- This plugin works great with [postcss-url](https://github.com/postcss/postcss-url) plugin,
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).
## Installation

@@ -11,0 +17,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc