@b9g/shovel 0.2.0-beta.10 → 0.2.0-beta.11

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/bin/create.js CHANGED
@@ -323,7 +323,7 @@ self.addEventListener("activate", (event) => {
323
323
  // Handle HTTP requests
324
324
  self.addEventListener("fetch", (event) => {
325
325
  try {
326
- const responsePromise = router.handler(event.request);
326
+ const responsePromise = router.handle(event.request);
327
327
  event.respondWith(responsePromise);
328
328
  } catch (error) {
329
329
  console.error("[${config.name}] Error handling request:", error);
@@ -365,7 +365,7 @@ router.route("/").get(async (request, context) => {
365
365
  <body>
366
366
  <h1>\u{1F680} Welcome to Shovel!</h1>
367
367
  <p>Your ${config.template} app is running on the <strong>${config.platform}</strong> platform.</p>
368
-
368
+
369
369
  <div class="info">
370
370
  <strong>Try these endpoints:</strong>
371
371
  <ul>
@@ -373,12 +373,12 @@ router.route("/").get(async (request, context) => {
373
373
  <li><a href="/api/time">GET /api/time</a> - Current timestamp</li>
374
374
  </ul>
375
375
  </div>
376
-
376
+
377
377
  <p>Edit <code>src/app.${config.typescript ? "ts" : "js"}</code> to customize your app!</p>
378
378
  </body>
379
379
  </html>
380
380
  \`;
381
-
381
+
382
382
  return new Response(html, {
383
383
  headers: { "Content-Type": "text/html" }
384
384
  });
@@ -408,7 +408,7 @@ router.route("/api/time").get(async (request, context) => {
408
408
  router.route("/").get(async (request, context) => {
409
409
  return new Response(JSON.stringify({
410
410
  name: "${config.name}",
411
- platform: "${config.platform}",
411
+ platform: "${config.platform}",
412
412
  endpoints: [
413
413
  { method: "GET", path: "/api/users", description: "Get all users" },
414
414
  { method: "POST", path: "/api/users", description: "Create a user" },
@@ -430,12 +430,12 @@ const users = [
430
430
  router.route("/api/users").get(async (request, context) => {
431
431
  const url = new URL(request.url);
432
432
  const active = url.searchParams.get('active');
433
-
433
+
434
434
  let filteredUsers = users;
435
435
  if (active !== null) {
436
436
  filteredUsers = users.filter(user => user.active === (active === 'true'));
437
437
  }
438
-
438
+
439
439
  return new Response(JSON.stringify({
440
440
  users: filteredUsers,
441
441
  total: filteredUsers.length
@@ -452,9 +452,9 @@ router.route("/api/users").post(async (request, context) => {
452
452
  email: userData.email || \`user\${Date.now()}@example.com\`,
453
453
  active: userData.active !== false
454
454
  };
455
-
455
+
456
456
  users.push(newUser);
457
-
457
+
458
458
  return new Response(JSON.stringify({
459
459
  success: true,
460
460
  user: newUser
@@ -467,7 +467,7 @@ router.route("/api/users").post(async (request, context) => {
467
467
  router.route("/api/users/:id").get(async (request, context) => {
468
468
  const id = parseInt(context.params.id);
469
469
  const user = users.find(u => u.id === id);
470
-
470
+
471
471
  if (!user) {
472
472
  return new Response(JSON.stringify({
473
473
  error: "User not found"
@@ -476,7 +476,7 @@ router.route("/api/users/:id").get(async (request, context) => {
476
476
  headers: { "Content-Type": "application/json" }
477
477
  });
478
478
  }
479
-
479
+
480
480
  return new Response(JSON.stringify({ user }), {
481
481
  headers: { "Content-Type": "application/json" }
482
482
  });
@@ -512,32 +512,32 @@ router.route("/").get(async (request, context) => {
512
512
  <body>
513
513
  <h1>\u{1F504} HTTP Echo Service</h1>
514
514
  <p>A simple HTTP request/response inspection service.</p>
515
-
515
+
516
516
  <div class="endpoint">
517
517
  <strong>POST /echo</strong><br>
518
518
  Echo back request details including headers, body, and metadata.
519
519
  </div>
520
-
520
+
521
521
  <div class="endpoint">
522
522
  <strong>GET /ip</strong><br>
523
523
  Get your IP address.
524
524
  </div>
525
-
525
+
526
526
  <div class="endpoint">
527
527
  <strong>GET /headers</strong><br>
528
528
  Get your request headers.
529
529
  </div>
530
-
530
+
531
531
  <div class="endpoint">
532
532
  <strong>GET /user-agent</strong><br>
533
533
  Get your user agent string.
534
534
  </div>
535
-
535
+
536
536
  <p>Try: <code>curl -X POST https://your-app.com/echo -d '{"test": "data"}'</code></p>
537
537
  </body>
538
538
  </html>
539
539
  \`;
540
-
540
+
541
541
  return new Response(html, {
542
542
  headers: { "Content-Type": "text/html" }
543
543
  });
@@ -546,24 +546,24 @@ router.route("/").get(async (request, context) => {
546
546
  router.route("/echo").all(async (request, context) => {
547
547
  const info = getRequestInfo(request);
548
548
  const body = await parseBody(request);
549
-
549
+
550
550
  const response = {
551
551
  ...info,
552
552
  body,
553
553
  contentType: request.headers.get("content-type") || null,
554
554
  timestamp: new Date().toISOString()
555
555
  };
556
-
556
+
557
557
  return new Response(JSON.stringify(response, null, 2), {
558
558
  headers: { "Content-Type": "application/json" }
559
559
  });
560
560
  });
561
561
 
562
562
  router.route("/ip").get(async (request, context) => {
563
- const ip = request.headers.get("x-forwarded-for") ||
564
- request.headers.get("x-real-ip") ||
563
+ const ip = request.headers.get("x-forwarded-for") ||
564
+ request.headers.get("x-real-ip") ||
565
565
  "127.0.0.1";
566
-
566
+
567
567
  return new Response(JSON.stringify({ ip }), {
568
568
  headers: { "Content-Type": "application/json" }
569
569
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/shovel",
3
- "version": "0.2.0-beta.10",
3
+ "version": "0.2.0-beta.11",
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
6
  "bin": {
@@ -10,41 +10,49 @@
10
10
  "create": "bin/create.js"
11
11
  },
12
12
  "dependencies": {
13
- "@b9g/async-context": "^0.1.4",
13
+ "@b9g/async-context": "^0.2.0-beta.0",
14
+ "@b9g/zen": "^0.1.6",
14
15
  "@clack/prompts": "^0.7.0",
15
16
  "@logtape/logtape": "^1.2.0",
16
17
  "commander": "^13.1.0",
17
- "esbuild": "^0.19.12",
18
+ "esbuild": "^0.27.2",
18
19
  "magic-string": "^0.30.5",
19
20
  "mime": "^4.0.4",
20
21
  "picocolors": "^1.0.0",
21
- "source-map": "^0.7.4"
22
+ "source-map": "^0.7.4",
23
+ "zod": "^3.23.0"
22
24
  },
23
25
  "devDependencies": {
24
- "@b9g/assets": "^0.1.15",
25
- "@b9g/cache": "^0.1.5",
26
+ "@b9g/assets": "^0.2.0-beta.0",
27
+ "@b9g/cache": "^0.2.0-beta.0",
26
28
  "@b9g/crank": "^0.7.2",
29
+ "@logtape/file": "^1.0.0",
27
30
  "@b9g/filesystem": "^0.1.7",
28
- "@b9g/http-errors": "^0.1.5",
29
- "@b9g/libuild": "^0.1.17",
31
+ "@b9g/http-errors": "^0.2.0-beta.0",
32
+ "@b9g/libuild": "^0.1.22",
30
33
  "@b9g/platform": "^0.1.12",
31
34
  "@b9g/platform-bun": "^0.1.10",
32
35
  "@b9g/platform-cloudflare": "^0.1.10",
33
36
  "@b9g/platform-node": "^0.1.12",
34
- "@b9g/router": "^0.1.10",
35
- "@types/bun": "^1.2.2",
37
+ "@b9g/router": "^0.2.0-beta.1",
38
+ "@types/bun": "^1.3.4",
39
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
40
+ "@typescript-eslint/parser": "^8.0.0",
41
+ "eslint": "^9.0.0",
42
+ "eslint-config-prettier": "^10.0.0",
43
+ "eslint-plugin-prettier": "^5.0.0",
36
44
  "mitata": "^1.0.34",
37
45
  "typescript": "^5.7.3"
38
46
  },
39
47
  "peerDependencies": {
40
- "@b9g/node-webworker": "^0.1.3",
48
+ "@b9g/node-webworker": "^0.2.0-beta.1",
41
49
  "@b9g/platform": "^0.1.12",
42
50
  "@b9g/platform-node": "^0.1.12",
43
51
  "@b9g/platform-cloudflare": "^0.1.10",
44
52
  "@b9g/platform-bun": "^0.1.10",
45
- "@b9g/cache": "^0.1.5",
53
+ "@b9g/cache": "^0.2.0-beta.0",
46
54
  "@b9g/filesystem": "^0.1.7",
47
- "@b9g/http-errors": "^0.1.5"
55
+ "@b9g/http-errors": "^0.2.0-beta.0"
48
56
  },
49
57
  "peerDependenciesMeta": {
50
58
  "@b9g/platform": {
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  applyJSXOptions,
3
+ assetsPlugin,
3
4
  importMetaPlugin,
4
5
  loadJSXConfig
5
- } from "./chunk-ILQUUH2L.js";
6
+ } from "./chunk-JJFM7PO2.js";
6
7
  import {
7
8
  DEFAULTS,
8
9
  findProjectRoot,
9
10
  getNodeModulesPath
10
- } from "./chunk-CSH7M4MK.js";
11
+ } from "./chunk-GRAFMTEH.js";
11
12
 
12
13
  // src/commands/activate.ts
13
14
  import { getLogger } from "@logtape/logtape";
@@ -15,17 +16,17 @@ import * as Platform from "@b9g/platform";
15
16
  import * as ESBuild from "esbuild";
16
17
  import { resolve, join } from "path";
17
18
  import { mkdir } from "fs/promises";
18
- import { assetsPlugin } from "@b9g/assets/plugin";
19
- var logger = getLogger(["cli"]);
19
+ var logger = getLogger(["shovel"]);
20
20
  async function activateCommand(entrypoint, options, config) {
21
21
  try {
22
22
  const platformName = Platform.resolvePlatform({ ...options, config });
23
23
  const workerCount = getWorkerCount(options, config);
24
24
  logger.debug("Platform: {platform}", { platform: platformName });
25
25
  logger.debug("Worker count: {workerCount}", { workerCount });
26
- logger.info("Building ServiceWorker for activation");
27
- const builtEntrypoint = await buildForActivate(entrypoint);
28
26
  const platformInstance = await Platform.createPlatform(platformName);
27
+ const platformESBuild = platformInstance.getESBuildConfig();
28
+ logger.info("Building ServiceWorker for activation");
29
+ const builtEntrypoint = await buildForActivate(entrypoint, platformESBuild);
29
30
  logger.info("Activating ServiceWorker", {});
30
31
  const serviceWorker = await platformInstance.loadServiceWorker(
31
32
  builtEntrypoint,
@@ -45,25 +46,26 @@ async function activateCommand(entrypoint, options, config) {
45
46
  process.exit(1);
46
47
  }
47
48
  }
48
- async function buildForActivate(entrypoint) {
49
+ async function buildForActivate(entrypoint, platformESBuildConfig) {
49
50
  const entryPath = resolve(entrypoint);
50
51
  const outputDir = resolve("dist");
51
52
  const serverDir = join(outputDir, "server");
52
53
  await mkdir(serverDir, { recursive: true });
53
- await mkdir(join(outputDir, "static"), { recursive: true });
54
+ await mkdir(join(outputDir, "public"), { recursive: true });
54
55
  const projectRoot = findProjectRoot();
55
56
  const jsxOptions = await loadJSXConfig(projectRoot);
56
57
  const outfile = join(serverDir, "server.js");
58
+ const external = platformESBuildConfig.external ?? ["node:*"];
57
59
  const buildConfig = {
58
60
  entryPoints: [entryPath],
59
61
  bundle: true,
60
62
  format: "esm",
61
63
  target: "es2022",
62
- platform: "node",
64
+ platform: platformESBuildConfig.platform ?? "node",
63
65
  outfile,
64
66
  absWorkingDir: projectRoot,
65
67
  mainFields: ["module", "main"],
66
- conditions: ["import", "module"],
68
+ conditions: platformESBuildConfig.conditions ?? ["import", "module"],
67
69
  nodePaths: [getNodeModulesPath()],
68
70
  plugins: [
69
71
  importMetaPlugin(),
@@ -77,7 +79,8 @@ async function buildForActivate(entrypoint) {
77
79
  }
78
80
  })
79
81
  ],
80
- external: ["node:*"]
82
+ define: platformESBuildConfig.define ?? {},
83
+ external
81
84
  };
82
85
  applyJSXOptions(buildConfig, jsxOptions);
83
86
  logger.debug("Building entrypoint: {entryPath}", { entryPath, outfile });