Skip to content

Commit 5c485e8

Browse files
committed
SAVEPOINT
1 parent f743c9f commit 5c485e8

File tree

14 files changed

+925
-593
lines changed

14 files changed

+925
-593
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ packages/gatsby-image/withIEPolyfill/index.js
2424
packages/gatsby/cache-dir/commonjs/**/*
2525
packages/gatsby-admin/public
2626
packages/gatsby/gatsby-admin-public
27+
28+
packages/gatsby-codemods/transforms/*

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"@types/bluebird": "^3.5.33",
1111
"@types/cache-manager": "^2.10.3",
1212
"@types/common-tags": "^1.8.0",
13-
"@types/eslint": "^6.8.1",
1413
"@types/express": "^4.17.3",
1514
"@types/fs-extra": "^8.1.1",
1615
"@types/got": "^9.6.11",
@@ -25,7 +24,6 @@
2524
"@types/semver": "^7.3.4",
2625
"@types/signal-exit": "^3.0.0",
2726
"@types/stack-trace": "^0.0.29",
28-
"@types/webpack": "^4.41.24",
2927
"@types/webpack-merge": "^4.1.5",
3028
"@typescript-eslint/eslint-plugin": "^2.34.0",
3129
"@typescript-eslint/parser": "^2.34.0",
@@ -161,4 +159,4 @@
161159
"workspaces": [
162160
"packages/*"
163161
]
164-
}
162+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"presets": [["babel-preset-gatsby-package", { "browser": true }]]
2+
"presets": [["babel-preset-gatsby-package"]],
3+
"overrides": [{
4+
"test": "./src/gatsby-browser.js",
5+
"presets": [["babel-preset-gatsby-package", {"browser": true}]]
6+
}]
37
}

packages/gatsby/cache-dir/develop-static-entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default (pagePath, callback) => {
104104
body: ``,
105105
headComponents: headComponents.concat([
106106
<script key={`io`} src="/socket.io/socket.io.js" />,
107+
<link key="styles" rel="stylesheet" href="/commons.css" />,
107108
]),
108109
htmlAttributes,
109110
bodyAttributes,

packages/gatsby/cache-dir/static-entry.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ export default (pagePath, callback) => {
301301
return { rel: `preload`, name: chunk }
302302
})
303303

304-
namedChunkGroups[s].assets.forEach(asset =>
305-
chunks.push({ rel: `preload`, name: asset })
306-
)
304+
namedChunkGroups[s].assets.forEach(asset => {
305+
chunks.push({ rel: `preload`, name: asset.name })
306+
})
307307

308308
const childAssets = namedChunkGroups[s].childAssets
309309
for (const rel in childAssets) {

packages/gatsby/package.json

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@mikaelkristiansson/domready": "^1.0.10",
2121
"@nodelib/fs.walk": "^1.2.4",
2222
"@pieh/friendly-errors-webpack-plugin": "1.7.0-chalk-2",
23-
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.1",
23+
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
2424
"@reach/router": "^1.3.4",
2525
"@types/http-proxy": "^1.17.4",
2626
"@typescript-eslint/eslint-plugin": "^2.24.0",
@@ -32,7 +32,7 @@
3232
"axios": "^0.21.1",
3333
"babel-core": "7.0.0-bridge.0",
3434
"babel-eslint": "^10.1.0",
35-
"babel-loader": "^8.1.0",
35+
"babel-loader": "^8.2.2",
3636
"babel-plugin-add-module-exports": "^1.0.4",
3737
"babel-plugin-dynamic-import-node": "^2.3.3",
3838
"babel-plugin-lodash": "^3.3.4",
@@ -52,7 +52,7 @@
5252
"copyfiles": "^2.3.0",
5353
"core-js": "^3.6.5",
5454
"cors": "^2.8.5",
55-
"css-loader": "^1.0.1",
55+
"css-loader": "^5.0.1",
5656
"date-fns": "^2.14.0",
5757
"debug": "^3.2.7",
5858
"del": "^5.1.0",
@@ -61,7 +61,7 @@
6161
"dotenv": "^8.2.0",
6262
"eslint": "^6.8.0",
6363
"eslint-config-react-app": "^5.2.1",
64-
"eslint-loader": "^2.2.1",
64+
"eslint-loader": "^4.0.2",
6565
"eslint-plugin-flowtype": "^3.13.0",
6666
"eslint-plugin-graphql": "^4.0.0",
6767
"eslint-plugin-import": "^2.22.0",
@@ -73,7 +73,7 @@
7373
"express": "^4.17.1",
7474
"express-graphql": "^0.9.0",
7575
"fastest-levenshtein": "^1.0.12",
76-
"file-loader": "^1.1.11",
76+
"file-loader": "^6.2.0",
7777
"find-cache-dir": "^3.3.1",
7878
"fs-exists-cached": "1.0.0",
7979
"fs-extra": "^8.1.0",
@@ -107,28 +107,28 @@
107107
"meant": "^1.0.1",
108108
"micromatch": "^4.0.2",
109109
"mime": "^2.4.6",
110-
"mini-css-extract-plugin": "^0.11.2",
110+
"mini-css-extract-plugin": "^1.3.4",
111111
"mitt": "^1.2.0",
112112
"mkdirp": "^0.5.1",
113113
"moment": "^2.27.0",
114114
"name-all-modules-plugin": "^1.0.1",
115115
"normalize-path": "^3.0.0",
116-
"null-loader": "^3.0.0",
116+
"null-loader": "^4.0.1",
117117
"opentracing": "^0.14.4",
118-
"optimize-css-assets-webpack-plugin": "^5.0.3",
118+
"optimize-css-assets-webpack-plugin": "^5.0.4",
119119
"p-defer": "^3.0.0",
120120
"parseurl": "^1.3.3",
121121
"physical-cpu-count": "^2.0.0",
122122
"pnp-webpack-plugin": "^1.6.4",
123123
"postcss-flexbugs-fixes": "^4.2.1",
124-
"postcss-loader": "^3.0.0",
124+
"postcss-loader": "^4.1.0",
125125
"prompts": "^2.3.2",
126126
"prop-types": "^15.7.2",
127127
"query-string": "^6.13.1",
128-
"raw-loader": "^0.5.1",
129-
"react-dev-utils": "^4.2.3",
128+
"raw-loader": "^4.0.2",
129+
"react-dev-utils": "^11.0.1",
130130
"react-error-overlay": "^3.0.0",
131-
"react-hot-loader": "^4.12.21",
131+
"react-hot-loader": "^4.13.0",
132132
"react-refresh": "^0.8.3",
133133
"redux": "^4.0.5",
134134
"redux-thunk": "^2.3.0",
@@ -144,29 +144,30 @@
144144
"stack-trace": "^0.0.10",
145145
"string-similarity": "^1.2.2",
146146
"strip-ansi": "^5.2.0",
147-
"style-loader": "^0.23.1",
147+
"style-loader": "^2.0.0",
148148
"terminal-link": "^2.1.1",
149-
"terser-webpack-plugin": "^2.3.8",
149+
"terser-webpack-plugin": "^5.1.1",
150150
"tmp": "^0.2.1",
151151
"true-case-path": "^2.2.1",
152152
"type-of": "^2.0.1",
153-
"url-loader": "^1.1.2",
153+
"url-loader": "^4.1.1",
154154
"util.promisify": "^1.0.1",
155155
"uuid": "3.4.0",
156156
"v8-compile-cache": "^1.1.2",
157-
"webpack": "^4.44.1",
158-
"webpack-dev-middleware": "^3.7.2",
157+
"webpack": "^5.16.0",
158+
"webpack-dev-middleware": "^4.1.0",
159159
"webpack-dev-server": "^3.11.2",
160160
"webpack-hot-middleware": "^2.25.0",
161-
"webpack-merge": "^4.2.2",
162-
"webpack-stats-plugin": "^0.3.2",
163-
"webpack-virtual-modules": "^0.2.2",
161+
"webpack-merge": "^5.7.3",
162+
"webpack-stats-plugin": "^1.0.3",
163+
"webpack-virtual-modules": "^0.4.2",
164164
"xstate": "^4.11.0",
165165
"yaml-loader": "^0.6.0"
166166
},
167167
"devDependencies": {
168168
"@babel/cli": "^7.12.1",
169169
"@babel/runtime": "^7.12.5",
170+
"@types/eslint": "^7.2.6",
170171
"@types/hapi__joi": "^16.0.12",
171172
"@types/micromatch": "^4.0.1",
172173
"@types/normalize-path": "^3.0.0",
@@ -176,7 +177,7 @@
176177
"@types/socket.io": "^2.1.4",
177178
"@types/string-similarity": "^3.0.0",
178179
"@types/tmp": "^0.2.0",
179-
"@types/webpack-dev-middleware": "^3.7.1",
180+
"@types/webpack-dev-middleware": "^4.1.0",
180181
"@types/webpack-virtual-modules": "^0.1.0",
181182
"babel-preset-gatsby-package": "^0.12.0-next.0",
182183
"cross-env": "^7.0.3",
@@ -241,8 +242,8 @@
241242
"remark-mdxjs": "^2.0.0-next.3"
242243
},
243244
"scripts": {
244-
"build": "npm run build:types && npm run build:src && npm run build:internal-plugins && npm run build:rawfiles && npm run build:cjs",
245-
"postbuild": "node scripts/output-api-file.js && yarn workspace gatsby-admin build",
245+
"build": "npm run build:src && npm run build:internal-plugins && npm run build:rawfiles && npm run build:cjs",
246+
"postbuild": "node scripts/output-api-file.js",
246247
"build:internal-plugins": "copyfiles -u 1 src/internal-plugins/**/package.json dist",
247248
"build:rawfiles": "copyfiles -u 1 src/internal-plugins/**/raw_* dist",
248249
"build:cjs": "babel cache-dir --out-dir cache-dir/commonjs --ignore \"**/__tests__\" --ignore \"**/__mocks__\"",

