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

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(
@@ -143,8 +142,10 @@ class CAWebCSSAuditPlugin {
143
142
  // get all .css files
144
143
  let files = fs.readdirSync( scanDir, { recursive: true } ).filter( f => f.endsWith( '.css' ) ).map( f => path.join( scanDir, f ) );
145
144
 
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`);
145
+ if( this.audit(files, this.config ) ){
146
+ 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`);
147
+ }
148
+
148
149
 
149
150
  });
150
151
  });
@@ -182,7 +183,22 @@ class CAWebCSSAuditPlugin {
182
183
  // outputFolder should not be absolute
183
184
  outputFolder = path.isAbsolute(outputFolder) ? path.join( process.cwd(), outputFolder ) : outputFolder;
184
185
 
185
-
186
+ // if no files are passed, exit
187
+ if( ! files || ! files.length ){
188
+ console.log( '\x1b[31mNo CSS files found to audit.\nAuditor did not execute.\x1b[0m' );
189
+
190
+ // ensure the output folder exists before moving files
191
+ fs.mkdirSync( outputFolder, { recursive: true } );
192
+
193
+ // copy no files sample report
194
+ fs.copyFileSync(
195
+ path.join(currentPath, 'sample', 'no-files.html'),
196
+ path.join(outputFolder, `${filename}.html`),
197
+ )
198
+
199
+ return;
200
+ }
201
+
186
202
  // pass all audits except propertyValues since those take a value there may be multiple
187
203
  let propertyValues = [];
188
204
  let auditArgs = audits.map( (audit) => {
@@ -229,7 +245,6 @@ class CAWebCSSAuditPlugin {
229
245
  if( stderr && stderr.toString() ){
230
246
  console.log( 'CSS Audit Error: ', stderr.toString() );
231
247
  }
232
-
233
248
 
234
249
  if( stdout && stdout.toString() ){
235
250
  // 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.0",
4
4
  "description": "CAWebPublishing Webpack Plugin to run WordPress CSS Audit",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -49,7 +49,7 @@
49
49
  "twig": "^1.17.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@caweb/html-webpack-plugin": "^2.0.2",
52
+ "@caweb/html-webpack-plugin": "^2.1.0",
53
53
  "webpack": "^5.104.1",
54
54
  "webpack-cli": "^6.0.1"
55
55
  }