typenative 0.4.1 → 0.6.0

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 (270) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/npm-publish-github-packages.yml +2 -2
  3. package/CHANGELOG.md +442 -1
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +73 -25
  6. package/bin/cli.js +2 -0
  7. package/bin/index.js +75 -5
  8. package/bin/main.js +2 -0
  9. package/bin/node/assert.js +2 -2
  10. package/bin/node/async_hooks.js +1 -1
  11. package/bin/node/buffer.js +16 -5
  12. package/bin/node/child_process.js +7 -7
  13. package/bin/node/cluster.js +3 -3
  14. package/bin/node/core.js +41 -0
  15. package/bin/node/crypto_keys.js +21 -21
  16. package/bin/node/dgram.js +1 -1
  17. package/bin/node/diagnostics_channel.js +3 -3
  18. package/bin/node/dns.js +2 -2
  19. package/bin/node/events.js +18 -13
  20. package/bin/node/fetch.js +2 -2
  21. package/bin/node/fs.js +3 -3
  22. package/bin/node/fs_watch.js +5 -5
  23. package/bin/node/http.js +3 -3
  24. package/bin/node/http2.js +3 -3
  25. package/bin/node/net.js +8 -8
  26. package/bin/node/path.js +17 -3
  27. package/bin/node/process.js +47 -11
  28. package/bin/node/punycode.js +2 -2
  29. package/bin/node/readline.js +1 -1
  30. package/bin/node/registry.js +4 -1
  31. package/bin/node/sqlite.js +6 -6
  32. package/bin/node/stream.js +81 -15
  33. package/bin/node/stream_web.js +10 -10
  34. package/bin/node/system_extra.js +3 -3
  35. package/bin/node/test.js +674 -366
  36. package/bin/node/test_coverage.js +187 -0
  37. package/bin/node/test_report.js +1392 -0
  38. package/bin/node/test_run.js +575 -0
  39. package/bin/node/timers.js +8 -6
  40. package/bin/node/tls.js +5 -5
  41. package/bin/node/url.js +1 -1
  42. package/bin/node/util.js +31 -7
  43. package/bin/node/util_extra.js +7 -7
  44. package/bin/node/webview.js +654 -0
  45. package/bin/node/worker_threads.js +1 -1
  46. package/bin/node/zlib.js +3 -3
  47. package/bin/parse-node.js +6 -2
  48. package/bin/regex_vm.js +2057 -0
  49. package/bin/transpiler.js +32872 -11265
  50. package/bin/typecheck-node.js +2 -1
  51. package/bin/version.js +1 -1
  52. package/conformance.md +515 -345
  53. package/examples/README.md +71 -11
  54. package/examples/angular-templates/README.md +139 -0
  55. package/examples/angular-templates/bench.mjs +173 -0
  56. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  57. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  58. package/examples/angular-templates/main.ts +135 -0
  59. package/examples/angular-templates/parity.mjs +157 -0
  60. package/examples/angular-templates/run-node.mjs +69 -0
  61. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  62. package/examples/desktop-notes/README.md +106 -0
  63. package/examples/desktop-notes/bench.mjs +125 -0
  64. package/examples/desktop-notes/main.ts +131 -0
  65. package/examples/desktop-notes/package-lock.json +726 -0
  66. package/examples/desktop-notes/package.json +9 -0
  67. package/examples/desktop-notes/ui.ts +176 -0
  68. package/examples/dupe-finder/README.md +78 -0
  69. package/examples/dupe-finder/bench.mjs +120 -0
  70. package/examples/dupe-finder/main.ts +87 -0
  71. package/examples/fibonacci/README.md +7 -7
  72. package/examples/hello-world/README.md +6 -6
  73. package/examples/json-server/README.md +19 -18
  74. package/examples/mandelbrot-png/README.md +63 -0
  75. package/examples/mandelbrot-png/bench.mjs +95 -0
  76. package/examples/mandelbrot-png/main.ts +98 -0
  77. package/examples/mandelbrot-png/preview.png +0 -0
  78. package/examples/marked-cli/README.md +160 -0
  79. package/examples/marked-cli/bench.mjs +178 -0
  80. package/examples/marked-cli/main.ts +292 -0
  81. package/examples/marked-cli/parity.mjs +185 -0
  82. package/examples/marked-cli/vendor/marked/LICENSE +44 -0
  83. package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
  84. package/examples/openai-chat/README.md +148 -0
  85. package/examples/openai-chat/bench.mjs +175 -0
  86. package/examples/openai-chat/main.ts +488 -0
  87. package/examples/react-compiler/README.md +170 -0
  88. package/examples/react-compiler/bench.mjs +181 -0
  89. package/examples/react-compiler/main.ts +158 -0
  90. package/examples/react-compiler/parity.mjs +362 -0
  91. package/examples/react-compiler/run-node.mjs +88 -0
  92. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  93. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  94. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  95. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  96. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  97. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  98. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  99. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  100. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  101. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  102. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  103. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  104. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  105. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  106. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  107. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  108. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  109. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  110. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  111. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  112. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  113. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  114. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  115. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  116. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  117. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  118. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  119. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  120. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  121. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  145. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  146. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  147. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  148. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  149. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  150. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  151. package/examples/react-compiler/vendor.mjs +688 -0
  152. package/examples/todo-cli/README.md +69 -0
  153. package/examples/todo-cli/bench.mjs +89 -0
  154. package/examples/todo-cli/main.ts +92 -0
  155. package/examples/yaml-cli/README.md +146 -0
  156. package/examples/yaml-cli/bench.mjs +265 -0
  157. package/examples/yaml-cli/main.ts +29 -0
  158. package/examples/yaml-cli/parity.mjs +156 -0
  159. package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
  160. package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
  161. package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
  162. package/govendor/github.com/jchv/go-webview2/README.md +21 -0
  163. package/govendor/github.com/jchv/go-webview2/common.go +84 -0
  164. package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
  165. package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
  166. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
  167. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
  168. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
  169. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
  170. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
  171. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
  172. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
  173. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
  174. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
  175. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
  176. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
  177. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
  178. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
  179. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
  180. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
  181. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
  182. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
  183. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
  184. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
  185. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
  186. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
  187. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
  188. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
  189. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
  190. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
  191. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
  192. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
  193. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
  194. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
  195. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
  196. package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
  197. package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
  198. package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
  199. package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
  200. package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
  201. package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
  202. package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
  203. package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
  204. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
  205. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
  206. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
  207. package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
  208. package/govendor/github.com/jchv/go-winloader/README.md +124 -0
  209. package/govendor/github.com/jchv/go-winloader/common.go +11 -0
  210. package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
  211. package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
  212. package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
  213. package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
  214. package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
  215. package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
  216. package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
  217. package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
  218. package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
  219. package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
  220. package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
  221. package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
  222. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
  223. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
  224. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
  225. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
  226. package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
  227. package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
  228. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
  229. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
  230. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
  231. package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
  232. package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
  233. package/govendor/manifest.txt +3 -1
  234. package/package.json +8 -5
  235. package/performance/README.md +195 -0
  236. package/performance/any-dynamic.ts +21 -0
  237. package/performance/any-record-view.ts +20 -0
  238. package/performance/arr-hof.ts +21 -0
  239. package/performance/arr-push-index.ts +15 -0
  240. package/performance/arr-sort.ts +21 -0
  241. package/performance/async-await.ts +24 -0
  242. package/performance/class-dispatch.ts +52 -0
  243. package/performance/events-emit.ts +27 -0
  244. package/performance/exc-throw-rare.ts +25 -0
  245. package/performance/exc-try-catch.ts +26 -0
  246. package/performance/fn-closures.ts +29 -0
  247. package/performance/fn-recursion-tree.ts +31 -0
  248. package/performance/gen-for-of.ts +46 -0
  249. package/performance/json-roundtrip.ts +27 -0
  250. package/performance/map-delete.ts +24 -0
  251. package/performance/map-string-keys.ts +22 -0
  252. package/performance/num-arith-loop.ts +14 -0
  253. package/performance/num-bitwise.ts +21 -0
  254. package/performance/num-mod-int.ts +16 -0
  255. package/performance/num-to-string.ts +16 -0
  256. package/performance/obj-alloc.ts +32 -0
  257. package/performance/regex-exec.ts +29 -0
  258. package/performance/regex-site.ts +28 -0
  259. package/performance/set-ops.ts +20 -0
  260. package/performance/str-char-scan.ts +35 -0
  261. package/performance/str-concat-plus.ts +18 -0
  262. package/performance/str-concat.ts +24 -0
  263. package/performance/str-short-scan.ts +26 -0
  264. package/performance/str-split-join.ts +23 -0
  265. package/performance/str-template.ts +16 -0
  266. package/performance/union-switch.ts +57 -0
  267. package/tsparser/check.go +2 -1
  268. package/tsparser/main.go +5 -0
  269. package/types/typenative-npm.d.ts +193 -4
  270. package/types/typenative.d.ts +138 -41
