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 6.0.0 to 6.1.1

17

CHANGELOG.md

@@ -0,1 +1,18 @@

# 6.1.1 - 2015-07-07
- Fixed: Prevent mutability issue, round 2
([#44](https://github.com/postcss/postcss-import/issues/44))
- Added: `plugins` option, to run some postcss plugin on imported files
([#55](https://github.com/postcss/postcss-import/issues/55))
- Added: `bower_components` is now part of the default paths
([#66](https://github.com/postcss/postcss-import/issues/66))
- Added: `async` option allow to use enable PostCSS async API usage.
Note that it's not enabling async fs read yet. It has been added to fix breaking
change introduced by 6.1.0.
# 6.1.0 - 2015-07-07 **YANKED**
_This release was not respecting semver and introduced a major breaking change.
It has been unpublished for now._
# 6.0.0 - 2015-06-17

@@ -2,0 +19,0 @@

186

index.js

@@ -15,2 +15,7 @@ /**

var Promize = global.Promise || require("es6-promise").Promise
var resolvedPromise = new Promize(function(resolvePromise) {
resolvePromise()
})
/**

@@ -22,2 +27,3 @@ * Constants

"node_modules",
"bower_components",
]

@@ -35,15 +41,18 @@

function AtImport(options) {
options = assign({}, options || {})
options.root = options.root || process.cwd()
options.path = (
// convert string to an array of a single element
typeof options.path === "string" ?
[options.path] :
(options.path || []) // fallback to empty array
)
options = assign({
root: process.cwd(),
async: false,
path: [],
}, options || {})
// convert string to an array of a single element
if (typeof options.path === "string") {
options.path = [options.path]
}
return function(styles, result) {
const opts = assign({}, options || {})
// auto add from option if possible
if (
!options.from &&
!opts.from &&
styles &&

@@ -56,41 +65,59 @@ styles.nodes &&

) {
options.from = styles.nodes[0].source.input.file
opts.from = styles.nodes[0].source.input.file
}
// if from available, prepend from directory in the path array
addInputToPath(options)
addInputToPath(opts)
// if we got nothing for the path, just use cwd
if (options.path.length === 0) {
options.path.push(process.cwd())
if (opts.path.length === 0) {
opts.path.push(process.cwd())
}
var importedFiles = {}
if (options.from) {
importedFiles[options.from] = {
var state = {
importedFiles: {},
ignoredAtRules: [],
hashFiles: {},
}
if (opts.from) {
state.importedFiles[opts.from] = {
"": true,
}
}
var ignoredAtRules = []
var hashFiles = {}
parseStyles(
var parsedStylesResult = parseStyles(
result,
styles,
options,
insertRules,
importedFiles,
ignoredAtRules,
opts,
state,
null,
hashFiles
createProcessor(result, options.plugins)
)
addIgnoredAtRulesOnTop(styles, ignoredAtRules)
if (typeof options.onImport === "function") {
options.onImport(Object.keys(importedFiles))
function onParseEnd() {
addIgnoredAtRulesOnTop(styles, state.ignoredAtRules)
if (typeof opts.onImport === "function") {
opts.onImport(Object.keys(state.importedFiles))
}
}
if (options.async) {
return parsedStylesResult.then(onParseEnd)
}
// else (!options.async)
onParseEnd()
}
}
function createProcessor(result, plugins) {
if (plugins) {
if (!Array.isArray(plugins)) {
throw new Error("plugins option must be an array")
}
return postcss(plugins)
}
return postcss()
}
/**

@@ -106,7 +133,5 @@ * lookup for @import rules

options,
cb,
importedFiles,
ignoredAtRules,
state,
media,
hashFiles
processor
) {

@@ -125,16 +150,21 @@ var imports = []

})
imports.forEach(function(atRule) {
helpers.try(function transformAtImport() {
readAtImport(
var importResults = imports.map(function(atRule) {
return helpers.try(function transformAtImport() {
return readAtImport(
result,
atRule,
options,
cb,
importedFiles,
ignoredAtRules,
state,
media,
hashFiles
processor
)
}, atRule.source)
})
if (options.async) {
return Promize.all(importResults)
}
// else (!options.async)
// nothing
}

@@ -191,3 +221,3 @@

* @param {Object} styles
* @param {Array} ignoredAtRules
* @param {Array} state
*/

@@ -229,7 +259,5 @@ function addIgnoredAtRulesOnTop(styles, ignoredAtRules) {

options,
cb,
importedFiles,
ignoredAtRules,
state,
media,
hashFiles
processor
) {

@@ -251,3 +279,3 @@ // parse-import module parse entire line

// save
ignoredAtRules.push([atRule, parsedAtImport])
state.ignoredAtRules.push([atRule, parsedAtImport])

@@ -257,3 +285,3 @@ // detach

return
return resolvedPromise
}

@@ -272,16 +300,16 @@

if (
importedFiles[resolvedFilename] &&
importedFiles[resolvedFilename][media]
state.importedFiles[resolvedFilename] &&
state.importedFiles[resolvedFilename][media]
) {
detach(atRule)
return
return resolvedPromise
}
// save imported files to skip them next time
if (!importedFiles[resolvedFilename]) {
importedFiles[resolvedFilename] = {}
if (!state.importedFiles[resolvedFilename]) {
state.importedFiles[resolvedFilename] = {}
}
importedFiles[resolvedFilename][media] = true
state.importedFiles[resolvedFilename][media] = true
readImportedContent(
return readImportedContent(
result,

@@ -292,7 +320,5 @@ atRule,

resolvedFilename,
cb,
importedFiles,
ignoredAtRules,
state,
media,
hashFiles
processor
)

@@ -308,3 +334,2 @@ }

* @param {String} resolvedFilename
* @param {Function} cb
*/

@@ -317,7 +342,5 @@ function readImportedContent(

resolvedFilename,
cb,
importedFiles,
ignoredAtRules,
state,
media,
hashFiles
processor
) {

@@ -344,3 +367,3 @@ // add directory containing the @imported file in the paths

detach(atRule)
return
return resolvedPromise
}

@@ -354,12 +377,15 @@

// skip files already imported at the same scope and same hash
if (hashFiles[fileContentHash] && hashFiles[fileContentHash][media]) {
if (
state.hashFiles[fileContentHash] &&
state.hashFiles[fileContentHash][media]
) {
detach(atRule)
return
return resolvedPromise
}
// save hash files to skip them next time
if (!hashFiles[fileContentHash]) {
hashFiles[fileContentHash] = {}
if (!state.hashFiles[fileContentHash]) {
state.hashFiles[fileContentHash] = {}
}
hashFiles[fileContentHash][media] = true
state.hashFiles[fileContentHash][media] = true
}

@@ -370,14 +396,26 @@

// recursion: import @import from imported file
parseStyles(
var parsedResult = parseStyles(
result,
newStyles,
options,
cb,
importedFiles,
ignoredAtRules,
state,
parsedAtImport.media,
hashFiles
processor
)
cb(atRule, parsedAtImport, newStyles, resolvedFilename)
if (options.async) {
return parsedResult.then(function() {
return processor.process(newStyles)
.then(function(newResult) {
result.messages = result.messages.concat(newResult.messages)
})
})
.then(function() {
insertRules(atRule, parsedAtImport, newStyles)
})
}
// else (!options.async)
var newResult = processor.process(newStyles)
result.messages = result.messages.concat(newResult.messages)
insertRules(atRule, parsedAtImport, newStyles)
}

@@ -384,0 +422,0 @@

{
"name": "postcss-import",
"version": "6.0.0",
"version": "6.1.1",
"description": "PostCSS plugin to import CSS files",

@@ -26,2 +26,3 @@ "keywords": [

"clone": "^0.1.17",
"es6-promise": "^2.3.0",
"glob": "^5.0.1",

@@ -28,0 +29,0 @@ "object-assign": "^3.0.0",

@@ -5,4 +5,4 @@ # 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.
This plugin can consume local files, node modules or bower packages.
To resolve path of an `@import` rule, it can look into root directory (by default `process.cwd()`), `node_modules`, `web_modules`, `bower_components` or local modules.
You can also provide manually multiples paths where to look at.

@@ -50,5 +50,7 @@

```css
/* can consume `node_modules`, `web_modules` or local modules */
/* can consume `node_modules`, `web_modules`, `bower_components` or local modules */
@import "cssrecipes-defaults"; /* == @import "./node_modules/cssrecipes-defaults/index.css"; */
@import "normalize.css/normalize"; /* == @import "./bower_components/normalize.css/normalize.css"; */
@import "css/foo.css"; /* relative to stylesheets/ according to `from` option above */

@@ -68,2 +70,4 @@

/* ... content of ./bower_components/my-css-on-bower/index.css */
/* ... content of foo.css */

@@ -89,3 +93,3 @@

Define the root where to resolve path (eg: place where `node_modules` is). Should not be used that much.
Define the root where to resolve path (eg: place where `node_modules` and `bower_components` are). Should not be used that much.

@@ -100,2 +104,11 @@ #### `path`

#### `async`
Type: `Boolean`
Default: `false`
Allow to enable PostCSS async API usage. Before enabling this, check that your
runner allow async usage.
_Note: this is not enabling async fs read yet._
#### `transform`

@@ -108,2 +121,9 @@

#### `plugins`
Type: `Array`
Default: `undefined`
An array of plugins to be applied on each imported file.
#### `encoding`

@@ -110,0 +130,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