@noego/trust 0.4.0 → 0.5.0-dev.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/README.md +962 -14
- package/dist/baseline-Bkav9mS0.d.ts +380 -0
- package/dist/chunk-7PY2Q6OX.js +3016 -0
- package/dist/chunk-7PY2Q6OX.js.map +1 -0
- package/dist/chunk-UG6D3V4M.js +6990 -0
- package/dist/chunk-UG6D3V4M.js.map +1 -0
- package/dist/chunk-XXLWC5DB.js +112 -0
- package/dist/chunk-XXLWC5DB.js.map +1 -0
- package/dist/cli/index.js +1391 -65
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/wasm-worker.js +257 -0
- package/dist/cli/wasm-worker.js.map +1 -0
- package/dist/core/index.d.ts +129 -0
- package/dist/core/index.js +115 -0
- package/dist/core/index.js.map +1 -0
- package/dist/eslint/index.d.ts +77 -167
- package/dist/eslint/index.js +320 -32
- package/dist/eslint/index.js.map +1 -1
- package/dist/licenses/@jridgewell__resolve-uri/LICENSE +19 -0
- package/dist/licenses/@jridgewell__sourcemap-codec/LICENSE +19 -0
- package/dist/licenses/@jridgewell__trace-mapping/LICENSE +19 -0
- package/dist/licenses/JS-DEPENDENCIES.json +83 -0
- package/dist/licenses/balanced-match/LICENSE.md +23 -0
- package/dist/licenses/brace-expansion/LICENSE +23 -0
- package/dist/licenses/dedent-js/LICENSE +19 -0
- package/dist/licenses/minimatch/LICENSE.md +55 -0
- package/dist/licenses/scule/LICENSE +21 -0
- package/dist/licenses/svelte2tsx/LICENSE +21 -0
- package/dist/native/licenses/CARGO-DEPENDENCIES.json +479 -0
- package/dist/native/licenses/LICENSE-trust.txt +15 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-0BSD +12 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/aho-corasick-1.1.5/COPYING +3 -0
- package/dist/native/licenses/cargo/aho-corasick-1.1.5/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/autocfg-1.5.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/autocfg-1.5.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/bitflags-1.3.2/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bitflags-1.3.2/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/COPYING +8 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/bumpalo-3.20.3/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bumpalo-3.20.3/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/cfg-if-1.0.5/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/cfg-if-1.0.5/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/crc32fast-1.5.2/LICENSE-APACHE +202 -0
- package/dist/native/licenses/cargo/crc32fast-1.5.2/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/defmt-1.1.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/defmt-1.1.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/defmt-macros-1.1.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/defmt-macros-1.1.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/equivalent-1.0.2/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/equivalent-1.0.2/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/flate2-1.1.10/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/flate2-1.1.10/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/globset-0.4.20/COPYING +3 -0
- package/dist/native/licenses/cargo/globset-0.4.20/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/hashbrown-0.17.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/hashbrown-0.17.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/indexmap-2.14.0/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/indexmap-2.14.0/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/itoa-1.0.18/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/itoa-1.0.18/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/jiff-0.2.37/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-0.2.37/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-core-0.1.1/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-core-0.1.1/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-tzdb-0.1.9/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-tzdb-0.1.9/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-tzdb-platform-0.1.3/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-tzdb-platform-0.1.3/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/log-0.4.34/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/log-0.4.34/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/lzma-rust2-0.21.0/LICENSE +201 -0
- package/dist/native/licenses/cargo/memchr-2.8.2/COPYING +3 -0
- package/dist/native/licenses/cargo/memchr-2.8.2/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE +25 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-APACHE.md +177 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-MIT.md +24 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-ZLIB.md +14 -0
- package/dist/native/licenses/cargo/num-bigint-0.4.6/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-bigint-0.4.6/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/num-integer-0.1.47/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-integer-0.1.47/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/num-traits-0.2.19/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-traits-0.2.19/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/proc-macro2-1.0.107/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/proc-macro2-1.0.107/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/quote-1.0.47/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/quote-1.0.47/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/regex-automata-0.4.18/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/regex-automata-0.4.18/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/regex-syntax-0.8.11/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/regex-syntax-0.8.11/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/rustc-hash-2.1.2/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/rustc-hash-2.1.2/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/ryu-js-1.0.2/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/ryu-js-1.0.2/LICENSE-BOOST +23 -0
- package/dist/native/licenses/cargo/serde-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_core-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_core-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_derive-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_derive-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_json-1.0.152/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_json-1.0.152/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/simd-adler32-0.3.10/LICENSE.md +21 -0
- package/dist/native/licenses/cargo/smallvec-1.15.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/smallvec-1.15.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/syn-2.0.119/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/syn-2.0.119/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/syn-3.0.7/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/syn-3.0.7/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/thiserror-2.0.21/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/thiserror-2.0.21/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/thiserror-impl-2.0.21/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/thiserror-impl-2.0.21/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
- package/dist/native/licenses/cargo/xxhash-rust-0.8.15/LICENSE +23 -0
- package/dist/native/licenses/cargo/zlib-rs-0.6.8/LICENSE +19 -0
- package/dist/native/licenses/cargo/zmij-1.0.23/LICENSE-MIT +23 -0
- package/dist/native/licenses/ts-rust/LICENSE +21 -0
- package/dist/native/licenses/ts-rust/NOTICE.md +53 -0
- package/dist/native/licenses/ts-rust/licenses/Go-LICENSE.txt +27 -0
- package/dist/native/licenses/ts-rust/licenses/TypeScript-LICENSE.txt +55 -0
- package/dist/native/licenses/ts-rust/licenses/TypeScript-NOTICE.txt +405 -0
- package/dist/native/licenses/ts-rust/licenses/Unicode-LICENSE.txt +39 -0
- package/dist/native/licenses/ts-rust/licenses/vscode-languageserver-node-LICENSE.txt +18 -0
- package/dist/native/licenses/typescript/LICENSE.txt +55 -0
- package/dist/native/licenses/typescript/ThirdPartyNoticeText.txt +193 -0
- package/dist/native/licenses/typescript/manifest.json +105 -0
- package/dist/native/trust_native_wasm.wasm +0 -0
- package/dist/svelte2tsx/index.cjs +7064 -0
- package/dist/svelte2tsx/svelte-jsx-v4.d.ts +230 -0
- package/dist/svelte2tsx/svelte-jsx.d.ts +1492 -0
- package/dist/svelte2tsx/svelte-shims-v4.d.ts +290 -0
- package/dist/svelte2tsx/svelte-shims.d.ts +305 -0
- package/package.json +31 -8
- package/dist/chunk-YJYGTNJD.js +0 -2168
- package/dist/chunk-YJYGTNJD.js.map +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// src/cli/wasm-worker.js
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { parentPort, workerData } from "worker_threads";
|
|
4
|
+
var encoder = new TextEncoder();
|
|
5
|
+
var decoder = new TextDecoder();
|
|
6
|
+
var FLAG_CASE_INSENSITIVE = 1;
|
|
7
|
+
var SUCCESS = 0;
|
|
8
|
+
var EBADF = 8;
|
|
9
|
+
var ENOSYS = 52;
|
|
10
|
+
var OP_READ = 0;
|
|
11
|
+
var OP_STAT = 1;
|
|
12
|
+
var OP_READ_DIR = 2;
|
|
13
|
+
var OP_REALPATH = 3;
|
|
14
|
+
var OP_WRITE = 4;
|
|
15
|
+
var OP_APPEND = 5;
|
|
16
|
+
var OP_REMOVE = 6;
|
|
17
|
+
var OP_CHTIMES = 7;
|
|
18
|
+
var KIND_CHAR = { file: "f", directory: "d", symlink: "l", other: "o" };
|
|
19
|
+
var WasiExit = class extends Error {
|
|
20
|
+
constructor(code) {
|
|
21
|
+
super(`exit ${code}`);
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var isEngineConfig = (path) => /\/\.trust-native-\d+-\d+\.tsconfig\.json$/.test(path);
|
|
26
|
+
function hostFileSystem() {
|
|
27
|
+
const virtual = new Map(Object.entries(JSON.parse(workerData.request).virtualFiles ?? {}).map(([path, code]) => [path, encoder.encode(code)]));
|
|
28
|
+
const kind = (entry) => entry.isDirectory() ? "directory" : entry.isFile() ? "file" : entry.isSymbolicLink() ? "symlink" : "other";
|
|
29
|
+
return {
|
|
30
|
+
readFile(path) {
|
|
31
|
+
const held = virtual.get(path);
|
|
32
|
+
if (held) return held;
|
|
33
|
+
try {
|
|
34
|
+
return fs.readFileSync(path);
|
|
35
|
+
} catch {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
stat(path) {
|
|
40
|
+
const held = virtual.get(path);
|
|
41
|
+
if (held) return { isDirectory: false, isFile: true, size: held.length, mtimeNs: 0n };
|
|
42
|
+
try {
|
|
43
|
+
const stat = fs.statSync(path, { bigint: true });
|
|
44
|
+
return { isDirectory: stat.isDirectory(), isFile: stat.isFile(), size: Number(stat.size), mtimeNs: stat.mtimeNs };
|
|
45
|
+
} catch {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
readDirectory(path) {
|
|
50
|
+
try {
|
|
51
|
+
const entries = fs.readdirSync(path, { withFileTypes: true }).map((entry) => ({ name: entry.name, kind: kind(entry) }));
|
|
52
|
+
const prefix = path.replace(/\/$/, "") + "/";
|
|
53
|
+
for (const file of virtual.keys()) {
|
|
54
|
+
if (!file.startsWith(prefix)) continue;
|
|
55
|
+
const rest = file.slice(prefix.length);
|
|
56
|
+
const name = rest.split("/")[0];
|
|
57
|
+
if (!entries.some((entry) => entry.name === name)) entries.push({ name, kind: rest.includes("/") ? "directory" : "file" });
|
|
58
|
+
}
|
|
59
|
+
return entries;
|
|
60
|
+
} catch {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
realpath(path) {
|
|
65
|
+
if (virtual.has(path)) return path;
|
|
66
|
+
try {
|
|
67
|
+
return fs.realpathSync.native(path).replaceAll("\\", "/");
|
|
68
|
+
} catch {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
writeFile(path, data, append) {
|
|
73
|
+
if (!isEngineConfig(path)) return `open ${path}: read-only file system`;
|
|
74
|
+
const bytes = new Uint8Array(data);
|
|
75
|
+
const previous = append ? virtual.get(path) : void 0;
|
|
76
|
+
if (previous) {
|
|
77
|
+
const joined = new Uint8Array(previous.length + bytes.length);
|
|
78
|
+
joined.set(previous);
|
|
79
|
+
joined.set(bytes, previous.length);
|
|
80
|
+
virtual.set(path, joined);
|
|
81
|
+
} else {
|
|
82
|
+
virtual.set(path, bytes);
|
|
83
|
+
}
|
|
84
|
+
return void 0;
|
|
85
|
+
},
|
|
86
|
+
remove(path) {
|
|
87
|
+
if (!virtual.delete(path)) return `remove ${path}: read-only file system`;
|
|
88
|
+
return void 0;
|
|
89
|
+
},
|
|
90
|
+
chtimes() {
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function caseInsensitive() {
|
|
96
|
+
const swapped = process.execPath.replace(/\w/g, (c) => c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase());
|
|
97
|
+
return swapped !== process.execPath && fs.existsSync(swapped);
|
|
98
|
+
}
|
|
99
|
+
function writeResult(result) {
|
|
100
|
+
if (typeof result === "string") return { error: result };
|
|
101
|
+
return new Uint8Array();
|
|
102
|
+
}
|
|
103
|
+
function fsCall(host, op, request2) {
|
|
104
|
+
const text2 = decoder.decode(request2);
|
|
105
|
+
switch (op) {
|
|
106
|
+
case OP_READ: {
|
|
107
|
+
const data = host.readFile(text2);
|
|
108
|
+
if (data === void 0) return void 0;
|
|
109
|
+
return typeof data === "string" ? encoder.encode(data) : data;
|
|
110
|
+
}
|
|
111
|
+
case OP_STAT: {
|
|
112
|
+
const stat = host.stat(text2);
|
|
113
|
+
if (!stat) return void 0;
|
|
114
|
+
const kind = stat.isDirectory ? "d" : stat.isFile === false ? "o" : "f";
|
|
115
|
+
return encoder.encode(`${kind} ${stat.size ?? 0} ${stat.mtimeNs ?? 0n}`);
|
|
116
|
+
}
|
|
117
|
+
case OP_READ_DIR: {
|
|
118
|
+
const entries = host.readDirectory(text2);
|
|
119
|
+
if (!entries) return void 0;
|
|
120
|
+
return encoder.encode(entries.map((e) => `${KIND_CHAR[e.kind] ?? "o"}${e.name}\0`).join(""));
|
|
121
|
+
}
|
|
122
|
+
case OP_REALPATH: {
|
|
123
|
+
const real = host.realpath(text2);
|
|
124
|
+
return real === void 0 ? void 0 : encoder.encode(real);
|
|
125
|
+
}
|
|
126
|
+
case OP_WRITE:
|
|
127
|
+
case OP_APPEND: {
|
|
128
|
+
const nul = request2.indexOf(0);
|
|
129
|
+
const path = decoder.decode(request2.subarray(0, nul));
|
|
130
|
+
return writeResult(host.writeFile(path, request2.subarray(nul + 1), op === OP_APPEND));
|
|
131
|
+
}
|
|
132
|
+
case OP_REMOVE:
|
|
133
|
+
return writeResult(host.remove(text2));
|
|
134
|
+
case OP_CHTIMES:
|
|
135
|
+
return writeResult(host.chtimes());
|
|
136
|
+
default:
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function prepareRun(module, { host, stdout, stderr }) {
|
|
141
|
+
let memory;
|
|
142
|
+
let staged;
|
|
143
|
+
const u8 = () => new Uint8Array(memory.buffer);
|
|
144
|
+
const dv = () => new DataView(memory.buffer);
|
|
145
|
+
const sizes = (list, countPtr, sizePtr) => {
|
|
146
|
+
dv().setUint32(countPtr, list.length, true);
|
|
147
|
+
dv().setUint32(sizePtr, 0, true);
|
|
148
|
+
return SUCCESS;
|
|
149
|
+
};
|
|
150
|
+
const wasi = {
|
|
151
|
+
args_sizes_get: (countPtr, sizePtr) => sizes([], countPtr, sizePtr),
|
|
152
|
+
args_get: () => SUCCESS,
|
|
153
|
+
environ_sizes_get: (countPtr, sizePtr) => sizes([], countPtr, sizePtr),
|
|
154
|
+
environ_get: () => SUCCESS,
|
|
155
|
+
clock_time_get: (id, _precision, out) => {
|
|
156
|
+
const ms = id === 0 ? performance.timeOrigin + performance.now() : performance.now();
|
|
157
|
+
dv().setBigUint64(out, BigInt(Math.round(ms * 1e6)), true);
|
|
158
|
+
return SUCCESS;
|
|
159
|
+
},
|
|
160
|
+
clock_res_get: (_id, out) => {
|
|
161
|
+
dv().setBigUint64(out, 1000n, true);
|
|
162
|
+
return SUCCESS;
|
|
163
|
+
},
|
|
164
|
+
random_get: (buf, len) => {
|
|
165
|
+
for (let at = 0; at < len; at += 65536) {
|
|
166
|
+
crypto.getRandomValues(u8().subarray(buf + at, buf + Math.min(len, at + 65536)));
|
|
167
|
+
}
|
|
168
|
+
return SUCCESS;
|
|
169
|
+
},
|
|
170
|
+
fd_write: (fd, iovs, iovsLen, nwritten) => {
|
|
171
|
+
if (fd !== 1 && fd !== 2) return EBADF;
|
|
172
|
+
const view = dv();
|
|
173
|
+
let total = 0;
|
|
174
|
+
for (let i = 0; i < iovsLen; i++) {
|
|
175
|
+
const ptr = view.getUint32(iovs + i * 8, true);
|
|
176
|
+
const len = view.getUint32(iovs + i * 8 + 4, true);
|
|
177
|
+
const chunk = u8().slice(ptr, ptr + len);
|
|
178
|
+
(fd === 1 ? stdout : stderr)(chunk);
|
|
179
|
+
total += len;
|
|
180
|
+
}
|
|
181
|
+
view.setUint32(nwritten, total, true);
|
|
182
|
+
return SUCCESS;
|
|
183
|
+
},
|
|
184
|
+
fd_fdstat_get: (fd, out) => {
|
|
185
|
+
if (fd > 2) return EBADF;
|
|
186
|
+
u8().fill(0, out, out + 24);
|
|
187
|
+
return SUCCESS;
|
|
188
|
+
},
|
|
189
|
+
fd_prestat_get: () => EBADF,
|
|
190
|
+
proc_exit: (code) => {
|
|
191
|
+
throw new WasiExit(code);
|
|
192
|
+
},
|
|
193
|
+
sched_yield: () => SUCCESS,
|
|
194
|
+
poll_oneoff: (_in, _out, _n, nevents) => {
|
|
195
|
+
dv().setUint32(nevents, 0, true);
|
|
196
|
+
return SUCCESS;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const imports = { wasi_snapshot_preview1: {}, ts_host: {} };
|
|
200
|
+
for (const { module: name, name: field } of WebAssembly.Module.imports(module)) {
|
|
201
|
+
if (name === "wasi_snapshot_preview1") imports[name][field] = wasi[field] ?? (() => ENOSYS);
|
|
202
|
+
}
|
|
203
|
+
imports.ts_host.fs = (op, ptr, len) => {
|
|
204
|
+
const result = fsCall(host, op, u8().slice(ptr, ptr + len));
|
|
205
|
+
if (result === void 0) return -1;
|
|
206
|
+
if (result.error !== void 0) {
|
|
207
|
+
staged = encoder.encode(result.error);
|
|
208
|
+
return -2 - staged.length;
|
|
209
|
+
}
|
|
210
|
+
staged = result;
|
|
211
|
+
return staged.length;
|
|
212
|
+
};
|
|
213
|
+
imports.ts_host.fs_take = (ptr) => {
|
|
214
|
+
u8().set(staged, ptr);
|
|
215
|
+
staged = void 0;
|
|
216
|
+
};
|
|
217
|
+
let exports;
|
|
218
|
+
return {
|
|
219
|
+
imports,
|
|
220
|
+
/** Writes the request into `instance` and runs it; returns the module's status. */
|
|
221
|
+
run(instance, flags, request2) {
|
|
222
|
+
exports = instance.exports;
|
|
223
|
+
memory = exports.memory;
|
|
224
|
+
const bytes = encoder.encode(`${flags}\0${request2}`);
|
|
225
|
+
const at = exports.trust_input(bytes.length);
|
|
226
|
+
u8().set(bytes, at);
|
|
227
|
+
return exports.trust_run();
|
|
228
|
+
},
|
|
229
|
+
/** The reply of the last run as text. */
|
|
230
|
+
output() {
|
|
231
|
+
const ptr = exports.trust_output();
|
|
232
|
+
const len = exports.trust_output_len();
|
|
233
|
+
return decoder.decode(u8().subarray(ptr, ptr + len));
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
var { wasmPath, request } = workerData;
|
|
238
|
+
var stdoutChunks = [];
|
|
239
|
+
var stderrChunks = [];
|
|
240
|
+
var text = (chunks) => Buffer.concat(chunks).toString();
|
|
241
|
+
try {
|
|
242
|
+
const module = await WebAssembly.compile(fs.readFileSync(wasmPath));
|
|
243
|
+
const run = prepareRun(module, { host: hostFileSystem(), stdout: (chunk) => stdoutChunks.push(chunk), stderr: (chunk) => stderrChunks.push(chunk) });
|
|
244
|
+
const instance = new WebAssembly.Instance(module, run.imports);
|
|
245
|
+
const flags = caseInsensitive() ? FLAG_CASE_INSENSITIVE : 0;
|
|
246
|
+
let status;
|
|
247
|
+
try {
|
|
248
|
+
status = run.run(instance, flags, request);
|
|
249
|
+
} catch (thrown) {
|
|
250
|
+
if (!(thrown instanceof WasiExit)) throw thrown;
|
|
251
|
+
status = thrown.code;
|
|
252
|
+
}
|
|
253
|
+
parentPort.postMessage({ status, output: status === 0 ? run.output() : text(stderrChunks) || run.output(), stdout: text(stdoutChunks), stderr: text(stderrChunks) });
|
|
254
|
+
} catch (error) {
|
|
255
|
+
parentPort.postMessage({ status: -1, output: `${error instanceof Error ? error.message : String(error)}`, stdout: text(stdoutChunks), stderr: text(stderrChunks) });
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=wasm-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/wasm-worker.js"],"sourcesContent":["// The Wasm fallback of `trust check` (native-check.ts). It instantiates native/wasm,\n// serves module file reads, and posts the engine response back. Programs are constructed in memory.\n// A worker is used because the checker recurses deeply and a worker can have a large stack\n// (`stackSizeMb`); the main thread's is about 1 MB. Plain JavaScript with only Node built-ins, so the same\n// file runs from src/ (vitest) and from dist/.\n//\n// The WASI preview1 shim and the host file-system bridge are adapted from ts-rust's npm/wasm/core.js and\n// node-run.js (https://github.com/pingdotgg/ts-rust, MIT AND Apache-2.0); native/wasm/src/host.rs is the\n// module side of the bridge.\nimport * as fs from 'node:fs';\nimport { parentPort, workerData } from 'node:worker_threads';\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\n// native/wasm/src/lib.rs FLAG_* bits.\nconst FLAG_CASE_INSENSITIVE = 1;\n\n// WASI errno values.\nconst SUCCESS = 0;\nconst EBADF = 8;\nconst ENOSYS = 52;\n\n// native/wasm/src/host.rs `Op`.\nconst OP_READ = 0;\nconst OP_STAT = 1;\nconst OP_READ_DIR = 2;\nconst OP_REALPATH = 3;\nconst OP_WRITE = 4;\nconst OP_APPEND = 5;\nconst OP_REMOVE = 6;\nconst OP_CHTIMES = 7;\n\nconst KIND_CHAR = { file: 'f', directory: 'd', symlink: 'l', other: 'o' };\n\n/** Thrown by the WASI `proc_exit` import to end a run. */\nclass WasiExit extends Error {\n constructor(code) {\n super(`exit ${code}`);\n this.code = code;\n }\n}\n\n/** The engine writes exactly one kind of file: its per-group tsconfig (src/lib.rs `write_root_config`). */\nconst isEngineConfig = (path) => /\\/\\.trust-native-\\d+-\\d+\\.tsconfig\\.json$/.test(path);\n\n/**\n * The real file system through node:fs, read-only, with the engine's temporary tsconfigs held in memory:\n * the module \"writes\" them, reads them back, and \"removes\" them without touching the disk.\n */\nfunction hostFileSystem() {\n const virtual = new Map(Object.entries(JSON.parse(workerData.request).virtualFiles ?? {}).map(([path, code]) => [path, encoder.encode(code)]));\n const kind = (entry) => (entry.isDirectory() ? 'directory' : entry.isFile() ? 'file' : entry.isSymbolicLink() ? 'symlink' : 'other');\n return {\n readFile(path) {\n const held = virtual.get(path);\n if (held) return held;\n try {\n return fs.readFileSync(path);\n } catch {\n return undefined;\n }\n },\n stat(path) {\n const held = virtual.get(path);\n if (held) return { isDirectory: false, isFile: true, size: held.length, mtimeNs: 0n };\n try {\n const stat = fs.statSync(path, { bigint: true });\n return { isDirectory: stat.isDirectory(), isFile: stat.isFile(), size: Number(stat.size), mtimeNs: stat.mtimeNs };\n } catch {\n return undefined;\n }\n },\n readDirectory(path) {\n try {\n const entries = fs.readdirSync(path, { withFileTypes: true }).map((entry) => ({ name: entry.name, kind: kind(entry) }));\n const prefix = path.replace(/\\/$/, '') + '/';\n for (const file of virtual.keys()) {\n if (!file.startsWith(prefix)) continue;\n const rest = file.slice(prefix.length);\n const name = rest.split('/')[0];\n if (!entries.some(entry => entry.name === name)) entries.push({ name, kind: rest.includes('/') ? 'directory' : 'file' });\n }\n return entries;\n } catch {\n return undefined;\n }\n },\n realpath(path) {\n if (virtual.has(path)) return path;\n try {\n return fs.realpathSync.native(path).replaceAll('\\\\', '/');\n } catch {\n return undefined;\n }\n },\n writeFile(path, data, append) {\n if (!isEngineConfig(path)) return `open ${path}: read-only file system`;\n // A copy: `data` is a view of the module's memory, which grows (and detaches the view) as it runs.\n const bytes = new Uint8Array(data);\n const previous = append ? virtual.get(path) : undefined;\n if (previous) {\n const joined = new Uint8Array(previous.length + bytes.length);\n joined.set(previous);\n joined.set(bytes, previous.length);\n virtual.set(path, joined);\n } else {\n virtual.set(path, bytes);\n }\n return undefined;\n },\n remove(path) {\n if (!virtual.delete(path)) return `remove ${path}: read-only file system`;\n return undefined;\n },\n chtimes() {\n return undefined;\n },\n };\n}\n\n/** Go's osvfs check: the file system ignores case when the executable is also found with its case swapped. */\nfunction caseInsensitive() {\n const swapped = process.execPath.replace(/\\w/g, (c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()));\n return swapped !== process.execPath && fs.existsSync(swapped);\n}\n\n/** The result of a host write method: undefined when it worked, or a string with the error text. */\nfunction writeResult(result) {\n if (typeof result === 'string') return { error: result };\n return new Uint8Array();\n}\n\n/** Runs one host file operation of host.rs on `host`: the result bytes, undefined on failure, or `{ error }`. */\nfunction fsCall(host, op, request) {\n const text = decoder.decode(request);\n switch (op) {\n case OP_READ: {\n const data = host.readFile(text);\n if (data === undefined) return undefined;\n return typeof data === 'string' ? encoder.encode(data) : data;\n }\n case OP_STAT: {\n const stat = host.stat(text);\n if (!stat) return undefined;\n const kind = stat.isDirectory ? 'd' : stat.isFile === false ? 'o' : 'f';\n return encoder.encode(`${kind} ${stat.size ?? 0} ${stat.mtimeNs ?? 0n}`);\n }\n case OP_READ_DIR: {\n const entries = host.readDirectory(text);\n if (!entries) return undefined;\n return encoder.encode(entries.map((e) => `${KIND_CHAR[e.kind] ?? 'o'}${e.name}\\0`).join(''));\n }\n case OP_REALPATH: {\n const real = host.realpath(text);\n return real === undefined ? undefined : encoder.encode(real);\n }\n case OP_WRITE:\n case OP_APPEND: {\n const nul = request.indexOf(0);\n const path = decoder.decode(request.subarray(0, nul));\n return writeResult(host.writeFile(path, request.subarray(nul + 1), op === OP_APPEND));\n }\n case OP_REMOVE:\n return writeResult(host.remove(text));\n case OP_CHTIMES:\n return writeResult(host.chtimes());\n default:\n return undefined;\n }\n}\n\n/** The imports of one run and the calls into the instance. */\nfunction prepareRun(module, { host, stdout, stderr }) {\n let memory;\n let staged;\n const u8 = () => new Uint8Array(memory.buffer);\n const dv = () => new DataView(memory.buffer);\n const sizes = (list, countPtr, sizePtr) => {\n dv().setUint32(countPtr, list.length, true);\n dv().setUint32(sizePtr, 0, true);\n return SUCCESS;\n };\n const wasi = {\n args_sizes_get: (countPtr, sizePtr) => sizes([], countPtr, sizePtr),\n args_get: () => SUCCESS,\n environ_sizes_get: (countPtr, sizePtr) => sizes([], countPtr, sizePtr),\n environ_get: () => SUCCESS,\n clock_time_get: (id, _precision, out) => {\n const ms = id === 0 ? performance.timeOrigin + performance.now() : performance.now();\n dv().setBigUint64(out, BigInt(Math.round(ms * 1e6)), true);\n return SUCCESS;\n },\n clock_res_get: (_id, out) => {\n dv().setBigUint64(out, 1000n, true);\n return SUCCESS;\n },\n random_get: (buf, len) => {\n for (let at = 0; at < len; at += 65536) {\n crypto.getRandomValues(u8().subarray(buf + at, buf + Math.min(len, at + 65536)));\n }\n return SUCCESS;\n },\n fd_write: (fd, iovs, iovsLen, nwritten) => {\n if (fd !== 1 && fd !== 2) return EBADF;\n const view = dv();\n let total = 0;\n for (let i = 0; i < iovsLen; i++) {\n const ptr = view.getUint32(iovs + i * 8, true);\n const len = view.getUint32(iovs + i * 8 + 4, true);\n const chunk = u8().slice(ptr, ptr + len);\n (fd === 1 ? stdout : stderr)(chunk);\n total += len;\n }\n view.setUint32(nwritten, total, true);\n return SUCCESS;\n },\n fd_fdstat_get: (fd, out) => {\n if (fd > 2) return EBADF;\n u8().fill(0, out, out + 24);\n return SUCCESS;\n },\n fd_prestat_get: () => EBADF,\n proc_exit: (code) => {\n throw new WasiExit(code);\n },\n sched_yield: () => SUCCESS,\n poll_oneoff: (_in, _out, _n, nevents) => {\n dv().setUint32(nevents, 0, true);\n return SUCCESS;\n },\n };\n const imports = { wasi_snapshot_preview1: {}, ts_host: {} };\n for (const { module: name, name: field } of WebAssembly.Module.imports(module)) {\n if (name === 'wasi_snapshot_preview1') imports[name][field] = wasi[field] ?? (() => ENOSYS);\n }\n imports.ts_host.fs = (op, ptr, len) => {\n const result = fsCall(host, op, u8().slice(ptr, ptr + len));\n if (result === undefined) return -1;\n if (result.error !== undefined) {\n staged = encoder.encode(result.error);\n return -2 - staged.length;\n }\n staged = result;\n return staged.length;\n };\n imports.ts_host.fs_take = (ptr) => {\n u8().set(staged, ptr);\n staged = undefined;\n };\n let exports;\n return {\n imports,\n /** Writes the request into `instance` and runs it; returns the module's status. */\n run(instance, flags, request) {\n exports = instance.exports;\n memory = exports.memory;\n const bytes = encoder.encode(`${flags}\\0${request}`);\n // The view comes after the call: `trust_input` grows the memory for a large request, which\n // detaches every earlier view of it.\n const at = exports.trust_input(bytes.length);\n u8().set(bytes, at);\n return exports.trust_run();\n },\n /** The reply of the last run as text. */\n output() {\n const ptr = exports.trust_output();\n const len = exports.trust_output_len();\n return decoder.decode(u8().subarray(ptr, ptr + len));\n },\n };\n}\n\nconst { wasmPath, request } = workerData;\nconst stdoutChunks = [];\nconst stderrChunks = [];\nconst text = (chunks) => Buffer.concat(chunks).toString();\ntry {\n const module = await WebAssembly.compile(fs.readFileSync(wasmPath));\n const run = prepareRun(module, { host: hostFileSystem(), stdout: (chunk) => stdoutChunks.push(chunk), stderr: (chunk) => stderrChunks.push(chunk) });\n const instance = new WebAssembly.Instance(module, run.imports);\n const flags = caseInsensitive() ? FLAG_CASE_INSENSITIVE : 0;\n let status;\n try {\n status = run.run(instance, flags, request);\n } catch (thrown) {\n if (!(thrown instanceof WasiExit)) throw thrown;\n status = thrown.code;\n }\n parentPort.postMessage({ status, output: status === 0 ? run.output() : text(stderrChunks) || run.output(), stdout: text(stdoutChunks), stderr: text(stderrChunks) });\n} catch (error) {\n parentPort.postMessage({ status: -1, output: `${error instanceof Error ? error.message : String(error)}`, stdout: text(stdoutChunks), stderr: text(stderrChunks) });\n}\n"],"mappings":";AASA,YAAY,QAAQ;AACpB,SAAS,YAAY,kBAAkB;AAEvC,IAAM,UAAU,IAAI,YAAY;AAChC,IAAM,UAAU,IAAI,YAAY;AAGhC,IAAM,wBAAwB;AAG9B,IAAM,UAAU;AAChB,IAAM,QAAQ;AACd,IAAM,SAAS;AAGf,IAAM,UAAU;AAChB,IAAM,UAAU;AAChB,IAAM,cAAc;AACpB,IAAM,cAAc;AACpB,IAAM,WAAW;AACjB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,aAAa;AAEnB,IAAM,YAAY,EAAE,MAAM,KAAK,WAAW,KAAK,SAAS,KAAK,OAAO,IAAI;AAGxE,IAAM,WAAN,cAAuB,MAAM;AAAA,EAC3B,YAAY,MAAM;AAChB,UAAM,QAAQ,IAAI,EAAE;AACpB,SAAK,OAAO;AAAA,EACd;AACF;AAGA,IAAM,iBAAiB,CAAC,SAAS,4CAA4C,KAAK,IAAI;AAMtF,SAAS,iBAAiB;AACxB,QAAM,UAAU,IAAI,IAAI,OAAO,QAAQ,KAAK,MAAM,WAAW,OAAO,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,QAAQ,OAAO,IAAI,CAAC,CAAC,CAAC;AAC7I,QAAM,OAAO,CAAC,UAAW,MAAM,YAAY,IAAI,cAAc,MAAM,OAAO,IAAI,SAAS,MAAM,eAAe,IAAI,YAAY;AAC5H,SAAO;AAAA,IACL,SAAS,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iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,IAAI,QAAQ,KAAK,YAAY,GAAG,QAAQ,KAAK,YAAY,EAAE,CAAC;AACpK;","names":["request","text"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { T as TypeScript, a as TsconfigMapping, Z as ZoneGroup, F as Finding } from '../baseline-Bkav9mS0.js';
|
|
2
|
+
export { B as BaselineCounts, b as BaselineDelta, c as BaselineFinding, d as BaselineScope, e as LineDirective, W as WHOLE_BASELINE, f as Zone, g as Zones, h as compareToBaseline, i as countFindings, j as describeBaselineDelta, k as directiveDirectlyAbove, l as directiveReason, m as groupMatches, n as isNamedDirective, o as lineDirectivesIn, p as loadTypeScript, q as matchesPatterns, r as nearestPackageName, s as nodeBelow, t as normalizePattern, u as parseBaseline, v as readBaseline, w as realpathOrSelf, x as relativeInside, y as serializeBaseline, z as toPosix, A as updateBaseline } from '../baseline-Bkav9mS0.js';
|
|
3
|
+
import * as TS from 'typescript';
|
|
4
|
+
|
|
5
|
+
/** Absolute paths, sorted and deduplicated: named files as-is, directories walked for .ts/.tsx. */
|
|
6
|
+
declare function resolveFiles(cwd: string, paths: readonly string[]): {
|
|
7
|
+
files: string[];
|
|
8
|
+
} | {
|
|
9
|
+
missing: string;
|
|
10
|
+
};
|
|
11
|
+
declare function relativeTo(rootDir: string, file: string): string;
|
|
12
|
+
interface LoadedFile {
|
|
13
|
+
readonly ts: TypeScript;
|
|
14
|
+
readonly program: TS.Program;
|
|
15
|
+
readonly sourceFile: TS.SourceFile;
|
|
16
|
+
/** Absolute path as resolved from the command line. */
|
|
17
|
+
readonly file: string;
|
|
18
|
+
}
|
|
19
|
+
type ProgramWalk = {
|
|
20
|
+
readonly status: 'ok';
|
|
21
|
+
}
|
|
22
|
+
/** TypeScript could not be resolved, a tsconfig could not be read, or a mapped tsconfig is missing. */
|
|
23
|
+
| {
|
|
24
|
+
readonly status: 'setup-failed';
|
|
25
|
+
readonly message: string;
|
|
26
|
+
}
|
|
27
|
+
/** Files no program could load, or with syntax errors. */
|
|
28
|
+
| {
|
|
29
|
+
readonly status: 'file-errors';
|
|
30
|
+
readonly errors: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
/** Which tsconfig compiles each file: `tsconfig` (relative to cwd) for all, else `mappings`, else the nearest one. */
|
|
33
|
+
interface ProgramOptions {
|
|
34
|
+
readonly tsconfig: string | undefined;
|
|
35
|
+
readonly mappings: readonly TsconfigMapping[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds one program per owning tsconfig and calls `visit` for every file that loads and parses.
|
|
39
|
+
* Files with errors are collected instead; callers must not trust findings when the walk is not ok.
|
|
40
|
+
*/
|
|
41
|
+
declare function forEachSourceFile(cwd: string, files: readonly string[], programs: ProgramOptions, visit: (loaded: LoadedFile) => void): ProgramWalk;
|
|
42
|
+
/** Why the walk failed, as lines headed by `label` (`trust check`, `ioc check`); at most 50 file errors. */
|
|
43
|
+
declare function formatWalkFailure(label: string, walk: Exclude<ProgramWalk, {
|
|
44
|
+
status: 'ok';
|
|
45
|
+
}>): string[];
|
|
46
|
+
|
|
47
|
+
interface TsconfigSettings {
|
|
48
|
+
readonly options: TS.CompilerOptions;
|
|
49
|
+
/** `.d.ts` files of the tsconfig's own file list. */
|
|
50
|
+
readonly declarationFiles: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/** Options and declaration files of `tsconfig` (strict + allowJs when there is none); throws on an unreadable tsconfig. */
|
|
53
|
+
declare function readTsconfig(ts: TypeScript, tsconfig: string | undefined): TsconfigSettings;
|
|
54
|
+
interface ProgramGroup {
|
|
55
|
+
/** Absolute tsconfig path, or undefined when no tsconfig owns the files. */
|
|
56
|
+
readonly tsconfig: string | undefined;
|
|
57
|
+
/** Absolute paths of the files to check, in input order. */
|
|
58
|
+
readonly files: readonly string[];
|
|
59
|
+
readonly program: TS.Program;
|
|
60
|
+
}
|
|
61
|
+
/** A file matched a trust config `tsconfig` entry whose tsconfig does not exist. */
|
|
62
|
+
interface MissingMappedTsconfig {
|
|
63
|
+
readonly kind: 'missing-mapped-tsconfig';
|
|
64
|
+
/** Names the config file, the entry and the missing path. */
|
|
65
|
+
readonly message: string;
|
|
66
|
+
}
|
|
67
|
+
type TsconfigGrouping = {
|
|
68
|
+
readonly kind: 'grouped';
|
|
69
|
+
readonly groups: Map<string | undefined, string[]>;
|
|
70
|
+
} | MissingMappedTsconfig;
|
|
71
|
+
type ProgramsCreation = {
|
|
72
|
+
readonly kind: 'created';
|
|
73
|
+
readonly groups: ProgramGroup[];
|
|
74
|
+
} | MissingMappedTsconfig;
|
|
75
|
+
/**
|
|
76
|
+
* Absolute files grouped by owning tsconfig: `tsconfig` (relative to cwd) for every file when given,
|
|
77
|
+
* else the first `mappings` entry whose globs match the file, else the nearest tsconfig.json.
|
|
78
|
+
*/
|
|
79
|
+
declare function groupByTsconfig(ts: TypeScript, cwd: string, files: readonly string[], tsconfig?: string, mappings?: readonly TsconfigMapping[]): TsconfigGrouping;
|
|
80
|
+
/**
|
|
81
|
+
* One Program per owning tsconfig (see groupByTsconfig), rooted at the given files. A missing mapped
|
|
82
|
+
* tsconfig is a returned failure; an unreadable tsconfig still throws (readTsconfig).
|
|
83
|
+
*/
|
|
84
|
+
declare function createPrograms(ts: TypeScript, cwd: string, files: readonly string[], tsconfig?: string, mappings?: readonly TsconfigMapping[]): ProgramsCreation;
|
|
85
|
+
/** The program's source file for `file` (also tried by realpath, for symlinked paths). */
|
|
86
|
+
declare function sourceFileOf(program: TS.Program, file: string): TS.SourceFile | undefined;
|
|
87
|
+
|
|
88
|
+
interface ToolConfig {
|
|
89
|
+
/** Absolute path of the config file, or undefined when the tool runs without one. */
|
|
90
|
+
readonly file: string | undefined;
|
|
91
|
+
/** Realpath of the directory globs, `tsconfig` paths and baseline keys resolve against. */
|
|
92
|
+
readonly rootDir: string;
|
|
93
|
+
readonly ignore: readonly ZoneGroup[];
|
|
94
|
+
readonly tsconfig: readonly TsconfigMapping[];
|
|
95
|
+
/** The tool's own keys as written (only the ones declared in `keys`). */
|
|
96
|
+
readonly settings: Readonly<Record<string, unknown>>;
|
|
97
|
+
}
|
|
98
|
+
interface LoadToolConfigOptions {
|
|
99
|
+
/** Names the config in messages: `ioc check config /path/x.json: …`. */
|
|
100
|
+
readonly tool: string;
|
|
101
|
+
/** The tool's own top-level keys besides `$comment`, `ignore` and `tsconfig`; any other key is an error. */
|
|
102
|
+
readonly keys: readonly string[];
|
|
103
|
+
/** Directory paths resolve against, instead of the config file's own directory. */
|
|
104
|
+
readonly rootDir?: string;
|
|
105
|
+
/** Check that every glob matches at least one file (default false, as `trust check`). */
|
|
106
|
+
readonly validateGlobs?: boolean;
|
|
107
|
+
}
|
|
108
|
+
type ToolConfigLoad = {
|
|
109
|
+
readonly kind: 'loaded';
|
|
110
|
+
readonly config: ToolConfig;
|
|
111
|
+
} | {
|
|
112
|
+
readonly kind: 'failed';
|
|
113
|
+
readonly message: string;
|
|
114
|
+
};
|
|
115
|
+
/** A config with nothing set, rooted at `rootDir` (a tool run without a config file). */
|
|
116
|
+
declare function emptyToolConfig(rootDir: string): ToolConfig;
|
|
117
|
+
/** Loads and validates `configFile`; a missing or invalid file is a `failed` result naming the tool's config. */
|
|
118
|
+
declare function loadToolConfig(configFile: string, options: LoadToolConfigOptions): ToolConfigLoad;
|
|
119
|
+
|
|
120
|
+
/** What a printed finding needs. */
|
|
121
|
+
type ReportFinding = Pick<Finding, 'file' | 'line' | 'column' | 'rule' | 'message'> & {
|
|
122
|
+
readonly severity?: 'error' | 'warning';
|
|
123
|
+
};
|
|
124
|
+
/** Sort order of printed findings: file, then line, then column. */
|
|
125
|
+
declare function compareFindings(a: ReportFinding, b: ReportFinding): number;
|
|
126
|
+
/** `file:line:col rule message`. */
|
|
127
|
+
declare function formatFinding(finding: ReportFinding): string;
|
|
128
|
+
|
|
129
|
+
export { type LoadToolConfigOptions, type LoadedFile, type ProgramGroup, type ProgramOptions, type ProgramWalk, type ProgramsCreation, type ReportFinding, type ToolConfig, type ToolConfigLoad, TsconfigMapping, type TsconfigSettings, TypeScript, ZoneGroup, compareFindings, createPrograms, emptyToolConfig, forEachSourceFile, formatFinding, formatWalkFailure, groupByTsconfig, loadToolConfig, readTsconfig, relativeTo, resolveFiles, sourceFileOf };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compareFindings,
|
|
3
|
+
forEachSourceFile,
|
|
4
|
+
formatFinding,
|
|
5
|
+
formatWalkFailure,
|
|
6
|
+
relativeTo,
|
|
7
|
+
resolveFiles
|
|
8
|
+
} from "../chunk-XXLWC5DB.js";
|
|
9
|
+
import {
|
|
10
|
+
WHOLE_BASELINE,
|
|
11
|
+
Zones,
|
|
12
|
+
compareToBaseline,
|
|
13
|
+
countFindings,
|
|
14
|
+
createPrograms,
|
|
15
|
+
describeBaselineDelta,
|
|
16
|
+
directiveDirectlyAbove,
|
|
17
|
+
directiveReason,
|
|
18
|
+
groupByTsconfig,
|
|
19
|
+
groupMatches,
|
|
20
|
+
isNamedDirective,
|
|
21
|
+
lineDirectivesIn,
|
|
22
|
+
loadTypeScript,
|
|
23
|
+
matchesPatterns,
|
|
24
|
+
nearestPackageName,
|
|
25
|
+
nodeBelow,
|
|
26
|
+
normalizePattern,
|
|
27
|
+
parseBaseline,
|
|
28
|
+
readBaseline,
|
|
29
|
+
readTsconfig,
|
|
30
|
+
readZoneSettings,
|
|
31
|
+
realpathOrSelf,
|
|
32
|
+
relativeInside,
|
|
33
|
+
serializeBaseline,
|
|
34
|
+
sourceFileOf,
|
|
35
|
+
toPosix,
|
|
36
|
+
updateBaseline
|
|
37
|
+
} from "../chunk-UG6D3V4M.js";
|
|
38
|
+
|
|
39
|
+
// src/core/tool-config.ts
|
|
40
|
+
import { existsSync, readFileSync } from "fs";
|
|
41
|
+
import { dirname, resolve } from "path";
|
|
42
|
+
var SHARED_KEYS = ["$comment", "ignore", "tsconfig"];
|
|
43
|
+
function emptyToolConfig(rootDir) {
|
|
44
|
+
return { file: void 0, rootDir: realpathOrSelf(resolve(rootDir)), ignore: [], tsconfig: [], settings: {} };
|
|
45
|
+
}
|
|
46
|
+
var ToolConfigProblem = class extends Error {
|
|
47
|
+
};
|
|
48
|
+
function isRecord(value) {
|
|
49
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
function loadToolConfig(configFile, options) {
|
|
52
|
+
const file = resolve(configFile);
|
|
53
|
+
const failWith = (source, message) => {
|
|
54
|
+
throw new ToolConfigProblem(`${options.tool} config ${source}: ${message}`);
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
if (!existsSync(file)) return { kind: "failed", message: `${options.tool} config not found: ${file}` };
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return failWith(file, `invalid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(raw)) return failWith(file, "expected an object");
|
|
65
|
+
const record = raw;
|
|
66
|
+
const allowed = /* @__PURE__ */ new Set([...SHARED_KEYS, ...options.keys]);
|
|
67
|
+
for (const key of Object.keys(record)) {
|
|
68
|
+
if (!allowed.has(key)) failWith(file, `unknown key "${key}" (known: ${[...allowed].map((name) => `"${name}"`).join(", ")})`);
|
|
69
|
+
}
|
|
70
|
+
const rootDir = realpathOrSelf(options.rootDir === void 0 ? dirname(file) : resolve(options.rootDir));
|
|
71
|
+
const zones = readZoneSettings(file, record, rootDir, options.validateGlobs ?? false, failWith);
|
|
72
|
+
const settings = Object.fromEntries(options.keys.filter((key) => key in record).map((key) => [key, record[key]]));
|
|
73
|
+
return { kind: "loaded", config: { file, rootDir, ignore: zones.ignore, tsconfig: zones.tsconfig, settings } };
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof ToolConfigProblem) return { kind: "failed", message: error.message };
|
|
76
|
+
return { kind: "failed", message: `${options.tool} config ${file}: ${error instanceof Error ? error.message : String(error)}` };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
WHOLE_BASELINE,
|
|
81
|
+
Zones,
|
|
82
|
+
compareFindings,
|
|
83
|
+
compareToBaseline,
|
|
84
|
+
countFindings,
|
|
85
|
+
createPrograms,
|
|
86
|
+
describeBaselineDelta,
|
|
87
|
+
directiveDirectlyAbove,
|
|
88
|
+
directiveReason,
|
|
89
|
+
emptyToolConfig,
|
|
90
|
+
forEachSourceFile,
|
|
91
|
+
formatFinding,
|
|
92
|
+
formatWalkFailure,
|
|
93
|
+
groupByTsconfig,
|
|
94
|
+
groupMatches,
|
|
95
|
+
isNamedDirective,
|
|
96
|
+
lineDirectivesIn,
|
|
97
|
+
loadToolConfig,
|
|
98
|
+
loadTypeScript,
|
|
99
|
+
matchesPatterns,
|
|
100
|
+
nearestPackageName,
|
|
101
|
+
nodeBelow,
|
|
102
|
+
normalizePattern,
|
|
103
|
+
parseBaseline,
|
|
104
|
+
readBaseline,
|
|
105
|
+
readTsconfig,
|
|
106
|
+
realpathOrSelf,
|
|
107
|
+
relativeInside,
|
|
108
|
+
relativeTo,
|
|
109
|
+
resolveFiles,
|
|
110
|
+
serializeBaseline,
|
|
111
|
+
sourceFileOf,
|
|
112
|
+
toPosix,
|
|
113
|
+
updateBaseline
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/tool-config.ts"],"sourcesContent":["// The config file of a sibling checker built on `@noego/trust/core` (`ioc-check.config.json`): one JSON\n// object, no `extend` chain, with trust's own `ignore` and `tsconfig` keys read exactly as trust reads\n// them (eslint/config.ts readZoneSettings: same glob semantics, paths relative to the config file's\n// directory or to `rootDir`) plus whatever keys the tool declares, handed back unread for the tool to\n// validate. Problems come back as a value naming the tool's config, never as a throw.\nimport { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { readZoneSettings, type ConfigFail, type TsconfigMapping } from '../eslint/config.js';\nimport { realpathOrSelf, type ZoneGroup } from '../eslint/zones.js';\n\nexport interface ToolConfig {\n /** Absolute path of the config file, or undefined when the tool runs without one. */\n readonly file: string | undefined;\n /** Realpath of the directory globs, `tsconfig` paths and baseline keys resolve against. */\n readonly rootDir: string;\n readonly ignore: readonly ZoneGroup[];\n readonly tsconfig: readonly TsconfigMapping[];\n /** The tool's own keys as written (only the ones declared in `keys`). */\n readonly settings: Readonly<Record<string, unknown>>;\n}\n\nexport interface LoadToolConfigOptions {\n /** Names the config in messages: `ioc check config /path/x.json: …`. */\n readonly tool: string;\n /** The tool's own top-level keys besides `$comment`, `ignore` and `tsconfig`; any other key is an error. */\n readonly keys: readonly string[];\n /** Directory paths resolve against, instead of the config file's own directory. */\n readonly rootDir?: string;\n /** Check that every glob matches at least one file (default false, as `trust check`). */\n readonly validateGlobs?: boolean;\n}\n\nexport type ToolConfigLoad = { readonly kind: 'loaded'; readonly config: ToolConfig } | { readonly kind: 'failed'; readonly message: string };\n\nconst SHARED_KEYS = ['$comment', 'ignore', 'tsconfig'];\n\n/** A config with nothing set, rooted at `rootDir` (a tool run without a config file). */\nexport function emptyToolConfig(rootDir: string): ToolConfig {\n return { file: undefined, rootDir: realpathOrSelf(resolve(rootDir)), ignore: [], tsconfig: [], settings: {} };\n}\n\nclass ToolConfigProblem extends Error {}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Loads and validates `configFile`; a missing or invalid file is a `failed` result naming the tool's config. */\nexport function loadToolConfig(configFile: string, options: LoadToolConfigOptions): ToolConfigLoad {\n const file = resolve(configFile);\n const failWith: ConfigFail = (source, message) => {\n throw new ToolConfigProblem(`${options.tool} config ${source}: ${message}`);\n };\n try {\n if (!existsSync(file)) return { kind: 'failed', message: `${options.tool} config not found: ${file}` };\n let raw: unknown;\n try {\n raw = JSON.parse(readFileSync(file, 'utf8'));\n } catch (error) {\n return failWith(file, `invalid JSON (${error instanceof Error ? error.message : String(error)})`);\n }\n if (!isRecord(raw)) return failWith(file, 'expected an object');\n const record = raw;\n const allowed = new Set([...SHARED_KEYS, ...options.keys]);\n for (const key of Object.keys(record)) {\n if (!allowed.has(key)) failWith(file, `unknown key \"${key}\" (known: ${[...allowed].map((name) => `\"${name}\"`).join(', ')})`);\n }\n const rootDir = realpathOrSelf(options.rootDir === undefined ? dirname(file) : resolve(options.rootDir));\n const zones = readZoneSettings(file, record, rootDir, options.validateGlobs ?? false, failWith);\n const settings = Object.fromEntries(options.keys.filter((key) => key in record).map((key) => [key, record[key]]));\n return { kind: 'loaded', config: { file, rootDir, ignore: zones.ignore, tsconfig: zones.tsconfig, settings } };\n } catch (error) {\n if (error instanceof ToolConfigProblem) return { kind: 'failed', message: error.message };\n return { kind: 'failed', message: `${options.tool} config ${file}: ${error instanceof Error ? error.message : String(error)}` };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,YAAY,oBAAoB;AACzC,SAAS,SAAS,eAAe;AA4BjC,IAAM,cAAc,CAAC,YAAY,UAAU,UAAU;AAG9C,SAAS,gBAAgB,SAA6B;AAC3D,SAAO,EAAE,MAAM,QAAW,SAAS,eAAe,QAAQ,OAAO,CAAC,GAAG,QAAQ,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,EAAE;AAC9G;AAEA,IAAM,oBAAN,cAAgC,MAAM;AAAC;AAEvC,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAGO,SAAS,eAAe,YAAoB,SAAgD;AACjG,QAAM,OAAO,QAAQ,UAAU;AAC/B,QAAM,WAAuB,CAAC,QAAQ,YAAY;AAChD,UAAM,IAAI,kBAAkB,GAAG,QAAQ,IAAI,WAAW,MAAM,KAAK,OAAO,EAAE;A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