@caweb/webpack 1.2.27 → 1.3.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.
Files changed (83) hide show
  1. package/.github/workflows/config-publish.yml +33 -0
  2. package/.github/workflows/plugins-publish.yml +45 -0
  3. package/.github/workflows/test +29 -0
  4. package/.gitmodules +3 -0
  5. package/README.md +1 -2
  6. package/changelog.txt +137 -0
  7. package/package.json +9 -16
  8. package/plugins/a11y/README.md +19 -0
  9. package/plugins/a11y/aceconfig.js +44 -0
  10. package/plugins/a11y/changelog.txt +31 -0
  11. package/plugins/a11y/index.js +271 -0
  12. package/plugins/a11y/package-lock.json +3303 -0
  13. package/plugins/a11y/package.json +42 -0
  14. package/plugins/css-audit/README.md +20 -0
  15. package/plugins/css-audit/changelog.txt +41 -0
  16. package/plugins/css-audit/css-audit.config.cjs +5 -0
  17. package/plugins/css-audit/default.config.js +19 -0
  18. package/plugins/css-audit/index.js +326 -0
  19. package/plugins/css-audit/package-lock.json +1522 -0
  20. package/plugins/css-audit/package.json +53 -0
  21. package/plugins/css-audit/sample/no-files.html +9 -0
  22. package/plugins/html/README.md +40 -0
  23. package/plugins/html/changelog.txt +134 -0
  24. package/plugins/html/entry/delta.js +20 -0
  25. package/plugins/html/entry/eureka.js +20 -0
  26. package/plugins/html/entry/mono.js +20 -0
  27. package/plugins/html/entry/oceanside.js +20 -0
  28. package/plugins/html/entry/orangecounty.js +20 -0
  29. package/plugins/html/entry/pasorobles.js +20 -0
  30. package/plugins/html/entry/sacramento.js +20 -0
  31. package/plugins/html/entry/santabarbara.js +20 -0
  32. package/plugins/html/entry/santacruz.js +20 -0
  33. package/plugins/html/entry/shasta.js +20 -0
  34. package/plugins/html/entry/sierra.js +20 -0
  35. package/plugins/html/entry/trinity.js +20 -0
  36. package/plugins/html/index.js +96 -0
  37. package/plugins/html/package-lock.json +21977 -0
  38. package/plugins/html/package.json +70 -0
  39. package/plugins/html/sample/blank.html +13 -0
  40. package/plugins/html/sample/components/alerts.html +32 -0
  41. package/plugins/html/sample/components/animations.html +7 -0
  42. package/plugins/html/sample/components/buttons.html +5 -0
  43. package/plugins/html/sample/components/cards.html +73 -0
  44. package/plugins/html/sample/components/lists.html +75 -0
  45. package/plugins/html/sample/components/locations.html +49 -0
  46. package/plugins/html/sample/components/profile-banners.html +48 -0
  47. package/plugins/html/sample/components/sections.html +16 -0
  48. package/plugins/html/sample/components/service-tiles.html +73 -0
  49. package/plugins/html/sample/components/typography.html +42 -0
  50. package/plugins/html/sample/default.html +31 -0
  51. package/plugins/html/sample/favicon.ico +0 -0
  52. package/plugins/html/sample/images/black_puppy.jpg +0 -0
  53. package/plugins/html/sample/images/dolphin_marine_mammals_water.jpg +0 -0
  54. package/plugins/html/sample/images/grayscale_mountain.jpg +0 -0
  55. package/plugins/html/sample/images/silhouette.png +0 -0
  56. package/plugins/html/sample/images/squirrel_tail_bushy_tail.jpg +0 -0
  57. package/plugins/html/sample/index.html +48 -0
  58. package/plugins/html/sample/missing/content.html +4 -0
  59. package/plugins/html/sample/structural/branding.html +15 -0
  60. package/plugins/html/sample/structural/footer.html +47 -0
  61. package/plugins/html/sample/structural/header.html +16 -0
  62. package/plugins/html/sample/structural/mobile-controls.html +5 -0
  63. package/plugins/html/sample/structural/navigation.html +26 -0
  64. package/plugins/html/sample/structural/search.html +15 -0
  65. package/plugins/html/sample/structural/utility-header.html +23 -0
  66. package/plugins/html/scripts/create-entrypoints.js +62 -0
  67. package/plugins/html/scripts/icon.js +60 -0
  68. package/plugins/html/scripts/webpack.test.js +41 -0
  69. package/plugins/html/webpack.config.js +279 -0
  70. package/plugins/jshint/.jshintrc +31 -0
  71. package/plugins/jshint/README.md +26 -0
  72. package/plugins/jshint/changelog.txt +30 -0
  73. package/plugins/jshint/index.js +296 -0
  74. package/plugins/jshint/package-lock.json +1779 -0
  75. package/plugins/jshint/package.json +45 -0
  76. package/plugins/jshint/reporter.cjs +663 -0
  77. package/plugins/jshint/sample/jshint.css +247 -0
  78. package/plugins/jshint/sample/jshint.html +7 -0
  79. package/plugins/jshint/sample/jshint.js +25 -0
  80. package/plugins/jshint/sample/no-files.html +9 -0
  81. package/sample/index.html +364 -0
  82. package/scripts/update-deps.js +38 -0
  83. package/webpack.config.js +0 -54
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import spawn from 'cross-spawn';
7
+ import { getAllFilesSync } from 'get-all-files'
8
+ import EntryDependency from "webpack/lib/dependencies/EntryDependency.js";
9
+ import path from 'path';
10
+ import fs from 'fs';
11
+ import deepmerge from 'deepmerge';
12
+ import chalk from 'chalk';
13
+ import { fileURLToPath, URL } from 'url';
14
+
15
+ const boldWhite = chalk.bold.white;
16
+ const boldGreen = chalk.bold.green;
17
+ const boldBlue = chalk.bold.hex('#03a7fc');
18
+ const currentPath = path.dirname(fileURLToPath(import.meta.url));
19
+
20
+ // JSHint Plugin
21
+ class JSHintPlugin {
22
+ config = {
23
+ outputFilename: 'jshint',
24
+ outputFolder: path.join(currentPath, 'public'),
25
+ }
26
+
27
+ constructor(opts = {}) {
28
+ // outputFolder must be resolved
29
+ if( opts.outputFolder ){
30
+ opts.outputFolder = path.join(process.cwd(), opts.outputFolder);
31
+ }
32
+ this.config = deepmerge(this.config, opts);
33
+ }
34
+
35
+ apply(compiler) {
36
+ const staticDir = {
37
+ directory: this.config.outputFolder,
38
+ watch: true
39
+ }
40
+ let { devServer } = compiler.options;
41
+ let hostUrl = 'localhost' === devServer.host ? `http://${devServer.host}`: devServer.host;
42
+ let hostPort = devServer.port;
43
+
44
+ if( hostPort && 80 !== hostPort )
45
+ {
46
+ hostUrl = `${hostUrl}:${hostPort}`;
47
+ }
48
+
49
+ // if dev server allows for multiple pages to be opened
50
+ // add jshint.html to open property.
51
+ if( Array.isArray(devServer.open) ){
52
+ devServer.open.push(`${hostUrl}/${this.config.outputFilename}.html`)
53
+ }else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
54
+ devServer.open.target.push(`${hostUrl}/${this.config.outputFilename}.html`)
55
+ }
56
+
57
+ // add our static directory
58
+ if( Array.isArray(devServer.static) ){
59
+ devServer.static.push(staticDir)
60
+ }else{
61
+ devServer.static = [].concat(devServer.static, staticDir );
62
+ }
63
+
64
+ // Wait for configuration preset plugins to apply all configure webpack defaults
65
+ compiler.hooks.initialize.tap('JSHint Plugin', () => {
66
+ compiler.hooks.compilation.tap(
67
+ "JSHint Plugin",
68
+ (compilation, { normalModuleFactory }) => {
69
+ compilation.dependencyFactories.set(
70
+ EntryDependency,
71
+ normalModuleFactory
72
+ );
73
+ }
74
+ );
75
+
76
+ const { entry, options, context } = {
77
+ entry: path.join( this.config.outputFolder, 'jshint.update.js'),
78
+ options: {
79
+ name: 'jshint.update'
80
+ },
81
+ context: 'jshint'
82
+ };
83
+
84
+ const dep = new EntryDependency(entry);
85
+ dep.loc = {
86
+ name: options.name
87
+ };
88
+
89
+ if( ! fs.existsSync(path.resolve(this.config.outputFolder))){
90
+ fs.mkdirSync( path.resolve(this.config.outputFolder), {recursive: true} );
91
+ }
92
+
93
+ fs.writeFileSync(
94
+ path.join(this.config.outputFolder, `jshint.update.js`),
95
+ `` // required for hot-update to compile on our page, blank script for now
96
+ );
97
+
98
+
99
+ compiler.hooks.thisCompilation.tap('JSHint Plugin',
100
+ /**
101
+ * Hook into the webpack compilation
102
+ * @param {Compilation} compilation
103
+ */
104
+ (compilation) => {
105
+
106
+ compiler.hooks.make.tapAsync("JSHint Plugin", (compilation, callback) => {
107
+
108
+ compilation.addEntry(
109
+ context,
110
+ dep,
111
+ options,
112
+ err => {
113
+ callback(err);
114
+ });
115
+ });
116
+
117
+ // process assets and run the jshint on appropriate assets.
118
+ compilation.hooks.processAssets.tapAsync(
119
+ {
120
+ name: 'JSHint Plugin',
121
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
122
+ },
123
+ /**
124
+ * Hook into the process assets hook
125
+ * @param {any} _
126
+ * @param {(err?: Error) => void} callback
127
+ */
128
+ (assets, callback) => {
129
+ let files = [];
130
+
131
+ Object.entries(assets).forEach(([pathname, source]) => {
132
+ if( pathname.endsWith('.js') ){
133
+ if( source['_source'] && source['_source']['_children'] ){
134
+ source['_source']['_children'].forEach((s, i) => {
135
+ if(
136
+ 'string' === typeof s && // is a string and
137
+ 0 < s.indexOf('.js') && // has a .js reference and
138
+ 0 > s.indexOf('node_modules') && // not referencing node_modules directory
139
+ 0 > s.indexOf('jshint.update.js') && // not referencing our update javascript
140
+ 0 > s.indexOf('a11y.update.js') && // not referencing our a11y javascript
141
+ 0 > s.indexOf('audit.update.js') // not referencing our css-audit javascript
142
+ ){
143
+ files.push( path.resolve(s.replace(/[\n\s\S\w]*"(.*)"[\n\s\S\w]*/, '$1')) )
144
+ }
145
+ })
146
+ }
147
+ }
148
+ })
149
+
150
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running JSHint...')}`);
151
+
152
+ let result = this.hint(files, this.config);
153
+
154
+ if( result ){
155
+ // we have to inject the jshint.update.js file into the head in order for the webpack-dev-server scripts to load.
156
+ let pageContent = fs.readFileSync(path.join(staticDir.directory, `${this.config.outputFilename}.html`))
157
+
158
+ fs.writeFileSync(
159
+ path.join(staticDir.directory, `${this.config.outputFilename}.html`),
160
+ pageContent.toString().replace('</head>', `<script src="./jshint.update.js"></script>\n</head>`)
161
+ )
162
+ }
163
+
164
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] JSHint can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
165
+
166
+ callback();
167
+ });
168
+
169
+ });
170
+
171
+ });
172
+
173
+ }
174
+
175
+ /**
176
+ * Run JSHint
177
+ *
178
+ * @link https://www.npmjs.com/package/jshint
179
+ *
180
+ * @param {Array} files
181
+ * @param {Object} options
182
+ * @param {boolean} options.debug
183
+ * @param {boolean} options.outputFilename Filename for the scan results.
184
+ * @param {boolean} options.outputFolder Where the scan results should be saved.
185
+ */
186
+ hint(files, {
187
+ debug,
188
+ outputFolder,
189
+ outputFilename
190
+ }){
191
+
192
+ let outputLocation = path.resolve(path.join(outputFolder, `${outputFilename}.html`));
193
+ let filesToBeAuditted = [];
194
+ let filesWithIssues = [];
195
+
196
+ files.forEach( (paths, i) => {
197
+ let resolvePath = path.resolve(paths);
198
+
199
+ try {
200
+ // if given path is a directory
201
+ if( fs.statSync(resolvePath).isDirectory() ){
202
+
203
+ // get all .js files
204
+ getAllFilesSync(resolvePath).toArray().forEach(f => {
205
+ if( f.endsWith('.js') ){
206
+ filesToBeAuditted.push(f)
207
+ }
208
+ })
209
+ // if given path is a file and a .js file
210
+ }else if( fs.statSync(paths).isFile() && paths.endsWith('.js') ){
211
+ filesToBeAuditted.push(paths)
212
+ }
213
+ // invalid path/file
214
+ } catch (error) {
215
+ filesWithIssues.push(paths)
216
+ }
217
+
218
+ });
219
+
220
+ if( ! filesToBeAuditted.length ){
221
+ console.log('No file(s) or directory path(s) were given or default directory was not found.')
222
+ console.log('Hinter did not execute.');
223
+
224
+ fs.copyFileSync(
225
+ path.join(currentPath, 'sample', 'no-files.html'),
226
+ outputLocation,
227
+ )
228
+ return
229
+ }
230
+
231
+ let hintConfigFile = path.join(currentPath, '.jshintrc');
232
+
233
+ /**
234
+ * JSHint does not allow for multiple configs so we have to merge and write 1 file
235
+ */
236
+ if( fs.existsSync(path.join(process.cwd(), '.jshintrc')) ){
237
+ let hintConfig = fs.readFileSync(hintConfigFile);
238
+ let customConfig = fs.readFileSync(path.join(process.cwd(), '.jshintrc'));
239
+
240
+ hintConfig = hintConfig.toString().replace(/[\r\t\n]|\/{2}.*/g, '')
241
+ hintConfig = JSON.parse(hintConfig)
242
+
243
+ customConfig = customConfig.toString().replace(/[\r\t\n]|\/{2}.*/g, '')
244
+ customConfig = JSON.parse(customConfig)
245
+
246
+ hintConfigFile = path.join(currentPath, '.customrc');
247
+ fs.writeFileSync(
248
+ hintConfigFile ,
249
+ JSON.stringify(deepmerge(hintConfig, customConfig), null, 4)
250
+ )
251
+ }
252
+
253
+ // Set the env for our reporter.
254
+ process.env.JSHINT_OUTPUT_DIR = outputFolder;
255
+ process.env.JSHINT_OUTPUT_FILENAME = outputFilename;
256
+
257
+ let hintArgs = [
258
+ '--config',
259
+ hintConfigFile,
260
+ '--reporter',
261
+ path.join(currentPath, 'reporter.cjs')
262
+ ].filter( e => e)
263
+
264
+ let { stdout, stderr } = spawn.sync(
265
+ 'jshint',
266
+ [
267
+ ...filesToBeAuditted,
268
+ ...hintArgs
269
+ ],
270
+ {
271
+ stdio: 'pipe',
272
+ }
273
+ )
274
+
275
+ if( stderr && stderr.toString() ){
276
+ console.log( stderr.toString())
277
+ }
278
+
279
+ if( stdout ){
280
+ if( 'jshint' === process.argv[2] ){
281
+ console.log( stdout.toString() );
282
+ console.log( outputLocation )
283
+ }else{
284
+ return outputLocation;
285
+ }
286
+ }else{
287
+ console.log( 'No output generated.')
288
+ return false;
289
+ }
290
+
291
+ } // end of hint
292
+
293
+ } // end of class
294
+
295
+
296
+ export default JSHintPlugin;