@caweb/a11y-webpack-plugin 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/index.js +27 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -85,7 +85,7 @@ class A11yPlugin {
85
85
  const { entry, options, context } = {
86
86
  entry: path.join( this.config.outputFolder, 'a11y.update.js'),
87
87
  options: {
88
- name: 'a11y'
88
+ name: 'a11y.update'
89
89
  },
90
90
  context: 'a11y'
91
91
  };
@@ -122,37 +122,36 @@ class A11yPlugin {
122
122
  });
123
123
  });
124
124
 
125
- compiler.hooks.done.tapAsync(
126
- 'IBM Accessibility Plugin',
127
- /**
128
- * Hook into the process assets hook
129
- * @param {any} _
130
- * @param {(err?: Error) => void} callback
131
- */
132
- ({compilation}, callback) => {
133
-
134
- console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running IBM Accessibility scan...')}`);
125
+ });
135
126
 
136
- this.a11yCheck(path.join(process.cwd(), output.publicPath ?? '/' ), this.config );
127
+ compiler.hooks.done.tapAsync(
128
+ 'IBM Accessibility Plugin',
129
+ /**
130
+ * Hook into the process assets hook
131
+ * @param {any} _
132
+ * @param {(err?: Error) => void} callback
133
+ */
134
+ (stats, callback) => {
135
+
136
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running IBM Accessibility scan...')}`);
137
137
 
138
- console.log(`<i> ${boldGreen('[webpack-dev-middleware] IBM Accessibilty Report can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
138
+ let result = this.a11yCheck(path.join(process.cwd(), output.publicPath ?? '/' ), this.config );
139
139
 
140
- callback();
141
- });
140
+ if( result ){
141
+ // we have to inject the a11y.update.js file into the head in order for the webpack-dev-server scripts to load.
142
+ let pageContent = fs.readFileSync(path.join(staticDir.directory, `${this.config.outputFilename}.html`))
143
+
144
+ fs.writeFileSync(
145
+ path.join(staticDir.directory, `${this.config.outputFilename}.html`),
146
+ pageContent.toString().replace('</head>', `<script src="${compiler.options.output.publicPath}/a11y.update.js"></script>\n</head>`)
147
+ )
148
+ }
142
149
 
143
- compiler.hooks.watchClose.tap( 'IBM Accessibility Plugin', () => {
144
- getAllFilesSync(compiler.options.output.path).toArray().forEach(f => {
145
- if(
146
- f.includes('a11y') || // delete any a11y files
147
- f.includes('.hot-update.js') // delete any HMR files
148
- ){
149
- fs.rmSync(f)
150
- }
151
- })
152
- });
153
-
154
- });
150
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] IBM Accessibilty Report can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
155
151
 
152
+ callback();
153
+ });
154
+
156
155
  });
157
156
 
158
157
  }
@@ -228,8 +227,7 @@ class A11yPlugin {
228
227
  resolveBin('accessibility-checker', {executable: 'achecker'}),
229
228
  acheckerArgs,
230
229
  {
231
- stdio: 'pipe',
232
- timeout: 30000 // stop after 30 seconds
230
+ stdio: 'pipe'
233
231
  }
234
232
  )
235
233
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/a11y-webpack-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CAWebPublishing Webpack Plugin to run Accessibility Scans",
5
5
  "type": "module",
6
6
  "main": "index.js",