diff --git a/packages/gatsby-cli/src/reporter/reporter.ts b/packages/gatsby-cli/src/reporter/reporter.ts index b0af507ef58d1..0722aa0188286 100644 --- a/packages/gatsby-cli/src/reporter/reporter.ts +++ b/packages/gatsby-cli/src/reporter/reporter.ts @@ -256,5 +256,5 @@ class Reporter { // "reporter._setStage is not a function" error when gatsby@<2.16 is used with gatsby-cli@>=2.8 _setStage = (): void => {} } - +export type { Reporter } export const reporter = new Reporter() diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 8b1e9e422e423..e387bd8fe31f7 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -2,7 +2,8 @@ import * as React from "react" import { Renderer } from "react-dom" import { EventEmitter } from "events" import { WindowLocation, NavigateFn } from "@reach/router" -import reporter from "gatsby-cli/lib/reporter" +import { Reporter } from "gatsby-cli/lib/reporter/reporter" +export { Reporter } import { ComposeEnumTypeConfig, ComposeInputObjectTypeConfig, @@ -1269,8 +1270,6 @@ export interface Store { replaceReducer: Function } -export type Reporter = typeof reporter - export type ActivityTracker = { start(): () => void end(): () => void diff --git a/packages/gatsby/internal.d.ts b/packages/gatsby/internal.d.ts new file mode 100644 index 0000000000000..4ef7da1dbb69b --- /dev/null +++ b/packages/gatsby/internal.d.ts @@ -0,0 +1,4 @@ +/** + * This is an internal API. It does not follow semver. Use at your own risk. + */ +export * from "./dist/internal" diff --git a/packages/gatsby/internal.js b/packages/gatsby/internal.js new file mode 100644 index 0000000000000..0df8c7f431b42 --- /dev/null +++ b/packages/gatsby/internal.js @@ -0,0 +1,5 @@ +/** + * This is an internal API. It does not follow semver. Use at your own risk. + */ + +module.exports = require("./dist/internal") \ No newline at end of file diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 178614ca7495e..d9cda82b48356 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -191,7 +191,9 @@ "graphql.js", "index.d.ts", "scripts/postinstall.js", - "utils.js" + "utils.js", + "internal.js", + "internal.d.ts" ], "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby#readme", "keywords": [ @@ -232,7 +234,8 @@ "clean-test-bundles": "find test/ -type f -name bundle.js* -exec rm -rf {} +", "prebuild": "rimraf dist && rimraf cache-dir/commonjs", "postinstall": "node scripts/postinstall.js", - "prepare": "cross-env NODE_ENV=production npm run build", + "prepare": "npm run typegen && cross-env NODE_ENV=production npm run build", + "typegen": "tsc --emitDeclarationOnly --declaration --declarationDir dist", "watch": "rimraf dist && mkdir dist && npm run build:internal-plugins && npm run build:rawfiles && npm run build:src -- --watch" }, "types": "index.d.ts", diff --git a/packages/gatsby/src/commands/types.ts b/packages/gatsby/src/commands/types.ts index bcd4889c88395..1cc9c692aef7c 100644 --- a/packages/gatsby/src/commands/types.ts +++ b/packages/gatsby/src/commands/types.ts @@ -35,7 +35,11 @@ export interface IProgram { setStore?: (store: Store) => void } -// @deprecated +/** + * @deprecated + * Use `Stage` instead + */ + export enum BuildHTMLStage { DevelopHTML = `develop-html`, BuildHTML = `build-html`, diff --git a/packages/gatsby/src/internal.ts b/packages/gatsby/src/internal.ts new file mode 100644 index 0000000000000..21fa3a20e3417 --- /dev/null +++ b/packages/gatsby/src/internal.ts @@ -0,0 +1,5 @@ +export * from "./state-machines" +export * from "./services" +export * from "./redux/types" +export * from "./query/types" +export * from "./commands/types" diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index 40168b63aa7b1..22a0da3f90059 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -120,7 +120,7 @@ export interface IPlugin { options: Record } -interface IBabelStage { +export interface IBabelStage { plugins: IPlugin[] presets: IPlugin[] options: { diff --git a/packages/gatsby/src/services/index.ts b/packages/gatsby/src/services/index.ts index 46f86a7ae2132..013a89655f349 100644 --- a/packages/gatsby/src/services/index.ts +++ b/packages/gatsby/src/services/index.ts @@ -1,65 +1,21 @@ -import { ServiceConfig } from "xstate" -import { IBuildContext } from "./" +export { startWebpackServer } from "./start-webpack-server" +export { rebuildSchemaWithSitePage } from "./rebuild-schema-with-site-pages" +export { extractQueries } from "./extract-queries" +export { writeOutRedirects } from "./write-out-redirects" +export { postBootstrap } from "./post-bootstrap" +export { buildSchema } from "./build-schema" +export { createPages } from "./create-pages" +export { createPagesStatefully } from "./create-pages-statefully" +export { customizeSchema } from "./customize-schema" +export { initialize } from "./initialize" +export { sourceNodes } from "./source-nodes" +export { writeOutRequires } from "./write-out-requires" +export { calculateDirtyQueries } from "./calculate-dirty-queries" +export { runStaticQueries } from "./run-static-queries" +export { runPageQueries } from "./run-page-queries" -import { startWebpackServer } from "./start-webpack-server" -import { rebuildSchemaWithSitePage } from "./rebuild-schema-with-site-pages" -import { extractQueries } from "./extract-queries" -import { writeOutRedirects } from "./write-out-redirects" -import { postBootstrap } from "./post-bootstrap" -import { buildSchema } from "./build-schema" -import { createPages } from "./create-pages" -import { createPagesStatefully } from "./create-pages-statefully" -import { customizeSchema } from "./customize-schema" -import { initialize } from "./initialize" -import { sourceNodes } from "./source-nodes" -import { writeOutRequires } from "./write-out-requires" -import { calculateDirtyQueries } from "./calculate-dirty-queries" -import { runStaticQueries } from "./run-static-queries" -import { runPageQueries } from "./run-page-queries" - -import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete" -import { runMutationBatch } from "./run-mutation-batch" -import { recompile } from "./recompile" +export { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete" +export { runMutationBatch } from "./run-mutation-batch" +export { recompile } from "./recompile" export * from "./types" - -export { - customizeSchema, - sourceNodes, - createPages, - buildSchema, - createPagesStatefully, - extractQueries, - writeOutRequires, - calculateDirtyQueries, - runStaticQueries, - runPageQueries, - initialize, - waitUntilAllJobsComplete, - postBootstrap, - writeOutRedirects, - startWebpackServer, - rebuildSchemaWithSitePage, - runMutationBatch, - recompile, -} - -export const buildServices: Record> = { - customizeSchema, - sourceNodes, - createPages, - buildSchema, - createPagesStatefully, - extractQueries, - writeOutRequires, - calculateDirtyQueries, - runStaticQueries, - runPageQueries, - initialize, - waitUntilAllJobsComplete, - postBootstrap, - writeOutRedirects, - startWebpackServer, - rebuildSchemaWithSitePage, - recompile, -} diff --git a/packages/gatsby/src/state-machines/index.ts b/packages/gatsby/src/state-machines/index.ts new file mode 100644 index 0000000000000..3e8721e9cebcc --- /dev/null +++ b/packages/gatsby/src/state-machines/index.ts @@ -0,0 +1,11 @@ +export { + initializeDataMachine, + reloadDataMachine, + recreatePagesMachine, +} from "./data-layer" +export { queryRunningMachine } from "./query-running" +export { waitingMachine } from "./waiting" +export { IDataLayerContext } from "./data-layer/types" +export { IQueryRunningContext } from "./query-running/types" +export { IWaitingContext } from "./waiting/types" +export { buildActions } from "./develop/actions" diff --git a/packages/gatsby/src/utils/mett.ts b/packages/gatsby/src/utils/mett.ts index d1f2af41060b8..39fa30160d32b 100644 --- a/packages/gatsby/src/utils/mett.ts +++ b/packages/gatsby/src/utils/mett.ts @@ -7,7 +7,7 @@ type MettHandler = ( eventName: EventName ) => void -interface IMett { +export interface IMett { on(eventName: EventName, callback: MettHandler): void off(eventName: EventName, callback: MettHandler): void emit(eventName: EventName, e: Payload): void @@ -16,7 +16,7 @@ interface IMett { type EventName = string type Payload = any -function mett(): IMett { +export function mett(): IMett { const mettEvents: Map< EventName, Set> @@ -53,5 +53,3 @@ function mett(): IMett { }, } } - -export { mett } diff --git a/packages/gatsby/tsconfig.json b/packages/gatsby/tsconfig.json index 4082f16a5d91c..3ad9a20cee4b1 100644 --- a/packages/gatsby/tsconfig.json +++ b/packages/gatsby/tsconfig.json @@ -1,3 +1,5 @@ { - "extends": "../../tsconfig.json" + "extends": "../../tsconfig.json", + // This is for typegen purposes only. For now index.d.ts is manually-created, but gatsby/internal is auto-generated + "include": ["./src/internal.ts"] }