@aihu/adapter-cloudflare 0.1.0 → 0.1.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/README.md +74 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,32 +1,93 @@
|
|
|
1
1
|
# @aihu/adapter-cloudflare
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **Aihu** — agentic discovery and interaction, for human purpose.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Cloudflare Workers/Pages deployment adapter for @aihu/app.
|
|
6
|
+
|
|
7
|
+
Part of the **meta-framework** layer of Aihu. Provides whole-app capability — file-based routing, SSR, loaders, cookies — without the boilerplate other meta-frameworks impose. See [arch-1](../../docs/roadmap/arch-1-website.md) for the meta-framework contract.
|
|
8
|
+
|
|
9
|
+
<!-- BEGIN_HANDWRITTEN: prose -->
|
|
10
|
+
_(Hand-written prose lives in this block. Replace this placeholder; everything below is auto-generated.)_
|
|
11
|
+
<!-- END_HANDWRITTEN: prose -->
|
|
6
12
|
|
|
7
13
|
## Install
|
|
8
14
|
|
|
15
|
+
<!-- BEGIN_AUTOGEN: install -->
|
|
16
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
17
|
+
|
|
9
18
|
```bash
|
|
10
19
|
npm install @aihu/adapter-cloudflare
|
|
11
20
|
# or
|
|
12
21
|
bun add @aihu/adapter-cloudflare
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
// vite.config.ts
|
|
19
|
-
import { defineConfig } from 'vite';
|
|
20
|
-
import { aihu } from '@aihu/app';
|
|
21
|
-
import cloudflare from '@aihu/adapter-cloudflare';
|
|
26
|
+
<!-- END_AUTOGEN: install -->
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
## Package facts
|
|
29
|
+
|
|
30
|
+
<!-- BEGIN_AUTOGEN: stats -->
|
|
31
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
32
|
+
|
|
33
|
+
| | |
|
|
34
|
+
|---|---|
|
|
35
|
+
| **Version** | `0.1.1` |
|
|
36
|
+
| **Tier** | B — Meta-framework — Cloudflare Workers/Pages deploy adapter |
|
|
37
|
+
| **Published files** | 3 entries |
|
|
38
|
+
| **License** | MIT |
|
|
39
|
+
|
|
40
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
41
|
+
|
|
42
|
+
<!-- END_AUTOGEN: stats -->
|
|
43
|
+
|
|
44
|
+
## Exports
|
|
45
|
+
|
|
46
|
+
<!-- BEGIN_AUTOGEN: exports -->
|
|
47
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
48
|
+
|
|
49
|
+
| Subpath | ESM | CJS |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `.` | `./dist/index.js` | `—` |
|
|
52
|
+
|
|
53
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
54
|
+
|
|
55
|
+
<!-- END_AUTOGEN: exports -->
|
|
25
56
|
|
|
26
|
-
##
|
|
57
|
+
## Dependencies
|
|
27
58
|
|
|
28
|
-
|
|
59
|
+
<!-- BEGIN_AUTOGEN: deps -->
|
|
60
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
61
|
+
|
|
62
|
+
**Peer dependencies:**
|
|
63
|
+
|
|
64
|
+
- `@aihu/app` — `workspace:*`
|
|
65
|
+
- `vite` — `>=5.0.0`
|
|
66
|
+
|
|
67
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
68
|
+
|
|
69
|
+
<!-- END_AUTOGEN: deps -->
|
|
70
|
+
|
|
71
|
+
## See also
|
|
72
|
+
|
|
73
|
+
<!-- BEGIN_AUTOGEN: see-also -->
|
|
74
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
75
|
+
|
|
76
|
+
- [@aihu/app](../app)
|
|
77
|
+
- [@aihu/server](../server)
|
|
78
|
+
- [Aihu framework root](../../README.md)
|
|
79
|
+
|
|
80
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
81
|
+
|
|
82
|
+
<!-- END_AUTOGEN: see-also -->
|
|
29
83
|
|
|
30
84
|
## License
|
|
31
85
|
|
|
32
|
-
|
|
86
|
+
<!-- BEGIN_AUTOGEN: license -->
|
|
87
|
+
<!-- regenerate: bun scripts/sync-readme.ts (also runs in pre-commit + CI) -->
|
|
88
|
+
|
|
89
|
+
MIT — see [LICENSE](../../LICENSE).
|
|
90
|
+
|
|
91
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
92
|
+
|
|
93
|
+
<!-- END_AUTOGEN: license -->
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAIiB,wBAAA;;AAAjB;;;EAKE,IAAA;EAAA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAIiB,wBAAA;;AAAjB;;;EAKE,IAAA;EAAA;;;;;AAiFF;EA1EE,IAAA;;;;;;EAMA,gBAAA;AAAA;;;;;;;;;;;;;;;;iBAoEc,UAAA,CAAW,OAAA,GAAU,wBAAA,GAA2B,WAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import{existsSync as e,readFileSync as t}from"node:fs";import{resolve as n}from"node:path";function r(r){let i=n(r,`package.json`);if(!e(i))return null;try{let e=JSON.parse(t(i,`utf8`));return typeof e.name==`string`?e.name:null}catch{return null}}function i(){return[`// AUTO-GENERATED by @aihu/adapter-cloudflare — do not edit`,`// Cloudflare Workers entry — SPA mode`,`//`,`// All page requests are served from the ASSETS binding (Cloudflare CDN).`,`// For SSR mode, upgrade to @aihu/adapter-cloudflare with ssr: true (V1+).`,``,`export default {`,` async fetch(request, env, _ctx) {`,` try {`,` return await env.ASSETS.fetch(request)`,` } catch {`,` // Fallback to index.html for client-side routing (404 from ASSETS).`,` const url = new URL(request.url)`,` const indexUrl = new URL('/index.html', url.origin)`,` return env.ASSETS.fetch(new Request(indexUrl, request))`,` }`,` },`,`}`].join(`
|
|
2
|
-
`)}function a(e){return[`# AUTO-GENERATED by @aihu/adapter-cloudflare`,`# Edit this file to customize your Worker configuration.`,`# Reference: https://developers.cloudflare.com/workers/wrangler/configuration/`,``,`name = "${e}"`,`main = "_worker.js"`,`compatibility_date = "2024-01-01"`,``,`[assets]`,`directory = "."`,`binding = "ASSETS"`].join(`
|
|
3
|
-
`)
|
|
4
|
-
`}function o(t){return{name:`cloudflare`,async adapt(o){let s=t?.name??r(o.root)??`aihu-app`,c=i();await o.emitFile(`_worker.js`,c),console.log(`[@aihu/adapter-cloudflare] Wrote _worker.js (SPA mode)`);let l=n(o.root,`wrangler.toml`);if(t?.generateWrangler!==!1&&!e(l)){let e=a(s);await o.writeFile(l,e),console.log(`[@aihu/adapter-cloudflare] Created wrangler.toml (name = "${s}")`)}console.log(`[@aihu/adapter-cloudflare] Build complete → ${o.outDir}`),console.log(`[@aihu/adapter-cloudflare] Deploy with: wrangler deploy --config wrangler.toml`)}}}export{o as cloudflare};
|
|
2
|
+
`)}function a(e){return`${[`# AUTO-GENERATED by @aihu/adapter-cloudflare`,`# Edit this file to customize your Worker configuration.`,`# Reference: https://developers.cloudflare.com/workers/wrangler/configuration/`,``,`name = "${e}"`,`main = "_worker.js"`,`compatibility_date = "2024-01-01"`,``,`[assets]`,`directory = "."`,`binding = "ASSETS"`].join(`
|
|
3
|
+
`)}\n`}function o(t){return{name:`cloudflare`,async adapt(o){let s=t?.name??r(o.root)??`aihu-app`,c=i();await o.emitFile(`_worker.js`,c),console.log(`[@aihu/adapter-cloudflare] Wrote _worker.js (SPA mode)`);let l=n(o.root,`wrangler.toml`);if(t?.generateWrangler!==!1&&!e(l)){let e=a(s);await o.writeFile(l,e),console.log(`[@aihu/adapter-cloudflare] Created wrangler.toml (name = "${s}")`)}console.log(`[@aihu/adapter-cloudflare] Build complete → ${o.outDir}`),console.log(`[@aihu/adapter-cloudflare] Deploy with: wrangler deploy --config wrangler.toml`)}}}export{o as cloudflare};
|
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["resolvePath"],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { resolve as resolvePath } from 'node:path'\nimport type { AdapterContext, AihuAdapter } from '@aihu/app'\n\nexport interface CloudflareAdapterOptions {\n /**\n * Cloudflare Worker name. Used in generated wrangler.toml.\n * Default: value of \"name\" in the project's package.json, or 'aihu-app'.\n */\n name?: string\n /**\n * Deployment mode.\n * - 'workers': Cloudflare Workers with static assets via env.ASSETS binding\n * - 'pages': Cloudflare Pages (_worker.js convention — same output, different deploy target)\n * Default: 'workers'\n */\n mode?: 'workers' | 'pages'\n /**\n * Whether to write wrangler.toml in the project root if it does not exist.\n * Never overwrites an existing wrangler.toml.\n * Default: true\n */\n generateWrangler?: boolean\n}\n\nfunction readPackageJsonName(root: string): string | null {\n const pkgPath = resolvePath(root, 'package.json')\n if (!existsSync(pkgPath)) return null\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string }\n return typeof pkg.name === 'string' ? pkg.name : null\n } catch {\n return null\n }\n}\n\nfunction generateWorkerEntry(): string {\n return [\n '// AUTO-GENERATED by @aihu/adapter-cloudflare — do not edit',\n '// Cloudflare Workers entry — SPA mode',\n '//',\n '// All page requests are served from the ASSETS binding (Cloudflare CDN).',\n '// For SSR mode, upgrade to @aihu/adapter-cloudflare with ssr: true (V1+).',\n '',\n 'export default {',\n ' async fetch(request, env, _ctx) {',\n ' try {',\n ' return await env.ASSETS.fetch(request)',\n ' } catch {',\n ' // Fallback to index.html for client-side routing (404 from ASSETS).',\n ' const url = new URL(request.url)',\n \" const indexUrl = new URL('/index.html', url.origin)\",\n ' return env.ASSETS.fetch(new Request(indexUrl, request))',\n ' }',\n ' },',\n '}',\n ].join('\\n')\n}\n\nfunction generateWranglerToml(name: string): string {\n return
|
|
1
|
+
{"version":3,"file":"index.js","names":["resolvePath"],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { resolve as resolvePath } from 'node:path'\nimport type { AdapterContext, AihuAdapter } from '@aihu/app'\n\nexport interface CloudflareAdapterOptions {\n /**\n * Cloudflare Worker name. Used in generated wrangler.toml.\n * Default: value of \"name\" in the project's package.json, or 'aihu-app'.\n */\n name?: string\n /**\n * Deployment mode.\n * - 'workers': Cloudflare Workers with static assets via env.ASSETS binding\n * - 'pages': Cloudflare Pages (_worker.js convention — same output, different deploy target)\n * Default: 'workers'\n */\n mode?: 'workers' | 'pages'\n /**\n * Whether to write wrangler.toml in the project root if it does not exist.\n * Never overwrites an existing wrangler.toml.\n * Default: true\n */\n generateWrangler?: boolean\n}\n\nfunction readPackageJsonName(root: string): string | null {\n const pkgPath = resolvePath(root, 'package.json')\n if (!existsSync(pkgPath)) return null\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string }\n return typeof pkg.name === 'string' ? pkg.name : null\n } catch {\n return null\n }\n}\n\nfunction generateWorkerEntry(): string {\n return [\n '// AUTO-GENERATED by @aihu/adapter-cloudflare — do not edit',\n '// Cloudflare Workers entry — SPA mode',\n '//',\n '// All page requests are served from the ASSETS binding (Cloudflare CDN).',\n '// For SSR mode, upgrade to @aihu/adapter-cloudflare with ssr: true (V1+).',\n '',\n 'export default {',\n ' async fetch(request, env, _ctx) {',\n ' try {',\n ' return await env.ASSETS.fetch(request)',\n ' } catch {',\n ' // Fallback to index.html for client-side routing (404 from ASSETS).',\n ' const url = new URL(request.url)',\n \" const indexUrl = new URL('/index.html', url.origin)\",\n ' return env.ASSETS.fetch(new Request(indexUrl, request))',\n ' }',\n ' },',\n '}',\n ].join('\\n')\n}\n\nfunction generateWranglerToml(name: string): string {\n return `${[\n '# AUTO-GENERATED by @aihu/adapter-cloudflare',\n '# Edit this file to customize your Worker configuration.',\n '# Reference: https://developers.cloudflare.com/workers/wrangler/configuration/',\n '',\n `name = \"${name}\"`,\n 'main = \"_worker.js\"',\n 'compatibility_date = \"2024-01-01\"',\n '',\n '[assets]',\n 'directory = \".\"',\n 'binding = \"ASSETS\"',\n ].join('\\n')}\\n`\n}\n\n/**\n * Cloudflare Workers / Pages adapter for aihu.\n *\n * Writes `_worker.js` to the Vite output directory and optionally creates\n * `wrangler.toml` in the project root (if absent).\n *\n * @example\n * // aihu.config.ts\n * import { defineConfig } from '@aihu/app'\n * import { cloudflare } from '@aihu/adapter-cloudflare'\n *\n * export default defineConfig({\n * adapter: cloudflare({ name: 'my-worker' }),\n * })\n */\nexport function cloudflare(options?: CloudflareAdapterOptions): AihuAdapter {\n return {\n name: 'cloudflare',\n\n async adapt(context: AdapterContext): Promise<void> {\n const workerName = options?.name ?? readPackageJsonName(context.root) ?? 'aihu-app'\n\n // Step 1 — Write _worker.js\n const workerEntry = generateWorkerEntry()\n await context.emitFile('_worker.js', workerEntry)\n console.log(`[@aihu/adapter-cloudflare] Wrote _worker.js (SPA mode)`)\n\n // Step 2 — Write wrangler.toml (only if absent, never overwrites)\n const wranglerPath = resolvePath(context.root, 'wrangler.toml')\n if (options?.generateWrangler !== false && !existsSync(wranglerPath)) {\n const toml = generateWranglerToml(workerName)\n await context.writeFile(wranglerPath, toml)\n console.log(`[@aihu/adapter-cloudflare] Created wrangler.toml (name = \"${workerName}\")`)\n }\n\n console.log(`[@aihu/adapter-cloudflare] Build complete → ${context.outDir}`)\n console.log(`[@aihu/adapter-cloudflare] Deploy with: wrangler deploy --config wrangler.toml`)\n },\n }\n}\n"],"mappings":"2FAyBA,SAAS,EAAoB,EAA6B,CACxD,IAAM,EAAUA,EAAY,EAAM,eAAe,CACjD,GAAI,CAAC,EAAW,EAAQ,CAAE,OAAO,KACjC,GAAI,CACF,IAAM,EAAM,KAAK,MAAM,EAAa,EAAS,OAAO,CAAC,CACrD,OAAO,OAAO,EAAI,MAAS,SAAW,EAAI,KAAO,UAC3C,CACN,OAAO,MAIX,SAAS,GAA8B,CACrC,MAAO,CACL,8DACA,yCACA,KACA,4EACA,6EACA,GACA,mBACA,sCACA,YACA,+CACA,gBACA,6EACA,yCACA,4DACA,gEACA,QACA,OACA,IACD,CAAC,KAAK;EAAK,CAGd,SAAS,EAAqB,EAAsB,CAClD,MAAO,GAAG,CACR,+CACA,2DACA,iFACA,GACA,WAAW,EAAK,GAChB,sBACA,oCACA,GACA,WACA,kBACA,qBACD,CAAC,KAAK;EAAK,CAAC,IAkBf,SAAgB,EAAW,EAAiD,CAC1E,MAAO,CACL,KAAM,aAEN,MAAM,MAAM,EAAwC,CAClD,IAAM,EAAa,GAAS,MAAQ,EAAoB,EAAQ,KAAK,EAAI,WAGnE,EAAc,GAAqB,CACzC,MAAM,EAAQ,SAAS,aAAc,EAAY,CACjD,QAAQ,IAAI,yDAAyD,CAGrE,IAAM,EAAeA,EAAY,EAAQ,KAAM,gBAAgB,CAC/D,GAAI,GAAS,mBAAqB,IAAS,CAAC,EAAW,EAAa,CAAE,CACpE,IAAM,EAAO,EAAqB,EAAW,CAC7C,MAAM,EAAQ,UAAU,EAAc,EAAK,CAC3C,QAAQ,IAAI,6DAA6D,EAAW,IAAI,CAG1F,QAAQ,IAAI,+CAA+C,EAAQ,SAAS,CAC5E,QAAQ,IAAI,iFAAiF,EAEhG"}
|