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,410 +0,0 @@
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 { availableParallelism, homedir, tmpdir } from 'node:os';
25
- import { Buffer } from 'node:buffer';
26
- import { gzipSync, gunzipSync } from 'node:zlib';
27
- import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
28
- import { marked } from './vendor/marked/src/marked.ts';
29
- import type { MarkedExtension, MarkedOptions } from './vendor/marked/src/marked.ts';
30
-
31
- const { access, readFile, unlink, writeFile } = promises;
32
-
33
- const VERSION = '18.1.2';
34
-
35
- const HELP = `marked - a markdown parser
36
-
37
- Usage: marked [options] [file]
38
-
39
- -o, --output <file> write the HTML to <file> instead of stdout
40
- -i, --input <file> read the markdown from <file>
41
- -s, --string <string> parse <string> as markdown
42
- -t, --tokens print the token list as JSON instead of HTML
43
- -c, --config <file> load options and extensions from a JSON file
44
- -n, --no-clobber don't overwrite the --output file
45
- -h, --help print this help
46
- -v, --version print the version
47
-
48
- --<option> / --no-<option>
49
- set or clear any option of marked.defaults,
50
- e.g. --gfm, --no-gfm, --breaks, --pedantic
51
-
52
- With no file, --input or --string, the markdown is read from stdin.
53
- `;
54
-
55
- interface CliError {
56
- code?: string;
57
- path?: string;
58
- message: string;
59
- }
60
-
61
- // Large documents are parsed in a few processes, one contiguous run of
62
- // sections each: marked renders top-level blocks independently, so the
63
- // concatenation is the whole document's HTML (checked byte for byte by
64
- // bench.mjs). Splits happen only before a top-level ATX heading that follows
65
- // a blank line and is outside a code fence; documents with reference link
66
- // definitions, raw HTML blocks or CRLF line endings take the sequential path,
67
- // as the pieces would not stand on their own. Between the processes a section
68
- // run travels in workerData, and its HTML comes back gzipped through one small
69
- // temporary file (the worker IPC handles one compact message, not megabytes).
70
- const PARALLEL_MIN_BYTES = 512 * 1024;
71
-
72
- function splitForParallel(data: string, options: MarkedOptions): string[] | undefined {
73
- if (data.length < PARALLEL_MIN_BYTES || data.includes('\r')) return undefined;
74
- if (options.extensions || options.hooks || options.walkTokens) return undefined;
75
- // a reference definition is shared by the whole document
76
- if (/(^|\n) {0,3}\[[^\]\n]+\]:/.test(data)) return undefined;
77
- // a cut line inside one of these would not be a top-level heading
78
- if (/<(?:pre|script|style|textarea)\b/i.test(data) || data.includes('<!--') || data.includes('<?') || data.includes('<![CDATA[')) return undefined;
79
-
80
- const lines = data.split('\n');
81
- const cuts: number[] = [0];
82
- let fence = '';
83
- for (let i = 0; i < lines.length; i++) {
84
- const line = lines[i];
85
- const open = /^ {0,3}(`{3,}|~{3,})/.exec(line);
86
- if (open) {
87
- if (!fence) fence = open[1][0];
88
- else if (open[1][0] === fence) fence = '';
89
- continue;
90
- }
91
- if (fence) continue;
92
- if (i > 0 && lines[i - 1] === '' && /^#{1,6} /.test(line)) cuts.push(i);
93
- }
94
- cuts.push(lines.length);
95
- if (cuts.length < 3) return undefined;
96
-
97
- // One contiguous run of chunks per process, balanced by size
98
- const chunks: string[] = [];
99
- let total = 0;
100
- for (let i = 0; i + 1 < cuts.length; i++) {
101
- const chunk = lines.slice(cuts[i], cuts[i + 1]).join('\n');
102
- chunks.push(chunk);
103
- total += chunk.length;
104
- }
105
- const requested = Number(process.env.MARKED_WORKERS ?? '0') || availableParallelism();
106
- const count = Math.min(6, Math.max(1, requested));
107
- if (count < 2) return undefined;
108
- const parts: string[] = [];
109
- let at = 0;
110
- let size = 0;
111
- for (let m = 0; m < count && at < chunks.length; m++) {
112
- const target = total * (m + 1) / count;
113
- const start = at;
114
- while (at < chunks.length && (at === start || size < target)) {
115
- size += chunks[at].length;
116
- at++;
117
- }
118
- parts.push(chunks.slice(start, at).join('\n'));
119
- }
120
- return parts.length > 1 ? parts : undefined;
121
- }
122
-
123
- interface ParseJob {
124
- text: string;
125
- output: string;
126
- options: MarkedOptions;
127
- }
128
-
129
- async function parseHtml(data: string, options: MarkedOptions): Promise<string> {
130
- const parts = splitForParallel(data, options);
131
- if (!parts) return await marked.parse(data, options);
132
- const base = tmpdir() + '/marked-' + process.pid + '-' + Date.now();
133
- const htmls: string[] = await Promise.all(parts.map((text, index) => new Promise<string>((resolve, reject) => {
134
- const output = base + '-' + index + '.html';
135
- const cleanup = () => unlink(output).catch(() => {});
136
- (async () => {
137
- try {
138
- const worker = new Worker(new URL(import.meta.url), { workerData: { text, output, options } as ParseJob });
139
- worker.on('message', async () => {
140
- try {
141
- resolve(gunzipSync(await readFile(output)).toString('utf8'));
142
- } catch (err) {
143
- reject(err);
144
- } finally {
145
- cleanup();
146
- }
147
- worker.terminate();
148
- });
149
- worker.on('error', (err) => {
150
- cleanup();
151
- reject(err);
152
- });
153
- } catch (err) {
154
- cleanup();
155
- reject(err);
156
- }
157
- })();
158
- }))) as string[];
159
- return htmls.join('');
160
- }
161
-
162
- async function workerMain() {
163
- const job = workerData as ParseJob;
164
- const options = job.options as MarkedOptions;
165
- const text = job.text as string;
166
- const output = job.output as string;
167
- await writeFile(output, gzipSync(Buffer.from(await marked.parse(text, options), 'utf8')));
168
- parentPort!.postMessage('ok');
169
- parentPort!.close();
170
- }
171
-
172
- export async function main() {
173
- async function help() {
174
- console.log(HELP);
175
- }
176
-
177
- async function version() {
178
- console.log(VERSION);
179
- }
180
-
181
- async function start(argv: string[]) {
182
- const files: string[] = [];
183
- const options: Record<string, unknown> = {};
184
- let input: string | undefined;
185
- let output: string | undefined;
186
- let string: string | undefined;
187
- let arg: string;
188
- let tokens = false;
189
- let config: string | undefined;
190
- let opt: string;
191
- let noclobber = false;
192
-
193
- function getArg(): string {
194
- let arg = argv.shift() as string;
195
-
196
- if (arg.indexOf('--') === 0) {
197
- // e.g. --opt
198
- const parts = arg.split('=');
199
- if (parts.length > 1) {
200
- // e.g. --opt=val
201
- argv.unshift(parts.slice(1).join('='));
202
- }
203
- arg = parts[0];
204
- } else if (arg[0] === '-') {
205
- if (arg.length > 2) {
206
- // e.g. -abc
207
- argv = arg.substring(1).split('').map(function(ch) {
208
- return '-' + ch;
209
- }).concat(argv);
210
- arg = argv.shift() as string;
211
- } else {
212
- // e.g. -a
213
- }
214
- } else {
215
- // e.g. foo
216
- }
217
-
218
- return arg;
219
- }
220
-
221
- while (argv.length) {
222
- arg = getArg();
223
- switch (arg) {
224
- case '-o':
225
- case '--output':
226
- output = argv.shift();
227
- break;
228
- case '-i':
229
- case '--input':
230
- input = argv.shift();
231
- break;
232
- case '-s':
233
- case '--string':
234
- string = argv.shift();
235
- break;
236
- case '-t':
237
- case '--tokens':
238
- tokens = true;
239
- break;
240
- case '-c':
241
- case '--config':
242
- config = argv.shift();
243
- break;
244
- case '-n':
245
- case '--no-clobber':
246
- noclobber = true;
247
- break;
248
- case '-h':
249
- case '--help':
250
- return await help();
251
- case '-v':
252
- case '--version':
253
- return await version();
254
- default:
255
- if (arg.indexOf('--') === 0) {
256
- opt = camelize(arg.replace(/^--(no-)?/, ''));
257
- const defaults = marked.defaults as Record<string, unknown>;
258
- if (!(opt in defaults)) {
259
- continue;
260
- }
261
- if (arg.indexOf('--no-') === 0) {
262
- options[opt] = typeof defaults[opt] !== 'boolean'
263
- ? null
264
- : false;
265
- } else {
266
- options[opt] = typeof defaults[opt] !== 'boolean'
267
- ? argv.shift()
268
- : true;
269
- }
270
- } else {
271
- files.push(arg);
272
- }
273
- break;
274
- }
275
- }
276
-
277
- async function getData(): Promise<string> {
278
- if (string !== undefined) {
279
- return string;
280
- }
281
- if (input) {
282
- return await readFile(input, 'utf8');
283
- }
284
- if (files.length > 0) {
285
- return await readFile(files.pop() as string, 'utf8');
286
- }
287
- return await getStdin();
288
- }
289
-
290
- function resolveFile(file: string): string {
291
- return resolve(file.replace(/^~/, () => homedir()));
292
- }
293
-
294
- async function fileExists(file: string): Promise<boolean> {
295
- try {
296
- await access(resolveFile(file));
297
- return true;
298
- } catch {
299
- return false;
300
- }
301
- }
302
-
303
- async function runConfig(file: string) {
304
- const configFile = resolveFile(file);
305
- if (!configFile.endsWith('.json')) {
306
- throw Error(`Cannot load config file '${file}': only JSON config files are supported`);
307
- }
308
- let markedConfig = JSON.parse(await readFile(configFile, 'utf8'));
309
- if (markedConfig.default) {
310
- markedConfig = markedConfig.default;
311
- }
312
- marked.use(markedConfig as MarkedExtension);
313
- }
314
-
315
- const data = await getData();
316
-
317
- if (config) {
318
- if (!await fileExists(config)) {
319
- throw Error(`Cannot load config file '${config}'`);
320
- }
321
-
322
- await runConfig(config);
323
- } else {
324
- const defaultConfig = [
325
- '~/.marked.json',
326
- '~/.marked.js',
327
- '~/.marked/index.js',
328
- ];
329
-
330
- for (const configFile of defaultConfig) {
331
- if (await fileExists(configFile)) {
332
- await runConfig(configFile);
333
- break;
334
- }
335
- }
336
- }
337
-
338
- const html = tokens
339
- ? JSON.stringify(marked.lexer(data, options as MarkedOptions), null, 2)
340
- : await parseHtml(data, options as MarkedOptions);
341
-
342
- if (output) {
343
- try {
344
- return await writeFile(output, html, { flag: noclobber ? 'wx' : 'w' });
345
- } catch (err) {
346
- if (noclobber && (err as CliError).code === 'EEXIST') {
347
- throw Error('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n');
348
- }
349
- throw err;
350
- }
351
- }
352
-
353
- // (flushed before main() exits the process: bin/main.js exits right after
354
- // the write, which cuts output to a pipe off at 64 KB)
355
- await new Promise<void>((resolve) => {
356
- process.stdout.write(html + '\n', () => resolve());
357
- });
358
- }
359
-
360
- /**
361
- * Helpers
362
- */
363
- function getStdin(): Promise<string> {
364
- return new Promise((resolve, reject) => {
365
- const stdin = process.stdin;
366
- let buff = '';
367
-
368
- stdin.setEncoding('utf8');
369
-
370
- stdin.on('data', function(data: string) {
371
- buff += data;
372
- });
373
-
374
- stdin.on('error', function(err: Error) {
375
- reject(err);
376
- });
377
-
378
- stdin.on('end', function() {
379
- resolve(buff);
380
- });
381
-
382
- stdin.resume();
383
- });
384
- }
385
-
386
- function camelize(text: string): string {
387
- return text.replace(/(\w)-(\w)/g, function(_, a: string, b: string) {
388
- return a + b.toUpperCase();
389
- });
390
- }
391
-
392
- try {
393
- await start(process.argv.slice(2));
394
- process.exit(0);
395
- } catch (err) {
396
- const e = err as CliError;
397
- if (e.code === 'ENOENT') {
398
- process.stderr.write('marked: ' + e.path + ': No such file or directory');
399
- } else {
400
- process.stderr.write(e.message);
401
- }
402
- return process.exit(1);
403
- }
404
- }
405
-
406
- if (isMainThread) {
407
- main();
408
- } else {
409
- workerMain();
410
- }
@@ -1,185 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
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.
@@ -1,26 +0,0 @@
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/).