Skip to content

Commit eb88ced

Browse files
committed
remove useless call and import
1 parent fbe09ae commit eb88ced

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

packages/open-next/src/build/createServerBundle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
patchUnstableCacheForISR,
2323
} from "./patch/patchFetchCacheISR.js";
2424
import { patchFetchCacheSetMissingWaitUntil } from "./patch/patchFetchCacheWaitUntil.js";
25+
import { patchEnvVars, patchNextServer } from "./patch/patchNextServer.js";
2526

2627
interface CodeCustomization {
2728
// These patches are meant to apply on user and next generated code
@@ -187,6 +188,8 @@ async function generateBundle(
187188
patchFetchCacheSetMissingWaitUntil,
188189
patchFetchCacheForISR,
189190
patchUnstableCacheForISR,
191+
patchNextServer,
192+
patchEnvVars,
190193
...additionalCodePatches,
191194
]);
192195

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { createPatchCode } from "./astCodePatcher.js";
2+
import type { CodePatcher } from "./codePatcher";
3+
4+
export const minimalRule = `
5+
rule:
6+
kind: member_expression
7+
pattern: process.env.NEXT_MINIMAL
8+
any:
9+
- inside:
10+
kind: parenthesized_expression
11+
stopBy: end
12+
inside:
13+
kind: if_statement
14+
any:
15+
- inside:
16+
kind: statement_block
17+
inside:
18+
kind: method_definition
19+
any:
20+
- has: {kind: property_identifier, field: name, regex: runEdgeFunction}
21+
- has: {kind: property_identifier, field: name, regex: runMiddleware}
22+
- has: {kind: property_identifier, field: name, regex: imageOptimizer}
23+
- has:
24+
kind: statement_block
25+
has:
26+
kind: expression_statement
27+
pattern: res.statusCode = 400;
28+
fix:
29+
'true'
30+
`;
31+
32+
export const disablePreloadingRule = `
33+
rule:
34+
kind: statement_block
35+
inside:
36+
kind: if_statement
37+
any:
38+
- has:
39+
kind: member_expression
40+
pattern: this.nextConfig.experimental.preloadEntriesOnStart
41+
stopBy: end
42+
- has:
43+
kind: binary_expression
44+
pattern: appDocumentPreloading === true
45+
stopBy: end
46+
fix:
47+
'{}'
48+
`;
49+
50+
const envVarRuleCreator = (envVar: string, value: string) => `
51+
rule:
52+
kind: member_expression
53+
pattern: process.env.${envVar}
54+
inside:
55+
kind: if_statement
56+
stopBy: end
57+
fix:
58+
'${value}'
59+
`;
60+
61+
export const patchNextServer: CodePatcher = {
62+
name: "patch-next-server",
63+
patches: [
64+
{
65+
versions: ">=15.0.0",
66+
field: {
67+
pathFilter: /next-server\.(js)$/,
68+
contentFilter: /process\.env\.NEXT_MINIMAL/,
69+
patchCode: createPatchCode(minimalRule),
70+
},
71+
},
72+
{
73+
versions: ">=15.0.0",
74+
field: {
75+
pathFilter: /next-server\.(js)$/,
76+
contentFilter: /this\.nextConfig\.experimental\.preloadEntriesOnStart/,
77+
patchCode: createPatchCode(disablePreloadingRule),
78+
},
79+
},
80+
],
81+
};
82+
83+
export const patchEnvVars: CodePatcher = {
84+
name: "patch-env-vars",
85+
patches: [
86+
{
87+
versions: ">=15.0.0",
88+
field: {
89+
pathFilter: /module\.compiled\.js$/,
90+
contentFilter: /process\.env\.NEXT_RUNTIME/,
91+
patchCode: createPatchCode(envVarRuleCreator("NEXT_RUNTIME", '"node"')),
92+
},
93+
},
94+
{
95+
versions: ">=15.0.0",
96+
field: {
97+
pathFilter:
98+
/(module\.compiled|react\/index|react\/jsx-runtime|react-dom\/index)\.js$/,
99+
contentFilter: /process\.env\.NODE_ENV/,
100+
patchCode: createPatchCode(
101+
envVarRuleCreator("NODE_ENV", '"production"'),
102+
),
103+
},
104+
},
105+
{
106+
versions: ">=15.0.0",
107+
field: {
108+
pathFilter: /module\.compiled\.js$/,
109+
contentFilter: /process\.env\.TURBOPACK/,
110+
patchCode: createPatchCode(envVarRuleCreator("TURBOPACK", "false")),
111+
},
112+
},
113+
],
114+
};

0 commit comments

Comments
 (0)