@noego/wood 0.4.7 → 0.4.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noego/wood",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,9 +20,11 @@
20
20
  "loaders",
21
21
  "docs",
22
22
  "src/components/",
23
+ "src/client/app_env.ts",
23
24
  "src/client/controller_contract.ts",
24
25
  "src/controller/controller_lifecycle.ts",
25
- "src/navigation/navigation_identity.ts"
26
+ "src/navigation/navigation_identity.ts",
27
+ "src/runtime/app_env.ts"
26
28
  ],
27
29
  "exports": {
28
30
  ".": {
@@ -0,0 +1,21 @@
1
+ import type { WoodAppEnv } from '../runtime/app_env.js';
2
+
3
+ export type { WoodAppEnv };
4
+
5
+ // Stored on globalThis because this module is loaded twice at runtime: once in
6
+ // wood's bundled dist (startWood) and once as raw source via the Svelte
7
+ // component exports (NavigationShell); a module-local variable would not be shared.
8
+ const CLIENT_APP_ENV_SYMBOL = Symbol.for('@noego/wood.client.app-env');
9
+
10
+ type GlobalWithAppEnv = typeof globalThis & { [CLIENT_APP_ENV_SYMBOL]?: WoodAppEnv };
11
+
12
+ export function setWoodAppEnv(value: unknown): void {
13
+ if (value === 'dev' || value === 'local' || value === 'packaged') {
14
+ (globalThis as GlobalWithAppEnv)[CLIENT_APP_ENV_SYMBOL] = value;
15
+ }
16
+ }
17
+
18
+ /** Environment tier of the running app, resolved by the main process during startWood boot. */
19
+ export function getWoodAppEnv(): WoodAppEnv {
20
+ return (globalThis as GlobalWithAppEnv)[CLIENT_APP_ENV_SYMBOL] ?? 'packaged';
21
+ }
@@ -0,0 +1,27 @@
1
+ export type WoodAppEnv = 'dev' | 'local' | 'packaged';
2
+
3
+ /**
4
+ * Resolve the runtime environment tier for the running app:
5
+ * - 'dev' — launched via `wood dev` (WOOD_MODE=development in the env)
6
+ * - 'local' — built output run directly (`electron .`), not packaged
7
+ * - 'packaged' — installed/packaged app (electron-forge etc.)
8
+ */
9
+ export async function resolveWoodAppEnv(
10
+ env: NodeJS.ProcessEnv = process.env,
11
+ ): Promise<WoodAppEnv> {
12
+ // ELECTRON_RENDERER_URL is set by electron-vite dev (same signal wood uses to
13
+ // choose loadURL vs loadFile); WOOD_MODE covers the wood CLI child env.
14
+ if (env.WOOD_MODE === 'development' || env.ELECTRON_RENDERER_URL) {
15
+ return 'dev';
16
+ }
17
+ try {
18
+ const electron = await import('electron');
19
+ const app = (electron as { app?: { isPackaged?: boolean } }).app;
20
+ if (app && app.isPackaged === false) {
21
+ return 'local';
22
+ }
23
+ } catch {
24
+ // Electron unavailable (tests/node) — treat as packaged so no ribbon shows.
25
+ }
26
+ return 'packaged';
27
+ }