typenative 0.4.1 → 0.5.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.
- package/CHANGELOG.md +171 -0
- package/README.md +62 -22
- package/ROUND2-HANDOFF.md +200 -0
- package/bin/cli.js +1 -0
- package/bin/index.js +13 -2
- package/bin/main.js +1 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +7 -7
- package/bin/node/cluster.js +3 -3
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +1 -1
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +2 -2
- package/bin/node/events.js +3 -3
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +3 -3
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +3 -3
- package/bin/node/http2.js +3 -3
- package/bin/node/net.js +8 -8
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +34 -11
- package/bin/node/readline.js +1 -1
- package/bin/node/registry.js +4 -1
- package/bin/node/sqlite.js +6 -6
- package/bin/node/stream.js +81 -15
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +674 -366
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +4 -4
- package/bin/node/tls.js +5 -5
- package/bin/node/util.js +31 -7
- package/bin/node/util_extra.js +7 -7
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +1 -1
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +4 -0
- package/bin/transpiler.js +10390 -1178
- package/bin/version.js +1 -1
- package/conformance.md +468 -340
- package/examples/README.md +47 -10
- package/examples/desktop-notes/README.md +108 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +76 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/mandelbrot-png/README.md +65 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +159 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +136 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/tsparser/main.go +4 -0
- package/types/typenative-npm.d.ts +190 -2
- package/types/typenative.d.ts +98 -31
|
@@ -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/).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Todo CLI
|
|
2
|
+
|
|
3
|
+
A to-do list for the terminal that keeps its items in a JSON file. Tools like
|
|
4
|
+
this run dozens of times a day, sometimes from shell prompts or git hooks.
|
|
5
|
+
Each call does a little work, so most of the wait is **process startup**.
|
|
6
|
+
That's where a native binary is a big improvement.
|
|
7
|
+
|
|
8
|
+
Demonstrates: `process.argv` destructuring with a default and a rest element,
|
|
9
|
+
`node:fs` reads and atomic writes (write a temp file, then `renameSync`),
|
|
10
|
+
`os.homedir()`, `process.env`, `JSON.parse` / `JSON.stringify`, interfaces and
|
|
11
|
+
`process.exit` codes.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
todo add Buy milk # added #1: Buy milk
|
|
17
|
+
todo add Write docs # added #2: Write docs
|
|
18
|
+
todo done 1 # done #1: Buy milk
|
|
19
|
+
todo # same as `todo list`
|
|
20
|
+
# [x] 1 Buy milk
|
|
21
|
+
# [ ] 2 Write docs
|
|
22
|
+
#
|
|
23
|
+
# 1 open, 1 done
|
|
24
|
+
todo rm 2 # removed #2: Write docs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Items are stored in `~/.todo.json`. Set `TODO_FILE` to use another file.
|
|
28
|
+
|
|
29
|
+
## Run it
|
|
30
|
+
|
|
31
|
+
With Node.js:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
node main.ts add Buy milk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
With TypeNative, build a binary and put it on your `PATH`:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx typenative --source main.ts --output dist/todo.exe --release
|
|
41
|
+
./dist/todo.exe add Buy milk
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
From a checkout of this repository:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
node bin/cli.js --source examples/todo-cli/main.ts --output dist/todo.exe
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Benchmark: Node.js vs TypeNative
|
|
51
|
+
|
|
52
|
+
Reproduce with `node bench.mjs [runs=30]`. The script compiles `main.ts`, fills
|
|
53
|
+
a temp file with 50 items for each runtime, and then times **complete process
|
|
54
|
+
runs** (spawn to exit) of `todo list` and `todo add`.
|
|
55
|
+
|
|
56
|
+
**Environment:** Windows 11 Pro, AMD Ryzen 5 5500U, Node v24.19.0, Go 1.26.0,
|
|
57
|
+
TypeNative 0.4.1, default (non-`--release`) build.
|
|
58
|
+
|
|
59
|
+
| Command | Runtime | min | median | mean | max |
|
|
60
|
+
|-------------|------------|-----------|-----------|-----------|-----------|
|
|
61
|
+
| `todo list` | Node.js | 104.98 ms | 111.37 ms | 112.74 ms | 130.05 ms |
|
|
62
|
+
| `todo list` | TypeNative | 14.45 ms | 16.26 ms | 16.44 ms | 20.40 ms |
|
|
63
|
+
| `todo add` | Node.js | 105.63 ms | 112.74 ms | 113.33 ms | 133.39 ms |
|
|
64
|
+
| `todo add` | TypeNative | 15.23 ms | 16.98 ms | 17.15 ms | 23.72 ms |
|
|
65
|
+
|
|
66
|
+
**TypeNative answers each command 6.6–6.8x faster** (median). At about 16 ms,
|
|
67
|
+
a call feels instant. At about 110 ms, there's a visible pause, and it adds up
|
|
68
|
+
when the tool runs from a prompt or a hook on every keystroke or commit. The
|
|
69
|
+
binary is a single 3.8 MB file, with no Node install and no `node_modules`.
|