@automattic/i18n-check-webpack-plugin 0.1.0 → 1.0.3
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/.eslintignore +3 -0
- package/CHANGELOG.md +26 -0
- package/README.md +2 -1
- package/package.json +2 -2
- package/src/GettextEntries.js +1 -1
- package/src/GettextEntry.js +1 -1
- package/src/I18nCheckPlugin.js +13 -0
package/.eslintignore
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,32 @@ 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.3] - 2022-01-25
|
|
9
|
+
### Changed
|
|
10
|
+
- Updated package dependencies.
|
|
11
|
+
|
|
12
|
+
## [1.0.2] - 2022-01-18
|
|
13
|
+
### Changed
|
|
14
|
+
- General: update required node version to v16.13.2
|
|
15
|
+
|
|
16
|
+
## [1.0.1] - 2022-01-04
|
|
17
|
+
### Changed
|
|
18
|
+
- Updated package dependencies
|
|
19
|
+
|
|
20
|
+
## [1.0.0] - 2021-12-22
|
|
21
|
+
### Added
|
|
22
|
+
- Allow specifying the expected textdomain to be used in the output assets.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- Fix a unit test that broke when we added i18n-loader to the webpack config.
|
|
26
|
+
- Fixed a documentation error.
|
|
27
|
+
- Fix use in Node 14.
|
|
28
|
+
|
|
8
29
|
## 0.1.0 - 2021-12-14
|
|
9
30
|
### Added
|
|
10
31
|
- Initial release.
|
|
32
|
+
|
|
33
|
+
[1.0.3]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.2...v1.0.3
|
|
34
|
+
[1.0.2]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.1...v1.0.2
|
|
35
|
+
[1.0.1]: https://github.com/Automattic/i18n-check-webpack-plugin/compare/v1.0.0...v1.0.1
|
|
36
|
+
[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
|
|
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": "
|
|
3
|
+
"version": "1.0.3",
|
|
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": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/core": "7.16.0",
|
|
24
24
|
"jest": "27.3.1",
|
|
25
|
-
"webpack": "5.
|
|
25
|
+
"webpack": "5.65.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@babel/core": "^7.0.0",
|
package/src/GettextEntries.js
CHANGED
package/src/GettextEntry.js
CHANGED
package/src/I18nCheckPlugin.js
CHANGED
|
@@ -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
|
}
|