Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vercel): remove nodeVersion #3368

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-toes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Remove `nodeVersion` option for `serverless` target. Now it is inferred from Vercel
13 changes: 0 additions & 13 deletions packages/integrations/vercel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ import vercel from '@astrojs/vercel/serverless';
import vercel from '@astrojs/vercel/static';
```

### Node.js version

When deploying to `serverless` you can choose what version of Node.js you want to target: `12.x`, `14.x` or `16.x` (default).

```js
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
adapter: vercel({ nodeVersion: '14.x' })
});
```

## Limitations

**A few known complex packages (example: [puppeteer](https://github.com/puppeteer/puppeteer)) do not support bundling and therefore will not work properly with this adapter.** By default, Vercel doesn't include npm installed files & packages from your project's `./node_modules` folder. To address this, the `@astrojs/vercel` adapter automatically bundles your final build output using `esbuild`.
14 changes: 8 additions & 6 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ function getAdapter(): AstroAdapter {
};
}

export interface Options {
nodeVersion?: '12.x' | '14.x' | '16.x';
}

export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): AstroIntegration {
export default function vercelEdge(): AstroIntegration {
let _config: AstroConfig;
let functionFolder: URL;
let serverEntry: string;
Expand Down Expand Up @@ -57,7 +53,7 @@ export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): Astr
// Serverless function config
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/serverless-functions/configuration
await writeJson(new URL(`./.vc-config.json`, functionFolder), {
runtime: `nodejs${nodeVersion}`,
runtime: getRuntime(),
handler: serverEntry,
launcherType: 'Nodejs',
});
Expand All @@ -76,3 +72,9 @@ export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): Astr
},
};
}

function getRuntime() {
const version = process.version.slice(1); // 'v16.5.0' --> '16.5.0'
const major = version.split('.')[0]; // '16.5.0' --> '16'
return `nodejs${major}.x`;
}