@opennextjs/aws 3.5.2 → 3.5.4
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/adapters/config/util.d.ts +1 -0
- package/dist/adapters/config/util.js +5 -2
- package/dist/adapters/logger.js +1 -1
- package/dist/build/compileCache.js +1 -1
- package/dist/build/compileConfig.d.ts +6 -2
- package/dist/build/compileConfig.js +8 -7
- package/dist/build/constant.d.ts +1 -0
- package/dist/build/constant.js +1 -0
- package/dist/build/copyTracedFiles.d.ts +21 -1
- package/dist/build/copyTracedFiles.js +28 -5
- package/dist/build/createImageOptimizationBundle.js +1 -1
- package/dist/build/createMiddleware.js +1 -0
- package/dist/build/createServerBundle.d.ts +9 -1
- package/dist/build/createServerBundle.js +39 -15
- package/dist/build/edge/createEdgeBundle.d.ts +9 -2
- package/dist/build/edge/createEdgeBundle.js +28 -17
- package/dist/build/helper.d.ts +3 -2
- package/dist/build/helper.js +45 -20
- package/dist/build/patch/astCodePatcher.d.ts +58 -0
- package/dist/build/patch/astCodePatcher.js +76 -0
- package/dist/build/patch/codePatcher.d.ts +46 -0
- package/dist/build/patch/codePatcher.js +119 -0
- package/dist/build/patch/patchFetchCacheISR.d.ts +5 -0
- package/dist/build/patch/patchFetchCacheISR.js +102 -0
- package/dist/build/patch/patchFetchCacheWaitUntil.d.ts +3 -0
- package/dist/build/patch/patchFetchCacheWaitUntil.js +36 -0
- package/dist/build.js +1 -1
- package/dist/core/requestHandler.js +3 -1
- package/dist/core/routing/cacheInterceptor.js +6 -1
- package/dist/core/routing/middleware.js +12 -2
- package/dist/core/routing/queue.d.ts +1 -0
- package/dist/core/routing/queue.js +12 -8
- package/dist/core/routing/util.js +3 -3
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +2 -0
- package/dist/overrides/wrappers/express-dev.js +2 -0
- package/dist/overrides/wrappers/node.js +0 -1
- package/dist/plugins/content-updater.d.ts +48 -0
- package/dist/plugins/content-updater.js +65 -0
- package/dist/plugins/edge.d.ts +3 -3
- package/dist/plugins/edge.js +18 -8
- package/dist/types/next-types.d.ts +3 -0
- package/dist/types/overrides.d.ts +2 -0
- package/package.json +4 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESBuild stops calling `onLoad` hooks after the first hook returns an updated content.
|
|
3
|
+
*
|
|
4
|
+
* The updater allows multiple plugins to update the content.
|
|
5
|
+
*/
|
|
6
|
+
import type { OnLoadOptions, Plugin, PluginBuild } from "esbuild";
|
|
7
|
+
import type { BuildOptions } from "../build/helper";
|
|
8
|
+
import { type VersionedField } from "../build/patch/codePatcher.js";
|
|
9
|
+
export type * from "esbuild";
|
|
10
|
+
/**
|
|
11
|
+
* The callbacks returns either an updated content or undefined if the content is unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export type Callback = (args: {
|
|
14
|
+
contents: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}) => string | undefined | Promise<string | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* The callback is called only when `contentFilter` matches the content.
|
|
19
|
+
* It can be used as a fast heuristic to prevent an expensive update.
|
|
20
|
+
*/
|
|
21
|
+
export type OnUpdateOptions = OnLoadOptions & {
|
|
22
|
+
contentFilter: RegExp;
|
|
23
|
+
};
|
|
24
|
+
export type Updater = OnUpdateOptions & {
|
|
25
|
+
callback: Callback;
|
|
26
|
+
};
|
|
27
|
+
export declare class ContentUpdater {
|
|
28
|
+
private buildOptions;
|
|
29
|
+
updaters: Map<string, Updater[]>;
|
|
30
|
+
constructor(buildOptions: BuildOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Register a callback to update the file content.
|
|
33
|
+
*
|
|
34
|
+
* The callbacks are called in order of registration.
|
|
35
|
+
*
|
|
36
|
+
* @param name The name of the plugin (must be unique).
|
|
37
|
+
* @param updater A versioned field with the callback and `OnUpdateOptions`.
|
|
38
|
+
* @returns A noop ESBuild plugin.
|
|
39
|
+
*/
|
|
40
|
+
updateContent(name: string, versionedUpdaters: VersionedField<Updater>[]): Plugin;
|
|
41
|
+
/**
|
|
42
|
+
* Returns an ESBuild plugin applying the registered updates.
|
|
43
|
+
*/
|
|
44
|
+
get plugin(): {
|
|
45
|
+
name: string;
|
|
46
|
+
setup: (build: PluginBuild) => Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESBuild stops calling `onLoad` hooks after the first hook returns an updated content.
|
|
3
|
+
*
|
|
4
|
+
* The updater allows multiple plugins to update the content.
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { extractVersionedField, } from "../build/patch/codePatcher.js";
|
|
8
|
+
export class ContentUpdater {
|
|
9
|
+
buildOptions;
|
|
10
|
+
updaters = new Map();
|
|
11
|
+
constructor(buildOptions) {
|
|
12
|
+
this.buildOptions = buildOptions;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Register a callback to update the file content.
|
|
16
|
+
*
|
|
17
|
+
* The callbacks are called in order of registration.
|
|
18
|
+
*
|
|
19
|
+
* @param name The name of the plugin (must be unique).
|
|
20
|
+
* @param updater A versioned field with the callback and `OnUpdateOptions`.
|
|
21
|
+
* @returns A noop ESBuild plugin.
|
|
22
|
+
*/
|
|
23
|
+
updateContent(name, versionedUpdaters) {
|
|
24
|
+
if (this.updaters.has(name)) {
|
|
25
|
+
throw new Error(`Plugin "${name}" already registered`);
|
|
26
|
+
}
|
|
27
|
+
const updaters = extractVersionedField(versionedUpdaters, this.buildOptions.nextVersion);
|
|
28
|
+
this.updaters.set(name, updaters);
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
setup() { },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns an ESBuild plugin applying the registered updates.
|
|
36
|
+
*/
|
|
37
|
+
get plugin() {
|
|
38
|
+
return {
|
|
39
|
+
name: "aggregate-on-load",
|
|
40
|
+
setup: async (build) => {
|
|
41
|
+
build.onLoad({ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/ }, async (args) => {
|
|
42
|
+
const updaters = Array.from(this.updaters.values()).flat();
|
|
43
|
+
if (updaters.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let contents = await readFile(args.path, "utf-8");
|
|
47
|
+
for (const { filter, namespace, contentFilter, callback, } of updaters) {
|
|
48
|
+
if (namespace !== undefined && args.namespace !== namespace) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!args.path.match(filter)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!contents.match(contentFilter)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
contents =
|
|
58
|
+
(await callback({ contents, path: args.path })) ?? contents;
|
|
59
|
+
}
|
|
60
|
+
return { contents };
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/plugins/edge.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import type { MiddlewareInfo } from "../types/next-types.js";
|
|
|
3
3
|
export interface IPluginSettings {
|
|
4
4
|
nextDir: string;
|
|
5
5
|
middlewareInfo?: MiddlewareInfo;
|
|
6
|
-
|
|
6
|
+
isInCloudflare?: boolean;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* @param opts.nextDir - The path to the .next directory
|
|
10
10
|
* @param opts.middlewareInfo - Information about the middleware
|
|
11
|
-
* @param opts.
|
|
11
|
+
* @param opts.isInCloudflare - Whether the code runs on the cloudflare runtime
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
export declare function openNextEdgePlugins({ nextDir, middlewareInfo,
|
|
14
|
+
export declare function openNextEdgePlugins({ nextDir, middlewareInfo, isInCloudflare, }: IPluginSettings): Plugin;
|
package/dist/plugins/edge.js
CHANGED
|
@@ -7,10 +7,10 @@ import { getCrossPlatformPathRegex } from "../utils/regex.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* @param opts.nextDir - The path to the .next directory
|
|
9
9
|
* @param opts.middlewareInfo - Information about the middleware
|
|
10
|
-
* @param opts.
|
|
10
|
+
* @param opts.isInCloudflare - Whether the code runs on the cloudflare runtime
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
export function openNextEdgePlugins({ nextDir, middlewareInfo,
|
|
13
|
+
export function openNextEdgePlugins({ nextDir, middlewareInfo, isInCloudflare, }) {
|
|
14
14
|
const entryFiles = middlewareInfo?.files.map((file) => path.join(nextDir, file)) ?? [];
|
|
15
15
|
const routes = middlewareInfo
|
|
16
16
|
? [
|
|
@@ -54,7 +54,7 @@ globalThis._ENTRIES = {};
|
|
|
54
54
|
globalThis.self = globalThis;
|
|
55
55
|
globalThis._ROUTES = ${JSON.stringify(routes)};
|
|
56
56
|
|
|
57
|
-
${
|
|
57
|
+
${isInCloudflare
|
|
58
58
|
? ""
|
|
59
59
|
: `
|
|
60
60
|
import {readFileSync} from "node:fs";
|
|
@@ -97,11 +97,7 @@ if (!globalThis.URLPattern) {
|
|
|
97
97
|
await import("urlpattern-polyfill");
|
|
98
98
|
}
|
|
99
99
|
`}
|
|
100
|
-
${wasmFiles
|
|
101
|
-
.map((file) => isInCloudfare
|
|
102
|
-
? `import ${file.name} from './wasm/${file.name}.wasm';`
|
|
103
|
-
: `const ${file.name} = readFileSync(path.join(__dirname,'/wasm/${file.name}.wasm'));`)
|
|
104
|
-
.join("\n")}
|
|
100
|
+
${importWasm(wasmFiles, { isInCloudflare })}
|
|
105
101
|
${entryFiles.map((file) => `require("${file}");`).join("\n")}
|
|
106
102
|
${contents}
|
|
107
103
|
`;
|
|
@@ -153,3 +149,17 @@ ${contents}
|
|
|
153
149
|
},
|
|
154
150
|
};
|
|
155
151
|
}
|
|
152
|
+
function importWasm(files, { isInCloudflare }) {
|
|
153
|
+
return files
|
|
154
|
+
.map(({ name }) => {
|
|
155
|
+
if (isInCloudflare) {
|
|
156
|
+
// As `.next/server/src/middleware.js` references the name,
|
|
157
|
+
// using `import ${name} from '...'` would cause ESBuild to rename the import.
|
|
158
|
+
// We use `globalThis.${name}` to make sure `middleware.js` reference name will match.
|
|
159
|
+
return `import __onw_${name}__ from './wasm/${name}.wasm'
|
|
160
|
+
globalThis.${name} = __onw_${name}__`;
|
|
161
|
+
}
|
|
162
|
+
return `const ${name} = readFileSync(path.join(__dirname,'/wasm/${name}.wasm'));`;
|
|
163
|
+
})
|
|
164
|
+
.join("\n");
|
|
165
|
+
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"access": "public"
|
|
4
4
|
},
|
|
5
5
|
"name": "@opennextjs/aws",
|
|
6
|
-
"version": "3.5.
|
|
6
|
+
"version": "3.5.4",
|
|
7
7
|
"bin": {
|
|
8
8
|
"open-next": "./dist/index.js"
|
|
9
9
|
},
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@ast-grep/napi": "^0.35.0",
|
|
36
37
|
"@aws-sdk/client-cloudfront": "3.398.0",
|
|
37
38
|
"@aws-sdk/client-dynamodb": "^3.398.0",
|
|
38
39
|
"@aws-sdk/client-lambda": "^3.398.0",
|
|
@@ -46,7 +47,8 @@
|
|
|
46
47
|
"esbuild": "0.19.2",
|
|
47
48
|
"express": "5.0.1",
|
|
48
49
|
"path-to-regexp": "^6.3.0",
|
|
49
|
-
"urlpattern-polyfill": "^10.0.0"
|
|
50
|
+
"urlpattern-polyfill": "^10.0.0",
|
|
51
|
+
"yaml": "^2.7.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@types/aws-lambda": "^8.10.109",
|