Skip to content

Commit 1cb97ef

Browse files
committed
Make min version check work with versionRanges
1 parent 49b7393 commit 1cb97ef

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

packages/runtime/src/index.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ function isLegacyNext(nextVersion: string) {
197197
/**
198198
* Check if the target: `server` can be used to build the app
199199
*/
200-
function isServerTargetNext(nextVersion: string): boolean {
201-
if (nextVersion === 'canary' || nextVersion === 'latest') {
200+
function isServerTargetNext(nextVersionRange: string): boolean {
201+
if (nextVersionRange === 'canary' || nextVersionRange === 'latest') {
202202
return true;
203203
}
204204

205-
return semver.gte(nextVersion, NextServerTargetVersion);
205+
// >= NextServerTargetVersion
206+
return !semver.gtr(NextServerTargetVersion, nextVersionRange);
206207
}
207208

208209
const name = '[@vercel/next]';
@@ -262,9 +263,6 @@ export async function build({
262263
const nodeVersion = await getNodeVersion(entryPath, undefined, config, meta);
263264
const spawnOpts = getSpawnOptions(meta, nodeVersion);
264265

265-
const isServerTarget =
266-
nextVersionRange && isServerTargetNext(nextVersionRange);
267-
268266
// Add Vercel build environment variables that some dependencies need
269267
// to determine a Vercel like build environment
270268
spawnOpts.env = {
@@ -276,15 +274,6 @@ export async function build({
276274
INIT_CWD: entryPath,
277275
};
278276

279-
// Next.js changed the default output folder beginning with
280-
// 10.0.8-canary.15 from `.next/serverless` to `.next/server`.
281-
// This is an opt-out of this behavior for older versions.
282-
// https://github.com/dealmore/terraform-aws-next-js/issues/86
283-
// https://github.com/vercel/next.js/pull/22731
284-
if (!isServerTarget) {
285-
spawnOpts.env['NEXT_PRIVATE_TARGET'] = 'experimental-serverless-trace';
286-
}
287-
288277
const nowJsonPath = await findUp(['now.json', 'vercel.json'], {
289278
cwd: entryPath,
290279
});
@@ -363,8 +352,9 @@ export async function build({
363352
console.warn('WARNING: You should not upload the `.next` directory.');
364353
}
365354

366-
const isLegacy =
367-
!isServerTarget && nextVersionRange && isLegacyNext(nextVersionRange);
355+
const isServerTarget =
356+
nextVersionRange && isServerTargetNext(nextVersionRange);
357+
const isLegacy = nextVersionRange && isLegacyNext(nextVersionRange);
368358
debug(
369359
`MODE: ${
370360
isServerTarget ? 'server(less)' : isLegacy ? 'legacy' : 'serverless'
@@ -465,6 +455,15 @@ export async function build({
465455
const env: typeof process.env = { ...spawnOpts.env };
466456
env.NODE_OPTIONS = `--max_old_space_size=${memoryToConsume}`;
467457

458+
// Next.js changed the default output folder beginning with
459+
// 10.0.8-canary.15 from `.next/serverless` to `.next/server`.
460+
// This is an opt-out of this behavior for older versions.
461+
// https://github.com/dealmore/terraform-aws-next-js/issues/86
462+
// https://github.com/vercel/next.js/pull/22731
463+
if (!isServerTarget) {
464+
env.NEXT_PRIVATE_TARGET = 'experimental-serverless-trace';
465+
}
466+
468467
if (buildCommand) {
469468
// Add `node_modules/.bin` to PATH
470469
const nodeBinPath = await getNodeBinPath({ cwd: entryPath });

0 commit comments

Comments
 (0)