@gjsify/process 0.4.0 → 0.4.4
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/package.json +44 -41
- package/src/extended.spec.ts +0 -214
- package/src/index.spec.ts +0 -454
- package/src/index.ts +0 -790
- package/src/test.mts +0 -5
- package/tsconfig.json +0 -31
- package/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "@gjsify/process",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"description": "Node.js process module for Gjs",
|
|
5
|
+
"module": "lib/esm/index.js",
|
|
6
|
+
"types": "lib/types/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
19
|
+
"check": "tsc --noEmit",
|
|
20
|
+
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
21
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
22
|
+
"build:types": "tsc",
|
|
23
|
+
"build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
|
|
24
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
25
|
+
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
26
|
+
"test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
|
|
27
|
+
"test:gjs": "gjsify run test.gjs.mjs",
|
|
28
|
+
"test:node": "node test.node.mjs"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"gjs",
|
|
32
|
+
"node",
|
|
33
|
+
"process"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@gjsify/events": "^0.4.4",
|
|
37
|
+
"@gjsify/terminal-native": "^0.4.4",
|
|
38
|
+
"@gjsify/utils": "^0.4.4"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@gjsify/cli": "^0.4.4",
|
|
42
|
+
"@gjsify/unit": "^0.4.4",
|
|
43
|
+
"@types/node": "^25.6.2",
|
|
44
|
+
"typescript": "^6.0.3"
|
|
12
45
|
}
|
|
13
|
-
|
|
14
|
-
"scripts": {
|
|
15
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
16
|
-
"check": "tsc --noEmit",
|
|
17
|
-
"build": "yarn build:gjsify && yarn build:types",
|
|
18
|
-
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
19
|
-
"build:types": "tsc",
|
|
20
|
-
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
21
|
-
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
22
|
-
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
23
|
-
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
24
|
-
"test:gjs": "gjsify run test.gjs.mjs",
|
|
25
|
-
"test:node": "node test.node.mjs"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"gjs",
|
|
29
|
-
"node",
|
|
30
|
-
"process"
|
|
31
|
-
],
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@gjsify/events": "^0.4.0",
|
|
34
|
-
"@gjsify/terminal-native": "^0.4.0",
|
|
35
|
-
"@gjsify/utils": "^0.4.0"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@gjsify/cli": "^0.4.0",
|
|
39
|
-
"@gjsify/unit": "^0.4.0",
|
|
40
|
-
"@types/node": "^25.6.2",
|
|
41
|
-
"typescript": "^6.0.3"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
46
|
+
}
|
package/src/extended.spec.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
// Ported from refs/node-test/parallel/test-process-*.js
|
|
2
|
-
// Original: MIT license, Node.js contributors
|
|
3
|
-
|
|
4
|
-
import { describe, it, expect } from '@gjsify/unit';
|
|
5
|
-
import process from 'node:process';
|
|
6
|
-
|
|
7
|
-
export default async () => {
|
|
8
|
-
|
|
9
|
-
// ===================== Signal handling =====================
|
|
10
|
-
await describe('process signal handling', async () => {
|
|
11
|
-
await it('should support registering SIGTERM handler', async () => {
|
|
12
|
-
let handlerCalled = false;
|
|
13
|
-
const handler = () => { handlerCalled = true; };
|
|
14
|
-
process.on('SIGTERM', handler);
|
|
15
|
-
expect(process.listenerCount('SIGTERM')).toBeGreaterThan(0);
|
|
16
|
-
process.removeListener('SIGTERM', handler);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
await it('should support registering SIGINT handler', async () => {
|
|
20
|
-
const handler = () => {};
|
|
21
|
-
process.on('SIGINT', handler);
|
|
22
|
-
expect(process.listenerCount('SIGINT')).toBeGreaterThan(0);
|
|
23
|
-
process.removeListener('SIGINT', handler);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// ===================== process.stdout/stderr =====================
|
|
28
|
-
await describe('process.stdout and process.stderr', async () => {
|
|
29
|
-
await it('process.stdout should exist', async () => {
|
|
30
|
-
expect(process.stdout).toBeDefined();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await it('process.stderr should exist', async () => {
|
|
34
|
-
expect(process.stderr).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
await it('process.stdout should have write method', async () => {
|
|
38
|
-
expect(typeof process.stdout.write).toBe('function');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await it('process.stderr should have write method', async () => {
|
|
42
|
-
expect(typeof process.stderr.write).toBe('function');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// ===================== process.stdin =====================
|
|
47
|
-
await describe('process.stdin', async () => {
|
|
48
|
-
await it('should exist', async () => {
|
|
49
|
-
expect(process.stdin).toBeDefined();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// ===================== process.nextTick ordering =====================
|
|
54
|
-
await describe('process.nextTick ordering', async () => {
|
|
55
|
-
await it('should execute callbacks in FIFO order', async () => {
|
|
56
|
-
const order: number[] = [];
|
|
57
|
-
await new Promise<void>((resolve) => {
|
|
58
|
-
process.nextTick(() => { order.push(1); });
|
|
59
|
-
process.nextTick(() => { order.push(2); });
|
|
60
|
-
process.nextTick(() => {
|
|
61
|
-
order.push(3);
|
|
62
|
-
resolve();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
expect(order[0]).toBe(1);
|
|
66
|
-
expect(order[1]).toBe(2);
|
|
67
|
-
expect(order[2]).toBe(3);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
await it('should pass arguments to callback', async () => {
|
|
71
|
-
const result = await new Promise<string>((resolve) => {
|
|
72
|
-
process.nextTick((a: string, b: string) => {
|
|
73
|
-
resolve(a + b);
|
|
74
|
-
}, 'hello', ' world');
|
|
75
|
-
});
|
|
76
|
-
expect(result).toBe('hello world');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// ===================== process.env deep =====================
|
|
81
|
-
await describe('process.env deep', async () => {
|
|
82
|
-
await it('should support setting and deleting env vars', async () => {
|
|
83
|
-
process.env.TEST_GJSIFY_VAR = 'test_value';
|
|
84
|
-
expect(process.env.TEST_GJSIFY_VAR).toBe('test_value');
|
|
85
|
-
delete process.env.TEST_GJSIFY_VAR;
|
|
86
|
-
expect(process.env.TEST_GJSIFY_VAR).toBeUndefined();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
await it('should coerce non-string values to strings', async () => {
|
|
90
|
-
(process.env as any).TEST_NUM = 42;
|
|
91
|
-
expect(typeof process.env.TEST_NUM).toBe('string');
|
|
92
|
-
expect(process.env.TEST_NUM).toBe('42');
|
|
93
|
-
delete process.env.TEST_NUM;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
await it('should enumerate env vars with Object.keys', async () => {
|
|
97
|
-
const keys = Object.keys(process.env);
|
|
98
|
-
expect(keys.length).toBeGreaterThan(0);
|
|
99
|
-
// PATH or HOME should be present
|
|
100
|
-
const hasCommon = keys.includes('PATH') || keys.includes('HOME') || keys.includes('USER');
|
|
101
|
-
expect(hasCommon).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// ===================== process.hrtime =====================
|
|
106
|
-
await describe('process.hrtime deep', async () => {
|
|
107
|
-
await it('hrtime should return [seconds, nanoseconds]', async () => {
|
|
108
|
-
const hr = process.hrtime();
|
|
109
|
-
expect(Array.isArray(hr)).toBe(true);
|
|
110
|
-
expect(hr.length).toBe(2);
|
|
111
|
-
expect(typeof hr[0]).toBe('number');
|
|
112
|
-
expect(typeof hr[1]).toBe('number');
|
|
113
|
-
expect(hr[0]).toBeGreaterThan(-1);
|
|
114
|
-
expect(hr[1]).toBeGreaterThan(-1);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
await it('hrtime diff should measure elapsed time', async () => {
|
|
118
|
-
const start = process.hrtime();
|
|
119
|
-
// Small busy wait
|
|
120
|
-
let sum = 0;
|
|
121
|
-
for (let i = 0; i < 100000; i++) sum += i;
|
|
122
|
-
const diff = process.hrtime(start);
|
|
123
|
-
expect(diff[0]).toBeGreaterThan(-1);
|
|
124
|
-
// Total nanoseconds should be positive
|
|
125
|
-
const totalNs = diff[0] * 1e9 + diff[1];
|
|
126
|
-
expect(totalNs).toBeGreaterThan(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
await it('hrtime.bigint should return bigint', async () => {
|
|
130
|
-
const t = process.hrtime.bigint();
|
|
131
|
-
expect(typeof t).toBe('bigint');
|
|
132
|
-
expect(t > 0n).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
await it('hrtime.bigint should be monotonic', async () => {
|
|
136
|
-
const a = process.hrtime.bigint();
|
|
137
|
-
const b = process.hrtime.bigint();
|
|
138
|
-
expect(b >= a).toBe(true);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// ===================== process.memoryUsage =====================
|
|
143
|
-
await describe('process.memoryUsage deep', async () => {
|
|
144
|
-
await it('should return object with expected fields', async () => {
|
|
145
|
-
const mem = process.memoryUsage();
|
|
146
|
-
expect(typeof mem).toBe('object');
|
|
147
|
-
expect(typeof mem.rss).toBe('number');
|
|
148
|
-
expect(typeof mem.heapTotal).toBe('number');
|
|
149
|
-
expect(typeof mem.heapUsed).toBe('number');
|
|
150
|
-
expect(typeof mem.external).toBe('number');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
await it('rss should be positive', async () => {
|
|
154
|
-
const mem = process.memoryUsage();
|
|
155
|
-
expect(mem.rss).toBeGreaterThan(0);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
await it('heapUsed should be less than or equal to heapTotal', async () => {
|
|
159
|
-
const mem = process.memoryUsage();
|
|
160
|
-
expect(mem.heapUsed <= mem.heapTotal).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// ===================== process.cpuUsage =====================
|
|
165
|
-
await describe('process.cpuUsage deep', async () => {
|
|
166
|
-
await it('should return user and system times', async () => {
|
|
167
|
-
const usage = process.cpuUsage();
|
|
168
|
-
expect(typeof usage.user).toBe('number');
|
|
169
|
-
expect(typeof usage.system).toBe('number');
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
await it('should accept previous value for delta', async () => {
|
|
173
|
-
const prev = process.cpuUsage();
|
|
174
|
-
// Do some work
|
|
175
|
-
let sum = 0;
|
|
176
|
-
for (let i = 0; i < 100000; i++) sum += i;
|
|
177
|
-
const delta = process.cpuUsage(prev);
|
|
178
|
-
expect(typeof delta.user).toBe('number');
|
|
179
|
-
expect(typeof delta.system).toBe('number');
|
|
180
|
-
// Delta user time should be non-negative
|
|
181
|
-
expect(delta.user >= 0).toBe(true);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// ===================== process.emitWarning =====================
|
|
186
|
-
await describe('process.emitWarning', async () => {
|
|
187
|
-
await it('should be a function', async () => {
|
|
188
|
-
expect(typeof process.emitWarning).toBe('function');
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// ===================== process.versions =====================
|
|
193
|
-
await describe('process.versions deep', async () => {
|
|
194
|
-
await it('should have versions object', async () => {
|
|
195
|
-
expect(typeof process.versions).toBe('object');
|
|
196
|
-
expect(process.versions !== null).toBe(true);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
await it('should have v8 or gjs version', async () => {
|
|
200
|
-
// On Node.js: v8 exists. On GJS: may have gjs or modules
|
|
201
|
-
const hasEngine = process.versions.v8 !== undefined ||
|
|
202
|
-
(process.versions as any).gjs !== undefined ||
|
|
203
|
-
process.versions.modules !== undefined;
|
|
204
|
-
expect(hasEngine).toBe(true);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// ===================== process.config =====================
|
|
209
|
-
await describe('process.config', async () => {
|
|
210
|
-
await it('should be an object', async () => {
|
|
211
|
-
expect(typeof process.config).toBe('object');
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
};
|