Introduce codemod for changing i18n text domain
This commit is contained in:
parent
989f50daa3
commit
6f23a5ae68
107
pnpm-lock.yaml
107
pnpm-lock.yaml
|
@ -1597,6 +1597,7 @@ importers:
|
|||
'@types/node': ^16.9.4
|
||||
eslint: ^7.32.0
|
||||
globby: ^11
|
||||
jscodeshift: ^0.13.1
|
||||
oclif: ^2
|
||||
shx: ^0.3.3
|
||||
ts-node: ^10.2.1
|
||||
|
@ -1611,6 +1612,7 @@ importers:
|
|||
'@types/node': 16.10.3
|
||||
eslint: 7.32.0
|
||||
globby: 11.0.4
|
||||
jscodeshift: 0.13.1
|
||||
oclif: 2.4.5
|
||||
shx: 0.3.4
|
||||
ts-node: 10.5.0_e0d88945dfc7787883e9c330c9196a96
|
||||
|
@ -2469,7 +2471,7 @@ packages:
|
|||
resolution: {integrity: sha512-+il1gTy0oHwUsBQZyJvukbB4vPMdcYBrFHa0Uc4AizLxbq6BOYC51Rv4tWocX9BLBDLZ4kc6qUFpQ6HRgL+3zw==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
dependencies:
|
||||
'@babel/types': 7.16.0
|
||||
'@babel/types': 7.17.0
|
||||
|
||||
/@babel/helper-split-export-declaration/7.16.0:
|
||||
resolution: {integrity: sha512-0YMMRpuDFNGTHNRiiqJX19GjNXA4H0E8jZ2ibccfSxaCogbm3am5WN/2nQNj0YnQwGWM1J06GOcQ2qnh3+0paw==}
|
||||
|
@ -3810,7 +3812,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.16.0
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.16.12:
|
||||
|
@ -3819,7 +3821,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.16.12
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
|
||||
/@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.17.8:
|
||||
resolution: {integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==}
|
||||
|
@ -3827,7 +3829,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
|
||||
/@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.12.9:
|
||||
resolution: {integrity: sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==}
|
||||
|
@ -3942,7 +3944,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.16.0
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.16.12:
|
||||
|
@ -3951,7 +3953,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.16.12
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
|
||||
/@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.17.8:
|
||||
resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==}
|
||||
|
@ -3959,7 +3961,7 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-plugin-utils': 7.14.5
|
||||
'@babel/helper-plugin-utils': 7.16.7
|
||||
|
||||
/@babel/plugin-syntax-private-property-in-object/7.14.5_@babel+core@7.16.0:
|
||||
resolution: {integrity: sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==}
|
||||
|
@ -6175,6 +6177,20 @@ packages:
|
|||
source-map-support: 0.5.20
|
||||
dev: true
|
||||
|
||||
/@babel/register/7.17.7_@babel+core@7.17.8:
|
||||
resolution: {integrity: sha512-fg56SwvXRifootQEDQAu1mKdjh5uthPzdO0N6t358FktfL4XjAVXuH58ULoiW8mesxiOgNIrxiImqEwv0+hRRA==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
clone-deep: 4.0.1
|
||||
find-cache-dir: 2.1.0
|
||||
make-dir: 2.1.0
|
||||
pirates: 4.0.5
|
||||
source-map-support: 0.5.20
|
||||
dev: true
|
||||
|
||||
/@babel/runtime-corejs3/7.16.3:
|
||||
resolution: {integrity: sha512-IAdDC7T0+wEB4y2gbIL0uOXEYpiZEeuFUTVbdGq+UwCcF35T/tS8KrmMomEwEc5wBbyfH3PJVpTSUqrhPDXFcQ==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
|
@ -16120,6 +16136,14 @@ packages:
|
|||
'@babel/core': 7.16.0
|
||||
dev: true
|
||||
|
||||
/babel-core/7.0.0-bridge.0_@babel+core@7.17.8:
|
||||
resolution: {integrity: sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==}
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
dev: true
|
||||
|
||||
/babel-eslint/10.1.0_eslint@6.8.0:
|
||||
resolution: {integrity: sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==}
|
||||
engines: {node: '>=6'}
|
||||
|
@ -21936,7 +21960,7 @@ packages:
|
|||
is-stream: 1.1.0
|
||||
npm-run-path: 2.0.2
|
||||
p-finally: 1.0.0
|
||||
signal-exit: 3.0.5
|
||||
signal-exit: 3.0.7
|
||||
strip-eof: 1.0.0
|
||||
dev: true
|
||||
|
||||
|
@ -22006,7 +22030,7 @@ packages:
|
|||
merge-stream: 2.0.0
|
||||
npm-run-path: 4.0.1
|
||||
onetime: 5.1.2
|
||||
signal-exit: 3.0.5
|
||||
signal-exit: 3.0.7
|
||||
strip-final-newline: 2.0.0
|
||||
dev: true
|
||||
|
||||
|
@ -22021,7 +22045,7 @@ packages:
|
|||
merge-stream: 2.0.0
|
||||
npm-run-path: 4.0.1
|
||||
onetime: 5.1.2
|
||||
signal-exit: 3.0.5
|
||||
signal-exit: 3.0.7
|
||||
strip-final-newline: 2.0.0
|
||||
dev: true
|
||||
|
||||
|
@ -22681,6 +22705,11 @@ packages:
|
|||
resolution: {integrity: sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==}
|
||||
dev: true
|
||||
|
||||
/flow-parser/0.174.1:
|
||||
resolution: {integrity: sha512-nDMOvlFR+4doLpB3OJpseHZ7uEr3ENptlF6qMas/kzQmNcLzMwfQeFX0gGJ/+em7UdldB/nGsk55tDTOvjbCuw==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
dev: true
|
||||
|
||||
/flush-write-stream/1.1.1:
|
||||
resolution: {integrity: sha512-3Z4XhFZ3992uIq0XOqb9AreonueSYphE6oYbpt5+3u06JWklbsPkNv3ZKkP9Bz/r+1MWCaMoSQ28P85+1Yc77w==}
|
||||
dependencies:
|
||||
|
@ -24708,7 +24737,7 @@ packages:
|
|||
resolution: {integrity: sha512-rzDQLaW4jQbh2YrOFlJdCtX8qgJTehFRYiUB2r1osqTeDzV/3+Jh8fz1oAPzUThf3iku8Ds4IDqawI5d8mUiQw==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
minimatch: 3.0.4
|
||||
minimatch: 3.1.2
|
||||
dev: true
|
||||
|
||||
/ignore/4.0.6:
|
||||
|
@ -27939,6 +27968,35 @@ packages:
|
|||
/jsbn/0.1.1:
|
||||
resolution: {integrity: sha1-peZUwuWi3rXyAdls77yoDA7y9RM=}
|
||||
|
||||
/jscodeshift/0.13.1:
|
||||
resolution: {integrity: sha512-lGyiEbGOvmMRKgWk4vf+lUrCWO/8YR8sUR3FKF1Cq5fovjZDlIcw3Hu5ppLHAnEXshVffvaM0eyuY/AbOeYpnQ==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@babel/preset-env': ^7.1.6
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/parser': 7.17.8
|
||||
'@babel/plugin-proposal-class-properties': 7.16.7_@babel+core@7.17.8
|
||||
'@babel/plugin-proposal-nullish-coalescing-operator': 7.16.7_@babel+core@7.17.8
|
||||
'@babel/plugin-proposal-optional-chaining': 7.16.7_@babel+core@7.17.8
|
||||
'@babel/plugin-transform-modules-commonjs': 7.17.7_@babel+core@7.17.8
|
||||
'@babel/preset-flow': 7.16.7_@babel+core@7.17.8
|
||||
'@babel/preset-typescript': 7.16.7_@babel+core@7.17.8
|
||||
'@babel/register': 7.17.7_@babel+core@7.17.8
|
||||
babel-core: 7.0.0-bridge.0_@babel+core@7.17.8
|
||||
chalk: 4.1.2
|
||||
flow-parser: 0.174.1
|
||||
graceful-fs: 4.2.9
|
||||
micromatch: 3.1.10
|
||||
neo-async: 2.6.2
|
||||
node-dir: 0.1.17
|
||||
recast: 0.20.5
|
||||
temp: 0.8.4
|
||||
write-file-atomic: 2.4.1
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/jsdoc-type-pratt-parser/2.2.5:
|
||||
resolution: {integrity: sha512-2a6eRxSxp1BW040hFvaJxhsCMI9lT8QB8t14t+NY5tC5rckIR0U9cr2tjOeaFirmEOy6MHvmJnY7zTBHq431Lw==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
@ -28607,7 +28665,7 @@ packages:
|
|||
resolution: {integrity: sha512-gUD/epcRms75Cw8RT1pUdHugZYM5ce64ucs2GEISABwkRsOQr0q2wm/MV2TKThycIe5e0ytRweW2RZxclogCdQ==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
graceful-fs: 4.2.8
|
||||
graceful-fs: 4.2.9
|
||||
parse-json: 5.2.0
|
||||
strip-bom: 4.0.0
|
||||
type-fest: 0.6.0
|
||||
|
@ -29275,7 +29333,7 @@ packages:
|
|||
globby: 11.0.4
|
||||
isbinaryfile: 4.0.8
|
||||
mem-fs: 2.2.1
|
||||
minimatch: 3.0.4
|
||||
minimatch: 3.1.2
|
||||
multimatch: 5.0.0
|
||||
normalize-path: 3.0.0
|
||||
textextensions: 5.14.0
|
||||
|
@ -29870,7 +29928,7 @@ packages:
|
|||
array-differ: 3.0.0
|
||||
array-union: 2.1.0
|
||||
arrify: 2.0.1
|
||||
minimatch: 3.0.4
|
||||
minimatch: 3.1.2
|
||||
dev: true
|
||||
|
||||
/mute-stream/0.0.7:
|
||||
|
@ -34262,6 +34320,16 @@ packages:
|
|||
resolution: {integrity: sha512-v1SEYUOXXdbBZK8ZuNgO4TBjamPsiSgcFr0aP+tEKpQZK8vooEUqV6nm6Cv502mX4NF2EfsnVqtNAHG+/6Ur1Q==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
/recast/0.20.5:
|
||||
resolution: {integrity: sha512-E5qICoPoNL4yU0H0NoBDntNB0Q5oMSNh9usFctYniLBluTthi3RsQVBXIJNbApOlvSwW/RGxIuokPcAc59J5fQ==}
|
||||
engines: {node: '>= 4'}
|
||||
dependencies:
|
||||
ast-types: 0.14.2
|
||||
esprima: 4.0.1
|
||||
source-map: 0.6.1
|
||||
tslib: 2.3.1
|
||||
dev: true
|
||||
|
||||
/rechoir/0.6.2:
|
||||
resolution: {integrity: sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=}
|
||||
engines: {node: '>= 0.10'}
|
||||
|
@ -36849,6 +36917,13 @@ packages:
|
|||
memoizerific: 1.11.3
|
||||
dev: true
|
||||
|
||||
/temp/0.8.4:
|
||||
resolution: {integrity: sha512-s0ZZzd0BzYv5tLSptZooSjK8oj6C+c19p7Vqta9+6NPOf7r+fxq0cJe6/oN4LTC79sy5NY8ucOJNgwsKCSbfqg==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
dependencies:
|
||||
rimraf: 2.6.3
|
||||
dev: true
|
||||
|
||||
/term-size/1.2.0:
|
||||
resolution: {integrity: sha1-RYuDiH8oj8Vtb/+/rSYuJmOO+mk=}
|
||||
engines: {node: '>=4'}
|
||||
|
@ -39474,7 +39549,7 @@ packages:
|
|||
dependencies:
|
||||
imurmurhash: 0.1.4
|
||||
is-typedarray: 1.0.0
|
||||
signal-exit: 3.0.5
|
||||
signal-exit: 3.0.7
|
||||
typedarray-to-buffer: 3.1.5
|
||||
|
||||
/write-file-atomic/4.0.1:
|
||||
|
@ -39490,7 +39565,7 @@ packages:
|
|||
engines: {node: '>=8.3'}
|
||||
dependencies:
|
||||
detect-indent: 6.1.0
|
||||
graceful-fs: 4.2.8
|
||||
graceful-fs: 4.2.9
|
||||
is-plain-obj: 2.1.0
|
||||
make-dir: 3.1.0
|
||||
sort-keys: 4.2.0
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
export const parser = 'tsx';
|
||||
|
||||
const i18nFunctionsToRename = [
|
||||
'__',
|
||||
'_n',
|
||||
'_x'
|
||||
]
|
||||
|
||||
|
||||
const isFunctionNamed = ( path, names ) => {
|
||||
return names.includes(path.value.callee.name);
|
||||
};
|
||||
|
||||
export default function transformer( file, api ) {
|
||||
const j = api.jscodeshift;
|
||||
|
||||
return j( file.source )
|
||||
.find( j.CallExpression )
|
||||
.filter( ( p ) => isFunctionNamed( p, i18nFunctionsToRename ) )
|
||||
.forEach( ( path ) => {
|
||||
j( path ) // Descend into each call expression to find any strings literal 'woocommerce-admin'
|
||||
.find( j.StringLiteral, { value: 'woocommerce-admin' } )
|
||||
.replaceWith( j.stringLiteral( 'woocommerce' ) );
|
||||
} )
|
||||
.toSource();
|
||||
}
|
|
@ -26,6 +26,7 @@
|
|||
"@types/node": "^16.9.4",
|
||||
"eslint": "^7.32.0",
|
||||
"globby": "^11",
|
||||
"jscodeshift": "^0.13.1",
|
||||
"oclif": "^2",
|
||||
"shx": "^0.3.3",
|
||||
"ts-node": "^10.2.1",
|
||||
|
|
Loading…
Reference in New Issue