@ryuugg/stanza 0.3.2 → 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 -659
  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 -368
  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 -332
  19. package/src/engine/gaps.ts +0 -357
  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 -103
  24. package/src/engine/types.ts +0 -38
  25. package/src/files.ts +0 -975
  26. package/src/format.ts +0 -159
  27. package/src/gitignore.ts +0 -280
  28. package/src/hook.ts +0 -365
  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 -312
  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 -4
@@ -1,327 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { realPath } from "../../../directories.ts";
3
- import type { Node, Program } from "oxc-parser";
4
- import { boundNames, children, declared, referenceChild, walk } from "../ast.ts";
5
- import { parse } from "../parse.ts";
6
- import type { Value } from "./evaluate.ts";
7
- import type { Loader } from "./find.ts";
8
-
9
- export interface Binding {
10
- node?: Node;
11
- imported?: { source: string; name: string; loader: Loader };
12
- local?: string;
13
- mutable?: boolean;
14
- value?: Value;
15
- resolved?: boolean;
16
- }
17
-
18
- export interface ConfigModule {
19
- file: string;
20
- text: string;
21
- program?: Program;
22
- yaml: boolean;
23
- mutated: boolean;
24
- bindings: Map<string, Binding>;
25
- exports: Map<string, Binding>;
26
- values: Map<string, Value>;
27
- }
28
-
29
- const modules = new Map<string, ConfigModule | null>();
30
-
31
- export function nameOf(node: Node): string | undefined {
32
- if (node.type === "Identifier") return node.name;
33
- if (node.type === "Literal" && typeof node.value === "string") return node.value;
34
- return undefined;
35
- }
36
-
37
- export function memberName(node: Node): string | undefined {
38
- return node.type === "MemberExpression" && (!node.computed || node.property.type === "Literal")
39
- ? nameOf(node.property)
40
- : undefined;
41
- }
42
-
43
- function rootName(node: Node): string | undefined {
44
- if (node.type === "MemberExpression") return rootName(node.object);
45
- return node.type === "Identifier" ? node.name : undefined;
46
- }
47
-
48
- const FUNCTION_TYPES = new Set([
49
- "FunctionDeclaration",
50
- "FunctionExpression",
51
- "ArrowFunctionExpression",
52
- ]);
53
-
54
- function varNames(body: Node): string[] {
55
- const names: string[] = [];
56
- const stack = [body];
57
- while (stack.length > 0) {
58
- const node = stack.pop()!;
59
- if (FUNCTION_TYPES.has(node.type)) continue;
60
- if (node.type === "VariableDeclaration" && node.kind === "var") names.push(...boundNames(node));
61
-
62
- for (const [, child] of children(node)) stack.push(child);
63
- }
64
-
65
- return names;
66
- }
67
-
68
- function scopeNames(node: Node): string[] {
69
- if (node.type === "ClassExpression") return node.id ? [node.id.name] : [];
70
- if (node.type !== "FunctionExpression" && node.type !== "ArrowFunctionExpression")
71
- return declared(node);
72
-
73
- const params = node.params.flatMap((param) => [...boundNames(param)]);
74
- const locals = [...params, ...(node.body ? varNames(node.body) : [])];
75
- return node.type === "FunctionExpression" && node.id ? [node.id.name, ...locals] : locals;
76
- }
77
-
78
- function dirtyReferences(root: Node, dirty: Set<string>, scanned: Set<Node>): void {
79
- const stack = [{ node: root, shadowed: new Set<string>() }];
80
- while (stack.length > 0) {
81
- const { node, shadowed } = stack.pop()!;
82
- if (scanned.has(node)) continue;
83
-
84
- scanned.add(node);
85
-
86
- if (node.type === "Identifier") {
87
- if (!shadowed.has(node.name)) dirty.add(node.name);
88
- continue;
89
- }
90
-
91
- const names = scopeNames(node);
92
- const visible = names.length === 0 ? shadowed : shadowed.union(new Set(names));
93
- for (const [key, child] of children(node))
94
- if (referenceChild(node, key)) stack.push({ node: child, shadowed: visible });
95
- }
96
- }
97
-
98
- function exportName(node: Node): string | undefined {
99
- if (node.type !== "MemberExpression") return undefined;
100
-
101
- if (
102
- node.object.type === "Identifier" &&
103
- node.object.name === "module" &&
104
- memberName(node) === "exports"
105
- )
106
- return "default";
107
-
108
- if (node.object.type === "Identifier" && node.object.name === "exports") return memberName(node);
109
-
110
- return undefined;
111
- }
112
-
113
- type HelperKind = "flatten" | "identity" | "ignore";
114
-
115
- const HELPERS: { source: string; name: string; kind: HelperKind }[] = [
116
- { source: "eslint/config", name: "defineConfig", kind: "flatten" },
117
- { source: "eslint/config", name: "globalIgnores", kind: "ignore" },
118
- { source: "eslint-define-config", name: "defineConfig", kind: "flatten" },
119
- { source: "typescript-eslint", name: "config", kind: "flatten" },
120
- { source: "@eslint/compat", name: "includeIgnoreFile", kind: "ignore" },
121
- { source: "oxlint", name: "defineConfig", kind: "identity" },
122
- ];
123
-
124
- export function requiredSource(node: Node): string | undefined {
125
- return node.type === "CallExpression" &&
126
- node.callee.type === "Identifier" &&
127
- node.callee.name === "require" &&
128
- node.arguments[0]?.type === "Literal" &&
129
- typeof node.arguments[0].value === "string"
130
- ? node.arguments[0].value
131
- : undefined;
132
- }
133
-
134
- export function helper(node: Node, module: ConfigModule): HelperKind | undefined {
135
- const local = node.type === "MemberExpression" ? node.object : node;
136
- if (local.type !== "Identifier") return undefined;
137
-
138
- const binding = module.bindings.get(local.name);
139
- const imported = binding?.imported;
140
- if (binding?.mutable || !imported) return undefined;
141
-
142
- const name = node.type === "MemberExpression" ? memberName(node) : imported.name;
143
- const namespace = node.type !== "MemberExpression" || ["default", "*"].includes(imported.name);
144
- if (!namespace) return undefined;
145
-
146
- return HELPERS.find((entry) => entry.source === imported.source && entry.name === name)?.kind;
147
- }
148
-
149
- function indexModule(module: ConfigModule): void {
150
- if (!module.program) return;
151
-
152
- const dirty = new Set<string>();
153
- const scanned = new Set<Node>();
154
- const aliases: [string, string][] = [];
155
- const assignments = new Map<string, Node[]>();
156
- for (const statement of module.program.body) {
157
- const node = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
158
- if (node?.type === "VariableDeclaration")
159
- for (const declaration of node.declarations) {
160
- const source =
161
- node.kind === "const" && declaration.init && requiredSource(declaration.init);
162
-
163
- if (declaration.id.type === "ObjectPattern" && source)
164
- for (const property of declaration.id.properties) {
165
- const imported =
166
- property.type === "Property" && !property.computed && nameOf(property.key);
167
-
168
- if (imported && property.value.type === "Identifier")
169
- module.bindings.set(property.value.name, {
170
- imported: { source, name: imported, loader: "require" },
171
- });
172
- }
173
-
174
- if (declaration.id.type !== "Identifier") continue;
175
-
176
- const name = declaration.id.name;
177
- module.bindings.set(
178
- name,
179
- source
180
- ? { imported: { source, name: "default", loader: "require" } }
181
- : { node: declaration.init ?? undefined, mutable: node.kind !== "const" },
182
- );
183
-
184
- if (statement.type === "ExportNamedDeclaration") module.exports.set(name, { local: name });
185
-
186
- const alias = declaration.init && rootName(declaration.init);
187
- if (alias) aliases.push([name, alias]);
188
- }
189
-
190
- if (statement.type === "ImportDeclaration")
191
- for (const specifier of statement.specifiers)
192
- module.bindings.set(specifier.local.name, {
193
- imported: {
194
- source: statement.source.value,
195
- name:
196
- specifier.type === "ImportDefaultSpecifier"
197
- ? "default"
198
- : specifier.type === "ImportNamespaceSpecifier"
199
- ? "*"
200
- : (nameOf(specifier.imported) ?? ""),
201
- loader: "import",
202
- },
203
- });
204
-
205
- if (statement.type === "ExportDefaultDeclaration")
206
- module.exports.set("default", { node: statement.declaration });
207
-
208
- if (statement.type === "ExportNamedDeclaration")
209
- for (const specifier of statement.specifiers)
210
- module.exports.set(
211
- nameOf(specifier.exported) ?? "",
212
- statement.source ? { mutable: true } : { local: nameOf(specifier.local) },
213
- );
214
-
215
- if (
216
- statement.type === "ExpressionStatement" &&
217
- statement.expression.type === "AssignmentExpression"
218
- ) {
219
- const assignment = statement.expression;
220
- const name = exportName(assignment.left);
221
- if (name !== undefined && assignment.operator === "=") {
222
- const previous = assignments.get(name) ?? [];
223
- previous.push(assignment);
224
- assignments.set(name, previous);
225
- module.exports.set(name, { node: assignment.right });
226
- }
227
- }
228
- }
229
-
230
- const permitted = new Set([...assignments.values()].filter((items) => items.length === 1).flat());
231
-
232
- let mutated = false;
233
- walk(module.program, (node) => {
234
- const target =
235
- node.type === "AssignmentExpression"
236
- ? node.left
237
- : node.type === "UpdateExpression"
238
- ? node.argument
239
- : node.type === "UnaryExpression" && node.operator === "delete"
240
- ? node.argument
241
- : undefined;
242
-
243
- if (target) {
244
- if (permitted.has(node)) return;
245
- if (target.type === "MemberExpression" || node.type === "UpdateExpression") mutated = true;
246
-
247
- const root = rootName(target);
248
- if (root) dirty.add(root);
249
- }
250
-
251
- if (node.type !== "CallExpression" && node.type !== "NewExpression") return;
252
- if (!helper(node.callee, module) && !requiredSource(node))
253
- for (const argument of node.arguments) dirtyReferences(argument, dirty, scanned);
254
-
255
- if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression") return;
256
-
257
- const callee = node.callee;
258
- const root = rootName(callee.object);
259
- if (
260
- root === "Reflect" ||
261
- (root === "Object" &&
262
- ["assign", "defineProperty", "defineProperties", "setPrototypeOf"].includes(
263
- memberName(callee) ?? "",
264
- ))
265
- )
266
- mutated = true;
267
-
268
- if (root && !helper(callee, module)) dirty.add(root);
269
- });
270
-
271
- if (mutated) {
272
- module.mutated = true;
273
-
274
- for (const binding of [...module.bindings.values(), ...module.exports.values()])
275
- binding.mutable = true;
276
-
277
- module.exports.set("default", { mutable: true });
278
- return;
279
- }
280
-
281
- for (let index = 0; index < aliases.length; index++)
282
- for (const [left, right] of aliases)
283
- if (dirty.has(left) || dirty.has(right)) {
284
- dirty.add(left);
285
- dirty.add(right);
286
- }
287
-
288
- for (const name of dirty) {
289
- const binding = module.bindings.get(name);
290
- if (binding) binding.mutable = true;
291
- }
292
-
293
- if (dirty.has("module") || dirty.has("exports")) module.exports.set("default", { mutable: true });
294
- }
295
-
296
- export function moduleAt(file: string): ConfigModule | null {
297
- try {
298
- file = realPath(file);
299
- if (modules.has(file)) return modules.get(file) ?? null;
300
-
301
- const text = readFileSync(file, "utf8");
302
- const script = /\.[cm]?[jt]s$/.test(file);
303
- const parsed = parse(script ? file : `${file}.js`, script ? text : `(${text}\n)`);
304
- const yaml = /\.ya?ml$/.test(file) || (file.endsWith(".eslintrc") && parsed.errors.length > 0);
305
- const module: ConfigModule = {
306
- file,
307
- text,
308
- program: parsed.errors.length ? undefined : parsed.program,
309
- yaml,
310
- mutated: false,
311
- bindings: new Map(),
312
- exports: new Map(),
313
- values: new Map(),
314
- };
315
-
316
- modules.set(file, module);
317
-
318
- if (script) indexModule(module);
319
- else if (module.program?.body[0]?.type === "ExpressionStatement")
320
- module.exports.set("default", { node: module.program.body[0].expression });
321
-
322
- return module;
323
- } catch {
324
- modules.set(file, null);
325
- return null;
326
- }
327
- }
@@ -1,170 +0,0 @@
1
- import { UNKNOWN, NO_SETTING, type Value, exported, object, property } from "./evaluate.ts";
2
- import { configDirectories, resolveModule } from "./find.ts";
3
- import { moduleAt } from "./module.ts";
4
- import {
5
- type Context,
6
- type Coverage,
7
- type Layer,
8
- type Reader,
9
- type Setting,
10
- UNKNOWN_LAYER,
11
- configAt,
12
- decided,
13
- excluding,
14
- expanded,
15
- intersectCoverage,
16
- lastLayers,
17
- patterns,
18
- read,
19
- } from "./layers.ts";
20
-
21
- function scope(value: Value, context: Context): Coverage {
22
- const reach = patterns(property(value, "files"), context, "legacy");
23
- return excluding(reach, property(value, "excludeFiles"), context, "legacy");
24
- }
25
-
26
- function oxlintLevel(value: Value): Setting {
27
- const seen = new Set<Value>();
28
- while (!seen.has(value)) {
29
- if (value === "off" || value === "allow" || value === 0) return "off";
30
- if (value === "warn" || value === "error" || value === "deny" || value === 1 || value === 2)
31
- return "on";
32
-
33
- if (typeof value === "string" || typeof value === "number") return "unknown";
34
-
35
- seen.add(value);
36
-
37
- if (Array.isArray(value)) value = value[0];
38
- else return "unknown";
39
- }
40
-
41
- return "unknown";
42
- }
43
-
44
- type OxlintPhase = "categories" | "rules" | "overrides";
45
-
46
- function oxlintOwnLayers(value: Value, context: Context, phase: OxlintPhase): Layer[] {
47
- if (value === UNKNOWN) return [UNKNOWN_LAYER];
48
-
49
- if (phase === "categories") {
50
- const style = read(read(value, "categories", context), "style", context);
51
- return style === undefined || style === NO_SETTING
52
- ? []
53
- : [{ reach: "all", setting: oxlintLevel(style) }];
54
- }
55
-
56
- if (phase === "rules") {
57
- const rules = read(value, "rules", context);
58
- if (!object(rules)) return rules === undefined || rules === NO_SETTING ? [] : [UNKNOWN_LAYER];
59
-
60
- let setting: Setting | undefined;
61
- for (const key of Object.keys(rules))
62
- if (key === "curly" || key === "eslint/curly")
63
- setting = oxlintLevel(read(rules, key, context));
64
-
65
- return setting === undefined ? [] : [{ reach: "all", setting }];
66
- }
67
-
68
- const overrides = property(value, "overrides");
69
- if (overrides === undefined) return [];
70
- if (!Array.isArray(overrides)) return [UNKNOWN_LAYER];
71
-
72
- return lastLayers(
73
- overrides.flatMap((item) => {
74
- const reach = scope(item, context);
75
- return oxlintOwnLayers(item, context, "rules").map((layer) => ({
76
- ...layer,
77
- reach: intersectCoverage(layer.reach, reach),
78
- }));
79
- }),
80
- );
81
- }
82
-
83
- interface OxlintValue {
84
- value: Value;
85
- context: Context;
86
- }
87
-
88
- function oxlintExtends(value: Value, context: Context): OxlintValue[] | null {
89
- const inherited = property(value, "extends");
90
- if (inherited === undefined) return [];
91
- if (!Array.isArray(inherited)) return null;
92
-
93
- const result: OxlintValue[] = [];
94
- for (const entry of inherited) {
95
- if (typeof entry !== "string") {
96
- result.push({ value: entry, context: { ...context, shared: true } });
97
- continue;
98
- }
99
-
100
- if (!entry.startsWith(".")) return null;
101
-
102
- const file = resolveModule(entry, context.file, "import");
103
- const module = file && moduleAt(file);
104
- if (!module || context.chain.includes(module.file)) return null;
105
-
106
- context.modules.add(module);
107
-
108
- result.push({
109
- value: exported(module.file, "default", context.chain),
110
- context: {
111
- ...context,
112
- file: module.file,
113
- shared: true,
114
- chain: [...context.chain, module.file],
115
- },
116
- });
117
- }
118
-
119
- return result;
120
- }
121
-
122
- function oxlintLayers(value: Value, context: Context): Layer[] {
123
- return lastLayers(
124
- (["categories", "rules", "overrides"] as const).flatMap((phase) =>
125
- oxlintPhaseLayers(value, context, phase),
126
- ),
127
- );
128
- }
129
-
130
- function oxlintPhaseLayers(value: Value, context: Context, phase: OxlintPhase): Layer[] {
131
- if (value === NO_SETTING) return [];
132
- if (context.work.exceeded) return [UNKNOWN_LAYER];
133
- if (context.ancestors.includes(value)) {
134
- context.work.cycles++;
135
- return [UNKNOWN_LAYER];
136
- }
137
-
138
- return expanded(value, context, phase, () => {
139
- if (value === UNKNOWN || !object(value)) return [UNKNOWN_LAYER];
140
-
141
- const next = { ...context, ancestors: [...context.ancestors, value] };
142
- const entries = oxlintExtends(value, next);
143
- if (!entries) return [UNKNOWN_LAYER];
144
-
145
- return lastLayers([
146
- ...entries.flatMap((entry) => oxlintPhaseLayers(entry.value, entry.context, phase)),
147
- ...oxlintOwnLayers(value, next, phase),
148
- ]);
149
- });
150
- }
151
-
152
- export const oxlint: Reader = {
153
- family: "oxlint",
154
- files: [".oxlintrc.json", ".oxlintrc.jsonc", "oxlint.config.ts", "oxlint.config.mts"],
155
- backstop: ["curly", "eslint/curly", "style"],
156
- backstopImports: true,
157
- layers: oxlintLayers,
158
- decide(dir, extension) {
159
- for (const files of configDirectories(dir, oxlint)) {
160
- if (files.length > 1) return { family: oxlint.family, setting: "unknown", files };
161
-
162
- const file = files[0];
163
- if (file === undefined) continue;
164
-
165
- return decided(oxlint, configAt(file, dir, extension, oxlint));
166
- }
167
-
168
- return null;
169
- },
170
- };