@ubean/shared 0.5.2 → 0.6.0-beta.2
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/index.d.ts +12 -0
- package/dist/index.js +16 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -399,6 +399,18 @@ export interface EnvValidationError {
|
|
|
399
399
|
export declare function defineEnv<S extends EnvSchema>(config: EnvConfig<S>): DefineEnvResult<S>;
|
|
400
400
|
export declare function setRuntimeEnv(env: Record<string, unknown>): void;
|
|
401
401
|
export declare function useRuntimeEnv<T = string>(key: string, defaultValue?: T): T;
|
|
402
|
+
/**
|
|
403
|
+
* 当前是否运行在 Node 系运行时(Node / Bun / Deno 的 node 兼容层)上。
|
|
404
|
+
*
|
|
405
|
+
* 用途:**把 Node 专用能力挡在动态 import 里**。Cloudflare Workers 这类运行时没有 `node:fs`
|
|
406
|
+
* (即使开 `nodejs_compat` 也不支持),而打包器会把「静态 import 的 node 内建」留在产物里 ——
|
|
407
|
+
* workerd 在**模块实例化**阶段就会失败(`No such module "node:fs/promises"`),根本轮不到分支
|
|
408
|
+
* 判断。因此判据必须是运行时的,且 `import()` 必须写在分支内部(动态 import 只在执行时才解析)。
|
|
409
|
+
*
|
|
410
|
+
* 判定用 `process.versions.node` 而不是 `typeof process`:bundler 常会把 `process` 替身注入浏览器
|
|
411
|
+
* 产物,只看 `process` 会在 worker/browser 里误判为真。
|
|
412
|
+
*/
|
|
413
|
+
export declare function isNodeRuntime(): boolean;
|
|
402
414
|
//#endregion
|
|
403
415
|
//#region src/path.d.ts
|
|
404
416
|
/**
|
package/dist/index.js
CHANGED
|
@@ -252,6 +252,21 @@ function setRuntimeEnv(env) {
|
|
|
252
252
|
function useRuntimeEnv(key, defaultValue) {
|
|
253
253
|
return _runtimeEnv[key] ?? defaultValue;
|
|
254
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* 当前是否运行在 Node 系运行时(Node / Bun / Deno 的 node 兼容层)上。
|
|
257
|
+
*
|
|
258
|
+
* 用途:**把 Node 专用能力挡在动态 import 里**。Cloudflare Workers 这类运行时没有 `node:fs`
|
|
259
|
+
* (即使开 `nodejs_compat` 也不支持),而打包器会把「静态 import 的 node 内建」留在产物里 ——
|
|
260
|
+
* workerd 在**模块实例化**阶段就会失败(`No such module "node:fs/promises"`),根本轮不到分支
|
|
261
|
+
* 判断。因此判据必须是运行时的,且 `import()` 必须写在分支内部(动态 import 只在执行时才解析)。
|
|
262
|
+
*
|
|
263
|
+
* 判定用 `process.versions.node` 而不是 `typeof process`:bundler 常会把 `process` 替身注入浏览器
|
|
264
|
+
* 产物,只看 `process` 会在 worker/browser 里误判为真。
|
|
265
|
+
*/
|
|
266
|
+
function isNodeRuntime() {
|
|
267
|
+
const proc = globalThis.process;
|
|
268
|
+
return typeof proc?.versions?.node === "string" || typeof proc?.versions?.bun === "string";
|
|
269
|
+
}
|
|
255
270
|
//#endregion
|
|
256
271
|
//#region src/string.ts
|
|
257
272
|
/**
|
|
@@ -336,4 +351,4 @@ function matchAnyGlob(route, patterns) {
|
|
|
336
351
|
return patterns.some((p) => matchGlob(route, p));
|
|
337
352
|
}
|
|
338
353
|
//#endregion
|
|
339
|
-
export { ACTION_BRAND, ActionError, UbeanError, capitalize, createError, defineEnv, errorToResponse, fail, getBasename, getDirname, getExtension, getStem, isActionFailure, isServerAction, isUbeanError, matchAnyGlob, matchGlob, normalizePath, pathToTitle, setRuntimeEnv, useRuntimeEnv };
|
|
354
|
+
export { ACTION_BRAND, ActionError, UbeanError, capitalize, createError, defineEnv, errorToResponse, fail, getBasename, getDirname, getExtension, getStem, isActionFailure, isNodeRuntime, isServerAction, isUbeanError, matchAnyGlob, matchGlob, normalizePath, pathToTitle, setRuntimeEnv, useRuntimeEnv };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-beta.2",
|
|
4
4
|
"description": "Shared protocol types, errors, env and universal utilities for ubean",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@standard-schema/spec": "1.1.0",
|
|
32
|
-
"hono": "4.13.
|
|
32
|
+
"hono": "4.13.8",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"scule": "^1.3.0",
|
|
35
35
|
"tslog": "^5.2.0",
|
|
36
36
|
"ufo": "1.6.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^26.
|
|
39
|
+
"@types/node": "^26.6.1",
|
|
40
40
|
"typescript": "npm:typescript-native-bridge@latest",
|
|
41
|
-
"vite-plus": "0.3.
|
|
41
|
+
"vite-plus": "0.3.3"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "vp pack",
|