Skip to content

Commit eea489a

Browse files
committed
update rollup config, new build, prettier
- update rollup config with the new naming - new build with rollup - npm run prettier
1 parent 7d4c0f1 commit eea489a

File tree

6 files changed

+30
-60
lines changed

6 files changed

+30
-60
lines changed

__tests__/purgecss.test.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('initialize purgecss', () => {
113113
new Purgecss({
114114
content: ['index.html'],
115115
css: ['style.css'],
116-
output: () => { }
116+
output: () => {}
117117
}).toThrow()
118118
})
119119
})
@@ -144,7 +144,7 @@ describe('initialize purgecss', () => {
144144
new Purgecss({
145145
content: ['index.html'],
146146
css: ['style.css'],
147-
extractors: () => { }
147+
extractors: () => {}
148148
}).toThrow()
149149
})
150150
})
@@ -175,7 +175,7 @@ describe('initialize purgecss', () => {
175175
new Purgecss({
176176
content: ['index.html'],
177177
css: ['style.css'],
178-
whitelist: () => { }
178+
whitelist: () => {}
179179
}).toThrow()
180180
})
181181
})
@@ -206,7 +206,7 @@ describe('initialize purgecss', () => {
206206
new Purgecss({
207207
content: ['index.html'],
208208
css: ['style.css'],
209-
stdout: () => { }
209+
stdout: () => {}
210210
}).toThrow()
211211
})
212212
})
@@ -237,7 +237,7 @@ describe('initialize purgecss', () => {
237237
new Purgecss({
238238
content: ['index.html'],
239239
css: ['style.css'],
240-
info: () => { }
240+
info: () => {}
241241
}).toThrow()
242242
})
243243
})
@@ -268,7 +268,7 @@ describe('initialize purgecss', () => {
268268
new Purgecss({
269269
content: ['index.html'],
270270
css: ['style.css'],
271-
rejected: () => { }
271+
rejected: () => {}
272272
}).toThrow()
273273
})
274274
})
@@ -653,4 +653,3 @@ describe('purge methods with files and legacy extractor', () => {
653653
})
654654
})
655655
})
656-

__tests__/purgecssDefault.test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Purgecss from './../src/index'
22
const root = './__tests__/test_examples/'
33

4-
5-
64
describe('purge methods with files and default extractor', () => {
75
it('purge correctly with default extractor', () => {
86
const purgeCss = new Purgecss({
@@ -325,5 +323,4 @@ describe('purge methods with files and default extractor', () => {
325323
expect(result.includes('parent2')).toBe(false)
326324
})
327325
})
328-
329-
})
326+
})

lib/purgecss.es.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/purgecss.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import uglify from "rollup-plugin-uglify"
77
import { minify } from "uglify-es"
88

