@opennextjs/cloudflare 0.5.11 → 0.6.0
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/README.md +8 -8
- package/dist/api/cloudflare-context.d.ts +16 -5
- package/dist/api/config.d.ts +16 -43
- package/dist/api/config.js +21 -19
- package/dist/api/durable-objects/queue.d.ts +32 -0
- package/dist/api/durable-objects/queue.js +234 -0
- package/dist/api/durable-objects/queue.spec.js +290 -0
- package/dist/api/durable-objects/sharded-tag-cache.d.ts +7 -0
- package/dist/api/durable-objects/sharded-tag-cache.js +22 -0
- package/dist/api/durable-objects/sharded-tag-cache.spec.js +37 -0
- package/dist/api/overrides/incremental-cache/internal.d.ts +5 -0
- package/dist/api/{kv-cache.d.ts → overrides/incremental-cache/kv-incremental-cache.d.ts} +1 -1
- package/dist/api/{kv-cache.js → overrides/incremental-cache/kv-incremental-cache.js} +5 -5
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.d.ts +17 -0
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.js +61 -0
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +51 -0
- package/dist/api/overrides/incremental-cache/regional-cache.js +111 -0
- package/dist/api/overrides/queue/do-queue.d.ts +6 -0
- package/dist/api/overrides/queue/do-queue.js +15 -0
- package/dist/api/{memory-queue.d.ts → overrides/queue/memory-queue.d.ts} +3 -3
- package/dist/api/{memory-queue.js → overrides/queue/memory-queue.js} +18 -14
- package/dist/api/overrides/queue/memory-queue.spec.d.ts +1 -0
- package/dist/api/{memory-queue.spec.js → overrides/queue/memory-queue.spec.js} +20 -14
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.d.ts +13 -0
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.js +61 -0
- package/dist/api/{d1-tag-cache.d.ts → overrides/tag-cache/d1-tag-cache.d.ts} +3 -5
- package/dist/api/{d1-tag-cache.js → overrides/tag-cache/d1-tag-cache.js} +22 -29
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.d.ts +122 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +247 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.d.ts +1 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.js +322 -0
- package/dist/cli/args.d.ts +13 -2
- package/dist/cli/args.js +44 -29
- package/dist/cli/build/build.d.ts +5 -1
- package/dist/cli/build/build.js +9 -19
- package/dist/cli/build/bundle-server.js +5 -13
- package/dist/cli/build/open-next/compile-cache-assets-manifest.d.ts +1 -1
- package/dist/cli/build/open-next/compile-cache-assets-manifest.js +4 -6
- package/dist/cli/build/open-next/compileDurableObjects.d.ts +2 -0
- package/dist/cli/build/open-next/compileDurableObjects.js +30 -0
- package/dist/cli/build/open-next/copyCacheAssets.js +1 -1
- package/dist/cli/build/open-next/createServerBundle.d.ts +9 -1
- package/dist/cli/build/open-next/createServerBundle.js +28 -9
- package/dist/cli/build/patches/ast/patch-vercel-og-library.js +1 -1
- package/dist/cli/build/patches/ast/vercel-og.d.ts +5 -5
- package/dist/cli/build/patches/ast/vercel-og.js +1 -1
- package/dist/cli/build/patches/ast/vercel-og.spec.js +1 -1
- package/dist/cli/build/patches/ast/webpack-runtime.js +1 -1
- package/dist/cli/build/patches/ast/webpack-runtime.spec.js +1 -1
- package/dist/cli/build/patches/plugins/build-id.d.ts +2 -2
- package/dist/cli/build/patches/plugins/build-id.js +12 -5
- package/dist/cli/build/patches/plugins/build-id.spec.js +1 -1
- package/dist/cli/build/patches/plugins/dynamic-requires.d.ts +1 -2
- package/dist/cli/build/patches/plugins/dynamic-requires.js +21 -11
- package/dist/cli/build/patches/plugins/eval-manifest.d.ts +2 -2
- package/dist/cli/build/patches/plugins/eval-manifest.js +12 -5
- package/dist/cli/build/patches/plugins/find-dir.d.ts +2 -2
- package/dist/cli/build/patches/plugins/find-dir.js +10 -5
- package/dist/cli/build/patches/plugins/instrumentation.d.ts +2 -5
- package/dist/cli/build/patches/plugins/instrumentation.js +19 -3
- package/dist/cli/build/patches/plugins/instrumentation.spec.js +1 -1
- package/dist/cli/build/patches/plugins/load-manifest.d.ts +2 -2
- package/dist/cli/build/patches/plugins/load-manifest.js +12 -5
- package/dist/cli/build/patches/plugins/next-minimal.d.ts +4 -7
- package/dist/cli/build/patches/plugins/next-minimal.js +31 -15
- package/dist/cli/build/patches/plugins/next-minimal.spec.js +1 -1
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.d.ts +2 -2
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.js +10 -2
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.spec.js +1 -1
- package/dist/cli/build/patches/plugins/require.d.ts +2 -2
- package/dist/cli/build/patches/plugins/require.js +43 -35
- package/dist/cli/build/patches/plugins/res-revalidate.d.ts +3 -0
- package/dist/cli/build/patches/plugins/res-revalidate.js +77 -0
- package/dist/cli/build/patches/plugins/res-revalidate.spec.d.ts +1 -0
- package/dist/cli/build/patches/plugins/res-revalidate.spec.js +141 -0
- package/dist/cli/build/utils/create-config-files.d.ts +2 -2
- package/dist/cli/build/utils/create-config-files.js +3 -3
- package/dist/cli/build/utils/ensure-cf-config.js +3 -13
- package/dist/cli/commands/deploy.d.ts +5 -0
- package/dist/cli/commands/deploy.js +9 -0
- package/dist/cli/commands/populate-cache.d.ts +7 -0
- package/dist/cli/commands/populate-cache.js +78 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.js +9 -0
- package/dist/cli/index.js +36 -9
- package/dist/cli/project-options.d.ts +5 -1
- package/dist/cli/templates/worker.d.ts +3 -4
- package/dist/cli/templates/worker.js +30 -18
- package/dist/cli/utils/run-wrangler.d.ts +18 -0
- package/dist/cli/utils/run-wrangler.js +41 -0
- package/package.json +8 -10
- package/templates/open-next.config.ts +1 -1
- package/templates/wrangler.jsonc +2 -2
- package/dist/api/kvCache.d.ts +0 -5
- package/dist/api/kvCache.js +0 -5
- package/dist/cli/build/patches/ast/util.d.ts +0 -50
- package/dist/cli/build/patches/ast/util.js +0 -65
- package/dist/cli/build/patches/ast/util.spec.js +0 -43
- package/dist/cli/build/patches/plugins/content-updater.d.ts +0 -44
- package/dist/cli/build/patches/plugins/content-updater.js +0 -55
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.d.ts +0 -14
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.js +0 -40
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.spec.js +0 -453
- package/dist/cli/templates/shims/node-fs.d.ts +0 -17
- package/dist/cli/templates/shims/node-fs.js +0 -51
- package/dist/cli/templates/shims/throw.d.ts +0 -0
- package/dist/cli/templates/shims/throw.js +0 -2
- /package/dist/api/{memory-queue.spec.d.ts → durable-objects/queue.spec.d.ts} +0 -0
- /package/dist/{cli/build/patches/ast/util.spec.d.ts → api/durable-objects/sharded-tag-cache.spec.d.ts} +0 -0
- /package/dist/{cli/build/patches/plugins/fetch-cache-wait-until.spec.d.ts → api/overrides/incremental-cache/internal.js} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import logger from "@opennextjs/aws/logger.js";
|
|
3
|
+
export function runWrangler(options, args, wranglerOpts = {}) {
|
|
4
|
+
const result = spawnSync(options.packager, [
|
|
5
|
+
"exec",
|
|
6
|
+
"wrangler",
|
|
7
|
+
...args,
|
|
8
|
+
wranglerOpts.environment && `--env ${wranglerOpts.environment}`,
|
|
9
|
+
wranglerOpts.target === "remote" && !wranglerOpts.excludeRemoteFlag && "--remote",
|
|
10
|
+
wranglerOpts.target === "local" && "--local",
|
|
11
|
+
].filter((v) => !!v), {
|
|
12
|
+
shell: true,
|
|
13
|
+
stdio: wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit",
|
|
14
|
+
});
|
|
15
|
+
if (result.status !== 0) {
|
|
16
|
+
logger.error("Wrangler command failed");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function isWranglerTarget(v) {
|
|
21
|
+
return !!v && ["local", "remote"].includes(v);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Find the value of the environment flag (`--env` / `-e`) used by Wrangler.
|
|
25
|
+
*
|
|
26
|
+
* @param args - CLI arguments.
|
|
27
|
+
* @returns Value of the environment flag.
|
|
28
|
+
*/
|
|
29
|
+
export function getWranglerEnvironmentFlag(args) {
|
|
30
|
+
for (let i = 0; i <= args.length; i++) {
|
|
31
|
+
const arg = args[i];
|
|
32
|
+
if (!arg)
|
|
33
|
+
continue;
|
|
34
|
+
if (arg === "--env" || arg === "-e") {
|
|
35
|
+
return args[i + 1];
|
|
36
|
+
}
|
|
37
|
+
if (arg.startsWith("--env=") || arg.startsWith("-e=")) {
|
|
38
|
+
return arg.split("=")[1];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opennextjs/cloudflare",
|
|
3
3
|
"description": "Cloudflare builder for next apps",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"opennextjs-cloudflare": "dist/cli/index.js"
|
|
@@ -41,6 +41,12 @@
|
|
|
41
41
|
"url": "https://github.com/opennextjs/opennextjs-cloudflare/issues"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@dotenvx/dotenvx": "1.31.0",
|
|
46
|
+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@798",
|
|
47
|
+
"enquirer": "^2.4.1",
|
|
48
|
+
"glob": "^11.0.0"
|
|
49
|
+
},
|
|
44
50
|
"devDependencies": {
|
|
45
51
|
"@cloudflare/workers-types": "^4.20250224.0",
|
|
46
52
|
"@eslint/js": "^9.11.1",
|
|
@@ -60,16 +66,8 @@
|
|
|
60
66
|
"typescript-eslint": "^8.7.0",
|
|
61
67
|
"vitest": "^2.1.1"
|
|
62
68
|
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"@ast-grep/napi": "^0.36.1",
|
|
65
|
-
"@dotenvx/dotenvx": "1.31.0",
|
|
66
|
-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@7e23eee",
|
|
67
|
-
"enquirer": "^2.4.1",
|
|
68
|
-
"glob": "^11.0.0",
|
|
69
|
-
"yaml": "^2.7.0"
|
|
70
|
-
},
|
|
71
69
|
"peerDependencies": {
|
|
72
|
-
"wrangler": "^3.
|
|
70
|
+
"wrangler": "^3.114.1 || ^4.0.0"
|
|
73
71
|
},
|
|
74
72
|
"scripts": {
|
|
75
73
|
"clean": "rimraf dist",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// default open-next.config.ts file created by @opennextjs/cloudflare
|
|
2
2
|
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";
|
|
3
|
-
import kvIncrementalCache from "@opennextjs/cloudflare/kv-cache";
|
|
3
|
+
import kvIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/kv-incremental-cache";
|
|
4
4
|
|
|
5
5
|
export default defineCloudflareConfig({
|
|
6
6
|
incrementalCache: kvIncrementalCache,
|
package/templates/wrangler.jsonc
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"binding": "ASSETS"
|
|
10
10
|
},
|
|
11
11
|
"kv_namespaces": [
|
|
12
|
-
// Create a KV binding with the binding name "
|
|
12
|
+
// Create a KV binding with the binding name "NEXT_INC_CACHE_KV"
|
|
13
13
|
// to enable the KV based caching:
|
|
14
14
|
// {
|
|
15
|
-
// "binding": "
|
|
15
|
+
// "binding": "NEXT_INC_CACHE_KV",
|
|
16
16
|
// "id": "<BINDING_ID>"
|
|
17
17
|
// }
|
|
18
18
|
]
|
package/dist/api/kvCache.d.ts
DELETED
package/dist/api/kvCache.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type Edit, Lang, type NapiConfig, type SgNode } from "@ast-grep/napi";
|
|
2
|
-
/**
|
|
3
|
-
* fix has the same meaning as in yaml rules
|
|
4
|
-
* see https://ast-grep.github.io/guide/rewrite-code.html#using-fix-in-yaml-rule
|
|
5
|
-
*/
|
|
6
|
-
export type RuleConfig = NapiConfig & {
|
|
7
|
-
fix?: string;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Returns the `Edit`s and `Match`es for an ast-grep rule in yaml format
|
|
11
|
-
*
|
|
12
|
-
* The rule must have a `fix` to rewrite the matched node.
|
|
13
|
-
*
|
|
14
|
-
* Tip: use https://ast-grep.github.io/playground.html to create rules.
|
|
15
|
-
*
|
|
16
|
-
* @param rule The rule. Either a yaml string or an instance of `RuleConfig`
|
|
17
|
-
* @param root The root node
|
|
18
|
-
* @param once only apply once
|
|
19
|
-
* @returns A list of edits and a list of matches.
|
|
20
|
-
*/
|
|
21
|
-
export declare function applyRule(rule: string | RuleConfig, root: SgNode, { once }?: {
|
|
22
|
-
once?: boolean | undefined;
|
|
23
|
-
}): {
|
|
24
|
-
edits: Edit[];
|
|
25
|
-
matches: SgNode<import("@ast-grep/napi/types/staticTypes").TypesMap, import("@ast-grep/napi/types/staticTypes").Kinds<import("@ast-grep/napi/types/staticTypes").TypesMap>>[];
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Parse a file and obtain its root.
|
|
29
|
-
*
|
|
30
|
-
* @param path The file path
|
|
31
|
-
* @param lang The language to parse. Defaults to TypeScript.
|
|
32
|
-
* @returns The root for the file.
|
|
33
|
-
*/
|
|
34
|
-
export declare function parseFile(path: string, lang?: Lang): SgNode<import("@ast-grep/napi/types/staticTypes").TypesMap, import("@ast-grep/napi/types/staticTypes").Kinds<import("@ast-grep/napi/types/staticTypes").TypesMap>>;
|
|
35
|
-
/**
|
|
36
|
-
* Patches the code from by applying the rule.
|
|
37
|
-
*
|
|
38
|
-
* This function is mainly for on off edits and tests,
|
|
39
|
-
* use `getRuleEdits` to apply multiple rules.
|
|
40
|
-
*
|
|
41
|
-
* @param code The source code
|
|
42
|
-
* @param rule The astgrep rule (yaml or NapiConfig)
|
|
43
|
-
* @param lang The language used by the source code
|
|
44
|
-
* @param lang Whether to apply the rule only once
|
|
45
|
-
* @returns The patched code
|
|
46
|
-
*/
|
|
47
|
-
export declare function patchCode(code: string, rule: string | RuleConfig, { lang, once }?: {
|
|
48
|
-
lang?: Lang | undefined;
|
|
49
|
-
once?: boolean | undefined;
|
|
50
|
-
}): string;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { Lang, parse } from "@ast-grep/napi";
|
|
3
|
-
import yaml from "yaml";
|
|
4
|
-
/**
|
|
5
|
-
* Returns the `Edit`s and `Match`es for an ast-grep rule in yaml format
|
|
6
|
-
*
|
|
7
|
-
* The rule must have a `fix` to rewrite the matched node.
|
|
8
|
-
*
|
|
9
|
-
* Tip: use https://ast-grep.github.io/playground.html to create rules.
|
|
10
|
-
*
|
|
11
|
-
* @param rule The rule. Either a yaml string or an instance of `RuleConfig`
|
|
12
|
-
* @param root The root node
|
|
13
|
-
* @param once only apply once
|
|
14
|
-
* @returns A list of edits and a list of matches.
|
|
15
|
-
*/
|
|
16
|
-
export function applyRule(rule, root, { once = false } = {}) {
|
|
17
|
-
const ruleConfig = typeof rule === "string" ? yaml.parse(rule) : rule;
|
|
18
|
-
if (ruleConfig.transform) {
|
|
19
|
-
throw new Error("transform is not supported");
|
|
20
|
-
}
|
|
21
|
-
if (!ruleConfig.fix) {
|
|
22
|
-
throw new Error("no fix to apply");
|
|
23
|
-
}
|
|
24
|
-
const fix = ruleConfig.fix;
|
|
25
|
-
const matches = once ? [root.find(ruleConfig)].filter((m) => m !== null) : root.findAll(ruleConfig);
|
|
26
|
-
const edits = [];
|
|
27
|
-
matches.forEach((match) => {
|
|
28
|
-
edits.push(match.replace(
|
|
29
|
-
// Replace known placeholders by their value
|
|
30
|
-
fix
|
|
31
|
-
.replace(/\$\$\$([A-Z0-9_]+)/g, (_m, name) => match
|
|
32
|
-
.getMultipleMatches(name)
|
|
33
|
-
.map((n) => n.text())
|
|
34
|
-
.join(""))
|
|
35
|
-
.replace(/\$([A-Z0-9_]+)/g, (m, name) => match.getMatch(name)?.text() ?? m)));
|
|
36
|
-
});
|
|
37
|
-
return { edits, matches };
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Parse a file and obtain its root.
|
|
41
|
-
*
|
|
42
|
-
* @param path The file path
|
|
43
|
-
* @param lang The language to parse. Defaults to TypeScript.
|
|
44
|
-
* @returns The root for the file.
|
|
45
|
-
*/
|
|
46
|
-
export function parseFile(path, lang = Lang.TypeScript) {
|
|
47
|
-
return parse(lang, readFileSync(path, { encoding: "utf-8" })).root();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Patches the code from by applying the rule.
|
|
51
|
-
*
|
|
52
|
-
* This function is mainly for on off edits and tests,
|
|
53
|
-
* use `getRuleEdits` to apply multiple rules.
|
|
54
|
-
*
|
|
55
|
-
* @param code The source code
|
|
56
|
-
* @param rule The astgrep rule (yaml or NapiConfig)
|
|
57
|
-
* @param lang The language used by the source code
|
|
58
|
-
* @param lang Whether to apply the rule only once
|
|
59
|
-
* @returns The patched code
|
|
60
|
-
*/
|
|
61
|
-
export function patchCode(code, rule, { lang = Lang.TypeScript, once = false } = {}) {
|
|
62
|
-
const node = parse(lang, code).root();
|
|
63
|
-
const { edits } = applyRule(rule, node, { once });
|
|
64
|
-
return node.commitEdits(edits);
|
|
65
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { patchCode } from "./util.js";
|
|
3
|
-
describe("patchCode", () => {
|
|
4
|
-
afterEach(() => {
|
|
5
|
-
vi.clearAllMocks();
|
|
6
|
-
});
|
|
7
|
-
it("should throw an error if rule has a transform", () => {
|
|
8
|
-
expect(() => patchCode(`console.log("hi")`, { rule: { pattern: "console.log($MSG)" }, transform: "not supported" })).toThrow(/not supported/);
|
|
9
|
-
});
|
|
10
|
-
it("should throw an error if rule has no fix", () => {
|
|
11
|
-
expect(() => patchCode(`console.log("hi")`, { rule: { pattern: "console.log($MSG)" } })).toThrow(/no fix/);
|
|
12
|
-
});
|
|
13
|
-
it("should accept yaml rules", () => {
|
|
14
|
-
const yamlRule = `
|
|
15
|
-
rule:
|
|
16
|
-
pattern: a
|
|
17
|
-
fix: b
|
|
18
|
-
`;
|
|
19
|
-
expect(patchCode(`a`, yamlRule)).toEqual("b");
|
|
20
|
-
});
|
|
21
|
-
it("should apply fix to a single match when once is true", () => {
|
|
22
|
-
expect(patchCode(`a+a`, { rule: { pattern: "a" }, fix: "b" }, { once: true })).toEqual("b+a");
|
|
23
|
-
});
|
|
24
|
-
it("should apply fix to all matches when once is false (default)", () => {
|
|
25
|
-
expect(patchCode(`a+a`, { rule: { pattern: "a" }, fix: "b" })).toEqual("b+b");
|
|
26
|
-
expect(patchCode(`a+a`, { rule: { pattern: "a" }, fix: "b" }, { once: false })).toEqual("b+b");
|
|
27
|
-
});
|
|
28
|
-
it("should handle no matches", () => {
|
|
29
|
-
expect(patchCode(`a`, { rule: { pattern: "b" }, fix: "c" })).toEqual("a");
|
|
30
|
-
});
|
|
31
|
-
it("should replace $PLACEHOLDER with match text", () => {
|
|
32
|
-
expect(patchCode(`console.log(message)`, { rule: { pattern: "console.log($MSG)" }, fix: "$MSG" })).toEqual("message");
|
|
33
|
-
});
|
|
34
|
-
it("should handle $PLACEHODLERS that are not found in matches", () => {
|
|
35
|
-
expect(patchCode(`console.log(message)`, { rule: { pattern: "console.log($MSG)" }, fix: "$WHAT$$$WHAT" })).toEqual("$WHAT");
|
|
36
|
-
});
|
|
37
|
-
it("should replace $$$PLACEHOLDER with match text", () => {
|
|
38
|
-
expect(patchCode(`console.log("hello" + world, "!")`, {
|
|
39
|
-
rule: { pattern: "console.log($$$ARGS)" },
|
|
40
|
-
fix: "$$$ARGS",
|
|
41
|
-
})).toEqual(`"hello" + world,"!"`);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
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, type Plugin, type PluginBuild } from "esbuild";
|
|
7
|
-
/**
|
|
8
|
-
* The callbacks returns either an updated content or undefined if the content is unchanged.
|
|
9
|
-
*/
|
|
10
|
-
export type Callback = (args: {
|
|
11
|
-
contents: string;
|
|
12
|
-
path: string;
|
|
13
|
-
}) => string | undefined | Promise<string | undefined>;
|
|
14
|
-
/**
|
|
15
|
-
* The callback is called only when `contentFilter` matches the content.
|
|
16
|
-
* It can be used as a fast heuristic to prevent an expensive update.
|
|
17
|
-
*/
|
|
18
|
-
export type OnUpdateOptions = OnLoadOptions & {
|
|
19
|
-
contentFilter: RegExp;
|
|
20
|
-
};
|
|
21
|
-
export type Updater = OnUpdateOptions & {
|
|
22
|
-
callback: Callback;
|
|
23
|
-
};
|
|
24
|
-
export declare class ContentUpdater {
|
|
25
|
-
updaters: Map<string, Updater>;
|
|
26
|
-
/**
|
|
27
|
-
* Register a callback to update the file content.
|
|
28
|
-
*
|
|
29
|
-
* The callbacks are called in order of registration.
|
|
30
|
-
*
|
|
31
|
-
* @param name The name of the plugin (must be unique).
|
|
32
|
-
* @param options Options.
|
|
33
|
-
* @param callback The callback updating the content.
|
|
34
|
-
* @returns A noop ESBuild plugin.
|
|
35
|
-
*/
|
|
36
|
-
updateContent(name: string, options: OnUpdateOptions, callback: Callback): Plugin;
|
|
37
|
-
/**
|
|
38
|
-
* Returns an ESBuild plugin applying the registered updates.
|
|
39
|
-
*/
|
|
40
|
-
get plugin(): {
|
|
41
|
-
name: string;
|
|
42
|
-
setup: (build: PluginBuild) => Promise<void>;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
export class ContentUpdater {
|
|
8
|
-
updaters = new Map();
|
|
9
|
-
/**
|
|
10
|
-
* Register a callback to update the file content.
|
|
11
|
-
*
|
|
12
|
-
* The callbacks are called in order of registration.
|
|
13
|
-
*
|
|
14
|
-
* @param name The name of the plugin (must be unique).
|
|
15
|
-
* @param options Options.
|
|
16
|
-
* @param callback The callback updating the content.
|
|
17
|
-
* @returns A noop ESBuild plugin.
|
|
18
|
-
*/
|
|
19
|
-
updateContent(name, options, callback) {
|
|
20
|
-
if (this.updaters.has(name)) {
|
|
21
|
-
throw new Error(`Plugin "${name}" already registered`);
|
|
22
|
-
}
|
|
23
|
-
this.updaters.set(name, { ...options, callback });
|
|
24
|
-
return {
|
|
25
|
-
name,
|
|
26
|
-
setup() { },
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Returns an ESBuild plugin applying the registered updates.
|
|
31
|
-
*/
|
|
32
|
-
get plugin() {
|
|
33
|
-
return {
|
|
34
|
-
name: "aggregate-on-load",
|
|
35
|
-
setup: async (build) => {
|
|
36
|
-
build.onLoad({ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/ }, async (args) => {
|
|
37
|
-
let contents = await readFile(args.path, "utf-8");
|
|
38
|
-
for (const { filter, namespace, contentFilter, callback } of this.updaters.values()) {
|
|
39
|
-
if (namespace !== undefined && args.namespace !== namespace) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (!args.path.match(filter)) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (!contents.match(contentFilter)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
contents = (await callback({ contents, path: args.path })) ?? contents;
|
|
49
|
-
}
|
|
50
|
-
return { contents };
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ContentUpdater } from "./content-updater.js";
|
|
2
|
-
/**
|
|
3
|
-
* The following Next.js code sets values in the incremental cache for fetch calls:
|
|
4
|
-
* https://github.com/vercel/next.js/blob/e5fc495e3d4/packages/next/src/server/lib/patch-fetch.ts#L690-L728
|
|
5
|
-
*
|
|
6
|
-
* The issue here is that this promise is never awaited in the Next.js code (since in a standard node.js server
|
|
7
|
-
* the promise will eventually simply just run) but we do need to run it inside `waitUntil` (so that the worker
|
|
8
|
-
* is not killed before the promise is fully executed), without that this promise gets discarded and values
|
|
9
|
-
* don't get saved in the incremental cache.
|
|
10
|
-
*
|
|
11
|
-
* This function wraps the promise in a `waitUntil` call (retrieved from `globalThis.__openNextAls.getStore()`).
|
|
12
|
-
*/
|
|
13
|
-
export declare function patchFetchCacheSetMissingWaitUntil(updater: ContentUpdater): import("esbuild").Plugin;
|
|
14
|
-
export declare const rule = "\nrule:\n kind: call_expression\n pattern: $PROMISE\n all:\n - has: { pattern: $_.arrayBuffer().then, stopBy: end }\n - has: { pattern: \"Buffer.from\", stopBy: end }\n - any:\n - inside:\n kind: sequence_expression\n inside:\n kind: return_statement\n - inside:\n kind: expression_statement\n precedes:\n kind: return_statement\n - has: { pattern: $_.FETCH, stopBy: end }\n\nfix: |\n globalThis.__openNextAls?.getStore()?.waitUntil?.($PROMISE)\n";
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
|
|
2
|
-
import { patchCode } from "../ast/util.js";
|
|
3
|
-
/**
|
|
4
|
-
* The following Next.js code sets values in the incremental cache for fetch calls:
|
|
5
|
-
* https://github.com/vercel/next.js/blob/e5fc495e3d4/packages/next/src/server/lib/patch-fetch.ts#L690-L728
|
|
6
|
-
*
|
|
7
|
-
* The issue here is that this promise is never awaited in the Next.js code (since in a standard node.js server
|
|
8
|
-
* the promise will eventually simply just run) but we do need to run it inside `waitUntil` (so that the worker
|
|
9
|
-
* is not killed before the promise is fully executed), without that this promise gets discarded and values
|
|
10
|
-
* don't get saved in the incremental cache.
|
|
11
|
-
*
|
|
12
|
-
* This function wraps the promise in a `waitUntil` call (retrieved from `globalThis.__openNextAls.getStore()`).
|
|
13
|
-
*/
|
|
14
|
-
export function patchFetchCacheSetMissingWaitUntil(updater) {
|
|
15
|
-
return updater.updateContent("patch-fetch-cache-set-missing-wait-until", {
|
|
16
|
-
filter: getCrossPlatformPathRegex(String.raw `(server/chunks/.*\.js|.*\.runtime\..*\.js|patch-fetch\.js)$`, { escape: false }),
|
|
17
|
-
contentFilter: /arrayBuffer\(\)\s*\.then/,
|
|
18
|
-
}, ({ contents }) => patchCode(contents, rule));
|
|
19
|
-
}
|
|
20
|
-
export const rule = `
|
|
21
|
-
rule:
|
|
22
|
-
kind: call_expression
|
|
23
|
-
pattern: $PROMISE
|
|
24
|
-
all:
|
|
25
|
-
- has: { pattern: $_.arrayBuffer().then, stopBy: end }
|
|
26
|
-
- has: { pattern: "Buffer.from", stopBy: end }
|
|
27
|
-
- any:
|
|
28
|
-
- inside:
|
|
29
|
-
kind: sequence_expression
|
|
30
|
-
inside:
|
|
31
|
-
kind: return_statement
|
|
32
|
-
- inside:
|
|
33
|
-
kind: expression_statement
|
|
34
|
-
precedes:
|
|
35
|
-
kind: return_statement
|
|
36
|
-
- has: { pattern: $_.FETCH, stopBy: end }
|
|
37
|
-
|
|
38
|
-
fix: |
|
|
39
|
-
globalThis.__openNextAls?.getStore()?.waitUntil?.($PROMISE)
|
|
40
|
-
`;
|