Skip to content

Commit 1b5a659

Browse files
authored
Replace NEXT_BUILD_ID with OPEN_NEXT_BUILD_ID for consistency (#1144)
* fix: replace NEXT_BUILD_ID with OPEN_NEXT_BUILD_ID for consistency and backward compatibility * changeset * linting
1 parent d7286a3 commit 1b5a659

15 files changed

Lines changed: 42 additions & 29 deletions

File tree

.changeset/smooth-parts-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Deprecate NEXT_BUILD_ID env variable, and replace it with OPEN_NEXT_BUILD_ID

packages/open-next/src/adapters/config/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@ export const AppPathRoutesManifest =
4141
export const FunctionsConfigManifest =
4242
/* @__PURE__ */ loadFunctionsConfigManifest(NEXT_DIR);
4343

44+
/**
45+
* @deprecated Do not use NEXT_BUILD_ID above Next 16.2, as it could be a fixed value if used in conjonction with deploymentId
46+
* We keep it for backward compatibility
47+
*/
4448
process.env.NEXT_BUILD_ID = BuildId;
49+
process.env.OPEN_NEXT_BUILD_ID = NextConfig.deploymentId ?? BuildId;
4550
process.env.NEXT_PREVIEW_MODE_ID = PrerenderManifest?.preview?.previewModeId;

packages/open-next/src/overrides/cdnInvalidation/cloudfront.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
? [`/${path}`, `/${path}?_rsc=*`]
2020
: [
2121
`/${path}`,
22-
`/_next/data/${process.env.NEXT_BUILD_ID}${path === "/" ? "/index" : `/${path}`}.json*`,
22+
`/_next/data/${process.env.OPEN_NEXT_BUILD_ID}${path === "/" ? "/index" : `/${path}`}.json*`,
2323
];
2424
},
2525
);

packages/open-next/src/overrides/incrementalCache/fs-dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "node:path";
44
import type { IncrementalCache } from "types/overrides.js";
55
import { getMonorepoRelativePath } from "utils/normalize-path";
66

7-
const buildId = process.env.NEXT_BUILD_ID;
7+
const buildId = process.env.OPEN_NEXT_BUILD_ID;
88
const basePath = path.join(getMonorepoRelativePath(), `cache/${buildId}`);
99

