@gjsify/node-globals 0.0.4 → 0.1.1
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 +25 -1
- package/lib/esm/index.js +147 -3
- package/lib/types/index.d.ts +3 -0
- package/package.json +20 -20
- package/src/index.spec.ts +763 -6
- package/src/index.ts +173 -3
- package/src/test.mts +1 -1
- package/tsconfig.json +23 -11
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/errors.js +0 -2
- package/lib/cjs/index.js +0 -3
- package/lib/esm/errors.js +0 -2
- package/src/errors.ts +0 -3
- package/test.gjs.mjs +0 -34685
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.mjs +0 -307
- package/tsconfig.types.json +0 -8
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
# @gjsify/node-globals
|
|
2
2
|
|
|
3
|
-
Node.js
|
|
3
|
+
GJS implementation of Node.js global objects including process, Buffer, structuredClone, TextEncoder/Decoder, atob/btoa, URL, and setImmediate.
|
|
4
|
+
|
|
5
|
+
Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gjsify/node-globals
|
|
11
|
+
# or
|
|
12
|
+
yarn add @gjsify/node-globals
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import '@gjsify/node-globals';
|
|
19
|
+
|
|
20
|
+
// Global objects are now available:
|
|
21
|
+
// process, Buffer, structuredClone, TextEncoder, TextDecoder,
|
|
22
|
+
// atob, btoa, URL, setImmediate
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT
|
package/lib/esm/index.js
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "@gjsify/
|
|
3
|
-
import "@gjsify/
|
|
1
|
+
import { initErrorV8Methods, structuredClone as structuredClonePolyfill } from "@gjsify/utils";
|
|
2
|
+
import process from "@gjsify/process";
|
|
3
|
+
import { Buffer } from "@gjsify/buffer";
|
|
4
|
+
import { URL, URLSearchParams } from "@gjsify/url";
|
|
5
|
+
import "@gjsify/abort-controller";
|
|
6
|
+
import "@gjsify/fetch";
|
|
7
|
+
import GLib from "@girs/glib-2.0";
|
|
8
|
+
if (typeof Promise.withResolvers !== "function") {
|
|
9
|
+
Promise.withResolvers = function() {
|
|
10
|
+
let resolve;
|
|
11
|
+
let reject;
|
|
12
|
+
const promise = new Promise((res, rej) => {
|
|
13
|
+
resolve = res;
|
|
14
|
+
reject = rej;
|
|
15
|
+
});
|
|
16
|
+
return { promise, resolve, reject };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (typeof queueMicrotask !== "function") {
|
|
20
|
+
Object.defineProperty(globalThis, "queueMicrotask", {
|
|
21
|
+
value: function queueMicrotask2(callback) {
|
|
22
|
+
Promise.resolve().then(callback).catch((err) => {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
throw err;
|
|
25
|
+
}, 0);
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
enumerable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
configurable: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
initErrorV8Methods(Error);
|
|
34
|
+
if (!("global" in globalThis)) {
|
|
35
|
+
Object.defineProperty(globalThis, "global", {
|
|
36
|
+
value: globalThis,
|
|
37
|
+
writable: false,
|
|
38
|
+
enumerable: false,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!("process" in globalThis)) {
|
|
43
|
+
Object.defineProperty(globalThis, "process", {
|
|
44
|
+
value: process,
|
|
45
|
+
enumerable: false,
|
|
46
|
+
writable: true,
|
|
47
|
+
configurable: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (!("Buffer" in globalThis)) {
|
|
51
|
+
Object.defineProperty(globalThis, "Buffer", {
|
|
52
|
+
value: Buffer,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
writable: true,
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function setImmediate(callback, ...args) {
|
|
59
|
+
return setTimeout(callback, 0, ...args);
|
|
60
|
+
}
|
|
61
|
+
function clearImmediate(id) {
|
|
62
|
+
clearTimeout(id);
|
|
63
|
+
}
|
|
64
|
+
if (!("setImmediate" in globalThis)) {
|
|
65
|
+
Object.defineProperty(globalThis, "setImmediate", {
|
|
66
|
+
value: setImmediate,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (!("clearImmediate" in globalThis)) {
|
|
73
|
+
Object.defineProperty(globalThis, "clearImmediate", {
|
|
74
|
+
value: clearImmediate,
|
|
75
|
+
enumerable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
configurable: true
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (typeof globalThis.btoa !== "function") {
|
|
81
|
+
Object.defineProperty(globalThis, "btoa", {
|
|
82
|
+
value: function btoa(data) {
|
|
83
|
+
const bytes = new Uint8Array(data.length);
|
|
84
|
+
for (let i = 0; i < data.length; i++) {
|
|
85
|
+
bytes[i] = data.charCodeAt(i) & 255;
|
|
86
|
+
}
|
|
87
|
+
return GLib.base64_encode(bytes);
|
|
88
|
+
},
|
|
89
|
+
enumerable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
configurable: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (typeof globalThis.atob !== "function") {
|
|
95
|
+
Object.defineProperty(globalThis, "atob", {
|
|
96
|
+
value: function atob(data) {
|
|
97
|
+
const bytes = GLib.base64_decode(data);
|
|
98
|
+
let result = "";
|
|
99
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
100
|
+
result += String.fromCharCode(bytes[i]);
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
},
|
|
104
|
+
enumerable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
configurable: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (typeof globalThis.structuredClone !== "function") {
|
|
110
|
+
Object.defineProperty(globalThis, "structuredClone", {
|
|
111
|
+
value: structuredClonePolyfill,
|
|
112
|
+
enumerable: true,
|
|
113
|
+
writable: true,
|
|
114
|
+
configurable: true
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (typeof globalThis.URL !== "function") {
|
|
118
|
+
Object.defineProperty(globalThis, "URL", {
|
|
119
|
+
value: URL,
|
|
120
|
+
enumerable: false,
|
|
121
|
+
writable: true,
|
|
122
|
+
configurable: true
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (typeof globalThis.URLSearchParams !== "function") {
|
|
126
|
+
Object.defineProperty(globalThis, "URLSearchParams", {
|
|
127
|
+
value: URLSearchParams,
|
|
128
|
+
enumerable: false,
|
|
129
|
+
writable: true,
|
|
130
|
+
configurable: true
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
for (const name of ["ReadableStream", "Blob"]) {
|
|
134
|
+
if (typeof globalThis[name] === "undefined") {
|
|
135
|
+
Object.defineProperty(globalThis, name, {
|
|
136
|
+
value: class {
|
|
137
|
+
},
|
|
138
|
+
enumerable: false,
|
|
139
|
+
writable: true,
|
|
140
|
+
configurable: true
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
import { ensureMainLoop } from "@gjsify/utils";
|
|
145
|
+
export {
|
|
146
|
+
ensureMainLoop
|
|
147
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/node-globals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Node.js globals module for Gjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gjs",
|
|
@@ -8,41 +8,41 @@
|
|
|
8
8
|
"globals"
|
|
9
9
|
],
|
|
10
10
|
"author": "Pascal Garber",
|
|
11
|
-
"main": "lib/cjs/index.js",
|
|
12
11
|
"module": "lib/esm/index.js",
|
|
12
|
+
"types": "lib/types/index.d.ts",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"default": "./lib/esm/index.js"
|
|
19
|
-
},
|
|
20
|
-
"require": {
|
|
21
|
-
"types": "./lib/types/index.d.ts",
|
|
22
|
-
"default": "./lib/cjs/index.js"
|
|
23
|
-
}
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"default": "./lib/esm/index.js"
|
|
24
18
|
}
|
|
25
19
|
},
|
|
26
20
|
"scripts": {
|
|
27
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo test.
|
|
28
|
-
"
|
|
29
|
-
"build": "yarn
|
|
21
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
22
|
+
"check": "tsc --noEmit",
|
|
23
|
+
"build": "yarn build:gjsify && yarn build:types",
|
|
30
24
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
31
|
-
"build:types": "tsc
|
|
25
|
+
"build:types": "tsc",
|
|
32
26
|
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
33
27
|
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
34
28
|
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
35
|
-
"test": "yarn
|
|
29
|
+
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
36
30
|
"test:gjs": "gjs -m test.gjs.mjs",
|
|
37
31
|
"test:node": "node test.node.mjs"
|
|
38
32
|
},
|
|
39
33
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@gjsify/
|
|
42
|
-
"@gjsify/
|
|
34
|
+
"@girs/glib-2.0": "^2.88.0-4.0.0-beta.43",
|
|
35
|
+
"@gjsify/abort-controller": "^0.1.1",
|
|
36
|
+
"@gjsify/buffer": "^0.1.1",
|
|
37
|
+
"@gjsify/fetch": "^0.1.1",
|
|
38
|
+
"@gjsify/process": "^0.1.1",
|
|
39
|
+
"@gjsify/url": "^0.1.1",
|
|
40
|
+
"@gjsify/utils": "^0.1.1"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
|
-
"@gjsify/cli": "^0.
|
|
46
|
-
"@gjsify/unit": "^0.
|
|
43
|
+
"@gjsify/cli": "^0.1.1",
|
|
44
|
+
"@gjsify/unit": "^0.1.1",
|
|
45
|
+
"@types/node": "^25.5.0",
|
|
46
|
+
"typescript": "^6.0.2"
|
|
47
47
|
}
|
|
48
48
|
}
|