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.
- package/bin/node/assert.js +2 -2
- package/bin/node/child_process.js +66 -8
- package/bin/node/fs.js +1012 -4
- package/bin/node/histogram.js +1991 -0
- package/bin/node/process.js +14 -2
- package/bin/node/sqlite.js +1488 -5
- package/bin/node/stream.js +2 -1
- package/bin/node/system_extra.js +3 -270
- package/bin/node/test.js +39 -1
- package/bin/node/test_report.js +47 -1
- package/bin/node/test_run.js +57 -2
- package/bin/node/util.js +8 -5
- package/bin/node/webassembly.js +20 -5
- package/bin/node/webview.js +3257 -244
- package/bin/node/zlib.js +118 -14
- package/bin/node/zlib_iter.js +585 -0
- package/bin/transpiler.js +1370 -258
- package/bin/version.js +1 -1
- package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
- package/package.json +10 -1
- package/types/tsconfig.json +17 -0
- package/types/typenative-npm.d.ts +492 -12
- package/types/typenative.d.ts +88 -2
- package/.gitattributes +0 -1
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/npm-publish-github-packages.yml +0 -88
- package/CHANGELOG.md +0 -1746
- package/CONTRIBUTION.md +0 -133
- package/conformance.md +0 -1497
- package/examples/README.md +0 -114
- package/examples/angular-templates/README.md +0 -141
- package/examples/angular-templates/bench.mjs +0 -173
- package/examples/angular-templates/dom-type-globals.d.ts +0 -21
- package/examples/angular-templates/dom-type-stubs.ts +0 -21
- package/examples/angular-templates/main.ts +0 -135
- package/examples/angular-templates/parity.mjs +0 -157
- package/examples/angular-templates/run-node.mjs +0 -69
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
- package/examples/desktop-notes/README.md +0 -106
- package/examples/desktop-notes/bench.mjs +0 -125
- package/examples/desktop-notes/main.ts +0 -131
- package/examples/desktop-notes/package-lock.json +0 -726
- package/examples/desktop-notes/package.json +0 -9
- package/examples/desktop-notes/ui.ts +0 -176
- package/examples/dupe-finder/README.md +0 -78
- package/examples/dupe-finder/bench.mjs +0 -120
- package/examples/dupe-finder/main.ts +0 -87
- package/examples/fibonacci/README.md +0 -89
- package/examples/fibonacci/bench.mjs +0 -87
- package/examples/fibonacci/main.ts +0 -21
- package/examples/hello-world/README.md +0 -62
- package/examples/hello-world/bench.mjs +0 -66
- package/examples/hello-world/main.ts +0 -7
- package/examples/json-server/README.md +0 -132
- package/examples/json-server/bench.mjs +0 -263
- package/examples/json-server/main.ts +0 -67
- package/examples/mandelbrot-png/README.md +0 -63
- package/examples/mandelbrot-png/bench.mjs +0 -95
- package/examples/mandelbrot-png/main.ts +0 -98
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +0 -174
- package/examples/marked-cli/bench.mjs +0 -178
- package/examples/marked-cli/main.ts +0 -410
- package/examples/marked-cli/parity.mjs +0 -185
- package/examples/marked-cli/vendor/marked/LICENSE +0 -44
- package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
- package/examples/openai-chat/README.md +0 -148
- package/examples/openai-chat/bench.mjs +0 -175
- package/examples/openai-chat/main.ts +0 -488
- package/examples/react-compiler/README.md +0 -185
- package/examples/react-compiler/bench.mjs +0 -181
- package/examples/react-compiler/main.ts +0 -324
- package/examples/react-compiler/parity.mjs +0 -362
- package/examples/react-compiler/run-node.mjs +0 -90
- package/examples/react-compiler/vendor/babel/LICENSE +0 -22
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
- package/examples/react-compiler/vendor/charcodes/package.json +0 -25
- package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
- package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
- package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
- package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
- package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
- package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
- package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
- package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
- package/examples/react-compiler/vendor/zod/LICENSE +0 -21
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
- package/examples/react-compiler/vendor.mjs +0 -688
- package/examples/todo-cli/README.md +0 -69
- package/examples/todo-cli/bench.mjs +0 -89
- package/examples/todo-cli/main.ts +0 -92
- package/examples/yaml-cli/README.md +0 -152
- package/examples/yaml-cli/bench.mjs +0 -265
- package/examples/yaml-cli/main.ts +0 -251
- package/examples/yaml-cli/parity.mjs +0 -156
- package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
- package/performance/README.md +0 -248
- package/performance/any-dynamic.ts +0 -21
- package/performance/any-record-view.ts +0 -20
- package/performance/arr-for-of.ts +0 -29
- package/performance/arr-hof.ts +0 -21
- package/performance/arr-push-index.ts +0 -15
- package/performance/arr-push-local.ts +0 -39
- package/performance/arr-slice-concat.ts +0 -24
- package/performance/arr-sort.ts +0 -21
- package/performance/async-await.ts +0 -24
- package/performance/async-promise-all.ts +0 -38
- package/performance/bigint-arith.ts +0 -36
- package/performance/buf-encode.ts +0 -29
- package/performance/class-accessors.ts +0 -48
- package/performance/class-dispatch.ts +0 -52
- package/performance/date-format.ts +0 -18
- package/performance/events-emit.ts +0 -27
- package/performance/exc-throw-rare.ts +0 -25
- package/performance/exc-try-catch.ts +0 -26
- package/performance/fn-closures.ts +0 -29
- package/performance/fn-recursion-tree.ts +0 -31
- package/performance/fn-rest-spread.ts +0 -43
- package/performance/gen-for-of.ts +0 -46
- package/performance/gen-next.ts +0 -32
- package/performance/iter-helpers.ts +0 -38
- package/performance/json-any.ts +0 -30
- package/performance/json-roundtrip.ts +0 -27
- package/performance/map-delete.ts +0 -24
- package/performance/map-iterate.ts +0 -26
- package/performance/map-number-keys.ts +0 -37
- package/performance/map-string-keys.ts +0 -22
- package/performance/num-arith-loop.ts +0 -14
- package/performance/num-bitwise.ts +0 -21
- package/performance/num-hash-imul.ts +0 -36
- package/performance/num-mod-int.ts +0 -16
- package/performance/num-to-string.ts +0 -16
- package/performance/obj-alloc.ts +0 -32
- package/performance/obj-keys-entries.ts +0 -44
- package/performance/obj-optional-chain.ts +0 -42
- package/performance/obj-record-dict.ts +0 -24
- package/performance/obj-spread-destructure.ts +0 -40
- package/performance/regex-exec.ts +0 -29
- package/performance/regex-replace-fn.ts +0 -24
- package/performance/regex-site.ts +0 -28
- package/performance/set-ops.ts +0 -20
- package/performance/str-char-scan.ts +0 -35
- package/performance/str-concat-plus.ts +0 -18
- package/performance/str-concat.ts +0 -24
- package/performance/str-methods.ts +0 -24
- package/performance/str-short-scan.ts +0 -26
- package/performance/str-split-join.ts +0 -23
- package/performance/str-switch-compare.ts +0 -50
- package/performance/str-template.ts +0 -16
- package/performance/str-unicode.ts +0 -25
- package/performance/typed-array.ts +0 -30
- package/performance/union-switch.ts +0 -57
- package/performance/union-typeof.ts +0 -40
- package/performance/wasm-call.ts +0 -63
- package/tsparser/check.go +0 -158
- package/tsparser/go.mod +0 -14
- package/tsparser/go.sum +0 -22
- package/tsparser/main.go +0 -363
- package/tsparser/tsparser.exe +0 -4
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
// The `yaml` npm package's own command-line tool, compiled from its unmodified
|
|
2
|
-
// upstream TypeScript (vendor/yaml/src, see vendor/yaml/VENDOR.md). This file
|
|
3
|
-
// is a TypeScript port of upstream's bin.js: it hands stdin and the arguments
|
|
4
|
-
// to cli() and turns the error it reports into an exit code.
|
|
5
|
-
//
|
|
6
|
-
// yaml < in.yaml re-emit the YAML stream
|
|
7
|
-
// yaml --json < in.yaml print it as JSON
|
|
8
|
-
// yaml valid < in.yaml exit 1 on the first error
|
|
9
|
-
// yaml lex < in.yaml print the lexer's tokens
|
|
10
|
-
// yaml cst < in.yaml print the concrete syntax tree
|
|
11
|
-
//
|
|
12
|
-
// Runs as-is under Node.js (`node main.ts`) and compiles with TypeNative.
|
|
13
|
-
//
|
|
14
|
-
// One addition to bin.js: `yaml --json` on a large stream of documents
|
|
15
|
-
// converts runs of documents in parallel worker processes (see below). The
|
|
16
|
-
// output is the same JSON cli() prints, byte for byte.
|
|
17
|
-
import { promises } from 'node:fs';
|
|
18
|
-
import { availableParallelism, tmpdir } from 'node:os';
|
|
19
|
-
import { PassThrough } from 'node:stream';
|
|
20
|
-
import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
21
|
-
import { UserError, cli, help } from './vendor/yaml/src/cli.ts';
|
|
22
|
-
import { Composer } from './vendor/yaml/src/compose/composer.ts';
|
|
23
|
-
import type { Document } from './vendor/yaml/src/doc/Document.ts';
|
|
24
|
-
import { Pair } from './vendor/yaml/src/nodes/Pair.ts';
|
|
25
|
-
import { Scalar } from './vendor/yaml/src/nodes/Scalar.ts';
|
|
26
|
-
import { YAMLMap } from './vendor/yaml/src/nodes/YAMLMap.ts';
|
|
27
|
-
import { YAMLSeq } from './vendor/yaml/src/nodes/YAMLSeq.ts';
|
|
28
|
-
import { YAMLSet } from './vendor/yaml/src/nodes/YAMLSet.ts';
|
|
29
|
-
import { Parser } from './vendor/yaml/src/parse/parser.ts';
|
|
30
|
-
|
|
31
|
-
const { readFile, unlink, writeFile } = promises;
|
|
32
|
-
|
|
33
|
-
function done(error?: Error) {
|
|
34
|
-
if (error instanceof UserError) {
|
|
35
|
-
if (error.code === UserError.ARGS) console.error(`${help}\n`);
|
|
36
|
-
console.error(error.message);
|
|
37
|
-
process.exitCode = error.code;
|
|
38
|
-
} else if (error) {
|
|
39
|
-
// bin.js rethrows here; Node then prints the error and exits with 1
|
|
40
|
-
console.error(error);
|
|
41
|
-
process.exitCode = 1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// `yaml --json` on a large stream is split before the `---` lines that start
|
|
46
|
-
// its documents, and up to six worker processes each compose one contiguous
|
|
47
|
-
// run of documents and print it as JSON; the main process joins the arrays.
|
|
48
|
-
// A `---` at the start of a line always ends the document before it (it ends
|
|
49
|
-
// any scalar or collection still open, or that one is an error), so each
|
|
50
|
-
// run's documents are the ones the whole stream has. Only plain streams take
|
|
51
|
-
// this path: no directives (% lines, which carry over to later documents) and
|
|
52
|
-
// no CR line endings. Any error, warning, collection-valued key (its warning
|
|
53
|
-
// is printed while the JSON is made) or exception in a worker sends the whole
|
|
54
|
-
// input through cli() instead, which reports it as it always would. A run
|
|
55
|
-
// travels in workerData; its JSON comes back through a temporary file (the
|
|
56
|
-
// worker IPC carries one compact message, not megabytes).
|
|
57
|
-
const PARALLEL_MIN_BYTES = 512 * 1024;
|
|
58
|
-
|
|
59
|
-
interface ConvertJob {
|
|
60
|
-
text: string;
|
|
61
|
-
output: string;
|
|
62
|
-
indent?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// The --indent value when the arguments are just --json (and --indent):
|
|
66
|
-
// undefined for none, null when the arguments ask for anything else
|
|
67
|
-
function jsonOnlyArgs(argv: string[]): { indent?: string } | null {
|
|
68
|
-
let json = false;
|
|
69
|
-
let indent: string | undefined;
|
|
70
|
-
for (let i = 0; i < argv.length; i++) {
|
|
71
|
-
const arg = argv[i];
|
|
72
|
-
if (arg === '--json' || arg === '-j') json = true;
|
|
73
|
-
else if ((arg === '--indent' || arg === '-i') && i + 1 < argv.length && !argv[i + 1].startsWith('-')) indent = argv[++i];
|
|
74
|
-
else if (arg.startsWith('--indent=')) indent = arg.slice('--indent='.length);
|
|
75
|
-
else return null;
|
|
76
|
-
}
|
|
77
|
-
return json ? { indent } : null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function splitDocuments(data: string): string[] | undefined {
|
|
81
|
-
if (data.length < PARALLEL_MIN_BYTES || data.includes('\r')) return undefined;
|
|
82
|
-
if (data.startsWith('%') || data.includes('\n%')) return undefined;
|
|
83
|
-
const cuts: number[] = [0];
|
|
84
|
-
let at = data.indexOf('\n---');
|
|
85
|
-
while (at !== -1) {
|
|
86
|
-
const after = data.charCodeAt(at + 4);
|
|
87
|
-
// (`---` then a space, a tab, a newline or the end: a document start)
|
|
88
|
-
if (Number.isNaN(after) || after === 32 || after === 9 || after === 10) cuts.push(at + 1);
|
|
89
|
-
at = data.indexOf('\n---', at + 4);
|
|
90
|
-
}
|
|
91
|
-
if (cuts.length < 3) return undefined;
|
|
92
|
-
cuts.push(data.length);
|
|
93
|
-
const requested = Number(process.env.YAML_WORKERS ?? '0') || availableParallelism();
|
|
94
|
-
const count = Math.min(6, Math.max(1, requested), cuts.length - 1);
|
|
95
|
-
if (count < 2) return undefined;
|
|
96
|
-
// one contiguous run of documents per process, balanced by size
|
|
97
|
-
const parts: string[] = [];
|
|
98
|
-
let next = 1;
|
|
99
|
-
let start = 0;
|
|
100
|
-
for (let m = 1; m <= count; m++) {
|
|
101
|
-
const target = (data.length * m) / count;
|
|
102
|
-
while (next < cuts.length - 1 && cuts[next] < target) next++;
|
|
103
|
-
const end = m === count ? data.length : cuts[next];
|
|
104
|
-
if (end > start) parts.push(data.slice(start, end));
|
|
105
|
-
start = end;
|
|
106
|
-
}
|
|
107
|
-
return parts.length > 1 ? parts : undefined;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Whether toJS could warn on this node: a map key that is not a scalar (an
|
|
111
|
-
// alias, a collection) is stringified with a warning. (A set: assumed so.)
|
|
112
|
-
function warnsOnKeys(node: unknown): boolean {
|
|
113
|
-
if (node instanceof Pair) {
|
|
114
|
-
return (node.key !== null && !(node.key instanceof Scalar)) || warnsOnKeys(node.value);
|
|
115
|
-
}
|
|
116
|
-
if (node instanceof YAMLMap) {
|
|
117
|
-
for (const pair of node.values.values()) if (warnsOnKeys(pair)) return true;
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
if (node instanceof YAMLSeq) {
|
|
121
|
-
for (const item of node) if (warnsOnKeys(item)) return true;
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
return node instanceof YAMLSet;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function workerMain() {
|
|
128
|
-
const job = workerData as ConvertJob;
|
|
129
|
-
const text = job.text as string;
|
|
130
|
-
const output = job.output as string;
|
|
131
|
-
const indent = job.indent as string | undefined;
|
|
132
|
-
try {
|
|
133
|
-
// as cli() composes a stream: new Composer({ version: opt.yaml, merge: opt.merge })
|
|
134
|
-
const composer = new Composer({ version: '1.2', merge: undefined });
|
|
135
|
-
const parser = new Parser();
|
|
136
|
-
for (const tok of parser.parse(text)) composer.next(tok);
|
|
137
|
-
const docs: Document[] = [];
|
|
138
|
-
let clean = true;
|
|
139
|
-
for (const doc of composer.end(false)) {
|
|
140
|
-
if (doc.errors.length > 0 || doc.warnings.length > 0 || warnsOnKeys(doc.value)) clean = false;
|
|
141
|
-
docs.push(doc);
|
|
142
|
-
}
|
|
143
|
-
// (a run with no document must be all blank lines and comments: an error
|
|
144
|
-
// with no document to report it is otherwise lost)
|
|
145
|
-
if (docs.length === 0 && /^[ \t]*[^ \t\n#]/m.test(job.text)) clean = false;
|
|
146
|
-
if (clean) {
|
|
147
|
-
await writeFile(output, JSON.stringify(docs, null, Number(indent)));
|
|
148
|
-
parentPort!.postMessage('ok');
|
|
149
|
-
} else {
|
|
150
|
-
parentPort!.postMessage('fallback');
|
|
151
|
-
}
|
|
152
|
-
} catch {
|
|
153
|
-
parentPort!.postMessage('fallback');
|
|
154
|
-
}
|
|
155
|
-
parentPort!.close();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// The JSON of each run's array, as the JSON of one array of all their items
|
|
159
|
-
function joinArrays(arrays: string[]): string {
|
|
160
|
-
const items: string[] = [];
|
|
161
|
-
let separator = ',';
|
|
162
|
-
for (const json of arrays) {
|
|
163
|
-
if (json === '[]') continue;
|
|
164
|
-
if (json.startsWith('[\n')) {
|
|
165
|
-
separator = ',\n';
|
|
166
|
-
items.push(json.slice(2, -2));
|
|
167
|
-
} else {
|
|
168
|
-
items.push(json.slice(1, -1));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (items.length === 0) return '[]';
|
|
172
|
-
return separator === ',' ? '[' + items.join(',') + ']' : '[\n' + items.join(',\n') + '\n]';
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// The runs converted in workers: their JSON, or '' when a worker found
|
|
176
|
-
// something cli() has to report
|
|
177
|
-
async function convertParallel(parts: string[], indent: string | undefined): Promise<string> {
|
|
178
|
-
const base = tmpdir() + '/yaml-' + process.pid + '-' + Date.now();
|
|
179
|
-
const results: string[] = await Promise.all(parts.map((text, index) => new Promise<string>((resolve, reject) => {
|
|
180
|
-
const output = base + '-' + index + '.json';
|
|
181
|
-
const job: ConvertJob = { text, output, indent };
|
|
182
|
-
try {
|
|
183
|
-
const worker = new Worker(new URL(import.meta.url), { workerData: job });
|
|
184
|
-
worker.on('message', async (message: string) => {
|
|
185
|
-
try {
|
|
186
|
-
if (message === 'ok') {
|
|
187
|
-
const json: string = await readFile(output, 'utf8');
|
|
188
|
-
await unlink(output).catch(() => {});
|
|
189
|
-
resolve(json);
|
|
190
|
-
} else {
|
|
191
|
-
resolve('');
|
|
192
|
-
}
|
|
193
|
-
} catch (err) {
|
|
194
|
-
reject(err);
|
|
195
|
-
}
|
|
196
|
-
worker.terminate();
|
|
197
|
-
});
|
|
198
|
-
worker.on('error', (err: Error) => {
|
|
199
|
-
unlink(output).catch(() => {});
|
|
200
|
-
reject(err);
|
|
201
|
-
});
|
|
202
|
-
} catch (err) {
|
|
203
|
-
reject(err);
|
|
204
|
-
}
|
|
205
|
-
})));
|
|
206
|
-
if (results.some((json) => json === '')) return '';
|
|
207
|
-
return joinArrays(results);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function readStdin(): Promise<string> {
|
|
211
|
-
return new Promise((resolve, reject) => {
|
|
212
|
-
let source = '';
|
|
213
|
-
process.stdin.setEncoding('utf-8');
|
|
214
|
-
process.stdin.on('data', (chunk: string) => {
|
|
215
|
-
source += chunk;
|
|
216
|
-
});
|
|
217
|
-
process.stdin.on('error', (err: Error) => reject(err));
|
|
218
|
-
process.stdin.on('end', () => resolve(source));
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async function main() {
|
|
223
|
-
const argv = process.argv.slice(2);
|
|
224
|
-
const json = jsonOnlyArgs(argv);
|
|
225
|
-
if (!json) {
|
|
226
|
-
cli(process.stdin, done, argv);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const source = await readStdin();
|
|
230
|
-
const parts = splitDocuments(source);
|
|
231
|
-
if (parts) {
|
|
232
|
-
const output = await convertParallel(parts, json.indent);
|
|
233
|
-
if (output !== '') {
|
|
234
|
-
// (flushed before the process exits: a pipe gets all of it)
|
|
235
|
-
await new Promise<void>((resolve) => {
|
|
236
|
-
process.stdout.write(output + '\n', () => resolve());
|
|
237
|
-
});
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// (the input read here, replayed to cli() as its stdin)
|
|
242
|
-
const replay = new PassThrough();
|
|
243
|
-
replay.end(source);
|
|
244
|
-
cli(replay, done, argv);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (isMainThread) {
|
|
248
|
-
main();
|
|
249
|
-
} else {
|
|
250
|
-
workerMain();
|
|
251
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// Parity check: Node.js vs the TypeNative build of the yaml CLI.
|
|
2
|
-
//
|
|
3
|
-
// Fetches the yaml-test-suite (tag data-2022-01-17) into .cache/, compiles
|
|
4
|
-
// main.ts to a native binary with the TypeNative CLI from this repo checkout,
|
|
5
|
-
// then feeds every test's in.yaml to both, in each mode: default (re-emit the
|
|
6
|
-
// YAML), --json, valid and lex. stdout, stderr and the exit code must match
|
|
7
|
-
// byte for byte (stack frames aside: see withoutStackFrames). Failures are
|
|
8
|
-
// written to .cache/failures/.
|
|
9
|
-
//
|
|
10
|
-
// Usage: node parity.mjs [filter] (filter: a test id substring or a mode)
|
|
11
|
-
|
|
12
|
-
import { spawn, spawnSync } from 'node:child_process';
|
|
13
|
-
import fs from 'node:fs';
|
|
14
|
-
import os from 'node:os';
|
|
15
|
-
import path from 'node:path';
|
|
16
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
-
|
|
18
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
-
const repoRoot = path.resolve(here, '..', '..');
|
|
20
|
-
const cli = path.join(repoRoot, 'bin', 'cli.js');
|
|
21
|
-
const cache = path.join(here, '.cache');
|
|
22
|
-
const suite = path.join(cache, 'yaml-test-suite');
|
|
23
|
-
const failuresDir = path.join(cache, 'failures');
|
|
24
|
-
const exePath = path.join(cache, process.platform === 'win32' ? 'yaml.exe' : 'yaml');
|
|
25
|
-
const filter = process.argv[2] ?? '';
|
|
26
|
-
const MODES = [
|
|
27
|
-
{ name: 'default', args: [] },
|
|
28
|
-
{ name: 'json', args: ['--json'] },
|
|
29
|
-
{ name: 'valid', args: ['valid'] },
|
|
30
|
-
{ name: 'lex', args: ['lex'] }
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
function run(command, args, options = {}) {
|
|
34
|
-
const result = spawnSync(command, args, { stdio: 'inherit', ...options });
|
|
35
|
-
if (result.status !== 0) {
|
|
36
|
-
console.error(`${command} ${args.join(' ')} failed`);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// The corpus: yaml-test-suite's data branch, one directory per test (some
|
|
42
|
-
// with numbered sub-tests), each with an in.yaml
|
|
43
|
-
function fetchSuite() {
|
|
44
|
-
if (fs.existsSync(path.join(suite, '.git')) || fs.existsSync(path.join(suite, '229Q'))) return;
|
|
45
|
-
fs.mkdirSync(cache, { recursive: true });
|
|
46
|
-
console.log('Fetching yaml-test-suite data-2022-01-17 ...');
|
|
47
|
-
run('git', ['clone', '--quiet', '--depth', '1', '--branch', 'data-2022-01-17', 'https://github.com/yaml/yaml-test-suite.git', suite]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function listInputs() {
|
|
51
|
-
const inputs = [];
|
|
52
|
-
const walk = (dir, id) => {
|
|
53
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
54
|
-
if (entry.isDirectory() && entry.name !== '.git') walk(path.join(dir, entry.name), id ? `${id}-${entry.name}` : entry.name);
|
|
55
|
-
else if (entry.name === 'in.yaml') inputs.push({ id, file: path.join(dir, entry.name) });
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
walk(suite, '');
|
|
59
|
-
return inputs;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function exec(command, args, input) {
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
const p = spawn(command, args, { cwd: here, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
65
|
-
const stdout = [];
|
|
66
|
-
const stderr = [];
|
|
67
|
-
p.stdout.on('data', (d) => stdout.push(d));
|
|
68
|
-
p.stderr.on('data', (d) => stderr.push(d));
|
|
69
|
-
const timer = setTimeout(() => p.kill('SIGKILL'), 10000);
|
|
70
|
-
p.on('close', (code, signal) => {
|
|
71
|
-
clearTimeout(timer);
|
|
72
|
-
resolve({ code: signal ? signal : code, stdout: Buffer.concat(stdout), stderr: Buffer.concat(stderr) });
|
|
73
|
-
});
|
|
74
|
-
p.stdin.on('error', () => {});
|
|
75
|
-
p.stdin.end(input);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Node prints an error's stack (" at …" lines, the frames of the JS call
|
|
80
|
-
// stack); a native binary has no JS frames to show. The frames are dropped
|
|
81
|
-
// (an inspected error's own properties, which follow the last frame as " {",
|
|
82
|
-
// stay where they are); warnings' process ids differ too
|
|
83
|
-
function withoutStackFrames(buffer) {
|
|
84
|
-
const out = [];
|
|
85
|
-
for (const line of buffer.toString().split('\n')) {
|
|
86
|
-
if (/^ {4}at /.test(line)) {
|
|
87
|
-
if (line.endsWith(' {')) out[out.length - 1] += ' {';
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
// (and process warnings name the process id)
|
|
91
|
-
out.push(line.replace(/^\(node:\d+\) /, '(node) '));
|
|
92
|
-
}
|
|
93
|
-
return Buffer.from(out.join('\n'));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function sameOutput(a, b) {
|
|
97
|
-
return a.code === b.code && a.stdout.equals(b.stdout) && withoutStackFrames(a.stderr).equals(withoutStackFrames(b.stderr));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function report(failure) {
|
|
101
|
-
const { id, mode, input, node, native } = failure;
|
|
102
|
-
const text = [
|
|
103
|
-
`# ${id} (${mode})`,
|
|
104
|
-
'## input',
|
|
105
|
-
input.toString(),
|
|
106
|
-
`## node (exit ${node.code})`,
|
|
107
|
-
'### stdout', node.stdout.toString(), '### stderr', node.stderr.toString(),
|
|
108
|
-
`## native (exit ${native.code})`,
|
|
109
|
-
'### stdout', native.stdout.toString(), '### stderr', native.stderr.toString()
|
|
110
|
-
].join('\n');
|
|
111
|
-
fs.writeFileSync(path.join(failuresDir, `${id}-${mode}.txt`), text);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
fetchSuite();
|
|
115
|
-
console.log('Compiling main.ts ...');
|
|
116
|
-
run(process.execPath, [cli, '--source', path.join(here, 'main.ts'), '--output', exePath], { cwd: here });
|
|
117
|
-
|
|
118
|
-
const cases = [];
|
|
119
|
-
for (const input of listInputs()) {
|
|
120
|
-
for (const mode of MODES) {
|
|
121
|
-
if (filter && !input.id.includes(filter) && mode.name !== filter) continue;
|
|
122
|
-
cases.push({ ...input, mode });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
fs.rmSync(failuresDir, { recursive: true, force: true });
|
|
126
|
-
fs.mkdirSync(failuresDir, { recursive: true });
|
|
127
|
-
|
|
128
|
-
let next = 0;
|
|
129
|
-
let passed = 0;
|
|
130
|
-
const failed = [];
|
|
131
|
-
async function worker() {
|
|
132
|
-
while (next < cases.length) {
|
|
133
|
-
const c = cases[next++];
|
|
134
|
-
const input = fs.readFileSync(c.file);
|
|
135
|
-
const [node, native] = await Promise.all([
|
|
136
|
-
exec(process.execPath, [path.join(here, 'main.ts'), ...c.mode.args], input),
|
|
137
|
-
exec(exePath, c.mode.args, input)
|
|
138
|
-
]);
|
|
139
|
-
if (sameOutput(node, native)) passed++;
|
|
140
|
-
else {
|
|
141
|
-
failed.push(`${c.id} (${c.mode.name})`);
|
|
142
|
-
report({ id: c.id, mode: c.mode.name, input, node, native });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const workers = Math.max(2, Math.min(16, os.availableParallelism()));
|
|
147
|
-
await Promise.all(Array.from({ length: workers }, () => worker()));
|
|
148
|
-
|
|
149
|
-
const rate = cases.length ? ((100 * passed) / cases.length).toFixed(2) : '100.00';
|
|
150
|
-
console.log(`\n${passed}/${cases.length} cases match (${rate}%)`);
|
|
151
|
-
if (failed.length > 0) {
|
|
152
|
-
console.log(`${failed.length} failures (details in .cache/failures/):`);
|
|
153
|
-
for (const f of failed.slice(0, 40)) console.log(` ${f}`);
|
|
154
|
-
if (failed.length > 40) console.log(` … and ${failed.length - 40} more`);
|
|
155
|
-
process.exitCode = 1;
|
|
156
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Copyright Eemeli Aro <eemeli@gmail.com>
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
-
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
-
and this permission notice appear in all copies.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
-
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
-
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
-
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
-
THIS SOFTWARE.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Vendored: `yaml`
|
|
2
|
-
|
|
3
|
-
| | |
|
|
4
|
-
| ---------- | ----------------------------------------------------------------------------------- |
|
|
5
|
-
| Upstream | [eemeli/yaml](https://github.com/eemeli/yaml) |
|
|
6
|
-
| Tag | `v3.0.0-2` |
|
|
7
|
-
| Commit | `15aa653fa2b94c4c9041a04964e83b9d794cf345` |
|
|
8
|
-
| License | ISC ([LICENSE](LICENSE)) |
|
|
9
|
-
| Copied | `src/` and `LICENSE`, byte for byte. Upstream's tests, docs and `bin.js` aren't vendored |
|
|
10
|
-
|
|
11
|
-
`bin.js` is ported to [../../main.ts](../../main.ts) instead of vendored. It's a
|
|
12
|
-
JavaScript file that imports the built package, and main.ts makes the same
|
|
13
|
-
`cli()` call from TypeScript.
|
|
14
|
-
|
|
15
|
-
## Patches
|
|
16
|
-
|
|
17
|
-
None. `src/` is upstream's tree unmodified. To check:
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
git clone --depth 1 --branch v3.0.0-2 https://github.com/eemeli/yaml.git /tmp/yaml
|
|
21
|
-
diff -r /tmp/yaml/src src && diff /tmp/yaml/LICENSE LICENSE
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Anything in this tree that TypeNative couldn't compile was fixed in the
|
|
25
|
-
transpiler, never here. Each fix has a probe in [conformance/](../../../../conformance/).
|