purgecss
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -116,3 +116,3 @@ // import Purgecss from "./../lib/purgecss" | ||
css: ['style.css'], | ||
output: () => { } | ||
output: () => {} | ||
}).toThrow() | ||
@@ -148,3 +148,3 @@ }) | ||
css: ['style.css'], | ||
extractors: () => { } | ||
extractors: () => {} | ||
}).toThrow() | ||
@@ -180,3 +180,3 @@ }) | ||
css: ['style.css'], | ||
whitelist: () => { } | ||
whitelist: () => {} | ||
}).toThrow() | ||
@@ -212,3 +212,3 @@ }) | ||
css: ['style.css'], | ||
stdout: () => { } | ||
stdout: () => {} | ||
}).toThrow() | ||
@@ -244,3 +244,3 @@ }) | ||
css: ['style.css'], | ||
info: () => { } | ||
info: () => {} | ||
}).toThrow() | ||
@@ -276,3 +276,3 @@ }) | ||
css: ['style.css'], | ||
rejected: () => { } | ||
rejected: () => {} | ||
}).toThrow() | ||
@@ -662,2 +662,1 @@ }) | ||
}) | ||
import Purgecss from './../src/index' | ||
const root = './__tests__/test_examples/' | ||
describe('purge methods with files and default extractor', () => { | ||
@@ -328,3 +326,2 @@ it('purge correctly with default extractor', () => { | ||
}) | ||
}) | ||
}) |
{ | ||
"name": "purgecss", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Remove unused css selectors.", | ||
@@ -27,3 +27,10 @@ "main": "./lib/purgecss.js", | ||
}, | ||
"keywords": ["optimization", "unused", "css", "purge", "uncss", "purify"], | ||
"keywords": [ | ||
"optimization", | ||
"unused", | ||
"css", | ||
"purge", | ||
"uncss", | ||
"purify" | ||
], | ||
"author": "Ffloriel", | ||
@@ -37,22 +44,22 @@ "license": "MIT", | ||
"glob": "^7.1.2", | ||
"postcss": "^6.0.4", | ||
"postcss": "^6.0.13", | ||
"postcss-selector-parser": "^2.2.3", | ||
"yargs": "^8.0.2" | ||
"yargs": "^9.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"babel-eslint": "^8.0.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-flow": "^6.23.0", | ||
"codacy-coverage": "^2.0.2", | ||
"eslint": "^4.4.1", | ||
"eslint-plugin-flowtype": "^2.35.0", | ||
"flow-bin": "^0.53.1", | ||
"jest": "^20.0.4", | ||
"prettier": "^1.5.3", | ||
"codacy-coverage": "^2.0.3", | ||
"eslint": "^4.9.0", | ||
"eslint-plugin-flowtype": "^2.39.1", | ||
"flow-bin": "^0.57.3", | ||
"jest": "^21.2.1", | ||
"prettier": "^1.7.4", | ||
"regenerator-runtime": "^0.11.0", | ||
"rollup": "^0.47.6", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"rollup-plugin-commonjs": "^8.1.0", | ||
"rollup-plugin-commonjs": "^8.2.3", | ||
"rollup-plugin-flow": "^1.1.1", | ||
@@ -63,3 +70,3 @@ "rollup-plugin-node-builtins": "^2.1.2", | ||
"rollup-watch": "^4.3.1", | ||
"uglify-es": "^3.0.27" | ||
"uglify-es": "^3.1.3" | ||
}, | ||
@@ -66,0 +73,0 @@ "engines": { |
@@ -10,10 +10,10 @@ import babel from "rollup-plugin-babel" | ||
export default { | ||
entry: "src/index.js", | ||
targets: [ | ||
input: "src/index.js", | ||
output: [ | ||
{ | ||
dest: "lib/purgecss.es.js", | ||
file: "lib/purgecss.es.js", | ||
format: "es" | ||
}, | ||
{ | ||
dest: "lib/purgecss.js", | ||
file: "lib/purgecss.js", | ||
format: "cjs" | ||
@@ -20,0 +20,0 @@ } |
@@ -46,4 +46,3 @@ // @flow | ||
loadConfigFile(configFile: string) { | ||
const pathConfig = | ||
typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile | ||
const pathConfig = typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile | ||
let options | ||
@@ -65,6 +64,4 @@ try { | ||
if (typeof options !== 'object') throw new TypeError(ERROR_OPTIONS_TYPE) | ||
if (!options.content || !options.content.length) | ||
throw new Error(ERROR_MISSING_CONTENT) | ||
if (!options.css || !options.css.length) | ||
throw new Error(ERROR_MISSING_CSS) | ||
if (!options.content || !options.content.length) throw new Error(ERROR_MISSING_CONTENT) | ||
if (!options.css || !options.css.length) throw new Error(ERROR_MISSING_CSS) | ||
if (options.output && typeof options.output !== 'string') | ||
@@ -78,4 +75,3 @@ throw new TypeError(ERROR_OUTPUT_TYPE) | ||
throw new TypeError(ERROR_STDOUT_TYPE) | ||
if (options.info && typeof options.info !== 'boolean') | ||
throw new TypeError(ERROR_INFO_TYPE) | ||
if (options.info && typeof options.info !== 'boolean') throw new TypeError(ERROR_INFO_TYPE) | ||
if (options.rejected && typeof options.rejected !== 'boolean') | ||
@@ -90,12 +86,7 @@ throw new TypeError(ERROR_REJECTED_TYPE) | ||
// Get selectors from content files | ||
let cssClasses = this.extractFileSelector( | ||
this.options.content, | ||
this.options.extractors | ||
) | ||
let cssClasses = this.extractFileSelector(this.options.content, this.options.extractors) | ||
// Get css selectors and remove unused ones | ||
let files = [] | ||
for (let file of this.options.css) { | ||
const cssContent = this.options.stdin | ||
? file | ||
: fs.readFileSync(file, 'utf8') | ||
const cssContent = this.options.stdin ? file : fs.readFileSync(file, 'utf8') | ||
files.push({ | ||
@@ -114,6 +105,3 @@ file, | ||
*/ | ||
extractFileSelector( | ||
files: Array<string>, | ||
extractors?: Array<ExtractorsObj> | ||
): Set<string> { | ||
extractFileSelector(files: Array<string>, extractors?: Array<ExtractorsObj>): Set<string> { | ||
let selectors = new Set() | ||
@@ -130,6 +118,3 @@ for (let globfile of files) { | ||
const extractor = this.getFileExtractor(file, extractors) | ||
selectors = new Set( | ||
...selectors, | ||
this.extractSelectors(content, extractor) | ||
) | ||
selectors = new Set(...selectors, this.extractSelectors(content, extractor)) | ||
} | ||
@@ -199,6 +184,3 @@ } | ||
let keepSelector = this.shouldKeepSelector( | ||
selectors, | ||
selectorsInRule | ||
) | ||
let keepSelector = this.shouldKeepSelector(selectors, selectorsInRule) | ||
if (!keepSelector) { | ||
@@ -237,7 +219,5 @@ selector.remove() | ||
(node.type === 'decl' && !node.value) || | ||
((node.type === 'rule' && !node.selector) || | ||
(node.nodes && !node.nodes.length)) || | ||
((node.type === 'rule' && !node.selector) || (node.nodes && !node.nodes.length)) || | ||
(node.type === 'atrule' && | ||
((!node.nodes && !node.params) || | ||
(!node.params && !node.nodes.length))) | ||
((!node.nodes && !node.params) || (!node.params && !node.nodes.length))) | ||
) { | ||
@@ -254,6 +234,3 @@ return true | ||
*/ | ||
shouldKeepSelector( | ||
selectorsInContent: Set<string>, | ||
selectorsInRule: Array<string> | ||
) { | ||
shouldKeepSelector(selectorsInContent: Set<string>, selectorsInRule: Array<string>) { | ||
for (let selector of selectorsInRule) { | ||
@@ -270,12 +247,9 @@ // legacy | ||
if (keepSelector) return true | ||
if (selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector)) return true | ||
} | ||
// non legacy extractors | ||
else { | ||
if (selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector)) | ||
return true | ||
} else { | ||
// non legacy extractors | ||
// pseudo class | ||
if (selector.startsWith(':')) continue | ||
if ( | ||
!(selectorsInContent.has(selector) || | ||
CSS_WHITELIST.includes(selector)) | ||
) { | ||
if (!(selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector))) { | ||
return false | ||
@@ -282,0 +256,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
439834
61
9018
+ Addedyargs@9.0.1(transitive)
- Removedyargs@8.0.2(transitive)
Updatedpostcss@^6.0.13
Updatedyargs@^9.0.1