Skip to content

Commit

Permalink
feat(vercel): remove nodeVersion (#3368)
Browse files Browse the repository at this point in the history
* Remove `nodeVersion`

* Changeset
  • Loading branch information
JuanM04 authored May 16, 2022
1 parent 9dd16ba commit 9d01f93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
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`;
}

0 comments on commit 9d01f93

Please sign in to comment.