@caweb/css-audit-webpack-plugin 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,6 @@ export default {
14
14
  audits: [
15
15
  'colors',
16
16
  'important',
17
- 'alphas',
18
17
  'display-none',
19
18
  'selectors',
20
19
  'media-queries',
package/index.js CHANGED
@@ -16,7 +16,6 @@ import { fileURLToPath, URL } from 'url';
16
16
 
17
17
  // default configuration
18
18
  import {default as DefaultConfig} from './css-audit.config.js';
19
- import { get } from 'http';
20
19
 
21
20
  const boldWhite = chalk.bold.white;
22
21
  const boldGreen = chalk.bold.green;
@@ -65,7 +64,8 @@ class CAWebCSSAuditPlugin {
65
64
  }else{
66
65
  devServer.static = [].concat(devServer.static, staticDir );
67
66
  }
68
-
67
+
68
+ // add url to devServer Open
69
69
  // if dev server allows for multiple pages to be opened
70
70
  // add filename.html to open property.
71
71
  if( Array.isArray(devServer.open) ){
@@ -73,7 +73,6 @@ class CAWebCSSAuditPlugin {
73
73
  }else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
74
74
  devServer.open.target.push(`${auditUrl}${this.config.outputFolder}/${this.config.filename}.html`)
75
75
  }
76
-
77
76
  // Wait for configuration preset plugins to apply all configure webpack defaults
78
77
  // compiler.hooks.initialize.tap(pluginName, () => {
79
78
  // compiler.hooks.compilation.tap(
@@ -130,21 +129,14 @@ class CAWebCSSAuditPlugin {
130
129
  compiler.hooks.done.tapAsync(pluginName,
131
130
  (stats, callback) => {
132
131
  console.log('<i> \x1b[32m[webpack-dev-middleware] Running CSS Auditor...\x1b[0m');
133
- /**
134
- * We run the css audit
135
- *
136
- * we scan the output.publicPath if its set and not set to 'auto'
137
- * otherwise we scan the output.path
138
- */
139
- let scanDir = compiler.options.output.publicPath && 'auto' !== compiler.options.output.publicPath ?
140
- compiler.options.output.publicPath :
141
- compiler.options.output.path;
142
-
143
- // get all .css files
144
- let files = fs.readdirSync( scanDir, { recursive: true } ).filter( f => f.endsWith( '.css' ) ).map( f => path.join( scanDir, f ) );
145
-
146
- this.audit(files, this.config );
147
- console.log(`<i> \x1b[32m[webpack-dev-middleware] CSS Auditor Report can be viewed at \x1b[34m ${new URL(`${auditUrl}${staticDir.publicPath}/${this.config.outputFilename}.html`).toString()}\x1b[0m`);
132
+
133
+ // get all .css files in the output directory and subdirectories
134
+ let files = fs.readdirSync( compiler.options.output.path, { recursive: true } ).filter( f => f.endsWith( '.css' ) ).map( f => path.join( compiler.options.output.path, f ) );
135
+
136
+ if( this.audit(files, this.config ) ){
137
+ console.log(`<i> \x1b[32m[webpack-dev-middleware] CSS Auditor completed successfully. Report can be viewed at \x1b[34m ${new URL(`${auditUrl}${staticDir.publicPath}/${this.config.filename}.html`).toString()}\x1b[0m`);
138
+ }
139
+
148
140
 
149
141
  });
150
142
  });
@@ -182,7 +174,22 @@ class CAWebCSSAuditPlugin {
182
174
  // outputFolder should not be absolute
183
175
  outputFolder = path.isAbsolute(outputFolder) ? path.join( process.cwd(), outputFolder ) : outputFolder;
184
176
 
185
-
177
+ // if no files are passed, exit
178
+ if( ! files || ! files.length ){
179
+ console.log( '\x1b[31mNo CSS files found to audit.\nAuditor did not execute.\x1b[0m' );
180
+
181
+ // ensure the output folder exists before moving files
182
+ fs.mkdirSync( outputFolder, { recursive: true } );
183
+
184
+ // copy no files sample report
185
+ fs.copyFileSync(
186
+ path.join(currentPath, 'sample', 'no-files.html'),
187
+ path.join(outputFolder, `${filename}.html`),
188
+ )
189
+
190
+ return;
191
+ }
192
+
186
193
  // pass all audits except propertyValues since those take a value there may be multiple
187
194
  let propertyValues = [];
188
195
  let auditArgs = audits.map( (audit) => {
@@ -229,7 +236,6 @@ class CAWebCSSAuditPlugin {
229
236
  if( stderr && stderr.toString() ){
230
237
  console.log( 'CSS Audit Error: ', stderr.toString() );
231
238
  }
232
-
233
239
 
234
240
  if( stdout && stdout.toString() ){
235
241
  // the css audit tool always outputs to its own public directory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/css-audit-webpack-plugin",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "description": "CAWebPublishing Webpack Plugin to run WordPress CSS Audit",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -40,7 +40,7 @@
40
40
  "test": "echo \"Error: run tests from root\" && exit 0"
41
41
  },
42
42
  "dependencies": {
43
- "@caweb/webpack": "^1.6.3",
43
+ "@caweb/webpack": "^1.6.6",
44
44
  "chalk": "^5.6.2",
45
45
  "cross-spawn": "^7.0.6",
46
46
  "deepmerge": "^4.3.1",
@@ -49,8 +49,8 @@
49
49
  "twig": "^1.17.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@caweb/html-webpack-plugin": "^2.0.2",
53
- "webpack": "^5.104.1",
52
+ "@caweb/html-webpack-plugin": "^2.1.5",
53
+ "webpack": "^5.105.1",
54
54
  "webpack-cli": "^6.0.1"
55
55
  }
56
56
  }