Skip to content

Commit

Permalink
don't (transitively) import report in jest-worker worker
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jan 27, 2021
1 parent 8776dbc commit 7fdf75f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 76 deletions.
70 changes: 70 additions & 0 deletions packages/gatsby/src/commands/build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../utils/page-html"
import { removePageData, fixedPagePath } from "../utils/page-data"
import { store } from "../redux"
import { IGatsbyState } from "../redux/types"

const checkFolderIsEmpty = (path: string): boolean =>
fs.existsSync(path) && !fs.readdirSync(path).length
Expand Down Expand Up @@ -62,3 +63,72 @@ export const removePageFiles = async (
})
})
}

export function calcDirtyHtmlFiles(
state: IGatsbyState
): { toRegenerate: Array<string>; toDelete: Array<string> } {
const toRegenerate: Array<string> = []
const toDelete: Array<string> = []

state.html.trackedHtmlFiles.forEach(function (htmlFile, path) {
if (htmlFile.isDeleted || !state.pages.has(path)) {
// FIXME: checking pages state here because pages are not persisted
// and because of that `isDeleted` might not be set ...
toDelete.push(path)
} else if (htmlFile.dirty) {
toRegenerate.push(path)
}
})

return {
toRegenerate,
toDelete,
}
}

export function markHtmlDirtyIfResultOfUsedStaticQueryChanged(): void {
const state = store.getState()

const dirtyStaticQueryResults = new Set<string>()
state.html.trackedStaticQueryResults.forEach(function (
staticQueryResultState,
staticQueryHash
) {
if (staticQueryResultState.dirty) {
dirtyStaticQueryResults.add(staticQueryHash)
}
})

// we have dirty static query hashes - now we need to find templates that use them
const dirtyTemplates = new Set<string>()
state.staticQueriesByTemplate.forEach(function (
staticQueryHashes,
componentPath
) {
for (const dirtyStaticQueryHash of dirtyStaticQueryResults) {
if (staticQueryHashes.includes(dirtyStaticQueryHash)) {
dirtyTemplates.add(componentPath)
break // we already know this template need to rebuild, no need to check rest of queries
}
}
})

// mark html as dirty
const dirtyPages = new Set<string>()
for (const dirtyTemplate of dirtyTemplates) {
const component = state.components.get(dirtyTemplate)
if (component) {
for (const page of component.pages) {
dirtyPages.add(page)
}
}
}

store.dispatch({
type: `HTML_MARK_DIRTY_BECAUSE_STATIC_QUERY_RESULT_CHANGED`,
payload: {
pages: dirtyPages,
staticQueryHashes: dirtyStaticQueryResults,
},
})
}
8 changes: 2 additions & 6 deletions packages/gatsby/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import fs from "fs-extra"
import telemetry from "gatsby-telemetry"

import { doBuildPages, buildRenderer, deleteRenderer } from "./build-html"
import {
calcDirtyHtmlFiles,
markHtmlDirtyIfResultOfUsedStaticQueryChanged,
} from "../utils/page-html"
import { buildProductionBundle } from "./build-javascript"
import { bootstrap } from "../bootstrap"
import apiRunnerNode from "../utils/api-runner-node"
Expand Down Expand Up @@ -206,11 +202,11 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
buildSSRBundleActivityProgress.end()
}

markHtmlDirtyIfResultOfUsedStaticQueryChanged()
buildUtils.markHtmlDirtyIfResultOfUsedStaticQueryChanged()

const { toRegenerate, toDelete } = process.env
.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES
? calcDirtyHtmlFiles(store.getState())
? buildUtils.calcDirtyHtmlFiles(store.getState())
: {
toRegenerate: [...store.getState().pages.keys()],
toDelete: [],
Expand Down
70 changes: 0 additions & 70 deletions packages/gatsby/src/utils/page-html.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import fs from "fs-extra"
import path from "path"

import { IGatsbyState } from "../redux/types"
import { store } from "../redux"

const checkForHtmlSuffix = (pagePath: string): boolean =>
!/\.(html?)$/i.test(pagePath)

Expand Down Expand Up @@ -31,70 +28,3 @@ export const remove = async (
}
return Promise.resolve()
}

export function calcDirtyHtmlFiles(
state: IGatsbyState
): { toRegenerate: Array<string>; toDelete: Array<string> } {
const toRegenerate: Array<string> = []
const toDelete: Array<string> = []

state.html.trackedHtmlFiles.forEach(function (htmlFile, path) {
if (htmlFile.isDeleted || !state.pages.has(path)) {
// FIXME: checking pages state here because pages are not persisted
// and because of that `isDeleted` might not be set ...
toDelete.push(path)
} else if (htmlFile.dirty) {
toRegenerate.push(path)
}
})

return {
toRegenerate,
toDelete,
}
}

export function markHtmlDirtyIfResultOfUsedStaticQueryChanged(): void {
const state = store.getState()

const dirtyStaticQueryResults = new Set<string>()
state.html.trackedStaticQueryResults.forEach(function (
staticQueryResultState,
staticQueryHash
) {
if (staticQueryResultState.dirty) {
dirtyStaticQueryResults.add(staticQueryHash)
}
})

// we have dirty static query hashes - now we need to find templates that use them
const dirtyTemplates = new Set<string>()
state.staticQueriesByTemplate.forEach(function (
staticQueryHashes,
componentPath
) {
for (const dirtyStaticQueryHash of dirtyStaticQueryResults) {
if (staticQueryHashes.includes(dirtyStaticQueryHash)) {
dirtyTemplates.add(componentPath)
break // we already know this template need to rebuild, no need to check rest of queries
}
}
})

// mark html as dirty
const dirtyPages = new Set<string>()
for (const dirtyTemplate of dirtyTemplates) {
const component = state.components.get(dirtyTemplate)
for (const page of component.pages) {
dirtyPages.add(page)
}
}

store.dispatch({
type: `HTML_MARK_DIRTY_BECAUSE_STATIC_QUERY_RESULT_CHANGED`,
payload: {
pages: dirtyPages,
staticQueryHashes: dirtyStaticQueryResults,
},
})
}

0 comments on commit 7fdf75f

Please sign in to comment.