From f2f30d46bb6d4e898098a9c528042b7d0aed7df1 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Tue, 7 Jan 2020 15:11:49 -0600 Subject: [PATCH 01/13] chore(gatsby): Begin typing the redux code --- package.json | 1 + .../actions/{internal.js => internal.ts} | 76 ++++++++----- .../gatsby/src/redux/{index.js => index.ts} | 40 ++++--- packages/gatsby/src/redux/persist.js | 11 -- packages/gatsby/src/redux/persist.ts | 11 ++ packages/gatsby/src/redux/types.ts | 107 ++++++++++++++++++ yarn.lock | 7 ++ 7 files changed, 192 insertions(+), 61 deletions(-) rename packages/gatsby/src/redux/actions/{internal.js => internal.ts} (69%) rename packages/gatsby/src/redux/{index.js => index.ts} (66%) delete mode 100644 packages/gatsby/src/redux/persist.js create mode 100644 packages/gatsby/src/redux/persist.ts create mode 100644 packages/gatsby/src/redux/types.ts diff --git a/package.json b/package.json index 257e58bfc7120..6b335bed33622 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@babel/runtime": "^7.7.7", "@lerna/prompt": "3.18.5", "@types/express": "^4.17.2", + "@types/fs-extra": "^8.0.1", "@types/got": "^9.6.9", "@types/jest": "^24.0.23", "@types/node": "^12.12.11", diff --git a/packages/gatsby/src/redux/actions/internal.js b/packages/gatsby/src/redux/actions/internal.ts similarity index 69% rename from packages/gatsby/src/redux/actions/internal.js rename to packages/gatsby/src/redux/actions/internal.ts index e685b992993c4..6fc62d3ad5941 100644 --- a/packages/gatsby/src/redux/actions/internal.js +++ b/packages/gatsby/src/redux/actions/internal.ts @@ -1,7 +1,18 @@ -// @flow -import type { Plugin } from "./types" +import { + ProgramStatus, + ICreatePageDependencyAction, + IDeleteComponentDependenciesAction, + IReplaceComponentQueryAction, + IReplaceStaticQueryAction, + IQueryExtractedAction, + IQueryExtractionGraphQLErrorAction, + IQueryExtractedBabelSuccessAction, + IQueryExtractionBabelErrorAction, + ISetProgramStatusAction, + IPageQueryRunAction, +} from "../types" -const actions = {} +// import type { Plugin } from "./types" /** * Create a dependency between a page and data. Probably for @@ -12,14 +23,14 @@ const actions = {} * @param {string} $0.connection A connection type * @private */ -actions.createPageDependency = ( +export const createPageDependency = ( { path, nodeId, connection, - }: { path: string, nodeId: string, connection: string }, - plugin: string = `` -) => { + }: { path: string; nodeId: string; connection: string }, + plugin = `` +): ICreatePageDependencyAction => { return { type: `CREATE_COMPONENT_DEPENDENCY`, plugin, @@ -37,7 +48,9 @@ actions.createPageDependency = ( * @param {Array} paths the paths to delete. * @private */ -actions.deleteComponentsDependencies = (paths: string[]) => { +export const deleteComponentsDependencies = ( + paths: string[] +): IDeleteComponentDependenciesAction => { return { type: `DELETE_COMPONENTS_DEPENDENCIES`, payload: { @@ -51,13 +64,13 @@ actions.deleteComponentsDependencies = (paths: string[]) => { * this to store the query with its component. * @private */ -actions.replaceComponentQuery = ({ +export const replaceComponentQuery = ({ query, componentPath, }: { - query: string, - componentPath: string, -}) => { + query: string + componentPath: string +}): IReplaceComponentQueryAction => { return { type: `REPLACE_COMPONENT_QUERY`, payload: { @@ -72,7 +85,10 @@ actions.replaceComponentQuery = ({ * components, it calls this to store the query with its component. * @private */ -actions.replaceStaticQuery = (args: any, plugin?: ?Plugin = null) => { +export const replaceStaticQuery = ( + args: any, + plugin: Plugin | null | undefined = null +): IReplaceStaticQueryAction => { return { type: `REPLACE_STATIC_QUERY`, plugin, @@ -91,11 +107,11 @@ actions.replaceStaticQuery = (args: any, plugin?: ?Plugin = null) => { * @param {query} $0.query The GraphQL query that was extracted from the component. * @private */ -actions.queryExtracted = ( - { componentPath, query }, +export const queryExtracted = ( + { componentPath, query }: { componentPath: string; query: string }, plugin: Plugin, traceId?: string -) => { +): IQueryExtractedAction => { return { type: `QUERY_EXTRACTED`, plugin, @@ -114,11 +130,11 @@ actions.queryExtracted = ( * @param {error} $0.error The GraphQL query that was extracted from the component. * @private */ -actions.queryExtractionGraphQLError = ( - { componentPath, error }, +export const queryExtractionGraphQLError = ( + { componentPath, error }: { componentPath: string; error: string }, plugin: Plugin, traceId?: string -) => { +): IQueryExtractionGraphQLErrorAction => { return { type: `QUERY_EXTRACTION_GRAPHQL_ERROR`, plugin, @@ -137,11 +153,11 @@ actions.queryExtractionGraphQLError = ( * its query read. * @private */ -actions.queryExtractedBabelSuccess = ( +export const queryExtractedBabelSuccess = ( { componentPath }, plugin: Plugin, traceId?: string -) => { +): IQueryExtractedBabelSuccessAction => { return { type: `QUERY_EXTRACTION_BABEL_SUCCESS`, plugin, @@ -160,11 +176,11 @@ actions.queryExtractedBabelSuccess = ( * @param {error} $0.error The Babel error object * @private */ -actions.queryExtractionBabelError = ( - { componentPath, error }, +export const queryExtractionBabelError = ( + { componentPath, error }: { componentPath: string; error: Error }, plugin: Plugin, traceId?: string -) => { +): IQueryExtractionBabelErrorAction => { return { type: `QUERY_EXTRACTION_BABEL_ERROR`, plugin, @@ -179,7 +195,11 @@ actions.queryExtractionBabelError = ( * @param {string} Program status * @private */ -actions.setProgramStatus = (status, plugin: Plugin, traceId?: string) => { +export const setProgramStatus = ( + status: ProgramStatus, + plugin: Plugin, + traceId?: string +): ISetProgramStatusAction => { return { type: `SET_PROGRAM_STATUS`, plugin, @@ -194,11 +214,11 @@ actions.setProgramStatus = (status, plugin: Plugin, traceId?: string) => { * @param {string} Path to the page component that changed. * @private */ -actions.pageQueryRun = ( +export const pageQueryRun = ( { path, componentPath, isPage }, plugin: Plugin, traceId?: string -) => { +): IPageQueryRunAction => { return { type: `PAGE_QUERY_RUN`, plugin, @@ -206,5 +226,3 @@ actions.pageQueryRun = ( payload: { path, componentPath, isPage }, } } - -module.exports = { actions } diff --git a/packages/gatsby/src/redux/index.js b/packages/gatsby/src/redux/index.ts similarity index 66% rename from packages/gatsby/src/redux/index.js rename to packages/gatsby/src/redux/index.ts index 058741c40cff4..70507d2dc979a 100644 --- a/packages/gatsby/src/redux/index.js +++ b/packages/gatsby/src/redux/index.ts @@ -1,16 +1,17 @@ -const Redux = require(`redux`) -const _ = require(`lodash`) +import Redux from "redux" +import _ from "lodash" -const mitt = require(`mitt`) -const thunk = require(`redux-thunk`).default -const reducers = require(`./reducers`) -const { writeToCache, readFromCache } = require(`./persist`) +import mitt from "mitt" +import thunk from "redux-thunk" +import reducers from "./reducers" +import { writeToCache, readFromCache } from "./persist" +import { IReduxState, ActionsUnion } from "./types" // Create event emitter for actions -const emitter = mitt() +export const emitter = mitt() // Read old node data from cache. -const readState = () => { +export const readState = (): IReduxState => { try { const state = readFromCache() if (state.nodes) { @@ -32,26 +33,31 @@ const readState = () => { } catch (e) { // ignore errors. } - return {} + // I feel like this could lead to bugs? + return {} as IReduxState } /** * Redux middleware handling array of actions */ -const multi = ({ dispatch }) => next => action => +const multi: Redux.Middleware = ({ dispatch }) => next => ( + action: ActionsUnion +): ActionsUnion | ActionsUnion[] => Array.isArray(action) ? action.filter(Boolean).map(dispatch) : next(action) -const configureStore = initialState => +export const configureStore = ( + initialState: IReduxState +): Redux.Store => Redux.createStore( Redux.combineReducers({ ...reducers }), initialState, Redux.applyMiddleware(thunk, multi) ) -const store = configureStore(readState()) +export const store = configureStore(readState()) // Persist state. -const saveState = () => { +export const saveState = (): Promise => { const state = store.getState() const pickedState = _.pick(state, [ `nodes`, @@ -70,11 +76,3 @@ store.subscribe(() => { const lastAction = store.getState().lastAction emitter.emit(lastAction.type, lastAction) }) - -module.exports = { - emitter, - store, - configureStore, - readState, - saveState, -} diff --git a/packages/gatsby/src/redux/persist.js b/packages/gatsby/src/redux/persist.js deleted file mode 100644 index 088c7d9f32add..0000000000000 --- a/packages/gatsby/src/redux/persist.js +++ /dev/null @@ -1,11 +0,0 @@ -const v8 = require(`v8`) -const fs = require(`fs-extra`) - -const file = () => `${process.cwd()}/.cache/redux.state` - -const readFromCache = () => v8.deserialize(fs.readFileSync(file())) - -const writeToCache = contents => - fs.writeFileSync(file(), v8.serialize(contents)) - -module.exports = { readFromCache, writeToCache } diff --git a/packages/gatsby/src/redux/persist.ts b/packages/gatsby/src/redux/persist.ts new file mode 100644 index 0000000000000..4a94188a63171 --- /dev/null +++ b/packages/gatsby/src/redux/persist.ts @@ -0,0 +1,11 @@ +import v8 from "v8" +import fs from "fs-extra" +import { IReduxState } from "./types" + +const file = (): string => `${process.cwd()}/.cache/redux.state` + +export const readFromCache = (): IReduxState => + v8.deserialize(fs.readFileSync(file())) + +export const writeToCache = (contents: IReduxState): Promise => + fs.writeFile(file(), v8.serialize(contents)) diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts new file mode 100644 index 0000000000000..347aded1be7c4 --- /dev/null +++ b/packages/gatsby/src/redux/types.ts @@ -0,0 +1,107 @@ +export interface IReduxState { + nodes?: any // TODO + nodesByType: Map // TODO + lastAction: ActionsUnion + jobs: { + active: Array // TODO + } + schema: any + schemaCustomization: any + config: { + developMiddleware: any + proxy: any + } +} + +export enum ProgramStatus { + BOOTSTRAP_FINISHED = `BOOTSTRAP_FINISHED`, + BOOTSTRAP_QUERY_RUNNING_FINISHED = `BOOTSTRAP_QUERY_RUNNING_FINISHED`, +} + +export type ActionsUnion = + | ICreatePageDependencyAction + | IDeleteComponentDependenciesAction + | IReplaceComponentQueryAction + | IReplaceStaticQueryAction + | IQueryExtractedAction + | IQueryExtractionGraphQLErrorAction + | IQueryExtractedBabelSuccessAction + | IQueryExtractionBabelErrorAction + | ISetProgramStatusAction + | IPageQueryRunAction + +export interface ICreatePageDependencyAction { + type: `CREATE_COMPONENT_DEPENDENCY` + plugin: string + payload: { + path: string + nodeId: string + connection: string + } +} + +export interface IDeleteComponentDependenciesAction { + type: "DELETE_COMPONENTS_DEPENDENCIES" + payload: { + paths: string[] + } +} + +export interface IReplaceComponentQueryAction { + type: "REPLACE_COMPONENT_QUERY" + payload: { + query: string + componentPath: string + } +} + +export interface IReplaceStaticQueryAction { + type: `REPLACE_STATIC_QUERY` + plugin: Plugin | null | undefined + payload: any // TODO +} + +export interface IQueryExtractedAction { + type: `QUERY_EXTRACTED` + plugin: Plugin + traceId: string | undefined + payload: { componentPath: string; query: string } +} + +export interface IQueryExtractionGraphQLErrorAction { + type: `QUERY_EXTRACTION_GRAPHQL_ERROR` + plugin: Plugin + traceId: string | undefined + payload: { componentPath: string; error: string } +} + +export interface IQueryExtractedBabelSuccessAction { + type: `QUERY_EXTRACTION_BABEL_SUCCESS` + plugin: Plugin + traceId: string | undefined + payload: { componentPath: string } +} + +export interface IQueryExtractionBabelErrorAction { + type: `QUERY_EXTRACTION_BABEL_ERROR` + plugin: Plugin + traceId: string | undefined + payload: { + componentPath: string + error: Error + } +} + +export interface ISetProgramStatusAction { + type: `SET_PROGRAM_STATUS` + plugin: Plugin + traceId: string | undefined + payload: ProgramStatus // TODO: Make this an enum +} + +export interface IPageQueryRunAction { + type: `PAGE_QUERY_RUN` + plugin: Plugin + traceId: string | undefined + payload: { path: string; componentPath: string; isPage: boolean } +} diff --git a/yarn.lock b/yarn.lock index 3fc6ca013a9ee..c53ac6c96ef1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3839,6 +3839,13 @@ "@types/express-serve-static-core" "*" "@types/serve-static" "*" +"@types/fs-extra@^8.0.1": + version "8.0.1" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.0.1.tgz#a2378d6e7e8afea1564e44aafa2e207dadf77686" + integrity sha512-J00cVDALmi/hJOYsunyT52Hva5TnJeKP5yd1r+mH/ZU0mbYZflR0Z5kw5kITtKTRYMhm1JMClOFYdHnQszEvqw== + dependencies: + "@types/node" "*" + "@types/get-port@^0.0.4": version "0.0.4" resolved "https://registry.yarnpkg.com/@types/get-port/-/get-port-0.0.4.tgz#eb6bb7423d9f888b632660dc7d2fd3e69a35643e" From 0df8de66d14f88c1a520de644197fe0f0bfdfe1d Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 12:28:58 -0600 Subject: [PATCH 02/13] fix tests --- packages/gatsby/src/redux/index.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.ts index 70507d2dc979a..3c9a39de9ee99 100644 --- a/packages/gatsby/src/redux/index.ts +++ b/packages/gatsby/src/redux/index.ts @@ -1,4 +1,10 @@ -import Redux from "redux" +import { + applyMiddleware, + combineReducers, + createStore, + Store, + Middleware, +} from "redux" import _ from "lodash" import mitt from "mitt" @@ -33,25 +39,24 @@ export const readState = (): IReduxState => { } catch (e) { // ignore errors. } - // I feel like this could lead to bugs? + // BUG: Would this not cause downstream bugs? seems likely. Why wouldn't we just + // throw and kill the program? return {} as IReduxState } /** * Redux middleware handling array of actions */ -const multi: Redux.Middleware = ({ dispatch }) => next => ( +const multi: Middleware = ({ dispatch }) => next => ( action: ActionsUnion ): ActionsUnion | ActionsUnion[] => Array.isArray(action) ? action.filter(Boolean).map(dispatch) : next(action) -export const configureStore = ( - initialState: IReduxState -): Redux.Store => - Redux.createStore( - Redux.combineReducers({ ...reducers }), +export const configureStore = (initialState: IReduxState): Store => + createStore( + combineReducers({ ...reducers }), initialState, - Redux.applyMiddleware(thunk, multi) + applyMiddleware(thunk, multi) ) export const store = configureStore(readState()) From 3604601af41d9d344db64147acd2abb7b70ac76a Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 13:03:10 -0600 Subject: [PATCH 03/13] undo file resets --- packages/gatsby/src/redux/actions/{internal.ts => internal.js} | 0 packages/gatsby/src/redux/{index.ts => index.js} | 0 packages/gatsby/src/redux/{persist.ts => persist.js} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename packages/gatsby/src/redux/actions/{internal.ts => internal.js} (100%) rename packages/gatsby/src/redux/{index.ts => index.js} (100%) rename packages/gatsby/src/redux/{persist.ts => persist.js} (100%) diff --git a/packages/gatsby/src/redux/actions/internal.ts b/packages/gatsby/src/redux/actions/internal.js similarity index 100% rename from packages/gatsby/src/redux/actions/internal.ts rename to packages/gatsby/src/redux/actions/internal.js diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.js similarity index 100% rename from packages/gatsby/src/redux/index.ts rename to packages/gatsby/src/redux/index.js diff --git a/packages/gatsby/src/redux/persist.ts b/packages/gatsby/src/redux/persist.js similarity index 100% rename from packages/gatsby/src/redux/persist.ts rename to packages/gatsby/src/redux/persist.js From 54c716062a28dbce0a8519de00f905c0673aa982 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 13:04:14 -0600 Subject: [PATCH 04/13] move files for git history; --- packages/gatsby/src/redux/actions/{internal.js => internal.ts} | 0 packages/gatsby/src/redux/{index.js => index.ts} | 0 packages/gatsby/src/redux/{persist.js => persist.ts} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename packages/gatsby/src/redux/actions/{internal.js => internal.ts} (100%) rename packages/gatsby/src/redux/{index.js => index.ts} (100%) rename packages/gatsby/src/redux/{persist.js => persist.ts} (100%) diff --git a/packages/gatsby/src/redux/actions/internal.js b/packages/gatsby/src/redux/actions/internal.ts similarity index 100% rename from packages/gatsby/src/redux/actions/internal.js rename to packages/gatsby/src/redux/actions/internal.ts diff --git a/packages/gatsby/src/redux/index.js b/packages/gatsby/src/redux/index.ts similarity index 100% rename from packages/gatsby/src/redux/index.js rename to packages/gatsby/src/redux/index.ts diff --git a/packages/gatsby/src/redux/persist.js b/packages/gatsby/src/redux/persist.ts similarity index 100% rename from packages/gatsby/src/redux/persist.js rename to packages/gatsby/src/redux/persist.ts From 58923c560c75054f8c25dd0f556eb7c2a8bf069c Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 13:05:13 -0600 Subject: [PATCH 05/13] fix a test --- packages/gatsby/src/redux/actions/add-page-dependency.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/redux/actions/add-page-dependency.js b/packages/gatsby/src/redux/actions/add-page-dependency.js index 8d9b23d919f5a..9fc127813a8ec 100644 --- a/packages/gatsby/src/redux/actions/add-page-dependency.js +++ b/packages/gatsby/src/redux/actions/add-page-dependency.js @@ -1,5 +1,5 @@ const { store } = require(`../`) -const { actions } = require(`./internal.js`) +const { actions } = require(`./internal`) function createPageDependency({ path, nodeId, connection }) { const state = store.getState() From 5b964a976f16d7a24defad4bea589eb9fb0b9c21 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 13:47:50 -0600 Subject: [PATCH 06/13] some changes to try to address test failures --- jest-transformer.js | 11 ++++++++++- jest.config.js | 8 ++++++-- package.json | 1 + packages/gatsby/src/redux/actions/index.js | 2 +- packages/gatsby/src/redux/persist.ts | 6 +++--- packages/gatsby/src/redux/types.ts | 12 +++++++++--- yarn.lock | 10 +++++++++- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/jest-transformer.js b/jest-transformer.js index 072aba2e1ecc4..2455ccd07f8e7 100644 --- a/jest-transformer.js +++ b/jest-transformer.js @@ -1,2 +1,11 @@ const babelPreset = require(`babel-preset-gatsby-package`)() -module.exports = require(`babel-jest`).createTransformer(babelPreset) +module.exports = require(`babel-jest`).createTransformer({ + ...babelPreset, + overrides: [ + ...(babelPreset.overrides || []), + { + test: `**/*.ts`, + plugins: [[`@babel/plugin-transform-typescript`, { isTSX: true }]], + }, + ], +}) diff --git a/jest.config.js b/jest.config.js index 9fe0c367c8025..b2ba26eb0ea86 100644 --- a/jest.config.js +++ b/jest.config.js @@ -35,7 +35,7 @@ module.exports = { ], transform: { "^.+\\.js$": `/jest-transformer.js`, - "^.+\\.tsx?$": `/node_modules/ts-jest/preprocessor.js`, + "^.+\\.tsx?$": `/jest-transformer.js`, }, moduleNameMapper: { "^highlight.js$": `/node_modules/highlight.js/lib/index.js`, @@ -52,7 +52,11 @@ module.exports = { }, }, collectCoverageFrom: coverageDirs, - reporters: [`default`].concat(useCoverage ? `jest-junit` : []), + reporters: [ + `default`, + ...(useCoverage ? `jest-junit` : []), + ...(process.env.CI ? [[`jest-silent-reporter`, { useDots: true }]] : []), + ], testEnvironment: `jest-environment-jsdom-fourteen`, moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`], } diff --git a/package.json b/package.json index 6b335bed33622..3185030a9f8dc 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "jest-environment-jsdom-fourteen": "^0.1.0", "jest-junit": "^6.4.0", "jest-serializer-path": "^0.1.15", + "jest-silent-reporter": "^0.1.2", "joi": "^14.3.1", "js-yaml": "^3.13.1", "lerna": "^3.19.0", diff --git a/packages/gatsby/src/redux/actions/index.js b/packages/gatsby/src/redux/actions/index.js index 80a05797e9c7f..7888d6c39dee8 100644 --- a/packages/gatsby/src/redux/actions/index.js +++ b/packages/gatsby/src/redux/actions/index.js @@ -1,7 +1,7 @@ const { bindActionCreators } = require(`redux`) const { store } = require(`..`) -const { actions: internalActions } = require(`./internal`) +const internalActions = require(`./internal`) const { actions: publicActions } = require(`./public`) const { actions: restrictedActions, diff --git a/packages/gatsby/src/redux/persist.ts b/packages/gatsby/src/redux/persist.ts index 4a94188a63171..32b44445b808e 100644 --- a/packages/gatsby/src/redux/persist.ts +++ b/packages/gatsby/src/redux/persist.ts @@ -1,11 +1,11 @@ import v8 from "v8" -import fs from "fs-extra" +import { readFileSync, writeFile } from "fs-extra" import { IReduxState } from "./types" const file = (): string => `${process.cwd()}/.cache/redux.state` export const readFromCache = (): IReduxState => - v8.deserialize(fs.readFileSync(file())) + v8.deserialize(readFileSync(file())) export const writeToCache = (contents: IReduxState): Promise => - fs.writeFile(file(), v8.serialize(contents)) + writeFile(file(), v8.serialize(contents)) diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index 347aded1be7c4..564817fec3ca7 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -1,5 +1,5 @@ export interface IReduxState { - nodes?: any // TODO + nodes?: Map> // TODO: Confirm this is correct. nodesByType: Map // TODO lastAction: ActionsUnion jobs: { @@ -58,7 +58,13 @@ export interface IReplaceComponentQueryAction { export interface IReplaceStaticQueryAction { type: `REPLACE_STATIC_QUERY` plugin: Plugin | null | undefined - payload: any // TODO + payload: { + name: string + componentPath: string + id: string + query: string + hash: string + } } export interface IQueryExtractedAction { @@ -96,7 +102,7 @@ export interface ISetProgramStatusAction { type: `SET_PROGRAM_STATUS` plugin: Plugin traceId: string | undefined - payload: ProgramStatus // TODO: Make this an enum + payload: ProgramStatus } export interface IPageQueryRunAction { diff --git a/yarn.lock b/yarn.lock index c53ac6c96ef1e..0c9952301b4e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13603,6 +13603,14 @@ jest-serializer@^24.9.0: resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-24.9.0.tgz#e6d7d7ef96d31e8b9079a714754c5d5c58288e73" integrity sha512-DxYipDr8OvfrKH3Kel6NdED3OXxjvxXZ1uIY2I9OFbGg+vUkkg7AGvi65qbhbWNPvDckXmzMPbK3u3HaDO49bQ== +jest-silent-reporter@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/jest-silent-reporter/-/jest-silent-reporter-0.1.2.tgz#9d797c0b509e1def16647a07daf25f014c50b333" + integrity sha512-w/qc9NvWqdX0vZv6TUG4EE15d72+JxQJYh+3hqq8cTi3BnfBOtwNtL3T6TwkZSy/sfc3REW5niz0eSBPTIvWnA== + dependencies: + chalk "^2.3.1" + jest-util "^24.0.0" + jest-snapshot@^22.4.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-22.4.3.tgz#b5c9b42846ffb9faccb76b841315ba67887362d2" @@ -13647,7 +13655,7 @@ jest-util@^22.4.1, jest-util@^22.4.3: mkdirp "^0.5.1" source-map "^0.6.0" -jest-util@^24.5.0, jest-util@^24.9.0: +jest-util@^24.0.0, jest-util@^24.5.0, jest-util@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-24.9.0.tgz#7396814e48536d2e85a37de3e4c431d7cb140162" integrity sha512-x+cZU8VRmOJxbA1K5oDBdxQmdq0OIdADarLxk0Mq+3XS4jgvhG/oKGWcIDCtPG0HgjxOYvF+ilPJQsAyXfbNOg== From 6f7f39858223dd88074e023532958cf9c45175ef Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 9 Jan 2020 14:19:24 -0600 Subject: [PATCH 07/13] try to fix this.. --- packages/gatsby/src/redux/actions/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/redux/actions/index.js b/packages/gatsby/src/redux/actions/index.js index 7888d6c39dee8..9c35f0469905b 100644 --- a/packages/gatsby/src/redux/actions/index.js +++ b/packages/gatsby/src/redux/actions/index.js @@ -1,7 +1,7 @@ const { bindActionCreators } = require(`redux`) const { store } = require(`..`) -const internalActions = require(`./internal`) +import * as internalActions from "./internal" const { actions: publicActions } = require(`./public`) const { actions: restrictedActions, From c308d1954d8b67c45a365bc1646a39bdcb7b40c0 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 09:33:07 -0600 Subject: [PATCH 08/13] fix imports for es6 code exports --- packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js | 2 +- packages/gatsby/src/redux/actions/add-page-dependency.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js index 18202c953aea0..c27992919ea14 100644 --- a/packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js @@ -5,7 +5,7 @@ const path = require(`path`) const sitemap = require(`sitemap`) const { onPostBuild } = require(`../gatsby-node`) -const internals = require(`../internals`) +import * as internals from "../internals" const pathPrefix = `` beforeEach(() => { diff --git a/packages/gatsby/src/redux/actions/add-page-dependency.js b/packages/gatsby/src/redux/actions/add-page-dependency.js index 9fc127813a8ec..e86652d4b2dc7 100644 --- a/packages/gatsby/src/redux/actions/add-page-dependency.js +++ b/packages/gatsby/src/redux/actions/add-page-dependency.js @@ -1,5 +1,5 @@ const { store } = require(`../`) -const { actions } = require(`./internal`) +import * as actions from "./internal" function createPageDependency({ path, nodeId, connection }) { const state = store.getState() From 8f2e2504a93a9098f9425dd9a8c345e670dd4b86 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 10:19:33 -0600 Subject: [PATCH 09/13] fix more tests --- jest.config.js | 8 ++-- .../__snapshots__/query-compiler.js.snap | 38 +++++++++---------- packages/gatsby/src/query/query-compiler.js | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/jest.config.js b/jest.config.js index b2ba26eb0ea86..3c67faff7d7ec 100644 --- a/jest.config.js +++ b/jest.config.js @@ -52,11 +52,9 @@ module.exports = { }, }, collectCoverageFrom: coverageDirs, - reporters: [ - `default`, - ...(useCoverage ? `jest-junit` : []), - ...(process.env.CI ? [[`jest-silent-reporter`, { useDots: true }]] : []), - ], + reporters: process.env.CI + ? [`jest-silent-reporter`, { useDots: true }] + : [`default`].concat(useCoverage ? `jest-junit` : []), testEnvironment: `jest-environment-jsdom-fourteen`, moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`], } diff --git a/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap b/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap index 5ebc996d9d692..56147970369ac 100644 --- a/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap +++ b/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap @@ -152,25 +152,25 @@ exports[`actual compiling errors on double root 1`] = ` Array [ Object { "context": Object { - "afterCodeFrame": " 1 | query anotherQueryAndMockFileQuery { - 2 | allPostsJson { - 3 | #... - 4 | } - 5 | allPostsJson { - 6 | #... - 7 | } - 8 | }", - "beforeCodeFrame": " 1 | query mockFileQuery { - 2 | allPostsJson { - 3 | #... - 4 | } - 5 | } - 6 | - 7 | query AnotherQuery { - 8 | allPostsJson { - 9 | #... - 10 | } - 11 | }", + "afterCodeFrame": "  1 | query anotherQueryAndMockFileQuery { +  2 |  allPostsJson { +  3 |  #... +  4 |  } +  5 |  allPostsJson { +  6 |  #... +  7 |  } +  8 | }", + "beforeCodeFrame": "  1 | query mockFileQuery { +  2 |  allPostsJson { +  3 |  #... +  4 |  } +  5 | } +  6 |  +  7 | query AnotherQuery { +  8 |  allPostsJson { +  9 |  #... +  10 |  } +  11 | }", "name": "AnotherQuery", "otherName": "mockFileQuery", }, diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index 78a787787cb14..db53e11a5a743 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -28,7 +28,7 @@ const { const getGatsbyDependents = require(`../utils/gatsby-dependents`) const { store } = require(`../redux`) -const { actions } = require(`../redux/actions/internal`) +import * as actions from "../redux/actions/internal" const { default: FileParser } = require(`./file-parser`) const { graphqlError, From c7d385b0864013156c36f23a6deeba38391247af Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 10:31:57 -0600 Subject: [PATCH 10/13] Fix types and async code --- .circleci/config.yml | 136 +++++++++++++-------------- jest.config.js | 2 +- packages/gatsby/src/redux/index.ts | 2 +- packages/gatsby/src/redux/persist.ts | 7 +- packages/gatsby/src/redux/types.ts | 2 +- 5 files changed, 75 insertions(+), 74 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 474727fef9fe5..815552a879981 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -454,74 +454,74 @@ workflows: build-test: jobs: - windows_unit_tests - - bootstrap - - lint: - requires: - - bootstrap - - unit_tests_node8: - <<: *ignore_docs - requires: - - bootstrap - - unit_tests_node10: - <<: *ignore_docs - requires: - - lint - - unit_tests_node8 - - unit_tests_node12: - <<: *ignore_docs - requires: - - lint - - unit_tests_node8 - - unit_tests_www: - requires: - - lint - - unit_tests_node8 - - integration_tests_long_term_caching: - <<: *e2e-test-workflow - - integration_tests_gatsby_pipeline: - <<: *e2e-test-workflow - - integration_tests_structured_logging: - <<: *e2e-test-workflow - - e2e_tests_path-prefix: - <<: *e2e-test-workflow - - e2e_tests_gatsby-image: - <<: *e2e-test-workflow - - e2e_tests_development_runtime: - <<: *e2e-test-workflow - - e2e_tests_production_runtime: - <<: *e2e-test-workflow - - themes_e2e_tests_production_runtime: - <<: *e2e-test-workflow - - themes_e2e_tests_development_runtime: - <<: *e2e-test-workflow - - starters_validate: - <<: *ignore_master - - starters_publish: - requires: - - bootstrap - filters: - branches: - only: - - master - - manual_www_approval: - type: approval - filters: - branches: - only: - - master - - build_www: - context: build_www - requires: - - manual_www_approval - - deploy_www: - requires: - - build_www - context: build_www - - update_i18n_source: - filters: - branches: - only: - - master + # - bootstrap + # - lint: + # requires: + # - bootstrap + # - unit_tests_node8: + # <<: *ignore_docs + # requires: + # - bootstrap + # - unit_tests_node10: + # <<: *ignore_docs + # requires: + # - lint + # - unit_tests_node8 + # - unit_tests_node12: + # <<: *ignore_docs + # requires: + # - lint + # - unit_tests_node8 + # - unit_tests_www: + # requires: + # - lint + # - unit_tests_node8 + # - integration_tests_long_term_caching: + # <<: *e2e-test-workflow + # - integration_tests_gatsby_pipeline: + # <<: *e2e-test-workflow + # - integration_tests_structured_logging: + # <<: *e2e-test-workflow + # - e2e_tests_path-prefix: + # <<: *e2e-test-workflow + # - e2e_tests_gatsby-image: + # <<: *e2e-test-workflow + # - e2e_tests_development_runtime: + # <<: *e2e-test-workflow + # - e2e_tests_production_runtime: + # <<: *e2e-test-workflow + # - themes_e2e_tests_production_runtime: + # <<: *e2e-test-workflow + # - themes_e2e_tests_development_runtime: + # <<: *e2e-test-workflow + # - starters_validate: + # <<: *ignore_master + # - starters_publish: + # requires: + # - bootstrap + # filters: + # branches: + # only: + # - master + # - manual_www_approval: + # type: approval + # filters: + # branches: + # only: + # - master + # - build_www: + # context: build_www + # requires: + # - manual_www_approval + # - deploy_www: + # requires: + # - build_www + # context: build_www + # - update_i18n_source: + # filters: + # branches: + # only: + # - master www_deploy: triggers: - schedule: diff --git a/jest.config.js b/jest.config.js index 3c67faff7d7ec..8012a0a5395c9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -53,7 +53,7 @@ module.exports = { }, collectCoverageFrom: coverageDirs, reporters: process.env.CI - ? [`jest-silent-reporter`, { useDots: true }] + ? [[`jest-silent-reporter`, { useDots: true }]] : [`default`].concat(useCoverage ? `jest-junit` : []), testEnvironment: `jest-environment-jsdom-fourteen`, moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`], diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.ts index 3c9a39de9ee99..8bc49682cee0a 100644 --- a/packages/gatsby/src/redux/index.ts +++ b/packages/gatsby/src/redux/index.ts @@ -62,7 +62,7 @@ export const configureStore = (initialState: IReduxState): Store => export const store = configureStore(readState()) // Persist state. -export const saveState = (): Promise => { +export const saveState = (): void => { const state = store.getState() const pickedState = _.pick(state, [ `nodes`, diff --git a/packages/gatsby/src/redux/persist.ts b/packages/gatsby/src/redux/persist.ts index 32b44445b808e..57501b234c0e4 100644 --- a/packages/gatsby/src/redux/persist.ts +++ b/packages/gatsby/src/redux/persist.ts @@ -1,5 +1,5 @@ import v8 from "v8" -import { readFileSync, writeFile } from "fs-extra" +import { readFileSync, writeFileSync } from "fs-extra" import { IReduxState } from "./types" const file = (): string => `${process.cwd()}/.cache/redux.state` @@ -7,5 +7,6 @@ const file = (): string => `${process.cwd()}/.cache/redux.state` export const readFromCache = (): IReduxState => v8.deserialize(readFileSync(file())) -export const writeToCache = (contents: IReduxState): Promise => - writeFile(file(), v8.serialize(contents)) +export const writeToCache = (contents: IReduxState): void => { + writeFileSync(file(), v8.serialize(contents)) +} diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index 564817fec3ca7..b22bd47d1e4b5 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -1,5 +1,5 @@ export interface IReduxState { - nodes?: Map> // TODO: Confirm this is correct. + nodes?: any // TODO nodesByType: Map // TODO lastAction: ActionsUnion jobs: { From 5e43447a4d40d84cdd8d09541d1a21ebe3cd2ed8 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 11:02:42 -0600 Subject: [PATCH 11/13] undo --- .../__snapshots__/query-compiler.js.snap | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap b/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap index 56147970369ac..5ebc996d9d692 100644 --- a/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap +++ b/packages/gatsby/src/query/__tests__/__snapshots__/query-compiler.js.snap @@ -152,25 +152,25 @@ exports[`actual compiling errors on double root 1`] = ` Array [ Object { "context": Object { - "afterCodeFrame": "  1 | query anotherQueryAndMockFileQuery { -  2 |  allPostsJson { -  3 |  #... -  4 |  } -  5 |  allPostsJson { -  6 |  #... -  7 |  } -  8 | }", - "beforeCodeFrame": "  1 | query mockFileQuery { -  2 |  allPostsJson { -  3 |  #... -  4 |  } -  5 | } -  6 |  -  7 | query AnotherQuery { -  8 |  allPostsJson { -  9 |  #... -  10 |  } -  11 | }", + "afterCodeFrame": " 1 | query anotherQueryAndMockFileQuery { + 2 | allPostsJson { + 3 | #... + 4 | } + 5 | allPostsJson { + 6 | #... + 7 | } + 8 | }", + "beforeCodeFrame": " 1 | query mockFileQuery { + 2 | allPostsJson { + 3 | #... + 4 | } + 5 | } + 6 | + 7 | query AnotherQuery { + 8 | allPostsJson { + 9 | #... + 10 | } + 11 | }", "name": "AnotherQuery", "otherName": "mockFileQuery", }, From fa46d033bbe8e1b1331932bb58e6ebaf6d995c0d Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 11:03:13 -0600 Subject: [PATCH 12/13] isolate different tests --- .circleci/config.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 815552a879981..9d9de1e0d9ca3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -453,15 +453,15 @@ workflows: build-test: jobs: - - windows_unit_tests - # - bootstrap + # - windows_unit_tests + - bootstrap # - lint: # requires: # - bootstrap - # - unit_tests_node8: - # <<: *ignore_docs - # requires: - # - bootstrap + - unit_tests_node8: + <<: *ignore_docs + requires: + - bootstrap # - unit_tests_node10: # <<: *ignore_docs # requires: From 8f159c21abedaa526c5d0e3acc8b8bcdaf77f88e Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Jan 2020 11:17:47 -0600 Subject: [PATCH 13/13] activate all of CI again --- .circleci/config.yml | 128 +++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d9de1e0d9ca3..474727fef9fe5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -453,75 +453,75 @@ workflows: build-test: jobs: - # - windows_unit_tests + - windows_unit_tests - bootstrap - # - lint: - # requires: - # - bootstrap + - lint: + requires: + - bootstrap - unit_tests_node8: <<: *ignore_docs requires: - bootstrap - # - unit_tests_node10: - # <<: *ignore_docs - # requires: - # - lint - # - unit_tests_node8 - # - unit_tests_node12: - # <<: *ignore_docs - # requires: - # - lint - # - unit_tests_node8 - # - unit_tests_www: - # requires: - # - lint - # - unit_tests_node8 - # - integration_tests_long_term_caching: - # <<: *e2e-test-workflow - # - integration_tests_gatsby_pipeline: - # <<: *e2e-test-workflow - # - integration_tests_structured_logging: - # <<: *e2e-test-workflow - # - e2e_tests_path-prefix: - # <<: *e2e-test-workflow - # - e2e_tests_gatsby-image: - # <<: *e2e-test-workflow - # - e2e_tests_development_runtime: - # <<: *e2e-test-workflow - # - e2e_tests_production_runtime: - # <<: *e2e-test-workflow - # - themes_e2e_tests_production_runtime: - # <<: *e2e-test-workflow - # - themes_e2e_tests_development_runtime: - # <<: *e2e-test-workflow - # - starters_validate: - # <<: *ignore_master - # - starters_publish: - # requires: - # - bootstrap - # filters: - # branches: - # only: - # - master - # - manual_www_approval: - # type: approval - # filters: - # branches: - # only: - # - master - # - build_www: - # context: build_www - # requires: - # - manual_www_approval - # - deploy_www: - # requires: - # - build_www - # context: build_www - # - update_i18n_source: - # filters: - # branches: - # only: - # - master + - unit_tests_node10: + <<: *ignore_docs + requires: + - lint + - unit_tests_node8 + - unit_tests_node12: + <<: *ignore_docs + requires: + - lint + - unit_tests_node8 + - unit_tests_www: + requires: + - lint + - unit_tests_node8 + - integration_tests_long_term_caching: + <<: *e2e-test-workflow + - integration_tests_gatsby_pipeline: + <<: *e2e-test-workflow + - integration_tests_structured_logging: + <<: *e2e-test-workflow + - e2e_tests_path-prefix: + <<: *e2e-test-workflow + - e2e_tests_gatsby-image: + <<: *e2e-test-workflow + - e2e_tests_development_runtime: + <<: *e2e-test-workflow + - e2e_tests_production_runtime: + <<: *e2e-test-workflow + - themes_e2e_tests_production_runtime: + <<: *e2e-test-workflow + - themes_e2e_tests_development_runtime: + <<: *e2e-test-workflow + - starters_validate: + <<: *ignore_master + - starters_publish: + requires: + - bootstrap + filters: + branches: + only: + - master + - manual_www_approval: + type: approval + filters: + branches: + only: + - master + - build_www: + context: build_www + requires: + - manual_www_approval + - deploy_www: + requires: + - build_www + context: build_www + - update_i18n_source: + filters: + branches: + only: + - master www_deploy: triggers: - schedule: