create-nodejs-fn 0.0.2 → 0.0.3
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 +37 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,27 +162,33 @@ Visit `http://localhost:5173/clock` to see a dynamically generated image with th
|
|
|
162
162
|
|
|
163
163
|
## 🪄 The Black Magic Revealed
|
|
164
164
|
|
|
165
|
-
### 1️⃣
|
|
165
|
+
### 1️⃣ Extract `nodejsFn` Contents (Clip & Crop)
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
Detects exported functions and **auto-generates proxy functions with identical type signatures**.
|
|
167
|
+
The plugin uses `ts-morph` to **statically analyze** `*.container.ts` files and **extracts the function bodies** wrapped in `nodejsFn()`.
|
|
169
168
|
|
|
170
169
|
```typescript
|
|
171
170
|
// Your code (clock.container.ts)
|
|
172
171
|
export const renderClock = nodejsFn(async () => {
|
|
173
|
-
|
|
172
|
+
const canvas = createCanvas(600, 200);
|
|
173
|
+
// ... Node.js native processing
|
|
174
174
|
return pngDataUrl;
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
// 🧙
|
|
178
|
-
// →
|
|
179
|
-
// → Calls are routed to the container via RPC!
|
|
177
|
+
// 🧙 Plugin extracts the inner function from nodejsFn()
|
|
178
|
+
// → Only the function body is clipped out for the container!
|
|
180
179
|
```
|
|
181
180
|
|
|
182
|
-
### 2️⃣
|
|
181
|
+
### 2️⃣ Bundle & Build Docker Image
|
|
182
|
+
|
|
183
|
+
The extracted functions are **bundled with esbuild** and combined with an auto-generated **Dockerfile** to create a Docker image.
|
|
184
|
+
|
|
185
|
+
- Functions are bundled as a Cap'n Proto RPC server
|
|
186
|
+
- Native dependencies specified in `external` are auto-extracted to `package.json`
|
|
187
|
+
- Dockerfile is auto-generated and image is built
|
|
183
188
|
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
### 3️⃣ Deploy as Cloudflare Containers
|
|
190
|
+
|
|
191
|
+
The generated Docker image is **bundled as Cloudflare Containers**, with **Durable Objects** managing the container lifecycle.
|
|
186
192
|
|
|
187
193
|
```typescript
|
|
188
194
|
// Route to specific instances with containerKey
|
|
@@ -195,11 +201,21 @@ export const renderClock = nodejsFn(
|
|
|
195
201
|
);
|
|
196
202
|
```
|
|
197
203
|
|
|
198
|
-
###
|
|
204
|
+
### 4️⃣ Auto-Replace Imports with Container Calls
|
|
205
|
+
|
|
206
|
+
Imports to `*.container.ts` files are **automatically replaced with proxy module imports** by the Vite plugin.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// Your code
|
|
210
|
+
import { renderClock } from "./clock.container";
|
|
211
|
+
|
|
212
|
+
// 🧙 Plugin auto-transforms this!
|
|
213
|
+
// → Actually imports a generated proxy function
|
|
214
|
+
// → Calls are transparently converted to Container RPC!
|
|
215
|
+
// → Types are fully preserved! IDE autocomplete works!
|
|
216
|
+
```
|
|
199
217
|
|
|
200
|
-
|
|
201
|
-
- **Auto-generates Dockerfile**
|
|
202
|
-
- Native deps specified in `external` are auto-extracted to `package.json`
|
|
218
|
+
**Result**: Code that looks like normal function calls actually executes inside Docker containers!
|
|
203
219
|
|
|
204
220
|
|
|
205
221
|
## ⚙️ Plugin Options
|
|
@@ -259,11 +275,13 @@ project/
|
|
|
259
275
|
│ ├── clock.container.ts # Your code
|
|
260
276
|
│ ├── index.ts # Worker entry
|
|
261
277
|
│ └── __generated__/ # 🧙 Auto-generated magic
|
|
262
|
-
│ ├── create-nodejs-fn.ts
|
|
263
|
-
│ ├── create-nodejs-fn.do.ts
|
|
264
|
-
│ ├── create-nodejs-fn.context.ts
|
|
265
|
-
│ ├── create-nodejs-fn.runtime.ts
|
|
266
|
-
│
|
|
278
|
+
│ ├── create-nodejs-fn.ts # RPC client & type definitions
|
|
279
|
+
│ ├── create-nodejs-fn.do.ts # Durable Object class
|
|
280
|
+
│ ├── create-nodejs-fn.context.ts # Container key resolution
|
|
281
|
+
│ ├── create-nodejs-fn.runtime.ts # nodejsFn / containerKey helpers
|
|
282
|
+
│ ├── create-nodejs-fn-stub-batch.ts # Cap'n Proto RPC batch client
|
|
283
|
+
│ └── __proxies__/
|
|
284
|
+
│ └── p-XXXXXXXX.ts # Proxy functions (hashed)
|
|
267
285
|
│
|
|
268
286
|
└── .create-nodejs-fn/ # 🐳 Container build artifacts
|
|
269
287
|
├── Dockerfile # Auto-generated
|
package/package.json
CHANGED