@@ -0,0 +1,292 @@
1
+ // The `marked` package's own command-line tool, compiled from its unmodified
2
+ // upstream TypeScript (vendor/marked/src, see vendor/marked/VENDOR.md). This
3
+ // file is a TypeScript port of upstream's bin/main.js: it parses the same
4
+ // options, reads markdown from a string, a file or stdin, and prints the HTML
5
+ // (or the lexer's tokens as JSON).
6
+ //
7
+ // marked < in.md render markdown to HTML
8
+ // marked -s '*hi*' render a string
9
+ // marked -i in.md -o out.html read a file, write a file
10
+ // marked --tokens < in.md print the token list as JSON
11
+ // marked --no-gfm --pedantic any boolean option of marked.defaults
12
+ //
13
+ // Runs as-is under Node.js (`node main.ts`) and compiles with TypeNative.
14
+ //
15
+ // Differences from bin/main.js: --help prints the option summary below
16
+ // instead of opening the man page, --version prints the vendored version
17
+ // instead of reading package.json, a config file (-c, ~/.marked.json) must be
18
+ // JSON (a JavaScript config is a module Node would import and run, which a
19
+ // native binary can't), and the HTML is flushed before the process exits
20
+ // (bin/main.js exits right after writing it, cutting output to a pipe off at
21
+ // 64 KB).
22
+ import { promises } from 'node:fs';
23
+ import { resolve } from 'node:path';
24
+ import { homedir } from 'node:os';
25
+ import { marked } from './vendor/marked/src/marked.ts';
26
+ import type { MarkedExtension, MarkedOptions } from './vendor/marked/src/marked.ts';
27
+
28
+ const { access, readFile, writeFile } = promises;
29
+
30
+ const VERSION = '18.1.2';
31
+
32
+ const HELP = `marked - a markdown parser
33
+
34
+ Usage: marked [options] [file]
35
+
36
+ -o, --output <file> write the HTML to <file> instead of stdout
37
+ -i, --input <file> read the markdown from <file>
38
+ -s, --string <string> parse <string> as markdown
39
+ -t, --tokens print the token list as JSON instead of HTML
40
+ -c, --config <file> load options and extensions from a JSON file
41
+ -n, --no-clobber don't overwrite the --output file
42
+ -h, --help print this help
43
+ -v, --version print the version
44
+
45
+ --<option> / --no-<option>
46
+ set or clear any option of marked.defaults,
47
+ e.g. --gfm, --no-gfm, --breaks, --pedantic
48
+
49
+ With no file, --input or --string, the markdown is read from stdin.
50
+ `;
51
+
52
+ interface CliError {
53
+ code?: string;
54
+ path?: string;
55
+ message: string;
56
+ }
57
+
58
+ export async function main() {
59
+ async function help() {
60
+ console.log(HELP);
61
+ }
62
+
63
+ async function version() {
64
+ console.log(VERSION);
65
+ }
66
+
67
+ async function start(argv: string[]) {
68
+ const files: string[] = [];
69
+ const options: Record<string, unknown> = {};
70
+ let input: string | undefined;
71
+ let output: string | undefined;
72
+ let string: string | undefined;
73
+ let arg: string;
74
+ let tokens = false;
75
+ let config: string | undefined;
76
+ let opt: string;
77
+ let noclobber = false;
78
+
79
+ function getArg(): string {
80
+ let arg = argv.shift() as string;
81
+
82
+ if (arg.indexOf('--') === 0) {
83
+ // e.g. --opt
84
+ const parts = arg.split('=');
85
+ if (parts.length > 1) {
86
+ // e.g. --opt=val
87
+ argv.unshift(parts.slice(1).join('='));
88
+ }
89
+ arg = parts[0];
90
+ } else if (arg[0] === '-') {
91
+ if (arg.length > 2) {
92
+ // e.g. -abc
93
+ argv = arg.substring(1).split('').map(function(ch) {
94
+ return '-' + ch;
95
+ }).concat(argv);
96
+ arg = argv.shift() as string;
97
+ } else {
98
+ // e.g. -a
99
+ }
100
+ } else {
101
+ // e.g. foo
102
+ }
103
+
104
+ return arg;
105
+ }
106
+
107
+ while (argv.length) {
108
+ arg = getArg();
109
+ switch (arg) {
110
+ case '-o':
111
+ case '--output':
112
+ output = argv.shift();
113
+ break;
114
+ case '-i':
115
+ case '--input':
116
+ input = argv.shift();
117
+ break;
118
+ case '-s':
119
+ case '--string':
120
+ string = argv.shift();
121
+ break;
122
+ case '-t':
123
+ case '--tokens':
124
+ tokens = true;
125
+ break;
126
+ case '-c':
127
+ case '--config':
128
+ config = argv.shift();
129
+ break;
130
+ case '-n':
131
+ case '--no-clobber':
132
+ noclobber = true;
133
+ break;
134
+ case '-h':
135
+ case '--help':
136
+ return await help();
137
+ case '-v':
138
+ case '--version':
139
+ return await version();
140
+ default:
141
+ if (arg.indexOf('--') === 0) {
142
+ opt = camelize(arg.replace(/^--(no-)?/, ''));
143
+ const defaults = marked.defaults as Record<string, unknown>;
144
+ if (!(opt in defaults)) {
145
+ continue;
146
+ }
147
+ if (arg.indexOf('--no-') === 0) {
148
+ options[opt] = typeof defaults[opt] !== 'boolean'
149
+ ? null
150
+ : false;
151
+ } else {
152
+ options[opt] = typeof defaults[opt] !== 'boolean'
153
+ ? argv.shift()
154
+ : true;
155
+ }
156
+ } else {
157
+ files.push(arg);
158
+ }
159
+ break;
160
+ }
161
+ }
162
+
163
+ async function getData(): Promise<string> {
164
+ if (string !== undefined) {
165
+ return string;
166
+ }
167
+ if (input) {
168
+ return await readFile(input, 'utf8');
169
+ }
170
+ if (files.length > 0) {
171
+ return await readFile(files.pop() as string, 'utf8');
172
+ }
173
+ return await getStdin();
174
+ }
175
+
176
+ function resolveFile(file: string): string {
177
+ return resolve(file.replace(/^~/, () => homedir()));
178
+ }
179
+
180
+ async function fileExists(file: string): Promise<boolean> {
181
+ try {
182
+ await access(resolveFile(file));
183
+ return true;
184
+ } catch {
185
+ return false;
186
+ }
187
+ }
188
+
189
+ async function runConfig(file: string) {
190
+ const configFile = resolveFile(file);
191
+ if (!configFile.endsWith('.json')) {
192
+ throw Error(`Cannot load config file '${file}': only JSON config files are supported`);
193
+ }
194
+ let markedConfig = JSON.parse(await readFile(configFile, 'utf8'));
195
+ if (markedConfig.default) {
196
+ markedConfig = markedConfig.default;
197
+ }
198
+ marked.use(markedConfig as MarkedExtension);
199
+ }
200
+
201
+ const data = await getData();
202
+
203
+ if (config) {
204
+ if (!await fileExists(config)) {
205
+ throw Error(`Cannot load config file '${config}'`);
206
+ }
207
+
208
+ await runConfig(config);
209
+ } else {
210
+ const defaultConfig = [
211
+ '~/.marked.json',
212
+ '~/.marked.js',
213
+ '~/.marked/index.js',
214
+ ];
215
+
216
+ for (const configFile of defaultConfig) {
217
+ if (await fileExists(configFile)) {
218
+ await runConfig(configFile);
219
+ break;
220
+ }
221
+ }
222
+ }
223
+
224
+ const html = tokens
225
+ ? JSON.stringify(marked.lexer(data, options as MarkedOptions), null, 2)
226
+ : await marked.parse(data, options as MarkedOptions);
227
+
228
+ if (output) {
229
+ try {
230
+ return await writeFile(output, html, { flag: noclobber ? 'wx' : 'w' });
231
+ } catch (err) {
232
+ if (noclobber && (err as CliError).code === 'EEXIST') {
233
+ throw Error('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n');
234
+ }
235
+ throw err;
236
+ }
237
+ }
238
+
239
+ // (flushed before main() exits the process: bin/main.js exits right after
240
+ // the write, which cuts output to a pipe off at 64 KB)
241
+ await new Promise<void>((resolve) => {
242
+ process.stdout.write(html + '\n', () => resolve());
243
+ });
244
+ }
245
+
246
+ /**
247
+ * Helpers
248
+ */
249
+ function getStdin(): Promise<string> {
250
+ return new Promise((resolve, reject) => {
251
+ const stdin = process.stdin;
252
+ let buff = '';
253
+
254
+ stdin.setEncoding('utf8');
255
+
256
+ stdin.on('data', function(data: string) {
257
+ buff += data;
258
+ });
259
+
260
+ stdin.on('error', function(err: Error) {
261
+ reject(err);
262
+ });
263
+
264
+ stdin.on('end', function() {
265
+ resolve(buff);
266
+ });
267
+
268
+ stdin.resume();
269
+ });
270
+ }
271
+
272
+ function camelize(text: string): string {
273
+ return text.replace(/(\w)-(\w)/g, function(_, a: string, b: string) {
274
+ return a + b.toUpperCase();
275
+ });
276
+ }
277
+
278
+ try {
279
+ await start(process.argv.slice(2));
280
+ process.exit(0);
281
+ } catch (err) {
282
+ const e = err as CliError;
283
+ if (e.code === 'ENOENT') {
284
+ process.stderr.write('marked: ' + e.path + ': No such file or directory');
285
+ } else {
286
+ process.stderr.write(e.message);
287
+ }
288
+ return process.exit(1);
289
+ }
290
+ }
291
+
292
+ main();
@@ -0,0 +1,185 @@
1
+ // Parity check: Node.js vs the TypeNative build of the marked CLI.
2
+ //
3
+ // Fetches marked's own spec suites at the vendored tag (v18.1.2) into .cache/,
4
+ // compiles main.ts to a native binary with the TypeNative CLI from this repo
5
+ // checkout, then feeds every case's markdown on stdin to both, in each mode:
6
+ // default (GFM), --no-gfm and --tokens (the lexer's token list as JSON). A
7
+ // case's front matter (gfm / pedantic / breaks) becomes CLI flags, as marked's
8
+ // test runner turns it into options. stdout, stderr and the exit code must
9
+ // match byte for byte (stack frames aside: see withoutStackFrames). Failures
10
+ // are written to .cache/failures/.
11
+ //
12
+ // Usage: node parity.mjs [filter] (filter: a case id substring or a mode)
13
+
14
+ import { spawn, spawnSync } from 'node:child_process';
15
+ import fs from 'node:fs';
16
+ import os from 'node:os';
17
+ import path from 'node:path';
18
+ import vm from 'node:vm';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ const here = path.dirname(fileURLToPath(import.meta.url));
22
+ const repoRoot = path.resolve(here, '..', '..');
23
+ const cli = path.join(repoRoot, 'bin', 'cli.js');
24
+ const cache = path.join(here, '.cache');
25
+ const upstream = path.join(cache, 'marked-src');
26
+ const specs = path.join(upstream, 'test', 'specs');
27
+ const failuresDir = path.join(cache, 'failures');
28
+ const exePath = path.join(cache, process.platform === 'win32' ? 'marked.exe' : 'marked');
29
+ const filter = process.argv[2] ?? '';
30
+ const MODES = [
31
+ { name: 'default', args: [] },
32
+ { name: 'no-gfm', args: ['--no-gfm'] },
33
+ { name: 'tokens', args: ['--tokens'] }
34
+ ];
35
+
36
+ function run(command, args, options = {}) {
37
+ const result = spawnSync(command, args, { stdio: 'inherit', ...options });
38
+ if (result.status !== 0) {
39
+ console.error(`${command} ${args.join(' ')} failed`);
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ // The corpus: marked's spec suites (test/specs) at the vendored tag
45
+ function fetchSpecs() {
46
+ if (fs.existsSync(path.join(specs, 'commonmark'))) return;
47
+ fs.mkdirSync(cache, { recursive: true });
48
+ console.log('Fetching marked v18.1.2 test/specs ...');
49
+ run('git', ['clone', '--quiet', '--depth', '1', '--branch', 'v18.1.2', '--filter=blob:none', '--sparse', 'https://github.com/markedjs/marked.git', upstream]);
50
+ run('git', ['-C', upstream, 'sparse-checkout', 'set', 'test/specs']);
51
+ }
52
+
53
+ // Front matter (---\nkey: value\n---\n) as CLI flags; the rest is the markdown
54
+ function frontMatter(text) {
55
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(text);
56
+ if (!match) return { markdown: text, args: [] };
57
+ const args = [];
58
+ for (const line of match[1].split(/\r?\n/)) {
59
+ const [key, value] = line.split(':').map((s) => s.trim());
60
+ if (!['gfm', 'pedantic', 'breaks'].includes(key)) continue;
61
+ args.push(value === 'false' ? `--no-${key}` : `--${key}`);
62
+ }
63
+ return { markdown: text.slice(match[0].length), args };
64
+ }
65
+
66
+ function listInputs() {
67
+ const inputs = [];
68
+ for (const [dir, file] of [['commonmark', 'commonmark.0.31.2.json'], ['gfm', 'gfm.0.29.json']]) {
69
+ for (const c of JSON.parse(fs.readFileSync(path.join(specs, dir, file), 'utf8'))) {
70
+ inputs.push({ id: `${dir}-${c.example}`, markdown: c.markdown, args: [] });
71
+ }
72
+ }
73
+ for (const dir of ['new', 'original', 'redos']) {
74
+ for (const name of fs.readdirSync(path.join(specs, dir)).sort()) {
75
+ const file = path.join(specs, dir, name);
76
+ if (name.endsWith('.md')) {
77
+ inputs.push({ id: `${dir}-${name.slice(0, -3)}`, ...frontMatter(fs.readFileSync(file, 'utf8')) });
78
+ } else if (name.endsWith('.cjs')) {
79
+ // module.exports = { markdown: `…`, html: `…` }: evaluated with
80
+ // nothing but a module object in scope
81
+ const sandbox = { module: { exports: {} } };
82
+ vm.runInNewContext(fs.readFileSync(file, 'utf8'), sandbox, { filename: file, timeout: 5000 });
83
+ const { markdown } = sandbox.module.exports;
84
+ inputs.push({ id: `${dir}-${name.slice(0, -4)}`, markdown: String(markdown), args: [] });
85
+ }
86
+ }
87
+ }
88
+ return inputs;
89
+ }
90
+
91
+ function exec(command, args, input) {
92
+ return new Promise((resolve) => {
93
+ const p = spawn(command, args, { cwd: here, stdio: ['pipe', 'pipe', 'pipe'] });
94
+ const stdout = [];
95
+ const stderr = [];
96
+ p.stdout.on('data', (d) => stdout.push(d));
97
+ p.stderr.on('data', (d) => stderr.push(d));
98
+ const timer = setTimeout(() => p.kill('SIGKILL'), 10000);
99
+ p.on('close', (code, signal) => {
100
+ clearTimeout(timer);
101
+ resolve({ code: signal ? signal : code, stdout: Buffer.concat(stdout), stderr: Buffer.concat(stderr) });
102
+ });
103
+ p.stdin.on('error', () => {});
104
+ p.stdin.end(input);
105
+ });
106
+ }
107
+
108
+ // Node prints an error's stack (" at …" lines, the frames of the JS call
109
+ // stack); a native binary has no JS frames to show. The frames are dropped
110
+ // (an inspected error's own properties, which follow the last frame as " {",
111
+ // stay where they are); warnings' process ids differ too
112
+ function withoutStackFrames(buffer) {
113
+ const out = [];
114
+ for (const line of buffer.toString().split('\n')) {
115
+ if (/^ {4}at /.test(line)) {
116
+ if (line.endsWith(' {')) out[out.length - 1] += ' {';
117
+ continue;
118
+ }
119
+ // (and process warnings name the process id)
120
+ out.push(line.replace(/^\(node:\d+\) /, '(node) '));
121
+ }
122
+ return Buffer.from(out.join('\n'));
123
+ }
124
+
125
+ function sameOutput(a, b) {
126
+ return a.code === b.code && a.stdout.equals(b.stdout) && withoutStackFrames(a.stderr).equals(withoutStackFrames(b.stderr));
127
+ }
128
+
129
+ function report(failure) {
130
+ const { id, mode, input, args, node, native } = failure;
131
+ const text = [
132
+ `# ${id} (${mode}: ${args.join(' ')})`,
133
+ '## input',
134
+ input.toString(),
135
+ `## node (exit ${node.code})`,
136
+ '### stdout', node.stdout.toString(), '### stderr', node.stderr.toString(),
137
+ `## native (exit ${native.code})`,
138
+ '### stdout', native.stdout.toString(), '### stderr', native.stderr.toString()
139
+ ].join('\n');
140
+ fs.writeFileSync(path.join(failuresDir, `${id}-${mode}.txt`), text);
141
+ }
142
+
143
+ fetchSpecs();
144
+ console.log('Compiling main.ts ...');
145
+ run(process.execPath, [cli, '--source', path.join(here, 'main.ts'), '--output', exePath], { cwd: here });
146
+
147
+ const cases = [];
148
+ for (const input of listInputs()) {
149
+ for (const mode of MODES) {
150
+ if (filter && !input.id.includes(filter) && mode.name !== filter) continue;
151
+ cases.push({ ...input, mode, allArgs: [...input.args, ...mode.args] });
152
+ }
153
+ }
154
+ fs.rmSync(failuresDir, { recursive: true, force: true });
155
+ fs.mkdirSync(failuresDir, { recursive: true });
156
+
157
+ let next = 0;
158
+ let passed = 0;
159
+ const failed = [];
160
+ async function worker() {
161
+ while (next < cases.length) {
162
+ const c = cases[next++];
163
+ const input = Buffer.from(c.markdown);
164
+ const [node, native] = await Promise.all([
165
+ exec(process.execPath, [path.join(here, 'main.ts'), ...c.allArgs], input),
166
+ exec(exePath, c.allArgs, input)
167
+ ]);
168
+ if (sameOutput(node, native)) passed++;
169
+ else {
170
+ failed.push(`${c.id} (${c.mode.name})`);
171
+ report({ id: c.id, mode: c.mode.name, input, args: c.allArgs, node, native });
172
+ }
173
+ }
174
+ }
175
+ const workers = Math.max(2, Math.min(16, os.availableParallelism()));
176
+ await Promise.all(Array.from({ length: workers }, () => worker()));
177
+
178
+ const rate = cases.length ? ((100 * passed) / cases.length).toFixed(2) : '100.00';
179
+ console.log(`\n${passed}/${cases.length} cases match (${rate}%)`);
180
+ if (failed.length > 0) {
181
+ console.log(`${failed.length} failures (details in .cache/failures/):`);
182
+ for (const f of failed.slice(0, 40)) console.log(` ${f}`);
183
+ if (failed.length > 40) console.log(` … and ${failed.length - 40} more`);
184
+ process.exitCode = 1;
185
+ }
@@ -0,0 +1,44 @@
1
+ # License information
2
+
3
+ ## Contribution License Agreement
4
+
5
+ If you contribute code to this project, you are implicitly allowing your code
6
+ to be distributed under the MIT license. You are also implicitly verifying that
7
+ all code is your original work. `</legalese>`
8
+
9
+ ## Marked
10
+
11
+ Copyright (c) 2018+, MarkedJS (https://github.com/markedjs/)
12
+ Copyright (c) 2011-2018, Christopher Jeffrey (https://github.com/chjj/)
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in
22
+ all copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
+ THE SOFTWARE.
31
+
32
+ ## Markdown
33
+
34
+ Copyright © 2004, John Gruber
35
+ http://daringfireball.net/
36
+ All rights reserved.
37
+
38
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
39
+
40
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
41
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
42
+ * Neither the name “Markdown” nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
43
+
44
+ This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
@@ -0,0 +1,26 @@
1
+ # Vendored: `marked`
2
+
3
+ | | |
4
+ | ---------- | ----------------------------------------------------------------------------------- |
5
+ | Upstream | [markedjs/marked](https://github.com/markedjs/marked) |
6
+ | Tag | `v18.1.2` |
7
+ | Commit | `5beecae42b0beb07eaccc3a732560f56867a8301` |
8
+ | License | MIT ([LICENSE](LICENSE)) |
9
+ | Copied | `src/` and `LICENSE`, byte for byte. Upstream's tests, docs, man page and `bin/` aren't vendored |
10
+
11
+ `bin/main.js` is ported to [../../main.ts](../../main.ts) instead of vendored.
12
+ It's a JavaScript file that imports the built package, and main.ts parses the
13
+ same options and makes the same `marked.parse` / `marked.lexer` calls from
14
+ TypeScript (its header comment lists the differences).
15
+
16
+ ## Patches
17
+
18
+ None. `src/` is upstream's tree unmodified. To check:
19
+
20
+ ```sh
21
+ git clone --depth 1 --branch v18.1.2 https://github.com/markedjs/marked.git /tmp/marked
22
+ diff -r /tmp/marked/src src && diff /tmp/marked/LICENSE LICENSE
23
+ ```
24
+
25
+ Anything in this tree that TypeNative couldn't compile was fixed in the
26
+ transpiler, never here. Each fix has a probe in [conformance/](../../../../conformance/).