packages/gatsby/src/services/start-webpack-server.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import openurl from "better-opn"
22
import report from "gatsby-cli/lib/reporter"
33
import formatWebpackMessages from "react-dev-utils/formatWebpackMessages"
44
import chalk from "chalk"
5-
import { Compiler } from "webpack"
5+
import webpack, { Compiler } from "webpack"
66
import { isEqual } from "lodash"
77
import { Stage } from "../commands/types"
8+
import semver from "semver"
89

910
import {
1011
reportWebpackWarnings,
@@ -26,6 +27,8 @@ import { enqueueFlush } from "../utils/page-data"
2627
import mapTemplatesToStaticQueryHashes from "../utils/map-templates-to-static-query-hashes"
2728
import { emitter } from "../redux"
2829

30+
const webpackMajor = semver.major(webpack.version)
31+
2932
export async function startWebpackServer({
3033
program,
3134
app,
@@ -89,7 +92,16 @@ export async function startWebpackServer({
8992
// We have switched off the default Webpack output in WebpackDevServer
9093
// options so we are going to "massage" the warnings and errors and present
9194
// them in a readable focused way.
92-
const messages = formatWebpackMessages(stats.toJson({}, true))
95+
const jsonStats = stats.toJson({})
96+
let errors = jsonStats.errors
97+
let warnings = jsonStats.warnings
98+
99+
if (webpackMajor >= 5) {
100+
errors = jsonStats.errors.map(error => error.message)
101+
warnings = jsonStats.warnings.map(warning => warning.message)
102+
}
103+
104+
const messages = formatWebpackMessages({ errors, warnings })
93105
const urls = prepareUrls(
94106
program.https ? `https` : `http`,
95107
program.host,
@@ -141,7 +153,6 @@ export async function startWebpackServer({
141153
state,
142154
stats.compilation
143155
)
144-
145156
mapOfTemplatesToStaticQueryHashes.forEach(
146157
(staticQueryHashes, componentPath) => {
147158
if (
@@ -167,7 +178,6 @@ export async function startWebpackServer({
167178
}
168179
}
169180
)
170-
171181
enqueueFlush()
172182
}
173183

packages/gatsby/src/utils/map-templates-to-static-query-hashes.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@ import { uniqBy, List } from "lodash"
22
import path from "path"
33
import { slash } from "gatsby-core-utils"
44
import { IGatsbyState } from "../redux/types"
5-
import { Stats } from "webpack"
5+
import webpack, { Stats, Compilation, NormalModule } from "webpack"
6+
import semver from "semver"
67

7-
interface ICompilation {
8-
modules: Array<IModule>
9-
}
10-
11-
interface IReason extends Omit<Stats.Reason, "module"> {
12-
module: IModule
13-
}
14-
15-
interface IModule extends Omit<Stats.FnModules, "identifier" | "reasons"> {
16-
hasReasons: () => boolean
17-
resource?: string
18-
identifier: () => string
19-
reasons: Array<IReason>
20-
}
8+
const webpackMajor = semver.major(webpack.version)
219

2210
/* When we traverse upwards, we need to know where to stop. We'll call these terminal nodes.
2311
* `async-requires.js` is the entry point for every page, while `api-runner-browser-plugins.js`
@@ -45,8 +33,11 @@ const entryNodes = [
4533
*/
4634
export default function mapTemplatesToStaticQueryHashes(
4735
reduxState: IGatsbyState,
48-
compilation: ICompilation
36+
compilation: Compilation
4937
): Map<string, Array<number>> {
38+
if (webpackMajor >= 5) {
39+
return new Map()
40+
}
5041
/* The `staticQueryComponents` slice of state is useful because
5142
* it is a pre extracted collection of all static queries found in a Gatsby site.
5243
* This lets us traverse upwards from those to templates that
@@ -69,15 +60,15 @@ export default function mapTemplatesToStaticQueryHashes(
6960
* a Set of strings, each an absolute path of a dependent
7061
* of this module
7162
*/
72-
function getDeps(mod: IModule): Set<string> {
63+
function getDeps(mod: NormalModule): Set<string> {
7364
const staticQueryModuleComponentPath = mod.resource
7465
const result = new Set<string>()
7566
const seen = new Set<string>(
7667
staticQueryModuleComponentPath ? [staticQueryModuleComponentPath] : []
7768
)
7869

7970
// This is the body of the recursively called function
80-
function getDepsRec(m: IModule, seen: Set<string>): Set<string> {
71+
function getDepsRec(m: NormalModule, seen: Set<string>): Set<string> {
8172
// Reasons in webpack are literally reasons of why this module was included in the tree
8273
const hasReasons = m.hasReasons()
8374

@@ -93,7 +84,7 @@ export default function mapTemplatesToStaticQueryHashes(
9384

9485
// These are non terminal dependents and hence modules that need
9586
// further upward traversal
96-
const nonTerminalDependents: List<IModule> = m.reasons
87+
const nonTerminalDependents: List<NormalModule> = m.reasons
9788
.filter(r => {
9889
const dependentModule = r.module
9990
const isTerminal = entryNodes.some(entryNode =>
@@ -136,8 +127,8 @@ export default function mapTemplatesToStaticQueryHashes(
136127
// componentPaths are slashed by gatsby-core-utils we undo it
137128
const nonSlashedPath = path.resolve(componentPath)
138129

139-
const staticQueryComponentModule = modules.find(
140-
m => m.resource === nonSlashedPath
130+
const staticQueryComponentModule: NormalModule = Array.from(modules).find(
131+
m => (m as NormalModule)?.resource === nonSlashedPath
141132
)
142133
const dependants = staticQueryComponentModule
143134
? getDeps(staticQueryComponentModule)
@@ -208,6 +199,6 @@ function mapComponentsToStaticQueryHashes(
208199
return map
209200
}
210201

211-
function isGatsbyBrowser(m: IModule): boolean {
202+
function isGatsbyBrowser(m: NormalModule): boolean {
212203
return !!m?.resource?.includes(`gatsby-browser.js`)
213204
}

packages/gatsby/src/utils/start-server.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import webpackHotMiddleware from "webpack-hot-middleware"
2-
import webpackDevMiddleware, {
3-
WebpackDevMiddleware,
4-
} from "webpack-dev-middleware"
2+
import webpackDevMiddleware from "webpack-dev-middleware"
53
import got from "got"
64
import webpack from "webpack"
75
import express from "express"
@@ -68,15 +66,6 @@ export interface IWebpackWatchingPauseResume extends webpack.Watching {
6866
resume: () => void
6967
}
7068

71-
// context seems to be public, but not documented API
72-
// see https://github.com/webpack/webpack-dev-middleware/issues/656
73-
type PatchedWebpackDevMiddleware = WebpackDevMiddleware &
74-
express.RequestHandler & {
75-
context: {
76-
watching: IWebpackWatchingPauseResume
77-
}
78-
}
79-
8069
export async function startServer(
8170
program: IProgram,
8271
app: Express,
@@ -340,13 +329,11 @@ module.exports = {
340329
// We serve by default an empty index.html that sets up the dev environment.
341330
app.use(developStatic(`public`, { index: false }))
342331

343-
const webpackDevMiddlewareInstance = (webpackDevMiddleware(compiler, {
344-
logLevel: `silent`,
332+
const webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, {
345333
publicPath: devConfig.output.publicPath,
346-
watchOptions: devConfig.devServer ? devConfig.devServer.watchOptions : null,
347334
stats: `errors-only`,
348335
serverSideRender: true,
349-
}) as unknown) as PatchedWebpackDevMiddleware
336+
})
350337

351338
app.use(webpackDevMiddlewareInstance)
352339

packages/gatsby/src/utils/webpack-error-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import reporter from "gatsby-cli/lib/reporter"
2-
import { Stats } from "webpack"
2+
import { Stats, WebpackError } from "webpack"
33
import { IMatch } from "../types"
44
import { Stage as StageEnum } from "../commands/types"
55

@@ -100,7 +100,7 @@ const transformWebpackError = (
100100

101101
export const structureWebpackErrors = (
102102
stage: StageEnum,
103-
webpackError: any
103+
webpackError: WebpackError
104104
): Array<ITransformedWebpackError> | ITransformedWebpackError => {
105105
if (Array.isArray(webpackError)) {
106106
return webpackError.map(e => transformWebpackError(stage, e))

0 commit comments

Comments
 (0)