@opennextjs/cloudflare 1.0.0-beta.4 → 1.0.1
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/api/cloudflare-context.d.ts +6 -3
- package/dist/api/config.d.ts +28 -1
- package/dist/api/config.js +15 -1
- package/dist/api/durable-objects/sharded-tag-cache.d.ts +1 -0
- package/dist/api/durable-objects/sharded-tag-cache.js +16 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/overrides/incremental-cache/kv-incremental-cache.d.ts +8 -9
- package/dist/api/overrides/incremental-cache/kv-incremental-cache.js +14 -14
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.d.ts +4 -11
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.js +8 -15
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +7 -7
- package/dist/api/overrides/incremental-cache/regional-cache.js +16 -13
- package/dist/api/overrides/incremental-cache/static-assets-incremental-cache.d.ts +3 -3
- package/dist/api/overrides/incremental-cache/static-assets-incremental-cache.js +9 -4
- package/dist/api/overrides/internal.d.ts +10 -3
- package/dist/api/overrides/internal.js +7 -0
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.d.ts +1 -0
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.js +20 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.d.ts +10 -4
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +50 -12
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.js +9 -5
- package/dist/api/overrides/tag-cache/tag-cache-filter.js +7 -0
- package/dist/api/overrides/tag-cache/tag-cache-filter.spec.js +1 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.js +3 -0
- package/dist/cli/build/build.d.ts +1 -1
- package/dist/cli/build/bundle-server.js +16 -4
- package/dist/cli/build/open-next/createServerBundle.js +15 -2
- package/dist/cli/build/patches/investigated/patch-cache.d.ts +1 -0
- package/dist/cli/build/patches/investigated/patch-cache.js +16 -0
- package/dist/cli/build/patches/plugins/eval-manifest.js +1 -1
- package/dist/cli/build/patches/plugins/load-manifest.js +1 -1
- package/dist/cli/build/patches/plugins/wrangler-external.js +2 -1
- package/dist/cli/build/utils/ensure-cf-config.d.ts +1 -1
- package/dist/cli/build/utils/workerd.d.ts +38 -0
- package/dist/cli/build/utils/workerd.js +80 -0
- package/dist/cli/build/utils/workerd.spec.d.ts +1 -0
- package/dist/cli/build/utils/workerd.spec.js +188 -0
- package/dist/cli/commands/deploy.d.ts +2 -1
- package/dist/cli/commands/deploy.js +1 -0
- package/dist/cli/commands/populate-cache.d.ts +1 -0
- package/dist/cli/commands/populate-cache.js +62 -24
- package/dist/cli/commands/preview.d.ts +2 -1
- package/dist/cli/commands/preview.js +1 -0
- package/dist/cli/commands/upload.d.ts +2 -1
- package/dist/cli/commands/upload.js +1 -0
- package/dist/cli/templates/init.js +3 -0
- package/dist/cli/utils/run-wrangler.d.ts +0 -1
- package/dist/cli/utils/run-wrangler.js +1 -1
- package/package.json +3 -3
- package/templates/wrangler.jsonc +1 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { transformBuildCondition, transformPackageJson } from "./workerd";
|
|
3
|
+
describe("transformBuildCondition", () => {
|
|
4
|
+
test("top level", () => {
|
|
5
|
+
const exports = {
|
|
6
|
+
workerd: "./path/to/workerd.js",
|
|
7
|
+
default: "./path/to/default.js",
|
|
8
|
+
};
|
|
9
|
+
const workerd = transformBuildCondition(exports, "workerd");
|
|
10
|
+
const defaultExport = transformBuildCondition(exports, "default");
|
|
11
|
+
const moduleExport = transformBuildCondition(exports, "module");
|
|
12
|
+
expect(workerd.hasBuildCondition).toBe(true);
|
|
13
|
+
expect(workerd.transformedExports).toEqual({
|
|
14
|
+
workerd: "./path/to/workerd.js",
|
|
15
|
+
});
|
|
16
|
+
expect(defaultExport.hasBuildCondition).toBe(true);
|
|
17
|
+
expect(defaultExport.transformedExports).toEqual({
|
|
18
|
+
default: "./path/to/default.js",
|
|
19
|
+
});
|
|
20
|
+
expect(moduleExport.hasBuildCondition).toBe(false);
|
|
21
|
+
expect(moduleExport.transformedExports).toEqual({
|
|
22
|
+
workerd: "./path/to/workerd.js",
|
|
23
|
+
default: "./path/to/default.js",
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
test("nested", () => {
|
|
27
|
+
const exports = {
|
|
28
|
+
".": "/path/to/index.js",
|
|
29
|
+
"./server": {
|
|
30
|
+
"react-server": {
|
|
31
|
+
workerd: "./server.edge.js",
|
|
32
|
+
other: "./server.js",
|
|
33
|
+
},
|
|
34
|
+
default: "./server.js",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const workerd = transformBuildCondition(exports, "workerd");
|
|
38
|
+
const defaultExport = transformBuildCondition(exports, "default");
|
|
39
|
+
const moduleExport = transformBuildCondition(exports, "module");
|
|
40
|
+
expect(workerd.hasBuildCondition).toBe(true);
|
|
41
|
+
expect(workerd.transformedExports).toEqual({
|
|
42
|
+
".": "/path/to/index.js",
|
|
43
|
+
"./server": {
|
|
44
|
+
"react-server": {
|
|
45
|
+
workerd: "./server.edge.js",
|
|
46
|
+
},
|
|
47
|
+
default: "./server.js",
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
expect(defaultExport.hasBuildCondition).toBe(true);
|
|
51
|
+
expect(defaultExport.transformedExports).toEqual({
|
|
52
|
+
".": "/path/to/index.js",
|
|
53
|
+
"./server": {
|
|
54
|
+
"react-server": {
|
|
55
|
+
workerd: "./server.edge.js",
|
|
56
|
+
other: "./server.js",
|
|
57
|
+
},
|
|
58
|
+
default: "./server.js",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
expect(moduleExport.hasBuildCondition).toBe(false);
|
|
62
|
+
expect(moduleExport.transformedExports).toEqual({
|
|
63
|
+
".": "/path/to/index.js",
|
|
64
|
+
"./server": {
|
|
65
|
+
"react-server": {
|
|
66
|
+
workerd: "./server.edge.js",
|
|
67
|
+
other: "./server.js",
|
|
68
|
+
},
|
|
69
|
+
default: "./server.js",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
test("only consider leaves", () => {
|
|
74
|
+
const exports = {
|
|
75
|
+
".": "/path/to/index.js",
|
|
76
|
+
"./server": {
|
|
77
|
+
workerd: {
|
|
78
|
+
default: "./server.edge.js",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
const workerd = transformBuildCondition(exports, "workerd");
|
|
83
|
+
expect(workerd.hasBuildCondition).toBe(false);
|
|
84
|
+
expect(workerd.transformedExports).toEqual({
|
|
85
|
+
".": "/path/to/index.js",
|
|
86
|
+
"./server": {
|
|
87
|
+
workerd: {
|
|
88
|
+
default: "./server.edge.js",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe("transformPackageJson", () => {
|
|
95
|
+
test("no exports nor imports", () => {
|
|
96
|
+
const json = {
|
|
97
|
+
name: "test",
|
|
98
|
+
main: "index.js",
|
|
99
|
+
version: "1.0.0",
|
|
100
|
+
description: "test package",
|
|
101
|
+
};
|
|
102
|
+
const { transformed, hasBuildCondition } = transformPackageJson(json);
|
|
103
|
+
expect(transformed).toEqual(json);
|
|
104
|
+
expect(hasBuildCondition).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
test("exports only with no workerd condition", () => {
|
|
107
|
+
const json = {
|
|
108
|
+
name: "test",
|
|
109
|
+
exports: {
|
|
110
|
+
".": "./index.js",
|
|
111
|
+
"./server": "./server.js",
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
const { transformed, hasBuildCondition } = transformPackageJson(json);
|
|
115
|
+
expect(transformed).toEqual(json);
|
|
116
|
+
expect(hasBuildCondition).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
test("exports only with nested workerd condition", () => {
|
|
119
|
+
const json = {
|
|
120
|
+
name: "test",
|
|
121
|
+
exports: {
|
|
122
|
+
".": "./index.js",
|
|
123
|
+
"./server": {
|
|
124
|
+
workerd: "./server.edge.js",
|
|
125
|
+
other: "./server.js",
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const { transformed, hasBuildCondition } = transformPackageJson(json);
|
|
130
|
+
expect(transformed).toEqual({
|
|
131
|
+
name: "test",
|
|
132
|
+
exports: {
|
|
133
|
+
".": "./index.js",
|
|
134
|
+
"./server": {
|
|
135
|
+
workerd: "./server.edge.js",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
expect(hasBuildCondition).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
test("imports only with top level workerd condition", () => {
|
|
142
|
+
const json = {
|
|
143
|
+
name: "test",
|
|
144
|
+
imports: {
|
|
145
|
+
workerd: "./server.edge.js",
|
|
146
|
+
default: "./server.js",
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
const { transformed, hasBuildCondition } = transformPackageJson(json);
|
|
150
|
+
expect(transformed).toEqual({
|
|
151
|
+
name: "test",
|
|
152
|
+
imports: {
|
|
153
|
+
workerd: "./server.edge.js",
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
expect(hasBuildCondition).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
test("exports and imports with workerd condition both nested and top level", () => {
|
|
159
|
+
const json = {
|
|
160
|
+
name: "test",
|
|
161
|
+
exports: {
|
|
162
|
+
".": "./index.js",
|
|
163
|
+
"./server": {
|
|
164
|
+
workerd: "./server.edge.js",
|
|
165
|
+
other: "./server.js",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
imports: {
|
|
169
|
+
workerd: "./server.edge.js",
|
|
170
|
+
default: "./server.js",
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
const { transformed, hasBuildCondition } = transformPackageJson(json);
|
|
174
|
+
expect(transformed).toEqual({
|
|
175
|
+
name: "test",
|
|
176
|
+
exports: {
|
|
177
|
+
".": "./index.js",
|
|
178
|
+
"./server": {
|
|
179
|
+
workerd: "./server.edge.js",
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
imports: {
|
|
183
|
+
workerd: "./server.edge.js",
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
expect(hasBuildCondition).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
2
|
-
import { OpenNextConfig } from "
|
|
2
|
+
import type { OpenNextConfig } from "../../api/config.js";
|
|
3
3
|
export declare function deploy(options: BuildOptions, config: OpenNextConfig, deployOptions: {
|
|
4
4
|
passthroughArgs: string[];
|
|
5
|
+
cacheChunkSize?: number;
|
|
5
6
|
}): Promise<void>;
|
|
@@ -4,6 +4,7 @@ export async function deploy(options, config, deployOptions) {
|
|
|
4
4
|
await populateCache(options, config, {
|
|
5
5
|
target: "remote",
|
|
6
6
|
environment: getWranglerEnvironmentFlag(deployOptions.passthroughArgs),
|
|
7
|
+
cacheChunkSize: deployOptions.cacheChunkSize,
|
|
7
8
|
});
|
|
8
9
|
runWrangler(options, ["deploy", ...deployOptions.passthroughArgs], { logging: "all" });
|
|
9
10
|
}
|
|
@@ -11,4 +11,5 @@ export declare function getCacheAssets(opts: BuildOptions): CacheAsset[];
|
|
|
11
11
|
export declare function populateCache(options: BuildOptions, config: OpenNextConfig, populateCacheOptions: {
|
|
12
12
|
target: WranglerTarget;
|
|
13
13
|
environment?: string;
|
|
14
|
+
cacheChunkSize?: number;
|
|
14
15
|
}): Promise<void>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { cpSync, existsSync } from "node:fs";
|
|
1
|
+
import { cpSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import logger from "@opennextjs/aws/logger.js";
|
|
4
4
|
import { globSync } from "glob";
|
|
5
5
|
import { tqdm } from "ts-tqdm";
|
|
6
|
-
import { unstable_readConfig } from "wrangler";
|
|
7
|
-
import { BINDING_NAME as KV_CACHE_BINDING_NAME,
|
|
8
|
-
import { BINDING_NAME as R2_CACHE_BINDING_NAME,
|
|
6
|
+
import { getPlatformProxy, unstable_readConfig } from "wrangler";
|
|
7
|
+
import { BINDING_NAME as KV_CACHE_BINDING_NAME, NAME as KV_CACHE_NAME, PREFIX_ENV_NAME as KV_CACHE_PREFIX_ENV_NAME, } from "../../api/overrides/incremental-cache/kv-incremental-cache.js";
|
|
8
|
+
import { BINDING_NAME as R2_CACHE_BINDING_NAME, NAME as R2_CACHE_NAME, PREFIX_ENV_NAME as R2_CACHE_PREFIX_ENV_NAME, } from "../../api/overrides/incremental-cache/r2-incremental-cache.js";
|
|
9
9
|
import { CACHE_DIR as STATIC_ASSETS_CACHE_DIR, NAME as STATIC_ASSETS_CACHE_NAME, } from "../../api/overrides/incremental-cache/static-assets-incremental-cache.js";
|
|
10
|
+
import { computeCacheKey } from "../../api/overrides/internal.js";
|
|
10
11
|
import { BINDING_NAME as D1_TAG_BINDING_NAME, NAME as D1_TAG_NAME, } from "../../api/overrides/tag-cache/d1-next-tag-cache.js";
|
|
11
12
|
import { runWrangler } from "../utils/run-wrangler.js";
|
|
12
13
|
async function resolveCacheName(value) {
|
|
@@ -48,7 +49,13 @@ export function getCacheAssets(opts) {
|
|
|
48
49
|
}
|
|
49
50
|
return assets;
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
+
async function getPlatformProxyEnv(options, key) {
|
|
53
|
+
const proxy = await getPlatformProxy(options);
|
|
54
|
+
const prefix = proxy.env[key];
|
|
55
|
+
await proxy.dispose();
|
|
56
|
+
return prefix;
|
|
57
|
+
}
|
|
58
|
+
async function populateR2IncrementalCache(options, populateCacheOptions) {
|
|
52
59
|
logger.info("\nPopulating R2 incremental cache...");
|
|
53
60
|
const config = unstable_readConfig({ env: populateCacheOptions.environment });
|
|
54
61
|
const binding = config.r2_buckets.find(({ binding }) => binding === R2_CACHE_BINDING_NAME);
|
|
@@ -59,39 +66,51 @@ function populateR2IncrementalCache(options, populateCacheOptions) {
|
|
|
59
66
|
if (!bucket) {
|
|
60
67
|
throw new Error(`R2 binding ${JSON.stringify(R2_CACHE_BINDING_NAME)} should have a 'bucket_name'`);
|
|
61
68
|
}
|
|
69
|
+
const prefix = await getPlatformProxyEnv(populateCacheOptions, R2_CACHE_PREFIX_ENV_NAME);
|
|
62
70
|
const assets = getCacheAssets(options);
|
|
63
71
|
for (const { fullPath, key, buildId, isFetch } of tqdm(assets)) {
|
|
64
|
-
const cacheKey =
|
|
65
|
-
|
|
72
|
+
const cacheKey = computeCacheKey(key, {
|
|
73
|
+
prefix,
|
|
66
74
|
buildId,
|
|
67
|
-
isFetch,
|
|
75
|
+
cacheType: isFetch ? "fetch" : "cache",
|
|
68
76
|
});
|
|
69
|
-
runWrangler(options, ["r2 object put",
|
|
77
|
+
runWrangler(options, ["r2 object put", quoteShellMeta(path.join(bucket, cacheKey)), `--file ${quoteShellMeta(fullPath)}`],
|
|
70
78
|
// NOTE: R2 does not support the environment flag and results in the following error:
|
|
71
79
|
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
|
|
72
|
-
{ target: populateCacheOptions.target,
|
|
80
|
+
{ target: populateCacheOptions.target, logging: "error" });
|
|
73
81
|
}
|
|
74
82
|
logger.info(`Successfully populated cache with ${assets.length} assets`);
|
|
75
83
|
}
|
|
76
|
-
function populateKVIncrementalCache(options, populateCacheOptions) {
|
|
84
|
+
async function populateKVIncrementalCache(options, populateCacheOptions) {
|
|
77
85
|
logger.info("\nPopulating KV incremental cache...");
|
|
78
86
|
const config = unstable_readConfig({ env: populateCacheOptions.environment });
|
|
79
87
|
const binding = config.kv_namespaces.find(({ binding }) => binding === KV_CACHE_BINDING_NAME);
|
|
80
88
|
if (!binding) {
|
|
81
89
|
throw new Error(`No KV binding ${JSON.stringify(KV_CACHE_BINDING_NAME)} found!`);
|
|
82
90
|
}
|
|
91
|
+
const prefix = await getPlatformProxyEnv(populateCacheOptions, KV_CACHE_PREFIX_ENV_NAME);
|
|
83
92
|
const assets = getCacheAssets(options);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
const chunkSize = Math.max(1, populateCacheOptions.cacheChunkSize ?? 25);
|
|
94
|
+
const totalChunks = Math.ceil(assets.length / chunkSize);
|
|
95
|
+
logger.info(`Inserting ${assets.length} assets to KV in chunks of ${chunkSize}`);
|
|
96
|
+
for (const i of tqdm(Array.from({ length: totalChunks }, (_, i) => i))) {
|
|
97
|
+
const chunkPath = path.join(options.outputDir, "cloudflare", `cache-chunk-${i}.json`);
|
|
98
|
+
const kvMapping = assets
|
|
99
|
+
.slice(i * chunkSize, (i + 1) * chunkSize)
|
|
100
|
+
.map(({ fullPath, key, buildId, isFetch }) => ({
|
|
101
|
+
key: computeCacheKey(key, {
|
|
102
|
+
prefix,
|
|
103
|
+
buildId,
|
|
104
|
+
cacheType: isFetch ? "fetch" : "cache",
|
|
105
|
+
}),
|
|
106
|
+
value: readFileSync(fullPath, "utf8"),
|
|
107
|
+
}));
|
|
108
|
+
writeFileSync(chunkPath, JSON.stringify(kvMapping));
|
|
109
|
+
runWrangler(options, ["kv bulk put", quoteShellMeta(chunkPath), `--binding ${KV_CACHE_BINDING_NAME}`], {
|
|
110
|
+
...populateCacheOptions,
|
|
111
|
+
logging: "error",
|
|
88
112
|
});
|
|
89
|
-
|
|
90
|
-
"kv key put",
|
|
91
|
-
JSON.stringify(cacheKey),
|
|
92
|
-
`--binding ${JSON.stringify(KV_CACHE_BINDING_NAME)}`,
|
|
93
|
-
`--path ${JSON.stringify(fullPath)}`,
|
|
94
|
-
], { ...populateCacheOptions, logging: "error" });
|
|
113
|
+
rmSync(chunkPath);
|
|
95
114
|
}
|
|
96
115
|
logger.info(`Successfully populated cache with ${assets.length} assets`);
|
|
97
116
|
}
|
|
@@ -104,7 +123,7 @@ function populateD1TagCache(options, populateCacheOptions) {
|
|
|
104
123
|
}
|
|
105
124
|
runWrangler(options, [
|
|
106
125
|
"d1 execute",
|
|
107
|
-
|
|
126
|
+
D1_TAG_BINDING_NAME,
|
|
108
127
|
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
|
|
109
128
|
], { ...populateCacheOptions, logging: "error" });
|
|
110
129
|
logger.info("\nSuccessfully created D1 table");
|
|
@@ -124,10 +143,10 @@ export async function populateCache(options, config, populateCacheOptions) {
|
|
|
124
143
|
const name = await resolveCacheName(incrementalCache);
|
|
125
144
|
switch (name) {
|
|
126
145
|
case R2_CACHE_NAME:
|
|
127
|
-
populateR2IncrementalCache(options, populateCacheOptions);
|
|
146
|
+
await populateR2IncrementalCache(options, populateCacheOptions);
|
|
128
147
|
break;
|
|
129
148
|
case KV_CACHE_NAME:
|
|
130
|
-
populateKVIncrementalCache(options, populateCacheOptions);
|
|
149
|
+
await populateKVIncrementalCache(options, populateCacheOptions);
|
|
131
150
|
break;
|
|
132
151
|
case STATIC_ASSETS_CACHE_NAME:
|
|
133
152
|
populateStaticAssetsIncrementalCache(options);
|
|
@@ -147,3 +166,22 @@ export async function populateCache(options, config, populateCacheOptions) {
|
|
|
147
166
|
}
|
|
148
167
|
}
|
|
149
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Escape shell metacharacters.
|
|
171
|
+
*
|
|
172
|
+
* When `spawnSync` is invoked with `shell: true`, metacharacters need to be escaped.
|
|
173
|
+
*
|
|
174
|
+
* Based on https://github.com/ljharb/shell-quote/blob/main/quote.js
|
|
175
|
+
*
|
|
176
|
+
* @param arg
|
|
177
|
+
* @returns escaped arg
|
|
178
|
+
*/
|
|
179
|
+
function quoteShellMeta(arg) {
|
|
180
|
+
if (/["\s]/.test(arg) && !/'/.test(arg)) {
|
|
181
|
+
return `'${arg.replace(/(['\\])/g, "\\$1")}'`;
|
|
182
|
+
}
|
|
183
|
+
if (/["'\s]/.test(arg)) {
|
|
184
|
+
return `"${arg.replace(/(["\\$`!])/g, "\\$1")}"`;
|
|
185
|
+
}
|
|
186
|
+
return arg.replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, "$1\\$2");
|
|
187
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
2
|
-
import { OpenNextConfig } from "
|
|
2
|
+
import type { OpenNextConfig } from "../../api/config.js";
|
|
3
3
|
export declare function preview(options: BuildOptions, config: OpenNextConfig, previewOptions: {
|
|
4
4
|
passthroughArgs: string[];
|
|
5
|
+
cacheChunkSize?: number;
|
|
5
6
|
}): Promise<void>;
|
|
@@ -4,6 +4,7 @@ export async function preview(options, config, previewOptions) {
|
|
|
4
4
|
await populateCache(options, config, {
|
|
5
5
|
target: "local",
|
|
6
6
|
environment: getWranglerEnvironmentFlag(previewOptions.passthroughArgs),
|
|
7
|
+
cacheChunkSize: previewOptions.cacheChunkSize,
|
|
7
8
|
});
|
|
8
9
|
runWrangler(options, ["dev", ...previewOptions.passthroughArgs], { logging: "all" });
|
|
9
10
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
2
|
-
import { OpenNextConfig } from "
|
|
2
|
+
import type { OpenNextConfig } from "../../api/config.js";
|
|
3
3
|
export declare function upload(options: BuildOptions, config: OpenNextConfig, uploadOptions: {
|
|
4
4
|
passthroughArgs: string[];
|
|
5
|
+
cacheChunkSize?: number;
|
|
5
6
|
}): Promise<void>;
|
|
@@ -4,6 +4,7 @@ export async function upload(options, config, uploadOptions) {
|
|
|
4
4
|
await populateCache(options, config, {
|
|
5
5
|
target: "remote",
|
|
6
6
|
environment: getWranglerEnvironmentFlag(uploadOptions.passthroughArgs),
|
|
7
|
+
cacheChunkSize: uploadOptions.cacheChunkSize,
|
|
7
8
|
});
|
|
8
9
|
runWrangler(options, ["versions upload", ...uploadOptions.passthroughArgs], { logging: "all" });
|
|
9
10
|
}
|
|
@@ -44,6 +44,9 @@ function initRuntime() {
|
|
|
44
44
|
Object.assign(process.versions, { node: "22.14.0", ...process.versions });
|
|
45
45
|
globalThis.__dirname ??= "";
|
|
46
46
|
globalThis.__filename ??= "";
|
|
47
|
+
// Some packages rely on `import.meta.url` but it is undefined in workerd
|
|
48
|
+
// For example it causes a bunch of issues, and will make even import crash with payload
|
|
49
|
+
import.meta.url ??= "file:///worker.js";
|
|
47
50
|
// Do not crash on cache not supported
|
|
48
51
|
// https://github.com/cloudflare/workerd/pull/2434
|
|
49
52
|
// compatibility flag "cache_option_enabled" -> does not support "force-cache"
|
|
@@ -3,7 +3,6 @@ export type WranglerTarget = "local" | "remote";
|
|
|
3
3
|
type WranglerOptions = {
|
|
4
4
|
target?: WranglerTarget;
|
|
5
5
|
environment?: string;
|
|
6
|
-
excludeRemoteFlag?: boolean;
|
|
7
6
|
logging?: "all" | "error";
|
|
8
7
|
};
|
|
9
8
|
export declare function runWrangler(options: BuildOptions, args: string[], wranglerOpts?: WranglerOptions): void;
|
|
@@ -43,7 +43,7 @@ export function runWrangler(options, args, wranglerOpts = {}) {
|
|
|
43
43
|
...injectPassthroughFlagForArgs(options, [
|
|
44
44
|
...args,
|
|
45
45
|
wranglerOpts.environment && `--env ${wranglerOpts.environment}`,
|
|
46
|
-
wranglerOpts.target === "remote" &&
|
|
46
|
+
wranglerOpts.target === "remote" && "--remote",
|
|
47
47
|
wranglerOpts.target === "local" && "--local",
|
|
48
48
|
].filter((v) => !!v)),
|
|
49
49
|
], {
|
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": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"opennextjs-cloudflare": "dist/cli/index.js"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@dotenvx/dotenvx": "1.31.0",
|
|
46
|
-
"@opennextjs/aws": "3.
|
|
46
|
+
"@opennextjs/aws": "~3.6.0",
|
|
47
47
|
"enquirer": "^2.4.1",
|
|
48
48
|
"glob": "^11.0.0",
|
|
49
49
|
"ts-tqdm": "^0.8.6"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"vitest": "^2.1.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"wrangler": "^4.
|
|
71
|
+
"wrangler": "^4.14.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"clean": "rimraf dist",
|
package/templates/wrangler.jsonc
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": ".open-next/worker.js",
|
|
4
4
|
"name": "app-name",
|
|
5
5
|
"compatibility_date": "2024-12-30",
|
|
6
|
-
"compatibility_flags": ["nodejs_compat"],
|
|
6
|
+
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
|
|
7
7
|
"assets": {
|
|
8
8
|
"directory": ".open-next/assets",
|
|
9
9
|
"binding": "ASSETS"
|