@stillwind/analysis 0.11.0 → 0.13.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/CHANGELOG.md +32 -0
- package/dist/index.js +1 -1
- package/dist/node.d.ts +116 -18
- package/dist/node.js +290 -53
- package/dist/node.js.map +1 -1
- package/dist/{reports-DvHppcFa.js → reports-Bu0OQg-C.js} +3 -2
- package/dist/reports-Bu0OQg-C.js.map +1 -0
- package/dist/{rewrite-Bdo2ssmD.js → rewrite-daiEBUgj.js} +94 -16
- package/dist/rewrite-daiEBUgj.js.map +1 -0
- package/dist/worker.js +237 -5
- package/dist/worker.js.map +1 -1
- package/package.json +5 -5
- package/dist/reports-DvHppcFa.js.map +0 -1
- package/dist/rewrite-Bdo2ssmD.js.map +0 -1
package/dist/node.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { t as RewriteFailure } from "./rewrite-
|
|
2
|
-
import { r as lintReports } from "./reports-
|
|
1
|
+
import { t as RewriteFailure } from "./rewrite-daiEBUgj.js";
|
|
2
|
+
import { r as lintReports } from "./reports-Bu0OQg-C.js";
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { findConfiguration, findDocumentConfiguration } from "@stillwind/config/node";
|
|
6
|
+
import { availableParallelism } from "node:os";
|
|
6
7
|
import { fork } from "node:child_process";
|
|
7
8
|
import process$1 from "node:process";
|
|
8
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
10
|
import { isStylesheet } from "@stillwind/host";
|
|
10
11
|
// src/worker-client.ts
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Isolates configuration and plugin logs from CLI JSON and the LSP stdout transport.
|
|
14
|
+
*/
|
|
12
15
|
var AnalysisWorker = class {
|
|
13
16
|
/** Owned child with IPC enabled. Both output streams are forwarded to the parent's stderr. */
|
|
14
17
|
#child;
|
|
@@ -92,11 +95,11 @@ var AnalysisWorker = class {
|
|
|
92
95
|
* Replaces the child workspace, closing any previously opened hosts first.
|
|
93
96
|
*
|
|
94
97
|
* @param config - Configuration path. Relative paths use the child's inherited working directory.
|
|
95
|
-
* @returns
|
|
98
|
+
* @returns The number of configured projects, after the configuration and project hosts have opened.
|
|
96
99
|
* @throws If configuration evaluation, project initialization, or transport fails.
|
|
97
100
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
open(config) {
|
|
102
|
+
return this.request({
|
|
100
103
|
method: "open",
|
|
101
104
|
config
|
|
102
105
|
});
|
|
@@ -119,13 +122,15 @@ var AnalysisWorker = class {
|
|
|
119
122
|
*
|
|
120
123
|
* @param patterns - Additional globs relative to each project root. Empty or omitted filters
|
|
121
124
|
* retain every configured target.
|
|
125
|
+
* @param projects - Zero-based indices of the projects to analyze. Omission analyzes every project.
|
|
122
126
|
* @returns Results in project order and sorted target order within each project.
|
|
123
127
|
* @throws If the workspace has not opened, enumeration fails, or transport fails.
|
|
124
128
|
*/
|
|
125
|
-
lint(patterns) {
|
|
129
|
+
lint(patterns, projects) {
|
|
126
130
|
return this.request({
|
|
127
131
|
method: "lint",
|
|
128
|
-
patterns
|
|
132
|
+
patterns,
|
|
133
|
+
projects
|
|
129
134
|
});
|
|
130
135
|
}
|
|
131
136
|
/**
|
|
@@ -144,6 +149,22 @@ var AnalysisWorker = class {
|
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
151
|
/**
|
|
152
|
+
* Enumerates the targets of each project in the opened workspace.
|
|
153
|
+
*
|
|
154
|
+
* @param patterns - Additional project-relative globs. Omission or an empty list retains all targets.
|
|
155
|
+
* @param stylesheets - Adds the stylesheets that each project lints.
|
|
156
|
+
* @returns One list of sorted absolute paths for each project, in project order. A path that
|
|
157
|
+
* several projects include appears in each of their lists.
|
|
158
|
+
* @throws If the workspace has not opened, enumeration fails, or transport fails.
|
|
159
|
+
*/
|
|
160
|
+
projectTargets(patterns, stylesheets) {
|
|
161
|
+
return this.request({
|
|
162
|
+
method: "projectTargets",
|
|
163
|
+
patterns,
|
|
164
|
+
stylesheets
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
147
168
|
* Computes replacements from captured buffers without writing files.
|
|
148
169
|
*
|
|
149
170
|
* @param inputs - Distinct absolute target paths and complete original text.
|
|
@@ -151,11 +172,12 @@ var AnalysisWorker = class {
|
|
|
151
172
|
* @returns Successful replacements and target failures in input order. Captured buffers are removed after planning.
|
|
152
173
|
* @throws If workspace setup, buffer installation, cleanup, or transport fails.
|
|
153
174
|
*/
|
|
154
|
-
rewrite(inputs, operation) {
|
|
175
|
+
rewrite(inputs, operation, hooks) {
|
|
155
176
|
return this.request({
|
|
156
177
|
method: "rewrite",
|
|
157
178
|
inputs,
|
|
158
|
-
operation
|
|
179
|
+
operation,
|
|
180
|
+
hooks
|
|
159
181
|
});
|
|
160
182
|
}
|
|
161
183
|
/**
|
|
@@ -182,6 +204,134 @@ var AnalysisWorker = class {
|
|
|
182
204
|
}
|
|
183
205
|
}
|
|
184
206
|
};
|
|
207
|
+
// src/project-workers.ts
|
|
208
|
+
/**
|
|
209
|
+
* Splits configured projects into groups that separate worker processes analyze concurrently.
|
|
210
|
+
*
|
|
211
|
+
* Projects that share a target stay in one group, because a rewrite must compare the answers of
|
|
212
|
+
* every project that includes the target. Groups are balanced by their number of distinct targets.
|
|
213
|
+
*
|
|
214
|
+
* @param targets - Absolute target paths of each project, in project order. Projects without
|
|
215
|
+
* targets are still assigned to a group.
|
|
216
|
+
* @param limit - Maximum number of groups. Values below 1 are treated as 1.
|
|
217
|
+
* @returns Non-empty groups of ascending zero-based project indices, ordered by their first index.
|
|
218
|
+
* Every project index appears in exactly one group. An empty input returns no groups.
|
|
219
|
+
*/
|
|
220
|
+
function groupProjects(targets, limit) {
|
|
221
|
+
const parents = targets.map((_, index) => index);
|
|
222
|
+
const root = (index) => {
|
|
223
|
+
while (parents[index] !== index) {
|
|
224
|
+
parents[index] = parents[parents[index]];
|
|
225
|
+
index = parents[index];
|
|
226
|
+
}
|
|
227
|
+
return index;
|
|
228
|
+
};
|
|
229
|
+
const owners = /* @__PURE__ */ new Map();
|
|
230
|
+
for (const [index, files] of targets.entries()) for (const file of files) {
|
|
231
|
+
const owner = owners.get(file);
|
|
232
|
+
if (owner === void 0) owners.set(file, index);
|
|
233
|
+
else parents[root(index)] = root(owner);
|
|
234
|
+
}
|
|
235
|
+
const components = /* @__PURE__ */ new Map();
|
|
236
|
+
for (const [index, files] of targets.entries()) {
|
|
237
|
+
const component = components.get(root(index)) ?? {
|
|
238
|
+
projects: [],
|
|
239
|
+
files: /* @__PURE__ */ new Set()
|
|
240
|
+
};
|
|
241
|
+
component.projects.push(index);
|
|
242
|
+
for (const file of files) component.files.add(file);
|
|
243
|
+
components.set(root(index), component);
|
|
244
|
+
}
|
|
245
|
+
const bins = Array.from({ length: Math.min(components.size, Math.max(1, Math.floor(limit))) }, () => ({
|
|
246
|
+
projects: [],
|
|
247
|
+
weight: 0
|
|
248
|
+
}));
|
|
249
|
+
const ordered = [...components.values()].sort((a, b) => b.files.size - a.files.size || a.projects[0] - b.projects[0]);
|
|
250
|
+
for (const component of ordered) {
|
|
251
|
+
const bin = bins.reduce((lightest, candidate) => candidate.weight < lightest.weight ? candidate : lightest);
|
|
252
|
+
bin.projects.push(...component.projects);
|
|
253
|
+
bin.weight += component.files.size;
|
|
254
|
+
}
|
|
255
|
+
return bins.map((bin) => bin.projects.sort((a, b) => a - b)).filter((projects) => projects.length).sort((a, b) => a[0] - b[0]);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Resolves the maximum number of analysis worker processes.
|
|
259
|
+
*
|
|
260
|
+
* @param concurrency - Requested maximum. Omission selects half of the available parallelism.
|
|
261
|
+
* @returns A positive integer.
|
|
262
|
+
* @throws If concurrency is present and is not a positive integer.
|
|
263
|
+
*/
|
|
264
|
+
function analysisConcurrency(concurrency) {
|
|
265
|
+
if (concurrency === void 0) return Math.max(1, Math.floor(availableParallelism() / 2));
|
|
266
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) throw new Error(`Analysis concurrency must be a positive integer: ${concurrency}`);
|
|
267
|
+
return concurrency;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Worker processes that analyze disjoint project groups of one configuration concurrently.
|
|
271
|
+
* Close it after use, also when an operation fails.
|
|
272
|
+
*/
|
|
273
|
+
var ProjectWorkers = class ProjectWorkers {
|
|
274
|
+
/** Every started worker, including workers that no group uses. */
|
|
275
|
+
#workers;
|
|
276
|
+
/** Groups in order of their first project index. */
|
|
277
|
+
groups;
|
|
278
|
+
/** Sorted, distinct absolute targets of every group. */
|
|
279
|
+
files;
|
|
280
|
+
constructor(workers, groups) {
|
|
281
|
+
this.#workers = workers;
|
|
282
|
+
this.groups = groups;
|
|
283
|
+
this.files = [...new Set(groups.flatMap((group) => group.files))].sort();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Opens the configuration in one worker, enumerates targets, and opens more workers when the
|
|
287
|
+
* configuration has several project groups.
|
|
288
|
+
*
|
|
289
|
+
* @param config - Absolute configuration path.
|
|
290
|
+
* @param options - Target filters, stylesheet selection, and the maximum number of workers.
|
|
291
|
+
* @returns Workers whose groups partition the selected targets. A group can have no files.
|
|
292
|
+
* @throws If a worker cannot open the configuration, enumeration fails, or concurrency is invalid.
|
|
293
|
+
* Started workers are closed before the error is rethrown.
|
|
294
|
+
*/
|
|
295
|
+
static async open(config, options) {
|
|
296
|
+
const limit = analysisConcurrency(options.concurrency);
|
|
297
|
+
const first = new AnalysisWorker();
|
|
298
|
+
const workers = [first];
|
|
299
|
+
try {
|
|
300
|
+
const count = await first.open(config);
|
|
301
|
+
if (Math.min(count, limit) <= 1) {
|
|
302
|
+
const files = await first.targets(options.patterns, options.stylesheets);
|
|
303
|
+
return new ProjectWorkers(workers, [{
|
|
304
|
+
worker: first,
|
|
305
|
+
files
|
|
306
|
+
}]);
|
|
307
|
+
}
|
|
308
|
+
const extra = Array.from({ length: Math.min(count, limit) - 1 }, () => new AnalysisWorker());
|
|
309
|
+
workers.push(...extra);
|
|
310
|
+
const opening = Promise.all(extra.map((worker) => worker.open(config)));
|
|
311
|
+
const [targets] = await Promise.all([first.projectTargets(options.patterns, options.stylesheets), opening]);
|
|
312
|
+
const groups = groupProjects(targets, limit).map((projects, index) => ({
|
|
313
|
+
worker: workers[index],
|
|
314
|
+
projects,
|
|
315
|
+
files: [...new Set(projects.flatMap((project) => targets[project]))].sort()
|
|
316
|
+
}));
|
|
317
|
+
const unused = workers.splice(groups.length);
|
|
318
|
+
await Promise.all(unused.map((worker) => worker.close()));
|
|
319
|
+
return new ProjectWorkers(workers, groups);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
await Promise.allSettled(workers.map((worker) => worker.close()));
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Closes every worker and waits for each process to exit.
|
|
327
|
+
*
|
|
328
|
+
* @throws The first cleanup failure after every worker has been closed.
|
|
329
|
+
*/
|
|
330
|
+
async close() {
|
|
331
|
+
const failure = (await Promise.allSettled(this.#workers.map((worker) => worker.close()))).find((result) => result.status === "rejected");
|
|
332
|
+
if (failure) throw failure.reason;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
185
335
|
// src/write.ts
|
|
186
336
|
/**
|
|
187
337
|
* Saves changed bytes once per file. Identical buffers perform no filesystem operations.
|
|
@@ -213,20 +363,26 @@ async function writeChangedFiles(changes) {
|
|
|
213
363
|
// src/rewrite-files.ts
|
|
214
364
|
/**
|
|
215
365
|
* Computes all replacements before optionally saving changed files. Fixes return final findings.
|
|
366
|
+
* Disjoint project groups are rewritten concurrently in separate worker processes. A group reads
|
|
367
|
+
* the targets of other groups from disk, not from their buffers of the current pass.
|
|
216
368
|
*
|
|
217
369
|
* @param options - Configuration discovery and optional filters within configured target scopes.
|
|
218
|
-
* @param operation - Utility sorting or converged lint fixes.
|
|
370
|
+
* @param operation - Utility sorting, converged lint fixes, or converged lint fixes followed by sorting.
|
|
219
371
|
* @param write - Whether to verify and save changed bytes after every replacement is planned.
|
|
220
372
|
* @returns Configuration, sorted changed paths, findings, and independent target failures.
|
|
221
373
|
* Saving reports only paths whose writes succeeded. Check mode reports planned changes.
|
|
222
|
-
* @throws If selection is empty, configuration, worker communication,
|
|
374
|
+
* @throws If selection is empty, concurrency is invalid, or configuration, worker communication,
|
|
375
|
+
* or cleanup fails.
|
|
223
376
|
*/
|
|
224
|
-
async function rewriteFiles(options, operation, write) {
|
|
377
|
+
async function rewriteFiles(options, operation, write, hooks) {
|
|
225
378
|
const config = resolveRewriteConfig(options);
|
|
226
|
-
const
|
|
379
|
+
const workers = await ProjectWorkers.open(config, {
|
|
380
|
+
patterns: options.patterns,
|
|
381
|
+
stylesheets: true,
|
|
382
|
+
concurrency: options.concurrency
|
|
383
|
+
});
|
|
227
384
|
try {
|
|
228
|
-
|
|
229
|
-
const files = await worker.targets(options.patterns, true);
|
|
385
|
+
const files = workers.files;
|
|
230
386
|
if (!files.length) throw new Error("No analysis targets matched the configured scopes");
|
|
231
387
|
const failures = [];
|
|
232
388
|
const originals = /* @__PURE__ */ new Map();
|
|
@@ -251,7 +407,15 @@ async function rewriteFiles(options, operation, write) {
|
|
|
251
407
|
});
|
|
252
408
|
}
|
|
253
409
|
}
|
|
254
|
-
const
|
|
410
|
+
const groupOf = new Map(workers.groups.flatMap((group, index) => group.files.map((file) => [file, index])));
|
|
411
|
+
const batches = await Promise.all(workers.groups.map((group, index) => group.worker.rewrite(inputs.filter((input) => groupOf.get(input.file) === index), operation, hooks && group.projects ? {
|
|
412
|
+
...hooks,
|
|
413
|
+
projects: group.projects
|
|
414
|
+
} : hooks)));
|
|
415
|
+
const batch = {
|
|
416
|
+
outputs: batches.flatMap((entry) => entry.outputs),
|
|
417
|
+
failures: batches.flatMap((entry) => entry.failures)
|
|
418
|
+
};
|
|
255
419
|
failures.push(...batch.failures);
|
|
256
420
|
const changes = batch.outputs.map((output) => ({
|
|
257
421
|
file: output.file,
|
|
@@ -274,7 +438,7 @@ async function rewriteFiles(options, operation, write) {
|
|
|
274
438
|
failures
|
|
275
439
|
};
|
|
276
440
|
} finally {
|
|
277
|
-
await
|
|
441
|
+
await workers.close();
|
|
278
442
|
}
|
|
279
443
|
}
|
|
280
444
|
/**
|
|
@@ -290,19 +454,25 @@ function resolveRewriteConfig(options) {
|
|
|
290
454
|
if (!config) throw new Error(`Cannot find Stillwind configuration above ${cwd}`);
|
|
291
455
|
return config;
|
|
292
456
|
}
|
|
293
|
-
// src/
|
|
457
|
+
// src/check.ts
|
|
294
458
|
/**
|
|
295
|
-
*
|
|
459
|
+
* Runs lint and utility sorting in one worker pass. Without fix, checks formatting and reports
|
|
460
|
+
* findings without saving. With fix, applies converged automatic fixes and utility sorting, saves
|
|
461
|
+
* changed files, and reports findings for the final sources.
|
|
296
462
|
*
|
|
297
|
-
* @param options - Configuration discovery, target filters, and optional
|
|
298
|
-
* @returns Changed paths,
|
|
463
|
+
* @param options - Configuration discovery, target filters, and optional fix mode.
|
|
464
|
+
* @returns Changed paths, findings, failures, and exit code. Healthy targets continue after a failure.
|
|
299
465
|
* @throws If selection, configuration, worker communication, or cleanup fails.
|
|
300
466
|
*/
|
|
301
|
-
async function
|
|
302
|
-
const result = await rewriteFiles(options, "sort",
|
|
467
|
+
async function check(options = {}) {
|
|
468
|
+
const result = await rewriteFiles(options, options.fix ? "fixes-and-sort" : "sort", !!options.fix, {
|
|
469
|
+
command: "check",
|
|
470
|
+
mode: options.fix ? "write" : "check"
|
|
471
|
+
});
|
|
472
|
+
const hasErrors = result.results.some(({ result: entry }) => entry.reports.some((report) => report.severity === "error"));
|
|
303
473
|
return {
|
|
304
474
|
...result,
|
|
305
|
-
exitCode: result.failures.length ? 2 : options.
|
|
475
|
+
exitCode: result.failures.length ? 2 : hasErrors || !options.fix && result.changed.length ? 1 : 0
|
|
306
476
|
};
|
|
307
477
|
}
|
|
308
478
|
// src/design-system.ts
|
|
@@ -339,6 +509,46 @@ async function designSystem(options, request) {
|
|
|
339
509
|
await worker.close();
|
|
340
510
|
}
|
|
341
511
|
}
|
|
512
|
+
// src/format.ts
|
|
513
|
+
/**
|
|
514
|
+
* Sorts configured targets and saves changed files unless check is true.
|
|
515
|
+
*
|
|
516
|
+
* @param options - Configuration discovery, target filters, and optional check mode.
|
|
517
|
+
* @returns Changed paths, original findings, and failures. Healthy targets continue after a failure.
|
|
518
|
+
* @throws If selection, configuration, worker communication, or cleanup fails.
|
|
519
|
+
*/
|
|
520
|
+
async function format(options = {}) {
|
|
521
|
+
const result = await rewriteFiles(options, "sort", !options.check, {
|
|
522
|
+
command: "fmt",
|
|
523
|
+
mode: options.check ? "check" : "write"
|
|
524
|
+
});
|
|
525
|
+
return {
|
|
526
|
+
...result,
|
|
527
|
+
exitCode: result.failures.length ? 2 : options.check && result.changed.length ? 1 : 0
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
// src/info.ts
|
|
531
|
+
/**
|
|
532
|
+
* Resolves the configuration and returns each project's effective scope, plugins, and active lint
|
|
533
|
+
* rules in a child process without compiling source files.
|
|
534
|
+
*
|
|
535
|
+
* @param options - Configuration discovery. Target globs do not apply.
|
|
536
|
+
* @returns Configuration path and resolved project metadata.
|
|
537
|
+
* @throws If configuration discovery, evaluation, worker initialization, or cleanup fails.
|
|
538
|
+
*/
|
|
539
|
+
async function info(options = {}) {
|
|
540
|
+
const config = resolveRewriteConfig(options);
|
|
541
|
+
const worker = new AnalysisWorker();
|
|
542
|
+
try {
|
|
543
|
+
await worker.open(config);
|
|
544
|
+
return {
|
|
545
|
+
config,
|
|
546
|
+
projects: await worker.request({ method: "info" })
|
|
547
|
+
};
|
|
548
|
+
} finally {
|
|
549
|
+
await worker.close();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
342
552
|
// src/inspect.ts
|
|
343
553
|
/**
|
|
344
554
|
* Parses a command-line target with an optional `:line` or `:line:column` suffix.
|
|
@@ -409,9 +619,15 @@ async function selectPreviews(worker, file, source, target, reports) {
|
|
|
409
619
|
const line = target.line === void 0 ? void 0 : target.line - 1;
|
|
410
620
|
const lineStart = line === void 0 ? void 0 : lines[line];
|
|
411
621
|
const lineEnd = line === void 0 ? void 0 : (lines[line + 1] ?? source.length + 1) - 1;
|
|
412
|
-
if (line !== void 0 && lineStart === void 0) return
|
|
622
|
+
if (line !== void 0 && lineStart === void 0) return {
|
|
623
|
+
previews: [],
|
|
624
|
+
emptyReason: "line-out-of-range"
|
|
625
|
+
};
|
|
413
626
|
const offset = target.column === void 0 ? void 0 : lineStart + target.column - 1;
|
|
414
|
-
if (offset !== void 0 && offset > lineEnd) return
|
|
627
|
+
if (offset !== void 0 && offset > lineEnd) return {
|
|
628
|
+
previews: [],
|
|
629
|
+
emptyReason: "column-out-of-range"
|
|
630
|
+
};
|
|
415
631
|
const query = (request) => worker.request({
|
|
416
632
|
method: "query",
|
|
417
633
|
file,
|
|
@@ -419,11 +635,15 @@ async function selectPreviews(worker, file, source, target, reports) {
|
|
|
419
635
|
});
|
|
420
636
|
const uri = pathToFileURL(file).href;
|
|
421
637
|
let selected;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
638
|
+
let fileHasPreviews = false;
|
|
639
|
+
if (offset === void 0) {
|
|
640
|
+
const all = await query({ kind: "previews" });
|
|
641
|
+
fileHasPreviews = all.some(({ result }) => (result.previews?.length ?? 0) > 0);
|
|
642
|
+
selected = all.flatMap(({ project, result }) => (result.previews ?? []).filter(({ start, end }) => line === void 0 || end > lineStart && start <= lineEnd).map((range) => ({
|
|
643
|
+
project,
|
|
644
|
+
range
|
|
645
|
+
})));
|
|
646
|
+
} else {
|
|
427
647
|
const hovers = await query({
|
|
428
648
|
kind: "hover",
|
|
429
649
|
offset
|
|
@@ -434,13 +654,15 @@ async function selectPreviews(worker, file, source, target, reports) {
|
|
|
434
654
|
}] : []);
|
|
435
655
|
if (selected.length < hovers.length) {
|
|
436
656
|
const answered = new Set(selected.map(({ project }) => project));
|
|
437
|
-
|
|
657
|
+
const all = await query({ kind: "previews" });
|
|
658
|
+
fileHasPreviews = all.some(({ result }) => (result.previews?.length ?? 0) > 0);
|
|
659
|
+
selected.push(...all.flatMap(({ project, result }) => answered.has(project) ? [] : (result.previews ?? []).filter(({ start, end }) => start <= offset && offset <= end).map((range) => ({
|
|
438
660
|
project,
|
|
439
661
|
range
|
|
440
662
|
}))));
|
|
441
663
|
}
|
|
442
664
|
}
|
|
443
|
-
|
|
665
|
+
const previews = selected.flatMap(({ project, range: { start, end, css, valid = true, documentation, runtimeNames } }) => {
|
|
444
666
|
const diagnostics = reports.filter(({ project: owner, report: { primary } }) => owner === project && primary.location.startUtf16 < end && start < Math.max(primary.location.endUtf16, primary.location.startUtf16 + 1)).map(({ report: { severity, code, message } }) => ({
|
|
445
667
|
severity,
|
|
446
668
|
code,
|
|
@@ -466,6 +688,11 @@ async function selectPreviews(worker, file, source, target, reports) {
|
|
|
466
688
|
...runtimeNames ? { runtimeNames } : {}
|
|
467
689
|
}];
|
|
468
690
|
});
|
|
691
|
+
if (!previews.length) return {
|
|
692
|
+
previews,
|
|
693
|
+
emptyReason: line !== void 0 && fileHasPreviews ? "no-match-at-position" : "no-styles"
|
|
694
|
+
};
|
|
695
|
+
return { previews };
|
|
469
696
|
}
|
|
470
697
|
/**
|
|
471
698
|
* Reports the generated CSS of configured source files in a child process.
|
|
@@ -499,6 +726,7 @@ async function inspect(options = {}) {
|
|
|
499
726
|
previews: [],
|
|
500
727
|
failures: []
|
|
501
728
|
};
|
|
729
|
+
const emptyReasons = /* @__PURE__ */ new Set();
|
|
502
730
|
for (const file of files) {
|
|
503
731
|
const analyses = await worker.analyze(file);
|
|
504
732
|
result.results.push(...analyses);
|
|
@@ -518,22 +746,27 @@ async function inspect(options = {}) {
|
|
|
518
746
|
const reports = lintReports(analyses).filter(({ report }) => report.primary.scope === "range" && isDocument(report.primary.location.uri, file));
|
|
519
747
|
const seen = /* @__PURE__ */ new Set();
|
|
520
748
|
const previews = [];
|
|
521
|
-
for (const target of selections.get(file))
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
startLine,
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
749
|
+
for (const target of selections.get(file)) {
|
|
750
|
+
const selection = await selectPreviews(worker, file, source, target, reports);
|
|
751
|
+
if (selection.emptyReason) emptyReasons.add(selection.emptyReason);
|
|
752
|
+
for (const preview of selection.previews) {
|
|
753
|
+
const { startLine, startColumn, endLine, endColumn } = preview.location;
|
|
754
|
+
const key = [
|
|
755
|
+
preview.project,
|
|
756
|
+
startLine,
|
|
757
|
+
startColumn,
|
|
758
|
+
endLine,
|
|
759
|
+
endColumn
|
|
760
|
+
].join();
|
|
761
|
+
if (complete.has(preview.project) && !seen.has(key)) {
|
|
762
|
+
seen.add(key);
|
|
763
|
+
previews.push(preview);
|
|
764
|
+
}
|
|
533
765
|
}
|
|
534
766
|
}
|
|
535
767
|
result.previews.push(...previews.sort((a, b) => a.project - b.project || a.location.startLine - b.location.startLine || a.location.startColumn - b.location.startColumn));
|
|
536
768
|
}
|
|
769
|
+
if (!result.previews.length && !result.failures.length) result.emptyReason = emptyReasons.has("no-match-at-position") ? "no-match-at-position" : emptyReasons.has("column-out-of-range") ? "column-out-of-range" : emptyReasons.has("line-out-of-range") ? "line-out-of-range" : "no-styles";
|
|
537
770
|
return result;
|
|
538
771
|
} finally {
|
|
539
772
|
await worker.close();
|
|
@@ -541,12 +774,14 @@ async function inspect(options = {}) {
|
|
|
541
774
|
}
|
|
542
775
|
// src/lint.ts
|
|
543
776
|
/**
|
|
544
|
-
* Analyzes configured target scopes in
|
|
777
|
+
* Analyzes configured target scopes in child processes and closes them before returning. Disjoint
|
|
778
|
+
* project groups are analyzed concurrently.
|
|
545
779
|
*
|
|
546
780
|
* @param options - Configuration discovery and optional target filters. Omission checks all
|
|
547
781
|
* configured targets from the process working directory.
|
|
548
782
|
* @returns Results and an exit code. Readonly lint returns code 2 for empty selection or incomplete analysis.
|
|
549
|
-
* @throws If configuration discovery, worker initialization, target enumeration, or cleanup fails
|
|
783
|
+
* @throws If configuration discovery, worker initialization, target enumeration, or cleanup fails,
|
|
784
|
+
* or if concurrency is invalid.
|
|
550
785
|
* Fix mode reports failures per target and continues with healthy targets. Empty selection throws.
|
|
551
786
|
*/
|
|
552
787
|
async function lint(options = {}) {
|
|
@@ -558,17 +793,19 @@ async function lint(options = {}) {
|
|
|
558
793
|
};
|
|
559
794
|
}
|
|
560
795
|
const config = resolveRewriteConfig(options);
|
|
561
|
-
const
|
|
796
|
+
const workers = await ProjectWorkers.open(config, {
|
|
797
|
+
patterns: options.patterns,
|
|
798
|
+
concurrency: options.concurrency
|
|
799
|
+
});
|
|
562
800
|
try {
|
|
563
|
-
await worker.
|
|
564
|
-
const results = await worker.lint(options.patterns);
|
|
801
|
+
const results = (await Promise.all(workers.groups.map((group) => group.worker.lint(options.patterns, group.projects)))).flat().sort((a, b) => a.project - b.project);
|
|
565
802
|
return {
|
|
566
803
|
config,
|
|
567
804
|
results,
|
|
568
805
|
exitCode: !results.length || results.some(({ result }) => result.status !== "complete") ? 2 : results.some(({ result }) => result.reports.some((report) => report.severity === "error")) ? 1 : 0
|
|
569
806
|
};
|
|
570
807
|
} finally {
|
|
571
|
-
await
|
|
808
|
+
await workers.close();
|
|
572
809
|
}
|
|
573
810
|
}
|
|
574
811
|
/**
|
|
@@ -796,6 +1033,6 @@ function findFormatterConfig(file, config) {
|
|
|
796
1033
|
if (config) return path.resolve(config);
|
|
797
1034
|
return findConfiguration(path.dirname(path.resolve(file)));
|
|
798
1035
|
}
|
|
799
|
-
export { SourceFormatter, designSystem, discoverNodeWorkspace, findFormatterConfig, format, formatLint, inspect, lint, lintReports, openNodeWorkspaces };
|
|
1036
|
+
export { SourceFormatter, check, designSystem, discoverNodeWorkspace, findFormatterConfig, format, formatLint, info, inspect, lint, lintReports, openNodeWorkspaces };
|
|
800
1037
|
|
|
801
1038
|
//# sourceMappingURL=node.js.map
|