@opennextjs/cloudflare 0.6.4 → 0.6.5

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.
@@ -221,13 +221,11 @@ export class DurableObjectQueueHandler extends DurableObject {
221
221
  try {
222
222
  if (this.disableSQLite)
223
223
  return false;
224
- const numNewer = this.sql
225
- .exec("SELECT COUNT(*) as numNewer FROM sync WHERE id = ? AND lastSuccess > ? LIMIT 1", `${msg.MessageBody.host}${msg.MessageBody.url}`, Math.round(msg.MessageBody.lastModified / 1000))
226
- .one().numNewer;
227
- return numNewer > 0;
228
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
224
+ return (this.sql
225
+ .exec("SELECT 1 FROM sync WHERE id = ? AND lastSuccess > ? LIMIT 1", `${msg.MessageBody.host}${msg.MessageBody.url}`, Math.round(msg.MessageBody.lastModified / 1000))
226
+ .toArray().length > 0);
229
227
  }
230
- catch (e) {
228
+ catch {
231
229
  return false;
232
230
  }
233
231
  }
@@ -9,10 +9,9 @@ export class DOShardedTagCache extends DurableObject {
9
9
  });
10
10
  }
11
11
  async hasBeenRevalidated(tags, lastModified) {
12
- const result = this.sql
13
- .exec(`SELECT COUNT(*) as cnt FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ?`, ...tags, lastModified ?? Date.now())
14
- .one();
15
- return result.cnt > 0;
12
+ return (this.sql
13
+ .exec(`SELECT 1 FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ? LIMIT 1`, ...tags, lastModified ?? Date.now())
14
+ .toArray().length > 0);
16
15
  }
