Skip to content

Commit ddcc788

Browse files
committed
support gatsby@^5.0.0
1 parent 1e0251e commit ddcc788

File tree

8 files changed

+8757
-9809
lines changed

8 files changed

+8757
-9809
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ yarn-error.log
6969
.yarn-integrity
7070

7171
# plugin build
72-
/*.js
72+
/*.js

package-lock.json

Lines changed: 8711 additions & 4880 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
{
22
"name": "gatsby-plugin-intl",
33
"description": "Gatsby plugin to add react-intl onto a site",
4-
"version": "0.3.3",
4+
"version": "5.8.1",
55
"author": "Daewoong Moon <[email protected]>",
66
"bugs": {
77
"url": "https://github.com/wiziple/gatsby-plugin-intl"
88
},
99
"dependencies": {
10-
"@babel/runtime": "^7.8.4",
11-
"@formatjs/intl-pluralrules": "^1.5.2",
12-
"@formatjs/intl-relativetimeformat": "^4.5.9",
13-
"browser-lang": "^0.1.0",
10+
"@babel/runtime": "^7.21.0",
11+
"@formatjs/intl-pluralrules": "^5.1.10",
12+
"@formatjs/intl-relativetimeformat": "^11.1.10",
13+
"browser-lang": "^0.2.1",
1414
"intl": "^1.2.5",
15-
"react-intl": "^3.12.0"
15+
"react-intl": "^6.3.2"
1616
},
1717
"devDependencies": {
18-
"@babel/cli": "^7.8.4",
19-
"@babel/core": "^7.8.4",
20-
"babel-preset-gatsby-package": "^0.2.16",
21-
"cross-env": "^7.0.0",
22-
"jest": "^25.1.0",
23-
"prettier": "^1.19.1",
24-
"rimraf": "^3.0.2"
25-
},
26-
"peerDependencies": {
27-
"gatsby": "^3.0.0"
18+
"@babel/cli": "^7.21.0",
19+
"@babel/core": "^7.21.3",
20+
"babel-preset-gatsby-package": "^3.8.0",
21+
"cross-env": "^7.0.3",
22+
"jest": "^25.5.4",
23+
"prettier": "^2.8.7",
24+
"rimraf": "^4.4.1"
2825
},
2926
"homepage": "https://github.com/wiziple/gatsby-plugin-intl",
3027
"keywords": [
@@ -42,8 +39,8 @@
4239
"build": "babel src --out-dir . --ignore **/__tests__",
4340
"prepare": "cross-env NODE_ENV=production npm run build",
4441
"watch": "babel -w src --out-dir . --ignore **/__tests__",
45-
"format": "prettier --write {src,__tests__}/**/*.{js,jsx}",
42+
"format": "prettier --write {src,__tests__}/**/*.js",
4643
"test": "jest",
4744
"clean": "rimraf *.js"
4845
}
49-
}
46+
}

src/gatsby-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports.onCreateWebpackConfig = ({ actions, plugins }, pluginOptions) => {
2020
if (!languages.includes(defaultLanguage)) {
2121
languages.push(defaultLanguage)
2222
}
23-
const regex = new RegExp(languages.map(l => l.split("-")[0]).join("|"))
23+
const regex = new RegExp(languages.map((l) => l.split("-")[0]).join("|"))
2424
actions.setWebpackConfig({
2525
plugins: [
2626
plugins.define({
@@ -95,7 +95,7 @@ exports.onCreatePage = async ({ page, actions }, pluginOptions) => {
9595
deletePage(page)
9696
createPage(newPage)
9797

98-
languages.forEach(language => {
98+
languages.forEach((language) => {
9999
const localePage = generatePage(true, language)
100100
const regexp = new RegExp("/404/?$")
101101
if (regexp.test(localePage.path)) {

src/link.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@ import PropTypes from "prop-types"
33
import { Link as GatsbyLink, navigate as gatsbyNavigate } from "gatsby"
44
import { IntlContextConsumer } from "./intl-context"
55

6-
const Link = React.forwardRef(({ to, language, children, onClick, ...rest }, ref) => (
7-
<IntlContextConsumer>
8-
{intl => {
9-
const languageLink = language || intl.language
10-
const link = intl.routed || language ? `/${languageLink}${to}` : `${to}`
6+
const Link = React.forwardRef(
7+
({ to, language, children, onClick, ...rest }, ref) => (
8+
<IntlContextConsumer>
9+
{(intl) => {
10+
const languageLink = language || intl.language
11+
const link = intl.routed || language ? `/${languageLink}${to}` : `${to}`
1112

12-
const handleClick = e => {
13-
if (language) {
14-
localStorage.setItem("gatsby-intl-language", language)
13+
const handleClick = (e) => {
14+
if (language) {
15+
localStorage.setItem("gatsby-intl-language", language)
16+
}
17+
if (onClick) {
18+
onClick(e)
19+
}
1520
}
16-
if (onClick) {
17-
onClick(e)
18-
}
19-
}
2021

21-
return (
22-
<GatsbyLink {...rest} to={link} onClick={handleClick} ref={ref}>
23-
{children}
24-
</GatsbyLink>
25-
)
26-
}}
27-
</IntlContextConsumer>
28-
))
22+
return (
23+
<GatsbyLink {...rest} to={link} onClick={handleClick} ref={ref}>
24+
{children}
25+
</GatsbyLink>
26+
)
27+
}}
28+
</IntlContextConsumer>
29+
)
30+
)
2931

3032
Link.propTypes = {
3133
children: PropTypes.node.isRequired,
@@ -55,7 +57,7 @@ export const changeLocale = (language, to) => {
5557
}
5658
const { routed } = window.___gatsbyIntl
5759

58-
const removePrefix = pathname => {
60+
const removePrefix = (pathname) => {
5961
const base =
6062
typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : __PATH_PREFIX__
6163
if (base && pathname.indexOf(base) === 0) {
@@ -64,7 +66,7 @@ export const changeLocale = (language, to) => {
6466
return pathname
6567
}
6668

67-
const removeLocalePart = pathname => {
69+
const removeLocalePart = (pathname) => {
6870
if (!routed) {
6971
return pathname
7072
}

src/with-intl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react"
22
import { injectIntl } from "react-intl"
3-
export default Component => props => {
3+
export default (Component) => (props) => {
44
console.warn("withIntl is deprecated. Please use injectIntl instead.")
55
return React.createElement(injectIntl(Component), props)
66
}

src/wrap-page.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { withPrefix } from "gatsby"
44
import { IntlProvider } from "react-intl"
55
import { IntlContextProvider } from "./intl-context"
66

7-
const preferDefault = m => (m && m.default) || m
7+
const preferDefault = (m) => (m && m.default) || m
88

9-
const polyfillIntl = language => {
9+
const polyfillIntl = (language) => {
1010
const locale = language.split("-")[0]
1111
try {
1212
if (!Intl.PluralRules) {
@@ -23,7 +23,7 @@ const polyfillIntl = language => {
2323
}
2424
}
2525

26-
const withIntlProvider = (intl) => children => {
26+
const withIntlProvider = (intl) => (children) => {
2727
polyfillIntl(intl.language)
2828
return (
2929
<IntlProvider

0 commit comments

Comments
 (0)