@r_masseater/fu4 0.3.0 → 0.3.2

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.
@@ -1,4 +1,230 @@
1
- import { Array as Array$1, Option, String as String$1, pipe } from "effect";
1
+ import { createRequire } from "node:module";
2
+ import { Array as Array$1, Boolean, Console, Effect, FileSystem, Function, Match, Option, Order, Path, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
+ import { runMain } from "@r_masseater/node-main";
4
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
5
+ import { Argument, Command } from "effect/cli";
6
+ import { resolveConfigFromFile } from "vite-plus";
7
+ // ../lint-host/src/entities/rule/model/setting.ts
8
+ const NO_OPTIONS = {};
9
+ const settingOf = (entry) => Match.value(entry).pipe(Match.when(Match.string, (severity) => ({
10
+ severity,
11
+ options: NO_OPTIONS
12
+ })), Match.orElse(([severity, options]) => ({
13
+ severity,
14
+ options: options ?? NO_OPTIONS
15
+ })));
16
+ // ../lint-host/src/shared/lib/target.ts
17
+ const abiOf = (platform) => Match.value(platform).pipe(Match.when("linux", () => "-gnu"), Match.when("win32", () => "-msvc"), Match.orElse(() => ""));
18
+ const platformTarget = `${process.platform}-${process.arch}${abiOf(process.platform)}`;
19
+ const addonFileOf = (binary) => `${binary}.${platformTarget}.node`;
20
+ // ../lint-host/src/features/build-addon/model/build.ts
21
+ const taggedError$1 = Schema.TaggedError;
22
+ var AddonBuildFailed = class extends taggedError$1()("AddonBuildFailed", { message: Schema.String }) {};
23
+ const LIBRARY = {
24
+ linux: (name) => `lib${name}.so`,
25
+ darwin: (name) => `lib${name}.dylib`,
26
+ win32: (name) => `${name}.dll`
27
+ };
28
+ const SUCCESS = 0;
29
+ const cargo = Effect.fn("cargo")(function* cargo(crate, workspace) {
30
+ const exitCode = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("cargo", [
31
+ "build",
32
+ "--release",
33
+ "--locked",
34
+ "-p",
35
+ crate
36
+ ], {
37
+ cwd: workspace,
38
+ stdout: "inherit",
39
+ stderr: "inherit"
40
+ }));
41
+ const failure = AddonBuildFailed.make({ message: `cargo exited with ${String(exitCode)}` });
42
+ yield* Effect.when(Effect.fail(failure), Effect.sync(() => Number(exitCode) !== SUCCESS));
43
+ });
44
+ Effect.fn("buildAddon")(function* build(options) {
45
+ const fileSystem = yield* FileSystem.FileSystem;
46
+ const path = yield* Path.Path;
47
+ const library = yield* Effect.fromOption(Record.get(LIBRARY, process.platform)).pipe(Effect.mapError(() => AddonBuildFailed.make({ message: `no native build for ${process.platform}` })));
48
+ yield* cargo(options.crate, options.workspaceDir);
49
+ const output = path.join(options.packageDir, "native");
50
+ yield* fileSystem.makeDirectory(output, { recursive: true });
51
+ const built = library(String$1.replaceAll("-", "_")(options.crate));
52
+ yield* fileSystem.copyFile(path.join(options.workspaceDir, "target", "release", built), path.join(output, addonFileOf(options.binary)));
53
+ });
54
+ // ../lint-host/src/features/load-addon/model/load.ts
55
+ const loadAddon = ({ packageName, binary, from, isAddon, failWith }) => {
56
+ const requireFrom = createRequire(from);
57
+ const loadFrom = (specifier) => Effect.try({
58
+ try: () => requireFrom(specifier),
59
+ catch: failWith(`could not load ${specifier}`)
60
+ });
61
+ return loadFrom(`${packageName}-${platformTarget}`).pipe(Effect.catchCause(() => loadFrom(`${packageName}/native/${addonFileOf(binary)}`)), Effect.filterOrFail(isAddon, (found) => failWith(`no ${binary} addon for ${platformTarget}`)(found)));
62
+ };
63
+ const callAddon = ({ addon, name, files, call, failWith }) => addon.pipe(Effect.flatMap((loaded) => Effect.try({
64
+ try: () => call(loaded),
65
+ catch: failWith(`${name} could not lint`)
66
+ }).pipe(Effect.tap(() => Effect.promise(() => loaded.flushTelemetry())))), Effect.withSpan(`${name}.native`, { attributes: { [`${name}.files`]: files } }));
67
+ // ../lint-host/src/features/load-addon/model/guard.ts
68
+ const hasFunction = (value) => (name) => Predicate.hasProperty(value, name) && Predicate.isFunction(value[name]);
69
+ const exposes = (names) => (value) => pipe(names, Array$1.every(hasFunction(value)));
70
+ // ../lint-host/src/shared/lib/fail.ts
71
+ const taggedError = Schema.TaggedError;
72
+ var NotUtf8Error = class extends taggedError()("NotUtf8Error", { path: Schema.String }) {};
73
+ // ../lint-host/src/features/run-cli/model/cli.ts
74
+ const CONFIG_FILES = [
75
+ "vite.config.ts",
76
+ "vite.config.mts",
77
+ "vite.config.js",
78
+ "vite.config.mjs"
79
+ ];
80
+ const FAILED = 1;
81
+ const DATA_FIRST_ARITY$1 = 2;
82
+ const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true });
83
+ const readSectionIn = (source, root) => Effect.gen(function* readConfig() {
84
+ const fileSystem = yield* FileSystem.FileSystem;
85
+ const path = yield* Path.Path;
86
+ const found = yield* pipe(CONFIG_FILES, Array$1.map((name) => path.join(root, name)), Effect.filter((file) => fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))));
87
+ const loaded = yield* Option.match(Array$1.head(found), {
88
+ onNone: () => Effect.succeed({}),
89
+ onSome: (file) => Effect.tryPromise({
90
+ try: () => resolveConfigFromFile(file),
91
+ catch: source.failWith(`could not load ${file}`)
92
+ })
93
+ });
94
+ return source.section(loaded);
95
+ }).pipe(Effect.withSpan(`${source.name}.config`));
96
+ Function.dual(DATA_FIRST_ARITY$1, readSectionIn);
97
+ const trackedFiles = (root, pathspecs) => Effect.gen(function* listFiles() {
98
+ const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
99
+ "ls-files",
100
+ "-co",
101
+ "--exclude-standard",
102
+ "-z",
103
+ "--",
104
+ ...pathspecs
105
+ ], { cwd: root }));
106
+ return pipe(String$1.split(output, "\0"), Array$1.filter(String$1.isNonEmpty));
107
+ });
108
+ const requestOf = (config, patterns) => Array$1.match(patterns, {
109
+ onEmpty: () => ({ config }),
110
+ onNonEmpty: (given) => ({
111
+ config,
112
+ patterns: given
113
+ })
114
+ });
115
+ const hasError = (found) => pipe(found, Array$1.some(({ severity }) => severity === "error"));
116
+ const failWhen = (failed) => Effect.when(Effect.sync(() => {
117
+ process.exitCode = FAILED;
118
+ }), Effect.succeed(failed)).pipe(Effect.asVoid);
119
+ const printAll = (found, format) => Array$1.match(found, {
120
+ onEmpty: () => Effect.void,
121
+ onNonEmpty: (all) => Console.log(pipe(all, Array$1.map(format), Array$1.join("\n")))
122
+ });
123
+ const readerIn = (root, failWith) => Effect.gen(function* reader() {
124
+ const fileSystem = yield* FileSystem.FileSystem;
125
+ const path = yield* Path.Path;
126
+ return (file) => fileSystem.readFile(path.resolve(root, file)).pipe(Effect.mapError(failWith(`could not read ${file}`)), Effect.flatMap((bytes) => Effect.try({
127
+ try: () => STRICT_UTF8.decode(bytes),
128
+ catch: () => NotUtf8Error.make({ path: file })
129
+ })));
130
+ });
131
+ const mainOf = (cli, patterns) => Effect.gen(function* main() {
132
+ const root = process.cwd();
133
+ const config = yield* readSectionIn(cli, root);
134
+ const pathspecs = cli.pathspecs(requestOf(config, patterns));
135
+ const { files, projectFiles } = yield* Effect.all({
136
+ files: trackedFiles(root, pathspecs).pipe(Effect.withSpan(`${cli.name}.files`)),
137
+ projectFiles: trackedFiles(root, []).pipe(Effect.withSpan(`${cli.name}.project`))
138
+ }, { concurrency: "unbounded" });
139
+ const read = yield* readerIn(root, cli.failWith);
140
+ const found = yield* cli.lint({
141
+ root,
142
+ files,
143
+ projectFiles,
144
+ config,
145
+ read
146
+ });
147
+ yield* printAll(found, cli.format);
148
+ yield* failWhen(hasError(found));
149
+ });
150
+ const variadicOf = ({ name, description }) => Argument.String(name).pipe(Argument.withDescription(description), Argument.variadic());
151
+ const pathspecArgument = () => variadicOf({
152
+ name: "pathspec",
153
+ description: "Git pathspecs of the files to lint, in place of the configured ones"
154
+ });
155
+ const runCli = (cli) => {
156
+ const command = Command.make(cli.name, { pathspecs: pathspecArgument() }, ({ pathspecs }) => mainOf(cli, pathspecs)).pipe(Command.withDescription(cli.description));
157
+ runMain(cli.name)(Command.run(command, { version: cli.version }));
158
+ };
159
+ Function.dual(2, (value, build) => Option.match(value, {
160
+ onNone: () => ({}),
161
+ onSome: build
162
+ }));
163
+ // ../lint-host/src/shared/lib/trace.ts
164
+ const SAMPLED = "01";
165
+ const NOT_SAMPLED = "00";
166
+ const LINE_START = 0;
167
+ const flagsOf = (sampled) => Boolean.match(sampled, {
168
+ onFalse: () => NOT_SAMPLED,
169
+ onTrue: () => SAMPLED
170
+ });
171
+ const traceparent = Effect.currentSpan.pipe(Effect.map((span) => `00-${span.traceId}-${span.spanId}-${flagsOf(span.sampled)}`), Effect.option);
172
+ Order.combine(Order.mapInput(Order.String, (found) => found.path), Order.combine(Order.mapInput(Order.Number, (found) => found.line), Order.mapInput(Order.Number, (found) => found.column ?? LINE_START)));
173
+ // ../lint-host/src/shared/lib/layers.ts
174
+ const mergedRecords = (records) => pipe(records, Array$1.flatMap((record) => Record.toEntries(record ?? {})), Record.fromEntries);
175
+ const layersOf = (config) => {
176
+ const { extends: bases = [], ...own } = config;
177
+ return [...pipe(bases, Array$1.flatMap(layersOf)), own];
178
+ };
179
+ const mergedLayers = (layers) => ({
180
+ plugins: mergedRecords(pipe(layers, Array$1.map((layer) => layer.plugins))),
181
+ rules: mergedRecords(pipe(layers, Array$1.map((layer) => layer.rules))),
182
+ ignores: pipe(layers, Array$1.flatMap((layer) => layer.ignores ?? [])),
183
+ overrides: pipe(layers, Array$1.flatMap((layer) => layer.overrides ?? []))
184
+ });
185
+ const EMPTY$1 = 0;
186
+ const LENGTH = 1;
187
+ const aligned = (buffer) => Option.match(Option.liftPredicate(buffer, ({ byteOffset }) => byteOffset % 4 === EMPTY$1), {
188
+ onNone: () => Uint8Array.from(buffer),
189
+ onSome: (value) => value
190
+ });
191
+ const wordAt = (words) => (index) => words[index] ?? EMPTY$1;
192
+ const fieldsOf = (header) => (fields) => pipe(fields, Record.map((index) => wordAt(header)(index)));
193
+ const wordsOf = (buffer) => (at, count) => new Uint32Array(buffer.buffer, buffer.byteOffset + at * 4, count);
194
+ const spanText = (words) => (blob, encoding) => (spansAt, unit) => {
195
+ const decoder = new TextDecoder(encoding);
196
+ const cache = /* @__PURE__ */ new Map();
197
+ const read = (index) => {
198
+ const at = spansAt + index * 2;
199
+ const offset = wordAt(words)(at) * unit;
200
+ const value = decoder.decode(blob.subarray(offset, offset + wordAt(words)(at + LENGTH) * unit));
201
+ cache.set(index, value);
202
+ return value;
203
+ };
204
+ return (index) => Option.getOrElse(Option.fromNullishOr(cache.get(index)), () => read(index));
205
+ };
206
+ // ../lint-host/src/shared/lib/diagnostic.ts
207
+ const notUtf8 = (tool) => (path) => ({
208
+ path,
209
+ line: 1,
210
+ column: 1,
211
+ rule: "utf8",
212
+ message: `The file is not valid UTF-8, so ${tool} cannot read it`,
213
+ severity: "error"
214
+ });
215
+ // ../lint-host/src/shared/lib/section.ts
216
+ const sectionOf = ({ name, fallback, prepare = Function.identity }) => {
217
+ const hasSection = (value) => Predicate.hasProperty(value, name) && Predicate.isObject(value[name]);
218
+ return (config) => pipe(Option.liftPredicate(config, hasSection), Option.flatMapNullishOr((value) => value[name]), Option.map(prepare), Option.getOrElse(() => fallback));
219
+ };
220
+ const pathspecsOf = ({ defaults, unowned = [] }) => ({ config, patterns = [] }) => [
221
+ ...Array$1.match(patterns, {
222
+ onEmpty: () => defaults,
223
+ onNonEmpty: Function.identity
224
+ }),
225
+ ...unowned,
226
+ ...pipe(config.ignores ?? [], Array$1.map((glob) => `:(glob,exclude)${glob}`))
227
+ ];
2
228
  // src/entities/rule/model/define.ts
