-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(vercel): Build Output API v3 (#3216)
* Removed ignores * Migration to v3 * More changes * Remove legacy redirects * Fail when there is no ENABLE_VC_BUILD * Fix edge * Updated readme * Changeset * Added static mode * Updated documentation * Updated shim * Made edge work! * Updated changeset * Ensure empty dir * Fixed redirects for dynamic paths * Removed extra declaration * Splited imports * Updated readme * Fixed some urls * Deprecated shim! * [test]: Vercel NFT * Beautify * Edge bundle to node 14.19 Vercel runs 14.19.1 (I've checked it manually) * Re-added shim (#3304) * Added `node:` prefix * Use the same bundling as Deno for Edge * Remove esbuild * Fixed shim * Moved nft * Updated changeset * Added note about Edge * fix typo * Added support for Node 16 (vercel/vercel#7772)
- Loading branch information
Showing
42 changed files
with
659 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'@astrojs/vercel': minor | ||
--- | ||
|
||
|
||
**[BREAKING]** Now with Build Output API (v3)! [See the README to get started](https://github.com/withastro/astro/tree/main/packages/integrations/vercel#readme). | ||
|
||
- `trailingSlash` redirects works without a `vercel.json` file: just configure them inside your `astro.config.mjs` | ||
- Multiple deploy targets: `edge`, `serverless` and `static`! | ||
- When building to `serverless`, your code isn't transpiled to CJS anymore. | ||
|
||
**Migrate from v0.1** | ||
|
||
1. Change the import inside `astro.config.mjs`: | ||
```diff | ||
- import vercel from '@astrojs/vercel'; | ||
+ import vercel from '@astrojs/vercel/serverless'; | ||
``` | ||
2. Rename the `ENABLE_FILE_SYSTEM_API` environment variable to `ENABLE_VC_BUILD`, as Vercel changed it. | ||
3. The output folder changed from `.output` to `.vercel/output` — you may need to update your `.gitignore`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules/ | ||
dist/ | ||
.output/ | ||
*.tsbuildinfo | ||
.DS_Store | ||
.vercel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
# Deep Directories | ||
**/dist | ||
**/.output | ||
**/smoke | ||
**/node_modules | ||
**/fixtures | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# build output | ||
dist/ | ||
.output/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; | ||
|
||
import { writeJson, getVercelOutput } from '../lib/fs.js'; | ||
import { getRedirects } from '../lib/redirects.js'; | ||
|
||
const PACKAGE_NAME = '@astrojs/vercel/edge'; | ||
|
||
function getAdapter(): AstroAdapter { | ||
return { | ||
name: PACKAGE_NAME, | ||
serverEntrypoint: `${PACKAGE_NAME}/entrypoint`, | ||
exports: ['default'], | ||
}; | ||
} | ||
|
||
export default function vercelEdge(): AstroIntegration { | ||
let _config: AstroConfig; | ||
let functionFolder: URL; | ||
let serverEntry: string; | ||
|
||
return { | ||
name: PACKAGE_NAME, | ||
hooks: { | ||
'astro:config:setup': ({ config }) => { | ||
config.outDir = getVercelOutput(config.root); | ||
}, | ||
'astro:config:done': ({ setAdapter, config }) => { | ||
setAdapter(getAdapter()); | ||
_config = config; | ||
}, | ||
'astro:build:setup': ({ vite, target }) => { | ||
if (target === 'server') { | ||
vite.resolve ||= {}; | ||
vite.resolve.alias ||= {}; | ||
const alias = vite.resolve.alias as Record<string, string>; | ||
alias['react-dom/server'] = 'react-dom/server.browser'; | ||
vite.ssr = { | ||
noExternal: true, | ||
}; | ||
} | ||
}, | ||
'astro:build:start': async ({ buildConfig }) => { | ||
if (String(process.env.ENABLE_VC_BUILD) !== '1') { | ||
throw new Error( | ||
`The enviroment variable "ENABLE_VC_BUILD" was not found. Make sure you have it set to "1" in your Vercel project.\nLearn how to set enviroment variables here: https://vercel.com/docs/concepts/projects/environment-variables` | ||
); | ||
} | ||
|
||
buildConfig.serverEntry = serverEntry = 'entry.mjs'; | ||
buildConfig.client = new URL('./static/', _config.outDir); | ||
buildConfig.server = functionFolder = new URL('./functions/render.func/', _config.outDir); | ||
}, | ||
'astro:build:done': async ({ routes }) => { | ||
// Edge function config | ||
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions/configuration | ||
await writeJson(new URL(`./.vc-config.json`, functionFolder), { | ||
runtime: 'edge', | ||
entrypoint: serverEntry, | ||
}); | ||
|
||
// Output configuration | ||
// https://vercel.com/docs/build-output-api/v3#build-output-configuration | ||
await writeJson(new URL(`./config.json`, _config.outDir), { | ||
version: 3, | ||
routes: [ | ||
...getRedirects(routes, _config), | ||
{ handle: 'filesystem' }, | ||
{ src: '/.*', middlewarePath: 'render' }, | ||
], | ||
}); | ||
}, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.