Skip to content

Commit 71b0348

Browse files
alexandernanberggaearon
authored andcommitted
Upgrade to Gatsby v2 (reactjs#1104)
* Upgrade to Gatsby v2 * Remove unnecessary polyfills since gatsby already provides them * Move global styles to gatsby-browser * Add fb comment and convert to cjs * Revert to use pageQuery again * Add back html.js * Update dependencies * Move TitleAndMetaTags * Replace glamor/reset with normalize.css which fixes style order in prod * Prettier formatting * Remove unused types * Remove old layout * Fix versions link * Update deps * Update deps * Remove hack since it's no longer needed * Update dependencies * Fix build error * Fix prettier config resolution * Update gatsby * Remove custom onCreatePage logic * Update dependencies * Fix build * Update dependencies * prettier formatting * update dependencies * add custom babel config for flow * upgrade dependencies * update dependencies * use stable gatsby release
1 parent 12f003c commit 71b0348

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4277
-4191
lines changed

.babelrc

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
{
2-
"presets": ['react', 'es2015', 'stage-1'],
3-
"plugins": ['add-module-exports']
4-
}
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"loose": true,
7+
"modules": false,
8+
"useBuiltIns": "usage",
9+
"shippedProposals": true,
10+
"targets": {
11+
"browsers": [">0.25%", "not dead"],
12+
}
13+
}
14+
],
15+
[
16+
"@babel/preset-react",
17+
{
18+
"useBuiltIns": true,
19+
"pragma": "React.createElement",
20+
}
21+
],
22+
"@babel/flow"
23+
],
24+
"plugins": [
25+
[
26+
"@babel/plugin-proposal-class-properties",
27+
{
28+
"loose": true
29+
}
30+
],
31+
"@babel/plugin-syntax-dynamic-import",
32+
"babel-plugin-macros",
33+
[
34+
"@babel/plugin-transform-runtime",
35+
{
36+
"helpers": true,
37+
"regenerator": true
38+
}
39+
]
40+
]
41+
}
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
declare module 'gatsby-link' {
1+
declare module 'gatsby' {
22
declare module.exports: any;
33
}

flow-typed/glamor.js

-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ declare module 'glamor/react' {
1515
propMerge: Function,
1616
};
1717
}
18-
19-
declare module 'glamor/reset' {
20-
declare module.exports: any;
21-
}

flow-typed/graphql.js

-1
This file was deleted.

flow-typed/polyfills.js

-11
This file was deleted.

gatsby-browser.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* @emails react-core
5+
*/
6+
7+
'use strict';
8+
9+
// Import global styles
10+
require('normalize.css');
11+
require('./src/css/reset.css');
12+
require('./src/prism-styles');
13+
require('./src/css/algolia.css');
14+
15+
// A stub function is needed because gatsby won't load this file otherwise
16+
// (https://github.com/gatsbyjs/gatsby/issues/6759)
17+
exports.onClientEntry = () => {};