1010
const getCacheKey = (key: string) => {

packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const awsFetch = (body: RequestInit["body"], type: "get" | "set" = "get") => {
4141
};
4242

4343
const buildDynamoKey = (key: string) => {
44-
const { NEXT_BUILD_ID } = process.env;
45-
return `__meta_${NEXT_BUILD_ID}_${key}`;
44+
const { OPEN_NEXT_BUILD_ID } = process.env;
45+
return `__meta_${OPEN_NEXT_BUILD_ID}_${key}`;
4646
};
4747

4848
/**

packages/open-next/src/overrides/incrementalCache/s3-lite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ const awsFetch = async (key: string, options: RequestInit) => {
3434
};
3535

3636
function buildS3Key(key: string, extension: Extension) {
37-
const { CACHE_BUCKET_KEY_PREFIX, NEXT_BUILD_ID } = process.env;
37+
const { CACHE_BUCKET_KEY_PREFIX, OPEN_NEXT_BUILD_ID } = process.env;
3838
return path.posix.join(
3939
CACHE_BUCKET_KEY_PREFIX ?? "",
4040
extension === "fetch" ? "__fetch" : "",
41-
NEXT_BUILD_ID ?? "",
41+
OPEN_NEXT_BUILD_ID ?? "",
4242
extension === "fetch" ? key : `${key}.${extension}`,
4343
);
4444
}

packages/open-next/src/overrides/incrementalCache/s3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { parseNumberFromEnv } from "../../adapters/util";
1616
const {
1717
CACHE_BUCKET_REGION,
1818
CACHE_BUCKET_KEY_PREFIX,
19-
NEXT_BUILD_ID,
19+
OPEN_NEXT_BUILD_ID,
2020
CACHE_BUCKET_NAME,
2121
} = process.env;
2222

@@ -34,7 +34,7 @@ function buildS3Key(key: string, extension: Extension) {
3434
return path.posix.join(
3535
CACHE_BUCKET_KEY_PREFIX ?? "",
3636
extension === "fetch" ? "__fetch" : "",
37-
NEXT_BUILD_ID ?? "",
37+
OPEN_NEXT_BUILD_ID ?? "",
3838
extension === "fetch" ? key : `${key}.${extension}`,
3939
);
4040
}

packages/open-next/src/overrides/tagCache/dynamodb-lite.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ const awsFetch = (
5151
};
5252

5353
function buildDynamoKey(key: string) {
54-
const { NEXT_BUILD_ID } = process.env;
54+
const { OPEN_NEXT_BUILD_ID } = process.env;
5555
// FIXME: We should probably use something else than path.join here
5656
// this could transform some fetch cache key into a valid path
57-
return path.posix.join(NEXT_BUILD_ID ?? "", key);
57+
return path.posix.join(OPEN_NEXT_BUILD_ID ?? "", key);
5858
}
5959

6060
function buildDynamoObject(
@@ -81,7 +81,7 @@ const tagCache: TagCache = {
8181
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
8282
return [];
8383
}
84-
const { CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
84+
const { CACHE_DYNAMO_TABLE, OPEN_NEXT_BUILD_ID } = process.env;
8585
const store = globalThis.__openNextAls.getStore();
8686
const cache = store?.requestCache.getOrCreate<string, string[]>(
8787
"dynamoDb:getByPath",
@@ -113,7 +113,7 @@ const tagCache: TagCache = {
113113
debug("tags for path", path, tags);
114114
// We need to remove the buildId from the path
115115
const resultTags = tags.map((tag: string) =>
116-
tag.replace(`${NEXT_BUILD_ID}/`, ""),
116+
tag.replace(`${OPEN_NEXT_BUILD_ID}/`, ""),
117117
);
118118
cache?.set(path, resultTags);
119119
return resultTags;
@@ -127,7 +127,7 @@ const tagCache: TagCache = {
127127
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
128128
return [];
129129
}
130-
const { CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
130+
const { CACHE_DYNAMO_TABLE, OPEN_NEXT_BUILD_ID } = process.env;
131131
const store = globalThis.__openNextAls.getStore();
132132
const cache = store?.requestCache.getOrCreate<string, string[]>(
133133
"dynamoDb:getByTag",
@@ -155,7 +155,7 @@ const tagCache: TagCache = {
155155
const paths =
156156
Items?.map(
157157
({ path: { S: key } }: any) =>
158-
key?.replace(`${NEXT_BUILD_ID}/`, "") ?? "",
158+
key?.replace(`${OPEN_NEXT_BUILD_ID}/`, "") ?? "",
159159
) ?? [];
160160
cache?.set(tag, paths);
161161
return paths;

packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ const awsFetch = (
5050
};
5151

5252
function buildDynamoKey(key: string) {
53-
const { NEXT_BUILD_ID } = process.env;
53+
const { OPEN_NEXT_BUILD_ID } = process.env;
5454
// FIXME: We should probably use something else than path.join here
5555
// this could transform some fetch cache key into a valid path
56-
return path.posix.join(NEXT_BUILD_ID ?? "", "_tag", key);
56+
return path.posix.join(OPEN_NEXT_BUILD_ID ?? "", "_tag", key);
5757
}
5858

5959
// We use the same key for both path and tag

packages/open-next/src/overrides/tagCache/dynamodb.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
getDynamoBatchWriteCommandConcurrency,
1616
} from "./constants";
1717

18-
const { CACHE_BUCKET_REGION, CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
18+
const { CACHE_BUCKET_REGION, CACHE_DYNAMO_TABLE, OPEN_NEXT_BUILD_ID } =
19+
process.env;
1920

2021
function parseDynamoClientConfigFromEnv(): DynamoDBClientConfig {
2122
return {
@@ -30,7 +31,7 @@ const dynamoClient = new DynamoDBClient(parseDynamoClientConfigFromEnv());
3031
function buildDynamoKey(key: string) {
3132
// FIXME: We should probably use something else than path.join here
3233
// this could transform some fetch cache key into a valid path
33-
return path.posix.join(NEXT_BUILD_ID ?? "", key);
34+
return path.posix.join(OPEN_NEXT_BUILD_ID ?? "", key);
3435
}
3536

3637
function buildDynamoObject(
@@ -81,7 +82,7 @@ const tagCache: TagCache = {
8182
debug("tags for path", path, tags);
8283
// We need to remove the buildId from the path
8384
const resultTags = tags.map((tag) =>
84-
tag.replace(`${NEXT_BUILD_ID}/`, ""),
85+
tag.replace(`${OPEN_NEXT_BUILD_ID}/`, ""),
8586
);
8687
cache?.set(path, resultTags);
8788
return resultTags;
@@ -117,7 +118,8 @@ const tagCache: TagCache = {
117118
// We need to remove the buildId from the path
118119
const paths =
119120
Items?.map(
120-
({ path: { S: key } }) => key?.replace(`${NEXT_BUILD_ID}/`, "") ?? "",
121+
({ path: { S: key } }) =>
122+
key?.replace(`${OPEN_NEXT_BUILD_ID}/`, "") ?? "",
121123
) ?? [];
122124
cache?.set(tag, paths);
123125
return paths;

0 commit comments

Comments
 (0)