@gjsify/events 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 CHANGED
@@ -1,42 +1,46 @@
1
1
  {
2
- "name": "@gjsify/events",
3
- "version": "0.4.0",
4
- "description": "Node.js events module for Gjs",
5
- "type": "module",
6
- "module": "lib/esm/index.js",
7
- "types": "lib/types/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "require": "./cjs-compat.cjs",
12
- "default": "./lib/esm/index.js"
2
+ "name": "@gjsify/events",
3
+ "version": "0.4.4",
4
+ "description": "Node.js events module for Gjs",
5
+ "type": "module",
6
+ "module": "lib/esm/index.js",
7
+ "types": "lib/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "require": "./cjs-compat.cjs",
12
+ "default": "./lib/esm/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "lib",
17
+ "cjs-compat.cjs"
18
+ ],
19
+ "scripts": {
20
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
21
+ "check": "tsc --noEmit",
22
+ "build": "gjsify run build:gjsify && gjsify run build:types",
23
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
24
+ "build:types": "tsc",
25
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
26
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
27
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
28
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
29
+ "test:gjs": "gjsify run test.gjs.mjs",
30
+ "test:node": "node test.node.mjs"
31
+ },
32
+ "keywords": [
33
+ "gjs",
34
+ "node",
35
+ "events"
36
+ ],
37
+ "dependencies": {
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"
13
45
  }
