diff --git a/packages/gatsby/src/redux/__tests__/nodes.ts b/packages/gatsby/src/redux/__tests__/nodes.ts index 15dae90525300..4943b82130407 100644 --- a/packages/gatsby/src/redux/__tests__/nodes.ts +++ b/packages/gatsby/src/redux/__tests__/nodes.ts @@ -1,5 +1,5 @@ import { actions } from "../actions" -import { nodeReducer } from "../reducers/nodes" +import { nodesReducer } from "../reducers/nodes" import { IGatsbyNode } from "../types" import { nodesTouchedReducer } from "../reducers/nodes-touched" @@ -43,7 +43,7 @@ describe(`Create and update nodes`, (): void => { expect(action).toMatchSnapshot({ payload: { internal: { counter: expect.any(Number) } }, }) - expect(fromMapToObject(nodeReducer(undefined, action))).toMatchSnapshot({ + expect(fromMapToObject(nodesReducer(undefined, action))).toMatchSnapshot({ hi: { internal: { counter: expect.any(Number) } }, }) }) @@ -98,8 +98,8 @@ describe(`Create and update nodes`, (): void => { )(dispatch) const updateAction = dispatch.mock.calls[1][0] - let state = nodeReducer(undefined, action) - state = nodeReducer(state, updateAction) + let state = nodesReducer(undefined, action) + state = nodesReducer(state, updateAction) expect(state.get(`hi`)!.pickle).toEqual(false) expect((state.get(`hi`)!.deep as any).array![0]).toEqual(1) @@ -148,7 +148,7 @@ describe(`Create and update nodes`, (): void => { } )(dispatch) const action = dispatch.mock.calls[0][0] - let state = nodeReducer(undefined, action) + let state = nodesReducer(undefined, action) const addFieldAction = actions.createNodeField( { @@ -161,7 +161,7 @@ describe(`Create and update nodes`, (): void => { } ) - state = nodeReducer(state, addFieldAction) + state = nodesReducer(state, addFieldAction) expect(fromMapToObject(state)).toMatchSnapshot({ hi: { internal: { counter: expect.any(Number) } }, }) @@ -184,7 +184,7 @@ describe(`Create and update nodes`, (): void => { } )(dispatch) const action = dispatch.mock.calls[0][0] - let state = nodeReducer(undefined, action) + let state = nodesReducer(undefined, action) const addFieldAction = actions.createNodeField( { @@ -196,7 +196,7 @@ describe(`Create and update nodes`, (): void => { name: `test`, } ) - state = nodeReducer(state, addFieldAction) + state = nodesReducer(state, addFieldAction) function callActionCreator(): void { actions.createNodeField( diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.ts index 92d52dfc27b10..c64dec02b3593 100644 --- a/packages/gatsby/src/redux/index.ts +++ b/packages/gatsby/src/redux/index.ts @@ -9,7 +9,7 @@ import _ from "lodash" import { mett } from "../utils/mett" import thunk from "redux-thunk" -import reducers from "./reducers" +import * as reducers from "./reducers" import { writeToCache, readFromCache } from "./persist" import { IGatsbyState, ActionsUnion } from "./types" diff --git a/packages/gatsby/src/redux/reducers/config.ts b/packages/gatsby/src/redux/reducers/config.ts index 10e7c9557b9a3..24f0d595d3277 100644 --- a/packages/gatsby/src/redux/reducers/config.ts +++ b/packages/gatsby/src/redux/reducers/config.ts @@ -1,6 +1,6 @@ import { IGatsbyConfig, ISetSiteConfig } from "../types" -module.exports = ( +export const configReducer = ( state: IGatsbyConfig = {}, action: ISetSiteConfig ): IGatsbyConfig => { diff --git a/packages/gatsby/src/redux/reducers/index.js b/packages/gatsby/src/redux/reducers/index.js deleted file mode 100644 index 7d07cff421e36..0000000000000 --- a/packages/gatsby/src/redux/reducers/index.js +++ /dev/null @@ -1,54 +0,0 @@ -import { nodeReducer } from "./nodes" -import { nodesByTypeReducer } from "./nodes-by-type" -import { pagesReducer } from "./pages" -import { redirectsReducer } from "./redirects" -import { schemaReducer } from "./schema" -import { staticQueryComponentsReducer } from "./static-query-components" -import { statusReducer } from "./status" -import { webpackReducer } from "./webpack" -import { pageDataReducer } from "./page-data" -import { themesReducer } from "./themes" -import { webpackCompilationHashReducer } from "./webpack-compilation-hash" -import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer" -import { lastAction } from "./last-action" -import { jobsV2Reducer } from "./jobsv2" -import { flattenedPluginsReducer } from "./flattened-plugins" -import { resolvedNodesCacheReducer } from "./resolved-nodes" -import { pageDataStatsReducer } from "./page-data-stats" -import { componentsReducer } from "./components" -import { componentDataDependenciesReducer } from "./component-data-dependencies" -import { nodesTouchedReducer } from "./nodes-touched" -import { babelrcReducer } from "./babelrc" -import { jobsReducer } from "./jobs" - -/** - * @property exports.nodesTouched Set - */ -module.exports = { - program: require(`./program`), - nodes: nodeReducer, - nodesByType: nodesByTypeReducer, - resolvedNodesCache: resolvedNodesCacheReducer, - nodesTouched: nodesTouchedReducer, - lastAction: lastAction, - flattenedPlugins: flattenedPluginsReducer, - config: require(`./config`), - schema: schemaReducer, - pages: pagesReducer, - status: statusReducer, - componentDataDependencies: componentDataDependenciesReducer, - components: componentsReducer, - staticQueryComponents: staticQueryComponentsReducer, - jobs: jobsReducer, - jobsV2: jobsV2Reducer, - webpack: webpackReducer, - webpackCompilationHash: webpackCompilationHashReducer, - redirects: redirectsReducer, - babelrc: babelrcReducer, - schemaCustomization: require(`./schema-customization`), - themes: themesReducer, - logs: logReducer, - inferenceMetadata: require(`./inference-metadata`), - pageDataStats: pageDataStatsReducer, - pageData: pageDataReducer, -} diff --git a/packages/gatsby/src/redux/reducers/index.ts b/packages/gatsby/src/redux/reducers/index.ts new file mode 100644 index 0000000000000..af293f8397f92 --- /dev/null +++ b/packages/gatsby/src/redux/reducers/index.ts @@ -0,0 +1,58 @@ +import { nodesReducer } from "./nodes" +import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer" +import { pagesReducer } from "./pages" +import { redirectsReducer } from "./redirects" +import { schemaReducer } from "./schema" +import { staticQueryComponentsReducer } from "./static-query-components" +import { statusReducer } from "./status" +import { webpackReducer } from "./webpack" +import { pageDataReducer } from "./page-data" +import { themesReducer } from "./themes" +import { webpackCompilationHashReducer } from "./webpack-compilation-hash" +import { configReducer } from "./config" +import { lastActionReducer } from "./last-action" +import { jobsV2Reducer } from "./jobsv2" +import { pageDataStatsReducer } from "./page-data-stats" +import { componentsReducer } from "./components" +import { componentDataDependenciesReducer } from "./component-data-dependencies" +import { babelrcReducer } from "./babelrc" +import { jobsReducer } from "./jobs" +import { nodesByTypeReducer } from "./nodes-by-type" +import programReducer from "./program" +import { resolvedNodesCacheReducer } from "./resolved-nodes" +import { nodesTouchedReducer } from "./nodes-touched" +import { flattenedPluginsReducer } from "./flattened-plugins" +import schemaCustomizationReducer from "./schema-customization" +import inferenceMetadataReducer from "./inference-metadata" + +/** + * @property exports.nodesTouched Set + */ +export { + programReducer as program, + nodesReducer as nodes, + nodesByTypeReducer as nodesByType, + resolvedNodesCacheReducer as resolvedNodesCache, + nodesTouchedReducer as nodesTouched, + lastActionReducer as lastAction, + flattenedPluginsReducer as flattenedPlugins, + configReducer as config, + schemaReducer as schema, + pagesReducer as pages, + statusReducer as status, + componentDataDependenciesReducer as componentDataDependencies, + componentsReducer as components, + staticQueryComponentsReducer as staticQueryComponents, + jobsReducer as jobs, + jobsV2Reducer as jobsV2, + webpackReducer as webpack, + webpackCompilationHashReducer as webpackCompilationHash, + redirectsReducer as redirects, + babelrcReducer as babelrc, + schemaCustomizationReducer as schemaCustomization, + themesReducer as themes, + logReducer as logs, + inferenceMetadataReducer as inferenceMetadata, + pageDataStatsReducer as pageDataStats, + pageDataReducer as pageData, +} diff --git a/packages/gatsby/src/redux/reducers/last-action.ts b/packages/gatsby/src/redux/reducers/last-action.ts index 1b3b11c756cf0..87ac11ced3775 100644 --- a/packages/gatsby/src/redux/reducers/last-action.ts +++ b/packages/gatsby/src/redux/reducers/last-action.ts @@ -1,6 +1,6 @@ import { IGatsbyState, ActionsUnion } from "../types" -export const lastAction = ( - _state: IGatsbyState["lastAction"], +export const lastActionReducer = ( + _state: unknown, action: ActionsUnion ): IGatsbyState["lastAction"] => action diff --git a/packages/gatsby/src/redux/reducers/nodes.ts b/packages/gatsby/src/redux/reducers/nodes.ts index d9ee830706a12..c1b13cf71c1a0 100644 --- a/packages/gatsby/src/redux/reducers/nodes.ts +++ b/packages/gatsby/src/redux/reducers/nodes.ts @@ -1,6 +1,6 @@ import { ActionsUnion, IGatsbyState } from "../types" -export const nodeReducer = ( +export const nodesReducer = ( state: IGatsbyState["nodes"] = new Map(), action: ActionsUnion ): IGatsbyState["nodes"] => {