@paimaexample/wallets 0.7.0 → 0.7.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/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/utils/src/mod.d.ts +1 -0
- package/esm/utils/src/mod.d.ts.map +1 -1
- package/esm/utils/src/mod.js +1 -0
- package/esm/utils/src/runtime.d.ts +32 -0
- package/esm/utils/src/runtime.d.ts.map +1 -0
- package/esm/utils/src/runtime.js +102 -0
- package/package.json +1 -1
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/utils/src/mod.d.ts +1 -0
- package/script/utils/src/mod.d.ts.map +1 -1
- package/script/utils/src/mod.js +1 -0
- package/script/utils/src/runtime.d.ts +32 -0
- package/script/utils/src/runtime.d.ts.map +1 -0
- package/script/utils/src/runtime.js +147 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const dntGlobals = {};
|
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
|
4
|
+
return new Proxy(baseObj, {
|
|
5
|
+
get(_target, prop, _receiver) {
|
|
6
|
+
if (prop in extObj) {
|
|
7
|
+
return extObj[prop];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return baseObj[prop];
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
set(_target, prop, value) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
delete extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
baseObj[prop] = value;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
deleteProperty(_target, prop) {
|
|
21
|
+
let success = false;
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
success = true;
|
|
25
|
+
}
|
|
26
|
+
if (prop in baseObj) {
|
|
27
|
+
delete baseObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
return success;
|
|
31
|
+
},
|
|
32
|
+
ownKeys(_target) {
|
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
+
const extKeysSet = new Set(extKeys);
|
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
+
},
|
|
38
|
+
defineProperty(_target, prop, desc) {
|
|
39
|
+
if (prop in extObj) {
|
|
40
|
+
delete extObj[prop];
|
|
41
|
+
}
|
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
+
if (prop in extObj) {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
has(_target, prop) {
|
|
54
|
+
return prop in extObj || prop in baseObj;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
package/esm/utils/src/mod.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/utils/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/utils/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
package/esm/utils/src/mod.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type RuntimeEnvironment = 'backend' | 'frontend' | 'unknown';
|
|
2
|
+
type Runtime = 'node' | 'deno' | 'bun' | 'browser' | 'unknown';
|
|
3
|
+
export declare function getRuntime(): {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
environment: RuntimeEnvironment;
|
|
6
|
+
};
|
|
7
|
+
/** Get environment variable. */
|
|
8
|
+
export declare function getEnv(key: string): string | undefined;
|
|
9
|
+
/** Set environment variable. */
|
|
10
|
+
export declare function setEnv(key: string, value: string): void;
|
|
11
|
+
/** CLI arguments (argv without script path). */
|
|
12
|
+
export declare function args(): string[];
|
|
13
|
+
/** Exit process with code. */
|
|
14
|
+
export declare function exit(code: number | undefined): never;
|
|
15
|
+
/** Current working directory. */
|
|
16
|
+
export declare function cwd(): string;
|
|
17
|
+
/** Terminal size when available. */
|
|
18
|
+
export declare function consoleSize(): {
|
|
19
|
+
columns: number;
|
|
20
|
+
rows: number;
|
|
21
|
+
};
|
|
22
|
+
/** Set process exit code (for graceful shutdown). */
|
|
23
|
+
export declare function setExitCode(code: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Register a test.
|
|
26
|
+
* Use: import { test } from "@paimaexample/utils/runtime";
|
|
27
|
+
*/
|
|
28
|
+
export declare function test(name: string, fn: () => void | Promise<void>): void;
|
|
29
|
+
/** Check if error is "file/dir not found". */
|
|
30
|
+
export declare function isNotFoundError(err: unknown): boolean;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/utils/src/runtime.ts"],"names":[],"mappings":"AAYA,KAAK,kBAAkB,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAC7D,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,wBAAgB,UAAU,IAAI;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,kBAAkB,CAAA;CAAC,CAkChF;AAED,gCAAgC;AAChC,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGtD;AAED,gCAAgC;AAChC,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIvD;AAED,gDAAgD;AAChD,wBAAgB,IAAI,IAAI,MAAM,EAAE,CAE/B;AAED,8BAA8B;AAC9B,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAMpD;AAED,iCAAiC;AACjC,wBAAgB,GAAG,IAAI,MAAM,CAG5B;AAED,oCAAoC;AACpC,wBAAgB,WAAW,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAK/D;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7B,IAAI,CAcN;AAED,8CAA8C;AAC9C,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOrD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
export function getRuntime() {
|
|
3
|
+
// Check for Deno
|
|
4
|
+
// @ts-ignore: Deno is added to global scope in Deno environments
|
|
5
|
+
if (typeof Deno !== 'undefined') {
|
|
6
|
+
return { runtime: 'deno', environment: 'backend' };
|
|
7
|
+
}
|
|
8
|
+
// Check for Bun
|
|
9
|
+
// @ts-ignore: Bun is added to global scope in Bun environments
|
|
10
|
+
if (typeof Bun !== 'undefined') {
|
|
11
|
+
return { runtime: 'bun', environment: 'backend' };
|
|
12
|
+
}
|
|
13
|
+
// Check for Node.js
|
|
14
|
+
// Node environments have a `process` object with versions
|
|
15
|
+
if (typeof process !== 'undefined' &&
|
|
16
|
+
process.versions &&
|
|
17
|
+
process.versions.node) {
|
|
18
|
+
return { runtime: 'node', environment: 'backend' };
|
|
19
|
+
}
|
|
20
|
+
// Check for Browser
|
|
21
|
+
// Browsers typically have `window` and `document`
|
|
22
|
+
if (typeof dntShim.dntGlobalThis !== 'undefined' &&
|
|
23
|
+
// @ts-ignore: document is added to global scope in browser environments
|
|
24
|
+
typeof document !== 'undefined') {
|
|
25
|
+
return { runtime: 'browser', environment: 'frontend' };
|
|
26
|
+
}
|
|
27
|
+
return { runtime: 'unknown', environment: 'unknown' };
|
|
28
|
+
}
|
|
29
|
+
/** Get environment variable. */
|
|
30
|
+
export function getEnv(key) {
|
|
31
|
+
if (typeof process !== "undefined" && process.env)
|
|
32
|
+
return process.env[key];
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Set environment variable. */
|
|
36
|
+
export function setEnv(key, value) {
|
|
37
|
+
if (typeof process !== "undefined" && process.env) {
|
|
38
|
+
process.env[key] = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** CLI arguments (argv without script path). */
|
|
42
|
+
export function args() {
|
|
43
|
+
return process.argv.slice(2);
|
|
44
|
+
}
|
|
45
|
+
/** Exit process with code. */
|
|
46
|
+
export function exit(code) {
|
|
47
|
+
if (code === undefined && process.exitCode !== undefined) {
|
|
48
|
+
process.exit(process.exitCode);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
process.exit(code);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Current working directory. */
|
|
55
|
+
export function cwd() {
|
|
56
|
+
if (typeof process !== "undefined" && process.cwd)
|
|
57
|
+
return process.cwd();
|
|
58
|
+
return ".";
|
|
59
|
+
}
|
|
60
|
+
/** Terminal size when available. */
|
|
61
|
+
export function consoleSize() {
|
|
62
|
+
if (typeof process !== "undefined" && process.stdout?.columns != null) {
|
|
63
|
+
return { columns: process.stdout.columns ?? 80, rows: process.stdout.rows ?? 24 };
|
|
64
|
+
}
|
|
65
|
+
return { columns: 80, rows: 24 };
|
|
66
|
+
}
|
|
67
|
+
/** Set process exit code (for graceful shutdown). */
|
|
68
|
+
export function setExitCode(code) {
|
|
69
|
+
process.exitCode = code;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Register a test.
|
|
73
|
+
* Use: import { test } from "@paimaexample/utils/runtime";
|
|
74
|
+
*/
|
|
75
|
+
export function test(name, fn) {
|
|
76
|
+
if (typeof process !== "undefined") {
|
|
77
|
+
try {
|
|
78
|
+
// dynamic import for ESM; require for CJS
|
|
79
|
+
const mod = typeof require !== "undefined"
|
|
80
|
+
? require("node:test")
|
|
81
|
+
: null;
|
|
82
|
+
if (mod?.test)
|
|
83
|
+
mod.test(name, fn);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// node:test not available
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw new Error("No test runner available");
|
|
91
|
+
}
|
|
92
|
+
/** Check if error is "file/dir not found". */
|
|
93
|
+
export function isNotFoundError(err) {
|
|
94
|
+
if (err && typeof err === "object") {
|
|
95
|
+
const e = err;
|
|
96
|
+
if (e.code === "ENOENT")
|
|
97
|
+
return true;
|
|
98
|
+
if (e.name === "NotFound" || e.constructor?.name === "NotFound")
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dntGlobalThis = void 0;
|
|
4
|
+
const dntGlobals = {};
|
|
5
|
+
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
6
|
+
function createMergeProxy(baseObj, extObj) {
|
|
7
|
+
return new Proxy(baseObj, {
|
|
8
|
+
get(_target, prop, _receiver) {
|
|
9
|
+
if (prop in extObj) {
|
|
10
|
+
return extObj[prop];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return baseObj[prop];
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
set(_target, prop, value) {
|
|
17
|
+
if (prop in extObj) {
|
|
18
|
+
delete extObj[prop];
|
|
19
|
+
}
|
|
20
|
+
baseObj[prop] = value;
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
deleteProperty(_target, prop) {
|
|
24
|
+
let success = false;
|
|
25
|
+
if (prop in extObj) {
|
|
26
|
+
delete extObj[prop];
|
|
27
|
+
success = true;
|
|
28
|
+
}
|
|
29
|
+
if (prop in baseObj) {
|
|
30
|
+
delete baseObj[prop];
|
|
31
|
+
success = true;
|
|
32
|
+
}
|
|
33
|
+
return success;
|
|
34
|
+
},
|
|
35
|
+
ownKeys(_target) {
|
|
36
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
37
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
38
|
+
const extKeysSet = new Set(extKeys);
|
|
39
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
40
|
+
},
|
|
41
|
+
defineProperty(_target, prop, desc) {
|
|
42
|
+
if (prop in extObj) {
|
|
43
|
+
delete extObj[prop];
|
|
44
|
+
}
|
|
45
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
49
|
+
if (prop in extObj) {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
has(_target, prop) {
|
|
57
|
+
return prop in extObj || prop in baseObj;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/utils/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/utils/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
package/script/utils/src/mod.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./captcha.js"), exports);
|
|
|
21
21
|
__exportStar(require("./binary-search.js"), exports);
|
|
22
22
|
__exportStar(require("./concurrency/mod.js"), exports);
|
|
23
23
|
__exportStar(require("./decorators/mod.js"), exports);
|
|
24
|
+
__exportStar(require("./runtime.js"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type RuntimeEnvironment = 'backend' | 'frontend' | 'unknown';
|
|
2
|
+
type Runtime = 'node' | 'deno' | 'bun' | 'browser' | 'unknown';
|
|
3
|
+
export declare function getRuntime(): {
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
environment: RuntimeEnvironment;
|
|
6
|
+
};
|
|
7
|
+
/** Get environment variable. */
|
|
8
|
+
export declare function getEnv(key: string): string | undefined;
|
|
9
|
+
/** Set environment variable. */
|
|
10
|
+
export declare function setEnv(key: string, value: string): void;
|
|
11
|
+
/** CLI arguments (argv without script path). */
|
|
12
|
+
export declare function args(): string[];
|
|
13
|
+
/** Exit process with code. */
|
|
14
|
+
export declare function exit(code: number | undefined): never;
|
|
15
|
+
/** Current working directory. */
|
|
16
|
+
export declare function cwd(): string;
|
|
17
|
+
/** Terminal size when available. */
|
|
18
|
+
export declare function consoleSize(): {
|
|
19
|
+
columns: number;
|
|
20
|
+
rows: number;
|
|
21
|
+
};
|
|
22
|
+
/** Set process exit code (for graceful shutdown). */
|
|
23
|
+
export declare function setExitCode(code: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Register a test.
|
|
26
|
+
* Use: import { test } from "@paimaexample/utils/runtime";
|
|
27
|
+
*/
|
|
28
|
+
export declare function test(name: string, fn: () => void | Promise<void>): void;
|
|
29
|
+
/** Check if error is "file/dir not found". */
|
|
30
|
+
export declare function isNotFoundError(err: unknown): boolean;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/utils/src/runtime.ts"],"names":[],"mappings":"AAYA,KAAK,kBAAkB,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAC7D,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,wBAAgB,UAAU,IAAI;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,kBAAkB,CAAA;CAAC,CAkChF;AAED,gCAAgC;AAChC,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGtD;AAED,gCAAgC;AAChC,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIvD;AAED,gDAAgD;AAChD,wBAAgB,IAAI,IAAI,MAAM,EAAE,CAE/B;AAED,8BAA8B;AAC9B,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAMpD;AAED,iCAAiC;AACjC,wBAAgB,GAAG,IAAI,MAAM,CAG5B;AAED,oCAAoC;AACpC,wBAAgB,WAAW,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAK/D;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7B,IAAI,CAcN;AAED,8CAA8C;AAC9C,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOrD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getRuntime = getRuntime;
|
|
37
|
+
exports.getEnv = getEnv;
|
|
38
|
+
exports.setEnv = setEnv;
|
|
39
|
+
exports.args = args;
|
|
40
|
+
exports.exit = exit;
|
|
41
|
+
exports.cwd = cwd;
|
|
42
|
+
exports.consoleSize = consoleSize;
|
|
43
|
+
exports.setExitCode = setExitCode;
|
|
44
|
+
exports.test = test;
|
|
45
|
+
exports.isNotFoundError = isNotFoundError;
|
|
46
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
47
|
+
function getRuntime() {
|
|
48
|
+
// Check for Deno
|
|
49
|
+
// @ts-ignore: Deno is added to global scope in Deno environments
|
|
50
|
+
if (typeof Deno !== 'undefined') {
|
|
51
|
+
return { runtime: 'deno', environment: 'backend' };
|
|
52
|
+
}
|
|
53
|
+
// Check for Bun
|
|
54
|
+
// @ts-ignore: Bun is added to global scope in Bun environments
|
|
55
|
+
if (typeof Bun !== 'undefined') {
|
|
56
|
+
return { runtime: 'bun', environment: 'backend' };
|
|
57
|
+
}
|
|
58
|
+
// Check for Node.js
|
|
59
|
+
// Node environments have a `process` object with versions
|
|
60
|
+
if (typeof process !== 'undefined' &&
|
|
61
|
+
process.versions &&
|
|
62
|
+
process.versions.node) {
|
|
63
|
+
return { runtime: 'node', environment: 'backend' };
|
|
64
|
+
}
|
|
65
|
+
// Check for Browser
|
|
66
|
+
// Browsers typically have `window` and `document`
|
|
67
|
+
if (typeof dntShim.dntGlobalThis !== 'undefined' &&
|
|
68
|
+
// @ts-ignore: document is added to global scope in browser environments
|
|
69
|
+
typeof document !== 'undefined') {
|
|
70
|
+
return { runtime: 'browser', environment: 'frontend' };
|
|
71
|
+
}
|
|
72
|
+
return { runtime: 'unknown', environment: 'unknown' };
|
|
73
|
+
}
|
|
74
|
+
/** Get environment variable. */
|
|
75
|
+
function getEnv(key) {
|
|
76
|
+
if (typeof process !== "undefined" && process.env)
|
|
77
|
+
return process.env[key];
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
/** Set environment variable. */
|
|
81
|
+
function setEnv(key, value) {
|
|
82
|
+
if (typeof process !== "undefined" && process.env) {
|
|
83
|
+
process.env[key] = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** CLI arguments (argv without script path). */
|
|
87
|
+
function args() {
|
|
88
|
+
return process.argv.slice(2);
|
|
89
|
+
}
|
|
90
|
+
/** Exit process with code. */
|
|
91
|
+
function exit(code) {
|
|
92
|
+
if (code === undefined && process.exitCode !== undefined) {
|
|
93
|
+
process.exit(process.exitCode);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
process.exit(code);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Current working directory. */
|
|
100
|
+
function cwd() {
|
|
101
|
+
if (typeof process !== "undefined" && process.cwd)
|
|
102
|
+
return process.cwd();
|
|
103
|
+
return ".";
|
|
104
|
+
}
|
|
105
|
+
/** Terminal size when available. */
|
|
106
|
+
function consoleSize() {
|
|
107
|
+
if (typeof process !== "undefined" && process.stdout?.columns != null) {
|
|
108
|
+
return { columns: process.stdout.columns ?? 80, rows: process.stdout.rows ?? 24 };
|
|
109
|
+
}
|
|
110
|
+
return { columns: 80, rows: 24 };
|
|
111
|
+
}
|
|
112
|
+
/** Set process exit code (for graceful shutdown). */
|
|
113
|
+
function setExitCode(code) {
|
|
114
|
+
process.exitCode = code;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Register a test.
|
|
118
|
+
* Use: import { test } from "@paimaexample/utils/runtime";
|
|
119
|
+
*/
|
|
120
|
+
function test(name, fn) {
|
|
121
|
+
if (typeof process !== "undefined") {
|
|
122
|
+
try {
|
|
123
|
+
// dynamic import for ESM; require for CJS
|
|
124
|
+
const mod = typeof require !== "undefined"
|
|
125
|
+
? require("node:test")
|
|
126
|
+
: null;
|
|
127
|
+
if (mod?.test)
|
|
128
|
+
mod.test(name, fn);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// node:test not available
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
throw new Error("No test runner available");
|
|
136
|
+
}
|
|
137
|
+
/** Check if error is "file/dir not found". */
|
|
138
|
+
function isNotFoundError(err) {
|
|
139
|
+
if (err && typeof err === "object") {
|
|
140
|
+
const e = err;
|
|
141
|
+
if (e.code === "ENOENT")
|
|
142
|
+
return true;
|
|
143
|
+
if (e.name === "NotFound" || e.constructor?.name === "NotFound")
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|