Skip to content

Commit

Permalink
fix(gatsby): [rendering engines] use results of exports removal if so…
Browse files Browse the repository at this point in the history
…urceMap was not generated alongside transformed code (#37282)

* fix(gatsby): [rendering engines] use results of exports removal if sourceMap was not generated alongside transformed code

* chore: regenerate also page-ssr bundle in standalone-regenerate
  • Loading branch information
pieh authored Dec 16, 2022
1 parent 42a3034 commit 770748d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ node node_modules/gatsby/dist/schema/graphql-engine/standalone-regenerate.js
*/

import { createGraphqlEngineBundle } from "./bundle-webpack"
import { createPageSSRBundle } from "./../../utils/page-ssr-module/bundle-webpack"
import reporter from "gatsby-cli/lib/reporter"
import { loadConfigAndPlugins } from "../../utils/worker/child/load-config-and-plugins"
import * as fs from "fs-extra"
import { store } from "../../redux"
import { validateEngines } from "../../utils/validate-engines"

async function run(): Promise<void> {
Expand All @@ -34,17 +36,30 @@ async function run(): Promise<void> {
console.log(`clearing webpack cache\n\n`)
// get rid of cache if it exist
await fs.remove(process.cwd() + `/.cache/webpack/query-engine`)
await fs.remove(process.cwd() + `/.cache/webpack/page-ssr`)
} catch (e) {
// eslint-disable no-empty
}

const state = store.getState()

// recompile
const buildActivityTimer = reporter.activityTimer(
`Building Rendering Engines`
)
try {
buildActivityTimer.start()
await createGraphqlEngineBundle(process.cwd(), reporter, true)
await Promise.all([
createGraphqlEngineBundle(process.cwd(), reporter, true),
createPageSSRBundle({
rootDir: process.cwd(),
components: store.getState().components,
staticQueriesByTemplate: state.staticQueriesByTemplate,
webpackCompilationHash: state.webpackCompilationHash, // we set webpackCompilationHash above
reporter,
isVerbose: state.program.verbose,
}),
])
} catch (err) {
buildActivityTimer.panic(err)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const webpackRemoveExportsLoader: LoaderDefinitionFunction<IOptions> =
(err, result) => {
if (err) {
callback(err)
} else if (result && result.code && result.map) {
callback(null, result?.code, result?.map)
} else if (result && result.code) {
callback(null, result?.code, result?.map ?? undefined)
} else {
callback(null, source, sourceMap)
}
Expand Down

0 comments on commit 770748d

Please sign in to comment.