@gjsify/node-globals 0.52.0 → 0.54.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @gjsify/node-globals
2
2
 
3
- Node.js globals for GJS: `process`, `Buffer`, `structuredClone`, `btoa`/`atob`, `URL`, `URLSearchParams`, `setImmediate`/`clearImmediate`, `queueMicrotask`, `global`, and the `Error.captureStackTrace` / `Promise.withResolvers` V8 polyfills.
3
+ Node.js globals for GJS: `process`, `Buffer`, `structuredClone`, `btoa`/`atob`, `URL`, `URLSearchParams`, `setImmediate`/`clearImmediate`, `queueMicrotask`, `navigator`, `global`, and the `Error.captureStackTrace` / `Promise.withResolvers` V8 polyfills.
4
4
 
5
5
  Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
6
6
 
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{ensureMainLoop as e}from"@gjsify/utils/core";export{e as ensureMainLoop};
1
+ import{Navigator as e,getNavigatorPlatform as t,navigator as n}from"./navigator.js";import{ensureMainLoop as r}from"@gjsify/utils/core";export{e as Navigator,r as ensureMainLoop,t as getNavigatorPlatform,n as navigator};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import t from"@gjsify/process";const n=Symbol(`kInitialize`);function getNavigatorPlatform(e,t){return t===`darwin`?`MacIntel`:t===`win32`?`Win32`:t===`linux`?e===`ia32`?`Linux i686`:e===`x64`?`Linux x86_64`:`Linux ${e}`:t===`freebsd`?e===`ia32`?`FreeBSD i386`:e===`x64`?`FreeBSD amd64`:`FreeBSD ${e}`:t===`openbsd`?e===`ia32`?`OpenBSD i386`:e===`x64`?`OpenBSD amd64`:`OpenBSD ${e}`:t===`sunos`?e===`ia32`?`SunOS i86pc`:`SunOS ${e}`:t===`aix`?`AIX`:`${t[0].toUpperCase()}${t.slice(1)} ${e}`}function gjsUserAgent(){let e=t.versions.gjs;if(!e)return`GJS`;let[n,r]=e.split(`.`);return`GJS/${n}.${r}`}function illegalConstructor(){let e=TypeError(`Illegal constructor`);return e.code=`ERR_ILLEGAL_CONSTRUCTOR`,e}var Navigator=class{#e;#t;#n;#r;constructor(e){if(e!==n)throw illegalConstructor()}get hardwareConcurrency(){return this.#e??=e.get_num_processors(),this.#e}get language(){return this.#r,new Intl.DateTimeFormat().resolvedOptions().locale||`en-US`}get languages(){return this.#r??=Object.freeze([this.language]),this.#r}get userAgent(){return this.#t??=gjsUserAgent(),this.#t}get platform(){return this.#n??=getNavigatorPlatform(t.arch,t.platform),this.#n}};for(let e of[`hardwareConcurrency`,`language`,`languages`,`userAgent`,`platform`])Object.defineProperty(Navigator.prototype,e,{enumerable:!0});const r=new Navigator(n);export{Navigator,getNavigatorPlatform,r as navigator};
@@ -0,0 +1 @@
1
+ import{Navigator as e,navigator as t}from"../navigator.js";globalThis.navigator===void 0&&Object.defineProperty(globalThis,"navigator",{value:t,enumerable:!0,writable:!0,configurable:!0}),globalThis.Navigator===void 0&&Object.defineProperty(globalThis,"Navigator",{value:e,enumerable:!1,writable:!0,configurable:!0});
@@ -1 +1 @@
1
- import"../_virtual/_rolldown/runtime.js";function getGLib(){return globalThis.imports?.gi?.GLib}const e=getGLib()!==void 0;var GjsifyTimeout=class{_id=null;_refed=!0;_callback;_delay;_args;_repeat;constructor(e,t,n,r){this._callback=e,this._delay=t,this._args=n,this._repeat=r,this._schedule()}_schedule(){let e=getGLib();if(!e)return;let t=e.timeout_add.bind(e);this._id=t(e.PRIORITY_DEFAULT,this._delay,()=>{try{this._callback.apply(globalThis,this._args)}catch(e){setTimeout(()=>{throw e},0)}return this._repeat?e.SOURCE_CONTINUE:(this._id=null,e.SOURCE_REMOVE)})}ref(){return this._refed=!0,this}unref(){return this._refed=!1,this}hasRef(){return this._refed}refresh(){return this._cancel(),this._schedule(),this}_cancel(){this._id!==null&&(getGLib()?.Source.remove(this._id),this._id=null)}[Symbol.toPrimitive](){return this._id}[Symbol.dispose](){this._cancel()}};function removeById(e){e instanceof GjsifyTimeout?e._cancel():typeof e==`number`&&getGLib()?.Source.remove(e)}if(e){let setT=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!1),setI=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!0),e=globalThis;e.setTimeout=setT,e.clearTimeout=removeById,e.setInterval=setI,e.clearInterval=removeById}function setImmediate(e,...t){return setTimeout(e,0,...t)}function clearImmediate(e){clearTimeout(e)}`setImmediate`in globalThis||Object.defineProperty(globalThis,"setImmediate",{value:setImmediate,enumerable:!0,writable:!0,configurable:!0}),`clearImmediate`in globalThis||Object.defineProperty(globalThis,"clearImmediate",{value:clearImmediate,enumerable:!0,writable:!0,configurable:!0});
1
+ import"../_virtual/_rolldown/runtime.js";function getGLib(){return globalThis.imports?.gi?.GLib}const e=getGLib()!==void 0;function reportTimerThrow(e,t){try{e.log_default_handler(`gjsify-timers`,e.LogLevelFlags.LEVEL_WARNING,`Uncaught exception in a timer callback: ${String(t)}\n${t?.stack??``}`,null)}catch{}}var GjsifyTimeout=class{_id=null;_refed=!0;_callback;_delay;_args;_repeat;constructor(e,t,n,r){this._callback=e,this._delay=t,this._args=n,this._repeat=r,this._schedule()}_schedule(){let e=getGLib();if(!e)return;let t=e.timeout_add.bind(e);this._id=t(e.PRIORITY_DEFAULT,this._delay,()=>{try{this._callback.apply(globalThis,this._args)}catch(t){reportTimerThrow(e,t)}return this._repeat?e.SOURCE_CONTINUE:(this._id=null,e.SOURCE_REMOVE)})}unref(){return this._refed=!1,this}ref(){return this._refed=!0,this}hasRef(){return this._refed}refresh(){return this._cancel(),this._schedule(),this}_cancel(){this._id!==null&&(getGLib()?.Source.remove(this._id),this._id=null)}close(){return this._cancel(),this}[Symbol.toPrimitive](){return this._id}[Symbol.dispose](){this._cancel()}};function removeById(e){e instanceof GjsifyTimeout||typeof e==`object`&&e&&`_cancel`in e?e._cancel():typeof e==`object`&&e&&typeof e.close==`function`?e.close():typeof e==`number`&&getGLib()?.Source.remove(e)}if(e){let setT=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!1),setI=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!0),e=globalThis;e.setTimeout=setT,e.clearTimeout=removeById,e.setInterval=setI,e.clearInterval=removeById}function setImmediate(e,...t){return setTimeout(e,0,...t)}function clearImmediate(e){clearTimeout(e)}`setImmediate`in globalThis||Object.defineProperty(globalThis,"setImmediate",{value:setImmediate,enumerable:!0,writable:!0,configurable:!0}),`clearImmediate`in globalThis||Object.defineProperty(globalThis,"clearImmediate",{value:clearImmediate,enumerable:!0,writable:!0,configurable:!0});
@@ -1 +1 @@
1
- import"./register/process.js";import"./register/buffer.js";import"./register/timers.js";import"./register/encoding.js";import"./register/url.js";import"./register/structured-clone.js";import"./register/microtask.js";
1
+ import"./register/process.js";import"./register/buffer.js";import"./register/timers.js";import"./register/encoding.js";import"./register/url.js";import"./register/structured-clone.js";import"./register/microtask.js";import"./register/navigator.js";
@@ -1 +1,2 @@
1
1
  export { ensureMainLoop } from '@gjsify/utils/core';
