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): convert build to typescript #23695

Merged
merged 8 commits into from
May 5, 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
6 changes: 3 additions & 3 deletions packages/gatsby/src/commands/build-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import webpack from "webpack"
import webpackConfig from "../utils/webpack.config"
import { structureWebpackErrors } from "../utils/webpack-error-utils"

import { BuildHTMLStage, IProgram } from "./types"
import { IProgram, Stage } from "./types"

type IActivity = any // TODO
type IWorkerPool = any // TODO
Expand Down Expand Up @@ -42,7 +42,7 @@ const doBuildRenderer = async (

const buildRenderer = async (
program: IProgram,
stage: BuildHTMLStage,
stage: Stage,
parentSpan: IActivity
): Promise<string> => {
const { directory } = program
Expand Down Expand Up @@ -122,7 +122,7 @@ export const buildHTML = async ({
workerPool,
}: {
program: IProgram
stage: BuildHTMLStage
stage: Stage
pagePaths: string[]
activity: IActivity
workerPool: IWorkerPool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/* @flow */
import path from "path"
import report from "gatsby-cli/lib/reporter"
import signalExit from "signal-exit"
import fs from "fs-extra"
import telemetry from "gatsby-telemetry"

const path = require(`path`)
const report = require(`gatsby-cli/lib/reporter`)
const fs = require(`fs-extra`)
import { buildHTML } from "./build-html"
import { buildProductionBundle } from "./build-javascript"
const bootstrap = require(`../bootstrap`)
const apiRunnerNode = require(`../utils/api-runner-node`)
const GraphQLRunner = require(`../query/graphql-runner`).default
const { copyStaticDirs } = require(`../utils/get-static-dir`)
import bootstrap from "../bootstrap"
import apiRunnerNode from "../utils/api-runner-node"
import GraphQLRunner from "../query/graphql-runner"
import { copyStaticDirs } from "../utils/get-static-dir"
import { initTracer, stopTracer } from "../utils/tracer"
const db = require(`../db`)
const signalExit = require(`signal-exit`)
const telemetry = require(`gatsby-telemetry`)
const { store, readState } = require(`../redux`)
const queryUtil = require(`../query`)
import db from "../db"
import { store, readState } from "../redux"
import queryUtil from "../query"
import * as appDataUtil from "../utils/app-data"
import * as WorkerPool from "../utils/worker/pool"
import { structureWebpackErrors } from "../utils/webpack-error-utils"
Expand All @@ -23,8 +22,10 @@ import {
showFeedbackRequest,
} from "../utils/feedback"
import * as buildUtils from "./build-utils"
const { boundActionCreators } = require(`../redux/actions`)
import { boundActionCreators } from "../redux/actions"
devrchancay marked this conversation as resolved.
Show resolved Hide resolved
import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete"
import { IProgram, Stage } from "./types"
import { PackageJson } from "../.."

let cachedPageData
let cachedWebpackCompilationHash
Expand All @@ -35,16 +36,16 @@ if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
cachedWebpackCompilationHash = webpackCompilationHash
}

type BuildArgs = {
directory: string,
sitePackageJson: object,
prefixPaths: boolean,
noUglify: boolean,
profile: boolean,
openTracingConfigFile: string,
interface IBuildArgs extends IProgram {
directory: string
sitePackageJson: PackageJson
prefixPaths: boolean
noUglify: boolean
profile: boolean
openTracingConfigFile: string
}

module.exports = async function build(program: BuildArgs) {
module.exports = async function build(program: IBuildArgs): Promise<void> {
if (program.profile) {
report.warn(
`React Profiling is enabled. This can have a performance impact. See https://www.gatsbyjs.org/docs/profiling-site-performance-with-react-profiler/#performance-impact`
Expand Down Expand Up @@ -95,12 +96,14 @@ module.exports = async function build(program: BuildArgs) {
{ parentSpan: buildSpan }
)
activity.start()
const stats = await buildProductionBundle(program, activity.span).catch(
err => {
activity.panic(structureWebpackErrors(`build-javascript`, err))
}
)
activity.end()
let stats
try {
stats = await buildProductionBundle(program, activity.span)
} catch (err) {
activity.panic(structureWebpackErrors(Stage.BuildJavascript, err))
} finally {
activity.end()
}

const workerPool = WorkerPool.create()

Expand Down Expand Up @@ -154,9 +157,7 @@ module.exports = async function build(program: BuildArgs) {
})
}

require(`../redux/actions`).boundActionCreators.setProgramStatus(
`BOOTSTRAP_QUERY_RUNNING_FINISHED`
)
boundActionCreators.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`)

await db.saveState()

Expand Down Expand Up @@ -191,7 +192,7 @@ module.exports = async function build(program: BuildArgs) {
try {
await buildHTML({
program,
stage: `build-html`,
stage: Stage.BuildHTML,
pagePaths,
activity,
workerPool,
Expand All @@ -200,6 +201,7 @@ module.exports = async function build(program: BuildArgs) {
let id = `95313` // TODO: verify error IDs exist
const context = {
errorPath: err.context && err.context.path,
ref: ``,
}

const match = err.message.match(
Expand All @@ -218,7 +220,7 @@ module.exports = async function build(program: BuildArgs) {
}
activity.done()

let deletedPageKeys = []
let deletedPageKeys: string[] = []
if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
activity = report.activityTimer(`Delete previous page data`)
activity.start()
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
showFeedbackRequest,
} from "../utils/feedback"

import { BuildHTMLStage, IProgram } from "./types"
import { Stage, IProgram } from "./types"

// checks if a string is a valid ip
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/
Expand Down Expand Up @@ -99,7 +99,7 @@ async function startServer(program: IProgram): Promise<IServer> {
try {
await buildHTML({
program,
stage: BuildHTMLStage.DevelopHTML,
stage: Stage.DevelopHTML,
pagePaths: [`/`],
workerPool,
activity,
Expand Down