Repository: gatsbyjs/gatsby
File: packages/gatsby/src/commands/build.ts (TypeScript)

Code before:
import db from "../db"
import { store, readState } from "../redux"
import * as appDataUtil from "../utils/app-data"
import { flush as flushPendingPageDataWrites } from "../utils/page-data"
import * as WorkerPool from "../utils/worker/pool"
import { structureWebpackErrors } from "../utils/webpack-error-utils"
import {
  userPassesFeedbackRequestHeuristic,
  showFeedbackRequest,
} from "../utils/feedback"
import * as buildUtils from "./build-utils"
import { boundActionCreators } from "../redux/actions"
import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete"
import { IProgram, Stage } from "./types"
import { PackageJson } from "../.."
import {
  calculateDirtyQueries,
  runStaticQueries,
  runPageQueries,
  writeOutRequires,
} from "../services"
import {
  markWebpackStatusAsPending,
  markWebpackStatusAsDone,
} from "../utils/webpack-status"

let cachedPageData
let cachedWebpackCompilationHash
if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
  const { pageData, webpackCompilationHash } = readState()
  // extract only data that we need to reuse and let v8 garbage collect rest of state
  cachedPageData = pageData
  cachedWebpackCompilationHash = webpackCompilationHash
}

interface IBuildArgs extends IProgram {
  directory: string
  sitePackageJson: PackageJson
  prefixPaths: boolean
  noUglify: boolean
  profile: boolean
  graphqlTracing: boolean
  openTracingConfigFile: string
}

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`
    )
  }

Review comment (suggestion):
```suggestion
// TODO make service-lock export from gatsby-core-utils
import { createServiceLock } from "gatsby-core-utils/dist/service-lock"
```

Code after:
import db from "../db"
import { store, readState } from "../redux"
import * as appDataUtil from "../utils/app-data"
import { flush as flushPendingPageDataWrites } from "../utils/page-data"
import * as WorkerPool from "../utils/worker/pool"
import { structureWebpackErrors } from "../utils/webpack-error-utils"
import {
  userPassesFeedbackRequestHeuristic,
  showFeedbackRequest,
} from "../utils/feedback"
import * as buildUtils from "./build-utils"
import { boundActionCreators } from "../redux/actions"
import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete"
import { IProgram, Stage } from "./types"
import { PackageJson } from "../.."
import {
  calculateDirtyQueries,
  runStaticQueries,
  runPageQueries,
  writeOutRequires,
} from "../services"
import {
  markWebpackStatusAsPending,
  markWebpackStatusAsDone,
} from "../utils/webpack-status"
import { createServiceLock } from "gatsby-core-utils/dist/service-lock"

let cachedPageData
let cachedWebpackCompilationHash
if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
  const { pageData, webpackCompilationHash } = readState()
  // extract only data that we need to reuse and let v8 garbage collect rest of state
  cachedPageData = pageData
  cachedWebpackCompilationHash = webpackCompilationHash
}

interface IBuildArgs extends IProgram {
  directory: string
  sitePackageJson: PackageJson
  prefixPaths: boolean
  noUglify: boolean
  profile: boolean
  graphqlTracing: boolean
  openTracingConfigFile: string
}

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`
    )