typenative 0.7.0 → 0.7.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.
Files changed (217) hide show
  1. package/bin/node/assert.js +2 -2
  2. package/bin/node/child_process.js +66 -8
  3. package/bin/node/fs.js +1012 -4
  4. package/bin/node/histogram.js +1991 -0
  5. package/bin/node/process.js +14 -2
  6. package/bin/node/sqlite.js +1488 -5
  7. package/bin/node/stream.js +2 -1
  8. package/bin/node/system_extra.js +3 -270
  9. package/bin/node/test.js +39 -1
  10. package/bin/node/test_report.js +47 -1
  11. package/bin/node/test_run.js +57 -2
  12. package/bin/node/util.js +8 -5
  13. package/bin/node/webassembly.js +20 -5
  14. package/bin/node/webview.js +3257 -244
  15. package/bin/node/zlib.js +118 -14
  16. package/bin/node/zlib_iter.js +585 -0
  17. package/bin/transpiler.js +1370 -258
  18. package/bin/version.js +1 -1
  19. package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
  20. package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
  21. package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
  22. package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
  23. package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
  24. package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
  25. package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
  26. package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
  27. package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
  28. package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
  29. package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
  30. package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
  31. package/package.json +10 -1
  32. package/types/tsconfig.json +17 -0
  33. package/types/typenative-npm.d.ts +492 -12
  34. package/types/typenative.d.ts +88 -2
  35. package/.gitattributes +0 -1
  36. package/.github/workflows/ci.yml +0 -68
  37. package/.github/workflows/npm-publish-github-packages.yml +0 -88
  38. package/CHANGELOG.md +0 -1746
  39. package/CONTRIBUTION.md +0 -133
  40. package/conformance.md +0 -1497
  41. package/examples/README.md +0 -114
  42. package/examples/angular-templates/README.md +0 -141
  43. package/examples/angular-templates/bench.mjs +0 -173
  44. package/examples/angular-templates/dom-type-globals.d.ts +0 -21
  45. package/examples/angular-templates/dom-type-stubs.ts +0 -21
  46. package/examples/angular-templates/main.ts +0 -135
  47. package/examples/angular-templates/parity.mjs +0 -157
  48. package/examples/angular-templates/run-node.mjs +0 -69
  49. package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
  50. package/examples/desktop-notes/README.md +0 -106
  51. package/examples/desktop-notes/bench.mjs +0 -125
  52. package/examples/desktop-notes/main.ts +0 -131
  53. package/examples/desktop-notes/package-lock.json +0 -726
  54. package/examples/desktop-notes/package.json +0 -9
  55. package/examples/desktop-notes/ui.ts +0 -176
  56. package/examples/dupe-finder/README.md +0 -78
  57. package/examples/dupe-finder/bench.mjs +0 -120
  58. package/examples/dupe-finder/main.ts +0 -87
  59. package/examples/fibonacci/README.md +0 -89
  60. package/examples/fibonacci/bench.mjs +0 -87
  61. package/examples/fibonacci/main.ts +0 -21
  62. package/examples/hello-world/README.md +0 -62
  63. package/examples/hello-world/bench.mjs +0 -66
  64. package/examples/hello-world/main.ts +0 -7
  65. package/examples/json-server/README.md +0 -132
  66. package/examples/json-server/bench.mjs +0 -263
  67. package/examples/json-server/main.ts +0 -67
  68. package/examples/mandelbrot-png/README.md +0 -63
  69. package/examples/mandelbrot-png/bench.mjs +0 -95
  70. package/examples/mandelbrot-png/main.ts +0 -98
  71. package/examples/mandelbrot-png/preview.png +0 -0
  72. package/examples/marked-cli/README.md +0 -174
  73. package/examples/marked-cli/bench.mjs +0 -178
  74. package/examples/marked-cli/main.ts +0 -410
  75. package/examples/marked-cli/parity.mjs +0 -185
  76. package/examples/marked-cli/vendor/marked/LICENSE +0 -44
  77. package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
  78. package/examples/openai-chat/README.md +0 -148
  79. package/examples/openai-chat/bench.mjs +0 -175
  80. package/examples/openai-chat/main.ts +0 -488
  81. package/examples/react-compiler/README.md +0 -185
  82. package/examples/react-compiler/bench.mjs +0 -181
  83. package/examples/react-compiler/main.ts +0 -324
  84. package/examples/react-compiler/parity.mjs +0 -362
  85. package/examples/react-compiler/run-node.mjs +0 -90
  86. package/examples/react-compiler/vendor/babel/LICENSE +0 -22
  87. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
  88. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
  89. package/examples/react-compiler/vendor/charcodes/package.json +0 -25
  90. package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
  91. package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
  92. package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
  93. package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
  94. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
  95. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
  96. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
  97. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
  98. package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
  99. package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
  100. package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
  101. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
  102. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
  103. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
  104. package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
  105. package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
  106. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
  107. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
  108. package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
  109. package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
  110. package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
  111. package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
  112. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
  113. package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
  114. package/examples/react-compiler/vendor/zod/LICENSE +0 -21
  115. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
  116. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
  117. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
  118. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
  119. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
  120. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
  121. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
  145. package/examples/react-compiler/vendor.mjs +0 -688
  146. package/examples/todo-cli/README.md +0 -69
  147. package/examples/todo-cli/bench.mjs +0 -89
  148. package/examples/todo-cli/main.ts +0 -92
  149. package/examples/yaml-cli/README.md +0 -152
  150. package/examples/yaml-cli/bench.mjs +0 -265
  151. package/examples/yaml-cli/main.ts +0 -251
  152. package/examples/yaml-cli/parity.mjs +0 -156
  153. package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
  154. package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
  155. package/performance/README.md +0 -248
  156. package/performance/any-dynamic.ts +0 -21
  157. package/performance/any-record-view.ts +0 -20
  158. package/performance/arr-for-of.ts +0 -29
  159. package/performance/arr-hof.ts +0 -21
  160. package/performance/arr-push-index.ts +0 -15
  161. package/performance/arr-push-local.ts +0 -39
  162. package/performance/arr-slice-concat.ts +0 -24
  163. package/performance/arr-sort.ts +0 -21
  164. package/performance/async-await.ts +0 -24
  165. package/performance/async-promise-all.ts +0 -38
  166. package/performance/bigint-arith.ts +0 -36
  167. package/performance/buf-encode.ts +0 -29
  168. package/performance/class-accessors.ts +0 -48
  169. package/performance/class-dispatch.ts +0 -52
  170. package/performance/date-format.ts +0 -18
  171. package/performance/events-emit.ts +0 -27
  172. package/performance/exc-throw-rare.ts +0 -25
  173. package/performance/exc-try-catch.ts +0 -26
  174. package/performance/fn-closures.ts +0 -29
  175. package/performance/fn-recursion-tree.ts +0 -31
  176. package/performance/fn-rest-spread.ts +0 -43
  177. package/performance/gen-for-of.ts +0 -46
  178. package/performance/gen-next.ts +0 -32
  179. package/performance/iter-helpers.ts +0 -38
  180. package/performance/json-any.ts +0 -30
  181. package/performance/json-roundtrip.ts +0 -27
  182. package/performance/map-delete.ts +0 -24
  183. package/performance/map-iterate.ts +0 -26
  184. package/performance/map-number-keys.ts +0 -37
  185. package/performance/map-string-keys.ts +0 -22
  186. package/performance/num-arith-loop.ts +0 -14
  187. package/performance/num-bitwise.ts +0 -21
  188. package/performance/num-hash-imul.ts +0 -36
  189. package/performance/num-mod-int.ts +0 -16
  190. package/performance/num-to-string.ts +0 -16
  191. package/performance/obj-alloc.ts +0 -32
  192. package/performance/obj-keys-entries.ts +0 -44
  193. package/performance/obj-optional-chain.ts +0 -42
  194. package/performance/obj-record-dict.ts +0 -24
  195. package/performance/obj-spread-destructure.ts +0 -40
  196. package/performance/regex-exec.ts +0 -29
  197. package/performance/regex-replace-fn.ts +0 -24
  198. package/performance/regex-site.ts +0 -28
  199. package/performance/set-ops.ts +0 -20
  200. package/performance/str-char-scan.ts +0 -35
  201. package/performance/str-concat-plus.ts +0 -18
  202. package/performance/str-concat.ts +0 -24
  203. package/performance/str-methods.ts +0 -24
  204. package/performance/str-short-scan.ts +0 -26
  205. package/performance/str-split-join.ts +0 -23
  206. package/performance/str-switch-compare.ts +0 -50
  207. package/performance/str-template.ts +0 -16
  208. package/performance/str-unicode.ts +0 -25
  209. package/performance/typed-array.ts +0 -30
  210. package/performance/union-switch.ts +0 -57
  211. package/performance/union-typeof.ts +0 -40
  212. package/performance/wasm-call.ts +0 -63
  213. package/tsparser/check.go +0 -158
  214. package/tsparser/go.mod +0 -14
  215. package/tsparser/go.sum +0 -22
  216. package/tsparser/main.go +0 -363
  217. package/tsparser/tsparser.exe +0 -4
