@stillwind/analysis 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/browser.d.ts +141 -0
- package/dist/browser.js +342 -0
- package/dist/browser.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/memory.d.ts +52 -0
- package/dist/memory.js +113 -0
- package/dist/memory.js.map +1 -0
- package/dist/node.d.ts +152 -0
- package/dist/node.js +510 -0
- package/dist/node.js.map +1 -0
- package/dist/reports-BKeFV47o.d.ts +12 -0
- package/dist/reports-nlgN4YL4.js +21 -0
- package/dist/reports-nlgN4YL4.js.map +1 -0
- package/dist/rewrite-Bdo2ssmD.js +155 -0
- package/dist/rewrite-Bdo2ssmD.js.map +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +78 -0
- package/dist/worker.js.map +1 -0
- package/dist/workspace-BF46yPpm.d.ts +149 -0
- package/package.json +51 -3
package/dist/node.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { t as lintReports } from "./reports-nlgN4YL4.js";
|
|
2
|
+
import { t as RewriteFailure } from "./rewrite-Bdo2ssmD.js";
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { findConfiguration } from "@stillwind/config/node";
|
|
6
|
+
import { fork } from "node:child_process";
|
|
7
|
+
import process$1 from "node:process";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
// src/worker-client.ts
|
|
10
|
+
/** Isolates configuration and plugin logs from CLI JSON and the LSP stdout transport. */
|
|
11
|
+
var AnalysisWorker = class {
|
|
12
|
+
/** Owned child with IPC enabled. Both output streams are forwarded to the parent's stderr. */
|
|
13
|
+
#child;
|
|
14
|
+
/** Unanswered requests keyed by monotonically assigned IPC sequence number. */
|
|
15
|
+
#pending = /* @__PURE__ */ new Map();
|
|
16
|
+
/** Resolves on process closure after outstanding requests have been rejected. */
|
|
17
|
+
#closed;
|
|
18
|
+
/** Next IPC sequence number, independent of source document versions. */
|
|
19
|
+
#nextId = 0;
|
|
20
|
+
/** Whether process closure has been observed. */
|
|
21
|
+
#exited = false;
|
|
22
|
+
/** Prevents repeated close calls from sending another cleanup request. */
|
|
23
|
+
#closing = false;
|
|
24
|
+
/**
|
|
25
|
+
* Starts the child process immediately. Call open before analysis and close when finished.
|
|
26
|
+
*/
|
|
27
|
+
constructor() {
|
|
28
|
+
this.#child = fork(fileURLToPath(new URL("./worker.js", import.meta.url)), [], {
|
|
29
|
+
stdio: [
|
|
30
|
+
"ignore",
|
|
31
|
+
"pipe",
|
|
32
|
+
"pipe",
|
|
33
|
+
"ipc"
|
|
34
|
+
],
|
|
35
|
+
execArgv: [],
|
|
36
|
+
windowsHide: true
|
|
37
|
+
});
|
|
38
|
+
this.#child.stdout.on("data", (data) => {
|
|
39
|
+
process$1.stderr.write(data);
|
|
40
|
+
});
|
|
41
|
+
this.#child.stderr.on("data", (data) => {
|
|
42
|
+
process$1.stderr.write(data);
|
|
43
|
+
});
|
|
44
|
+
this.#child.on("message", (reply) => {
|
|
45
|
+
const request = this.#pending.get(reply.id);
|
|
46
|
+
this.#pending.delete(reply.id);
|
|
47
|
+
if (reply.error) request?.reject(reply.error.results ? new RewriteFailure(reply.error.message, reply.error.results) : new Error(reply.error.message));
|
|
48
|
+
else request?.resolve(reply.value);
|
|
49
|
+
});
|
|
50
|
+
this.#child.on("error", (error) => {
|
|
51
|
+
for (const request of this.#pending.values()) request.reject(error);
|
|
52
|
+
this.#pending.clear();
|
|
53
|
+
});
|
|
54
|
+
this.#closed = new Promise((resolve) => {
|
|
55
|
+
this.#child.on("close", (code, signal) => {
|
|
56
|
+
this.#exited = true;
|
|
57
|
+
for (const request of this.#pending.values()) request.reject(/* @__PURE__ */ new Error(`Stillwind analysis worker closed (${code ?? signal})`));
|
|
58
|
+
this.#pending.clear();
|
|
59
|
+
resolve();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sends an IPC operation and correlates its reply. Calls are not serialized here.
|
|
65
|
+
*
|
|
66
|
+
* @param request - Operation payload. Await open before using workspace operations, and avoid
|
|
67
|
+
* overlapping replacement or closure with analysis requests.
|
|
68
|
+
* @returns The reply value cast to T. The caller must choose T to match the operation's result.
|
|
69
|
+
* @throws If the child is closed, IPC delivery fails, or the child operation reports an error.
|
|
70
|
+
*/
|
|
71
|
+
async request(request) {
|
|
72
|
+
if (this.#exited) throw new Error("Stillwind analysis worker is closed");
|
|
73
|
+
const id = this.#nextId++;
|
|
74
|
+
return await new Promise((resolve, reject) => {
|
|
75
|
+
this.#pending.set(id, {
|
|
76
|
+
resolve,
|
|
77
|
+
reject
|
|
78
|
+
});
|
|
79
|
+
this.#child.send({
|
|
80
|
+
id,
|
|
81
|
+
request
|
|
82
|
+
}, (error) => {
|
|
83
|
+
if (error) {
|
|
84
|
+
this.#pending.delete(id);
|
|
85
|
+
reject(error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Replaces the child workspace, closing any previously opened hosts first.
|
|
92
|
+
*
|
|
93
|
+
* @param config - Configuration path. Relative paths use the child's inherited working directory.
|
|
94
|
+
* @returns A promise that resolves after the configuration and project hosts have opened.
|
|
95
|
+
* @throws If configuration evaluation, project initialization, or transport fails.
|
|
96
|
+
*/
|
|
97
|
+
async open(config) {
|
|
98
|
+
await this.request({
|
|
99
|
+
method: "open",
|
|
100
|
+
config
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Analyzes a target in each matching project of the opened workspace.
|
|
105
|
+
*
|
|
106
|
+
* @param file - Absolute target path. Unsaved buffers use preceding update requests.
|
|
107
|
+
* @returns Scoped results in project order, or an empty list when no scope includes the target.
|
|
108
|
+
* @throws If the workspace has not opened or transport fails.
|
|
109
|
+
*/
|
|
110
|
+
analyze(file) {
|
|
111
|
+
return this.request({
|
|
112
|
+
method: "analyze",
|
|
113
|
+
file
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Enumerates and analyzes targets in the opened workspace.
|
|
118
|
+
*
|
|
119
|
+
* @param patterns - Additional globs relative to each project root. Empty or omitted filters
|
|
120
|
+
* retain every configured target.
|
|
121
|
+
* @returns Results in project order and sorted target order within each project.
|
|
122
|
+
* @throws If the workspace has not opened, enumeration fails, or transport fails.
|
|
123
|
+
*/
|
|
124
|
+
lint(patterns) {
|
|
125
|
+
return this.request({
|
|
126
|
+
method: "lint",
|
|
127
|
+
patterns
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Enumerates distinct targets in the opened workspace.
|
|
132
|
+
*
|
|
133
|
+
* @param patterns - Additional project-relative globs. Omission or an empty list retains all targets.
|
|
134
|
+
* @param stylesheets - Adds the stylesheets that each project lints.
|
|
135
|
+
* @returns Sorted absolute paths, deduplicated across projects.
|
|
136
|
+
* @throws If the workspace has not opened, enumeration fails, or transport fails.
|
|
137
|
+
*/
|
|
138
|
+
targets(patterns, stylesheets) {
|
|
139
|
+
return this.request({
|
|
140
|
+
method: "targets",
|
|
141
|
+
patterns,
|
|
142
|
+
stylesheets
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Computes replacements from captured buffers without writing files.
|
|
147
|
+
*
|
|
148
|
+
* @param inputs - Distinct absolute target paths and complete original text.
|
|
149
|
+
* @param operation - Utility sorting or lint fixes, limited to ten changing passes per target.
|
|
150
|
+
* @returns Successful replacements and target failures in input order. Captured buffers are removed after planning.
|
|
151
|
+
* @throws If workspace setup, buffer installation, cleanup, or transport fails.
|
|
152
|
+
*/
|
|
153
|
+
rewrite(inputs, operation) {
|
|
154
|
+
return this.request({
|
|
155
|
+
method: "rewrite",
|
|
156
|
+
inputs,
|
|
157
|
+
operation
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Requests host cleanup and waits for the child process to close. After the cleanup request
|
|
162
|
+
* settles, a child that remains alive for five seconds is terminated.
|
|
163
|
+
*
|
|
164
|
+
* @returns A promise that resolves after process closure. Repeated calls wait for that closure.
|
|
165
|
+
* @throws If the initial cleanup request or its transport fails.
|
|
166
|
+
*/
|
|
167
|
+
async close() {
|
|
168
|
+
if (this.#closing || this.#exited) {
|
|
169
|
+
await this.#closed;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.#closing = true;
|
|
173
|
+
try {
|
|
174
|
+
await this.request({ method: "close" });
|
|
175
|
+
} finally {
|
|
176
|
+
const timer = setTimeout(() => {
|
|
177
|
+
this.#child.kill();
|
|
178
|
+
}, 5e3);
|
|
179
|
+
await this.#closed;
|
|
180
|
+
clearTimeout(timer);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
// src/write.ts
|
|
185
|
+
/**
|
|
186
|
+
* Saves changed bytes once per file. Identical buffers perform no filesystem operations.
|
|
187
|
+
* Checks each original immediately before saving and continues after a target fails.
|
|
188
|
+
* @param changes - Distinct target paths and original/replacement bytes. Buffers remain unchanged.
|
|
189
|
+
* @returns Saved paths and failures. A stale file is left unchanged.
|
|
190
|
+
*/
|
|
191
|
+
async function writeChangedFiles(changes) {
|
|
192
|
+
const changed = changes.filter((change) => !change.before.equals(change.after));
|
|
193
|
+
const saved = [];
|
|
194
|
+
const failures = [];
|
|
195
|
+
for (const change of changed) try {
|
|
196
|
+
if (!(await readFile(change.file)).equals(change.before)) throw new Error(`Source changed before saving ${change.file}`);
|
|
197
|
+
await writeFile(change.file, change.after);
|
|
198
|
+
saved.push(change.file);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
failures.push({
|
|
201
|
+
file: change.file,
|
|
202
|
+
message: error instanceof Error ? error.message : String(error),
|
|
203
|
+
results: []
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
changed: saved,
|
|
208
|
+
failures
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
// src/rewrite-files.ts
|
|
212
|
+
/**
|
|
213
|
+
* Computes all replacements before optionally saving changed files. Fixes return final findings.
|
|
214
|
+
* @param options - Configuration discovery and optional filters within configured target scopes.
|
|
215
|
+
* @param operation - Utility sorting or converged lint fixes.
|
|
216
|
+
* @param write - Whether to verify and save changed bytes after every replacement is planned.
|
|
217
|
+
* @returns Configuration, sorted changed paths, findings, and independent target failures.
|
|
218
|
+
* Saving reports only paths whose writes succeeded. Check mode reports planned changes.
|
|
219
|
+
* @throws If selection is empty, configuration, worker communication, or cleanup fails.
|
|
220
|
+
*/
|
|
221
|
+
async function rewriteFiles(options, operation, write) {
|
|
222
|
+
const config = resolveRewriteConfig(options);
|
|
223
|
+
const worker = new AnalysisWorker();
|
|
224
|
+
try {
|
|
225
|
+
await worker.open(config);
|
|
226
|
+
const files = await worker.targets(options.patterns, true);
|
|
227
|
+
if (!files.length) throw new Error("No analysis targets matched the configured scopes");
|
|
228
|
+
const failures = [];
|
|
229
|
+
const originals = /* @__PURE__ */ new Map();
|
|
230
|
+
const inputs = [];
|
|
231
|
+
const reads = await Promise.allSettled(files.map((file) => readFile(file)));
|
|
232
|
+
for (const [index, read] of reads.entries()) {
|
|
233
|
+
const file = files[index];
|
|
234
|
+
try {
|
|
235
|
+
if (read.status === "rejected") throw read.reason;
|
|
236
|
+
const source = read.value.toString("utf8");
|
|
237
|
+
if (!Buffer.from(source).equals(read.value)) throw new Error(`Source is not valid UTF-8: ${file}`);
|
|
238
|
+
originals.set(file, read.value);
|
|
239
|
+
inputs.push({
|
|
240
|
+
file,
|
|
241
|
+
source
|
|
242
|
+
});
|
|
243
|
+
} catch (error) {
|
|
244
|
+
failures.push({
|
|
245
|
+
file,
|
|
246
|
+
message: error instanceof Error ? error.message : String(error),
|
|
247
|
+
results: []
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const batch = await worker.rewrite(inputs, operation);
|
|
252
|
+
failures.push(...batch.failures);
|
|
253
|
+
const changes = batch.outputs.map((output) => ({
|
|
254
|
+
file: output.file,
|
|
255
|
+
before: originals.get(output.file),
|
|
256
|
+
after: Buffer.from(output.code)
|
|
257
|
+
}));
|
|
258
|
+
let changed = changes.filter((change) => !change.before.equals(change.after)).map((change) => change.file);
|
|
259
|
+
if (write) {
|
|
260
|
+
const saved = await writeChangedFiles(changes);
|
|
261
|
+
changed = saved.changed;
|
|
262
|
+
failures.push(...saved.failures);
|
|
263
|
+
}
|
|
264
|
+
changed.sort();
|
|
265
|
+
failures.sort((a, b) => a.file.localeCompare(b.file));
|
|
266
|
+
const results = [...batch.outputs, ...batch.failures].flatMap((output) => output.results).sort((a, b) => a.project - b.project || a.result.entry.localeCompare(b.result.entry));
|
|
267
|
+
return {
|
|
268
|
+
config,
|
|
269
|
+
changed,
|
|
270
|
+
results,
|
|
271
|
+
failures
|
|
272
|
+
};
|
|
273
|
+
} finally {
|
|
274
|
+
await worker.close();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Resolves an explicit configuration path or searches above the chosen working directory.
|
|
279
|
+
* @param options - Optional config path and cwd, defaulting to process.cwd().
|
|
280
|
+
* @returns An absolute path. Explicit paths are resolved without evaluating the configuration.
|
|
281
|
+
* @throws If discovery finds no configuration.
|
|
282
|
+
*/
|
|
283
|
+
function resolveRewriteConfig(options) {
|
|
284
|
+
const cwd = options.cwd ?? process.cwd();
|
|
285
|
+
const config = options.config ? path.resolve(cwd, options.config) : findConfiguration(cwd);
|
|
286
|
+
if (!config) throw new Error(`Cannot find Stillwind configuration above ${cwd}`);
|
|
287
|
+
return config;
|
|
288
|
+
}
|
|
289
|
+
// src/format.ts
|
|
290
|
+
/**
|
|
291
|
+
* Sorts configured targets and saves changed files unless check is true.
|
|
292
|
+
* @param options - Configuration discovery, target filters, and optional check mode.
|
|
293
|
+
* @returns Changed paths, original findings, and failures. Healthy targets continue after a failure.
|
|
294
|
+
* @throws If selection, configuration, worker communication, or cleanup fails.
|
|
295
|
+
*/
|
|
296
|
+
async function format(options = {}) {
|
|
297
|
+
const result = await rewriteFiles(options, "sort", !options.check);
|
|
298
|
+
return {
|
|
299
|
+
...result,
|
|
300
|
+
exitCode: result.failures.length ? 2 : options.check && result.changed.length ? 1 : 0
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
// src/lint.ts
|
|
304
|
+
/**
|
|
305
|
+
* Analyzes configured target scopes in a child process and closes it before returning.
|
|
306
|
+
*
|
|
307
|
+
* @param options - Configuration discovery and optional target filters. Omission checks all
|
|
308
|
+
* configured targets from the process working directory.
|
|
309
|
+
* @returns Results and an exit code. Readonly lint returns code 2 for empty selection or incomplete analysis.
|
|
310
|
+
* @throws If configuration discovery, worker initialization, target enumeration, or cleanup fails.
|
|
311
|
+
* Fix mode reports failures per target and continues with healthy targets. Empty selection throws.
|
|
312
|
+
*/
|
|
313
|
+
async function lint(options = {}) {
|
|
314
|
+
if (options.fix) {
|
|
315
|
+
const result = await rewriteFiles(options, "fixes", true);
|
|
316
|
+
return {
|
|
317
|
+
...result,
|
|
318
|
+
exitCode: result.failures.length ? 2 : result.results.some(({ result }) => result.reports.some((report) => report.severity === "error")) ? 1 : 0
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const config = resolveRewriteConfig(options);
|
|
322
|
+
const worker = new AnalysisWorker();
|
|
323
|
+
try {
|
|
324
|
+
await worker.open(config);
|
|
325
|
+
const results = await worker.lint(options.patterns);
|
|
326
|
+
return {
|
|
327
|
+
config,
|
|
328
|
+
results,
|
|
329
|
+
exitCode: !results.length || results.some(({ result }) => result.status !== "complete") ? 2 : results.some(({ result }) => result.reports.some((report) => report.severity === "error")) ? 1 : 0
|
|
330
|
+
};
|
|
331
|
+
} finally {
|
|
332
|
+
await worker.close();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Formats findings and incomplete analysis for terminal output.
|
|
337
|
+
*
|
|
338
|
+
* @param result - Lint results whose reports use original document locations.
|
|
339
|
+
* @returns Text with one-based line and column positions. Duplicate findings are removed per
|
|
340
|
+
* project. Findings from overlapping projects remain separate. Successful results can return empty text.
|
|
341
|
+
*/
|
|
342
|
+
function formatLint(result) {
|
|
343
|
+
const lines = [];
|
|
344
|
+
for (const { project, report } of lintReports(result.results)) {
|
|
345
|
+
const location = report.primary.location;
|
|
346
|
+
const at = report.primary.scope === "document" ? location.uri : `${location.uri}:${location.startLine + 1}:${location.startColumn + 1}`;
|
|
347
|
+
lines.push(`[project ${project + 1}] ${at}: ${report.severity} ${report.code}: ${report.message}`);
|
|
348
|
+
for (const related of report.related) lines.push(` ${related.location.uri}:${related.location.startLine + 1}:${related.location.startColumn + 1}${related.message ? `: ${related.message}` : ""}`);
|
|
349
|
+
lines.push(...report.notes.map((note) => ` ${note}`));
|
|
350
|
+
}
|
|
351
|
+
for (const entry of result.results) if (entry.result.status !== "complete") {
|
|
352
|
+
lines.push(`[project ${entry.project + 1}] ${entry.result.entry}: incomplete analysis${entry.result.error ? `: ${entry.result.error}` : ""}`);
|
|
353
|
+
for (const dependency of entry.result.graph?.dependencies ?? []) if (dependency.status === "unresolved" || dependency.status === "unsupported") lines.push(` ${dependency.status}: ${dependency.specifier} from ${dependency.importer}`);
|
|
354
|
+
for (const range of entry.result.graph?.unverified ?? []) lines.push(` unverified: ${range.moduleId}${range.start === void 0 ? "" : `:${range.start}-${range.end}`}: ${range.reason}`);
|
|
355
|
+
}
|
|
356
|
+
for (const failure of result.failures ?? []) if (!failure.results.some(({ result }) => result.status !== "complete")) lines.push(`${failure.file}: ${failure.message}`);
|
|
357
|
+
if (!result.results.length && !result.failures?.length) lines.push("No analysis targets matched the configured scopes");
|
|
358
|
+
return lines.join("\n");
|
|
359
|
+
}
|
|
360
|
+
// src/node-workspace.ts
|
|
361
|
+
/**
|
|
362
|
+
* Opens one isolated Node analysis process for each distinct configuration.
|
|
363
|
+
*
|
|
364
|
+
* @param context - Workspace directory URIs. File URIs use upward configuration discovery.
|
|
365
|
+
* Other URI schemes cannot open Node workspaces. An empty list uses the process working directory.
|
|
366
|
+
* @param config - Optional explicit configuration path, resolved from the process working directory.
|
|
367
|
+
* When supplied, it replaces discovery from workspace folders.
|
|
368
|
+
* @returns Services keyed by absolute configuration path and separate initialization errors.
|
|
369
|
+
* Services accept file URIs, forward buffers to their workers, and discard cancelled results.
|
|
370
|
+
* @throws If converting a malformed file URI or closing a failed worker throws.
|
|
371
|
+
*/
|
|
372
|
+
async function openNodeWorkspaces(context, config) {
|
|
373
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
374
|
+
const errors = /* @__PURE__ */ new Map();
|
|
375
|
+
const paths = config ? [path.resolve(config)] : (context.workspaceFolders.length ? context.workspaceFolders : [pathToFileURL(process$1.cwd()).href]).map((uri) => uri.startsWith("file:") ? findConfiguration(fileURLToPath(uri)) : void 0);
|
|
376
|
+
if (paths.some((file) => !file) || !paths.length) errors.set("configuration", "Cannot find Stillwind configuration for the workspace");
|
|
377
|
+
for (const file of new Set(paths.filter((file) => Boolean(file)))) {
|
|
378
|
+
const worker = new AnalysisWorker();
|
|
379
|
+
try {
|
|
380
|
+
await worker.open(file);
|
|
381
|
+
/**
|
|
382
|
+
* Selects document identities that can be forwarded to the filesystem worker.
|
|
383
|
+
* @param uri - Document URI whose syntax is validated later by `fileURLToPath`.
|
|
384
|
+
* @returns Whether the URI begins with the `file:` scheme.
|
|
385
|
+
*/
|
|
386
|
+
const accepts = (uri) => uri.startsWith("file:");
|
|
387
|
+
workspaces.set(file, {
|
|
388
|
+
refresh: (uris) => worker.request({
|
|
389
|
+
method: "refresh",
|
|
390
|
+
files: uris.filter(accepts).map((uri) => fileURLToPath(uri))
|
|
391
|
+
}),
|
|
392
|
+
prepare: async (uris, signal) => {
|
|
393
|
+
if (!signal?.aborted) await worker.request({
|
|
394
|
+
method: "prepare",
|
|
395
|
+
files: uris.filter(accepts).map((uri) => fileURLToPath(uri))
|
|
396
|
+
});
|
|
397
|
+
},
|
|
398
|
+
query: async (uri, request, signal) => {
|
|
399
|
+
if (!accepts(uri) || signal?.aborted) return [];
|
|
400
|
+
const results = await worker.request({
|
|
401
|
+
method: "query",
|
|
402
|
+
file: fileURLToPath(uri),
|
|
403
|
+
request
|
|
404
|
+
});
|
|
405
|
+
return signal?.aborted ? [] : results;
|
|
406
|
+
},
|
|
407
|
+
update: async (uri, source, version) => {
|
|
408
|
+
if (accepts(uri)) await worker.request({
|
|
409
|
+
method: "update",
|
|
410
|
+
file: fileURLToPath(uri),
|
|
411
|
+
source,
|
|
412
|
+
version
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
analyze: async (uri, signal) => {
|
|
416
|
+
if (!accepts(uri) || signal?.aborted) return [];
|
|
417
|
+
const results = await worker.analyze(fileURLToPath(uri));
|
|
418
|
+
return signal?.aborted ? [] : results.map(({ project, config, result }) => ({
|
|
419
|
+
project,
|
|
420
|
+
config,
|
|
421
|
+
result: {
|
|
422
|
+
entry: result.entry,
|
|
423
|
+
revision: result.revision,
|
|
424
|
+
status: result.status,
|
|
425
|
+
reports: result.reports,
|
|
426
|
+
error: result.error,
|
|
427
|
+
dependencies: result.graph?.dependencies,
|
|
428
|
+
unverified: result.graph?.unverified,
|
|
429
|
+
generation: result.graph?.generation
|
|
430
|
+
}
|
|
431
|
+
}));
|
|
432
|
+
},
|
|
433
|
+
closeDocument: async (uri) => {
|
|
434
|
+
if (accepts(uri)) await worker.request({
|
|
435
|
+
method: "closeDocument",
|
|
436
|
+
file: fileURLToPath(uri)
|
|
437
|
+
});
|
|
438
|
+
},
|
|
439
|
+
close: async () => {
|
|
440
|
+
await worker.close();
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
} catch (error) {
|
|
444
|
+
errors.set(file, String(error));
|
|
445
|
+
await worker.close();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
workspaces,
|
|
450
|
+
errors
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
// src/source-formatter.ts
|
|
454
|
+
/** Reuses an isolated process while refreshing trusted configuration for each formatting request. */
|
|
455
|
+
var SourceFormatter = class {
|
|
456
|
+
config;
|
|
457
|
+
/** Child process reused across formatting requests and owned until close completes. */
|
|
458
|
+
#worker = new AnalysisWorker();
|
|
459
|
+
/** Serializes requests while allowing a new request after a preceding failure. */
|
|
460
|
+
#queue = Promise.resolve();
|
|
461
|
+
/**
|
|
462
|
+
* Starts the isolated worker that evaluates configuration on each formatting request.
|
|
463
|
+
* @param config - Configuration path resolved in the worker's inherited working directory.
|
|
464
|
+
*/
|
|
465
|
+
constructor(config) {
|
|
466
|
+
this.config = config;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Sorts the supplied buffer with current project settings.
|
|
470
|
+
* Files outside all configured scopes return unchanged text. Requests are serialized and never write files.
|
|
471
|
+
* @param input - Original buffer and optional protected ranges. Relative paths are resolved from cwd.
|
|
472
|
+
* @returns The sorted buffer and original findings after configuration is reopened.
|
|
473
|
+
* @throws If configuration loading, parsing, analysis, project agreement, rewriting, or worker communication fails.
|
|
474
|
+
*/
|
|
475
|
+
format(input) {
|
|
476
|
+
const task = this.#queue.then(async () => {
|
|
477
|
+
await this.#worker.open(this.config);
|
|
478
|
+
const { outputs, failures } = await this.#worker.rewrite([{
|
|
479
|
+
...input,
|
|
480
|
+
file: path.resolve(input.file)
|
|
481
|
+
}], "sort");
|
|
482
|
+
if (failures.length) throw new RewriteFailure(failures[0].message, failures[0].results);
|
|
483
|
+
return outputs[0];
|
|
484
|
+
});
|
|
485
|
+
this.#queue = task.catch(() => {});
|
|
486
|
+
return task;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Waits for queued formatting and releases the child process. Stop submitting requests before closure.
|
|
490
|
+
* @returns Completion of worker cleanup.
|
|
491
|
+
* @throws If the worker's cleanup request fails.
|
|
492
|
+
*/
|
|
493
|
+
async close() {
|
|
494
|
+
await this.#queue;
|
|
495
|
+
await this.#worker.close();
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Finds a configuration above a source file or resolves an explicit path from cwd.
|
|
500
|
+
* @param file - Source path whose parent starts upward discovery. Relative paths use cwd.
|
|
501
|
+
* @param config - Optional explicit configuration path, returned without an existence check.
|
|
502
|
+
* @returns The absolute configuration path, or undefined when discovery finds none.
|
|
503
|
+
*/
|
|
504
|
+
function findFormatterConfig(file, config) {
|
|
505
|
+
if (config) return path.resolve(config);
|
|
506
|
+
return findConfiguration(path.dirname(path.resolve(file)));
|
|
507
|
+
}
|
|
508
|
+
export { SourceFormatter, findFormatterConfig, format, formatLint, lint, lintReports, openNodeWorkspaces };
|
|
509
|
+
|
|
510
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":["process"],"sources":["../src/worker-client.ts","../src/write.ts","../src/rewrite-files.ts","../src/format.ts","../src/lint.ts","../src/node-workspace.ts","../src/source-formatter.ts"],"sourcesContent":["import { fork, type ChildProcess } from \"node:child_process\";\nimport process from \"node:process\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { EditorRequest, WorkspaceResult } from \"@stillwind/host\";\n\nimport { RewriteFailure, type RewriteInput, type RewriteBatchResult } from \"./rewrite.ts\";\n\n/** Requests sent to the process that owns trusted config evaluation and plugin lifetimes. */\nexport type WorkerRequest =\n | {\n /** Serialized discriminator for replacing the child workspace. */\n method: \"open\";\n /** Configuration path evaluated in the child process, replacing any previously opened workspace. */\n config: string;\n }\n | {\n /** Serialized discriminator for analyzing configured targets. */\n method: \"lint\";\n /** Additional target globs relative to each project root. Omission checks all configured targets. */\n patterns?: readonly string[];\n }\n | {\n /** Serialized discriminator for enumerating distinct targets. */\n method: \"targets\";\n /** Additional project-relative globs. An empty or omitted list keeps every configured target. */\n patterns?: readonly string[];\n /** Adds the stylesheets that each project lints. */\n stylesheets?: boolean;\n }\n | {\n /** Serialized discriminator for computing source replacements. */\n method: \"rewrite\";\n /** Distinct absolute target paths and captured text, retained in result order. */\n inputs: readonly RewriteInput[];\n /** Selects one sort pass or lint fixes that must converge. */\n operation: \"sort\" | \"fixes\";\n }\n | {\n /** Serialized discriminator for preparing a batch of targets. */\n method: \"prepare\";\n /** Absolute target paths. */\n files: readonly string[];\n }\n | {\n /** Serialized discriminator for analyzing one target in matching projects. */\n method: \"analyze\";\n /** Absolute target path. Each project whose scope contains the file returns a result. */\n file: string;\n }\n | {\n /** Serialized discriminator for an editor query against original text. */\n method: \"query\";\n /** Absolute target file path. */\n file: string;\n /** Editor operation in original UTF-16 coordinates. */\n request: EditorRequest;\n }\n | {\n /** Serialized discriminator for replacing an unsaved buffer. */\n method: \"update\";\n /** Absolute source path, including dependencies outside target scopes. */\n file: string;\n /** Complete unsaved source text. */\n source: string;\n /** Safe integer that increases while this file is open. */\n version: number;\n }\n | {\n /** Serialized discriminator for removing an unsaved buffer. */\n method: \"closeDocument\";\n /** Absolute path of the buffer to remove. Unknown files have no effect. */\n file: string;\n }\n | {\n /** Serialized discriminator for checking whether the caller needs to reopen the workspace. */\n method: \"refresh\";\n /** Absolute file paths reported by save or watch notifications. */\n files: readonly string[];\n }\n | {\n /** Serialized discriminator for refreshing disk and compiler caches. */\n method: \"invalidate\";\n }\n | {\n /** Serialized discriminator for closing hosts and disconnecting the child. */\n method: \"close\";\n };\n\n/** IPC response correlated with one request. Successful void operations can omit value. */\nexport interface WorkerReply {\n /** Request sequence number assigned by AnalysisWorker. */\n id: number;\n /** Serialized operation result when error is absent. */\n value?: unknown;\n /** Exception message and any analysis results that prevented a rewrite. */\n error?: {\n message: string;\n results?: WorkspaceResult[];\n };\n}\n\n/** Isolates configuration and plugin logs from CLI JSON and the LSP stdout transport. */\nexport class AnalysisWorker {\n /** Owned child with IPC enabled. Both output streams are forwarded to the parent's stderr. */\n readonly #child: ChildProcess;\n /** Unanswered requests keyed by monotonically assigned IPC sequence number. */\n readonly #pending = new Map<\n number,\n {\n /** Settles the request with the child's unvalidated reply value. */\n resolve: (value: unknown) => void;\n /** Rejects the request after delivery, child-operation, or process failure. */\n reject: (error: Error) => void;\n }\n >();\n /** Resolves on process closure after outstanding requests have been rejected. */\n readonly #closed: Promise<void>;\n\n /** Next IPC sequence number, independent of source document versions. */\n #nextId = 0;\n /** Whether process closure has been observed. */\n #exited = false;\n /** Prevents repeated close calls from sending another cleanup request. */\n #closing = false;\n\n /**\n * Starts the child process immediately. Call open before analysis and close when finished.\n */\n constructor() {\n this.#child = fork(fileURLToPath(new URL(\"./worker.js\", import.meta.url)), [], {\n stdio: [\"ignore\", \"pipe\", \"pipe\", \"ipc\"],\n execArgv: [],\n windowsHide: true,\n });\n this.#child.stdout!.on(\"data\", (data: Buffer) => {\n process.stderr.write(data);\n });\n this.#child.stderr!.on(\"data\", (data: Buffer) => {\n process.stderr.write(data);\n });\n this.#child.on(\"message\", (reply: WorkerReply) => {\n const request = this.#pending.get(reply.id);\n this.#pending.delete(reply.id);\n if (reply.error) {\n request?.reject(\n reply.error.results\n ? new RewriteFailure(reply.error.message, reply.error.results)\n : new Error(reply.error.message),\n );\n } else {\n request?.resolve(reply.value);\n }\n });\n this.#child.on(\"error\", (error) => {\n for (const request of this.#pending.values()) {\n request.reject(error);\n }\n this.#pending.clear();\n });\n this.#closed = new Promise((resolve) => {\n this.#child.on(\"close\", (code, signal) => {\n this.#exited = true;\n for (const request of this.#pending.values()) {\n request.reject(new Error(`Stillwind analysis worker closed (${code ?? signal})`));\n }\n this.#pending.clear();\n resolve();\n });\n });\n }\n\n /**\n * Sends an IPC operation and correlates its reply. Calls are not serialized here.\n *\n * @param request - Operation payload. Await open before using workspace operations, and avoid\n * overlapping replacement or closure with analysis requests.\n * @returns The reply value cast to T. The caller must choose T to match the operation's result.\n * @throws If the child is closed, IPC delivery fails, or the child operation reports an error.\n */\n async request<T = void>(request: WorkerRequest): Promise<T> {\n if (this.#exited) {\n throw new Error(\"Stillwind analysis worker is closed\");\n }\n const id = this.#nextId++;\n return (await new Promise<unknown>((resolve, reject) => {\n this.#pending.set(id, { resolve, reject });\n this.#child.send({ id, request }, (error) => {\n if (error) {\n this.#pending.delete(id);\n reject(error);\n }\n });\n })) as T;\n }\n\n /**\n * Replaces the child workspace, closing any previously opened hosts first.\n *\n * @param config - Configuration path. Relative paths use the child's inherited working directory.\n * @returns A promise that resolves after the configuration and project hosts have opened.\n * @throws If configuration evaluation, project initialization, or transport fails.\n */\n async open(config: string): Promise<void> {\n await this.request({\n method: \"open\",\n config,\n });\n }\n\n /**\n * Analyzes a target in each matching project of the opened workspace.\n *\n * @param file - Absolute target path. Unsaved buffers use preceding update requests.\n * @returns Scoped results in project order, or an empty list when no scope includes the target.\n * @throws If the workspace has not opened or transport fails.\n */\n analyze(file: string): Promise<WorkspaceResult[]> {\n return this.request({\n method: \"analyze\",\n file,\n });\n }\n\n /**\n * Enumerates and analyzes targets in the opened workspace.\n *\n * @param patterns - Additional globs relative to each project root. Empty or omitted filters\n * retain every configured target.\n * @returns Results in project order and sorted target order within each project.\n * @throws If the workspace has not opened, enumeration fails, or transport fails.\n */\n lint(patterns?: readonly string[]): Promise<WorkspaceResult[]> {\n return this.request({\n method: \"lint\",\n patterns,\n });\n }\n\n /**\n * Enumerates distinct targets in the opened workspace.\n *\n * @param patterns - Additional project-relative globs. Omission or an empty list retains all targets.\n * @param stylesheets - Adds the stylesheets that each project lints.\n * @returns Sorted absolute paths, deduplicated across projects.\n * @throws If the workspace has not opened, enumeration fails, or transport fails.\n */\n targets(patterns?: readonly string[], stylesheets?: boolean): Promise<string[]> {\n return this.request({\n method: \"targets\",\n patterns,\n stylesheets,\n });\n }\n\n /**\n * Computes replacements from captured buffers without writing files.\n *\n * @param inputs - Distinct absolute target paths and complete original text.\n * @param operation - Utility sorting or lint fixes, limited to ten changing passes per target.\n * @returns Successful replacements and target failures in input order. Captured buffers are removed after planning.\n * @throws If workspace setup, buffer installation, cleanup, or transport fails.\n */\n rewrite(\n inputs: readonly RewriteInput[],\n operation: \"sort\" | \"fixes\",\n ): Promise<RewriteBatchResult> {\n return this.request({\n method: \"rewrite\",\n inputs,\n operation,\n });\n }\n\n /**\n * Requests host cleanup and waits for the child process to close. After the cleanup request\n * settles, a child that remains alive for five seconds is terminated.\n *\n * @returns A promise that resolves after process closure. Repeated calls wait for that closure.\n * @throws If the initial cleanup request or its transport fails.\n */\n async close(): Promise<void> {\n if (this.#closing || this.#exited) {\n await this.#closed;\n return;\n }\n this.#closing = true;\n try {\n await this.request({\n method: \"close\",\n });\n } finally {\n const timer = setTimeout(() => {\n this.#child.kill();\n }, 5000);\n await this.#closed;\n clearTimeout(timer);\n }\n }\n}\n","import { readFile, writeFile } from \"node:fs/promises\";\n\nimport type { RewriteFileFailure } from \"./rewrite.ts\";\n\n/** A replacement with the original bytes retained for verification before saving. */\nexport interface FileChange {\n /** Target path. The caller must provide at most one change per file. */\n file: string;\n /** Bytes captured before planning, compared against disk before saving. */\n before: Buffer;\n /** Planned replacement bytes. Equal bytes skip verification and writing. */\n after: Buffer;\n}\n\n/**\n * Saves changed bytes once per file. Identical buffers perform no filesystem operations.\n * Checks each original immediately before saving and continues after a target fails.\n * @param changes - Distinct target paths and original/replacement bytes. Buffers remain unchanged.\n * @returns Saved paths and failures. A stale file is left unchanged.\n */\nexport async function writeChangedFiles(changes: readonly FileChange[]): Promise<{\n changed: string[];\n failures: RewriteFileFailure[];\n}> {\n const changed = changes.filter((change) => !change.before.equals(change.after));\n const saved: string[] = [];\n const failures: RewriteFileFailure[] = [];\n for (const change of changed) {\n try {\n if (!(await readFile(change.file)).equals(change.before)) {\n throw new Error(`Source changed before saving ${change.file}`);\n }\n await writeFile(change.file, change.after);\n saved.push(change.file);\n } catch (error) {\n failures.push({\n file: change.file,\n message: error instanceof Error ? error.message : String(error),\n results: [],\n });\n }\n }\n return {\n changed: saved,\n failures,\n };\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { findConfiguration } from \"@stillwind/config/node\";\nimport type { WorkspaceResult } from \"@stillwind/host\";\n\nimport type { RewriteFileFailure, RewriteInput } from \"./rewrite.ts\";\nimport { AnalysisWorker } from \"./worker-client.ts\";\nimport { writeChangedFiles } from \"./write.ts\";\n\n/** Selects configured source files for CLI analysis and rewriting. */\nexport interface RewriteOptions {\n /** Explicit configuration path, absolute or relative to cwd. Omission searches upward from cwd. */\n config?: string;\n /** Directory for configuration discovery and relative config paths. Defaults to process.cwd(). */\n cwd?: string;\n /** Additional globs relative to each project root. Omission or an empty list retains all configured targets. */\n patterns?: string[];\n}\n\n/** A completed rewrite batch with findings kept separately for each owning project. */\ninterface RewriteFilesResult {\n /** Absolute configuration path used by the isolated worker. */\n config: string;\n /** Absolute paths whose original and final bytes differ, in sorted order. */\n changed: string[];\n /** Original findings for sorting and final findings for lint fixes, in project and target order. */\n results: WorkspaceResult[];\n /** Targets that could not be read, rewritten, or saved. */\n failures: RewriteFileFailure[];\n}\n\n/**\n * Computes all replacements before optionally saving changed files. Fixes return final findings.\n * @param options - Configuration discovery and optional filters within configured target scopes.\n * @param operation - Utility sorting or converged lint fixes.\n * @param write - Whether to verify and save changed bytes after every replacement is planned.\n * @returns Configuration, sorted changed paths, findings, and independent target failures.\n * Saving reports only paths whose writes succeeded. Check mode reports planned changes.\n * @throws If selection is empty, configuration, worker communication, or cleanup fails.\n */\nexport async function rewriteFiles(\n options: RewriteOptions,\n operation: \"sort\" | \"fixes\",\n write: boolean,\n): Promise<RewriteFilesResult> {\n const config = resolveRewriteConfig(options);\n const worker = new AnalysisWorker();\n try {\n await worker.open(config);\n const files = await worker.targets(options.patterns, true);\n if (!files.length) {\n throw new Error(\"No analysis targets matched the configured scopes\");\n }\n const failures: RewriteFileFailure[] = [];\n const originals = new Map<string, Buffer>();\n const inputs: RewriteInput[] = [];\n const reads = await Promise.allSettled(files.map((file) => readFile(file)));\n for (const [index, read] of reads.entries()) {\n const file = files[index];\n try {\n if (read.status === \"rejected\") {\n throw read.reason;\n }\n const source = read.value.toString(\"utf8\");\n if (!Buffer.from(source).equals(read.value)) {\n throw new Error(`Source is not valid UTF-8: ${file}`);\n }\n originals.set(file, read.value);\n inputs.push({\n file,\n source,\n });\n } catch (error) {\n failures.push({\n file,\n message: error instanceof Error ? error.message : String(error),\n results: [],\n });\n }\n }\n const batch = await worker.rewrite(inputs, operation);\n failures.push(...batch.failures);\n const changes = batch.outputs.map((output) => ({\n file: output.file,\n before: originals.get(output.file)!,\n after: Buffer.from(output.code),\n }));\n let changed = changes\n .filter((change) => !change.before.equals(change.after))\n .map((change) => change.file);\n if (write) {\n const saved = await writeChangedFiles(changes);\n changed = saved.changed;\n failures.push(...saved.failures);\n }\n changed.sort();\n failures.sort((a, b) => a.file.localeCompare(b.file));\n const results = [...batch.outputs, ...batch.failures]\n .flatMap((output) => output.results)\n .sort((a, b) => a.project - b.project || a.result.entry.localeCompare(b.result.entry));\n return {\n config,\n changed,\n results,\n failures,\n };\n } finally {\n await worker.close();\n }\n}\n\n/**\n * Resolves an explicit configuration path or searches above the chosen working directory.\n * @param options - Optional config path and cwd, defaulting to process.cwd().\n * @returns An absolute path. Explicit paths are resolved without evaluating the configuration.\n * @throws If discovery finds no configuration.\n */\nexport function resolveRewriteConfig(options: RewriteOptions): string {\n const cwd = options.cwd ?? process.cwd();\n const config = options.config ? path.resolve(cwd, options.config) : findConfiguration(cwd);\n if (!config) {\n throw new Error(`Cannot find Stillwind configuration above ${cwd}`);\n }\n return config;\n}\n","import type { WorkspaceResult } from \"@stillwind/host\";\n\nimport { rewriteFiles, type RewriteOptions } from \"./rewrite-files.ts\";\nimport type { RewriteFileFailure } from \"./rewrite.ts\";\n\n/** Sorting results whose changed paths compare original and final source bytes. */\nexport interface FormatResult {\n /** Absolute path of the evaluated configuration. */\n config: string;\n /** Absolute paths that changed or would change, in sorted order. */\n changed: string[];\n /** Findings from the original sources, in configured project and target order. */\n results: WorkspaceResult[];\n /** Targets that could not be read, rewritten, or saved. */\n failures: RewriteFileFailure[];\n /** Failures return 2. Check mode otherwise returns 1 when any file would change. */\n exitCode: 0 | 1 | 2;\n}\n\n/**\n * Sorts configured targets and saves changed files unless check is true.\n * @param options - Configuration discovery, target filters, and optional check mode.\n * @returns Changed paths, original findings, and failures. Healthy targets continue after a failure.\n * @throws If selection, configuration, worker communication, or cleanup fails.\n */\nexport async function format(\n options: RewriteOptions & {\n /** Whether to report changes without saving them. Defaults to false. */\n check?: boolean;\n } = {},\n): Promise<FormatResult> {\n const result = await rewriteFiles(options, \"sort\", !options.check);\n return {\n ...result,\n exitCode: result.failures.length ? 2 : options.check && result.changed.length ? 1 : 0,\n };\n}\n","import type { WorkspaceResult } from \"@stillwind/host\";\n\nimport { lintReports } from \"./reports.ts\";\nimport { resolveRewriteConfig, rewriteFiles, type RewriteOptions } from \"./rewrite-files.ts\";\nimport type { RewriteFileFailure } from \"./rewrite.ts\";\nimport { AnalysisWorker } from \"./worker-client.ts\";\n\n/** Lint results preserve project membership and identify incomplete analysis. */\nexport interface LintResult {\n /** Absolute path of the evaluated configuration. */\n config: string;\n /** Target results in configured project order, including overlapping project memberships. */\n results: WorkspaceResult[];\n /** Files whose bytes changed when fix was requested. */\n changed?: string[];\n /** Targets that could not be read, fixed, or saved when fix was requested. */\n failures?: RewriteFileFailure[];\n /**\n * - 0: successful checks\n * - 1: compiler errors or denied lint\n * - 2: incomplete execution\n */\n exitCode: 0 | 1 | 2;\n}\n\n/**\n * Analyzes configured target scopes in a child process and closes it before returning.\n *\n * @param options - Configuration discovery and optional target filters. Omission checks all\n * configured targets from the process working directory.\n * @returns Results and an exit code. Readonly lint returns code 2 for empty selection or incomplete analysis.\n * @throws If configuration discovery, worker initialization, target enumeration, or cleanup fails.\n * Fix mode reports failures per target and continues with healthy targets. Empty selection throws.\n */\nexport async function lint(\n options: RewriteOptions & {\n /** Applies converged fixes and reports findings from the final source buffers. */\n fix?: boolean;\n } = {},\n): Promise<LintResult> {\n if (options.fix) {\n const result = await rewriteFiles(options, \"fixes\", true);\n return {\n ...result,\n exitCode: result.failures.length\n ? 2\n : result.results.some(({ result }) =>\n result.reports.some((report) => report.severity === \"error\"),\n )\n ? 1\n : 0,\n };\n }\n const config = resolveRewriteConfig(options);\n const worker = new AnalysisWorker();\n try {\n await worker.open(config);\n const results = await worker.lint(options.patterns);\n const exitCode =\n !results.length || results.some(({ result }) => result.status !== \"complete\")\n ? 2\n : results.some(({ result }) => result.reports.some((report) => report.severity === \"error\"))\n ? 1\n : 0;\n return { config, results, exitCode };\n } finally {\n await worker.close();\n }\n}\n\n/**\n * Formats findings and incomplete analysis for terminal output.\n *\n * @param result - Lint results whose reports use original document locations.\n * @returns Text with one-based line and column positions. Duplicate findings are removed per\n * project. Findings from overlapping projects remain separate. Successful results can return empty text.\n */\nexport function formatLint(result: LintResult): string {\n const lines: string[] = [];\n for (const { project, report } of lintReports(result.results)) {\n const location = report.primary.location;\n const at =\n report.primary.scope === \"document\"\n ? location.uri\n : `${location.uri}:${location.startLine + 1}:${location.startColumn + 1}`;\n lines.push(\n `[project ${project + 1}] ${at}: ${report.severity} ${report.code}: ${report.message}`,\n );\n for (const related of report.related) {\n lines.push(\n ` ${related.location.uri}:${related.location.startLine + 1}:${related.location.startColumn + 1}${related.message ? `: ${related.message}` : \"\"}`,\n );\n }\n lines.push(...report.notes.map((note) => ` ${note}`));\n }\n for (const entry of result.results) {\n if (entry.result.status !== \"complete\") {\n lines.push(\n `[project ${entry.project + 1}] ${entry.result.entry}: incomplete analysis${entry.result.error ? `: ${entry.result.error}` : \"\"}`,\n );\n for (const dependency of entry.result.graph?.dependencies ?? []) {\n if (dependency.status === \"unresolved\" || dependency.status === \"unsupported\") {\n lines.push(` ${dependency.status}: ${dependency.specifier} from ${dependency.importer}`);\n }\n }\n for (const range of entry.result.graph?.unverified ?? []) {\n lines.push(\n ` unverified: ${range.moduleId}${range.start === undefined ? \"\" : `:${range.start}-${range.end}`}: ${range.reason}`,\n );\n }\n }\n }\n for (const failure of result.failures ?? []) {\n if (!failure.results.some(({ result }) => result.status !== \"complete\")) {\n lines.push(`${failure.file}: ${failure.message}`);\n }\n }\n if (!result.results.length && !result.failures?.length) {\n lines.push(\"No analysis targets matched the configured scopes\");\n }\n return lines.join(\"\\n\");\n}\n","import path from \"node:path\";\nimport process from \"node:process\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport { findConfiguration } from \"@stillwind/config/node\";\n\nimport { AnalysisWorker } from \"./worker-client.ts\";\nimport type {\n AnalysisWorkspaceContext,\n AnalysisWorkspaceService,\n OpenAnalysisWorkspaces,\n WorkspaceEditorResult,\n} from \"./workspace.ts\";\n\n/**\n * Opens one isolated Node analysis process for each distinct configuration.\n *\n * @param context - Workspace directory URIs. File URIs use upward configuration discovery.\n * Other URI schemes cannot open Node workspaces. An empty list uses the process working directory.\n * @param config - Optional explicit configuration path, resolved from the process working directory.\n * When supplied, it replaces discovery from workspace folders.\n * @returns Services keyed by absolute configuration path and separate initialization errors.\n * Services accept file URIs, forward buffers to their workers, and discard cancelled results.\n * @throws If converting a malformed file URI or closing a failed worker throws.\n */\nexport async function openNodeWorkspaces(\n context: AnalysisWorkspaceContext,\n config?: string,\n): Promise<OpenAnalysisWorkspaces> {\n const workspaces = new Map<string, AnalysisWorkspaceService>();\n const errors = new Map<string, string>();\n\n const paths = config\n ? [path.resolve(config)]\n : (context.workspaceFolders.length\n ? context.workspaceFolders\n : [pathToFileURL(process.cwd()).href]\n ).map((uri) => (uri.startsWith(\"file:\") ? findConfiguration(fileURLToPath(uri)) : undefined));\n if (paths.some((file) => !file) || !paths.length) {\n errors.set(\"configuration\", \"Cannot find Stillwind configuration for the workspace\");\n }\n\n for (const file of new Set(paths.filter((file): file is string => Boolean(file)))) {\n const worker = new AnalysisWorker();\n try {\n await worker.open(file);\n /**\n * Selects document identities that can be forwarded to the filesystem worker.\n * @param uri - Document URI whose syntax is validated later by `fileURLToPath`.\n * @returns Whether the URI begins with the `file:` scheme.\n */\n const accepts = (uri: string) => uri.startsWith(\"file:\");\n workspaces.set(file, {\n refresh: (uris) =>\n worker.request<boolean>({\n method: \"refresh\",\n files: uris.filter(accepts).map((uri) => fileURLToPath(uri)),\n }),\n prepare: async (uris, signal) => {\n if (!signal?.aborted) {\n await worker.request({\n method: \"prepare\",\n files: uris.filter(accepts).map((uri) => fileURLToPath(uri)),\n });\n }\n },\n query: async (uri, request, signal) => {\n if (!accepts(uri) || signal?.aborted) {\n return [];\n }\n const results = await worker.request<WorkspaceEditorResult[]>({\n method: \"query\",\n file: fileURLToPath(uri),\n request,\n });\n return signal?.aborted ? [] : results;\n },\n update: async (uri, source, version) => {\n if (accepts(uri)) {\n await worker.request({\n method: \"update\",\n file: fileURLToPath(uri),\n source,\n version,\n });\n }\n },\n analyze: async (uri, signal) => {\n if (!accepts(uri) || signal?.aborted) {\n return [];\n }\n const results = await worker.analyze(fileURLToPath(uri));\n return signal?.aborted\n ? []\n : results.map(({ project, config, result }) => ({\n project,\n config,\n result: {\n entry: result.entry,\n revision: result.revision,\n status: result.status,\n reports: result.reports,\n error: result.error,\n dependencies: result.graph?.dependencies,\n unverified: result.graph?.unverified,\n generation: result.graph?.generation,\n },\n }));\n },\n closeDocument: async (uri) => {\n if (accepts(uri)) {\n await worker.request({\n method: \"closeDocument\",\n file: fileURLToPath(uri),\n });\n }\n },\n close: async () => {\n await worker.close();\n },\n });\n } catch (error) {\n errors.set(file, String(error));\n await worker.close();\n }\n }\n\n return {\n workspaces,\n errors,\n };\n}\n","import path from \"node:path\";\n\nimport { findConfiguration } from \"@stillwind/config/node\";\n\nimport { RewriteFailure, type RewriteInput, type RewriteResult } from \"./rewrite.ts\";\nimport { AnalysisWorker } from \"./worker-client.ts\";\n\n/** Reuses an isolated process while refreshing trusted configuration for each formatting request. */\nexport class SourceFormatter {\n /** Child process reused across formatting requests and owned until close completes. */\n readonly #worker = new AnalysisWorker();\n /** Serializes requests while allowing a new request after a preceding failure. */\n #queue: Promise<unknown> = Promise.resolve();\n\n /**\n * Starts the isolated worker that evaluates configuration on each formatting request.\n * @param config - Configuration path resolved in the worker's inherited working directory.\n */\n constructor(private readonly config: string) {}\n\n /**\n * Sorts the supplied buffer with current project settings.\n * Files outside all configured scopes return unchanged text. Requests are serialized and never write files.\n * @param input - Original buffer and optional protected ranges. Relative paths are resolved from cwd.\n * @returns The sorted buffer and original findings after configuration is reopened.\n * @throws If configuration loading, parsing, analysis, project agreement, rewriting, or worker communication fails.\n */\n format(input: RewriteInput): Promise<RewriteResult> {\n const task = this.#queue.then(async () => {\n await this.#worker.open(this.config);\n const { outputs, failures } = await this.#worker.rewrite(\n [\n {\n ...input,\n file: path.resolve(input.file),\n },\n ],\n \"sort\",\n );\n if (failures.length) {\n throw new RewriteFailure(failures[0].message, failures[0].results);\n }\n return outputs[0];\n });\n this.#queue = task.catch(() => {});\n return task;\n }\n\n /**\n * Waits for queued formatting and releases the child process. Stop submitting requests before closure.\n * @returns Completion of worker cleanup.\n * @throws If the worker's cleanup request fails.\n */\n async close(): Promise<void> {\n await this.#queue;\n await this.#worker.close();\n }\n}\n\n/**\n * Finds a configuration above a source file or resolves an explicit path from cwd.\n * @param file - Source path whose parent starts upward discovery. Relative paths use cwd.\n * @param config - Optional explicit configuration path, returned without an existence check.\n * @returns The absolute configuration path, or undefined when discovery finds none.\n */\nexport function findFormatterConfig(file: string, config?: string): string | undefined {\n if (config) {\n return path.resolve(config);\n }\n return findConfiguration(path.dirname(path.resolve(file)));\n}\n"],"mappings":";;;;;;;;;;AAuGA,IAAa,iBAAb,MAA4B;;CAE1B;;CAEA,2BAAoB,IAAI,IAQtB;;CAEF;;CAGA,UAAU;;CAEV,UAAU;;CAEV,WAAW;;;;CAKX,cAAc;EACZ,KAAK,SAAS,KAAK,cAAc,IAAI,IAAI,eAAe,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG;GAC7E,OAAO;IAAC;IA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AAQ,MAAM;CAE5B,OAAO,kBAAkB,KAAK,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC;AAC3D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { c as WorkspaceResult } from "./workspace-BF46yPpm.js";
|
|
2
|
+
/**
|
|
3
|
+
* Collects distinct reports per project while preserving their analysis order.
|
|
4
|
+
* @param results - Analysis results with their project membership.
|
|
5
|
+
* @returns Reports in first-occurrence order. Equal reports from different projects remain separate.
|
|
6
|
+
*/
|
|
7
|
+
declare function lintReports(results: readonly WorkspaceResult[]): {
|
|
8
|
+
project: number;
|
|
9
|
+
report: import("@stillwind/native").BindingReport;
|
|
10
|
+
}[];
|
|
11
|
+
export { lintReports as t };
|
|
12
|
+
//# sourceMappingURL=reports-BKeFV47o.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/reports.ts
|
|
2
|
+
/**
|
|
3
|
+
* Collects distinct reports per project while preserving their analysis order.
|
|
4
|
+
* @param results - Analysis results with their project membership.
|
|
5
|
+
* @returns Reports in first-occurrence order. Equal reports from different projects remain separate.
|
|
6
|
+
*/
|
|
7
|
+
function lintReports(results) {
|
|
8
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9
|
+
return results.flatMap((entry) => entry.result.reports.flatMap((report) => {
|
|
10
|
+
const key = JSON.stringify([entry.project, report]);
|
|
11
|
+
if (seen.has(key)) return [];
|
|
12
|
+
seen.add(key);
|
|
13
|
+
return [{
|
|
14
|
+
project: entry.project,
|
|
15
|
+
report
|
|
16
|
+
}];
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
export { lintReports as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=reports-nlgN4YL4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reports-nlgN4YL4.js","names":[],"sources":["../src/reports.ts"],"sourcesContent":["import type { WorkspaceResult } from \"./workspace.ts\";\n\n/**\n * Collects distinct reports per project while preserving their analysis order.\n * @param results - Analysis results with their project membership.\n * @returns Reports in first-occurrence order. Equal reports from different projects remain separate.\n */\nexport function lintReports(results: readonly WorkspaceResult[]) {\n const seen = new Set<string>();\n return results.flatMap((entry) =>\n entry.result.reports.flatMap((report) => {\n const key = JSON.stringify([entry.project, report]);\n if (seen.has(key)) {\n return [];\n }\n seen.add(key);\n return [\n {\n project: entry.project,\n report,\n },\n ];\n }),\n );\n}\n"],"mappings":";;;;;;AAOA,SAAgB,YAAY,SAAqC;CAC/D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO,QAAQ,SAAS,UACtB,MAAM,OAAO,QAAQ,SAAS,WAAW;EACvC,MAAM,MAAM,KAAK,UAAU,CAAC,MAAM,SAAS,MAAM,CAAC;EAClD,IAAI,KAAK,IAAI,GAAG,GACd,OAAO,CAAC;EAEV,KAAK,IAAI,GAAG;EACZ,OAAO,CACL;GACE,SAAS,MAAM;GACf;EACF,CACF;CACF,CAAC,CACH;AACF"}
|