99
export default {
10-
entry: "src/index.js",
11-
targets: [
10+
input: "src/index.js",
11+
output: [
1212
{
13-
dest: "lib/purgecss.es.js",
13+
file: "lib/purgecss.es.js",
1414
format: "es"
1515
},
1616
{
17-
dest: "lib/purgecss.js",
17+
file: "lib/purgecss.js",
1818
format: "cjs"
1919
}
2020
],

src/index.js

+17-43
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class Purgecss {
4343
* @param {string} configFile Path of the config file
4444
*/
4545
loadConfigFile(configFile: string) {
46-
const pathConfig =
47-
typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile
46+
const pathConfig = typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile
4847
let options
4948
try {
5049
const t = path.resolve(process.cwd(), pathConfig)
@@ -61,10 +60,8 @@ class Purgecss {
6160
*/
6261
checkOptions(options: Options) {
6362
if (typeof options !== 'object') throw new TypeError(ERROR_OPTIONS_TYPE)
64-
if (!options.content || !options.content.length)
65-
throw new Error(ERROR_MISSING_CONTENT)
66-
if (!options.css || !options.css.length)
67-
throw new Error(ERROR_MISSING_CSS)
63+
if (!options.content || !options.content.length) throw new Error(ERROR_MISSING_CONTENT)
64+
if (!options.css || !options.css.length) throw new Error(ERROR_MISSING_CSS)
6865
if (options.output && typeof options.output !== 'string')
6966
throw new TypeError(ERROR_OUTPUT_TYPE)
7067
if (options.extractors && !Array.isArray(options.extractors))
@@ -73,8 +70,7 @@ class Purgecss {
7370
throw new TypeError(ERROR_WHITELIST_TYPE)
7471
if (options.stdout && typeof options.stdout !== 'boolean')
7572
throw new TypeError(ERROR_STDOUT_TYPE)
76-
if (options.info && typeof options.info !== 'boolean')
77-
throw new TypeError(ERROR_INFO_TYPE)
73+
if (options.info && typeof options.info !== 'boolean') throw new TypeError(ERROR_INFO_TYPE)
7874
if (options.rejected && typeof options.rejected !== 'boolean')
7975
throw new TypeError(ERROR_REJECTED_TYPE)
8076
}
@@ -84,16 +80,11 @@ class Purgecss {
8480
*/
8581
purge() {
8682
// Get selectors from content files
87-
let cssClasses = this.extractFileSelector(
88-
this.options.content,
89-
this.options.extractors
90-
)
83+
let cssClasses = this.extractFileSelector(this.options.content, this.options.extractors)
9184
// Get css selectors and remove unused ones
9285
let files = []
9386
for (let file of this.options.css) {
94-
const cssContent = this.options.stdin
95-
? file
96-
: fs.readFileSync(file, 'utf8')
87+
const cssContent = this.options.stdin ? file : fs.readFileSync(file, 'utf8')
9788
files.push({
9889
file,
9990
css: this.getSelectorsCss(cssContent, cssClasses)
@@ -107,10 +98,7 @@ class Purgecss {
10798
* @param {array} files Array of files path or glob pattern
10899
* @param {array} extractors Array of extractors
109100
*/
110-
extractFileSelector(
111-
files: Array<string>,
112-
extractors?: Array<ExtractorsObj>
113-
): Set<string> {
101+
extractFileSelector(files: Array<string>, extractors?: Array<ExtractorsObj>): Set<string> {
114102
let selectors = new Set()
115103
for (let globfile of files) {
116104
let filesnames = []
@@ -122,10 +110,7 @@ class Purgecss {
122110
for (let file of filesnames) {
123111
const content = fs.readFileSync(file, 'utf8')
124112
const extractor = this.getFileExtractor(file, extractors)
125-
selectors = new Set(
126-
...selectors,
127-
this.extractSelectors(content, extractor)
128-
)
113+
selectors = new Set(...selectors, this.extractSelectors(content, extractor))
129114
}
130115
}
131116

@@ -190,10 +175,7 @@ class Purgecss {
190175
}
191176
}
192177

193-
let keepSelector = this.shouldKeepSelector(
194-
selectors,
195-
selectorsInRule
196-
)
178+
let keepSelector = this.shouldKeepSelector(selectors, selectorsInRule)
197179
if (!keepSelector) {
198180
selector.remove()
199181
}
@@ -227,11 +209,9 @@ class Purgecss {
227209
isRuleEmpty(node: Object) {
228210
if (
229211
(node.type === 'decl' && !node.value) ||
230-
((node.type === 'rule' && !node.selector) ||
231-
(node.nodes && !node.nodes.length)) ||
212+
((node.type === 'rule' && !node.selector) || (node.nodes && !node.nodes.length)) ||
232213
(node.type === 'atrule' &&
233-
((!node.nodes && !node.params) ||
234-
(!node.params && !node.nodes.length)))
214+
((!node.nodes && !node.params) || (!node.params && !node.nodes.length)))
235215
) {
236216
return true
237217
}
@@ -243,10 +223,7 @@ class Purgecss {
243223
* @param {Set} selectorsInContent Set of css selectors found in the content files
244224
* @param {Array} selectorsInRule Array of selectors
245225
*/
246-
shouldKeepSelector(
247-
selectorsInContent: Set<string>,
248-
selectorsInRule: Array<string>
249-
) {
226+
shouldKeepSelector(selectorsInContent: Set<string>, selectorsInRule: Array<string>) {
250227
for (let selector of selectorsInRule) {
251228
// legacy
252229
if (this.options.legacy) {
@@ -258,16 +235,13 @@ class Purgecss {
258235
keepSelector = true
259236
}
260237
if (keepSelector) return true
261-
if (selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector)) return true
262-
}
263-
// non legacy extractors
264-
else {
238+
if (selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector))
239+
return true
240+
} else {
241+
// non legacy extractors
265242
// pseudo class
266243
if (selector.startsWith(':')) continue
267-
if (
268-
!(selectorsInContent.has(selector) ||
269-
CSS_WHITELIST.includes(selector))
270-
) {
244+
if (!(selectorsInContent.has(selector) || CSS_WHITELIST.includes(selector))) {
271245
return false
272246
}
273247
}

0 commit comments

Comments
 (0)