@tokamakdev/plugin 0.1.0-beta.50 → 0.1.0-beta.52

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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/worker.ts +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/plugin",
3
- "version": "0.1.0-beta.50",
3
+ "version": "0.1.0-beta.52",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mantty/tokamak.git",
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "type": "module",
10
10
  "exports": {
11
- ".": "./src/index.ts"
11
+ ".": "./src/index.ts",
12
+ "./worker": "./src/worker.ts"
12
13
  },
13
14
  "files": [
14
15
  "src"
package/src/worker.ts ADDED
@@ -0,0 +1,17 @@
1
+ declare const process:
2
+ | { readonly env: { readonly NODE_ENV?: string; readonly TOKAMAK_RUNTIME?: string } }
3
+ | undefined;
4
+
5
+ /**
6
+ * Whether the Worker serves the tokamak runtime's calls to endpoints under `/tokamak/`: in a
7
+ * tokamak app, where the runtime sets `TOKAMAK_RUNTIME`, and in development. Those endpoints
8
+ * refuse requests otherwise.
9
+ */
10
+ export function acceptsRuntimeCalls(): boolean {
11
+ // One expression: Rollup 4.63.0 drops callers' checks when this is an early return followed
12
+ // by a return of `typeof process !== "undefined" && false`.
13
+ return (
14
+ typeof process !== "undefined" &&
15
+ (process.env.NODE_ENV === "development" || process.env.TOKAMAK_RUNTIME === "true")
16
+ );
17
+ }