@takazudo/zfb-adapter-cloudflare 0.1.0-next.27 → 0.1.0-next.29
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/emit-worker.mjs +38 -0
- package/package.json +3 -2
- package/src/emit-worker.mjs +38 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Shared, dependency-free implementation of `emitWorker`.
|
|
2
|
+
//
|
|
3
|
+
// Kept as a plain `.mjs` module (no TypeScript) so it can be imported from
|
|
4
|
+
// both the typed TypeScript surface (`src/build.ts`) and the dependency-free
|
|
5
|
+
// CLI binary (`bin/cli.mjs`) without needing a TypeScript loader.
|
|
6
|
+
//
|
|
7
|
+
// Do NOT duplicate this logic elsewhere. The two consumers always stay in
|
|
8
|
+
// sync by importing from here.
|
|
9
|
+
//
|
|
10
|
+
// invariant: no runtime npm deps — see SECURITY-DEPS.md
|
|
11
|
+
|
|
12
|
+
import { copyFile, mkdir, writeFile } from "node:fs/promises";
|
|
13
|
+
import { join, resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Emit a Cloudflare Pages `_worker.js` that wraps the zfb input bundle.
|
|
17
|
+
*
|
|
18
|
+
* Output shape (two files in `outdir`):
|
|
19
|
+
*
|
|
20
|
+
* _worker.js — entry imported by Cloudflare Pages advanced mode
|
|
21
|
+
* _zfb_inner.mjs — the input bundle, copied verbatim
|
|
22
|
+
*
|
|
23
|
+
* @param {{ inputBundlePath: string; outdir: string; workerWrapperSource: string }} input
|
|
24
|
+
* @returns {Promise<{ workerPath: string; innerBundlePath: string }>}
|
|
25
|
+
*/
|
|
26
|
+
export async function emitWorker({ inputBundlePath, outdir, workerWrapperSource }) {
|
|
27
|
+
const outdirAbs = resolve(outdir);
|
|
28
|
+
const inputAbs = resolve(inputBundlePath);
|
|
29
|
+
|
|
30
|
+
await mkdir(outdirAbs, { recursive: true });
|
|
31
|
+
const innerBundlePath = join(outdirAbs, "_zfb_inner.mjs");
|
|
32
|
+
await copyFile(inputAbs, innerBundlePath);
|
|
33
|
+
|
|
34
|
+
const workerPath = join(outdirAbs, "_worker.js");
|
|
35
|
+
await writeFile(workerPath, workerWrapperSource, "utf8");
|
|
36
|
+
|
|
37
|
+
return { workerPath, innerBundlePath };
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takazudo/zfb-adapter-cloudflare",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.29",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Rust-built static-site engine for Astro and Next.js users — millisecond rebuilds, single binary. Cloudflare Pages adapter.",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dist",
|
|
45
45
|
"bin",
|
|
46
46
|
"src/worker-wrapper.mjs",
|
|
47
|
+
"src/emit-worker.mjs",
|
|
47
48
|
"README.md",
|
|
48
49
|
"CHANGELOG.md",
|
|
49
50
|
"LICENSE"
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"vitest": "^2.1.9"
|
|
62
63
|
},
|
|
63
64
|
"scripts": {
|
|
64
|
-
"build": "tsc && cp src/worker-wrapper.mjs dist/worker-wrapper.mjs",
|
|
65
|
+
"build": "tsc && cp src/worker-wrapper.mjs dist/worker-wrapper.mjs && cp src/emit-worker.mjs dist/emit-worker.mjs",
|
|
65
66
|
"test": "vitest run",
|
|
66
67
|
"test:watch": "vitest",
|
|
67
68
|
"typecheck": "tsc --noEmit"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Shared, dependency-free implementation of `emitWorker`.
|
|
2
|
+
//
|
|
3
|
+
// Kept as a plain `.mjs` module (no TypeScript) so it can be imported from
|
|
4
|
+
// both the typed TypeScript surface (`src/build.ts`) and the dependency-free
|
|
5
|
+
// CLI binary (`bin/cli.mjs`) without needing a TypeScript loader.
|
|
6
|
+
//
|
|
7
|
+
// Do NOT duplicate this logic elsewhere. The two consumers always stay in
|
|
8
|
+
// sync by importing from here.
|
|
9
|
+
//
|
|
10
|
+
// invariant: no runtime npm deps — see SECURITY-DEPS.md
|
|
11
|
+
|
|
12
|
+
import { copyFile, mkdir, writeFile } from "node:fs/promises";
|
|
13
|
+
import { join, resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Emit a Cloudflare Pages `_worker.js` that wraps the zfb input bundle.
|
|
17
|
+
*
|
|
18
|
+
* Output shape (two files in `outdir`):
|
|
19
|
+
*
|
|
20
|
+
* _worker.js — entry imported by Cloudflare Pages advanced mode
|
|
21
|
+
* _zfb_inner.mjs — the input bundle, copied verbatim
|
|
22
|
+
*
|
|
23
|
+
* @param {{ inputBundlePath: string; outdir: string; workerWrapperSource: string }} input
|
|
24
|
+
* @returns {Promise<{ workerPath: string; innerBundlePath: string }>}
|
|
25
|
+
*/
|
|
26
|
+
export async function emitWorker({ inputBundlePath, outdir, workerWrapperSource }) {
|
|
27
|
+
const outdirAbs = resolve(outdir);
|
|
28
|
+
const inputAbs = resolve(inputBundlePath);
|
|
29
|
+
|
|
30
|
+
await mkdir(outdirAbs, { recursive: true });
|
|
31
|
+
const innerBundlePath = join(outdirAbs, "_zfb_inner.mjs");
|
|
32
|
+
await copyFile(inputAbs, innerBundlePath);
|
|
33
|
+
|
|
34
|
+
const workerPath = join(outdirAbs, "_worker.js");
|
|
35
|
+
await writeFile(workerPath, workerWrapperSource, "utf8");
|
|
36
|
+
|
|
37
|
+
return { workerPath, innerBundlePath };
|
|
38
|
+
}
|