@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
@@ -1,278 +0,0 @@
1
- import type { Node } from "oxc-parser";
2
- import { children } from "../ast.ts";
3
- import { resolveModule } from "./find.ts";
4
- import {
5
- type Binding,
6
- type ConfigModule,
7
- helper,
8
- memberName,
9
- moduleAt,
10
- nameOf,
11
- requiredSource,
12
- } from "./module.ts";
13
-
14
- export const UNKNOWN = Symbol("unknown");
15
- export const NO_SETTING = Symbol("no setting");
16
- export type Value =
17
- | string
18
- | number
19
- | boolean
20
- | null
21
- | undefined
22
- | typeof UNKNOWN
23
- | typeof NO_SETTING
24
- | Value[]
25
- | { [key: string]: Value };
26
-
27
- const emptyConfigs: Value = new Proxy({}, { get: () => [] });
28
- const js: Value = { configs: { recommended: { rules: {} }, all: { rules: { curly: "error" } } } };
29
- const prettier: Value = { rules: { curly: "off" } };
30
- const KNOWN: { pattern: RegExp; value: Value }[] = [
31
- { pattern: /^eslint:recommended$/, value: {} },
32
- { pattern: /^eslint:all$/, value: { rules: { curly: "error" } } },
33
- { pattern: /^@eslint\/js$/, value: js },
34
- {
35
- pattern: /^typescript-eslint$/,
36
- value: { configs: emptyConfigs },
37
- },
38
- {
39
- pattern:
40
- /^(prettier|eslint-config-prettier(?:\/flat)?|plugin:prettier\/recommended|eslint-plugin-prettier\/recommended)$/,
41
- value: prettier,
42
- },
43
- { pattern: /^eslint\/config$/, value: {} },
44
- ];
45
-
46
- const origins = new WeakMap<object, Map<string, Node>>();
47
-
48
- export function object(value: Value): value is { [key: string]: Value } {
49
- return typeof value === "object" && value !== null && !Array.isArray(value);
50
- }
51
-
52
- export function property(value: Value, key: string): Value {
53
- if (value === undefined || value === NO_SETTING) return value;
54
- return object(value) ? value[key] : UNKNOWN;
55
- }
56
-
57
- export function origin(value: Value, key: string): Node | undefined {
58
- return object(value) ? origins.get(value)?.get(key) : undefined;
59
- }
60
-
61
- export function known(name: string): Value {
62
- const preset = KNOWN.find((entry) => entry.pattern.test(name));
63
- if (preset) return preset.value;
64
-
65
- const parts = name.split("/");
66
- const packageName = parts.slice(0, name.startsWith("@") ? 2 : 1).join("/");
67
- return name.startsWith("plugin:") ||
68
- /^eslint-plugin-|^@[^/]+\/eslint-plugin(-.*)?$/.test(packageName)
69
- ? NO_SETTING
70
- : undefined;
71
- }
72
-
73
- function bindingValue(binding: Binding | undefined, module: ConfigModule, chain: string[]): Value {
74
- if (!binding || binding.mutable) return UNKNOWN;
75
- if (binding.resolved) return binding.value;
76
-
77
- binding.resolved = true;
78
- binding.value = UNKNOWN;
79
-
80
- let value: Value;
81
- if (binding.imported) {
82
- const preset = known(binding.imported.source);
83
- const file =
84
- preset === undefined
85
- ? resolveModule(binding.imported.source, module.file, binding.imported.loader)
86
- : undefined;
87
-
88
- value =
89
- preset !== undefined
90
- ? binding.imported.name === "default" || binding.imported.name === "*"
91
- ? preset
92
- : property(preset, binding.imported.name)
93
- : file
94
- ? exported(file, binding.imported.name, chain)
95
- : UNKNOWN;
96
- } else if (binding.local) value = bindingValue(module.bindings.get(binding.local), module, chain);
97
- else value = binding.node ? evaluate(binding.node, module, chain) : UNKNOWN;
98
-
99
- binding.value = value;
100
- return value;
101
- }
102
-
103
- export function exported(file: string, name: string, chain: string[] = []): Value {
104
- const module = moduleAt(file);
105
- if (
106
- !module ||
107
- !module.program ||
108
- module.mutated ||
109
- chain.includes(module.file) ||
110
- chain.length >= 32
111
- )
112
- return UNKNOWN;
113
-
114
- if (module.values.has(name)) return module.values.get(name);
115
-
116
- const next = [...chain, module.file];
117
-
118
- let value: Value;
119
- if (name === "*") {
120
- const namespace: { [key: string]: Value } = {};
121
- for (const key of module.exports.keys())
122
- Object.defineProperty(namespace, key, {
123
- enumerable: true,
124
- configurable: true,
125
- get: () => exported(file, key, chain),
126
- });
127
-
128
- value = namespace;
129
- } else value = bindingValue(module.exports.get(name), module, next);
130
-
131
- module.values.set(name, value);
132
- return value;
133
- }
134
-
135
- function objectValue(
136
- node: Extract<Node, { type: "ObjectExpression" }>,
137
- module: ConfigModule,
138
- chain: string[],
139
- ): Value {
140
- const result: { [key: string]: Value } = Object.create(null);
141
- const locations = new Map<string, Node>();
142
- for (const item of node.properties)
143
- if (item.type === "SpreadElement") {
144
- const value = evaluate(item.argument, module, chain);
145
- if (value === NO_SETTING) continue;
146
- if (!object(value)) return UNKNOWN;
147
-
148
- for (const key of Object.keys(value))
149
- Object.defineProperty(result, key, {
150
- enumerable: true,
151
- configurable: true,
152
- get: () => value[key],
153
- });
154
-
155
- for (const [key, location] of origins.get(value) ?? []) locations.set(key, location);
156
- } else {
157
- const key = !item.computed && nameOf(item.key);
158
- if (!key) return UNKNOWN;
159
-
160
- let value: Value;
161
- let resolved = false;
162
- Object.defineProperty(result, key, {
163
- enumerable: true,
164
- configurable: true,
165
- get: () => {
166
- if (!resolved) {
167
- resolved = true;
168
- value = UNKNOWN;
169
- value =
170
- item.method || item.kind !== "init" ? UNKNOWN : evaluate(item.value, module, chain);
171
- }
172
-
173
- return value;
174
- },
175
- });
176
-
177
- locations.set(key, item);
178
- }
179
-
180
- origins.set(result, locations);
181
- return result;
182
- }
183
-
184
- export function evaluate(node: Node, module: ConfigModule, chain: string[]): Value {
185
- switch (node.type) {
186
- case "Literal":
187
- return typeof node.value === "bigint" ||
188
- (typeof node.value === "object" && node.value !== null)
189
- ? UNKNOWN
190
- : node.value;
191
-
192
- case "TemplateLiteral":
193
- return node.expressions.length === 0 ? node.quasis[0]?.value.cooked : UNKNOWN;
194
-
195
- case "ObjectExpression":
196
- return objectValue(node, module, chain);
197
-
198
- case "ArrayExpression": {
199
- if (node.elements.length > 10000) return UNKNOWN;
200
-
201
- const result: Value[] = [];
202
- for (const item of node.elements) {
203
- const value = item
204
- ? evaluate(item.type === "SpreadElement" ? item.argument : item, module, chain)
205
- : UNKNOWN;
206
-
207
- if (item?.type === "SpreadElement") {
208
- if (value === NO_SETTING) continue;
209
- if (!Array.isArray(value)) return UNKNOWN;
210
- if (result.length + value.length > 10000) return UNKNOWN;
211
-
212
- result.push(...value);
213
- } else result.push(value);
214
-
215
- if (result.length > 10000) return UNKNOWN;
216
- }
217
-
218
- return result;
219
- }
220
-
221
- case "Identifier":
222
- return bindingValue(module.bindings.get(node.name), module, chain);
223
-
224
- case "MemberExpression": {
225
- const value = evaluate(node.object, module, chain);
226
- if (value === NO_SETTING) return value;
227
-
228
- const key = memberName(node);
229
- return key === undefined ? UNKNOWN : property(value, key);
230
- }
231
-
232
- case "CallExpression": {
233
- const name = requiredSource(node);
234
- if (name !== undefined) {
235
- const preset = known(name);
236
- const file = preset === undefined ? resolveModule(name, module.file, "require") : undefined;
237
- return preset !== undefined ? preset : file ? exported(file, "default", chain) : UNKNOWN;
238
- }
239
-
240
- const kind = helper(node.callee, module);
241
- if (kind === "ignore") return {};
242
- if (kind === "identity")
243
- return node.arguments.length === 1 ? evaluate(node.arguments[0]!, module, chain) : UNKNOWN;
244
-
245
- if (kind === "flatten") {
246
- const result = node.arguments.flatMap((item): Value[] => {
247
- const value = evaluate(
248
- item.type === "SpreadElement" ? item.argument : item,
249
- module,
250
- chain,
251
- );
252
-
253
- return Array.isArray(value) ? value : [value];
254
- });
255
-
256
- return result.length > 10000 ? UNKNOWN : result;
257
- }
258
-
259
- return UNKNOWN;
260
- }
261
-
262
- default:
263
- if (
264
- [
265
- "TSAsExpression",
266
- "TSSatisfiesExpression",
267
- "TSNonNullExpression",
268
- "TSTypeAssertion",
269
- "ParenthesizedExpression",
270
- ].includes(node.type)
271
- ) {
272
- const expression = children(node).find(([key]) => key === "expression")?.[1];
273
- return expression ? evaluate(expression, module, chain) : UNKNOWN;
274
- }
275
-
276
- return UNKNOWN;
277
- }
278
- }
@@ -1,105 +0,0 @@
1
- import { readFileSync, realpathSync, statSync } from "node:fs";
2
- import { dirname, isAbsolute, join, resolve } from "node:path";
3
- import { holds } from "../../../directories.ts";
4
-
5
- const suffixes = ["", ".json", ".jsonc", ".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", "/index.js"];
6
-
7
- const directoryFiles = new Map<string, string[]>();
8
-
9
- function fileAt(path: string): string | undefined {
10
- for (const suffix of suffixes) {
11
- try {
12
- const candidate = path + suffix;
13
- if (statSync(candidate).isFile()) return candidate;
14
- } catch {}
15
- }
16
-
17
- if (path.endsWith(".js"))
18
- return fileAt(path.slice(0, -3) + ".ts") ?? fileAt(path.slice(0, -3) + ".mts");
19
-
20
- return undefined;
21
- }
22
-
23
- export type Loader = "import" | "require";
24
-
25
- function entryOf(value: unknown, loader: Loader): string | undefined {
26
- if (typeof value === "string") return value;
27
-
28
- if (value && typeof value === "object" && !Array.isArray(value))
29
- for (const [key, target] of Object.entries(value))
30
- if (key === loader || key === "node" || key === "default") {
31
- const entry = entryOf(target, loader);
32
- if (entry !== undefined) return entry;
33
- }
34
-
35
- return undefined;
36
- }
37
-
38
- export function resolveModule(specifier: string, from: string, loader: Loader): string | undefined {
39
- let dir: string;
40
- try {
41
- dir = dirname(realpathSync(from));
42
- } catch {
43
- return undefined;
44
- }
45
-
46
- if (specifier.startsWith(".") || isAbsolute(specifier))
47
- return fileAt(resolve(dirname(from), specifier));
48
-
49
- const parts = specifier.split("/");
50
- const name = parts.splice(0, specifier.startsWith("@") ? 2 : 1).join("/");
51
- const subpath = parts.join("/");
52
- while (true) {
53
- const root = join(dir, "node_modules", name);
54
- try {
55
- const manifest: unknown = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
56
- if (!manifest || typeof manifest !== "object") return undefined;
57
-
58
- const exports: unknown = Reflect.get(manifest, "exports");
59
- const target =
60
- exports && typeof exports === "object"
61
- ? Reflect.get(exports, subpath ? `./${subpath}` : ".")
62
- : subpath
63
- ? undefined
64
- : exports;
65
-
66
- const entry = entryOf(target, loader) ?? (!subpath ? entryOf(exports, loader) : undefined);
67
- const main: unknown = Reflect.get(manifest, "main");
68
- return fileAt(
69
- join(root, entry ?? (subpath || (typeof main === "string" ? main : "index.js"))),
70
- );
71
- } catch {}
72
-
73
- const parent = dirname(dir);
74
- if (parent === dir) return undefined;
75
-
76
- dir = parent;
77
- }
78
- }
79
-
80
- export function* configDirectories(
81
- dir: string,
82
- reader: { family: string; files: readonly string[]; candidate?(file: string): boolean },
83
- ): Generator<string[]> {
84
- while (true) {
85
- const key = `${reader.family}:${dir}`;
86
-
87
- let files = directoryFiles.get(key);
88
- if (!files) {
89
- const current = dir;
90
- files = reader.files
91
- .filter((name) => holds(current, name))
92
- .map((name) => join(current, name))
93
- .filter((file) => reader.candidate?.(file) ?? true);
94
-
95
- directoryFiles.set(key, files);
96
- }
97
-
98
- yield files;
99
-
100
- const parent = dirname(dir);
101
- if (parent === dir) break;
102
-
103
- dir = parent;
104
- }
105
- }
@@ -1,149 +0,0 @@
1
- import { extname } from "node:path";
2
- import type { Reach } from "./layers.ts";
3
- import { entry } from "../entry.ts";
4
-
5
- interface CompiledGlob {
6
- directory: RegExp;
7
- filenames: Reach[];
8
- }
9
-
10
- interface PatternList {
11
- positive: CompiledGlob[];
12
- uncertain: boolean;
13
- negated: boolean;
14
- reaches: Map<string, Reach>;
15
- }
16
-
17
- const compiled = new Map<string, CompiledGlob>();
18
- const lists = new Map<string, PatternList>();
19
- const identities = new WeakMap<string[], Map<boolean, PatternList>>();
20
- const allExtensions = [...entry.extensions];
21
-
22
- const expansionLimit = 256;
23
- function expand(pattern: string, limit = expansionLimit): string[] | undefined {
24
- const match = /\{([^{}]+)\}/.exec(pattern);
25
- if (!match) return [pattern];
26
-
27
- const result: string[] = [];
28
- for (const part of match[1]!.split(",")) {
29
- const expanded = expand(
30
- pattern.slice(0, match.index) + part + pattern.slice(match.index + match[0].length),
31
- limit - result.length,
32
- );
33
-
34
- if (!expanded || result.length + expanded.length > limit) return undefined;
35
-
36
- result.push(...expanded);
37
- }
38
-
39
- return result;
40
- }
41
-
42
- function filenameReach(pattern: string, extension: string): Reach {
43
- if (pattern === "*" || pattern === "**" || pattern === `*${extension}`) return "all";
44
- if (!pattern.includes("*")) return extname(pattern) === extension ? "some" : "none";
45
-
46
- const ending = pattern.slice(pattern.lastIndexOf("*") + 1);
47
- if (ending.includes(".") && !ending.endsWith(extension) && !extension.endsWith(ending))
48
- return "none";
49
-
50
- return "some";
51
- }
52
-
53
- function compile(pattern: string): CompiledGlob {
54
- const cached = compiled.get(pattern);
55
- if (cached) return cached;
56
-
57
- const segments = pattern.split("/");
58
- const filename = segments.pop()!;
59
- if (filename === "**") segments.push("**");
60
-
61
- const source = segments
62
- .map((segment) =>
63
- segment === "**"
64
- ? "(?:[^/]+/)*"
65
- : `${segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*")}/`,
66
- )
67
- .join("");
68
-
69
- const glob = {
70
- directory: new RegExp(`^${source}$`),
71
- filenames: allExtensions.map((extension) => filenameReach(filename, extension)),
72
- };
73
-
74
- compiled.set(pattern, glob);
75
- return glob;
76
- }
77
-
78
- function patternList(patterns: string[], legacy: boolean): PatternList {
79
- const byMode = identities.get(patterns) ?? new Map<boolean, PatternList>();
80
- const cached = byMode.get(legacy);
81
- if (cached) return cached;
82
-
83
- const key = JSON.stringify([patterns, legacy]);
84
-
85
- let list = lists.get(key);
86
- if (!list) {
87
- let expanded: string[] | undefined = [];
88
- for (const pattern of patterns.filter((item) => !item.startsWith("!"))) {
89
- const alternatives: string[] | undefined = expand(pattern, expansionLimit - expanded.length);
90
- expanded = alternatives && [...expanded, ...alternatives];
91
- if (!expanded) break;
92
- }
93
-
94
- const uncertain =
95
- !expanded || patterns.some((pattern) => /[?[\]()+@!]/.test(pattern.replace(/^!/, "")));
96
-
97
- const positive =
98
- !expanded || uncertain
99
- ? []
100
- : expanded.map((input) => {
101
- const pattern = input.replace(/^\.\//, "");
102
- if (legacy && !pattern.includes("*"))
103
- return { directory: /.*/, filenames: allExtensions.map((): Reach => "some") };
104
-
105
- return compile(legacy && !pattern.includes("/") ? `**/${pattern}` : pattern);
106
- });
107
-
108
- list = {
109
- positive,
110
- uncertain,
111
- negated: patterns.some((pattern) => pattern.startsWith("!")),
112
- reaches: new Map(),
113
- };
114
-
115
- lists.set(key, list);
116
- }
117
-
118
- byMode.set(legacy, list);
119
- identities.set(patterns, byMode);
120
- return list;
121
- }
122
-
123
- export function globReach(
124
- patterns: string[],
125
- relDir: string,
126
- legacy: boolean,
127
- extension?: string,
128
- ): Reach {
129
- const list = patternList(patterns, legacy);
130
- const key = `${relDir}\0${extension ?? ""}`;
131
- const cached = list.reaches.get(key);
132
- if (cached) return cached;
133
-
134
- const index = extension === undefined ? -1 : allExtensions.indexOf(extension);
135
- const considered = index === -1 ? allExtensions.map((_, at) => at) : [index];
136
-
137
- let reach: Reach;
138
- if (list.uncertain) reach = "some";
139
- else {
140
- const dir = relDir ? `${relDir}/` : "";
141
- const matching = list.positive.filter((glob) => glob.directory.test(dir));
142
- const all = considered.every((at) => matching.some((glob) => glob.filenames[at] === "all"));
143
- const some = matching.some((glob) => considered.some((at) => glob.filenames[at] !== "none"));
144
- reach = all && !list.negated ? "all" : some ? "some" : "none";
145
- }
146
-
147
- list.reaches.set(key, reach);
148
- return reach;
149
- }
@@ -1,48 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { biome } from "./biome.ts";
3
- import { flat, legacy } from "./eslint.ts";
4
- import { realDirectory } from "../../../directories.ts";
5
- import type { Decision, Reader } from "./layers.ts";
6
- import { oxlint } from "./oxlint.ts";
7
-
8
- const READERS: Reader[] = [flat, legacy, biome, oxlint];
9
-
10
- export interface BracesSetting {
11
- enforced: boolean;
12
- unread: string[];
13
- }
14
-
15
- const cache = new Map<string, BracesSetting>();
16
-
17
- export function braceDecisions(dir: string, extension?: string): Decision[] {
18
- dir = realDirectory(resolve(dir));
19
- return READERS.map((reader) => reader.decide(dir, extension)).filter(
20
- (decision) => decision !== null,
21
- );
22
- }
23
-
24
- export function bracesSetting(dir: string, extension?: string): BracesSetting {
25
- const requested = `${dir}\0${extension ?? ""}`;
26
- const cached = cache.get(requested);
27
- if (cached !== undefined) return cached;
28
-
29
- let result: BracesSetting = { enforced: true, unread: [] };
30
- try {
31
- const decisions = braceDecisions(dir, extension);
32
- const enforced = decisions.some((decision) => decision.setting !== "off");
33
- const unread = decisions.some((decision) => decision.setting === "on")
34
- ? []
35
- : decisions
36
- .filter((decision) => decision.setting === "unknown")
37
- .flatMap((decision) => decision.files);
38
-
39
- result = { enforced, unread };
40
- } catch {}
41
-
42
- cache.set(requested, result);
43
- return result;
44
- }
45
-
46
- export function bracesEnforced(dir: string, extension?: string): boolean {
47
- return bracesSetting(dir, extension).enforced;
48
- }