@ryuugg/stanza 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +7 -5
  2. package/package.json +19 -11
  3. package/src/launcher +102 -8
  4. package/src/cli.ts +0 -684
  5. package/src/compile/darwin-arm64.ts +0 -3
  6. package/src/compile/darwin-x64.ts +0 -3
  7. package/src/compile/linux-arm64-musl.ts +0 -3
  8. package/src/compile/linux-arm64.ts +0 -3
  9. package/src/compile/linux-x64-musl.ts +0 -3
  10. package/src/compile/linux-x64.ts +0 -3
  11. package/src/compiled.ts +0 -9
  12. package/src/depth.ts +0 -372
  13. package/src/directories.ts +0 -77
  14. package/src/engine/attach.ts +0 -62
  15. package/src/engine/directives.ts +0 -157
  16. package/src/engine/doc.ts +0 -93
  17. package/src/engine/edits.ts +0 -79
  18. package/src/engine/explain.ts +0 -337
  19. package/src/engine/gaps.ts +0 -361
  20. package/src/engine/hunks.ts +0 -319
  21. package/src/engine/index.ts +0 -273
  22. package/src/engine/model.ts +0 -103
  23. package/src/engine/rules.ts +0 -104
  24. package/src/engine/types.ts +0 -38
  25. package/src/files.ts +0 -1186
  26. package/src/format.ts +0 -159
  27. package/src/gitignore.ts +0 -280
  28. package/src/hook.ts +0 -380
  29. package/src/languages/index.ts +0 -34
  30. package/src/languages/javascript/ast.ts +0 -261
  31. package/src/languages/javascript/braces.ts +0 -374
  32. package/src/languages/javascript/config/biome.ts +0 -112
  33. package/src/languages/javascript/config/eslint.ts +0 -128
  34. package/src/languages/javascript/config/evaluate.ts +0 -278
  35. package/src/languages/javascript/config/find.ts +0 -105
  36. package/src/languages/javascript/config/glob.ts +0 -149
  37. package/src/languages/javascript/config/index.ts +0 -48
  38. package/src/languages/javascript/config/layers.ts +0 -468
  39. package/src/languages/javascript/config/module.ts +0 -327
  40. package/src/languages/javascript/config/oxlint.ts +0 -170
  41. package/src/languages/javascript/config/width.ts +0 -723
  42. package/src/languages/javascript/deserializers.ts +0 -17
  43. package/src/languages/javascript/embedded.ts +0 -7
  44. package/src/languages/javascript/entry.ts +0 -42
  45. package/src/languages/javascript/facts.ts +0 -294
  46. package/src/languages/javascript/index.ts +0 -20
  47. package/src/languages/javascript/lists.ts +0 -64
  48. package/src/languages/javascript/oracle.ts +0 -191
  49. package/src/languages/javascript/oxc-raw.d.ts +0 -31
  50. package/src/languages/javascript/parse.ts +0 -131
  51. package/src/languages/javascript/raw.ts +0 -95
  52. package/src/languages/javascript/scan.ts +0 -68
  53. package/src/languages/language.ts +0 -109
  54. package/src/native-file.d.ts +0 -4
  55. package/src/pool.ts +0 -473
  56. package/src/start.ts +0 -49
  57. package/src/step.ts +0 -113
  58. package/src/usage.ts +0 -35
  59. package/src/worker.ts +0 -5
