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) (#37299)

* 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

(cherry picked from commit 770748d)

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
ViCo0TeCH and pieh committed Dec 20, 2022
1 parent ea42d7f commit 48a3db4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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
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 48a3db4

Please sign in to comment.