@aihu/adapter-cloudflare 0.1.1 → 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 +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install @aihu/adapter-cloudflare
|
|
|
21
21
|
bun add @aihu/adapter-cloudflare
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
24
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
25
25
|
|
|
26
26
|
<!-- END_AUTOGEN: install -->
|
|
27
27
|
|
|
@@ -37,7 +37,7 @@ bun add @aihu/adapter-cloudflare
|
|
|
37
37
|
| **Published files** | 3 entries |
|
|
38
38
|
| **License** | MIT |
|
|
39
39
|
|
|
40
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
40
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
41
41
|
|
|
42
42
|
<!-- END_AUTOGEN: stats -->
|
|
43
43
|
|
|
@@ -50,7 +50,7 @@ bun add @aihu/adapter-cloudflare
|
|
|
50
50
|
|---|---|---|
|
|
51
51
|
| `.` | `./dist/index.js` | `—` |
|
|
52
52
|
|
|
53
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
53
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
54
54
|
|
|
55
55
|
<!-- END_AUTOGEN: exports -->
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ bun add @aihu/adapter-cloudflare
|
|
|
64
64
|
- `@aihu/app` — `workspace:*`
|
|
65
65
|
- `vite` — `>=5.0.0`
|
|
66
66
|
|
|
67
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
67
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
68
68
|
|
|
69
69
|
<!-- END_AUTOGEN: deps -->
|
|
70
70
|
|
|
@@ -77,7 +77,7 @@ bun add @aihu/adapter-cloudflare
|
|
|
77
77
|
- [@aihu/server](../server)
|
|
78
78
|
- [Aihu framework root](../../README.md)
|
|
79
79
|
|
|
80
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
80
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
81
81
|
|
|
82
82
|
<!-- END_AUTOGEN: see-also -->
|
|
83
83
|
|
|
@@ -88,6 +88,6 @@ bun add @aihu/adapter-cloudflare
|
|
|
88
88
|
|
|
89
89
|
MIT — see [LICENSE](../../LICENSE).
|
|
90
90
|
|
|
91
|
-
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1
|
|
91
|
+
<sub><i>Auto-generated against `@aihu/adapter-cloudflare@0.1.1`.</i></sub>
|
|
92
92
|
|
|
93
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aihu/adapter-cloudflare",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"prepublishOnly": "bun run build"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@aihu/app": "
|
|
28
|
+
"@aihu/app": "workspace:*",
|
|
29
29
|
"vite": ">=5.0.0"
|
|
30
30
|
},
|
|
31
31
|
"description": "Cloudflare Workers/Pages deployment adapter for @aihu/app.",
|