package/src/format.ts DELETED
@@ -1,159 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import {
3
- accessSync,
4
- chmodSync,
5
- constants,
6
- readFileSync,
7
- realpathSync,
8
- renameSync,
9
- type Stats,
10
- statSync,
11
- unlinkSync,
12
- writeFileSync,
13
- } from "node:fs";
14
- import { dirname, join } from "node:path";
15
- import { errorCode } from "./files.ts";
16
- import type { Changed } from "./engine/model.ts";
17
- import { compareFindings, type Braces, type Finding, type Mode } from "./engine/types.ts";
18
- import { decode, type Decoded, formatText } from "./step.ts";
19
-
20
- export interface Input {
21
- path: string;
22
- read: () => Decoded;
23
- changedLines?: Changed | undefined;
24
- }
25
-
26
- export interface FormatRun {
27
- mode: Mode;
28
- braces: Braces | undefined;
29
- write: boolean;
30
- }
31
-
32
- export interface Warnings {
33
- unread: Set<string>;
34
- unreadWidth: Set<string>;
35
- }
36
-
37
- export interface FileOutcome {
38
- path: string;
39
- findings: Finding[];
40
- failed: boolean;
41
- rewritten?: string;
42
- kept?: string;
43
- }
44
-
45
- export interface Formatted extends Warnings {
46
- findings: Finding[];
47
- failed: boolean;
48
- rewritten: string[];
49
- kept: Map<string, string>;
50
- }
51
-
52
- export function readText(path: string): Decoded {
53
- try {
54
- return decode(readFileSync(path));
55
- } catch (error: unknown) {
56
- return { message: String(error) };
57
- }
58
- }
59
-
60
- function removeQuietly(path: string): void {
61
- try {
62
- unlinkSync(path);
63
- } catch {}
64
- }
65
-
66
- function replaceFile(real: string, text: string, target: Stats): boolean {
67
- const temp = join(dirname(real), `.stanza-${randomUUID()}.tmp`);
68
- try {
69
- writeFileSync(temp, text, { encoding: "utf8", flag: "wx", mode: 0o600 });
70
- } catch (error: unknown) {
71
- removeQuietly(temp);
72
- if (["EACCES", "EPERM"].includes(errorCode(error))) return false;
73
- throw error;
74
- }
75
-
76
- try {
77
- const created = statSync(temp);
78
- if (created.uid !== target.uid || created.gid !== target.gid) {
79
- removeQuietly(temp);
80
- return false;
81
- }
82
-
83
- chmodSync(temp, target.mode & 0o7777);
84
- renameSync(temp, real);
85
- return true;
86
- } catch (error: unknown) {
87
- removeQuietly(temp);
88
- throw error;
89
- }
90
- }
91
-
92
- function writeInPlace(real: string, text: string): void {
93
- const original = readFileSync(real);
94
- try {
95
- writeFileSync(real, text, "utf8");
96
- } catch (error: unknown) {
97
- try {
98
- writeFileSync(real, original);
99
- } catch {}
100
-
101
- throw error;
102
- }
103
- }
104
-
105
- function writeFixed(path: string, text: string, output: string): Finding | undefined {
106
- try {
107
- const real = realpathSync(path);
108
- const target = statSync(real);
109
- accessSync(real, constants.W_OK);
110
-
111
- if (target.nlink > 1 || !replaceFile(real, text, target)) writeInPlace(real, text);
112
- } catch (error: unknown) {
113
- return { path: output, line: 1, col: 1, rule: "write", message: String(error), fixable: false };
114
- }
115
- }
116
-
117
- export function formatFile(
118
- input: Input,
119
- run: FormatRun,
120
- output: string,
121
- warnings: Warnings,
122
- ): FileOutcome {
123
- const result = formatText(input.path, input.read(), {
124
- mode: run.mode,
125
- braces: run.braces,
126
- changedLines: input.changedLines,
127
- ...warnings,
128
- });
129
-
130
- const outcome: FileOutcome = {
131
- path: input.path,
132
- findings: result.findings.map((finding) => ({ ...finding, path: output })),
133
- failed: result.parseError,
134
- };
135
-
136
- if (result.fixed === undefined) return outcome;
137
- if (!run.write) return { ...outcome, kept: result.fixed };
138
-
139
- const unwritten = writeFixed(input.path, result.fixed, output);
140
- if (unwritten) return { ...outcome, findings: [...outcome.findings, unwritten], failed: true };
141
-
142
- return { ...outcome, rewritten: output };
143
- }
144
-
145
- export function mergeOutcomes(outcomes: FileOutcome[], warnings: Warnings): Formatted {
146
- const findings: Finding[] = [];
147
- const rewritten: string[] = [];
148
- const kept = new Map<string, string>();
149
-
150
- let failed = false;
151
- for (const outcome of outcomes) {
152
- findings.push(...outcome.findings);
153
- failed ||= outcome.failed;
154
- if (outcome.rewritten !== undefined) rewritten.push(outcome.rewritten);
155
- if (outcome.kept !== undefined) kept.set(outcome.path, outcome.kept);
156
- }
157
-
158
- return { findings: findings.sort(compareFindings), failed, rewritten, kept, ...warnings };
159
- }
package/src/gitignore.ts DELETED
@@ -1,280 +0,0 @@
1
- type CharacterSet = {
2
- singles: string[];
3
- ranges: [string, string][];
4
- classes: string[];
5
- negated: boolean;
6
- };
7
-
8
- type Token =
9
- | { kind: "literal"; value: string }
10
- | { kind: "star" | "globstar" | "directories" | "any" }
11
- | { kind: "set"; value: CharacterSet };
12
-
13
- export interface Rule {
14
- tokens: Token[];
15
- anchored: boolean;
16
- directory: boolean;
17
- negated: boolean;
18
- }
19
-
20
- const posixClasses = new Set([
21
- "alnum",
22
- "alpha",
23
- "blank",
24
- "cntrl",
25
- "digit",
26
- "graph",
27
- "lower",
28
- "print",
29
- "punct",
30
- "space",
31
- "upper",
32
- "xdigit",
33
- ]);
34
-
35
- function characterSet(pattern: string, start: number): { token: Token; end: number } | undefined {
36
- let index = start + 1;
37
- const negated = pattern[index] === "!" || pattern[index] === "^";
38
- if (negated) index++;
39
-
40
- const singles: string[] = [];
41
- const ranges: [string, string][] = [];
42
- const classes: string[] = [];
43
-
44
- let first = true;
45
- let previous: string | undefined;
46
- while (index < pattern.length) {
47
- if (pattern[index] === "]" && !first) {
48
- if (previous !== undefined) singles.push(previous);
49
- return {
50
- token: { kind: "set", value: { singles, ranges, classes, negated } },
51
- end: index + 1,
52
- };
53
- }
54
-
55
- first = false;
56
- const classMatch = pattern.slice(index).match(/^\[:([a-z]+):\]/);
57
- if (classMatch && posixClasses.has(classMatch[1]!)) {
58
- if (previous !== undefined) singles.push(previous);
59
- previous = undefined;
60
- classes.push(classMatch[1]!);
61
- index += classMatch[0].length;
62
- continue;
63
- }
64
-
65
- let character = pattern[index]!;
66
- const escaped = character === "\\";
67
- if (escaped) {
68
- index++;
69
- if (index === pattern.length) return undefined;
70
- character = pattern[index]!;
71
- }
72
-
73
- if (
74
- !escaped &&
75
- character === "-" &&
76
- previous !== undefined &&
77
- pattern[index + 1] !== "]" &&
78
- index + 1 < pattern.length
79
- ) {
80
- index++;
81
-
82
- let end = pattern[index]!;
83
- if (end === "\\") {
84
- index++;
85
- if (index === pattern.length) return undefined;
86
- end = pattern[index]!;
87
- }
88
-
89
- ranges.push([previous, end]);
90
- previous = undefined;
91
- } else {
92
- if (previous !== undefined) singles.push(previous);
93
- previous = character;
94
- }
95
-
96
- index++;
97
- }
98
-
99
- return undefined;
100
- }
101
-
102
- function tokenize(pattern: string): Token[] | undefined {
103
- const tokens: Token[] = [];
104
- for (let index = 0; index < pattern.length;) {
105
- const character = pattern[index]!;
106
- if (character === "\\") {
107
- if (index + 1 === pattern.length) return undefined;
108
- tokens.push({ kind: "literal", value: pattern[index + 1]! });
109
- index += 2;
110
- } else if (character === "[") {
111
- const parsed = characterSet(pattern, index);
112
- if (!parsed) return undefined;
113
-
114
- tokens.push(parsed.token);
115
- index = parsed.end;
116
- } else if (character === "*") {
117
- const start = index;
118
- while (pattern[index] === "*") index++;
119
-
120
- const run = index - start;
121
- const afterBoundary = start === 0 || pattern[start - 1] === "/";
122
- if (run > 1 && afterBoundary && pattern[index] === "/") {
123
- tokens.push({ kind: "directories" });
124
- index++;
125
- } else if (run > 1 && afterBoundary && index === pattern.length)
126
- tokens.push({ kind: "globstar" });
127
- else tokens.push({ kind: "star" });
128
- } else {
129
- tokens.push(character === "?" ? { kind: "any" } : { kind: "literal", value: character });
130
- index++;
131
- }
132
- }
133
-
134
- return tokens;
135
- }
136
-
137
- function bytes(text: string): string {
138
- return Buffer.from(text, "utf8").toString("latin1");
139
- }
140
-
141
- export function parseIgnore(text: string): Rule[] {
142
- const rules: Rule[] = [];
143
- for (let line of bytes(text).split("\n")) {
144
- if (line.endsWith("\r")) line = line.slice(0, -1);
145
- if (!line || line.startsWith("#")) continue;
146
-
147
- let trailing = line.length;
148
- while (trailing > 0 && line[trailing - 1] === " ") {
149
- let slashes = 0;
150
- for (let index = trailing - 2; index >= 0 && line[index] === "\\"; index--) slashes++;
151
-
152
- if (slashes % 2 === 1) break;
153
-
154
- trailing--;
155
- }
156
-
157
- line = line.slice(0, trailing);
158
- if (!line) continue;
159
-
160
- const negated = line.startsWith("!");
161
- if (negated) line = line.slice(1);
162
-
163
- const directory = line.endsWith("/");
164
- if (directory) line = line.slice(0, -1);
165
-
166
- const anchored = line.includes("/");
167
- if (line.startsWith("/")) line = line.slice(1);
168
-
169
- const tokens = tokenize(line);
170
- if (tokens) rules.push({ tokens, anchored, directory, negated });
171
- }
172
-
173
- return rules;
174
- }
175
-
176
- function inClass(name: string, character: string): boolean {
177
- const code = character.charCodeAt(0);
178
- const upper = code >= 65 && code <= 90;
179
- const lower = code >= 97 && code <= 122;
180
- const digit = code >= 48 && code <= 57;
181
- switch (name) {
182
- case "alnum":
183
- return upper || lower || digit;
184
-
185
- case "alpha":
186
- return upper || lower;
187
-
188
- case "blank":
189
- return character === " " || character === "\t";
190
-
191
- case "cntrl":
192
- return code < 32 || code === 127;
193
-
194
- case "digit":
195
- return digit;
196
-
197
- case "graph":
198
- return code >= 33 && code <= 126;
199
-
200
- case "lower":
201
- return lower;
202
-
203
- case "print":
204
- return code >= 32 && code <= 126;
205
-
206
- case "punct":
207
- return code >= 33 && code <= 126 && !upper && !lower && !digit;
208
-
209
- case "space":
210
- return character === " " || (code >= 9 && code <= 13);
211
-
212
- case "upper":
213
- return upper;
214
-
215
- case "xdigit":
216
- return digit || (code >= 65 && code <= 70) || (code >= 97 && code <= 102);
217
- }
218
-
219
- return false;
220
- }
221
-
222
- function matches(tokens: Token[], path: string): boolean {
223
- const length = path.length;
224
-
225
- let next = Array.from({ length: length + 1 }, (_, index) => index === length);
226
- for (let tokenIndex = tokens.length - 1; tokenIndex >= 0; tokenIndex--) {
227
- const token = tokens[tokenIndex]!;
228
- const current = Array<boolean>(length + 1).fill(false);
229
- const throughSlash = Array<boolean>(length + 1).fill(false);
230
- for (let index = length; index >= 0; index--) {
231
- const character = path[index];
232
- if (token.kind === "literal") current[index] = character === token.value && next[index + 1]!;
233
- else if (token.kind === "any")
234
- current[index] = character !== undefined && character !== "/" && next[index + 1]!;
235
- else if (token.kind === "set") {
236
- if (character !== undefined && character !== "/") {
237
- const set = token.value;
238
- const included =
239
- set.singles.includes(character) ||
240
- set.ranges.some(([start, end]) => start <= character && character <= end) ||
241
- set.classes.some((name) => inClass(name, character));
242
-
243
- current[index] = (set.negated ? !included : included) && next[index + 1]!;
244
- }
245
- } else if (token.kind === "directories") {
246
- throughSlash[index] =
247
- character !== undefined &&
248
- ((character === "/" && next[index + 1]!) || throughSlash[index + 1]!);
249
-
250
- current[index] = next[index]! || throughSlash[index]!;
251
- } else
252
- current[index] =
253
- next[index]! ||
254
- (character !== undefined &&
255
- (token.kind === "globstar" || character !== "/") &&
256
- current[index + 1]!);
257
- }
258
-
259
- next = current;
260
- }
261
-
262
- return next[0]!;
263
- }
264
-
265
- export function ignoredByRules(
266
- rules: Rule[],
267
- path: string,
268
- isDirectory: boolean,
269
- ): boolean | undefined {
270
- const target = bytes(path);
271
-
272
- let ignored: boolean | undefined;
273
- for (const rule of rules) {
274
- if (rule.directory && !isDirectory) continue;
275
- if (matches(rule.tokens, rule.anchored ? target : target.slice(target.lastIndexOf("/") + 1)))
276
- ignored = !rule.negated;
277
- }
278
-
279
- return ignored;
280
- }