@@ -1,9 +0,0 @@
1
- {
2
- "name": "desktop-notes-example",
3
- "private": true,
4
- "type": "module",
5
- "description": "The Node.js side of the example: compiled builds don't use this package",
6
- "dependencies": {
7
- "@webviewjs/webview": "1.0.0-rc.4"
8
- }
9
- }
@@ -1,176 +0,0 @@
1
- // The app's whole user interface: one HTML page with inline CSS and JS. It is
2
- // a TypeScript string, so it is compiled into the binary (no files to ship
3
- // next to it) and works unchanged under Node.js.
4
- export const page = `<!doctype html>
5
- <html lang="en" translate="no">
6
- <head>
7
- <meta charset="utf-8">
8
- <meta name="viewport" content="width=device-width, initial-scale=1">
9
- <title>Notes</title>
10
- <style>
11
- :root {
12
- color-scheme: light dark;
13
- --bg: #f6f7f9; --side: #eceef2; --text: #1d2330; --muted: #677085;
14
- --line: #d9dde5; --accent: #3d7be0; --active: #dde6f7; --danger: #c4402e;
15
- }
16
- @media (prefers-color-scheme: dark) {
17
- :root { --bg: #16191f; --side: #1d212a; --text: #e8ebf2; --muted: #8b93a7;
18
- --line: #2b313d; --active: #26324a; }
19
- }
20
- * { box-sizing: border-box; }
21
- html, body { height: 100%; }
22
- body { margin: 0; display: flex; background: var(--bg); color: var(--text);
23
- font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
24
- aside { width: 240px; flex-shrink: 0; background: var(--side); display: flex; flex-direction: column;
25
- border-right: 1px solid var(--line); }
26
- aside header { display: flex; gap: 6px; padding: 12px; }
27
- #search { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
28
- background: var(--bg); color: inherit; font: inherit; }
29
- button { border: 0; border-radius: 6px; padding: 6px 10px; font: inherit; cursor: pointer;
30
- background: var(--accent); color: #fff; }
31
- button.ghost { background: transparent; color: var(--danger); }
32
- ul { list-style: none; margin: 0; padding: 0 6px; overflow-y: auto; flex: 1; }
33
- li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
34
- li.active { background: var(--active); }
35
- li small { display: block; color: var(--muted); font-size: 12px; }
36
- aside footer { padding: 10px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
37
- main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
38
- main header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
39
- #title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
40
- #status { color: var(--muted); font-size: 12px; }
41
- textarea { flex: 1; border: 0; padding: 16px; resize: none; outline: none; background: transparent; color: inherit;
42
- font: 15px/1.6 ui-monospace, "Cascadia Code", Menlo, monospace; }
43
- .empty { margin: auto; color: var(--muted); }
44
- @media (max-width: 560px) { aside { width: 150px; } }
45
- </style>
46
- </head>
47
- <body>
48
- <aside>
49
- <header>
50
- <input id="search" placeholder="Search" autocomplete="off">
51
- <button id="new" title="New note">+</button>
52
- </header>
53
- <ul id="list"></ul>
54
- <footer id="info"></footer>
55
- </aside>
56
- <main>
57
- <header>
58
- <div id="title">No note selected</div>
59
- <span id="status"></span>
60
- <button id="delete" class="ghost" hidden>Delete</button>
61
- </header>
62
- <textarea id="editor" spellcheck="false" hidden></textarea>
63
- <div class="empty" id="empty">Create a note with +</div>
64
- </main>
65
- <script>
66
- const $ = (id) => document.getElementById(id);
67
- let notes = [];
68
- let current = null;
69
- let saveTimer = 0;
70
-
71
- const ago = (ms) => {
72
- const s = Math.round((Date.now() - ms) / 1000);
73
- if (s < 60) return 'just now';
74
- if (s < 3600) return Math.floor(s / 60) + ' min ago';
75
- if (s < 86400) return Math.floor(s / 3600) + ' h ago';
76
- return new Date(ms).toLocaleDateString();
77
- };
78
-
79
- async function loadList() {
80
- notes = await (await fetch('/api/notes')).json();
81
- render();
82
- }
83
-
84
- function render() {
85
- const q = $('search').value.toLowerCase();
86
- $('list').innerHTML = '';
87
- for (const n of notes.filter((n) => n.name.toLowerCase().includes(q))) {
88
- const li = document.createElement('li');
89
- li.className = n.name === current ? 'active' : '';
90
- li.textContent = n.name;
91
- const meta = document.createElement('small');
92
- meta.textContent = ago(n.modified) + ' · ' + n.size + ' B';
93
- li.append(meta);
94
- li.onclick = () => open(n.name);
95
- $('list').append(li);
96
- }
97
- }
98
-
99
- async function open(name) {
100
- await flush();
101
- const res = await fetch('/api/notes/' + encodeURIComponent(name));
102
- current = name;
103
- $('editor').value = res.ok ? await res.text() : '';
104
- $('title').textContent = name;
105
- $('editor').hidden = false;
106
- $('delete').hidden = false;
107
- $('empty').hidden = true;
108
- $('status').textContent = '';
109
- $('editor').focus();
110
- render();
111
- }
112
-
113
- async function flush() {
114
- if (!saveTimer) return;
115
- clearTimeout(saveTimer);
116
- saveTimer = 0;
117
- await save();
118
- }
119
-
120
- async function save() {
121
- saveTimer = 0;
122
- await fetch('/api/notes/' + encodeURIComponent(current), { method: 'PUT', body: $('editor').value });
123
- $('status').textContent = 'Saved';
124
- await loadList();
125
- }
126
-
127
- $('editor').oninput = () => {
128
- $('status').textContent = 'Editing…';
129
- clearTimeout(saveTimer);
130
- saveTimer = setTimeout(save, 400);
131
- };
132
-
133
- $('new').onclick = async () => {
134
- let n = 1;
135
- while (notes.some((x) => x.name === 'Untitled ' + n)) n++;
136
- current = 'Untitled ' + n;
137
- await fetch('/api/notes/' + encodeURIComponent(current), { method: 'PUT', body: '' });
138
- await loadList();
139
- open(current);
140
- };
141
-
142
- $('delete').onclick = async () => {
143
- clearTimeout(saveTimer);
144
- saveTimer = 0;
145
- await fetch('/api/notes/' + encodeURIComponent(current), { method: 'DELETE' });
146
- current = null;
147
- $('editor').hidden = true;
148
- $('delete').hidden = true;
149
- $('empty').hidden = false;
150
- $('title').textContent = 'No note selected';
151
- await loadList();
152
- };
153
-
154
- $('search').oninput = render;
155
-
156
- async function refreshInfo() {
157
- try {
158
- const i = await (await fetch('/api/info')).json();
159
- $('info').textContent = i.dir + ' · ' + i.runtime + ' · ' + (i.rss / 1048576).toFixed(1) + ' MiB';
160
- } catch {
161
- $('info').textContent = 'disconnected';
162
- }
163
- }
164
-
165
- loadList().then(() => notes.length && open(notes[0].name));
166
- refreshInfo();
167
- setInterval(refreshInfo, 5000);
168
- // Closing the window saves what the autosave hasn't reached. Not pagehide:
169
- // webviews can tear the page down without it.
170
- addEventListener('beforeunload', () => {
171
- if (saveTimer) navigator.sendBeacon('/api/notes/' + encodeURIComponent(current), $('editor').value);
172
- });
173
- </script>
174
- </body>
175
- </html>
176
- `;
@@ -1,78 +0,0 @@
1
- # Duplicate Finder
2
-
3
- Scans a directory tree, finds files with identical content and writes a JSON
4
- report of the duplicates and the space they waste. It's a disk-bound and
5
- hash-bound tool you can hand to anyone as one binary, with no runtime to
6
- install.
7
-
8
- Demonstrates: `fs.readdirSync` with `recursive` + `withFileTypes`,
9
- `fs.statSync`, `fs.readFileSync` / `fs.writeFileSync`, SHA-256 via
10
- `crypto.createHash`, `Map` grouping, sorting with a compound comparator,
11
- `reduce`, `JSON.stringify` with indentation and `performance.now()`.
12
-
13
- ## How it works
14
-
15
- 1. Walk the tree and group every non-empty file by size.
16
- 2. Hash (SHA-256) only the files whose size matches at least one other file.
17
- A file with a unique size can't have a duplicate, so it's never read.
18
- 3. Files with the same hash form a duplicate group. Groups are sorted by
19
- wasted bytes (`size × (copies − 1)`) and written to the report.
20
-
21
- ```sh
22
- node main.ts ~/Downloads report.json
23
- # Scanned 2000 files (243.5 MiB), hashed 1494
24
- # Found 449 duplicate groups wasting 81.9 MiB
25
- # <copies> x <size> B <first path> (the 5 biggest groups)
26
- # Report written to report.json in 412 ms
27
- ```
28
-
29
- `report.json` lists every group with its hash, size and full file paths.
30
-
31
- ## Run it
32
-
33
- With Node.js:
34
-
35
- ```sh
36
- node main.ts <dir> [report.json]
37
- ```
38
-
39
- With TypeNative:
40
-
41
- ```sh
42
- npx typenative --source main.ts --output dist/dupes.exe
43
- ./dist/dupes.exe <dir> [report.json]
44
- ```
45
-
46
- From a checkout of this repository:
47
-
48
- ```sh
49
- node bin/cli.js --source examples/dupe-finder/main.ts --output dist/dupes.exe
50
- ```
51
-
52
- ## Benchmark: Node.js vs TypeNative
53
-
54
- Reproduce with `node bench.mjs [runs=10]`. The script compiles `main.ts` and
55
- generates a deterministic fixture tree in a temp directory: 2,000 files
56
- (1 KiB–256 KiB, 243.5 MiB) across 280 folders. A quarter of the files are
57
- exact copies of earlier ones, and another quarter have the same size as an
58
- earlier file but different bytes, so they get hashed without being
59
- duplicates. It runs each runtime once to warm the OS file cache, then times
60
- **complete process runs** of both and checks that the two reports are
61
- byte-identical.
62
-
63
- **Environment:** Windows 11 Pro, AMD Ryzen 5 7600, Node v26.13.0, Go 1.27.4,
64
- TypeNative 0.7.0, default (non-`--release`) build.
65
-
66
- | Runtime | min | median | mean | max |
67
- |------------|-----------|-----------|-----------|-----------|
68
- | Node.js | 634.70 ms | 643.34 ms | 645.54 ms | 662.58 ms |
69
- | TypeNative | 227.20 ms | 230.55 ms | 780.92 ms | 5743.15 ms |
70
-
71
- Both runtimes found the same 449 duplicate groups (1,494 files hashed,
72
- 81.9 MiB wasted). **TypeNative finishes the scan 2.8x faster** (median). One native run in
73
- ten took several seconds (it happened on every re-run, likely antivirus
74
- scanning), which skews the mean and max but not the median. The
75
- work is reading and hashing about 180 MiB, so the gap comes from Go's
76
- SHA-256 and file I/O, and from skipping the ~100 ms Node startup. The OS
77
- file cache is warm in both cases. On a cold cache, disk speed dominates and
78
- the gap narrows.
@@ -1,120 +0,0 @@
1
- // Disk-scan benchmark: Node.js vs TypeNative for the duplicate finder.
2
- //
3
- // Compiles main.ts to a native binary with the TypeNative CLI from this repo
4
- // checkout (../../bin/cli.js), generates a fixture tree in a temp directory
5
- // (2,000 files in 40 folders, 1 KiB - 256 KiB, a quarter of them duplicates,
6
- // plus same-size files with different content), then times complete process
7
- // runs of both runtimes over it and checks that the two reports match.
8
- //
9
- // Usage: node bench.mjs [runs=10]
10
-
11
- import { spawnSync } from 'node:child_process';
12
- import fs from 'node:fs';
13
- import os from 'node:os';
14
- import path from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
-
17
- const here = path.dirname(fileURLToPath(import.meta.url));
18
- const repoRoot = path.resolve(here, '..', '..');
19
- const cli = path.join(repoRoot, 'bin', 'cli.js');
20
- const runs = Number(process.argv[2] ?? '10') || 10;
21
- const exeName = process.platform === 'win32' ? 'dupes.exe' : 'dupes';
22
- const exePath = path.join(here, 'dist', exeName);
23
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dupes-bench-'));
24
- const fixture = path.join(tmpDir, 'tree');
25
-
26
- function stats(samples) {
27
- const sorted = [...samples].sort((a, b) => a - b);
28
- const mean = samples.reduce((sum, x) => sum + x, 0) / samples.length;
29
- return { min: sorted[0], median: sorted[Math.floor(sorted.length / 2)], mean, max: sorted[sorted.length - 1] };
30
- }
31
-
32
- function fmt(ms) {
33
- return `${ms.toFixed(2)} ms`.padStart(11);
34
- }
35
-
36
- // Deterministic pseudo-random bytes, so every run scans the same tree
37
- function makeFixture() {
38
- let seed = 42;
39
- const rand = () => {
40
- seed ^= seed << 13;
41
- seed ^= seed >>> 17;
42
- seed ^= seed << 5;
43
- return (seed >>> 0) / 0x100000000;
44
- };
45
- const originals = [];
46
- let bytes = 0;
47
- for (let i = 0; i < 2000; i++) {
48
- const dir = path.join(fixture, `dir-${i % 40}`, `sub-${i % 7}`);
49
- fs.mkdirSync(dir, { recursive: true });
50
- let content;
51
- if (i % 4 === 3 && originals.length > 0) {
52
- // An exact copy of an earlier file
53
- content = originals[Math.floor(rand() * originals.length)];
54
- } else if (i % 4 === 2 && originals.length > 0) {
55
- // Same size as an earlier file, different bytes: hashed, but not a duplicate
56
- const twin = originals[Math.floor(rand() * originals.length)];
57
- content = Buffer.from(twin);
58
- content[content.length - 1] ^= 0xff;
59
- } else {
60
- content = Buffer.alloc(1024 + 4 * Math.floor(rand() * 255 * 256));
61
- for (let j = 0; j < content.length; j += 4) content.writeUInt32LE(Math.floor(rand() * 0xffffffff), j);
62
- originals.push(content);
63
- }
64
- fs.writeFileSync(path.join(dir, `file-${i}.bin`), content);
65
- bytes += content.length;
66
- }
67
- return bytes;
68
- }
69
-
70
- function timeRuns(command, args) {
71
- const samples = [];
72
- for (let i = 0; i < runs; i++) {
73
- const t0 = performance.now();
74
- const result = spawnSync(command, args, { cwd: here, encoding: 'utf8' });
75
- const elapsed = performance.now() - t0;
76
- if (result.status !== 0) {
77
- console.error(`run failed: ${command} ${args.join(' ')}\n${result.stderr}`);
78
- process.exit(1);
79
- }
80
- samples.push(elapsed);
81
- }
82
- return stats(samples);
83
- }
84
-
85
- // 1. Compile the finder to a native binary.
86
- fs.mkdirSync(path.join(here, 'dist'), { recursive: true });
87
- console.log('Compiling main.ts to a native binary with TypeNative...');
88
- const build = spawnSync(process.execPath, [cli, '--source', 'main.ts', '--output', path.join('dist', exeName)], {
89
- cwd: here,
90
- stdio: 'inherit',
91
- });
92
- if (build.status !== 0) process.exit(build.status ?? 1);
93
-
94
- // 2. Build the fixture tree.
95
- const fixtureBytes = makeFixture();
96
- console.log(`\nFixture: 2000 files, ${(fixtureBytes / 1024 / 1024).toFixed(1)} MiB in ${fixture}`);
97
-
98
- // 3. Time full runs of both runtimes (the first run of each also warms the OS file cache).
99
- const nodeReport = path.join(tmpDir, 'node.json');
100
- const nativeReport = path.join(tmpDir, 'native.json');
101
- timeRuns(process.execPath, ['main.ts', fixture, nodeReport]);
102
- console.log(`\nTiming ${runs} full process runs of each runtime...\n`);
103
- const nodeStats = timeRuns(process.execPath, ['main.ts', fixture, nodeReport]);
104
- const nativeStats = timeRuns(exePath, [fixture, nativeReport]);
105
-
106
- const same = fs.readFileSync(nodeReport, 'utf8') === fs.readFileSync(nativeReport, 'utf8');
107
- const report = JSON.parse(fs.readFileSync(nativeReport, 'utf8'));
108
- fs.rmSync(tmpDir, { recursive: true, force: true });
109
-
110
- console.log(`Scan + hash + report, ${runs} runs (full process: spawn -> exit):\n`);
111
- console.log('| Runtime | min | median | mean | max |');
112
- console.log('|------------|-------------|-------------|-------------|-------------|');
113
- console.log(`| Node.js |${fmt(nodeStats.min)} |${fmt(nodeStats.median)} |${fmt(nodeStats.mean)} |${fmt(nodeStats.max)} |`);
114
- console.log(`| TypeNative |${fmt(nativeStats.min)} |${fmt(nativeStats.median)} |${fmt(nativeStats.mean)} |${fmt(nativeStats.max)} |`);
115
- console.log(
116
- `\nBoth found ${report.groups.length} duplicate groups (${report.hashedFiles} files hashed, ` +
117
- `${(report.wastedBytes / 1024 / 1024).toFixed(1)} MiB wasted); reports identical: ${same}`
118
- );
119
- console.log(`TypeNative is ${(nodeStats.median / nativeStats.median).toFixed(1)}x faster (median).`);
120
- if (!same) process.exit(1);
@@ -1,87 +0,0 @@
1
- // Finds duplicate files under a directory and writes a JSON report.
2
- // Files are grouped by size first, so only files that share a size are read
3
- // and hashed (SHA-256). Duplicates are files whose hashes match.
4
- //
5
- // node main.ts <dir> [report.json]
6
- // ./dupes <dir> [report.json] (default report: dupes.json)
7
- import crypto from 'node:crypto';
8
- import fs from 'node:fs';
9
- import path from 'node:path';
10
-
11
- interface DuplicateGroup {
12
- hash: string;
13
- size: number;
14
- files: string[];
15
- }
16
-
17
- interface Report {
18
- root: string;
19
- scannedFiles: number;
20
- scannedBytes: number;
21
- hashedFiles: number;
22
- groups: DuplicateGroup[];
23
- wastedBytes: number;
24
- }
25
-
26
- const root = path.resolve(process.argv[2] ?? '.');
27
- const reportPath = process.argv[3] ?? 'dupes.json';
28
- const started = performance.now();
29
-
30
- // 1. Walk the tree and group every regular file by size.
31
- const bySize = new Map<number, string[]>();
32
- let scannedFiles = 0;
33
- let scannedBytes = 0;
34
- for (const entry of fs.readdirSync(root, { recursive: true, withFileTypes: true })) {
35
- if (!entry.isFile()) continue;
36
- const file = path.join(entry.parentPath, entry.name);
37
- const size = fs.statSync(file).size;
38
- scannedFiles++;
39
- scannedBytes += size;
40
- if (size === 0) continue;
41
- const sameSize = bySize.get(size) ?? [];
42
- sameSize.push(file);
43
- bySize.set(size, sameSize);
44
- }
45
-
46
- // 2. Hash only the files that share a size with another file.
47
- const byHash = new Map<string, DuplicateGroup>();
48
- let hashedFiles = 0;
49
- for (const [size, files] of bySize) {
50
- if (files.length < 2) continue;
51
- for (const file of files) {
52
- const hash = crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
53
- hashedFiles++;
54
- const group = byHash.get(hash);
55
- if (group) group.files.push(file);
56
- else byHash.set(hash, { hash: hash, size: size, files: [file] });
57
- }
58
- }
59
-
60
- // 3. Keep the groups with more than one file, biggest savings first.
61
- const groups: DuplicateGroup[] = [];
62
- for (const group of byHash.values()) {
63
- if (group.files.length > 1) {
64
- group.files.sort();
65
- groups.push(group);
66
- }
67
- }
68
- groups.sort((a, b) => b.size * (b.files.length - 1) - a.size * (a.files.length - 1) || (a.hash < b.hash ? -1 : 1));
69
- const wastedBytes = groups.reduce((sum, g) => sum + g.size * (g.files.length - 1), 0);
70
-
71
- const report: Report = {
72
- root: root,
73
- scannedFiles: scannedFiles,
74
- scannedBytes: scannedBytes,
75
- hashedFiles: hashedFiles,
76
- groups: groups,
77
- wastedBytes: wastedBytes
78
- };
79
- fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
80
-
81
- const mib = (n: number): string => (n / 1024 / 1024).toFixed(1);
82
- console.log(`Scanned ${scannedFiles} files (${mib(scannedBytes)} MiB), hashed ${hashedFiles}`);
83
- console.log(`Found ${groups.length} duplicate groups wasting ${mib(wastedBytes)} MiB`);
84
- for (const group of groups.slice(0, 5)) {
85
- console.log(` ${group.files.length} x ${group.size} B ${path.relative(root, group.files[0])}`);
86
- }
87
- console.log(`Report written to ${reportPath} in ${Math.round(performance.now() - started)} ms`);
@@ -1,89 +0,0 @@
1
- # Fibonacci
2
-
3
- The classic CPU-bound benchmark: naive recursive Fibonacci. The same source
4
- runs unchanged under Node.js and as a compiled TypeNative binary, and times
5
- itself with `performance.now()` so both runtimes are measured the same way —
6
- compute time only, startup excluded.
7
-
8
- ## The code
9
-
10
- ```ts
11
- // main.ts
12
- import { performance } from 'node:perf_hooks';
13
-
14
- function fib(n: number): number {
15
- return n < 2 ? n : fib(n - 1) + fib(n - 2);
16
- }
17
-
18
- const n = Number(process.argv[2] ?? '35');
19
-
20
- const start = performance.now();
21
- const result = fib(n);
22
- const elapsedMs = performance.now() - start;
23
-
24
- console.log(`fib(${n}) = ${result}`);
25
- console.log(`computed in ${elapsedMs.toFixed(2)} ms`);
26
- ```
27
-
28
- ## Run it
29
-
30
- With Node.js:
31
-
32
- ```sh
33
- node main.ts 35
34
- # fib(35) = 9227465
35
- # computed in 94.81 ms
36
- ```
37
-
38
- With TypeNative (compile to a native binary and run it):
39
-
40
- ```sh
41
- npx typenative --source main.ts --output dist/fib.exe
42
- ./dist/fib.exe 35
43
- # fib(35) = 9227465
44
- # computed in 50.16 ms
45
- ```
46
-
47
- From a checkout of this repository, use the local CLI instead of `npx`:
48
-
49
- ```sh
50
- node bin/cli.js --source examples/fibonacci/main.ts --script # compile + run
51
- node bin/cli.js --source examples/fibonacci/main.ts --output dist/fib.exe
52
- ```
53
-
54
- (`--script` compiles and runs in one step; passing a custom `n` requires a
55
- built binary, as shown above.)
56
-
57
- ## Benchmark: Node.js vs TypeNative
58
-
59
- Reproduce with `node bench.mjs [n=35] [runs=15]`. The script compiles
60
- `main.ts` with the TypeNative CLI, runs `fib(35)` under both runtimes, and
61
- reports two numbers per run: the program's own in-process compute time
62
- (parsed from its output) and the total wall time including process startup.
63
-
64
- **Environment:** Windows 11 Pro, AMD Ryzen 5 7600, Node v26.13.0, Go 1.27.4,
65
- TypeNative 0.7.0, default (non-`--release`) build.
66
-
67
- Compute time, `fib(35)` over 15 runs (measured in-program):
68
-
69
- | Runtime | min | median | mean | max |
70
- |------------|-----------|-----------|-----------|-----------|
71
- | Node.js | 65.60 ms | 66.06 ms | 66.35 ms | 69.04 ms |
72
- | TypeNative | 30.61 ms | 31.77 ms | 31.79 ms | 33.14 ms |
73
-
74
- Total wall time per run, including startup (spawn to exit):
75
-
76
- | Runtime | min | median | mean | max |
77
- |------------|-----------|-----------|-----------|-----------|
78
- | Node.js | 112.81 ms | 115.82 ms | 116.67 ms | 125.42 ms |
79
- | TypeNative | 36.36 ms | 37.34 ms | 43.80 ms | 133.02 ms |
80
-
81
- **TypeNative computes 2.1x faster** and finishes the whole run **3.1x
82
- faster**. The recursive calls, arithmetic, and number boxing all compile
83
- ahead of time to native machine code via Go, while V8 must tier up through
84
- its JIT before it reaches comparable speed — and never reaches it here, since
85
- Go's float64 arithmetic and non-virtual calls map directly onto the hardware.
86
-
87
- Takeaway: for CPU-bound TypeScript (number crunching, parsing, simulations),
88
- compiling with TypeNative roughly doubles throughput without changing a line
89
- of code.
@@ -1,87 +0,0 @@
1
- // CPU benchmark: Node.js vs TypeNative for the fibonacci program.
2
- //
3
- // Compiles main.ts to a native binary with the TypeNative CLI from this repo
4
- // checkout (../../bin/cli.js), then runs the same program under both runtimes.
5
- // Each run reports two numbers:
6
- // - compute time: parsed from the program's own `computed in X ms` output
7
- // (measured inside the program with process.hrtime.bigint)
8
- // - total wall time: process spawn to exit, measured here
9
- //
10
- // Usage: node bench.mjs [n=35] [runs=15]
11
-
12
- import { spawnSync } from 'node:child_process';
13
- import fs from 'node:fs';
14
- import path from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
-
17
- const here = path.dirname(fileURLToPath(import.meta.url));
18
- const repoRoot = path.resolve(here, '..', '..');
19
- const cli = path.join(repoRoot, 'bin', 'cli.js');
20
- const n = Number(process.argv[2] ?? '35') || 35;
21
- const runs = Number(process.argv[3] ?? '15') || 15;
22
- const exeName = process.platform === 'win32' ? 'fib.exe' : 'fib';
23
- const exePath = path.join(here, 'dist', exeName);
24
-
25
- function stats(samples) {
26
- const sorted = [...samples].sort((a, b) => a - b);
27
- const mean = samples.reduce((sum, x) => sum + x, 0) / samples.length;
28
- return { min: sorted[0], median: sorted[Math.floor(sorted.length / 2)], mean, max: sorted[sorted.length - 1] };
29
- }
30
-
31
- function fmt(ms) {
32
- return `${ms.toFixed(2)} ms`.padStart(12);
33
- }
34
-
35
- function runOnce(command, args) {
36
- const t0 = performance.now();
37
- const result = spawnSync(command, args, { cwd: here, encoding: 'utf8' });
38
- const wall = performance.now() - t0;
39
- if (result.status !== 0) {
40
- console.error(`run failed: ${command} ${args.join(' ')}\n${result.stderr}`);
41
- process.exit(1);
42
- }
43
- const match = result.stdout.match(/computed in ([\d.]+) ms/);
44
- if (!match) {
45
- console.error(`unexpected output:\n${result.stdout}`);
46
- process.exit(1);
47
- }
48
- return { wall, compute: Number(match[1]) };
49
- }
50
-
51
- function measure(command, args) {
52
- const walls = [];
53
- const computes = [];
54
- for (let i = 0; i < runs; i++) {
55
- const sample = runOnce(command, args);
56
- walls.push(sample.wall);
57
- computes.push(sample.compute);
58
- }
59
- return { wall: stats(walls), compute: stats(computes) };
60
- }
61
-
62
- // 1. Compile fibonacci to a native binary.
63
- fs.mkdirSync(path.join(here, 'dist'), { recursive: true });
64
- console.log('Compiling main.ts to a native binary with TypeNative...');
65
- const build = spawnSync(process.execPath, [cli, '--source', 'main.ts', '--output', path.join('dist', exeName)], {
66
- cwd: here,
67
- stdio: 'inherit',
68
- });
69
- if (build.status !== 0) process.exit(build.status ?? 1);
70
-
71
- // 2. Run fib(n) under both runtimes.
72
- console.log(`\nComputing fib(${n}) ${runs} times per runtime...\n`);
73
- const nodeStats = measure(process.execPath, ['main.ts', String(n)]);
74
- const nativeStats = measure(exePath, [String(n)]);
75
-
76
- console.log(`Compute time, fib(${n}) over ${runs} runs (measured in-program):\n`);
77
- console.log('| Runtime | min | median | mean | max |');
78
- console.log('|------------|--------------|--------------|--------------|--------------|');
79
- console.log(`| Node.js |${fmt(nodeStats.compute.min)} |${fmt(nodeStats.compute.median)} |${fmt(nodeStats.compute.mean)} |${fmt(nodeStats.compute.max)} |`);
80
- console.log(`| TypeNative |${fmt(nativeStats.compute.min)} |${fmt(nativeStats.compute.median)} |${fmt(nativeStats.compute.mean)} |${fmt(nativeStats.compute.max)} |`);
81
- console.log(`\nTypeNative computes ${(nodeStats.compute.median / nativeStats.compute.median).toFixed(1)}x faster (median).\n`);
82
-
83
- console.log(`Total wall time per run incl. startup (spawn -> exit):\n`);
84
- console.log('| Runtime | min | median | mean | max |');
85
- console.log('|------------|--------------|--------------|--------------|--------------|');
86
- console.log(`| Node.js |${fmt(nodeStats.wall.min)} |${fmt(nodeStats.wall.median)} |${fmt(nodeStats.wall.mean)} |${fmt(nodeStats.wall.max)} |`);
87
- console.log(`| TypeNative |${fmt(nativeStats.wall.min)} |${fmt(nativeStats.wall.median)} |${fmt(nativeStats.wall.mean)} |${fmt(nativeStats.wall.max)} |`);
@@ -1,21 +0,0 @@
1
- // Naive recursive Fibonacci: the classic CPU-bound benchmark. The same source
2
- // runs unchanged under Node.js and as a compiled TypeNative binary, and times
3
- // itself with performance.now() so both runtimes are measured the same way
4
- // (compute time only, startup excluded).
5
- //
6
- // node main.ts [n] (default n = 35)
7
- // ./fib [n]
8
- import { performance } from 'node:perf_hooks';
9
-
10
- function fib(n: number): number {
11
- return n < 2 ? n : fib(n - 1) + fib(n - 2);
12
- }
13
-
14
- const n = Number(process.argv[2] ?? '35');
15
-
16
- const start = performance.now();
17
- const result = fib(n);
18
- const elapsedMs = performance.now() - start;
19
-
20
- console.log(`fib(${n}) = ${result}`);
21
- console.log(`computed in ${elapsedMs.toFixed(2)} ms`);