@opennextjs/aws 3.9.8 → 3.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/createServerBundle.js +0 -1
- package/dist/build/patch/patches/index.d.ts +1 -1
- package/dist/build/patch/patches/index.js +1 -1
- package/dist/build/patch/patches/patchOriginalNextConfig.d.ts +12 -0
- package/dist/build/patch/patches/patchOriginalNextConfig.js +82 -0
- package/dist/build.js +3 -0
- package/dist/plugins/inline-require-resolve.d.ts +10 -0
- package/dist/plugins/inline-require-resolve.js +27 -0
- package/package.json +1 -1
- package/dist/build/patch/patches/patchNextConfig.d.ts +0 -2
- package/dist/build/patch/patches/patchNextConfig.js +0 -54
|
@@ -127,7 +127,6 @@ async function generateBundle(name, options, fnOptions, codeCustomization) {
|
|
|
127
127
|
patches.patchBackgroundRevalidation,
|
|
128
128
|
patches.patchUseCacheForISR,
|
|
129
129
|
patches.patchNodeEnvironment,
|
|
130
|
-
patches.patchNextConfig,
|
|
131
130
|
...additionalCodePatches,
|
|
132
131
|
]);
|
|
133
132
|
// Build Lambda code
|
|
@@ -4,4 +4,4 @@ export { patchFetchCacheForISR, patchUnstableCacheForISR, patchUseCacheForISR, }
|
|
|
4
4
|
export { patchFetchCacheSetMissingWaitUntil } from "./patchFetchCacheWaitUntil.js";
|
|
5
5
|
export { patchBackgroundRevalidation } from "./patchBackgroundRevalidation.js";
|
|
6
6
|
export { patchNodeEnvironment } from "./patchNodeEnvironment.js";
|
|
7
|
-
export {
|
|
7
|
+
export { patchOriginalNextConfig } from "./patchOriginalNextConfig.js";
|
|
@@ -4,4 +4,4 @@ export { patchFetchCacheForISR, patchUnstableCacheForISR, patchUseCacheForISR, }
|
|
|
4
4
|
export { patchFetchCacheSetMissingWaitUntil } from "./patchFetchCacheWaitUntil.js";
|
|
5
5
|
export { patchBackgroundRevalidation } from "./patchBackgroundRevalidation.js";
|
|
6
6
|
export { patchNodeEnvironment } from "./patchNodeEnvironment.js";
|
|
7
|
-
export {
|
|
7
|
+
export { patchOriginalNextConfig } from "./patchOriginalNextConfig.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as buildHelper from "../../helper.js";
|
|
2
|
+
/**
|
|
3
|
+
* Next 16.1.0-16.1.4 has missing fields in `required-server-files.json`:
|
|
4
|
+
* - `skipTrailingSlashRedirect`
|
|
5
|
+
* - `serverExternalPackages`
|
|
6
|
+
*
|
|
7
|
+
* This patch adds them back in by compiling and importing the user's `next.config.js` file.
|
|
8
|
+
*
|
|
9
|
+
* It is a regression in https://github.com/vercel/next.js/pull/86830 (16.1.0)
|
|
10
|
+
* Fixed in https://github.com/vercel/next.js/pull/88733 (16.1.4)
|
|
11
|
+
*/
|
|
12
|
+
export declare function patchOriginalNextConfig(options: buildHelper.BuildOptions): Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { build } from "esbuild";
|
|
4
|
+
import { inlineRequireResolvePlugin } from "../../../plugins/inline-require-resolve.js";
|
|
5
|
+
import * as buildHelper from "../../helper.js";
|
|
6
|
+
/**
|
|
7
|
+
* Next 16.1.0-16.1.4 has missing fields in `required-server-files.json`:
|
|
8
|
+
* - `skipTrailingSlashRedirect`
|
|
9
|
+
* - `serverExternalPackages`
|
|
10
|
+
*
|
|
11
|
+
* This patch adds them back in by compiling and importing the user's `next.config.js` file.
|
|
12
|
+
*
|
|
13
|
+
* It is a regression in https://github.com/vercel/next.js/pull/86830 (16.1.0)
|
|
14
|
+
* Fixed in https://github.com/vercel/next.js/pull/88733 (16.1.4)
|
|
15
|
+
*/
|
|
16
|
+
export async function patchOriginalNextConfig(options) {
|
|
17
|
+
if (buildHelper.compareSemver(options.nextVersion, "<", "16.1.0") ||
|
|
18
|
+
buildHelper.compareSemver(options.nextVersion, ">=", "16.1.4")) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// The manifests in both `.next` and `.next/standalone` folders
|
|
22
|
+
// are patched as Open Next uses either of them.
|
|
23
|
+
const manifestPath = path.join(options.appBuildOutputPath, ".next/required-server-files.json");
|
|
24
|
+
const manifestStandalonePath = path.join(options.appBuildOutputPath, ".next/standalone", buildHelper.getPackagePath(options), ".next/required-server-files.json");
|
|
25
|
+
if (fs.existsSync(manifestPath)) {
|
|
26
|
+
const manifest = JSON.parse(await fs.promises.readFile(manifestPath, "utf-8"));
|
|
27
|
+
if (manifest.config.skipTrailingSlashRedirect === undefined) {
|
|
28
|
+
const { skipTrailingSlashRedirect, serverExternalPackages } = await importNextConfigFromSource(options);
|
|
29
|
+
manifest.config.skipTrailingSlashRedirect =
|
|
30
|
+
skipTrailingSlashRedirect ?? false;
|
|
31
|
+
manifest.config.serverExternalPackages = serverExternalPackages ?? [];
|
|
32
|
+
await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
|
|
33
|
+
if (fs.existsSync(manifestStandalonePath)) {
|
|
34
|
+
await fs.promises.writeFile(manifestStandalonePath, JSON.stringify(manifest, null, 2), "utf-8");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error(`Could not find required-server-files.json at path: ${manifestPath}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Compile and import the user's `next.config` file
|
|
44
|
+
*
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
async function importNextConfigFromSource(buildOptions) {
|
|
48
|
+
// Find the `next.config file with any supported extension
|
|
49
|
+
const tsExtensions = [".ts", ".mts", ".cts"];
|
|
50
|
+
const possibleExtensions = [...tsExtensions, ".mjs", ".js", ".cjs"];
|
|
51
|
+
let configPath;
|
|
52
|
+
let configExtension;
|
|
53
|
+
for (const ext of possibleExtensions) {
|
|
54
|
+
const testPath = path.join(buildOptions.appPath, `next.config${ext}`);
|
|
55
|
+
if (fs.existsSync(testPath)) {
|
|
56
|
+
configPath = testPath;
|
|
57
|
+
configExtension = ext;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!configPath || !configExtension) {
|
|
62
|
+
throw new Error("Could not find next.config file");
|
|
63
|
+
}
|
|
64
|
+
let configToImport;
|
|
65
|
+
// Only compile if the extension is a TypeScript extension
|
|
66
|
+
if (tsExtensions.includes(configExtension)) {
|
|
67
|
+
await build({
|
|
68
|
+
entryPoints: [configPath],
|
|
69
|
+
outfile: path.join(buildOptions.tempBuildDir, "next.config.mjs"),
|
|
70
|
+
bundle: true,
|
|
71
|
+
format: "esm",
|
|
72
|
+
platform: "node",
|
|
73
|
+
plugins: [inlineRequireResolvePlugin],
|
|
74
|
+
});
|
|
75
|
+
configToImport = path.join(buildOptions.tempBuildDir, "next.config.mjs");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// For .js, .mjs, .cjs, use the file directly
|
|
79
|
+
configToImport = configPath;
|
|
80
|
+
}
|
|
81
|
+
return (await import(configToImport)).default;
|
|
82
|
+
}
|
package/dist/build.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createServerBundle } from "./build/createServerBundle.js";
|
|
|
12
12
|
import { createWarmerBundle } from "./build/createWarmerBundle.js";
|
|
13
13
|
import { generateOutput } from "./build/generateOutput.js";
|
|
14
14
|
import * as buildHelper from "./build/helper.js";
|
|
15
|
+
import { patchOriginalNextConfig } from "./build/patch/patches/index.js";
|
|
15
16
|
import { printHeader, showWarningOnWindows } from "./build/utils.js";
|
|
16
17
|
import logger from "./logger.js";
|
|
17
18
|
export async function build(openNextConfigPath, nodeExternals) {
|
|
@@ -33,6 +34,8 @@ export async function build(openNextConfigPath, nodeExternals) {
|
|
|
33
34
|
buildNextjsApp(options);
|
|
34
35
|
// Generate deployable bundle
|
|
35
36
|
printHeader("Generating bundle");
|
|
37
|
+
// Patch the original Next.js config
|
|
38
|
+
await patchOriginalNextConfig(options);
|
|
36
39
|
// Compile cache.ts
|
|
37
40
|
compileCache(options);
|
|
38
41
|
// Compile middleware
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from "esbuild";
|
|
2
|
+
/**
|
|
3
|
+
* Inlines calls to `require.resolve` in JavaScript files.
|
|
4
|
+
*
|
|
5
|
+
* esbuild does not statically analyse `require.resolve` calls, and the polyfill
|
|
6
|
+
* does not include an implementation to handle them. This can be problematic
|
|
7
|
+
* if you attempt to dynamically import a file built by esbuild that unknowingly
|
|
8
|
+
* contains `require.resolve` calls, as they will throw an error during import.
|
|
9
|
+
*/
|
|
10
|
+
export declare const inlineRequireResolvePlugin: Plugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
/**
|
|
4
|
+
* Inlines calls to `require.resolve` in JavaScript files.
|
|
5
|
+
*
|
|
6
|
+
* esbuild does not statically analyse `require.resolve` calls, and the polyfill
|
|
7
|
+
* does not include an implementation to handle them. This can be problematic
|
|
8
|
+
* if you attempt to dynamically import a file built by esbuild that unknowingly
|
|
9
|
+
* contains `require.resolve` calls, as they will throw an error during import.
|
|
10
|
+
*/
|
|
11
|
+
export const inlineRequireResolvePlugin = {
|
|
12
|
+
name: "inline-require-resolve",
|
|
13
|
+
setup: (build) => {
|
|
14
|
+
build.onLoad({ filter: /\.(js|ts|mjs|cjs)$/ }, async (args) => {
|
|
15
|
+
const source = await fs.promises.readFile(args.path, "utf-8");
|
|
16
|
+
const transformed = source.replace(/require\.resolve\((?<quote>['"])((?:\\.|.)*?)\k<quote>\)/g, (_, quote, modulePath) => {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.stringify(createRequire(args.path).resolve(modulePath));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return `require.resolve(${quote}${modulePath}${quote})`;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return { contents: transformed, loader: "default" };
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { buildSync } from "esbuild";
|
|
4
|
-
export const patchNextConfig = {
|
|
5
|
-
name: "patch-next-config",
|
|
6
|
-
patches: [
|
|
7
|
-
{
|
|
8
|
-
pathFilter: /required\-server\-files\.json$/,
|
|
9
|
-
versions: ">=16.1.0",
|
|
10
|
-
patchCode: async ({ code, buildOptions }) => {
|
|
11
|
-
// Find the next.config file with any supported extension
|
|
12
|
-
const tsExtensions = [".ts", ".mts", ".cts"];
|
|
13
|
-
const possibleExtensions = [...tsExtensions, ".mjs", ".js", ".cjs"];
|
|
14
|
-
let configPath;
|
|
15
|
-
let configExtension;
|
|
16
|
-
for (const ext of possibleExtensions) {
|
|
17
|
-
const testPath = path.join(buildOptions.appPath, `next.config${ext}`);
|
|
18
|
-
if (fs.existsSync(testPath)) {
|
|
19
|
-
configPath = testPath;
|
|
20
|
-
configExtension = ext;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (!configPath || !configExtension) {
|
|
25
|
-
throw new Error("Could not find next.config file");
|
|
26
|
-
}
|
|
27
|
-
let configToImport;
|
|
28
|
-
// Only compile if the extension is a TypeScript extension
|
|
29
|
-
if (tsExtensions.includes(configExtension)) {
|
|
30
|
-
buildSync({
|
|
31
|
-
entryPoints: [configPath],
|
|
32
|
-
outfile: path.join(buildOptions.tempBuildDir, "next.config.mjs"),
|
|
33
|
-
bundle: true,
|
|
34
|
-
format: "esm",
|
|
35
|
-
platform: "node",
|
|
36
|
-
});
|
|
37
|
-
configToImport = path.join(buildOptions.tempBuildDir, "next.config.mjs");
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// For .js, .mjs, .cjs, use the file directly
|
|
41
|
-
configToImport = configPath;
|
|
42
|
-
}
|
|
43
|
-
// In next 16.1+ we need to add `skipTrailingSlashRedirect` manually because next removes it from the config
|
|
44
|
-
const originalConfig = (await import(configToImport)).default;
|
|
45
|
-
const config = JSON.parse(code);
|
|
46
|
-
if (config.config.skipTrailingSlashRedirect === undefined) {
|
|
47
|
-
config.config.skipTrailingSlashRedirect =
|
|
48
|
-
originalConfig.skipTrailingSlashRedirect ?? false;
|
|
49
|
-
}
|
|
50
|
-
return JSON.stringify(config, null, 2);
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
};
|