@automattic/i18n-check-webpack-plugin 0.1.0 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ 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.0] - 2021-12-22
9
+ ### Added
10
+ - Allow specifying the expected textdomain to be used in the output assets.
11
+
12
+ ### Fixed
13
+ - Fix a unit test that broke when we added i18n-loader to the webpack config.
14
+ - Fixed a documentation error.
15
+ - Fix use in Node 14.
16
+
8
17
  ## 0.1.0 - 2021-12-14
9
18
  ### Added
10
19
  - Initial release.
20
+
21
+ [1.0.0]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v0.1.0...v1.0.0
package/README.md CHANGED
@@ -16,7 +16,7 @@ This goes in the `plugins` section of your Webpack config, e.g.
16
16
  ```js
17
17
  {
18
18
  plugins: [
19
- new I18nLoaderWebpackPlugin(),
19
+ new I18nCheckWebpackPlugin(),
20
20
  ],
21
21
  };
22
22
  ```
@@ -26,6 +26,7 @@ Parameters recognized by the plugin are:
26
26
  - `filter`: Allows for specifying which source modules to process for i18n strings. The default is to process all files with extensions `js`, `jsx`, `ts`, `tsx`, `cjs`, and `mjs`.
27
27
 
28
28
  The value may be a function, which will be passed the file path relative to [Webpack's context] and which should return true if the file should be processed, or a string or RegExp to be compared with the relative file path, or an array of such strings, RegExps, and/or functions.
29
+ - `expectDomain`: Set to the expected text domain that should be used in the output assets. If the assets use some other domain, an error will be generated.
29
30
  - `warnOnly`: Set true to produce warnings rather than errors when issues are found.
30
31
  - `extractorOptions`: Supply options for `GettextExtractor`.
31
32
  - `babelOptions`: Supply options for Babel.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/i18n-check-webpack-plugin",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
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": {
@@ -1,4 +1,4 @@
1
- const assert = require( 'assert/strict' );
1
+ const assert = require( 'assert' ).strict;
2
2
  const GettextEntry = require( './GettextEntry' );
3
3
  const PROJECT_NAME = require( './plugin-name.js' );
4
4
 
@@ -1,4 +1,4 @@
1
- const assert = require( 'assert/strict' );
1
+ const assert = require( 'assert' ).strict;
2
2
 
3
3
  class StringSet extends Set {
4
4
  add( v ) {
@@ -51,6 +51,10 @@ const schema = {
51
51
  description: 'Set true to produce warnings rather than errors.',
52
52
  type: 'boolean',
53
53
  },
54
+ expectDomain: {
55
+ description: 'Set the expected text domain.',
56
+ type: 'string',
57
+ },
54
58
  extractorOptions: {
55
59
  description: 'Options for the extractor. Ignored if `extractor` was specified.',
56
60
  type: 'object',
@@ -89,6 +93,7 @@ class I18nCheckPlugin {
89
93
  #extractor;
90
94
  #filter;
91
95
  #reportkey;
96
+ #expectDomain;
92
97
 
93
98
  constructor( options = {} ) {
94
99
  webpack.validateSchema( schema, options, {
@@ -98,6 +103,7 @@ class I18nCheckPlugin {
98
103
 
99
104
  this.#extractor = new GettextExtractor( options.extractorOptions );
100
105
  this.#reportkey = options.warnOnly ? 'warnings' : 'errors';
106
+ this.#expectDomain = options.expectDomain;
101
107
 
102
108
  if ( options.filter ) {
103
109
  const filters = ( Array.isArray( options.filter ) ? options.filter : [ options.filter ] ).map(
@@ -334,6 +340,13 @@ class I18nCheckPlugin {
334
340
  `${ filename }: Multiple textdomains are used: ${ Array.from( domains, JSON.stringify ).sort().join( ', ' ) }\nYou may want to use @automattic/babel-plugin-replace-textdomain to fix that.`
335
341
  )
336
342
  );
343
+ } else if ( this.#expectDomain && domains.size > 0 && ! domains.has( this.#expectDomain ) ) {
344
+ compilation[ this.#reportkey ].push(
345
+ new Error(
346
+ // prettier-ignore
347
+ `${ filename }: Expected textdomain ${ JSON.stringify( this.#expectDomain ) }, but the asset uses ${ Array.from( domains, JSON.stringify )[ 0 ] } instead.\nYou may want to use @automattic/babel-plugin-replace-textdomain to fix that.`
348
+ )
349
+ );
337
350
  }
338
351
  }
339
352
  }