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

fix(gatsby-plugin-gatsby-cloud): Revert removal of _gatsby-config.json functionality in gatsby-plugin-gatsby-cloud #34526

Merged
merged 1 commit into from
Jan 19, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import createSiteConfig from "../create-site-config"
import * as fs from "fs-extra"

jest.mock(`fs-extra`, () => {
return {
writeJSON: jest.fn(),
}
})

describe(`create-site-config`, () => {
beforeEach(() => {
fs.writeJSON.mockClear()
})

it(`should generate a site-config file with pathPrefix null`, async () => {
await createSiteConfig(
{
pathPrefix: ``,
publicFolder: file => `public/${file}`,
},
{}
)

expect(fs.writeJSON).toBeCalledTimes(1)
expect(fs.writeJSON.mock.calls[0][0]).toBe(`public/_gatsby-config.json`)
expect(fs.writeJSON.mock.calls[0][1]).toMatchInlineSnapshot(`
Object {
"pathPrefix": null,
}
`)
})

it(`should generate a site-config file with pathPrefix set`, async () => {
await createSiteConfig(
{
pathPrefix: `/nested`,
publicFolder: file => `public/${file}`,
},
{}
)

expect(fs.writeJSON).toBeCalledTimes(1)
expect(fs.writeJSON.mock.calls[0][0]).toBe(`public/_gatsby-config.json`)
expect(fs.writeJSON.mock.calls[0][1]).toMatchInlineSnapshot(`
Object {
"pathPrefix": "/nested",
}
`)
})
})
1 change: 1 addition & 0 deletions packages/gatsby-plugin-gatsby-cloud/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const BUILD_CSS_STAGE = `build-css`
export const HEADERS_FILENAME = `_headers.json`
export const REDIRECTS_FILENAME = `_redirects.json`
export const PUBLIC_FUNCTIONS_FILENAME = `_functions.json`
export const SITE_CONFIG_FILENAME = `_gatsby-config.json`
export const CACHE_FUNCTIONS_FILENAME = `manifest.json`

export const DEFAULT_OPTIONS = {
Expand Down
15 changes: 15 additions & 0 deletions packages/gatsby-plugin-gatsby-cloud/src/create-site-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as fs from "fs-extra"
import { SITE_CONFIG_FILENAME } from "./constants"

/*
* @deprecated TODO(v5): Will be Remove in V5 since we're now sending config over IPC
* see https://github.com/gatsbyjs/gatsby/pull/34411/files#:~:text=process.send(%7B,%7D)
*/
export default async function createSiteConfig(pluginData, _pluginOptions) {
const { publicFolder } = pluginData
const siteConfig = {
pathPrefix: pluginData.pathPrefix ? pluginData.pathPrefix : null,
}

return fs.writeJSON(publicFolder(SITE_CONFIG_FILENAME), siteConfig)
}
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import makePluginData from "./plugin-data"
import buildHeadersProgram from "./build-headers-program"
import copyFunctionsManifest from "./copy-functions-manifest"
import createRedirects from "./create-redirects"
import createSiteConfig from "./create-site-config"
import { DEFAULT_OPTIONS, BUILD_HTML_STAGE, BUILD_CSS_STAGE } from "./constants"
import { emitRoutes, emitFileNodes } from "./ipc"

Expand Down Expand Up @@ -111,6 +112,7 @@ exports.onPostBuild = async ({ store, getNodesByType }, userPluginOptions) => {
await Promise.all([
ensureEmittingFileNodesFinished,
buildHeadersProgram(pluginData, pluginOptions),
createSiteConfig(pluginData, pluginOptions),
createRedirects(pluginData, redirects, rewrites),
copyFunctionsManifest(pluginData),
])
Expand Down