[static-build] add support for gatsby esm config (#9183)

Adds support for auto injection into Gatsby's new ESM config format. Only injects if the `gatsby-config.mjs` is present, and continues to default generation of `gatsby-config.js`
This commit is contained in:
Ethan Arrowood
2023-01-09 13:59:29 -07:00
committed by GitHub
parent 1e13a6ca48
commit e28c5f9733
8 changed files with 9319 additions and 0 deletions

View File

@@ -290,6 +290,54 @@ it(
FOUR_MINUTES
);
it(
'Should build Gatsby with configuration defined in esm',
async () => {
const { workPath } = await runBuildLambda(
path.join(__dirname, 'build-fixtures/14-gatsby-with-esm-config')
);
const contents = await fs.readdir(workPath);
expect(contents.some(name => name === 'gatsby-config.js')).toBeFalsy();
expect(contents.some(name => name === 'gatsby-config.ts')).toBeFalsy();
expect(contents.some(name => name === 'gatsby-config.mjs')).toBeTruthy();
// using `import` causes a seg fault.
expect(await fs.readFile(path.join(workPath, 'gatsby-config.mjs'), 'utf-8'))
.toBe(`import userConfig from "./gatsby-config.mjs.__vercel_builder_backup__.mjs";
// https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
const preferDefault = (m) => (m && m.default) || m;
const vercelConfig = Object.assign(
{},
// https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
preferDefault(userConfig)
);
if (!vercelConfig.plugins) {
vercelConfig.plugins = [];
}
const hasPlugin = vercelConfig.plugins.find(
(p) =>
p && (p === "gatsby-plugin-vercel" || p.resolve === "gatsby-plugin-vercel")
);
if (!hasPlugin) {
vercelConfig.plugins = vercelConfig.plugins.slice();
vercelConfig.plugins.push({
resolve: "gatsby-plugin-vercel",
options: {},
});
}
export default vercelConfig;
`);
},
FOUR_MINUTES
);
it(
'Should build Nuxt.js with "@nuxtjs/web-vitals" plugin',
async () => {