gatsby-config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
'gatsby-transformer-versions-yaml',
2424
'gatsby-plugin-netlify',
2525
'gatsby-plugin-glamor',
26-
'gatsby-plugin-react-next',
2726
'gatsby-plugin-twitter',
2827
{
2928
resolve: 'gatsby-plugin-nprogress',
@@ -134,7 +133,7 @@ module.exports = {
134133
{
135134
allMarkdownRemark
136135
(limit: 10,
137-
filter: {id: {regex: "/blog/"}},
136+
filter: {fileAbsolutePath: {regex: "/blog/"}},
138137
sort: {fields: [fields___date],
139138
order: DESC}) {
140139
edges {

gatsby-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
'use strict';
88

9-
exports.modifyWebpackConfig = require('./gatsby/modifyWebpackConfig');
9+
exports.onCreateWebpackConfig = require('./gatsby/onCreateWebpackConfig');
1010
exports.createPages = require('./gatsby/createPages');
1111
exports.onCreateNode = require('./gatsby/onCreateNode');
1212
exports.onCreatePage = require('./gatsby/onCreatePage');

gatsby/createPages.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
const {resolve} = require('path');
1010

11-
module.exports = async ({graphql, boundActionCreators}) => {
12-
const {createPage, createRedirect} = boundActionCreators;
11+
module.exports = async ({graphql, actions}) => {
12+
const {createPage, createRedirect} = actions;
1313

1414
// Used to detect and prevent duplicate redirects
1515
const redirectToSlugMap = {};
@@ -129,7 +129,7 @@ module.exports = async ({graphql, boundActionCreators}) => {
129129
{
130130
allMarkdownRemark(
131131
limit: 1
132-
filter: {id: {regex: "/blog/"}}
132+
filter: {fileAbsolutePath: {regex: "/blog/"}}
133133
sort: {fields: [fields___date], order: DESC}
134134
) {
135135
edges {
@@ -143,6 +143,7 @@ module.exports = async ({graphql, boundActionCreators}) => {
143143
}
144144
`,
145145
);
146+
146147
const newestBlogNode = newestBlogEntry.data.allMarkdownRemark.edges[0].node;
147148

148149
// Blog landing page should always show the most recent blog entry.
@@ -151,4 +152,4 @@ module.exports = async ({graphql, boundActionCreators}) => {
151152
redirectInBrowser: true,
152153
toPath: newestBlogNode.fields.slug,
153154
});
154-
};
155+
};

gatsby/modifyWebpackConfig.js

-23
This file was deleted.

gatsby/onCreateNode.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function buildRedirectString(permalink, redirect_from) {
2424
}
2525

2626
// Add custom fields to MarkdownRemark nodes.
27-
module.exports = exports.onCreateNode = ({node, boundActionCreators, getNode}) => {
28-
const {createNodeField} = boundActionCreators;
27+
module.exports = exports.onCreateNode = ({node, actions, getNode}) => {
28+
const {createNodeField} = actions;
2929

3030
switch (node.internal.type) {
3131
case 'MarkdownRemark':

gatsby/onCreatePage.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66

77
'use strict';
88

9-
module.exports = async ({page, boundActionCreators}) => {
10-
const {createPage} = boundActionCreators;
9+
module.exports = async ({page, actions}) => {
10+
const {createPage} = actions;
1111

1212
return new Promise(resolvePromise => {
13-
// page.matchPath is a special key that's used for matching pages only on the client.
14-
// Explicitly wire up all error code wildcard matches to redirect to the error code page.
1513
if (page.path.includes('docs/error-decoder.html')) {
16-
page.matchPath = 'docs/error-decoder:path?';
1714
page.context.slug = 'docs/error-decoder.html';
1815

1916
createPage(page);
2017
}
21-
2218
resolvePromise();
2319
});
2420
};

gatsby/onCreateWebpackConfig.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* @emails react-core
5+
*/
6+
7+
'use strict';
8+
9+
const {resolve} = require('path');
10+
const webpack = require('webpack');
11+
12+
module.exports = ({stage, actions}) => {
13+
actions.setWebpackConfig({
14+
resolve: {
15+
modules: [
16+
resolve(__dirname, '../src'),
17+
resolve(__dirname, '../node_modules'),
18+
],
19+
},
20+
// See https://github.com/FormidableLabs/react-live/issues/5
21+
plugins: [new webpack.IgnorePlugin(/^(xor|props)$/)],
22+
});
23+
};

package.json

+30-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"url": "https://github.com/reactjs/reactjs.org"
88
},
99
"dependencies": {
10-
"array-from": "^2.1.1",
1110
"babel-eslint": "^8.0.1",
1211
"eslint": "^4.8.0",
1312
"eslint-config-fbjs": "^2.0.0",
@@ -19,40 +18,41 @@
1918
"eslint-plugin-react": "^7.4.0",
2019
"eslint-plugin-relay": "^0.0.19",
2120
"flow-bin": "^0.56.0",
22-
"gatsby": "^1.9.273",
23-
"gatsby-link": "^1.6.9",
24-
"gatsby-plugin-catch-links": "^1.0.9",
25-
"gatsby-plugin-feed": "^1.3.9",
26-
"gatsby-plugin-glamor": "^1.6.4",
27-
"gatsby-plugin-google-analytics": "^1.0.4",
28-
"gatsby-plugin-manifest": "^1.0.4",
29-
"gatsby-plugin-netlify": "^1.0.21",
30-
"gatsby-plugin-nprogress": "^1.0.7",
31-
"gatsby-plugin-react-helmet": "^1.0.3",
32-
"gatsby-plugin-react-next": "^1.0.3",
33-
"gatsby-plugin-sharp": "^1.6.48",
34-
"gatsby-plugin-twitter": "^1.0.10",
35-
"gatsby-remark-autolink-headers": "^1.4.4",
36-
"gatsby-remark-code-repls": "^1.0.2",
37-
"gatsby-remark-copy-linked-files": "^1.5.2",
38-
"gatsby-remark-embed-snippet": "^1.0.22",
39-
"gatsby-remark-images": "^1.5.67",
40-
"gatsby-remark-prismjs": "^1.2.24",
41-
"gatsby-remark-responsive-iframe": "^1.4.3",
42-
"gatsby-remark-smartypants": "^1.4.3",
43-
"gatsby-source-filesystem": "^1.4.4",
44-
"gatsby-transformer-remark": "^1.7.44",
45-
"gatsby-transformer-sharp": "^1.6.27",
21+
"gatsby": "^2.0.0",
22+
"gatsby-plugin-catch-links": "^2.0.0",
23+
"gatsby-plugin-feed": "^2.0.0",
24+
"gatsby-plugin-glamor": "^2.0.0",
25+
"gatsby-plugin-google-analytics": "^2.0.0",
26+
"gatsby-plugin-manifest": "^2.0.0",
27+
"gatsby-plugin-netlify": "^2.0.0",
28+
"gatsby-plugin-nprogress": "^2.0.0",
29+
"gatsby-plugin-react-helmet": "^3.0.0",
30+
"gatsby-plugin-sharp": "^2.0.0",
31+
"gatsby-plugin-twitter": "^2.0.0",
32+
"gatsby-remark-autolink-headers": "^2.0.0",
33+
"gatsby-remark-code-repls": "^2.0.0",
34+
"gatsby-remark-copy-linked-files": "^2.0.0",
35+
"gatsby-remark-embed-snippet": "^3.0.0",
36+
"gatsby-remark-images": "^2.0.0",
37+
"gatsby-remark-prismjs": "^3.0.0",
38+
"gatsby-remark-responsive-iframe": "^2.0.0",
39+
"gatsby-remark-smartypants": "^2.0.0",
40+
"gatsby-source-filesystem": "^2.0.0",
41+
"gatsby-transformer-remark": "^2.0.0",
42+
"gatsby-transformer-sharp": "^2.0.0",
4643
"glamor": "^2.20.40",
4744
"hex2rgba": "^0.0.1",
45+
"normalize.css": "^8.0.0",
4846
"prettier": "^1.7.4",
47+
"prismjs": "^1.15.0",
48+
"react": "^16.4.1",
49+
"react-dom": "^16.4.1",
50+
"react-helmet": "^5.2.0",
4951
"react-live": "1.8.0-0",
5052
"remarkable": "^1.7.1",
5153
"request-promise": "^4.2.2",
5254
"rimraf": "^2.6.1",
5355
"slugify": "^1.2.1",
54-
"string.prototype.includes": "^1.0.0",
55-
"string.prototype.repeat": "^0.2.0",
5656
"unist-util-visit": "^1.1.3"
5757
},
5858
"engines": {
@@ -76,16 +76,17 @@
7676
"dev": "gatsby develop -H 0.0.0.0",
7777
"flow": "flow",
7878
"format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
79-
"format:examples": "prettier --config .prettierrc.examples --write \"examples/**/*.js\"",
79+
"format:examples": "prettier --config examples/.prettierrc --write \"examples/**/*.js\"",
8080
"lint": "eslint .",
8181
"netlify": "yarn --version && rimraf node_modules && yarn install --frozen-lockfile --check-files && yarn build",
8282
"nit:source": "prettier --config .prettierrc --list-different \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
83-
"nit:examples": "prettier --config .prettierrc.examples --list-different \"examples/**/*.js\"",
83+
"nit:examples": "prettier --config examples/.prettierrc --list-different \"examples/**/*.js\"",
8484
"prettier": "yarn format:source && yarn format:examples",
8585
"prettier:diff": "yarn nit:source && yarn nit:examples",
8686
"reset": "rimraf ./.cache"
8787
},
8888
"devDependencies": {
89+
"@babel/preset-flow": "^7.0.0",
8990
"eslint-config-prettier": "^2.6.0",
9091
"lz-string": "^1.4.4",
9192
"npm-run-all": "^4.1.2",

plugins/gatsby-source-react-error-codes/gatsby-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const request = require('request-promise');
33
const errorCodesUrl =
44
'http://raw.githubusercontent.com/facebook/react/master/scripts/error-codes/codes.json';
55

6-
exports.sourceNodes = async ({boundActionCreators}) => {
7-
const {createNode} = boundActionCreators;
6+
exports.sourceNodes = async ({actions}) => {
7+
const {createNode} = actions;
88

99
try {
1010
const jsonString = await request(errorCodesUrl);

plugins/gatsby-transformer-authors-yaml/gatsby-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const safeLoad = require('js-yaml').safeLoad;
88

99
// Reads authors.yml data into GraphQL.
1010
// This is auto-linked by gatsby-config.js to blog posts.
11-
exports.sourceNodes = ({graphql, boundActionCreators}) => {
12-
const {createNode} = boundActionCreators;
11+
exports.sourceNodes = ({graphql, actions}) => {
12+
const {createNode} = actions;
1313

1414
const path = resolve(__dirname, '../../content/authors.yml');
1515
const file = readFileSync(path, 'utf8');

plugins/gatsby-transformer-home-example-code/gatsby-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const {join, resolve} = require('path');
33

44
// Store code snippets in GraphQL for the home page examples.
55
// Snippets will be matched with markdown templates of the same name.
6-
exports.sourceNodes = ({graphql, boundActionCreators}) => {
7-
const {createNode} = boundActionCreators;
6+
exports.sourceNodes = ({graphql, actions}) => {
7+
const {createNode} = actions;
88

99
const path = resolve(__dirname, '../../content/home/examples');
1010
const files = readdirSync(path);

src/components/ButtonLink/ButtonLink.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @emails react-core
55
*/
66

7-
import Link from 'gatsby-link';
7+
import {Link} from 'gatsby';
88
import React from 'react';
99
import {colors, media} from 'theme';
1010

src/components/ErrorDecoder/ErrorDecoder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function ErrorDecoder(props: {|
9595
let msg = '';
9696

9797
const errorCodes = JSON.parse(props.errorCodesString);
98-
const parseResult = parseQueryString(props.location.search);
98+
const parseResult = parseQueryString(props.location.search || '');
9999
if (parseResult != null) {
100100
code = parseResult.code;
101101
msg = replaceArgs(errorCodes[code], parseResult.args);

0 commit comments

Comments
 (0)