Skip to content

Commit 583c052

Browse files
authored
Add Next.js adapter opt-in behind flag (#14574)
This adds an opt-in flag for new [Vercel deployment adapter](https://github.com/nextjs/adapter-vercel)
1 parent b62058a commit 583c052

File tree

5 files changed

+477
-2
lines changed

5 files changed

+477
-2
lines changed

.changeset/nervous-dancers-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vercel/next': patch
3+
---
4+
5+
Add Next.js adapter opt-in behind flag

packages/next/build.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { copy } from 'fs-extra';
12
import { readFileSync, promises as fsPromises } from 'node:fs';
23
import { createRequire } from 'node:module';
3-
import { join } from 'node:path';
4+
import { dirname, join } from 'node:path';
45

56
import { esbuild } from '../../utils/build.mjs';
67
import buildEdgeFunctionTemplate from './scripts/build-edge-function-template.js';
@@ -46,6 +47,14 @@ await copyFile(
4647
join(process.cwd(), 'dist/mappings.wasm')
4748
);
4849

50+
await copy(
51+
join(
52+
dirname(require.resolve('@next-community/adapter-vercel/package.json')),
53+
'dist'
54+
),
55+
join(process.cwd(), 'dist/adapter')
56+
);
57+
4958
await esbuild({
5059
bundle: true,
5160
external: ['@vercel/build-utils', ...externals],

packages/next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@vercel/nft": "1.1.1"
2727
},
2828
"devDependencies": {
29+
"@next-community/adapter-vercel": "0.0.1-beta.1",
2930
"@types/aws-lambda": "8.10.19",
3031
"@types/buffer-crc32": "0.2.0",
3132
"@types/bytes": "3.1.1",

packages/next/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,17 @@ export const build: BuildV2 = async buildOptions => {
508508
env.NODE_ENV = 'production';
509509
}
510510

511+
if (
512+
// integration tests expect outputs object
513+
!process.env.NEXT_BUILDER_INTEGRATION &&
514+
process.env.NEXT_ENABLE_ADAPTER
515+
// TODO: replace above opt-in with Next.js version
516+
// semver.gte(nextVersion, '16.1.1-canary.18', { includePrerelease: true })
517+
) {
518+
env.NEXT_ADAPTER_PATH = path.join(__dirname, 'adapter/index.js');
519+
env.NEXT_ADAPTER_VERCEL_CONFIG = JSON.stringify(config);
520+
}
521+
511522
const shouldRunCompileStep =
512523
Boolean(buildCommand) || Boolean(buildScriptName);
513524

@@ -578,7 +589,7 @@ export const build: BuildV2 = async buildOptions => {
578589

579590
if (buildOutputVersion) {
580591
return {
581-
buildOutputPath: path.join(outputDirectory, 'output'),
592+
buildOutputPath: path.join(entryPath, outputDirectory, 'output'),
582593
buildOutputVersion,
583594
} as BuildResultBuildOutput;
584595
}

0 commit comments

Comments
 (0)