14
- },
15
- "scripts": {
16
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
17
- "check": "tsc --noEmit",
18
- "build": "yarn build:gjsify && yarn build:types",
19
- "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
20
- "build:types": "tsc",
21
- "build:test": "yarn build:test:gjs && yarn build:test:node",
22
- "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
23
- "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
24
- "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
25
- "test:gjs": "gjsify run test.gjs.mjs",
26
- "test:node": "node test.node.mjs"
27
- },
28
- "keywords": [
29
- "gjs",
30
- "node",
31
- "events"
32
- ],
33
- "dependencies": {
34
- "@gjsify/utils": "^0.4.0"
35
- },
36
- "devDependencies": {
37
- "@gjsify/cli": "^0.4.0",
38
- "@gjsify/unit": "^0.4.0",
39
- "@types/node": "^25.6.2",
40
- "typescript": "^6.0.3"
41
- }
42
- }
46
+ }
@@ -1,146 +0,0 @@
1
- // Legacy `.call(this)` + `util.inherits(Sub, EventEmitter)` compatibility tests.
2
- //
3
- // Regression coverage for the `makeCallable` Proxy wrapper in @gjsify/utils:
4
- // `EventEmitter.call(this)` from CJS consumers must not throw
5
- // "TypeError: Class constructor EventEmitter cannot be invoked without 'new'".
6
- //
7
- // Ported from refs/node-test/parallel/test-util-inherits.js
8
- // Original: MIT license, Node.js contributors
9
- // Modifications: adapted to @gjsify/unit, scoped to EventEmitter.
10
-
11
- import { describe, it, expect } from '@gjsify/unit';
12
- import { EventEmitter } from 'node:events';
13
- import { inherits } from 'node:util';
14
-
15
- export default async () => {
16
- await describe('EventEmitter.makeCallable: new invocation still works', async () => {
17
- await it('new EventEmitter() returns a valid instance', async () => {
18
- const ee = new EventEmitter();
19
- expect(typeof ee.on).toBe('function');
20
- expect(typeof ee.emit).toBe('function');
21
- expect(typeof ee.removeListener).toBe('function');
22
- expect(ee instanceof EventEmitter).toBe(true);
23
- });
24
-
25
- await it('instance methods are available after new', async () => {
26
- const ee = new EventEmitter();
27
- const results: string[] = [];
28
- ee.on('data', (v: string) => results.push(v));
29
- ee.emit('data', 'hello');
30
- expect(results).toEqualArray(['hello']);
31
- });
32
-
33
- await it('EventEmitter.prototype is accessible', async () => {
34
- expect(typeof (EventEmitter as any).prototype).toBe('object');
35
- expect(typeof (EventEmitter as any).prototype.on).toBe('function');
36
- expect(typeof (EventEmitter as any).prototype.emit).toBe('function');
37
- });
38
-
39
- await it('instanceof works after new', async () => {
40
- const ee = new EventEmitter();
41
- expect(ee instanceof EventEmitter).toBe(true);
42
- });
43
- });
44
-
45
- await describe('EventEmitter.makeCallable: EventEmitter.call(this)', async () => {
46
- await it('EventEmitter.call(plain) assigns EventEmitter state', async () => {
47
- const plain: any = Object.create((EventEmitter as any).prototype);
48
- (EventEmitter as any).call(plain);
49
- // After .call(), the instance should be usable as an EventEmitter
50
- let received: string | undefined;
51
- plain.on('ping', (msg: string) => { received = msg; });
52
- plain.emit('ping', 'pong');
53
- expect(received).toBe('pong');
54
- });
55
-
56
- await it('EventEmitter.call(this) does not throw', async () => {
57
- let threw = false;
58
- try {
59
- const ctx: any = Object.create((EventEmitter as any).prototype);
60
- (EventEmitter as any).call(ctx);
61
- } catch {
62
- threw = true;
63
- }
64
- expect(threw).toBe(false);
65
- });
66
-
67
- await it('EventEmitter.call(this) — resulting object has on/emit/removeListener', async () => {
68
- const ctx: any = Object.create((EventEmitter as any).prototype);
69
- (EventEmitter as any).call(ctx);
70
- expect(typeof ctx.on).toBe('function');
71
- expect(typeof ctx.emit).toBe('function');
72
- expect(typeof ctx.removeListener).toBe('function');
73
- });
74
- });
75
-
76
- await describe('EventEmitter.makeCallable: util.inherits pattern', async () => {
77
- await it('util.inherits(Sub, EventEmitter) + Sub.call pattern', async () => {
78
- function MyEmitter(this: any) {
79
- (EventEmitter as any).call(this);
80
- this.name = 'my-emitter';
81
- }
82
- inherits(MyEmitter as any, EventEmitter as any);
83
-
84
- const ee: any = new (MyEmitter as any)();
85
- expect(ee.name).toBe('my-emitter');
86
- expect(typeof ee.on).toBe('function');
87
- expect(typeof ee.emit).toBe('function');
88
- expect(ee instanceof EventEmitter).toBe(true);
89
- });
90
-
91
- await it('events emitted by inherits-based subclass work correctly', async () => {
92
- function Counter(this: any) {
93
- (EventEmitter as any).call(this);
94
- this.count = 0;
95
- }
96
- inherits(Counter as any, EventEmitter as any);
97
- (Counter.prototype as any).increment = function(this: any) {
98
- this.count++;
99
- this.emit('incremented', this.count);
100
- };
101
-
102
- const c: any = new (Counter as any)();
103
- const received: number[] = [];
104
- c.on('incremented', (n: number) => received.push(n));
105
- c.increment();
106
- c.increment();
107
- c.increment();
108
- expect(c.count).toBe(3);
109
- expect(received).toEqualArray([1, 2, 3]);
110
- });
111
-
112
- await it('multi-level inherits (A extends EE, B extends A)', async () => {
113
- function A(this: any) {
114
- (EventEmitter as any).call(this);
115
- this.levelA = true;
116
- }
117
- inherits(A as any, EventEmitter as any);
118
-
119
- function B(this: any) {
120
- (A as any).call(this);
121
- this.levelB = true;
122
- }
123
- inherits(B as any, A as any);
124
-
125
- const b: any = new (B as any)();
126
- expect(b.levelA).toBe(true);
127
- expect(b.levelB).toBe(true);
128
- expect(typeof b.on).toBe('function');
129
- expect(b instanceof EventEmitter).toBe(true);
130
- });
131
-
132
- await it('once() works on inherits-based subclass', async () => {
133
- function OneShot(this: any) {
134
- (EventEmitter as any).call(this);
135
- }
136
- inherits(OneShot as any, EventEmitter as any);
137
-
138
- const os: any = new (OneShot as any)();
139
- let callCount = 0;
140
- os.once('event', () => callCount++);
141
- os.emit('event');
142
- os.emit('event'); // second emit should be ignored
143
- expect(callCount).toBe(1);
144
- });
145
- });
146
- };