postcss-critical-css
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -31,5 +31,9 @@ 'use strict'; | ||
var clone = root.clone(); | ||
clone.walkDecls(test, function (decl) { | ||
decl.remove(); | ||
}); | ||
if (clone.type === 'decl') { | ||
clone.remove(); | ||
} else { | ||
clone.walkDecls(test, function (decl) { | ||
decl.remove(); | ||
}); | ||
} | ||
return clone; | ||
@@ -92,6 +96,9 @@ } | ||
var clonedRoot = root.clone(); | ||
update.clone().each(function (rule) { | ||
var ruleRoot = rule.root(); | ||
clonedRoot.append(clean(ruleRoot)); | ||
}); | ||
if (update.type === 'rule') { | ||
clonedRoot.append(clean(update.clone())); | ||
} else { | ||
update.clone().each(function (rule) { | ||
clonedRoot.append(clean(rule.root())); | ||
}); | ||
} | ||
return clonedRoot; | ||
@@ -98,0 +105,0 @@ } |
{ | ||
"name": "postcss-critical-css", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Generate critical CSS using PostCSS", | ||
@@ -22,17 +22,17 @@ "main": "index.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.11.4", | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^7.2.3", | ||
"babel-plugin-transform-flow-strip-types": "^6.8.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.20.2", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-es2015": "^6.13.2", | ||
"eslint": "^3.3.1", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-flowtype": "^2.7.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-node": "^4.2.2", | ||
"eslint-plugin-promise": "^3.4.0", | ||
"eslint-plugin-flowtype": "^2.41.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^4.2.3", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"flow-bin": "^0.48.0", | ||
"minimist": "^1.2.0", | ||
"tape": "^4.6.0" | ||
"tape": "^4.8.0" | ||
}, | ||
@@ -46,9 +46,15 @@ "scripts": { | ||
"pretest": "./node_modules/.bin/babel-node test/preTest.js", | ||
"test": "npm run build && npm run test-default && npm run test-no-preserve && npm run test-output-path && npm run test-output-dest && npm run test-no-args && npm run test-no-minify", | ||
"test-no-args": "npm run pretest -- --noArgs && tape test --noArgs --test=default", | ||
"test-no-minify": "npm run pretest -- --minify=false --fixtures-dir=fixtures-no-minify && tape test --fixtures-dir=fixtures-no-minify --test=default", | ||
"test-output-dest": "npm run pretest -- --outputDest='custom.css' --fixtures-dir=fixtures-output-dest && tape test --outputDest='custom.css' --fixtures-dir=fixtures-output-dest --test=default", | ||
"test": | ||
"npm run build && npm run test-default && npm run test-no-preserve && npm run test-output-path && npm run test-output-dest && npm run test-no-args && npm run test-no-minify", | ||
"test-no-args": | ||
"npm run pretest -- --noArgs && tape test --noArgs --test=default", | ||
"test-no-minify": | ||
"npm run pretest -- --minify=false --fixtures-dir=fixtures-no-minify && tape test --fixtures-dir=fixtures-no-minify --test=default,this", | ||
"test-output-dest": | ||
"npm run pretest -- --outputDest='custom.css' --fixtures-dir=fixtures-output-dest && tape test --outputDest='custom.css' --fixtures-dir=fixtures-output-dest --test=default", | ||
"test-default": "npm run pretest && tape test", | ||
"test-no-preserve": "npm run pretest -- --fixtures-dir=fixtures-no-preserve --preserve=false && tape test --fixtures-dir=fixtures-no-preserve --preserve=false", | ||
"test-output-path": "npm run pretest -- --outputPath='test/fixtures-output-path' && tape test --outputPath='test/fixtures-output-path' --test=default" | ||
"test-no-preserve": | ||
"npm run pretest -- --fixtures-dir=fixtures-no-preserve --preserve=false && tape test --fixtures-dir=fixtures-no-preserve --preserve=false", | ||
"test-output-path": | ||
"npm run pretest -- --outputPath='test/fixtures-output-path' && tape test --outputPath='test/fixtures-output-path' --test=default" | ||
}, | ||
@@ -58,4 +64,4 @@ "dependencies": { | ||
"cssnano": "^3.7.4", | ||
"postcss": "^6.0.1" | ||
"postcss": "^6.0.16" | ||
} | ||
} |
@@ -17,5 +17,9 @@ // @flow | ||
const clone = root.clone() | ||
clone.walkDecls(test, (decl: Object) => { | ||
decl.remove() | ||
}) | ||
if (clone.type === 'decl') { | ||
clone.remove() | ||
} else { | ||
clone.walkDecls(test, (decl: Object) => { | ||
decl.remove() | ||
}) | ||
} | ||
return clone | ||
@@ -85,6 +89,9 @@ } | ||
const clonedRoot = root.clone() | ||
update.clone().each((rule: Object) => { | ||
const ruleRoot = rule.root() | ||
clonedRoot.append(clean(ruleRoot)) | ||
}) | ||
if (update.type === 'rule') { | ||
clonedRoot.append(clean(update.clone())) | ||
} else { | ||
update.clone().each((rule: Object) => { | ||
clonedRoot.append(clean(rule.root())) | ||
}) | ||
} | ||
return clonedRoot | ||
@@ -91,0 +98,0 @@ } |
@@ -163,15 +163,16 @@ // @flow | ||
const criticalOutput = getCriticalRules(css, outputDest) | ||
return Object.keys( | ||
criticalOutput | ||
).reduce((init: Object, cur: string): Function => { | ||
const criticalCSS = postcss.root() | ||
const filePath = path.join(outputPath, cur) | ||
criticalOutput[cur].each((rule: Object): Function => | ||
criticalCSS.append(rule.clone()) | ||
) | ||
return postcss(minify ? [cssnano] : []) | ||
.process(criticalCSS) | ||
.then(dryRunOrWriteFile.bind(null, dryRun, filePath)) | ||
.then(clean.bind(null, css, preserve)) | ||
}, {}) | ||
return Object.keys(criticalOutput).reduce( | ||
(init: Object, cur: string): Function => { | ||
const criticalCSS = postcss.root() | ||
const filePath = path.join(outputPath, cur) | ||
criticalOutput[cur].each((rule: Object): Function => | ||
criticalCSS.append(rule.clone()) | ||
) | ||
return postcss(minify ? [cssnano] : []) | ||
.process(criticalCSS) | ||
.then(dryRunOrWriteFile.bind(null, dryRun, filePath)) | ||
.then(clean.bind(null, css, preserve)) | ||
}, | ||
{} | ||
) | ||
} | ||
@@ -178,0 +179,0 @@ } |
#!/usr/bin/env node | ||
const { cyan } = require('chalk') | ||
const fs = require('fs') | ||
@@ -150,3 +149,4 @@ const test = require('tape') | ||
if (key) { | ||
tests[key]() | ||
const keys = key.split(',') | ||
keys.forEach(k => tests[k]()) | ||
} else { | ||
@@ -153,0 +153,0 @@ Object.keys(tests).forEach(key => tests[key]()) |
50507
131
1504
Updatedpostcss@^6.0.16