@b9g/shovel 0.2.3 → 0.2.4
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/LICENSE +1 -1
- package/README.md +58 -48
- package/bin/cli.js +11 -3
- package/bin/create.js +2 -2
- package/package.json +17 -20
- package/src/_chunks/{build-BM4A74RI.js → build-KBQU2OA7.js} +2 -2
- package/src/_chunks/{chunk-NZVIBZYG.js → chunk-7GONPLNW.js} +1 -1
- package/src/_chunks/{chunk-WVHECOTO.js → chunk-ABGHNBNM.js} +1 -1
- package/src/_chunks/{develop-6DPQE5H4.js → develop-JUQG2G7M.js} +2 -2
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2026 Brian Kim
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
# Shovel.js
|
|
1
|
+
# Shovel.js
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Run Service Workers anywhere.**
|
|
4
4
|
|
|
5
|
-
Shovel is a
|
|
5
|
+
Shovel is a meta-framework for building server applications using the ServiceWorker API. Write once, deploy to Node.js, Bun, or Cloudflare Workers.
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
//
|
|
7
|
+
```typescript
|
|
8
|
+
// server.ts
|
|
9
9
|
import {Router} from "@b9g/router";
|
|
10
|
+
|
|
10
11
|
const router = new Router();
|
|
11
12
|
|
|
12
|
-
router.route("/")
|
|
13
|
+
router.route("/kv/:key")
|
|
14
|
+
.get(async (req, ctx) => {
|
|
15
|
+
const cache = await self.caches.open("kv");
|
|
16
|
+
const cached = await cache.match(ctx.params.key);
|
|
17
|
+
return cached ?? new Response(null, {status: 404});
|
|
18
|
+
})
|
|
19
|
+
.put(async (req, ctx) => {
|
|
20
|
+
const cache = await self.caches.open("kv");
|
|
21
|
+
await cache.put(ctx.params.key, new Response(await req.text()));
|
|
22
|
+
return new Response(null, {status: 201});
|
|
23
|
+
})
|
|
24
|
+
.delete(async (req, ctx) => {
|
|
25
|
+
const cache = await self.caches.open("kv");
|
|
26
|
+
await cache.delete(ctx.params.key);
|
|
27
|
+
return new Response(null, {status: 204});
|
|
28
|
+
});
|
|
13
29
|
|
|
14
30
|
self.addEventListener("fetch", (ev) => {
|
|
15
31
|
ev.respondWith(router.handle(ev.request));
|
|
@@ -17,30 +33,20 @@ self.addEventListener("fetch", (ev) => {
|
|
|
17
33
|
```
|
|
18
34
|
|
|
19
35
|
```bash
|
|
20
|
-
shovel develop
|
|
21
|
-
|
|
22
|
-
## Quick Start
|
|
36
|
+
$ shovel develop server.ts
|
|
37
|
+
listening on http://localhost:7777
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
// src/server.js
|
|
26
|
-
import {Router} from "@b9g/router";
|
|
39
|
+
$ curl -X PUT :7777/kv/hello -d "world"
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
router.route("/").get(() => new Response("Hello World"));
|
|
31
|
-
|
|
32
|
-
router.route("/greet/:name").get((request, {params}) => {
|
|
33
|
-
return new Response(`Hello ${params.name}`);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
self.addEventListener("fetch", (event) => {
|
|
37
|
-
event.respondWith(router.handle(event.request));
|
|
38
|
-
});
|
|
41
|
+
$ curl :7777/kv/hello
|
|
42
|
+
world
|
|
39
43
|
```
|
|
40
44
|
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
41
47
|
```bash
|
|
42
48
|
# Create a new project
|
|
43
|
-
npm create
|
|
49
|
+
npm create shovel my-app
|
|
44
50
|
|
|
45
51
|
# Development with hot reload
|
|
46
52
|
npx @b9g/shovel develop src/server.ts
|
|
@@ -51,19 +57,23 @@ npx @b9g/shovel build src/server.ts --platform=bun
|
|
|
51
57
|
npx @b9g/shovel build src/server.ts --platform=cloudflare
|
|
52
58
|
```
|
|
53
59
|
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
Visit [shovel.js.org](https://shovel.js.org) for guides and API reference.
|
|
54
63
|
|
|
55
64
|
## Web Standards
|
|
65
|
+
|
|
56
66
|
Shovel is obsessively standards-first. All Shovel APIs use web standards, and Shovel implements/shims useful standards when they're missing.
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
| API | Standard | Purpose |
|
|
69
|
+
|-----|----------|---------|
|
|
70
|
+
| `fetch()` | [Fetch](https://fetch.spec.whatwg.org) | Networking |
|
|
71
|
+
| `install`, `activate`, `fetch` events | [Service Workers](https://w3c.github.io/ServiceWorker/) | Server lifecycle |
|
|
72
|
+
| `AsyncContext.Variable` | [TC39 Stage 2](https://github.com/tc39/proposal-async-context) | Request-scoped state |
|
|
73
|
+
| `self.caches` | [Cache API](https://w3c.github.io/ServiceWorker/#cache-interface) | Response caching |
|
|
74
|
+
| `self.directories` | [FileSystem API](https://fs.spec.whatwg.org/) | Storage (local, S3, R2) |
|
|
75
|
+
| `self.cookieStore` | [CookieStore API](https://cookiestore.spec.whatwg.org) | Cookie management |
|
|
76
|
+
| `URLPattern` | [URLPattern](https://urlpattern.spec.whatwg.org/) | Route matching |
|
|
67
77
|
|
|
68
78
|
Your code uses standards. Shovel makes them work everywhere.
|
|
69
79
|
|
|
@@ -87,7 +97,7 @@ The core abstraction is the **ServiceWorker-style storage pattern**. Globals pro
|
|
|
87
97
|
const cache = await self.caches.open("sessions"); // Cache API
|
|
88
98
|
const dir = await self.directories.open("uploads"); // FileSystem API
|
|
89
99
|
const db = self.databases.get("main"); // Zen DB (opened on activate)
|
|
90
|
-
const logger = self.loggers.get(["app", "requests"]);
|
|
100
|
+
const logger = self.loggers.get(["app", "requests"]); // LogTape
|
|
91
101
|
```
|
|
92
102
|
|
|
93
103
|
Each storage type is:
|
|
@@ -168,27 +178,27 @@ Shovel's configuration follows these principles:
|
|
|
168
178
|
|
|
169
179
|
```json
|
|
170
180
|
{
|
|
171
|
-
"port": "PORT ||
|
|
172
|
-
"host": "HOST || localhost",
|
|
173
|
-
"workers": "WORKERS ?? 1",
|
|
181
|
+
"port": "$PORT || 7777",
|
|
182
|
+
"host": "$HOST || localhost",
|
|
183
|
+
"workers": "$WORKERS ?? 1",
|
|
174
184
|
"caches": {
|
|
175
185
|
"sessions": {
|
|
176
186
|
"module": "@b9g/cache-redis",
|
|
177
187
|
"export": "RedisCache",
|
|
178
|
-
"url": "REDIS_URL"
|
|
188
|
+
"url": "$REDIS_URL"
|
|
179
189
|
}
|
|
180
190
|
},
|
|
181
191
|
"directories": {
|
|
182
192
|
"uploads": {
|
|
183
193
|
"module": "@b9g/filesystem-s3",
|
|
184
194
|
"export": "S3Directory",
|
|
185
|
-
"bucket": "S3_BUCKET"
|
|
195
|
+
"bucket": "$S3_BUCKET"
|
|
186
196
|
}
|
|
187
197
|
},
|
|
188
198
|
"databases": {
|
|
189
199
|
"main": {
|
|
190
200
|
"module": "@b9g/zen/bun",
|
|
191
|
-
"url": "DATABASE_URL"
|
|
201
|
+
"url": "$DATABASE_URL"
|
|
192
202
|
}
|
|
193
203
|
},
|
|
194
204
|
"logging": {
|
|
@@ -213,7 +223,7 @@ Configure cache backends using `module` and `export`:
|
|
|
213
223
|
"sessions": {
|
|
214
224
|
"module": "@b9g/cache-redis",
|
|
215
225
|
"export": "RedisCache",
|
|
216
|
-
"url": "REDIS_URL"
|
|
226
|
+
"url": "$REDIS_URL"
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
}
|
|
@@ -292,7 +302,7 @@ Configure database drivers using the same `module`/`export` pattern:
|
|
|
292
302
|
"databases": {
|
|
293
303
|
"main": {
|
|
294
304
|
"module": "@b9g/zen/bun",
|
|
295
|
-
"url": "DATABASE_URL"
|
|
305
|
+
"url": "$DATABASE_URL"
|
|
296
306
|
}
|
|
297
307
|
}
|
|
298
308
|
}
|
|
@@ -359,7 +369,7 @@ $DATADIR/uploads → joins env var with path segment
|
|
|
359
369
|
|
|
360
370
|
```json
|
|
361
371
|
{
|
|
362
|
-
"port": "$PORT ||
|
|
372
|
+
"port": "$PORT || 7777",
|
|
363
373
|
"host": "$HOST || 0.0.0.0",
|
|
364
374
|
"directories": {
|
|
365
375
|
"server": { "path": "[outdir]/server" },
|
|
@@ -388,17 +398,17 @@ console.log(config.port); // Resolved value
|
|
|
388
398
|
| Package | Description |
|
|
389
399
|
|---------|-------------|
|
|
390
400
|
| `@b9g/shovel` | CLI for development and deployment |
|
|
391
|
-
| `@b9g/platform` | Core runtime and platform APIs |
|
|
392
|
-
| `@b9g/platform-node` | Node.js adapter |
|
|
393
|
-
| `@b9g/platform-bun` | Bun.js adapter |
|
|
394
|
-
| `@b9g/platform-cloudflare` | Cloudflare Workers adapter |
|
|
395
401
|
| `@b9g/router` | URLPattern-based routing with middleware |
|
|
396
402
|
| `@b9g/cache` | Cache API implementation |
|
|
397
403
|
| `@b9g/filesystem` | File System Access implementation |
|
|
398
|
-
| `@b9g/match-pattern` | URLPattern with extensions (100% WPT) |
|
|
399
404
|
| `@b9g/async-context` | AsyncContext.Variable implementation |
|
|
400
405
|
| `@b9g/http-errors` | Standard HTTP error classes |
|
|
401
406
|
| `@b9g/assets` | Static asset handling |
|
|
407
|
+
| `@b9g/platform` | Core runtime and platform APIs |
|
|
408
|
+
| `@b9g/platform-node` | Node.js adapter |
|
|
409
|
+
| `@b9g/platform-bun` | Bun adapter |
|
|
410
|
+
| `@b9g/platform-cloudflare` | Cloudflare Workers adapter |
|
|
411
|
+
| `@b9g/match-pattern` | URLPattern with extensions (100% WPT) |
|
|
402
412
|
|
|
403
413
|
## License
|
|
404
414
|
|
package/bin/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
DEFAULTS,
|
|
6
6
|
findProjectRoot,
|
|
7
7
|
loadConfig
|
|
8
|
-
} from "../src/_chunks/chunk-
|
|
8
|
+
} from "../src/_chunks/chunk-7GONPLNW.js";
|
|
9
9
|
|
|
10
10
|
// bin/cli.ts
|
|
11
11
|
import { resolve, relative } from "path";
|
|
@@ -75,15 +75,23 @@ program.command("develop <entrypoint>").description("Start development server wi
|
|
|
75
75
|
DEFAULTS.WORKERS
|
|
76
76
|
).option("--platform <name>", "Runtime platform (node, cloudflare, bun)").action(async (entrypoint, options) => {
|
|
77
77
|
checkPlatformReexec(options);
|
|
78
|
-
const { developCommand } = await import("../src/_chunks/develop-
|
|
78
|
+
const { developCommand } = await import("../src/_chunks/develop-JUQG2G7M.js");
|
|
79
79
|
await developCommand(entrypoint, options, config);
|
|
80
80
|
});
|
|
81
|
+
program.command("create [name]").description("Create a new Shovel project").action(async (name) => {
|
|
82
|
+
if (name) {
|
|
83
|
+
process.argv = [process.argv[0], process.argv[1], name];
|
|
84
|
+
} else {
|
|
85
|
+
process.argv = [process.argv[0], process.argv[1]];
|
|
86
|
+
}
|
|
87
|
+
await import("./create.js");
|
|
88
|
+
});
|
|
81
89
|
program.command("build <entrypoint>").description("Build app for production").option("--platform <name>", "Runtime platform (node, cloudflare, bun)").option(
|
|
82
90
|
"--lifecycle [stage]",
|
|
83
91
|
"Run ServiceWorker lifecycle after build (install or activate, default: activate)"
|
|
84
92
|
).action(async (entrypoint, options) => {
|
|
85
93
|
checkPlatformReexec(options);
|
|
86
|
-
const { buildCommand } = await import("../src/_chunks/build-
|
|
94
|
+
const { buildCommand } = await import("../src/_chunks/build-KBQU2OA7.js");
|
|
87
95
|
await buildCommand(entrypoint, options, config);
|
|
88
96
|
process.exit(0);
|
|
89
97
|
});
|
package/bin/create.js
CHANGED
|
@@ -134,7 +134,7 @@ async function main() {
|
|
|
134
134
|
console.info(` npm install`);
|
|
135
135
|
console.info(` npm run dev`);
|
|
136
136
|
console.info("");
|
|
137
|
-
console.info("Your app will be available at: http://localhost:
|
|
137
|
+
console.info("Your app will be available at: http://localhost:7777");
|
|
138
138
|
console.info("");
|
|
139
139
|
} catch (error) {
|
|
140
140
|
s.stop("Failed to create project");
|
|
@@ -497,7 +497,7 @@ npm install
|
|
|
497
497
|
npm run dev
|
|
498
498
|
\`\`\`
|
|
499
499
|
|
|
500
|
-
Open http://localhost:
|
|
500
|
+
Open http://localhost:7777
|
|
501
501
|
|
|
502
502
|
## Scripts
|
|
503
503
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/shovel",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "ServiceWorker-first universal deployment platform. Write ServiceWorker apps once, deploy anywhere (Node/Bun/Cloudflare). Registry-based multi-app orchestration.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/bikeshaving/shovel.git"
|
|
9
|
+
},
|
|
6
10
|
"bin": {
|
|
7
11
|
"shovel": "bin/cli.js",
|
|
8
12
|
"create-shovel": "bin/create.js",
|
|
@@ -10,15 +14,15 @@
|
|
|
10
14
|
"create": "bin/create.js"
|
|
11
15
|
},
|
|
12
16
|
"dependencies": {
|
|
13
|
-
"@b9g/async-context": "^0.2.
|
|
14
|
-
"@b9g/cache": "^0.2.
|
|
15
|
-
"@b9g/filesystem": "^0.1.
|
|
16
|
-
"@b9g/http-errors": "^0.2.
|
|
17
|
-
"@b9g/node-webworker": "^0.2.
|
|
18
|
-
"@b9g/platform": "^0.1.
|
|
19
|
-
"@b9g/platform-bun": "^0.1.
|
|
20
|
-
"@b9g/platform-cloudflare": "^0.1.
|
|
21
|
-
"@b9g/platform-node": "^0.1.
|
|
17
|
+
"@b9g/async-context": "^0.2.1",
|
|
18
|
+
"@b9g/cache": "^0.2.1",
|
|
19
|
+
"@b9g/filesystem": "^0.1.9",
|
|
20
|
+
"@b9g/http-errors": "^0.2.1",
|
|
21
|
+
"@b9g/node-webworker": "^0.2.1",
|
|
22
|
+
"@b9g/platform": "^0.1.16",
|
|
23
|
+
"@b9g/platform-bun": "^0.1.14",
|
|
24
|
+
"@b9g/platform-cloudflare": "^0.1.14",
|
|
25
|
+
"@b9g/platform-node": "^0.1.16",
|
|
22
26
|
"@clack/prompts": "^0.7.0",
|
|
23
27
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
24
28
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
@@ -29,18 +33,11 @@
|
|
|
29
33
|
"zod": "^3.23.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@b9g/assets": "^0.2.
|
|
33
|
-
"@b9g/cache": "^0.2.0",
|
|
36
|
+
"@b9g/assets": "^0.2.1",
|
|
34
37
|
"@b9g/crank": "^0.7.2",
|
|
35
|
-
"@logtape/file": "^1.0.0",
|
|
36
|
-
"@b9g/filesystem": "^0.1.8",
|
|
37
|
-
"@b9g/http-errors": "^0.2.0",
|
|
38
38
|
"@b9g/libuild": "^0.1.22",
|
|
39
|
-
"@b9g/
|
|
40
|
-
"@
|
|
41
|
-
"@b9g/platform-cloudflare": "^0.1.13",
|
|
42
|
-
"@b9g/platform-node": "^0.1.15",
|
|
43
|
-
"@b9g/router": "^0.2.0",
|
|
39
|
+
"@b9g/router": "^0.2.1",
|
|
40
|
+
"@logtape/file": "^1.0.0",
|
|
44
41
|
"@types/bun": "^1.3.4",
|
|
45
42
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
46
43
|
"@typescript-eslint/parser": "^8.0.0",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ServerBundler,
|
|
3
3
|
loadPlatformModule
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ABGHNBNM.js";
|
|
5
5
|
import {
|
|
6
6
|
findProjectRoot,
|
|
7
7
|
findWorkspaceRoot
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-7GONPLNW.js";
|
|
9
9
|
|
|
10
10
|
// src/commands/build.ts
|
|
11
11
|
import { resolve, join, dirname, basename } from "path";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ServerBundler,
|
|
3
3
|
loadPlatformModule
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ABGHNBNM.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULTS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7GONPLNW.js";
|
|
8
8
|
|
|
9
9
|
// src/commands/develop.ts
|
|
10
10
|
import { getLogger } from "@logtape/logtape";
|