mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
fix(vercel): Switch to node 18 when local version is not supported (#7718)
* fix(vercel): switch to node 18 when needed * fix types, reword * reorder sentences * add changeset * fix(vercel): switch to node 18 when needed * add referencce to vercel documentation --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
92382ea1d4
commit
35a0b6c8a9
2 changed files with 24 additions and 0 deletions
5
.changeset/gorgeous-ads-develop.md
Normal file
5
.changeset/gorgeous-ads-develop.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vercel': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
The vercel adapter now Warns when using a deprecated version of Node, and switches to 18 when using an unsupported version.
|
|
@ -19,6 +19,13 @@ const PACKAGE_NAME = '@astrojs/vercel/serverless';
|
||||||
export const ASTRO_LOCALS_HEADER = 'x-astro-locals';
|
export const ASTRO_LOCALS_HEADER = 'x-astro-locals';
|
||||||
export const VERCEL_EDGE_MIDDLEWARE_FILE = 'vercel-edge-middleware';
|
export const VERCEL_EDGE_MIDDLEWARE_FILE = 'vercel-edge-middleware';
|
||||||
|
|
||||||
|
// https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/node-js#node.js-version
|
||||||
|
const SUPPORTED_NODE_VERSIONS: Record<string, { status: 'current' } | { status: 'deprecated', removal: Date }> = {
|
||||||
|
14: { status: 'deprecated', removal: new Date('August 15 2023') },
|
||||||
|
16: { status: 'deprecated', removal: new Date('February 6 2024') },
|
||||||
|
18: { status: 'current' }
|
||||||
|
}
|
||||||
|
|
||||||
function getAdapter(): AstroAdapter {
|
function getAdapter(): AstroAdapter {
|
||||||
return {
|
return {
|
||||||
name: PACKAGE_NAME,
|
name: PACKAGE_NAME,
|
||||||
|
@ -193,5 +200,17 @@ export default function vercelServerless({
|
||||||
function getRuntime() {
|
function getRuntime() {
|
||||||
const version = process.version.slice(1); // 'v16.5.0' --> '16.5.0'
|
const version = process.version.slice(1); // 'v16.5.0' --> '16.5.0'
|
||||||
const major = version.split('.')[0]; // '16.5.0' --> '16'
|
const major = version.split('.')[0]; // '16.5.0' --> '16'
|
||||||
|
const support = SUPPORTED_NODE_VERSIONS[major]
|
||||||
|
if (support === undefined) {
|
||||||
|
console.warn(`[${PACKAGE_NAME}] The local Node.js version (${major}) is not supported by Vercel Serverless Functions.`)
|
||||||
|
console.warn(`[${PACKAGE_NAME}] Your project will use Node.js 18 as the runtime instead.`)
|
||||||
|
console.warn(`[${PACKAGE_NAME}] Consider switching your local version to 18.`)
|
||||||
|
return 'nodejs18.x';
|
||||||
|
}
|
||||||
|
if (support.status === 'deprecated') {
|
||||||
|
console.warn(`[${PACKAGE_NAME}] Your project is being built for Node.js ${major} as the runtime.`)
|
||||||
|
console.warn(`[${PACKAGE_NAME}] This version is deprecated by Vercel Serverless Functions, and scheduled to be disabled on ${new Intl.DateTimeFormat(undefined, { dateStyle: "long" }).format(support.removal)}.`)
|
||||||
|
console.warn(`[${PACKAGE_NAME}] Consider upgrading your local version to 18.`)
|
||||||
|
}
|
||||||
return `nodejs${major}.x`;
|
return `nodejs${major}.x`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue