Skip to content

Commit d3d9c43

Browse files
committed
fix: babel-plugin-react-intl error
1 parent fb088f2 commit d3d9c43

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/test/fixtures/**
22
.github
3+
dist
34
package.json

cli.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
/* eslint-disable no-console, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
32
'use strict'
43
const meow = require('meow')
54
const fn = require('./dist').default
@@ -48,17 +47,15 @@ const cli = meow(
4847
default: false
4948
},
5049
// babel-plugin-react-intl boolean options
51-
enforceDescriptions: {
50+
extractSourceLocation: {
5251
type: 'boolean',
5352
default: false
5453
},
55-
enforceDefaultMessage: {
56-
type: 'boolean',
57-
default: true
54+
removeDefaultMessage: {
55+
type: 'boolean'
5856
},
59-
extractSourceLocation: {
60-
type: 'boolean',
61-
default: false
57+
extractFromFormatMessageCall: {
58+
type: 'boolean'
6259
}
6360
}
6461
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "dist/index.js",
1616
"scripts": {
1717
"add-contributor": "all-contributors add",
18-
"fmt": "prettier --write '**/*.{json,js,md}'",
18+
"fmt": "prettier --write '**/*.{ts,json,js,md}'",
1919
"example": "./cli.js -l=en,ja -o example/i18n -d en --extractFromFormatMessageCall=true 'example/**/*.{js,tsx}'",
2020
"prepublish": "npm run build",
2121
"build": "tsc",
@@ -90,12 +90,12 @@
9090
"typescript": "^3.6.2"
9191
},
9292
"lint-staged": {
93-
"*.{js}": [
93+
"*.{ts}": [
9494
"prettier --write",
9595
"eslint --fix",
9696
"git add"
9797
],
98-
"*.{json,md}": [
98+
"*.{js,json,md}": [
9999
"prettier --write",
100100
"git add"
101101
]

src/extract-react-intl/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ const getBabelrc = (cwd: string) => {
5353
const getBabelrcDir = (cwd: string) =>
5454
path.dirname(readBabelrcUp.sync({ cwd }).path)
5555

56+
const babelPluginReactIntlOptions = [
57+
'moduleSourceName',
58+
'extractSourceLocation',
59+
'messagesDir',
60+
'overrideIdFn',
61+
'removeDefaultMessage',
62+
'extractFromFormatMessageCall',
63+
'additionalComponentNames'
64+
]
65+
5666
type Options = {
5767
defaultLocale?: string
5868
cwd?: string
@@ -91,7 +101,19 @@ export default async (
91101
const presets = babelrc.presets || []
92102
const plugins = babelrc.plugins || []
93103

94-
presets.unshift({ plugins: [[babelPluginReactIntl, pluginOptions]] })
104+
presets.unshift({
105+
plugins: [
106+
[
107+
babelPluginReactIntl,
108+
Object.entries(pluginOptions).reduce((acc, [key, value]) => {
109+
if (babelPluginReactIntlOptions.includes(key)) {
110+
return { ...acc, [key]: value }
111+
}
112+
return acc
113+
}, {})
114+
]
115+
]
116+
})
95117

96118
const extractFromFile = async (file: string) => {
97119
const babelOpts = {

0 commit comments

Comments
 (0)