@isograph/disposable-types 0.0.0-main-ae4fea0e → 0.0.0-main-a8e129cf

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.
@@ -1,11 +1,11 @@
1
1
  ../.. |  WARN  Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v24.20.0","pnpm":"10.15.0"})
2
2
 
3
- > @isograph/disposable-types@0.0.0-main-ae4fea0e compile-libs /home/runner/work/isograph/isograph/libs/isograph-disposable-types
3
+ > @isograph/disposable-types@0.0.0-main-a8e129cf compile-libs /home/runner/work/isograph/isograph/libs/isograph-disposable-types
4
4
  > tsdown
5
5
 
6
6
  ℹ tsdown v0.20.1 powered by rolldown v1.0.0-rc.1
7
7
  ℹ config file: /home/runner/work/isograph/isograph/tsdown.config.ts
8
- (node:2653) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/isograph/isograph/tsdown.config.ts?no-cache=dea0ee5b-991e-42cf-93dd-ff44b8fc144d is not specified and it doesn't parse as CommonJS.
8
+ (node:2582) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/isograph/isograph/tsdown.config.ts?no-cache=8163f23a-2e6b-411e-9d32-00b32bf8012c is not specified and it doesn't parse as CommonJS.
9
9
  Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
10
10
  To eliminate this warning, add "type": "module" to /home/runner/work/isograph/isograph/package.json.
11
11
  (Use `node --trace-warnings ...` to show where the warning was created)
@@ -1,5 +1,5 @@
1
1
  ../.. |  WARN  Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v24.20.0","pnpm":"10.15.0"})
2
2
 
3
- > @isograph/disposable-types@0.0.0-main-ae4fea0e tsc /home/runner/work/isograph/isograph/libs/isograph-disposable-types
3
+ > @isograph/disposable-types@0.0.0-main-a8e129cf tsc /home/runner/work/isograph/isograph/libs/isograph-disposable-types
4
4
  > tsc
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isograph/disposable-types",
3
- "version": "0.0.0-main-ae4fea0e",
3
+ "version": "0.0.0-main-a8e129cf",
4
4
  "description": "Common types for disposable items",
5
5
  "homepage": "https://isograph.dev",
6
6
  "main": "./dist/index.cjs",
@@ -28,9 +28,9 @@
28
28
  "scripts": {
29
29
  "compile-libs": "tsdown",
30
30
  "watch-libs": "tsdown --watch",
31
- "test": "echo this package has no tests",
32
- "test-watch": "echo this package has no tests",
33
- "coverage": "echo this package has no coverage",
31
+ "test": "vitest run",
32
+ "test-watch": "vitest watch",
33
+ "coverage": "vitest run --coverage",
34
34
  "tsc": "tsc",
35
35
  "tsc-force": "tsc --build --clean && tsc --build --force"
36
36
  }
@@ -0,0 +1,97 @@
1
+ import { assert, describe, expect, test } from 'vitest';
2
+ import { joinCleanups } from './index';
3
+
4
+ describe('joinCleanups', () => {
5
+ test('Disposes in reverse argument order', () => {
6
+ const order: string[] = [];
7
+ const [items, dispose] = joinCleanups(
8
+ [
9
+ 'a',
10
+ () => {
11
+ order.push('a');
12
+ },
13
+ ],
14
+ [
15
+ 'b',
16
+ () => {
17
+ order.push('b');
18
+ },
19
+ ],
20
+ [
21
+ 'c',
22
+ () => {
23
+ order.push('c');
24
+ },
25
+ ],
26
+ );
27
+
28
+ expect(items).toEqual(['a', 'b', 'c']);
29
+ dispose();
30
+ expect(order).toEqual(['c', 'b', 'a']);
31
+ });
32
+
33
+ test('If a cleanup throws, remaining cleanups still run and the first error is rethrown', () => {
34
+ const order: string[] = [];
35
+ const errorB = new Error('b');
36
+ const [, dispose] = joinCleanups(
37
+ [
38
+ 'a',
39
+ () => {
40
+ order.push('a');
41
+ },
42
+ ],
43
+ [
44
+ 'b',
45
+ () => {
46
+ order.push('b');
47
+ throw errorB;
48
+ },
49
+ ],
50
+ [
51
+ 'c',
52
+ () => {
53
+ order.push('c');
54
+ },
55
+ ],
56
+ );
57
+
58
+ let thrown: unknown;
59
+ try {
60
+ dispose();
61
+ } catch (e) {
62
+ thrown = e;
63
+ }
64
+
65
+ assert(thrown === errorB);
66
+ expect(order).toEqual(['c', 'b', 'a']);
67
+ });
68
+
69
+ test('If two cleanups throw, the first error in dispose order is rethrown', () => {
70
+ const errorA = new Error('a');
71
+ const errorC = new Error('c');
72
+ const [, dispose] = joinCleanups(
73
+ [
74
+ 'a',
75
+ () => {
76
+ throw errorA;
77
+ },
78
+ ],
79
+ ['b', () => {}],
80
+ [
81
+ 'c',
82
+ () => {
83
+ throw errorC;
84
+ },
85
+ ],
86
+ );
87
+
88
+ let thrown: unknown;
89
+ try {
90
+ dispose();
91
+ } catch (e) {
92
+ thrown = e;
93
+ }
94
+
95
+ assert(thrown === errorC);
96
+ });
97
+ });