@automattic/i18n-check-webpack-plugin 1.0.4 → 1.0.7

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.7] - 2022-04-05
9
+ ### Changed
10
+ - Updated package dependencies.
11
+
12
+ ## [1.0.6] - 2022-03-23
13
+ ### Changed
14
+ - Updated package dependencies
15
+
16
+ ## [1.0.5] - 2022-02-16
17
+ ### Added
18
+ - Add timing info to debug output.
19
+
8
20
  ## [1.0.4] - 2022-01-27
9
21
  ### Changed
10
22
  - Updated package dependencies.
@@ -34,6 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
34
46
  ### Added
35
47
  - Initial release.
36
48
 
49
+ [1.0.7]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.6...v1.0.7
50
+ [1.0.6]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.5...v1.0.6
51
+ [1.0.5]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.4...v1.0.5
37
52
  [1.0.4]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.3...v1.0.4
38
53
  [1.0.3]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.2...v1.0.3
39
54
  [1.0.2]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.1...v1.0.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/i18n-check-webpack-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "A Webpack plugin to check that WordPress i18n hasn't been mangled by Webpack optimizations.",
5
5
  "homepage": "https://jetpack.com",
6
6
  "bugs": {
@@ -20,7 +20,7 @@
20
20
  "debug": "^4.3.2"
21
21
  },
22
22
  "devDependencies": {
23
- "@babel/core": "7.16.0",
23
+ "@babel/core": "7.17.8",
24
24
  "jest": "27.3.1",
25
25
  "webpack": "5.65.0"
26
26
  },
@@ -7,6 +7,7 @@ const GettextEntries = require( './GettextEntries.js' );
7
7
  const GettextExtractor = require( './GettextExtractor.js' );
8
8
 
9
9
  const debug = require( 'debug' )( PLUGIN_NAME + ':plugin' );
10
+ const debugtiming = require( 'debug' )( PLUGIN_NAME + ':timing' );
10
11
 
11
12
  const schema = {
12
13
  title: `${ PLUGIN_NAME } plugin options`,
@@ -193,11 +194,14 @@ class I18nCheckPlugin {
193
194
  additionalAssets: true,
194
195
  },
195
196
  assets => {
197
+ const t0 = Date.now();
196
198
  const promises = [];
197
199
  for ( const filename of Object.keys( assets ) ) {
198
200
  promises.push( this.#processAsset( compilation, filename, moduleCache ) );
199
201
  }
200
- return Promise.all( promises );
202
+ return Promise.all( promises ).finally( () => {
203
+ debugtiming( `Processed all assets in ${ Date.now() - t0 }ms` );
204
+ } );
201
205
  }
202
206
  );
203
207
  } );
@@ -211,6 +215,7 @@ class I18nCheckPlugin {
211
215
  * @param {Map} moduleCache - Cache for processed modules.
212
216
  */
213
217
  async #processAsset( compilation, filename, moduleCache ) {
218
+ const t0 = Date.now();
214
219
  const asset = compilation.getAsset( filename );
215
220
 
216
221
  // Detemine if we even need to process this asset. JavaScript assets seem to always
@@ -226,28 +231,36 @@ class I18nCheckPlugin {
226
231
 
227
232
  // Extract strings from the source resources.
228
233
  const sourceEntries = new Set();
234
+ const promises = [];
229
235
  for ( const resource of asset.info.resources ) {
230
236
  if ( ! moduleCache.has( resource ) ) {
231
- const promise = new Promise( resolve => {
232
- this.#extractor
233
- .extractFromFile( resource, {
234
- filename: npath.relative( compilation.compiler.context, resource ),
235
- } )
236
- .then( resolve );
237
+ const promise = this.#extractor.extractFromFile( resource, {
238
+ filename: npath.relative( compilation.compiler.context, resource ),
237
239
  } );
238
240
  moduleCache.set( resource, promise );
239
241
  }
240
- const resourceEntries = await moduleCache.get( resource );
241
- resourceEntries.forEach( e => sourceEntries.add( e ) );
242
+ promises.push(
243
+ moduleCache.get( resource ).then( resourceEntries => {
244
+ resourceEntries.forEach( e => sourceEntries.add( e ) );
245
+ } )
246
+ );
242
247
  }
243
248
 
244
249
  // Extract strings from the asset.
245
250
  const lintLogger = s => {
246
251
  compilation[ this.#reportkey ].push( new Error( s ) );
247
252
  };
248
- const source = asset.source.source();
249
- const babelFile = await this.#extractor.parse( source, { filename, lintLogger } );
250
- const assetEntries = this.#extractor.extractFromAst( babelFile, { filename, lintLogger } );
253
+ let babelFile, assetEntries;
254
+ promises.push(
255
+ ( async () => {
256
+ const source = asset.source.source();
257
+ babelFile = await this.#extractor.parse( source, { filename, lintLogger } );
258
+ assetEntries = this.#extractor.extractFromAst( babelFile, { filename, lintLogger } );
259
+ } )()
260
+ );
261
+
262
+ // Wait for all the extractions to complete.
263
+ await Promise.all( promises );
251
264
 
252
265
  // Analyze. First, collect the missing entries and report any entries with lost translator comments.
253
266
  const missingEntries = new GettextEntries();
@@ -348,6 +361,7 @@ class I18nCheckPlugin {
348
361
  )
349
362
  );
350
363
  }
364
+ debugtiming( `Processed asset ${ filename } in ${ Date.now() - t0 }ms` );
351
365
  }
352
366
  }
353
367