@tokamakdev/tok 0.1.1-beta.127 → 0.1.1-beta.129

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 CHANGED
@@ -17,10 +17,11 @@ npx tok targets
17
17
  | `@tokamakdev/tok/astro` | The Astro adapter, `tokamak()` |
18
18
  | `tok` | The CLI |
19
19
 
20
- Create a plugin with `tok plugin my-plugin`. It starts as a TypeScript package
21
- composing native context APIs. Add `--native apple` or `--native android` for a
22
- small Swift or Kotlin implementation. Install it in an app as a workspace or
23
- local npm dependency; Tokamak generates its clients and service bindings.
20
+ Create a plugin with `tok plugin new my-plugin`. It starts as a TypeScript package
21
+ composing native context APIs. Add `--platforms` with the platforms its native
22
+ code runs on, such as `ios,macos,android`, for a small Swift (iOS, macOS) or
23
+ Kotlin (Android) implementation. Install it in an app as a workspace or local
24
+ npm dependency; Tokamak generates its clients and service bindings.
24
25
  The generated README covers checking, local development, packing and publishing.
25
26
 
26
27
  The Vite integration includes Cloudflare's plugin. Its options are the app's
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { TokamakEntrypoint } from "@tokamakdev/plugin/worker";
1
+ export { TokamakEntrypoint, platform } from "@tokamakdev/plugin/worker";
2
2
  export type { TokamakContext, TokamakEvent, WebView } from "@tokamakdev/plugin/worker";
3
3
  /** A setting value. */
4
4
  export type Value = string | number | boolean;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { TokamakEntrypoint } from "@tokamakdev/plugin/worker";
1
+ export { TokamakEntrypoint, platform } from "@tokamakdev/plugin/worker";
@@ -3,8 +3,10 @@ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { normalizePath } from "vite";
6
+ import { platformGlobal } from "@tokamakdev/plugin/native-protocol";
6
7
  import { WorkerTypes } from "./worker-types.mjs";
7
8
  const NATIVE_CONNECTION = "virtual:tokamak/native-connection";
9
+ const PLATFORM = "virtual:tokamak/platform";
8
10
  const NATIVE_CALLS = normalizePath(fileURLToPath(new URL("./native.mjs", import.meta.url)));
9
11
  /** The two Workers' roles: the app's main Worker and the Tokamak worker. */
10
12
  const ROLES = ["main", "native"];
@@ -177,7 +179,7 @@ export const TokamakEvents = eventEntrypoint(Worker, nativeContext);\n`);
177
179
  return [];
178
180
  },
179
181
  resolveId(id) {
180
- if ([NATIVE_CONNECTION, serviceModule("main"), serviceModule("native")].includes(id))
182
+ if ([NATIVE_CONNECTION, PLATFORM, serviceModule("main"), serviceModule("native")].includes(id))
181
183
  return `\0${id}`;
182
184
  if (id.startsWith("\0tokamak:") || id.startsWith("\0virtual:tokamak/"))
183
185
  return id;
@@ -185,6 +187,8 @@ export const TokamakEvents = eventEntrypoint(Worker, nativeContext);\n`);
185
187
  async load(id) {
186
188
  if (id === `\0${NATIVE_CONNECTION}`)
187
189
  return nativeConnectionModule(dev ? relay : undefined);
190
+ if (id === `\0${PLATFORM}`)
191
+ return platformModule(relay);
188
192
  const role = ROLES.find(role => id === bindingsModule(role) || id === `\0${serviceModule(role)}`);
189
193
  if (!role)
190
194
  return;
@@ -205,7 +209,8 @@ export { Service${index} as ${JSON.stringify(name)} };`);
205
209
  const hostEvents = role === "native"
206
210
  ? `export const TokamakEvents = developmentEvents(module.TokamakEvents, ${JSON.stringify(bindings(role))});`
207
211
  : "";
208
- return `import ${JSON.stringify(bindingsModule(role))};
212
+ return `import ${JSON.stringify(PLATFORM)};
213
+ import ${JSON.stringify(bindingsModule(role))};
209
214
  import * as module from ${source};
210
215
  export * from ${source};
211
216
  import { developmentEntrypoint, developmentEvents } from ${JSON.stringify(development)};
@@ -257,6 +262,15 @@ function nativeConnectionModule(relay) {
257
262
  return `import { connectDevice } from ${JSON.stringify(NATIVE_CALLS)};
258
263
  export const connect = ctx => connectDevice(${JSON.stringify(relay)}, ctx);`;
259
264
  }
265
+ /**
266
+ * The module that names the `relay`'s device platform for `@tokamakdev/plugin`, as the native
267
+ * runtime does, before the development Workers' modules run.
268
+ */
269
+ function platformModule(relay) {
270
+ if (!relay?.platform)
271
+ return "";
272
+ return `globalThis.${platformGlobal} = ${JSON.stringify(relay.platform)};`;
273
+ }
260
274
  /** The native platforms of each plugin operation. */
261
275
  function availability(plugins) {
262
276
  return Object.fromEntries(plugins.map(({ definition, operations }) => [definition.id, operations]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/tok",
3
- "version": "0.1.1-beta.127",
3
+ "version": "0.1.1-beta.129",
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",
@@ -43,7 +43,7 @@
43
43
  "node": ">=18"
44
44
  },
45
45
  "dependencies": {
46
- "@tokamakdev/plugin": "0.1.0-beta.127",
46
+ "@tokamakdev/plugin": "0.1.0-beta.129",
47
47
  "typescript": "5.9.3",
48
48
  "ws": "^8.22.0"
49
49
  },
@@ -75,17 +75,17 @@
75
75
  "wrangler": "4.147.0"
76
76
  },
77
77
  "optionalDependencies": {
78
- "@tokamakdev/platform-android-arm64": "0.1.1-beta.127",
79
- "@tokamakdev/platform-ios-arm64": "0.1.1-beta.127",
80
- "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.127",
81
- "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.127",
82
- "@tokamakdev/platform-macos-arm64": "0.1.1-beta.127",
83
- "@tokamakdev/platform-macos-x64": "0.1.1-beta.127",
84
- "@tokamakdev/platform-windows-x64": "0.1.1-beta.127",
85
- "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.127",
86
- "@tokamakdev/tok-darwin-x64": "0.1.1-beta.127",
87
- "@tokamakdev/tok-linux-x64": "0.1.1-beta.127",
88
- "@tokamakdev/tok-win32-x64": "0.1.1-beta.127"
78
+ "@tokamakdev/platform-android-arm64": "0.1.1-beta.129",
79
+ "@tokamakdev/platform-ios-arm64": "0.1.1-beta.129",
80
+ "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.129",
81
+ "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.129",
82
+ "@tokamakdev/platform-macos-arm64": "0.1.1-beta.129",
83
+ "@tokamakdev/platform-macos-x64": "0.1.1-beta.129",
84
+ "@tokamakdev/platform-windows-x64": "0.1.1-beta.129",
85
+ "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.129",
86
+ "@tokamakdev/tok-darwin-x64": "0.1.1-beta.129",
87
+ "@tokamakdev/tok-linux-x64": "0.1.1-beta.129",
88
+ "@tokamakdev/tok-win32-x64": "0.1.1-beta.129"
89
89
  },
90
90
  "publishConfig": {
91
91
  "access": "public"