@gjsify/node-globals 0.3.12 → 0.3.14
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/index.js +2 -3
- package/lib/esm/register/buffer.js +10 -6
- package/lib/esm/register/encoding.js +29 -25
- package/lib/esm/register/microtask.js +11 -7
- package/lib/esm/register/process.js +27 -19
- package/lib/esm/register/structured-clone.js +11 -7
- package/lib/esm/register/timers.js +100 -93
- package/lib/esm/register/url.js +16 -12
- package/package.json +8 -8
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Buffer } from "@gjsify/buffer";
|
|
2
2
|
import "@gjsify/buffer/register";
|
|
3
|
+
|
|
4
|
+
//#region src/register/buffer.ts
|
|
3
5
|
if (!("Buffer" in globalThis)) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Object.defineProperty(globalThis, "Buffer", {
|
|
7
|
+
value: Buffer,
|
|
8
|
+
enumerable: false,
|
|
9
|
+
writable: true,
|
|
10
|
+
configurable: true
|
|
11
|
+
});
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import GLib from "@girs/glib-2.0";
|
|
2
|
+
|
|
3
|
+
//#region src/register/encoding.ts
|
|
2
4
|
if (typeof globalThis.btoa !== "function") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
Object.defineProperty(globalThis, "btoa", {
|
|
6
|
+
value: function btoa(data) {
|
|
7
|
+
const bytes = new Uint8Array(data.length);
|
|
8
|
+
for (let i = 0; i < data.length; i++) {
|
|
9
|
+
bytes[i] = data.charCodeAt(i) & 255;
|
|
10
|
+
}
|
|
11
|
+
return GLib.base64_encode(bytes);
|
|
12
|
+
},
|
|
13
|
+
enumerable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
configurable: true
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
18
|
if (typeof globalThis.atob !== "function") {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
Object.defineProperty(globalThis, "atob", {
|
|
20
|
+
value: function atob(data) {
|
|
21
|
+
const bytes = GLib.base64_decode(data);
|
|
22
|
+
let result = "";
|
|
23
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
24
|
+
result += String.fromCharCode(bytes[i]);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
},
|
|
28
|
+
enumerable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
configurable: true
|
|
31
|
+
});
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { queueMicrotask as
|
|
1
|
+
import { queueMicrotask as queueMicrotask$1 } from "@gjsify/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/register/microtask.ts
|
|
2
4
|
if (typeof queueMicrotask !== "function") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(globalThis, "queueMicrotask", {
|
|
6
|
+
value: queueMicrotask$1,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
import { initErrorV8Methods } from "@gjsify/utils";
|
|
2
2
|
import process from "@gjsify/process";
|
|
3
|
+
|
|
4
|
+
//#region src/register/process.ts
|
|
3
5
|
if (typeof Promise.withResolvers !== "function") {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
Promise.withResolvers = function() {
|
|
7
|
+
let resolve;
|
|
8
|
+
let reject;
|
|
9
|
+
const promise = new Promise((res, rej) => {
|
|
10
|
+
resolve = res;
|
|
11
|
+
reject = rej;
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
promise,
|
|
15
|
+
resolve,
|
|
16
|
+
reject
|
|
17
|
+
};
|
|
18
|
+
};
|
|
13
19
|
}
|
|
14
20
|
initErrorV8Methods(Error);
|
|
15
21
|
if (!("global" in globalThis)) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
Object.defineProperty(globalThis, "global", {
|
|
23
|
+
value: globalThis,
|
|
24
|
+
writable: false,
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
22
28
|
}
|
|
23
29
|
Object.defineProperty(globalThis, "process", {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
value: process,
|
|
31
|
+
enumerable: false,
|
|
32
|
+
writable: true,
|
|
33
|
+
configurable: true
|
|
28
34
|
});
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { structuredClone
|
|
1
|
+
import { structuredClone } from "@gjsify/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/register/structured-clone.ts
|
|
2
4
|
if (typeof globalThis.structuredClone !== "function") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(globalThis, "structuredClone", {
|
|
6
|
+
value: structuredClone,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
@@ -1,107 +1,114 @@
|
|
|
1
|
+
//#region src/register/timers.ts
|
|
1
2
|
function getGLib() {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
const _isGjsTimer = getGLib() !== void 0;
|
|
5
|
-
class GjsifyTimeout {
|
|
6
|
-
_id = null;
|
|
7
|
-
_refed = true;
|
|
8
|
-
_callback;
|
|
9
|
-
_delay;
|
|
10
|
-
_args;
|
|
11
|
-
_repeat;
|
|
12
|
-
constructor(callback, delay, args, repeat) {
|
|
13
|
-
this._callback = callback;
|
|
14
|
-
this._delay = delay;
|
|
15
|
-
this._args = args;
|
|
16
|
-
this._repeat = repeat;
|
|
17
|
-
this._schedule();
|
|
18
|
-
}
|
|
19
|
-
_schedule() {
|
|
20
|
-
const GLib = getGLib();
|
|
21
|
-
if (!GLib) return;
|
|
22
|
-
const timeoutAdd = GLib.timeout_add.bind(GLib);
|
|
23
|
-
this._id = timeoutAdd(GLib.PRIORITY_DEFAULT, this._delay, () => {
|
|
24
|
-
try {
|
|
25
|
-
this._callback.apply(globalThis, this._args);
|
|
26
|
-
} catch (err) {
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
throw err;
|
|
29
|
-
}, 0);
|
|
30
|
-
}
|
|
31
|
-
if (this._repeat) return GLib.SOURCE_CONTINUE;
|
|
32
|
-
this._id = null;
|
|
33
|
-
return GLib.SOURCE_REMOVE;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
ref() {
|
|
37
|
-
this._refed = true;
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
unref() {
|
|
41
|
-
this._refed = false;
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
hasRef() {
|
|
45
|
-
return this._refed;
|
|
46
|
-
}
|
|
47
|
-
refresh() {
|
|
48
|
-
this._cancel();
|
|
49
|
-
this._schedule();
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
_cancel() {
|
|
53
|
-
if (this._id === null) return;
|
|
54
|
-
try {
|
|
55
|
-
getGLib()?.Source.remove(this._id);
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
this._id = null;
|
|
59
|
-
}
|
|
60
|
-
[Symbol.toPrimitive]() {
|
|
61
|
-
return this._id;
|
|
62
|
-
}
|
|
63
|
-
[Symbol.dispose]() {
|
|
64
|
-
this._cancel();
|
|
65
|
-
}
|
|
3
|
+
return globalThis.imports?.gi?.GLib;
|
|
66
4
|
}
|
|
5
|
+
const _isGjsTimer = getGLib() !== undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Node-compatible Timeout returned by our setTimeout / setInterval. Mirrors
|
|
8
|
+
* `NodeJS.Timeout`: `.ref() / .unref() / .hasRef() / .refresh()`, and
|
|
9
|
+
* `Symbol.toPrimitive` so `+timeout` yields the numeric GLib source ID (a few
|
|
10
|
+
* Node-ecosystem libraries key Maps on this coercion).
|
|
11
|
+
*/
|
|
12
|
+
var GjsifyTimeout = class {
|
|
13
|
+
_id = null;
|
|
14
|
+
_refed = true;
|
|
15
|
+
_callback;
|
|
16
|
+
_delay;
|
|
17
|
+
_args;
|
|
18
|
+
_repeat;
|
|
19
|
+
constructor(callback, delay, args, repeat) {
|
|
20
|
+
this._callback = callback;
|
|
21
|
+
this._delay = delay;
|
|
22
|
+
this._args = args;
|
|
23
|
+
this._repeat = repeat;
|
|
24
|
+
this._schedule();
|
|
25
|
+
}
|
|
26
|
+
_schedule() {
|
|
27
|
+
const GLib = getGLib();
|
|
28
|
+
if (!GLib) return;
|
|
29
|
+
const timeoutAdd = GLib.timeout_add.bind(GLib);
|
|
30
|
+
this._id = timeoutAdd(GLib.PRIORITY_DEFAULT, this._delay, () => {
|
|
31
|
+
try {
|
|
32
|
+
this._callback.apply(globalThis, this._args);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
throw err;
|
|
36
|
+
}, 0);
|
|
37
|
+
}
|
|
38
|
+
if (this._repeat) return GLib.SOURCE_CONTINUE;
|
|
39
|
+
this._id = null;
|
|
40
|
+
return GLib.SOURCE_REMOVE;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
ref() {
|
|
44
|
+
this._refed = true;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
unref() {
|
|
48
|
+
this._refed = false;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
hasRef() {
|
|
52
|
+
return this._refed;
|
|
53
|
+
}
|
|
54
|
+
refresh() {
|
|
55
|
+
this._cancel();
|
|
56
|
+
this._schedule();
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
_cancel() {
|
|
60
|
+
if (this._id === null) return;
|
|
61
|
+
try {
|
|
62
|
+
getGLib()?.Source.remove(this._id);
|
|
63
|
+
} catch {}
|
|
64
|
+
this._id = null;
|
|
65
|
+
}
|
|
66
|
+
[Symbol.toPrimitive]() {
|
|
67
|
+
return this._id;
|
|
68
|
+
}
|
|
69
|
+
[Symbol.dispose]() {
|
|
70
|
+
this._cancel();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
67
73
|
function removeById(timeout) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
74
|
+
if (timeout instanceof GjsifyTimeout) {
|
|
75
|
+
timeout._cancel();
|
|
76
|
+
} else if (typeof timeout === "number") {
|
|
77
|
+
try {
|
|
78
|
+
getGLib()?.Source.remove(timeout);
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
76
81
|
}
|
|
77
82
|
if (_isGjsTimer) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const setT = (cb, delay = 0, ...args) => new GjsifyTimeout(cb, Math.max(0, delay | 0), args, false);
|
|
84
|
+
const setI = (cb, delay = 0, ...args) => new GjsifyTimeout(cb, Math.max(0, delay | 0), args, true);
|
|
85
|
+
const g = globalThis;
|
|
86
|
+
g.setTimeout = setT;
|
|
87
|
+
g.clearTimeout = removeById;
|
|
88
|
+
g.setInterval = setI;
|
|
89
|
+
g.clearInterval = removeById;
|
|
85
90
|
}
|
|
86
91
|
function setImmediate(callback, ...args) {
|
|
87
|
-
|
|
92
|
+
return setTimeout(callback, 0, ...args);
|
|
88
93
|
}
|
|
89
94
|
function clearImmediate(id) {
|
|
90
|
-
|
|
95
|
+
clearTimeout(id);
|
|
91
96
|
}
|
|
92
97
|
if (!("setImmediate" in globalThis)) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
Object.defineProperty(globalThis, "setImmediate", {
|
|
99
|
+
value: setImmediate,
|
|
100
|
+
enumerable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
configurable: true
|
|
103
|
+
});
|
|
99
104
|
}
|
|
100
105
|
if (!("clearImmediate" in globalThis)) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
Object.defineProperty(globalThis, "clearImmediate", {
|
|
107
|
+
value: clearImmediate,
|
|
108
|
+
enumerable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
configurable: true
|
|
111
|
+
});
|
|
107
112
|
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
package/lib/esm/register/url.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { URL, URLSearchParams } from "@gjsify/url";
|
|
2
|
+
|
|
3
|
+
//#region src/register/url.ts
|
|
2
4
|
if (typeof globalThis.URL !== "function") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(globalThis, "URL", {
|
|
6
|
+
value: URL,
|
|
7
|
+
enumerable: false,
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
9
11
|
}
|
|
10
12
|
if (typeof globalThis.URLSearchParams !== "function") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
Object.defineProperty(globalThis, "URLSearchParams", {
|
|
14
|
+
value: URLSearchParams,
|
|
15
|
+
enumerable: false,
|
|
16
|
+
writable: true,
|
|
17
|
+
configurable: true
|
|
18
|
+
});
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/node-globals",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Node.js globals module for Gjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gjs",
|
|
@@ -60,15 +60,15 @@
|
|
|
60
60
|
"test:node": "node test.node.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@girs/glib-2.0": "
|
|
64
|
-
"@gjsify/buffer": "^0.3.
|
|
65
|
-
"@gjsify/process": "^0.3.
|
|
66
|
-
"@gjsify/url": "^0.3.
|
|
67
|
-
"@gjsify/utils": "^0.3.
|
|
63
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.9",
|
|
64
|
+
"@gjsify/buffer": "^0.3.14",
|
|
65
|
+
"@gjsify/process": "^0.3.14",
|
|
66
|
+
"@gjsify/url": "^0.3.14",
|
|
67
|
+
"@gjsify/utils": "^0.3.14"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@gjsify/cli": "^0.3.
|
|
71
|
-
"@gjsify/unit": "^0.3.
|
|
70
|
+
"@gjsify/cli": "^0.3.14",
|
|
71
|
+
"@gjsify/unit": "^0.3.14",
|
|
72
72
|
"@types/node": "^25.6.0",
|
|
73
73
|
"typescript": "^6.0.3"
|
|
74
74
|
}
|