17
16
  async writeTags(tags, lastModified) {
18
17
  tags.forEach((tag) => {
@@ -10,12 +10,10 @@ export class D1NextModeTagCache {
10
10
  return false;
11
11
  try {
12
12
  const result = await db
13
- .prepare(`SELECT COUNT(*) as cnt FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ? LIMIT 1`)
13
+ .prepare(`SELECT 1 FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ? LIMIT 1`)
14
14
  .bind(...tags.map((tag) => this.getCacheKey(tag)), lastModified ?? Date.now())
15
- .first();
16
- if (!result)
17
- throw new RecoverableError(`D1 select failed for ${tags}`);
18
- return result.cnt > 0;
15
+ .raw();
16
+ return result.length > 0;
19
17
  }
20
18
  catch (e) {
21
19
  error(e);
@@ -87,7 +87,7 @@ export async function bundleServer(buildOpts) {
87
87
  // Apply updater updates, must be the last plugin
88
88
  updater.plugin,
89
89
  ],
90
- external: ["./middleware/handler.mjs"],
90
+ external: ["./middleware/handler.mjs", "*.wasm"],
91
91
  alias: {
92
92
  // Note: it looks like node-fetch is actually not necessary for us, so we could replace it with an empty shim
93
93
  // but just to be safe we replace it with a module that re-exports the native fetch
@@ -2,10 +2,11 @@
2
2
  // Adapted for cloudflare workers
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
+ import { loadMiddlewareManifest } from "@opennextjs/aws/adapters/config/util.js";
5
6
  import { bundleNextServer } from "@opennextjs/aws/build/bundleNextServer.js";
6
7
  import { compileCache } from "@opennextjs/aws/build/compileCache.js";
7
8
  import { copyTracedFiles } from "@opennextjs/aws/build/copyTracedFiles.js";
8
- import { generateEdgeBundle } from "@opennextjs/aws/build/edge/createEdgeBundle.js";
9
+ import { copyMiddlewareResources, generateEdgeBundle } from "@opennextjs/aws/build/edge/createEdgeBundle.js";
9
10
  import * as buildHelper from "@opennextjs/aws/build/helper.js";
10
11
  import { installDependencies } from "@opennextjs/aws/build/installDeps.js";
11
12
  import { applyCodePatches } from "@opennextjs/aws/build/patch/codePatcher.js";
@@ -86,25 +87,28 @@ async function generateBundle(name, options, fnOptions, codeCustomization) {
86
87
  // `.next/standalone/package/path` (ie. `.next`, `server.js`).
87
88
  // We need to output the handler file inside the package path.
88
89
  const packagePath = buildHelper.getPackagePath(options);
89
- fs.mkdirSync(path.join(outputPath, packagePath), { recursive: true });
90
+ const outPackagePath = path.join(outputPath, packagePath);
91
+ fs.mkdirSync(outPackagePath, { recursive: true });
90
92
  const ext = fnOptions.runtime === "deno" ? "mjs" : "cjs";
91
- fs.copyFileSync(path.join(options.buildDir, `cache.${ext}`), path.join(outputPath, packagePath, "cache.cjs"));
93
+ fs.copyFileSync(path.join(options.buildDir, `cache.${ext}`), path.join(outPackagePath, "cache.cjs"));
92
94
  if (fnOptions.runtime === "deno") {
93
95
  addDenoJson(outputPath, packagePath);
94
96
  }
95
97
  // Bundle next server if necessary
96
98
  const isBundled = fnOptions.experimentalBundledNextServer ?? false;
97
99
  if (isBundled) {
98
- await bundleNextServer(path.join(outputPath, packagePath), appPath, {
100
+ await bundleNextServer(outPackagePath, appPath, {
99
101
  minify: options.minify,
100
102
  });
101
103
  }
102
104
  // Copy middleware
103
105
  if (!config.middleware?.external) {
104
- fs.copyFileSync(path.join(options.buildDir, "middleware.mjs"), path.join(outputPath, packagePath, "middleware.mjs"));
106
+ fs.copyFileSync(path.join(options.buildDir, "middleware.mjs"), path.join(outPackagePath, "middleware.mjs"));
107
+ const middlewareManifest = loadMiddlewareManifest(path.join(options.appBuildOutputPath, ".next"));
108
+ copyMiddlewareResources(options, middlewareManifest.middleware["/"], outPackagePath);
105
109
  }
106
110
  // Copy open-next.config.mjs
107
- buildHelper.copyOpenNextConfig(options.buildDir, path.join(outputPath, packagePath), true);
111
+ buildHelper.copyOpenNextConfig(options.buildDir, outPackagePath, true);
108
112
  // Copy env files
109
113
  buildHelper.copyEnvFile(appBuildOutputPath, packagePath, outputPath);
110
114
  // Copy all necessary traced files
@@ -164,7 +168,7 @@ async function generateBundle(name, options, fnOptions, codeCustomization) {
164
168
  : []),
165
169
  openNextEdgePlugins({
166
170
  nextDir: path.join(options.appBuildOutputPath, ".next"),
167
- isInCloudfare: true,
171
+ isInCloudflare: true,
168
172
  }),
169
173
  ];
170
174
  const outfileExt = fnOptions.runtime === "deno" ? "ts" : "mjs";
@@ -228,7 +232,7 @@ function addMonorepoEntrypoint(outputPath, packagePath) {
228
232
  // the Lambda function to be able to find the handler at
229
233
  // the root of the bundle. We will create a dummy `index.mjs`
230
234
  // that re-exports the real handler.
231
- fs.writeFileSync(path.join(outputPath, "index.mjs"), `export * from "./${normalizePath(packagePath)}/index.mjs";`);
235
+ fs.writeFileSync(path.join(outputPath, "index.mjs"), `export { handler } from "./${normalizePath(packagePath)}/index.mjs";`);
232
236
  }
233
237
  async function minifyServerBundle(outputDir) {
234
238
  logger.info("Minimizing server function...");
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.6.4",
4
+ "version": "0.6.5",
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": "https://pkg.pr.new/@opennextjs/aws@798",
46
+ "@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@802",
47
47
  "enquirer": "^2.4.1",
48
48
  "glob": "^11.0.0"
49
49
  },
@@ -67,7 +67,7 @@
67
67
  "vitest": "^2.1.1"
68
68
  },
69
69
  "peerDependencies": {
70
- "wrangler": "^3.114.1 || ^4.0.0"
70
+ "wrangler": "^3.114.1 || ^4.6.0"
71
71
  },
72
72
  "scripts": {
73
73
  "clean": "rimraf dist",