@solcreek/adapter-creek 0.2.0 → 0.2.2
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/bundler.d.ts +15 -0
- package/dist/bundler.js +30 -6
- package/dist/index.js +27 -13
- package/dist/worker-entry.js +13 -1
- package/package.json +2 -2
package/dist/bundler.d.ts
CHANGED
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
* This works with both webpack and Turbopack output — wrangler handles
|
|
8
8
|
* the custom chunk format that plain esbuild cannot follow.
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Resolve wrangler's CLI entry script through Node module resolution.
|
|
12
|
+
*
|
|
13
|
+
* Never guess `<adapterDir>/node_modules/.bin/wrangler`: npm hoists
|
|
14
|
+
* wrangler to the top of the install tree (under the Creek CLI's lazy
|
|
15
|
+
* install that's `.creek/node_modules/.bin`), so the nested path only
|
|
16
|
+
* exists when hoisting is defeated by a version conflict. Resolving
|
|
17
|
+
* `wrangler/package.json` and reading its `bin` field finds the real
|
|
18
|
+
* entry under npm hoisting, pnpm's virtual store, and link installs
|
|
19
|
+
* alike — and running it with process.execPath sidesteps `.bin` shell
|
|
20
|
+
* shims entirely (which also don't exist as POSIX scripts on Windows).
|
|
21
|
+
*
|
|
22
|
+
* Exported for tests.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveWranglerEntry(requireFn: Pick<NodeRequire, "resolve">): Promise<string>;
|
|
10
25
|
export interface BundleOptions {
|
|
11
26
|
workerSource: string;
|
|
12
27
|
outputDir: string;
|
package/dist/bundler.js
CHANGED
|
@@ -9,8 +9,32 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as fs from "node:fs/promises";
|
|
11
11
|
import * as path from "node:path";
|
|
12
|
-
import {
|
|
12
|
+
import { execFileSync } from "node:child_process";
|
|
13
13
|
import { builtinModules, createRequire } from "node:module";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
/**
|
|
16
|
+
* Resolve wrangler's CLI entry script through Node module resolution.
|
|
17
|
+
*
|
|
18
|
+
* Never guess `<adapterDir>/node_modules/.bin/wrangler`: npm hoists
|
|
19
|
+
* wrangler to the top of the install tree (under the Creek CLI's lazy
|
|
20
|
+
* install that's `.creek/node_modules/.bin`), so the nested path only
|
|
21
|
+
* exists when hoisting is defeated by a version conflict. Resolving
|
|
22
|
+
* `wrangler/package.json` and reading its `bin` field finds the real
|
|
23
|
+
* entry under npm hoisting, pnpm's virtual store, and link installs
|
|
24
|
+
* alike — and running it with process.execPath sidesteps `.bin` shell
|
|
25
|
+
* shims entirely (which also don't exist as POSIX scripts on Windows).
|
|
26
|
+
*
|
|
27
|
+
* Exported for tests.
|
|
28
|
+
*/
|
|
29
|
+
export async function resolveWranglerEntry(requireFn) {
|
|
30
|
+
const pkgPath = requireFn.resolve("wrangler/package.json");
|
|
31
|
+
const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
|
|
32
|
+
const binRel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.wrangler;
|
|
33
|
+
if (!binRel) {
|
|
34
|
+
throw new Error(`wrangler package.json at ${pkgPath} has no usable bin field`);
|
|
35
|
+
}
|
|
36
|
+
return path.join(path.dirname(pkgPath), binRel);
|
|
37
|
+
}
|
|
14
38
|
/**
|
|
15
39
|
* Patch Turbopack runtime to inline chunk loading.
|
|
16
40
|
*
|
|
@@ -645,8 +669,9 @@ export async function bundleForWorkers(opts) {
|
|
|
645
669
|
const destPath = path.join(opts.outputDir, destName);
|
|
646
670
|
await fs.copyFile(absPath, destPath);
|
|
647
671
|
}
|
|
648
|
-
// Resolve adapter paths
|
|
649
|
-
|
|
672
|
+
// Resolve adapter paths. fileURLToPath, not URL#pathname — the latter
|
|
673
|
+
// yields "/C:/..." on Windows, which every alias below would inherit.
|
|
674
|
+
const adapterDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
650
675
|
// Generate wrangler config for the bundle step
|
|
651
676
|
const wranglerConfig = {
|
|
652
677
|
name: "creek-adapter-build",
|
|
@@ -778,10 +803,9 @@ export async function bundleForWorkers(opts) {
|
|
|
778
803
|
}
|
|
779
804
|
}
|
|
780
805
|
const bundleDir = path.join(opts.outputDir, "__bundle");
|
|
781
|
-
|
|
782
|
-
const wranglerBin = path.join(adapterDir, "node_modules", ".bin", "wrangler");
|
|
806
|
+
const wranglerEntry = await resolveWranglerEntry(adapterRequire);
|
|
783
807
|
try {
|
|
784
|
-
|
|
808
|
+
execFileSync(process.execPath, [wranglerEntry, "deploy", "--dry-run", "--outdir", bundleDir, "--config", configPath], {
|
|
785
809
|
cwd: path.dirname(opts.distDir),
|
|
786
810
|
stdio: "pipe",
|
|
787
811
|
env: process.env,
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import {
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
package/dist/worker-entry.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.2.2",
|
|
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.
|
|
49
|
+
"@solcreek/adapter-next-core": "^0.1.1",
|
|
50
50
|
"sql.js": "^1.14.1",
|
|
51
51
|
"wrangler": "^4.82.2"
|
|
52
52
|
},
|