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

feat(gatsby): Add internal types export #25921

Merged
merged 3 commits into from
Jul 23, 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
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing export type because we don't want to give access to the class itself, just the type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart, i like this

export const reporter = new Reporter()
5 changes: 2 additions & 3 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1269,8 +1270,6 @@ export interface Store {
replaceReducer: Function
}

export type Reporter = typeof reporter

export type ActivityTracker = {
start(): () => void
end(): () => void
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby/internal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This is an internal API. It does not follow semver. Use at your own risk.
*/
export * from "./dist/internal"
5 changes: 5 additions & 0 deletions packages/gatsby/internal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* This is an internal API. It does not follow semver. Use at your own risk.
*/

module.exports = require("./dist/internal")
7 changes: 5 additions & 2 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -227,7 +229,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",
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby/src/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export interface IProgram {
setStore?: (store: Store<IGatsbyState, AnyAction>) => void
}

// @deprecated
/**
* @deprecated
* Use `Stage` instead
*/

export enum BuildHTMLStage {
DevelopHTML = `develop-html`,
BuildHTML = `build-html`,
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby/src/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./state-machines"
export * from "./services"
export * from "./redux/types"
export * from "./query/types"
export * from "./commands/types"
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export interface IPlugin {
options: Record<string, any>
}

interface IBabelStage {
export interface IBabelStage {
plugins: IPlugin[]
presets: IPlugin[]
options: {
Expand Down
80 changes: 18 additions & 62 deletions packages/gatsby/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, ServiceConfig<IBuildContext>> = {
customizeSchema,
sourceNodes,
createPages,
buildSchema,
createPagesStatefully,
extractQueries,
writeOutRequires,
calculateDirtyQueries,
runStaticQueries,
runPageQueries,
initialize,
waitUntilAllJobsComplete,
postBootstrap,
writeOutRedirects,
startWebpackServer,
rebuildSchemaWithSitePage,
recompile,
}
11 changes: 11 additions & 0 deletions packages/gatsby/src/state-machines/index.ts
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 2 additions & 4 deletions packages/gatsby/src/utils/mett.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type MettHandler<EventName, Payload> = (
eventName: EventName
) => void

interface IMett {
export interface IMett {
on(eventName: EventName, callback: MettHandler<EventName, Payload>): void
off(eventName: EventName, callback: MettHandler<EventName, Payload>): void
emit(eventName: EventName, e: Payload): void
Expand All @@ -16,7 +16,7 @@ interface IMett {
type EventName = string
type Payload = any

function mett(): IMett {
export function mett(): IMett {
const mettEvents: Map<
EventName,
Set<MettHandler<EventName, Payload>>
Expand Down Expand Up @@ -53,5 +53,3 @@ function mett(): IMett {
},
}
}

export { mett }
4 changes: 3 additions & 1 deletion packages/gatsby/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}