Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): migrate webpack reducer to TS #23566

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.30",
"@types/node-fetch": "^2.5.5",
"@types/react": "^16.9.31",
"@types/semver": "^7.1.0",
"@types/signal-exit": "^3.0.0",
"@types/react": "^16.9.31",
"@types/stack-trace": "^0.0.29",
"@types/webpack": "^4.41.7",
"@types/webpack-merge": "^4.1.5",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"babel-eslint": "^10.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const lokiNodes = require(`../../db/loki/nodes`).reducer
import { redirectsReducer } from "./redirects"
import { staticQueryComponentsReducer } from "./static-query-components"
import { statusReducer } from "./status"
import { webpackReducer } from "./webpack"
import { webpackCompilationHashReducer } from "./webpack-compilation-hash"
import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer"

Expand Down Expand Up @@ -62,7 +63,7 @@ module.exports = {
staticQueryComponents: staticQueryComponentsReducer,
jobs: require(`./jobs`),
jobsV2: require(`./jobsv2`),
webpack: require(`./webpack`),
webpack: webpackReducer,
webpackCompilationHash: webpackCompilationHashReducer,
redirects: redirectsReducer,
babelrc: require(`./babelrc`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const merge = require(`webpack-merge`)
import merge from "webpack-merge"
import { ActionsUnion, IGatsbyState } from "../types"

module.exports = (state = {}, action) => {
export const webpackReducer = (
state: IGatsbyState["webpack"] = {},
action: ActionsUnion
): IGatsbyState["webpack"] => {
switch (action.type) {
case `SET_WEBPACK_CONFIG`: {
let nextConfig = action.payload
const nextConfig = action.payload
delete nextConfig.entry
delete nextConfig.output
delete nextConfig.target
Expand Down
12 changes: 12 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ export type ActionsUnion =
| IRemoveStaticQuery
| IReplaceComponentQueryAction
| IReplaceStaticQueryAction
| IReplaceWebpackConfigAction
| ISetPluginStatusAction
| ISetProgramStatusAction
| ISetWebpackCompilationHashAction
| ISetWebpackConfigAction
| IUpdatePluginsHashAction

export interface ICreatePageDependencyAction {
Expand Down Expand Up @@ -399,3 +401,13 @@ export interface ISetPluginStatusAction {
[key: string]: any
}
}

export interface IReplaceWebpackConfigAction {
type: `REPLACE_WEBPACK_CONFIG`
payload: IGatsbyState["webpack"]
}

export interface ISetWebpackConfigAction {
type: `SET_WEBPACK_CONFIG`
payload: Partial<IGatsbyState["webpack"]>
}
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,13 @@
"@types/unist" "*"
"@types/vfile-message" "*"

"@types/webpack-merge@^4.1.5":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/webpack-merge/-/webpack-merge-4.1.5.tgz#265fbee4810474860d0f4c17e0107032881eed47"
integrity sha512-cbDo592ljSHeaVe5Q39JKN6Z4vMhmo4+C3JbksOIg+kjhKQYN2keGN7dvr/i18+dughij98Qrsfn1mU9NgVoCA==
dependencies:
"@types/webpack" "*"

"@types/webpack-sources@*":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-0.1.5.tgz#be47c10f783d3d6efe1471ff7f042611bd464a92"
Expand All @@ -4082,6 +4089,18 @@
"@types/source-list-map" "*"
source-map "^0.6.1"

"@types/webpack@*":
version "4.41.12"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.12.tgz#0386ee2a2814368e2f2397abb036c0bf173ff6c3"
integrity sha512-BpCtM4NnBen6W+KEhrL9jKuZCXVtiH6+0b6cxdvNt2EwU949Al334PjQSl2BeAyvAX9mgoNNG21wvjP3xZJJ5w==
dependencies:
"@types/anymatch" "*"
"@types/node" "*"
"@types/tapable" "*"
"@types/uglify-js" "*"
"@types/webpack-sources" "*"
source-map "^0.6.0"

"@types/webpack@^4.41.7":
version "4.41.7"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.7.tgz#22be27dbd4362b01c3954ca9b021dbc9328d9511"
Expand Down