Skip to content

Commit 032232c

Browse files
chore: update module (#87)
1 parent c123fef commit 032232c

15 files changed

+78
-246
lines changed

.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Common
2+
node_modules
3+
dist
4+
.nuxt
5+
coverage

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ node_modules
22
*.iml
33
.idea
44
*.log*
5-
.nuxt*
5+
.nuxt
66
.vscode
7-
.DS_STORE
7+
.DS_Store
88
coverage
99
dist

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export default {
4242

4343
:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`.
4444

45-
4645
## Options
4746

4847
### Defaults
@@ -105,7 +104,6 @@ export default {
105104

106105
### Override a default value
107106

108-
109107
```js
110108
//nuxt.config.js
111109
export default {
@@ -121,7 +119,6 @@ export default {
121119

122120
### Append a value to the defaults
123121

124-
125122
```js
126123
//nuxt.config.js
127124
export default {
@@ -137,7 +134,6 @@ export default {
137134

138135
### Override a default value
139136

140-
141137
```js
142138
//nuxt.config.js
143139
export default {
@@ -152,6 +148,7 @@ export default {
152148
```
153149

154150
### Use custom extractors
151+
155152
Only one extractor can be applied to each file extention.
156153
If you want to apply a custom extractor to the extensions that the default extractor already covers, you have to override the default extractor. This is only possible with the functional notation.
157154

@@ -218,4 +215,3 @@ Copyright (c) Alexander Lichter
218215

219216
[license-src]: https://img.shields.io/npm/l/nuxt-purgecss.svg
220217
[license-href]: https://npmjs.com/package/nuxt-purgecss
221-

package.json

+18-44
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,36 @@
22
"name": "nuxt-purgecss",
33
"version": "1.0.0",
44
"description": "Drop superfluous CSS! A neat PurgeCSS wrapper for Nuxt.js",
5+
"keywords": [
6+
"nuxtjs",
7+
"nuxt",
8+
"nuxt-module",
9+
"purgecss",
10+
"css"
11+
],
12+
"repository": "Developmint/nuxt-purgecss",
513
"license": "MIT",
614
"contributors": [
715
{
816
"name": "Alexander Lichter <npm@lichter.io>"
917
}
1018
],
1119
"main": "lib/module.js",
12-
"repository": {
13-
"mode": "git",
14-
"url": "git+https://github.com/Developmint/nuxt-purgecss"
15-
},
16-
"bugs": {
17-
"url": "https://github.com/Developmint/nuxt-purgecss/issues"
18-
},
19-
"publishConfig": {
20-
"access": "public"
21-
},
20+
"files": [
21+
"lib"
22+
],
2223
"scripts": {
2324
"dev": "nuxt --config-file test/fixture/configs/postcss/default.js",
2425
"lint": "eslint --ext .js,.vue .",
2526
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
2627
"test": "yarn lint && jest"
2728
},
28-
"files": [
29-
"lib"
30-
],
31-
"keywords": [
32-
"nuxtjs",
33-
"nuxt",
34-
"nuxt-module",
35-
"purgecss",
36-
"css"
37-
],
38-
"engines": {
39-
"node": ">=10.0.0",
40-
"npm": ">=5.0.0"
41-
},
42-
"jest": {
43-
"testEnvironment": "node",
44-
"collectCoverage": true,
45-
"coveragePathIgnorePatterns": [
46-
"/node_modules/",
47-
"/test/fixture"
48-
],
49-
"forceExit": true
50-
},
5129
"dependencies": {
52-
"@fullhuman/postcss-purgecss": "^2.0.5",
53-
"consola": "^1.4.5",
54-
"glob-all": "^3.1.0",
55-
"purgecss": "^2.0.5",
56-
"purgecss-webpack-plugin": "^2.0.5"
30+
"@fullhuman/postcss-purgecss": "^2.1.2",
31+
"consola": "^2.11.3",
32+
"glob-all": "^3.2.1",
33+
"purgecss": "^2.1.2",
34+
"purgecss-webpack-plugin": "^2.1.2"
5735
},
5836
"devDependencies": {
5937
"@commitlint/cli": "latest",
@@ -63,14 +41,10 @@
6341
"eslint": "latest",
6442
"husky": "latest",
6543
"jest": "latest",
66-
"jsdom": "latest",
6744
"nuxt-edge": "latest",
6845
"standard-version": "latest"
6946
},
70-
"husky": {
71-
"hooks": {
72-
"pre-commit": "yarn run lint",
73-
"commit-msg": "yarn run commitlint"
74-
}
47+
"publishConfig": {
48+
"access": "public"
7549
}
7650
}

test/fixture/configs/postcss/custom-options-fn.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
optimization: {

test/fixture/configs/postcss/custom-options.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: [['@@', { mode: 'postcss' }]],
11+
buildModules: [
12+
[require('../../../../'), { mode: 'postcss' }]
13+
],
1214
build: {
1315
quiet: false,
1416
optimization: {

test/fixture/configs/postcss/default.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
optimization: {

test/fixture/configs/postcss/disabled.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
optimization: {

test/fixture/configs/webpack/custom-options-fn.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
extractCSS: true,

test/fixture/configs/webpack/custom-options.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
extractCSS: true,

test/fixture/configs/webpack/default.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
build: {
1315
quiet: false,
1416
extractCSS: true,

test/fixture/configs/webpack/dev.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
render: {
88
resourceHints: false
99
},
10-
modules: ['@@'],
10+
buildModules: [
11+
{ handler: require('../../../../') }
12+
],
1113
build: {
1214
quiet: false,
1315
extractCSS: true,

test/fixture/configs/webpack/disabled.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module.exports = {
88
resourceHints: false
99
},
1010
dev: false,
11-
modules: ['@@'],
11+
buildModules: [
12+
{ handler: require('../../../../') }
13+
],
1214
purgeCSS: {
1315
mode: 'webpack',
1416
enabled: false

test/module.test.js

+12-24
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ const { promisify } = require('util')
44

55
const readFile = promisify(fsReadFile)
66

7-
const consola = require('consola')
87
const { setup } = require('@nuxtjs/module-test-utils')
8+
const logger = require('../lib/logger')
99

10+
logger.mockTypes(() => jest.fn())
1011
jest.setTimeout(60 * 1000)
1112

1213
describe('nuxt-purgecss', () => {
13-
let log
1414
let nuxt
1515

1616
beforeEach(() => {
17-
log = jest.fn()
18-
consola.clear().add({ log })
17+
logger.clear()
1918
})
2019

2120
describe('webpack', () => {
2221
test('extract and purge css by default', async () => {
2322
({ nuxt } = await setup(require('./fixture/configs/webpack/default')))
2423

25-
const consolaMessages = getConsolaMessages(log)
26-
expect(consolaMessages).toContain('Module initialized in webpack mode')
24+
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')
2725

2826
const actualGlobalCSS = await getGlobalCSS()
2927
const expectedGlobalCSS = {
@@ -45,15 +43,13 @@ describe('nuxt-purgecss', () => {
4543
test('don\'t show webpack error message in dev', async () => {
4644
({ nuxt } = await setup(require('./fixture/configs/webpack/dev')))
4745

48-
const consolaMessages = getConsolaMessages(log)
49-
expect(consolaMessages).not.toContain('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
46+
expect(logger.error).not.toContain('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
5047
})
5148

5249
test('globally disable module', async () => {
5350
({ nuxt } = await setup(require('./fixture/configs/webpack/disabled')))
5451

55-
const consolaMessages = getConsolaMessages(log)
56-
expect(consolaMessages).toContain('Module is not enabled')
52+
expect(logger.info).toHaveBeenCalledWith('Module is not enabled')
5753

5854
const globalCSS = await getGlobalCSS()
5955
const expectedGlobalCSS = {
@@ -72,8 +68,7 @@ describe('nuxt-purgecss', () => {
7268
test('define custom options for css lookup (concatenating)', async () => {
7369
({ nuxt } = await setup(require('./fixture/configs/webpack/custom-options')))
7470

75-
const consolaMessages = getConsolaMessages(log)
76-
expect(consolaMessages).toContain('Module initialized in webpack mode')
71+
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')
7772

7873
const globalCSS = await getGlobalCSS()
7974
const expectedGlobalCSS = {
@@ -94,8 +89,7 @@ describe('nuxt-purgecss', () => {
9489
test('define custom function options for css lookup (overriding)', async () => {
9590
({ nuxt } = await setup(require('./fixture/configs/webpack/custom-options-fn')))
9691

97-
const consolaMessages = getConsolaMessages(log)
98-
expect(consolaMessages).toContain('Module initialized in webpack mode')
92+
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')
9993

10094
const globalCSS = await getGlobalCSS()
10195
const expectedGlobalCSS = {
@@ -139,8 +133,7 @@ describe('nuxt-purgecss', () => {
139133
test('purge css by default', async () => {
140134
({ nuxt } = await setup(require('./fixture/configs/postcss/default')))
141135

142-
const consolaMessages = getConsolaMessages(log)
143-
expect(consolaMessages).toContain('Module initialized in postcss mode')
136+
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')
144137

145138
const actualGlobalCSS = await getGlobalCSS('js')
146139
const expectedGlobalCSS = {
@@ -161,8 +154,7 @@ describe('nuxt-purgecss', () => {
161154
test('globally disable module', async () => {
162155
({ nuxt } = await setup(require('./fixture/configs/postcss/disabled')))
163156

164-
const consolaMessages = getConsolaMessages(log)
165-
expect(consolaMessages).toContain('Module is not enabled')
157+
expect(logger.info).toHaveBeenCalledWith('Module is not enabled')
166158

167159
const globalCSS = await getGlobalCSS('js')
168160
const expectedGlobalCSS = {
@@ -181,8 +173,7 @@ describe('nuxt-purgecss', () => {
181173
test('define custom options for css lookup (concatenating)', async () => {
182174
({ nuxt } = await setup(require('./fixture/configs/postcss/custom-options')))
183175

184-
const consolaMessages = getConsolaMessages(log)
185-
expect(consolaMessages).toContain('Module initialized in postcss mode')
176+
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')
186177

187178
const globalCSS = await getGlobalCSS('js')
188179
const expectedGlobalCSS = {
@@ -203,8 +194,7 @@ describe('nuxt-purgecss', () => {
203194
test('define custom function options for css lookup (overriding)', async () => {
204195
({ nuxt } = await setup(require('./fixture/configs/postcss/custom-options-fn')))
205196

206-
const consolaMessages = getConsolaMessages(log)
207-
expect(consolaMessages).toContain('Module initialized in postcss mode')
197+
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')
208198

209199
const globalCSS = await getGlobalCSS('js')
210200
const expectedGlobalCSS = {
@@ -247,5 +237,3 @@ const checkCSS = (expected, actual) => {
247237
}
248238

249239
const getFileContent = path => readFile(path, 'utf-8')
250-
251-
const getConsolaMessages = log => log.mock.calls.map(([res]) => res.message)

0 commit comments

Comments
 (0)