@opennextjs/cloudflare 1.8.3 → 1.8.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.
@@ -6,7 +6,7 @@ import type { WithWranglerArgs } from "./utils.js";
6
6
  * @param args
7
7
  */
8
8
  export declare function deployCommand(args: WithWranglerArgs<{
9
- cacheChunkSize: number;
9
+ cacheChunkSize?: number;
10
10
  }>): Promise<void>;
11
11
  /**
12
12
  * Add the `deploy` command to yargs configuration.
@@ -24,6 +24,7 @@ export async function deployCommand(args) {
24
24
  environment: args.env,
25
25
  wranglerConfigPath: args.wranglerConfigPath,
26
26
  cacheChunkSize: args.cacheChunkSize,
27
+ shouldUsePreviewId: false,
27
28
  });
28
29
  runWrangler(options, [
29
30
  "deploy",
@@ -11,10 +11,28 @@ export type CacheAsset = {
11
11
  };
12
12
  export declare function getCacheAssets(opts: BuildOptions): CacheAsset[];
13
13
  type PopulateCacheOptions = {
14
+ /**
15
+ * Whether to populate the local or remote cache.
16
+ */
14
17
  target: WranglerTarget;
18
+ /**
19
+ * Wrangler environment to use.
20
+ */
15
21
  environment?: string;
22
+ /**
23
+ * Path to the Wrangler config file.
24
+ */
16
25
  wranglerConfigPath?: string;
26
+ /**
27
+ * Chunk sizes to use when populating KV cache. Ignored for R2.
28
+ *
29
+ * @default 25 for KV
30
+ */
17
31
  cacheChunkSize?: number;
32
+ /**
33
+ * Instructs Wrangler to use the preview namespace or ID defined in the Wrangler config for the remote target.
34
+ */
35
+ shouldUsePreviewId: boolean;
18
36
  };
19
37
  export declare function populateCache(options: BuildOptions, config: OpenNextConfig, wranglerConfig: WranglerConfig, populateCacheOptions: PopulateCacheOptions): Promise<void>;
20
38
  /**
@@ -30,6 +48,6 @@ export declare function withPopulateCacheOptions<T extends yargs.Argv>(args: T):
30
48
  } & {
31
49
  env: string | undefined;
32
50
  } & {
33
- cacheChunkSize: number;
51
+ cacheChunkSize: number | undefined;
34
52
  }>;
35
53
  export {};
@@ -110,7 +110,12 @@ async function populateKVIncrementalCache(options, config, populateCacheOptions)
110
110
  value: readFileSync(fullPath, "utf8"),
111
111
  }));
112
112
  writeFileSync(chunkPath, JSON.stringify(kvMapping));
113
- runWrangler(options, ["kv bulk put", quoteShellMeta(chunkPath), `--binding ${KV_CACHE_BINDING_NAME}`], {
113
+ runWrangler(options, [
114
+ "kv bulk put",
115
+ quoteShellMeta(chunkPath),
116
+ `--binding ${KV_CACHE_BINDING_NAME}`,
117
+ `--preview ${populateCacheOptions.shouldUsePreviewId}`,
118
+ ], {
114
119
  target: populateCacheOptions.target,
115
120
  environment: populateCacheOptions.environment,
116
121
  configPath: populateCacheOptions.wranglerConfigPath,
@@ -130,6 +135,7 @@ function populateD1TagCache(options, config, populateCacheOptions) {
130
135
  "d1 execute",
131
136
  D1_TAG_BINDING_NAME,
132
137
  `--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
138
+ `--preview ${populateCacheOptions.shouldUsePreviewId}`,
133
139
  ], {
134
140
  target: populateCacheOptions.target,
135
141
  environment: populateCacheOptions.environment,
@@ -191,6 +197,7 @@ async function populateCacheCommand(target, args) {
191
197
  environment: args.env,
192
198
  wranglerConfigPath: args.wranglerConfigPath,
193
199
  cacheChunkSize: args.cacheChunkSize,
200
+ shouldUsePreviewId: false,
194
201
  });
195
202
  }
196
203
  /**
@@ -207,7 +214,6 @@ export function addPopulateCacheCommand(y) {
207
214
  export function withPopulateCacheOptions(args) {
208
215
  return withWranglerOptions(args).options("cacheChunkSize", {
209
216
  type: "number",
210
- default: 25,
211
217
  desc: "Number of entries per chunk when populating the cache",
212
218
  });
213
219
  }
@@ -6,7 +6,8 @@ import type { WithWranglerArgs } from "./utils.js";
6
6
  * @param args
7
7
  */
