[static-build] support gatsby-config as typescript (#8894)

### Related Issues

A customer issue was raised that web-vitals analytics were not working for their Gatsby application, even though this is meant to be zero config. 

It turns out the issue is due to their `gatsby-config` file being declared as a `ts` file, rather than `js`. This is perfectly valid and supported in Gatsby. 

However, the static-build modifications that are made to automatically add the `gatsby-plugin-vercel` only apply to existing `js` files. 

This lead to their deployments containing both a `js` and `ts` version of `gatsby-config`. Luckily, the `ts` version has higher precedence, so _only_ web-vitals were affected. 

Closes https://linear.app/vercel/issue/FLA-364/investigate-gatsby-and-nuxt-data-issues

#### Tests

- [X] The code changed/added as part of this PR has been covered with tests
- [X] All tests pass locally with `yarn test-unit`

#### Code Review

- [X] This PR has a concise title and thorough description useful to a reviewer
- [X] Issue from task tracker has a link to this PR
This commit is contained in:
Douglas Parsons
2022-11-15 22:37:18 +00:00
committed by GitHub
parent 74593e4d81
commit feabd64d5e
10 changed files with 9507 additions and 25 deletions

View File

@@ -257,6 +257,39 @@ it(
FOUR_MINUTES
);
it(
'Should build Gatsby with configuration defined in typescript',
async () => {
const { workPath } = await runBuildLambda(
path.join(__dirname, 'build-fixtures/13-gatsby-with-typescript-config')
);
const contents = await fs.readdir(workPath);
expect(contents.some(name => name === 'gatsby-config.js')).toBeFalsy();
expect(contents.some(name => name === 'gatsby-config.ts')).toBeTruthy();
expect(require(path.join(workPath, 'gatsby-config.ts')))
.toMatchInlineSnapshot(`
Object {
"default": Object {
"plugins": Array [
Object {
"options": Object {},
"resolve": "gatsby-plugin-vercel",
},
],
"siteMetadata": Object {
"siteUrl": "https://gatsby-typescript-config.vercel.app",
"title": "Gatsby Typescript Config",
},
},
}
`);
},
FOUR_MINUTES
);
it(
'Should build Nuxt.js with "@nuxtjs/web-vitals" plugin',
async () => {