2
+ export { Navigator, navigator, getNavigatorPlatform } from './navigator.js';
@@ -0,0 +1,14 @@
1
+ /** `navigator.platform` as browsers spell it, from Node's `process.platform`/`process.arch`. */
2
+ export declare function getNavigatorPlatform(arch: string, platform: string): string;
3
+ export declare class Navigator {
4
+ #private;
5
+ constructor(key?: symbol);
6
+ /** Processors this process may run on — GLib reads the CPU affinity mask, as libuv does. */
7
+ get hardwareConcurrency(): number;
8
+ /** The engine's default locale, which SpiderMonkey and Node's ICU both derive from `LANG`. */
9
+ get language(): string;
10
+ get languages(): readonly string[];
11
+ get userAgent(): string;
12
+ get platform(): string;
13
+ }
14
+ export declare const navigator: Navigator;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,3 +5,4 @@ import './register/encoding.js';
5
5
  import './register/url.js';
6
6
  import './register/structured-clone.js';
7
7
  import './register/microtask.js';
8
+ import './register/navigator.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/node-globals",
3
- "version": "0.52.0",
3
+ "version": "0.54.0",
4
4
  "description": "Node.js globals module for Gjs",
5
5
  "keywords": [
6
6
  "gjs",
@@ -43,6 +43,10 @@
43
43
  },
44
44
  "./register/microtask": {
45
45
  "default": "./lib/esm/register/microtask.js"
46
+ },
47
+ "./register/navigator": {
48
+ "types": "./lib/types/register/navigator.d.ts",
49
+ "default": "./lib/esm/register/navigator.js"
46
50
  }
47
51
  },
48
52
  "sideEffects": [
@@ -64,14 +68,14 @@
64
68
  },
65
69
  "dependencies": {
66
70
  "@girs/glib-2.0": "5.4.0",
67
- "@gjsify/buffer": "^0.52.0",
68
- "@gjsify/process": "^0.52.0",
69
- "@gjsify/url": "^0.52.0",
70
- "@gjsify/utils": "^0.52.0"
71
+ "@gjsify/buffer": "^0.54.0",
72
+ "@gjsify/process": "^0.54.0",
73
+ "@gjsify/url": "^0.54.0",
74
+ "@gjsify/utils": "^0.54.0"
71
75
  },
72
76
  "devDependencies": {
73
- "@gjsify/cli": "^0.52.0",
74
- "@gjsify/unit": "^0.52.0",
77
+ "@gjsify/cli": "^0.54.0",
78
+ "@gjsify/unit": "^0.54.0",
75
79
  "@types/node": "^25.9.2",
76
80
  "typescript": "^6.0.3"
77
81
  },
@@ -82,7 +86,12 @@
82
86
  "browser": "none",
83
87
  "nativescript": "none"
84
88
  },
85
- "tier": 1
89
+ "tier": 1,
90
+ "os": {
91
+ "linux": "supported",
92
+ "darwin": "supported",
93
+ "win32": "supported"
94
+ }
86
95
  },
87
96
  "license": "MIT",
88
97
  "repository": {