8
8
  export declare function previewCommand(args: WithWranglerArgs<{
9
- cacheChunkSize: number;
9
+ cacheChunkSize?: number;
10
+ remote: boolean;
10
11
  }>): Promise<void>;
11
12
  /**
12
13
  * Add the `preview` command to yargs configuration.
@@ -12,10 +12,11 @@ export async function previewCommand(args) {
12
12
  const options = getNormalizedOptions(config);
13
13
  const wranglerConfig = readWranglerConfig(args);
14
14
  await populateCache(options, config, wranglerConfig, {
15
- target: "local",
15
+ target: args.remote ? "remote" : "local",
16
16
  environment: args.env,
17
17
  wranglerConfigPath: args.wranglerConfigPath,
18
18
  cacheChunkSize: args.cacheChunkSize,
19
+ shouldUsePreviewId: args.remote,
19
20
  });
20
21
  runWrangler(options, ["dev", ...args.wranglerArgs], { logging: "all" });
21
22
  }
@@ -25,5 +26,10 @@ export async function previewCommand(args) {
25
26
  * Consumes 1 positional parameter.
26
27
  */
27
28
  export function addPreviewCommand(y) {
28
- return y.command("preview", "Preview a built OpenNext app with a Wrangler dev server", (c) => withPopulateCacheOptions(c), (args) => previewCommand(withWranglerPassthroughArgs(args)));
29
+ return y.command("preview", "Preview a built OpenNext app with a Wrangler dev server", (c) => withPopulateCacheOptions(c).option("remote", {
30
+ type: "boolean",
31
+ alias: "r",
32
+ default: false,
33
+ desc: "Run on the global Cloudflare network with access to production resources",
34
+ }), (args) => previewCommand(withWranglerPassthroughArgs(args)));
29
35
  }
@@ -6,7 +6,7 @@ import type { WithWranglerArgs } from "./utils.js";
6
6
  * @param args
7
7
  */
8
8
  export declare function uploadCommand(args: WithWranglerArgs<{
9
- cacheChunkSize: number;
9
+ cacheChunkSize?: number;
10
10
  }>): Promise<void>;
11
11
  /**
12
12
  * Add the `upload` command to yargs configuration.
@@ -24,6 +24,7 @@ export async function uploadCommand(args) {
24
24
  environment: args.env,
25
25
  wranglerConfigPath: args.wranglerConfigPath,
26
26
  cacheChunkSize: args.cacheChunkSize,
27
+ shouldUsePreviewId: false,
27
28
  });
28
29
  runWrangler(options, [
29
30
  "versions upload",
@@ -80,6 +80,7 @@ type WranglerInputArgs = {
80
80
  configPath: string | undefined;
81
81
  config: string | undefined;
82
82
  env: string | undefined;
83
+ remote?: boolean | undefined;
83
84
  };
84
85
  /**
85
86
  *
@@ -115,6 +115,7 @@ function getWranglerArgs(args) {
115
115
  ...(args.configPath ? ["--config", args.configPath] : []),
116
116
  ...(args.config ? ["--config", args.config] : []),
117
117
  ...(args.env ? ["--env", args.env] : []),
118
+ ...(args.remote ? ["--remote"] : []),
118
119
  // Note: the first args in `_` will be the commands.
119
120
  ...args._.slice(args._[0] === "populateCache" ? 2 : 1).map((a) => `${a}`),
120
121
  ];
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.8.3",
4
+ "version": "1.8.4",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "opennextjs-cloudflare": "dist/cli/index.js"