@gjsify/runtime 0.36.0 → 0.38.0
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/lib/esm/_virtual/_rolldown/runtime.js +1 -0
- package/lib/esm/detect.js +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/detect.d.ts +48 -0
- package/lib/types/index.d.ts +15 -16
- package/package.json +4 -4
- package/lib/types/index.spec.d.ts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e={gjs:`GJS`,node:`Node.js`,bun:`Bun`,deno:`Deno`};function detectRuntime(t){let n=detectTarget(t);return n===void 0?{target:void 0,name:`Unknown`,version:void 0}:{target:n,name:e[n],version:versionOf(t,n)}}function detectTarget(e){if(e.Bun!==void 0)return`bun`;if(e.Deno!==void 0)return`deno`;if(typeof e.process?.versions?.gjs==`string`||e.process===void 0&&e.imports?.gi!==void 0)return`gjs`;if(typeof e.process?.versions?.node==`string`)return`node`}function versionOf(e,t){switch(t){case`bun`:return e.Bun?.version;case`deno`:return e.Deno?.version?.deno;case`gjs`:return e.process?.versions?.gjs;case`node`:return e.process?.versions?.node}}export{detectRuntime};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{detectRuntime as e}from"./detect.js";const t=e(globalThis),n=t.target===`bun`,r=t.target===`deno`,i=t.target===`gjs`,a=t.target===`node`,o=t.name,s=t.target,c=t.version;export{e as detectRuntime,n as isBun,r as isDeno,i as isGJS,a as isNode,o as runtimeName,s as runtimeTarget,c as runtimeVersion};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The host globals the detection rule reads, all optional by construction. */
|
|
2
|
+
export interface RuntimeHost {
|
|
3
|
+
Bun?: {
|
|
4
|
+
version?: string;
|
|
5
|
+
};
|
|
6
|
+
Deno?: {
|
|
7
|
+
version?: {
|
|
8
|
+
deno?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
imports?: {
|
|
12
|
+
gi?: unknown;
|
|
13
|
+
};
|
|
14
|
+
process?: {
|
|
15
|
+
versions?: {
|
|
16
|
+
gjs?: string;
|
|
17
|
+
node?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The runtime as the CLI vocabulary spells it (`--runtime`, `gjsify.example.runtimes`). */
|
|
22
|
+
export type RuntimeTarget = 'gjs' | 'node' | 'bun' | 'deno';
|
|
23
|
+
/** Prose name for a user interface. `'Unknown'` where no branch matched. */
|
|
24
|
+
export type RuntimeLabel = 'GJS' | 'Node.js' | 'Bun' | 'Deno' | 'Unknown';
|
|
25
|
+
export interface RuntimeIdentity {
|
|
26
|
+
target: RuntimeTarget | undefined;
|
|
27
|
+
name: RuntimeLabel;
|
|
28
|
+
/** The version OF THIS RUNTIME, never the Node version Bun/Deno emulate. */
|
|
29
|
+
version: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Which runtime do these globals describe?
|
|
33
|
+
*
|
|
34
|
+
* PROBE ORDER IS LOAD-BEARING, and each step earns its position:
|
|
35
|
+
*
|
|
36
|
+
* 1. `Bun` / `Deno` — the only globals unique to those two. Both fake
|
|
37
|
+
* `process.versions.node` for npm compatibility, so any version-table read
|
|
38
|
+
* before this point is a false Node positive on two of the four runtimes.
|
|
39
|
+
* 2. GJS via `process.versions.gjs`, which only `@gjsify/process` sets.
|
|
40
|
+
* 3. GJS via ambient `imports.gi`, but ONLY where there is no `process` at all
|
|
41
|
+
* — a bare GJS program that never pulled the Node globals in. It must not
|
|
42
|
+
* come earlier: `@gjsify/node-gi` provides `imports.gi` ON NODE, so an
|
|
43
|
+
* unconditional read names a V8 process `'GJS'`, and callers branch on this
|
|
44
|
+
* to pick a run/exit strategy (`@gjsify/unit` would take the blocking
|
|
45
|
+
* main-loop path and never return).
|
|
46
|
+
* 4. real Node.
|
|
47
|
+
*/
|
|
48
|
+
export declare function detectRuntime(host: RuntimeHost): RuntimeIdentity;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { type RuntimeTarget } from './detect.js';
|
|
2
|
+
export type { RuntimeHost, RuntimeIdentity, RuntimeLabel, RuntimeTarget } from './detect.js';
|
|
3
|
+
export { detectRuntime } from './detect.js';
|
|
1
4
|
/** `true` when running on Bun. */
|
|
2
5
|
export declare const isBun: boolean;
|
|
3
6
|
/** `true` when running on Deno. */
|
|
4
7
|
export declare const isDeno: boolean;
|
|
5
8
|
/**
|
|
6
|
-
* `true` when running on GJS (GNOME JavaScript).
|
|
9
|
+
* `true` when running on GJS (GNOME JavaScript) — the ENGINE, not the bindings.
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* GJS program that does not pull the Node globals in has no `process` at all
|
|
11
|
-
* and used to report `'Unknown'` about itself.
|
|
11
|
+
* `@gjsify/node-gi` gives a Node process `imports.gi` and GObject introspection;
|
|
12
|
+
* that process is still V8 and reports `isNode`. See `./detect.js`.
|
|
12
13
|
*/
|
|
13
14
|
export declare const isGJS: boolean;
|
|
14
15
|
/** `true` when running on Node.js — and NOT on Bun, Deno or GJS. */
|
|
@@ -22,20 +23,18 @@ export declare const isNode: boolean;
|
|
|
22
23
|
*/
|
|
23
24
|
export declare const runtimeName: string;
|
|
24
25
|
/**
|
|
25
|
-
* The runtime as the CLI spells it —
|
|
26
|
-
*
|
|
27
|
-
* unrecognised host.
|
|
26
|
+
* The runtime as the CLI spells it — the vocabulary of `--runtime` and of
|
|
27
|
+
* `gjsify.example.runtimes`; `undefined` on an unrecognised host.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
* one
|
|
29
|
+
* Distinct from {@link runtimeName}, which is prose for a user interface: only this
|
|
30
|
+
* one is safe to pass back to the tooling.
|
|
31
31
|
*/
|
|
32
|
-
export declare const runtimeTarget:
|
|
32
|
+
export declare const runtimeTarget: RuntimeTarget | undefined;
|
|
33
33
|
/**
|
|
34
|
-
* Runtime version string,
|
|
35
|
-
* `'1.2.0'` (Bun), `'2.1.0'` (Deno). `undefined` if it cannot be determined.
|
|
34
|
+
* Runtime version string, or `undefined` if it cannot be determined.
|
|
36
35
|
*
|
|
37
|
-
* Bun and Deno are read from their own globals
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Bun and Deno are read from their own globals, not `process.versions.node`, which
|
|
37
|
+
* on both reports the Node version they emulate — a real number about a runtime you
|
|
38
|
+
* are not on.
|
|
40
39
|
*/
|
|
41
40
|
export declare const runtimeVersion: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Platform-independent runtime detection for GJS, Node.js, Bun and Deno",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"check": "gjsify tsc --noEmit",
|
|
28
28
|
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
29
29
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
30
|
-
"build:types": "gjsify tsc",
|
|
30
|
+
"build:types": "gjsify tsc -p tsconfig.build.json",
|
|
31
31
|
"build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
|
|
32
32
|
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
33
33
|
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test:cross-runtime": "gjsify run build:test:node && gjsify run test:node && gjsify run test:bun && gjsify run test:deno"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.
|
|
43
|
-
"@gjsify/unit": "^0.
|
|
42
|
+
"@gjsify/cli": "^0.38.0",
|
|
43
|
+
"@gjsify/unit": "^0.38.0",
|
|
44
44
|
"@types/node": "^25.9.2",
|
|
45
45
|
"typescript": "^6.0.3"
|
|
46
46
|
},
|