Commit Graph

22 Commits

Author SHA1 Message Date
Shohei Maeda
ab24444660 [gatsby-plugin-vercel-builder] use --keep-names esbuild flag (#11117)
Some packages are very sensitive to minification.
For example: https://github.com/node-fetch/node-fetch/issues/784 which ends up in runtime error, and is hard to notice as they don't reproduce on local dev.

Setting `--keep-names` should prevent those edge cases: https://esbuild.github.io/api/#keep-names
2024-02-05 21:15:50 +00:00
Nathan Rajlich
652a312753 [gatsby-plugin-vercel-builder] Add support for "rewrites" (#10954) 2023-12-14 17:08:07 -08:00
Nathan Rajlich
efd3cc05dc [gatsby-plugin-vercel-builder] Fix nested SSR routes (#10751)
Fixes SSR / DSG pages that are nested deeper than the root path for Gatsby projects.

Also introduces unit tests for the logic related to determining which page name to use.
2023-10-24 20:15:46 +00:00
Nathan Rajlich
4b376a564a [gatsby-plugin-vercel-builder] Use "esbuild" to build package (#10508)
Removes the two-staged `tsc` build into a single `esbuild` bundle. The `ssr-handler.ts` template file is moved to the root of the package and converted to JavaScript.
2023-09-20 13:26:31 +00:00
Chris Barber
bc7a5d38be Exclude Gatsby from default 404 error route (#10365)
All static builds (except Next.js) have a default 404 error route. This PR add the exclusion of Gatsby from being assigned a 404 error route. The error routes are now introduced by the `gatsby-plugin-vercel-builder`.

Linear: https://linear.app/vercel/issue/VCCLI-749/fix-gatsby-404500-pages-directory-listing-bug
2023-08-18 17:10:40 +00:00
Nathan Rajlich
fda76691d1 [gatsby-plugin-vercel-builder] Log validation errors (#9854)
Log state validation errors, because they can be user error.

Example:

```
error "gatsby-node.js" threw an error while running the onPostBuild lifecycle:

Gatsby state validation failed:
  - Expected boolean, got string ("true") at path "/redirects/0/isPermanent"
Please check your Gatsby configuration files, or file an issue at https://vercel.com/help#issues

  3 |
  4 | export const onPostBuild = async ({ store }: { store: any }) => {
> 5 |   await generateVercelBuildOutputAPI3Output({
    |         ^
  6 |     // validated by `pluginOptionSchema`
  7 |     gatsbyStoreState: store.getState(),
  8 |   });
```
2023-04-25 06:31:27 +00:00
Nathan Rajlich
43a57a3a60 [gatsby-plugin-vercel-builder] Ignore assetPrefix completely (#9787)
Before, we were stripping off only the hostname portion of `assetPrefix`, so any pathname was still being "handled" by the plugin.

Instead, we should be ignoring the `assetPrefix` entirely, so that these two configurations are treated differently:

 * `{ assetPrefix: 'http://example.com', pathPrefix: '/foo' }` - Gatsby project is served from `/foo`
 * `{ assetPrefix: 'http://example.com/foo', pathPrefix: undefined }` - Gatsby project is served from the root `/`

Currently, both configuration behave as the first version listed above. This change makes it so they can behave differently, specifically for some proxy configurations.

In both cases, the generated HTML contains the full URL `http://example.com/foo/*` for JS/CSS/etc. assets
2023-04-11 19:52:38 +00:00
Sean Massa
ffdca76155 [gatsby-plugin-vercel-builder] link instead of move (#9673)
When creating the `./vercel/output/static` dir...

**Moving the `public` dir** is what currently happens. This causes Gatsby to believe that the build was not complete:

> info We've detected that the Gatsby cache is incomplete (the .cache directory exists but the public directory does not). As a precaution, we're deleting your site's cache to ensure there's no stale data.

**Copying the `public` dir** is not an option because it can cause a build to run out of space.

**Symlinking the `public` dir** would work, but it would require more changes throughout the system to make sure the symlink was followed properly.

**Hard Linking the `public` dir's files** is the best option. This PR links the directories instead of moving them. We did look for a library that already does the `hardlinkFileTree` thing, but couldn't find one.

---

**Testing**

This was manually tested with real deployments.

---

* paired with @TooTallNate 
* [user report](https://github.com/vercel/vercel/issues/9452#issuecomment-1432858615)
2023-03-16 18:00:56 +00:00
Nathan Rajlich
2e8423e24e [gatsby] Remove "gatsby" dependency, use typebox instead of ajv for validation (#9606)
The "gatsby" dependency is large and relies on native packages ("sharp" specifically, which are error prone because it attempts to download a precompiled binary, of which the CDN has been down before causing us to not be able to merge anything).

The package is only used for TypeScript types, and we've decided that including the package only for those types is not worth the trouble. The existing JSON schemas already validate at runtime that the Gatsby redux store provides the values that we depend on.

`ajv` was ditched in favor of TypeBox types, which provide both JSON Schema and validation using a simpler syntax.
2023-03-06 21:44:23 +00:00
Steven
1dd421e1f6 [build-utils][next] Add images.contentDispositionType (#9513)
- Related to https://github.com/vercel/next.js/pull/46254
- Depends on https://github.com/vercel/api/pull/17434
2023-02-22 20:13:16 -05:00
Nathan Rajlich
e24f42e9bc [gatsby-plugin-vercel-builder] Strip assetPrefix from pathPrefix (#9394)
Removes the `assetPrefix` value from the `pathPrefix` config value,
since Gatsby concats them for some reason.
2023-02-08 10:15:20 -06:00
Nathan Rajlich
6420e54b35 [gatsby-plugin-vercel-builder] Use pathPrefix from BuildArgs (#9362)
Instead of using `pathPrefix` from the Redux store, grab the value
directly from the "BuildArgs" passed to `onPostBuild()`. This value
seems to properly reflect whether or not `--prefix-path` mode was
enabled during the Gatsby build process.
2023-02-01 13:27:24 -07:00
Nathan Rajlich
aa6b957b23 [gatsby-plugin-vercel-builder] Move "public" dir instead of copying (#9356)
We are getting reports of some larger Gatsby projects running out of
disk space during build which seem to be the result of copying the
static directory multiple times.

So move instead of copying, which doesn't fully solve the problem, but
it does kick the can down the road a bit. Very large projects would
probably still hit the disk limit at some point. Anyways, moving is
faster than copying so this is still a net positive.
2023-02-01 11:05:45 -08:00
Nathan Rajlich
e3f326f714 [gatsby-plugin-vercel-builder] Don't delete .vercel/output (#9327)
`.vercel/output` is already made fresh when running `vc build`, so the
plugin should not be doing this. In fact, it makes the `builds.json`
file be wiped away, which we don't want to happen.
2023-01-27 09:08:22 -08:00
Ethan Arrowood
a4240e89e1 [gatsby-plugin-vercel-builder] add support for pathPrefix (#9294)
This pr adds support for the gatsby `pathPrefix`  properties
2023-01-24 23:37:03 +00:00
Nathan Rajlich
0863ae0c6f [gatsby-plugin-vercel-builder] Get rid of the _ssr function (#9304)
Right now we create the SSR serverless function at path `_ssr`, and then symlink all the other pages to that function.

Instead just make the first page encountered be the "real" function, and symlink all the other pages to that endpoint.
2023-01-24 22:10:43 +00:00
Nathan Rajlich
f5f544ffd2 [gatsby-plugin-vercel-builder] Merge SSR and page-data into single Serverless Function (#9292)
Previously, the page-data Serverless Function and SSR Serverless Function were two distinct functions. They had almost identical file contents and just slightly different handler logic. So here we merge the handler logic into a single function and re-use the same Serverless Function for both page-data and SSR.

This simplifies the output quite a bit and deletes a good amount of code, and helps with build output size, cold boot times, etc.
2023-01-24 19:36:47 +00:00
Nathan Rajlich
f535a20aad [gatsby-plugin-vercel-builder] Remove vercel.config.js file handling (#9290) 2023-01-23 21:31:49 +00:00
Ethan Arrowood
f35a77c292 [gatsby-plugin-vercel-builder] support trailingSlash configuration (#9278)
Connects the gatsby trailingslash configuration property to our BOA3
trailingslash property
2023-01-20 14:15:58 -07:00
Nathan Rajlich
6ea2db4ae9 [gatsby-plugin-vercel-builder] Various fixes and refactoring (#9268)
* Sets a valid number of seconds for DSG expiration (10 minutes - do we want to make that configurable somehow?)
* Sets the `group` of DSG pages, so that the page-data and SSR pages are associated
* Outputs SSR/DSG pages with `/index.html` suffix so that those paths are accessible
* Updates SSR and page-data functions URL path parsing logic to handle querystrings and the `index.html` scenario
* Remove the unnecessary `rewrite` related to page-data URL paths
* Remove the page-data function static file fallback handling (they are accessible as just regular static files)
* Correct the path for the page-data endpoing when the root-level index page is SSR/DSG
2023-01-20 18:49:44 +00:00
Nathan Rajlich
ed33c2b27c [gatsby-plugin-vercel-builder] Remove some leftover console.log calls (#9265) 2023-01-19 16:05:48 -08:00
Ethan Arrowood
ae89b8b8be [gatsby-plugin-vercel-builder] Implement @vercel/gatsby-plugin-vercel-builder (#9218)
<picture data-single-emoji=":gatsby:" title=":gatsby:"><img class="emoji" src="https://single-emoji.vercel.app/api/emoji/eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..Dli3tTuity9MEBnK.YyaiT9ASg3XvFmlx5q0Ovkdbkto2fgJGjIJhsLcraR_hqYG0DAC6CcBMiaARcI_hF0502EnqhkrHQLeYfEoxfomLi9iKk4WBAe-oSfsENsG9oAwzYdH4LA.VMtHCMaOXNOqpB2xvph3Kg" alt=":gatsby:" width="20" height="auto" align="absmiddle"></picture> 

Implement the Build Output API v3 Gatsby plugin for use within `@vercel/static-build`.

Supersedes https://github.com/vercel/vercel/pull/8259.
2023-01-18 02:24:32 +00:00