@effectstream/utils 0.103.1 → 0.103.3
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 +2 -1
- package/src/runtime.ts +22 -2
- package/src/types/mod.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/utils",
|
|
3
|
-
"version": "0.103.
|
|
3
|
+
"version": "0.103.3",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./src/mod.ts",
|
|
16
|
+
"./types": "./src/types/mod.ts",
|
|
16
17
|
"./node-env": "./src/config.ts",
|
|
17
18
|
"./runtime": "./src/runtime.ts",
|
|
18
19
|
"./runtime-spawn": "./src/runtime-spawn.ts",
|
package/src/runtime.ts
CHANGED
|
@@ -39,15 +39,35 @@ export function getRuntime(): {runtime: Runtime, environment: RuntimeEnvironment
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Helpers for common process operations.
|
|
42
|
+
*
|
|
43
|
+
* These are node-only by nature, but this module is reachable from BROWSER
|
|
44
|
+
* bundles: `AddressType` is a value export of this package, so importing it
|
|
45
|
+
* (as @effectstream/wallets' IProvider does) pulls the barrel, and the barrel
|
|
46
|
+
* re-exports config.ts — which calls getEnv() at module top level. An
|
|
47
|
+
* unguarded `process` there is a hard `ReferenceError: process is not defined`
|
|
48
|
+
* at import time, before any app code runs.
|
|
49
|
+
*
|
|
50
|
+
* `getEnv` therefore degrades to `undefined` in a browser (an unset variable
|
|
51
|
+
* is the truthful answer there). The mutating/process-control helpers below
|
|
52
|
+
* still throw, because silently doing nothing would hide a real porting bug.
|
|
42
53
|
*/
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
const hasProcess = (): boolean =>
|
|
56
|
+
typeof process !== "undefined" && process != null;
|
|
57
|
+
|
|
58
|
+
/** Get environment variable. Returns undefined where there is no process. */
|
|
45
59
|
export function getEnv(key: string): string | undefined {
|
|
46
|
-
return
|
|
60
|
+
if (!hasProcess()) return undefined;
|
|
61
|
+
return process.env?.[key];
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
/** Set environment variable. */
|
|
50
65
|
export function setEnv(key: string, value: string): void {
|
|
66
|
+
if (!hasProcess()) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`setEnv(${key}) is not available in this runtime — there is no process to mutate.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
51
71
|
process.env[key] = value;
|
|
52
72
|
}
|
|
53
73
|
|
package/src/types/mod.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// Exposed as `@effectstream/utils/types` — the browser-safe subset.
|
|
2
|
+
//
|
|
3
|
+
// The ROOT barrel re-exports config.ts, which runs dotenv (.env loading from
|
|
4
|
+
// disk) at import time. Any browser bundle that imports the root for a mere
|
|
5
|
+
// type or enum (AddressType, Result, WalletAddress…) drags that bootstrap —
|
|
6
|
+
// and once crashed outright on `process`. Browser-reachable code should import
|
|
7
|
+
// this subpath instead; keep this tree free of node-only modules (node:buffer
|
|
8
|
+
// is the one allowed exception — it has a real browser polyfill).
|
|
1
9
|
export type * from "./misc.ts";
|
|
2
10
|
export type * from "./json-query.ts";
|
|
3
11
|
export type * from "./nominal.ts";
|