@solcreek/adapter-creek 0.2.0 → 0.2.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/index.js CHANGED
@@ -1,17 +1,26 @@
1
1
  import * as path from "node:path";
2
- import { fileURLToPath } from "node:url";
2
+ import { createRequire } from "node:module";
3
3
  import { copyFileSync, existsSync } from "node:fs";
4
4
  import { applyBaseModifyConfig } from "@solcreek/adapter-next-core";
5
5
  import { handleBuild } from "./build.js";
6
- // Dev-fallback path to the cache handler shipped by @solcreek/adapter-next-core.
7
- // applyBaseModifyConfig prefers the node_modules-installed copy when one
8
- // exists (the production path); this resolves the package's own bundled
9
- // copy as a last resort for the rare case where the adapter is used
10
- // without `npm install`ing it.
11
- const coreEntryUrl = new URL("../node_modules/@solcreek/adapter-next-core/dist/cache-handler.js", import.meta.url);
12
- const fallbackCacheHandlerPath = existsSync(fileURLToPath(coreEntryUrl))
13
- ? fileURLToPath(coreEntryUrl)
14
- : path.join(process.cwd(), "node_modules", "@solcreek", "adapter-next-core", "dist", "cache-handler.js");
6
+ // Path to the cache handler shipped by @solcreek/adapter-next-core, resolved
7
+ // from THIS module's location — not from the consumer project. The adapter is
8
+ // not always installed in the project's own node_modules: the Creek CLI
9
+ // lazy-installs it into <project>/.creek/node_modules, which is outside the
10
+ // project's require walk. Resolving from import.meta.url walks up from
11
+ // wherever the adapter actually lives, so it finds the dependency under npm
12
+ // hoisting, pnpm's content-addressed store, and the CLI's .creek install
13
+ // alike.
14
+ function resolveCacheHandlerPath() {
15
+ try {
16
+ return createRequire(import.meta.url).resolve("@solcreek/adapter-next-core/cache-handler");
17
+ }
18
+ catch {
19
+ // Last resort: assume a flat install in the consumer project.
20
+ return path.join(process.cwd(), "node_modules", "@solcreek", "adapter-next-core", "dist", "cache-handler.js");
21
+ }
22
+ }
23
+ const fallbackCacheHandlerPath = resolveCacheHandlerPath();
15
24
  function mirrorCacheHandlerIntoProject(cacheHandlerPath) {
16
25
  if (!existsSync(cacheHandlerPath))
17
26
  return cacheHandlerPath;
@@ -41,9 +50,14 @@ const adapter = {
41
50
  // for other phases, so guarding here matches its behaviour.
42
51
  if (ctx.phase !== "phase-production-build")
43
52
  return baseConfig;
44
- const cacheHandlerPath = typeof baseConfig.cacheHandler === "string"
45
- ? mirrorCacheHandlerIntoProject(baseConfig.cacheHandler)
46
- : mirrorCacheHandlerIntoProject(fallbackCacheHandlerPath);
53
+ // Keep the mirrored handler anchored to this adapter's dependency tree,
54
+ // not the consumer project's shared @solcreek/adapter-next-core copy.
55
+ // For Workers the project-local .solcreek-cache-handler.mjs path is a
56
+ // bundler sentinel: dynamic imports of that path are redirected to the
57
+ // inline CreekCacheHandler in worker-entry. If we mirror an arbitrary
58
+ // project copy here, Node App Page fetch-cache paths can bypass the
59
+ // Workers-specific runtime cache implementation.
60
+ const cacheHandlerPath = mirrorCacheHandlerIntoProject(fallbackCacheHandlerPath);
47
61
  return {
48
62
  ...baseConfig,
49
63
  // Next may dynamically import this cache handler on error/404 render
@@ -2693,6 +2693,10 @@ function __creekValueWithCacheTags(value, tags) {
2693
2693
  function __creekScopedCacheKey(key, ctx, value) {
2694
2694
  const isFetchEntry = ctx?.kind === "FETCH" || value?.kind === "FETCH";
2695
2695
  if (!isFetchEntry) return key;
2696
+ const ctxRuntime = ctx?.runtime;
2697
+ if (ctxRuntime === "edge" || ctxRuntime === "nodejs") {
2698
+ return "__fetch:" + ctxRuntime + ":" + key;
2699
+ }
2696
2700
  try {
2697
2701
  const runtime = __INTERNAL_FETCH_CONTEXT.getStore()?.handlerRuntime;
2698
2702
  if (runtime === "edge" || runtime === "nodejs") {
@@ -3020,12 +3024,18 @@ function __creekOriginalFetchArgs(input, init) {
3020
3024
  }
3021
3025
  if (init && typeof init === "object") {
3022
3026
  const fetchInit = { ...init };
3027
+ const hasOriginalBody = "_ogBody" in fetchInit;
3023
3028
  if ("_ogBody" in fetchInit) {
3024
3029
  fetchInit.body = fetchInit._ogBody;
3025
3030
  delete fetchInit._ogBody;
3026
3031
  }
3027
3032
  delete fetchInit.next;
3028
3033
  delete fetchInit.cache;
3034
+ if (hasOriginalBody && fetchInit.body !== undefined && fetchInit.body !== null) {
3035
+ try {
3036
+ return [new Request(input, fetchInit), undefined];
3037
+ } catch {}
3038
+ }
3029
3039
  return [input, fetchInit];
3030
3040
  }
3031
3041
  return [input, init];
@@ -3128,9 +3138,11 @@ function __creekWrapAppPageFetchCache(patchedFetch) {
3128
3138
  if (!cacheKey) return patchedFetch(input, init);
3129
3139
 
3130
3140
  const tags = Array.isArray(nextConfig?.tags) ? nextConfig.tags : [];
3141
+ const cacheRuntime = store?.handlerRuntime === "edge" ? "edge" : "nodejs";
3131
3142
  const cache = new CreekCacheHandler();
3132
3143
  const cacheCtx = {
3133
3144
  kind: "FETCH",
3145
+ runtime: cacheRuntime,
3134
3146
  revalidate,
3135
3147
  fetchUrl,
3136
3148
  tags,
@@ -8231,7 +8243,7 @@ async function __handleRequestInner(request, env, ctx) {
8231
8243
  try {
8232
8244
  const store = __INTERNAL_FETCH_CONTEXT.getStore();
8233
8245
  if (store) {
8234
- store.handlerRuntime = handler.runtime;
8246
+ store.handlerRuntime = handler.runtime === "edge" ? "edge" : "nodejs";
8235
8247
  store.handlerType = handler.type;
8236
8248
  }
8237
8249
  } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solcreek/adapter-creek",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Next.js deployment adapter for Creek (Cloudflare Workers)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@next/routing": "16.2.3",
48
48
  "@solcreek/adapter-core": "^0.2.0",
49
- "@solcreek/adapter-next-core": "^0.1.0",
49
+ "@solcreek/adapter-next-core": "^0.1.1",
50
50
  "sql.js": "^1.14.1",
51
51
  "wrangler": "^4.82.2"
52
52
  },