@tokamakdev/tok 0.1.1-beta.81 → 0.1.1-beta.82

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/dist/vite.d.mts CHANGED
@@ -2,8 +2,9 @@ import { type Plugin } from "vite";
2
2
  import type { Config } from "./index.mjs";
3
3
  /**
4
4
  * Reports the app's tokamak configuration, and the development server's
5
- * address and Worker name, to `tok`, and makes the entry Worker import
6
- * `module`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it adds no hooks.
5
+ * address, HTTPS certificate and Worker name, to `tok`, and makes the entry
6
+ * Worker import `module`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it
7
+ * adds no hooks.
7
8
  */
8
9
  export declare function tokamak({ module, ...config }?: Config & {
9
10
  /**
package/dist/vite.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { X509Certificate } from "node:crypto";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { normalizePath } from "vite";
@@ -5,10 +6,12 @@ import { normalizePath } from "vite";
5
6
  const DEFAULT_MODULES = ["src/tokamak.ts", "src/tokamak.js"];
6
7
  /** Wrangler configuration files Cloudflare's plugin tries in order. */
7
8
  const WRANGLER_FILES = ["wrangler.jsonc", "wrangler.json", "wrangler.toml"];
9
+ const MIDDLEWARE_MODE_ERROR = "Vite is running in middleware mode, so tokamak cannot find the development server's address; tok dev needs Vite's own dev server";
8
10
  /**
9
11
  * Reports the app's tokamak configuration, and the development server's
10
- * address and Worker name, to `tok`, and makes the entry Worker import
11
- * `module`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it adds no hooks.
12
+ * address, HTTPS certificate and Worker name, to `tok`, and makes the entry
13
+ * Worker import `module`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it
14
+ * adds no hooks.
12
15
  */
13
16
  export function tokamak({ module, ...config } = {}) {
14
17
  const output = process.env.TOKAMAK_VITE_OUTPUT;
@@ -29,13 +32,22 @@ export function tokamak({ module, ...config } = {}) {
29
32
  },
30
33
  async configureServer(server) {
31
34
  const httpServer = server.httpServer;
35
+ // A middleware-mode server beside a reported one, such as the server
36
+ // Astro syncs content with, leaves the report in place.
32
37
  if (!httpServer) {
38
+ if (!fs.existsSync(path.join(output, "server.json"))) {
39
+ writeJson(output, "server.json", { error: MIDDLEWARE_MODE_ERROR });
40
+ }
33
41
  return;
34
42
  }
35
43
  const workerName = await readWorkerName(server.config.root);
36
44
  httpServer.on("listening", () => {
37
45
  const urls = server.resolvedUrls;
38
- writeJson(output, "server.json", { url: urls?.local[0] ?? urls?.network[0], workerName });
46
+ writeJson(output, "server.json", {
47
+ url: urls?.local[0] ?? urls?.network[0],
48
+ workerName,
49
+ certificates: endEntityCertificates(server.config.server.https),
50
+ });
39
51
  });
40
52
  },
41
53
  async buildApp(builder) {
@@ -92,6 +104,22 @@ async function readWorkerName(root) {
92
104
  const worker = unstable_readConfig({ config: file, env: process.env.CLOUDFLARE_ENV }, { hideWarnings: true });
93
105
  return worker.topLevelName ?? worker.name;
94
106
  }
107
+ /**
108
+ * The PEM of the end-entity certificate of each chain in `https.cert`, which
109
+ * Vite reads from a file when a string names one.
110
+ */
111
+ function endEntityCertificates(https) {
112
+ const cert = typeof https?.cert === "string" ? readFileIfExists(https.cert) : https?.cert;
113
+ return cert && [cert].flat().map((chain) => new X509Certificate(chain).toString()).join("");
114
+ }
115
+ function readFileIfExists(file) {
116
+ try {
117
+ return fs.readFileSync(path.resolve(file));
118
+ }
119
+ catch {
120
+ return file;
121
+ }
122
+ }
95
123
  /**
96
124
  * Whether an environment builds from the entry Worker: Cloudflare's plugin
97
125
  * gives a manifest to its entry and prerender Workers, and Astro to its server
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/tok",
3
- "version": "0.1.1-beta.81",
3
+ "version": "0.1.1-beta.82",
4
4
  "description": "The tokamak CLI, Vite plugin and app API: build native apps from a Cloudflare Workers codebase",
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,17 +55,17 @@
55
55
  "wrangler": "4.147.0"
56
56
  },
57
57
  "optionalDependencies": {
58
- "@tokamakdev/platform-android-arm64": "0.1.1-beta.81",
59
- "@tokamakdev/platform-ios-arm64": "0.1.1-beta.81",
60
- "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.81",
61
- "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.81",
62
- "@tokamakdev/platform-macos-arm64": "0.1.1-beta.81",
63
- "@tokamakdev/platform-macos-x64": "0.1.1-beta.81",
64
- "@tokamakdev/platform-windows-x64": "0.1.1-beta.81",
65
- "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.81",
66
- "@tokamakdev/tok-darwin-x64": "0.1.1-beta.81",
67
- "@tokamakdev/tok-linux-x64": "0.1.1-beta.81",
68
- "@tokamakdev/tok-win32-x64": "0.1.1-beta.81"
58
+ "@tokamakdev/platform-android-arm64": "0.1.1-beta.82",
59
+ "@tokamakdev/platform-ios-arm64": "0.1.1-beta.82",
60
+ "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.82",
61
+ "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.82",
62
+ "@tokamakdev/platform-macos-arm64": "0.1.1-beta.82",
63
+ "@tokamakdev/platform-macos-x64": "0.1.1-beta.82",
64
+ "@tokamakdev/platform-windows-x64": "0.1.1-beta.82",
65
+ "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.82",
66
+ "@tokamakdev/tok-darwin-x64": "0.1.1-beta.82",
67
+ "@tokamakdev/tok-linux-x64": "0.1.1-beta.82",
68
+ "@tokamakdev/tok-win32-x64": "0.1.1-beta.82"
69
69
  },
70
70
  "publishConfig": {
71
71
  "access": "public"