3
229
  const defineRule = (rule) => rule;
4
230
  const definePlugin = (plugin) => plugin;
@@ -2126,6 +2352,225 @@ const INPUT_KINDS = [
2126
2352
  "dependabot",
2127
2353
  "pre-commit"
2128
2354
  ];
2129
- export { baseName as a, afterPrefix as i, matcher as n, definePlugin as o, selects as r, defineRule as s, INPUT_KINDS as t };
2355
+ // src/shared/native/source.ts
2356
+ const EMPTY = 0;
2357
+ const START = 0;
2358
+ const NONE = 4294967295;
2359
+ const HEADER = {
2360
+ version: 0,
2361
+ semanticCount: 1,
2362
+ semanticRoot: 2,
2363
+ concreteCount: 3,
2364
+ concreteRoot: 4,
2365
+ childCount: 5,
2366
+ errorCount: 6,
2367
+ stringCount: 7
2368
+ };
2369
+ const SEMANTIC = {
2370
+ kind: 0,
2371
+ tag: 1,
2372
+ value: 2,
2373
+ style: 3,
2374
+ line: 4,
2375
+ column: 5,
2376
+ childStart: 6,
2377
+ childCount: 7
2378
+ };
2379
+ const CONCRETE = {
2380
+ kind: 0,
2381
+ flags: 1,
2382
+ start: 2,
2383
+ end: 3,
2384
+ field: 4,
2385
+ parent: 5,
2386
+ childStart: 6,
2387
+ childCount: 7
2388
+ };
2389
+ const FLAG = {
2390
+ named: 1,
2391
+ error: 2,
2392
+ missing: 4,
2393
+ extra: 8
2394
+ };
2395
+ const UTF16 = "utf-16le";
2396
+ const rootOf = (value) => Option.liftPredicate(value, (id) => id !== NONE);
2397
+ const layoutOf = (header) => {
2398
+ const fields = fieldsOf(header)(HEADER);
2399
+ const { semanticCount, concreteCount, errorCount } = fields;
2400
+ const semanticAt = 8;
2401
+ const concreteAt = semanticAt + semanticCount * 8;
2402
+ const childAt = concreteAt + concreteCount * 8;
2403
+ const errorAt = childAt + fields.childCount;
2404
+ const spanAt = errorAt + errorCount * 3;
2405
+ return {
2406
+ semanticCount,
2407
+ concreteCount,
2408
+ errorCount,
2409
+ semanticAt,
2410
+ concreteAt,
2411
+ childAt,
2412
+ errorAt,
2413
+ spanAt,
2414
+ blobAt: (spanAt + fields.stringCount * 2) * 4
2415
+ };
2416
+ };
2417
+ const sourceView = (raw) => {
2418
+ const buffer = aligned(raw);
2419
+ const header = wordsOf(buffer)(START, 8);
2420
+ const layout = layoutOf(header);
2421
+ const words = wordsOf(buffer)(START, layout.blobAt / 4);
2422
+ const stringAt = spanText(words)(buffer.subarray(layout.blobAt), UTF16)(layout.spanAt, 2);
2423
+ return {
2424
+ semanticCount: layout.semanticCount,
2425
+ semanticRoot: rootOf(wordAt(header)(HEADER.semanticRoot)),
2426
+ concreteCount: layout.concreteCount,
2427
+ concreteRoot: rootOf(wordAt(header)(HEADER.concreteRoot)),
2428
+ errorCount: layout.errorCount,
2429
+ semantic: (id, field) => wordAt(words)(layout.semanticAt + id * 8 + field),
2430
+ concrete: (id, field) => wordAt(words)(layout.concreteAt + id * 8 + field),
2431
+ child: (index) => wordAt(words)(layout.childAt + index),
2432
+ error: (index, field) => wordAt(words)(layout.errorAt + index * 3 + field),
2433
+ stringAt,
2434
+ text: stringAt(EMPTY)
2435
+ };
2436
+ };
2437
+ // src/entities/source/model/source.ts
2438
+ const FIRST = 1;
2439
+ const FIRST_LINE = 0;
2440
+ const HALF = 2;
2441
+ const BIT = 2;
2442
+ const SET = 1;
2443
+ const ERROR_FIELD = {
2444
+ line: 0,
2445
+ column: 1,
2446
+ message: 2
2447
+ };
2448
+ const LINE_BREAK = /\r\n|\r|\n/u;
2449
+ const NEWLINES = /\n/gu;
2450
+ const KINDS = [
2451
+ "scalar",
2452
+ "sequence",
2453
+ "mapping",
2454
+ "alias"
2455
+ ];
2456
+ const STYLES = [
2457
+ "plain",
2458
+ "single-quoted",
2459
+ "double-quoted",
2460
+ "literal",
2461
+ "folded"
2462
+ ];
2463
+ const pick = (values, index, fallback) => pipe(Array$1.get(values, index), Option.getOrElse(() => fallback));
2464
+ const lazy = (make) => {
2465
+ let made = Option.none();
2466
+ return () => pipe(made, Option.getOrElse(() => {
2467
+ const value = make();
2468
+ made = Option.some(value);
2469
+ return value;
2470
+ }));
2471
+ };
2472
+ const memo = (make) => {
2473
+ const made = /* @__PURE__ */ new Map();
2474
+ return (id) => made.getOrInsertComputed(id, () => make(id));
2475
+ };
2476
+ const times = (count, make) => Array.from({ length: count }, (_empty, index) => make(index));
2477
+ const childrenOf = (view, at) => (start, count) => times(count, (offset) => at(view.child(start + offset)));
2478
+ const yamlTree = (view) => {
2479
+ const at = memo((id) => {
2480
+ const field = (name) => view.semantic(id, SEMANTIC[name]);
2481
+ const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
2482
+ return {
2483
+ id,
2484
+ kind: pick(KINDS, field("kind"), "scalar"),
2485
+ tag: view.stringAt(field("tag")),
2486
+ value: view.stringAt(field("value")),
2487
+ style: pick(STYLES, field("style"), "plain"),
2488
+ line: field("line"),
2489
+ column: field("column"),
2490
+ get children() {
2491
+ return children();
2492
+ }
2493
+ };
2494
+ });
2495
+ return at;
2496
+ };
2497
+ const hasFlag = (flags, flag) => Math.floor(flags / flag) % BIT === SET;
2498
+ const present = (index) => Option.liftPredicate(index, (value) => value !== NONE);
2499
+ const syntaxNode = (view, at) => (id) => {
2500
+ const field = (name) => view.concrete(id, CONCRETE[name]);
2501
+ const flags = field("flags");
2502
+ const start = field("start");
2503
+ const end = field("end");
2504
+ const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
2505
+ return {
2506
+ id,
2507
+ type: view.stringAt(field("kind")),
2508
+ named: hasFlag(flags, FLAG.named),
2509
+ isError: hasFlag(flags, FLAG.error),
2510
+ isMissing: hasFlag(flags, FLAG.missing),
2511
+ isExtra: hasFlag(flags, FLAG.extra),
2512
+ start,
2513
+ end,
2514
+ field: pipe(present(field("field")), Option.map(view.stringAt), Option.getOrUndefined),
2515
+ get parent() {
2516
+ return pipe(present(field("parent")), Option.map(at), Option.getOrUndefined);
2517
+ },
2518
+ get children() {
2519
+ return children();
2520
+ },
2521
+ get namedChildren() {
2522
+ return pipe(children(), Array$1.filter((child) => child.named));
2523
+ },
2524
+ get text() {
2525
+ return String$1.slice(start, end)(view.text);
2526
+ }
2527
+ };
2528
+ };
2529
+ const syntaxTree = (view) => {
2530
+ const at = memo((id) => syntaxNode(view, at)(id));
2531
+ return at;
2532
+ };
2533
+ const lineStartsOf = (text) => [FIRST_LINE, ...Array.from(String$1.matchAll(NEWLINES)(text), (match) => (match.index ?? FIRST_LINE) + FIRST)];
2534
+ const lineAt = (starts, offset) => {
2535
+ let low = FIRST_LINE;
2536
+ let high = starts.length - FIRST;
2537
+ while (low < high) {
2538
+ const middle = Math.ceil((low + high) / HALF);
2539
+ if ((starts[middle] ?? FIRST_LINE) <= offset) low = middle;
2540
+ else high = middle - FIRST;
2541
+ }
2542
+ return low;
2543
+ };
2544
+ const positionIn = (text) => {
2545
+ const starts = lineStartsOf(text);
2546
+ return (offset) => {
2547
+ const line = lineAt(starts, offset);
2548
+ return {
2549
+ line: line + FIRST,
2550
+ column: offset - (starts[line] ?? FIRST_LINE) + FIRST
2551
+ };
2552
+ };
2553
+ };
2554
+ const errorsOf = (view) => times(view.errorCount, (index) => ({
2555
+ line: view.error(index, ERROR_FIELD.line),
2556
+ column: view.error(index, ERROR_FIELD.column),
2557
+ message: view.stringAt(view.error(index, ERROR_FIELD.message))
2558
+ }));
2559
+ const sourceOf = (view) => {
2560
+ const yaml = yamlTree(view);
2561
+ const syntax = syntaxTree(view);
2562
+ const lines = lazy(() => String$1.split(LINE_BREAK)(view.text));
2563
+ return {
2564
+ text: view.text,
2565
+ yaml: pipe(view.semanticRoot, Option.map(yaml), Option.getOrUndefined),
2566
+ syntax: pipe(view.concreteRoot, Option.map(syntax), Option.getOrUndefined),
2567
+ errors: errorsOf(view),
2568
+ get lines() {
2569
+ return lines();
2570
+ },
2571
+ positionOf: positionIn(view.text)
2572
+ };
2573
+ };
2574
+ export { settingOf as S, traceparent as _, matcher as a, callAddon as b, baseName as c, pathspecsOf as d, sectionOf as f, mergedRecords as g, mergedLayers as h, INPUT_KINDS as i, definePlugin as l, layersOf as m, sourceOf as n, selects as o, notUtf8 as p, sourceView as r, afterPrefix as s, lineStartsOf as t, defineRule as u, runCli as v, loadAddon as x, exposes as y };
2130
2575
 
2131
- //# sourceMappingURL=types-CsheTVso.mjs.map
2576
+ //# sourceMappingURL=source-CzBgefky.mjs.map