@stillwind/analysis 0.0.0-stage → 0.1.0-rc.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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Stillwind contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stillwind/analysis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stillwind compiles Tailwind CSS v4 utilities into component props and static CSS.
|
|
4
|
+
It uses theme rules and compiler checks to keep styling code in order, even when
|
|
5
|
+
AI agents write much of it.
|
|
6
|
+
|
|
7
|
+
`@stillwind/analysis` provides analysis and formatting services for Stillwind's
|
|
8
|
+
CLI, language server, and browser editors. Its Node, browser, and memory
|
|
9
|
+
entrypoints adapt these services to their hosts.
|
|
10
|
+
|
|
11
|
+
See [Analysis contracts](https://github.com/SegaraRai/stillwind/blob/main/docs/standalone-analysis.md)
|
|
12
|
+
for configuration, service lifetimes, and embedding.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { c as WorkspaceResult, i as AnalysisWorkspaceService, s as WorkspaceEditorResult } from "./workspace-BF46yPpm.js";
|
|
2
|
+
import { AnalysisProjectConfig } from "@stillwind/config";
|
|
3
|
+
import { BrowserModuleCss, BrowserProject, BrowserStylesheetOutput, EditorRequest, PluginHost } from "@stillwind/host/browser";
|
|
4
|
+
/**
|
|
5
|
+
* Browser workspace with original URIs and a complete virtual dependency inventory.
|
|
6
|
+
*/
|
|
7
|
+
export interface BrowserWorkspaceOptions {
|
|
8
|
+
/** Configuration URI used to identify diagnostic groups. */
|
|
9
|
+
config: string;
|
|
10
|
+
/** Evaluated projects whose roots are absolute virtual paths. */
|
|
11
|
+
projects: readonly AnalysisProjectConfig[];
|
|
12
|
+
/** Saved source and dependency files, keyed by absolute virtual path. */
|
|
13
|
+
files: ReadonlyMap<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Maps virtual paths back to workspace URIs. Defaults to file URIs.
|
|
16
|
+
*
|
|
17
|
+
* @param path - Decoded absolute virtual path.
|
|
18
|
+
* @returns Original URI used in diagnostics and source maps.
|
|
19
|
+
*/
|
|
20
|
+
documentUri?(this: void, path: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Loads plugin packages and plugin files for `@plugin` statements. Omission limits the projects
|
|
23
|
+
* to the plugins of their configurations.
|
|
24
|
+
*/
|
|
25
|
+
plugins?: PluginHost;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Shares snapshot compilation between LSP analysis and application builds.
|
|
29
|
+
*/
|
|
30
|
+
export declare class BrowserAnalysisWorkspace implements AnalysisWorkspaceService {
|
|
31
|
+
#private;
|
|
32
|
+
/**
|
|
33
|
+
* Creates the projects without loading CSS or compiling sources.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Evaluated settings and saved files captured by this service.
|
|
36
|
+
* Replace the service to apply new configuration or saved inventory. Open buffers use update.
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: BrowserWorkspaceOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Reads the revision required when requesting an application build.
|
|
41
|
+
*
|
|
42
|
+
* @returns Change counter that increases after an effective buffer update or closure.
|
|
43
|
+
*/
|
|
44
|
+
get revision(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Stores an original buffer and increments the workspace revision when it changes.
|
|
47
|
+
*
|
|
48
|
+
* @param uri - Original document URI or virtual path, including dependency files outside target scopes.
|
|
49
|
+
* @param source - Complete unsaved text.
|
|
50
|
+
* @param version - Safe integer greater than the previous version. Identical text at the same version is accepted.
|
|
51
|
+
* @throws If the service is closed or the version is invalid or does not increase.
|
|
52
|
+
*/
|
|
53
|
+
update(uri: string, source: string, version: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Removes an open buffer and increments the revision only when that buffer existed.
|
|
56
|
+
*
|
|
57
|
+
* @param uri - Original URI or virtual path. Future snapshots use saved text for this path.
|
|
58
|
+
*/
|
|
59
|
+
closeDocument(uri: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Captures saved files with open buffers applied.
|
|
62
|
+
*
|
|
63
|
+
* @returns An independent map keyed by absolute virtual path. Later buffer changes do not alter it.
|
|
64
|
+
*/
|
|
65
|
+
files(): ReadonlyMap<string, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Reads one file without copying the inventory.
|
|
68
|
+
*
|
|
69
|
+
* @param uri - Original URI identifying a saved file or open buffer.
|
|
70
|
+
* @param revision - Revision captured when the application build started.
|
|
71
|
+
* @returns Current buffer text, saved text, or undefined for an absent file.
|
|
72
|
+
* @throws If the service is closed or the captured revision is obsolete.
|
|
73
|
+
*/
|
|
74
|
+
readFile(uri: string, revision: number): string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Analyzes the current buffers in each matching project, one queued request at a time.
|
|
77
|
+
* Stylesheets match projects that lint them and return only stylesheet lint findings.
|
|
78
|
+
*
|
|
79
|
+
* @param uri - Original target URI or virtual path.
|
|
80
|
+
* @param signal - Optional cancellation checked before and after compiler work.
|
|
81
|
+
* @returns Results in project order. Compiler failures produce incomplete results, and obsolete
|
|
82
|
+
* or cancelled results omit reports. Targets outside all scopes return an empty list.
|
|
83
|
+
* @throws If the service is closed or its projects cannot be prepared.
|
|
84
|
+
*/
|
|
85
|
+
analyze(uri: string, signal?: AbortSignal): Promise<WorkspaceResult[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Prepares script targets in the projects that include the requested documents.
|
|
88
|
+
*
|
|
89
|
+
* @param uris - Target URIs or absolute virtual paths. Stylesheets do not select a project here.
|
|
90
|
+
* @param signal - Optional cancellation checked before queued work starts.
|
|
91
|
+
* @returns Completion of preparation. Closed, cancelled, and outdated requests do no work.
|
|
92
|
+
* Source failures are left for analyze to report.
|
|
93
|
+
* @throws If project files cannot be replaced.
|
|
94
|
+
*/
|
|
95
|
+
prepare(uris: readonly string[], signal?: AbortSignal): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Checks whether save or watch notifications need a new workspace.
|
|
98
|
+
*
|
|
99
|
+
* @param uris - Document URIs or absolute virtual paths reported by the notification.
|
|
100
|
+
* @returns True when every file has an open buffer and none is the workspace configuration,
|
|
101
|
+
* a tsconfig, or package.json. This method does not change files or reopen projects.
|
|
102
|
+
*/
|
|
103
|
+
refresh(uris: readonly string[]): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Transforms a module for a browser application build.
|
|
106
|
+
*
|
|
107
|
+
* @param uri - Source URI in exactly one configured project.
|
|
108
|
+
* @param revision - Workspace revision captured when the application build started.
|
|
109
|
+
* @returns Transformed source, CSS, and reports.
|
|
110
|
+
* Blocked graphs retain diagnostics and return empty CSS and CSS values.
|
|
111
|
+
* @throws If project selection fails or the build revision became obsolete.
|
|
112
|
+
*/
|
|
113
|
+
compile(uri: string, revision: number): Promise<{
|
|
114
|
+
/** Transformed source graph, including diagnostic reports and generation eligibility. */
|
|
115
|
+
graph: Awaited<ReturnType<BrowserProject["analyze"]>>;
|
|
116
|
+
/** Current combined CSS, empty when the graph blocks generation. */
|
|
117
|
+
css: string;
|
|
118
|
+
/** Naming fallbacks observed during document assembly. */
|
|
119
|
+
rejectedNames: BrowserStylesheetOutput["rejectedNames"];
|
|
120
|
+
/** Module identity and its CSS record, empty when generation is blocked. */
|
|
121
|
+
cssValues: [string, BrowserModuleCss][];
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Queries retained projects against a captured inventory and discards obsolete answers.
|
|
125
|
+
*
|
|
126
|
+
* @param uri - Original target URI or virtual path.
|
|
127
|
+
* @param request - Operation with offsets in the original UTF-16 document.
|
|
128
|
+
* @param signal - Optional cancellation checked around project preparation and queries.
|
|
129
|
+
* @returns Answers in project order, or an empty list after closure, cancellation, or a revision change.
|
|
130
|
+
* @throws If project preparation or an editor query fails.
|
|
131
|
+
*/
|
|
132
|
+
query(uri: string, request: EditorRequest, signal?: AbortSignal): Promise<WorkspaceEditorResult[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Marks the service closed, invalidates captured revisions, and releases retained projects after queued work.
|
|
135
|
+
*
|
|
136
|
+
* @returns Completion of queued work and project cleanup.
|
|
137
|
+
* @throws If a retained project fails to close.
|
|
138
|
+
*/
|
|
139
|
+
close(): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=browser.d.ts.map
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { captureProjectConfig } from "@stillwind/config";
|
|
2
|
+
import { BrowserProject, virtualPath } from "@stillwind/host/browser";
|
|
3
|
+
import { minimatch } from "minimatch";
|
|
4
|
+
import { relative, resolve } from "pathe";
|
|
5
|
+
// src/browser.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shares snapshot compilation between LSP analysis and application builds.
|
|
8
|
+
*/
|
|
9
|
+
var BrowserAnalysisWorkspace = class {
|
|
10
|
+
/** Owned settings and saved inventory fixed when this service is created. */
|
|
11
|
+
#options;
|
|
12
|
+
/** Open buffers keyed by decoded virtual path, applied over the saved inventory. */
|
|
13
|
+
#documents = /* @__PURE__ */ new Map();
|
|
14
|
+
/** Change counter captured by analyses, editor queries, and application builds. */
|
|
15
|
+
#revision = 0;
|
|
16
|
+
/** Retained projects updated between compiler transactions and shared by queries and builds. */
|
|
17
|
+
#projects;
|
|
18
|
+
/** Revision of the files installed in the projects. -1 means no installation yet. */
|
|
19
|
+
#projectRevision = -1;
|
|
20
|
+
/** Project indices whose targets have been prepared at projectRevision. */
|
|
21
|
+
#preparedProjects = /* @__PURE__ */ new Set();
|
|
22
|
+
/** Prevents new analysis and invalidates queued editor queries during closure. */
|
|
23
|
+
#closed = false;
|
|
24
|
+
/** Serializes compiler operations and absorbs failures for subsequent operations. */
|
|
25
|
+
#queue = Promise.resolve();
|
|
26
|
+
/**
|
|
27
|
+
* Updates project files and prepares targets once per workspace revision.
|
|
28
|
+
*
|
|
29
|
+
* @param revision - Workspace revision captured with files before this operation was queued.
|
|
30
|
+
* @param files - All saved files with the captured open buffers applied.
|
|
31
|
+
* @param indices - Project indices whose script targets need preparation. Omission only updates files.
|
|
32
|
+
* @returns Completion of file updates and target preparation. Repeated requests reuse that work.
|
|
33
|
+
* @throws If a project's files cannot be replaced.
|
|
34
|
+
*/
|
|
35
|
+
async #prepareProjects(revision, files, indices = []) {
|
|
36
|
+
if (this.#projectRevision !== revision) {
|
|
37
|
+
await Promise.all(this.#projects.map((project) => project.replaceFiles(files)));
|
|
38
|
+
this.#preparedProjects.clear();
|
|
39
|
+
this.#projectRevision = revision;
|
|
40
|
+
}
|
|
41
|
+
for (const index of indices) if (!this.#preparedProjects.has(index)) {
|
|
42
|
+
await this.#projects[index].prepare([...files.keys()].filter((id) => includes(this.#options.projects[index], id) && !isStylesheet(id)));
|
|
43
|
+
this.#preparedProjects.add(index);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates the projects without loading CSS or compiling sources.
|
|
48
|
+
*
|
|
49
|
+
* @param options - Evaluated settings and saved files captured by this service.
|
|
50
|
+
* Replace the service to apply new configuration or saved inventory. Open buffers use update.
|
|
51
|
+
*/
|
|
52
|
+
constructor(options) {
|
|
53
|
+
this.#options = {
|
|
54
|
+
...options,
|
|
55
|
+
projects: options.projects.map(captureProjectConfig),
|
|
56
|
+
files: new Map(options.files)
|
|
57
|
+
};
|
|
58
|
+
this.#projects = this.#options.projects.map((config) => new BrowserProject({
|
|
59
|
+
root: config.root,
|
|
60
|
+
config,
|
|
61
|
+
files: this.#options.files,
|
|
62
|
+
documentUri: this.#options.documentUri,
|
|
63
|
+
plugins: this.#options.plugins
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reads the revision required when requesting an application build.
|
|
68
|
+
*
|
|
69
|
+
* @returns Change counter that increases after an effective buffer update or closure.
|
|
70
|
+
*/
|
|
71
|
+
get revision() {
|
|
72
|
+
return this.#revision;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stores an original buffer and increments the workspace revision when it changes.
|
|
76
|
+
*
|
|
77
|
+
* @param uri - Original document URI or virtual path, including dependency files outside target scopes.
|
|
78
|
+
* @param source - Complete unsaved text.
|
|
79
|
+
* @param version - Safe integer greater than the previous version. Identical text at the same version is accepted.
|
|
80
|
+
* @throws If the service is closed or the version is invalid or does not increase.
|
|
81
|
+
*/
|
|
82
|
+
update(uri, source, version) {
|
|
83
|
+
if (this.#closed) throw new Error("Browser workspace is closed");
|
|
84
|
+
const id = virtualPath(uri);
|
|
85
|
+
const previous = this.#documents.get(id);
|
|
86
|
+
if (previous?.version === version && previous.source === source) return;
|
|
87
|
+
if (!Number.isSafeInteger(version) || previous && version <= previous.version) throw new Error("Analysis document versions must increase");
|
|
88
|
+
this.#documents.set(id, {
|
|
89
|
+
source,
|
|
90
|
+
version
|
|
91
|
+
});
|
|
92
|
+
this.#revision++;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Removes an open buffer and increments the revision only when that buffer existed.
|
|
96
|
+
*
|
|
97
|
+
* @param uri - Original URI or virtual path. Future snapshots use saved text for this path.
|
|
98
|
+
*/
|
|
99
|
+
closeDocument(uri) {
|
|
100
|
+
if (this.#documents.delete(virtualPath(uri))) this.#revision++;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Captures saved files with open buffers applied.
|
|
104
|
+
*
|
|
105
|
+
* @returns An independent map keyed by absolute virtual path. Later buffer changes do not alter it.
|
|
106
|
+
*/
|
|
107
|
+
files() {
|
|
108
|
+
return new Map([...this.#options.files, ...[...this.#documents].map(([id, document]) => [id, document.source])]);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reads one file without copying the inventory.
|
|
112
|
+
*
|
|
113
|
+
* @param uri - Original URI identifying a saved file or open buffer.
|
|
114
|
+
* @param revision - Revision captured when the application build started.
|
|
115
|
+
* @returns Current buffer text, saved text, or undefined for an absent file.
|
|
116
|
+
* @throws If the service is closed or the captured revision is obsolete.
|
|
117
|
+
*/
|
|
118
|
+
readFile(uri, revision) {
|
|
119
|
+
if (this.#closed || revision !== this.#revision) throw new Error("Browser build snapshot is obsolete");
|
|
120
|
+
const id = virtualPath(uri);
|
|
121
|
+
return this.#documents.get(id)?.source ?? this.#options.files.get(id);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Analyzes the current buffers in each matching project, one queued request at a time.
|
|
125
|
+
* Stylesheets match projects that lint them and return only stylesheet lint findings.
|
|
126
|
+
*
|
|
127
|
+
* @param uri - Original target URI or virtual path.
|
|
128
|
+
* @param signal - Optional cancellation checked before and after compiler work.
|
|
129
|
+
* @returns Results in project order. Compiler failures produce incomplete results, and obsolete
|
|
130
|
+
* or cancelled results omit reports. Targets outside all scopes return an empty list.
|
|
131
|
+
* @throws If the service is closed or its projects cannot be prepared.
|
|
132
|
+
*/
|
|
133
|
+
analyze(uri, signal) {
|
|
134
|
+
const revision = this.#revision;
|
|
135
|
+
const files = this.files();
|
|
136
|
+
const id = virtualPath(uri);
|
|
137
|
+
const task = this.#queue.then(async () => {
|
|
138
|
+
if (this.#closed) throw new Error("Browser workspace is closed");
|
|
139
|
+
/**
|
|
140
|
+
* Classifies work that can no longer publish results from the captured revision.
|
|
141
|
+
*
|
|
142
|
+
* @returns `cancelled` for an aborted signal, `stale` for a newer revision, or undefined.
|
|
143
|
+
*/
|
|
144
|
+
const obsolete = () => signal?.aborted ? "cancelled" : revision !== this.#revision ? "stale" : void 0;
|
|
145
|
+
const results = [];
|
|
146
|
+
const stylesheet = isStylesheet(id);
|
|
147
|
+
for (const [index, config] of this.#options.projects.entries()) {
|
|
148
|
+
if (!includes(config, id) && !stylesheet) continue;
|
|
149
|
+
await this.#prepareProjects(revision, files, stylesheet ? [] : [index]);
|
|
150
|
+
const project = this.#projects[index];
|
|
151
|
+
let result = {
|
|
152
|
+
entry: uri,
|
|
153
|
+
revision,
|
|
154
|
+
status: "incomplete",
|
|
155
|
+
reports: []
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
if (stylesheet) {
|
|
159
|
+
const lint = await project.stylesheetLint().catch(() => void 0);
|
|
160
|
+
if (!lint?.sources.includes(id)) continue;
|
|
161
|
+
result = {
|
|
162
|
+
...result,
|
|
163
|
+
status: "complete",
|
|
164
|
+
reports: lint.reports.filter((report) => virtualPath(report.primary.location.uri) === id)
|
|
165
|
+
};
|
|
166
|
+
} else if (!obsolete()) {
|
|
167
|
+
const graph = await project.analyze(id);
|
|
168
|
+
const observations = structuredClone({
|
|
169
|
+
reports: graph.batches.flatMap((batch) => batch.reports).filter((report) => includes(config, virtualPath(report.primary.location.uri))),
|
|
170
|
+
dependencies: graph.dependencies,
|
|
171
|
+
unverified: graph.unverified
|
|
172
|
+
});
|
|
173
|
+
result = {
|
|
174
|
+
...result,
|
|
175
|
+
...observations,
|
|
176
|
+
status: graph.unverified.length || graph.dependencies.some((dependency) => dependency.status === "unresolved" || dependency.status === "unsupported") ? "incomplete" : "complete",
|
|
177
|
+
generation: graph.generation
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
result.error = error instanceof Error ? error.message : String(error);
|
|
182
|
+
}
|
|
183
|
+
const status = obsolete();
|
|
184
|
+
if (status) result = {
|
|
185
|
+
entry: uri,
|
|
186
|
+
revision,
|
|
187
|
+
status,
|
|
188
|
+
reports: []
|
|
189
|
+
};
|
|
190
|
+
results.push({
|
|
191
|
+
project: index,
|
|
192
|
+
config: this.#options.config,
|
|
193
|
+
result
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return results;
|
|
197
|
+
});
|
|
198
|
+
this.#queue = task.catch(() => {});
|
|
199
|
+
return task;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Prepares script targets in the projects that include the requested documents.
|
|
203
|
+
*
|
|
204
|
+
* @param uris - Target URIs or absolute virtual paths. Stylesheets do not select a project here.
|
|
205
|
+
* @param signal - Optional cancellation checked before queued work starts.
|
|
206
|
+
* @returns Completion of preparation. Closed, cancelled, and outdated requests do no work.
|
|
207
|
+
* Source failures are left for analyze to report.
|
|
208
|
+
* @throws If project files cannot be replaced.
|
|
209
|
+
*/
|
|
210
|
+
prepare(uris, signal) {
|
|
211
|
+
const revision = this.#revision;
|
|
212
|
+
const files = this.files();
|
|
213
|
+
const task = this.#queue.then(async () => {
|
|
214
|
+
if (!this.#closed && !signal?.aborted && revision === this.#revision) {
|
|
215
|
+
const ids = uris.map(virtualPath).filter((id) => !isStylesheet(id));
|
|
216
|
+
const indices = this.#options.projects.flatMap((config, index) => ids.some((id) => includes(config, id)) ? [index] : []);
|
|
217
|
+
await this.#prepareProjects(revision, files, indices);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
this.#queue = task.catch(() => {});
|
|
221
|
+
return task;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Checks whether save or watch notifications need a new workspace.
|
|
225
|
+
*
|
|
226
|
+
* @param uris - Document URIs or absolute virtual paths reported by the notification.
|
|
227
|
+
* @returns True when every file has an open buffer and none is the workspace configuration,
|
|
228
|
+
* a tsconfig, or package.json. This method does not change files or reopen projects.
|
|
229
|
+
*/
|
|
230
|
+
async refresh(uris) {
|
|
231
|
+
return uris.every((uri) => uri !== this.#options.config && this.#documents.has(virtualPath(uri)) && !/(?:^|\/)(?:tsconfig(?:\.[^/]+)?\.json|package\.json)$/.test(virtualPath(uri)));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Transforms a module for a browser application build.
|
|
235
|
+
*
|
|
236
|
+
* @param uri - Source URI in exactly one configured project.
|
|
237
|
+
* @param revision - Workspace revision captured when the application build started.
|
|
238
|
+
* @returns Transformed source, CSS, and reports.
|
|
239
|
+
* Blocked graphs retain diagnostics and return empty CSS and CSS values.
|
|
240
|
+
* @throws If project selection fails or the build revision became obsolete.
|
|
241
|
+
*/
|
|
242
|
+
compile(uri, revision) {
|
|
243
|
+
const files = this.files();
|
|
244
|
+
const id = virtualPath(uri);
|
|
245
|
+
const task = this.#queue.then(async () => {
|
|
246
|
+
if (this.#closed || revision !== this.#revision) throw new Error("Browser build snapshot is obsolete");
|
|
247
|
+
const matches = this.#options.projects.map((config, index) => ({
|
|
248
|
+
config,
|
|
249
|
+
index
|
|
250
|
+
})).filter(({ config }) => includes(config, id));
|
|
251
|
+
if (matches.length !== 1) throw new Error(`Expected one Stillwind project for ${uri}`);
|
|
252
|
+
await this.#prepareProjects(revision, files, [matches[0].index]);
|
|
253
|
+
const project = this.#projects[matches[0].index];
|
|
254
|
+
const graph = await project.analyze(id);
|
|
255
|
+
if (revision !== this.#revision) throw new Error("Browser build snapshot is obsolete");
|
|
256
|
+
return {
|
|
257
|
+
graph,
|
|
258
|
+
...graph.generation === "complete" ? project.css() : {
|
|
259
|
+
css: "",
|
|
260
|
+
rejectedNames: []
|
|
261
|
+
},
|
|
262
|
+
cssValues: graph.generation === "complete" ? [...project.cssValues()] : []
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
this.#queue = task.catch(() => {});
|
|
266
|
+
return task;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Queries retained projects against a captured inventory and discards obsolete answers.
|
|
270
|
+
*
|
|
271
|
+
* @param uri - Original target URI or virtual path.
|
|
272
|
+
* @param request - Operation with offsets in the original UTF-16 document.
|
|
273
|
+
* @param signal - Optional cancellation checked around project preparation and queries.
|
|
274
|
+
* @returns Answers in project order, or an empty list after closure, cancellation, or a revision change.
|
|
275
|
+
* @throws If project preparation or an editor query fails.
|
|
276
|
+
*/
|
|
277
|
+
query(uri, request, signal) {
|
|
278
|
+
const revision = this.#revision;
|
|
279
|
+
const files = this.files();
|
|
280
|
+
const id = virtualPath(uri);
|
|
281
|
+
const task = this.#queue.then(async () => {
|
|
282
|
+
/**
|
|
283
|
+
* Checks whether this query must discard its captured results.
|
|
284
|
+
*
|
|
285
|
+
* @returns Whether the service is closed, the signal is aborted, or the revision has changed.
|
|
286
|
+
*/
|
|
287
|
+
const obsolete = () => this.#closed || signal?.aborted || revision !== this.#revision;
|
|
288
|
+
if (obsolete()) return [];
|
|
289
|
+
await this.#prepareProjects(revision, files);
|
|
290
|
+
const results = [];
|
|
291
|
+
for (const [index, config] of this.#options.projects.entries()) {
|
|
292
|
+
if (!includes(config, id) && !isStylesheet(id)) continue;
|
|
293
|
+
if (!isStylesheet(id)) await this.#prepareProjects(revision, files, [index]);
|
|
294
|
+
const result = await this.#projects[index].query(id, request);
|
|
295
|
+
if (obsolete()) return [];
|
|
296
|
+
if (result) results.push({
|
|
297
|
+
project: index,
|
|
298
|
+
config: this.#options.config,
|
|
299
|
+
result
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return results;
|
|
303
|
+
});
|
|
304
|
+
this.#queue = task.catch(() => {});
|
|
305
|
+
return task;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Marks the service closed, invalidates captured revisions, and releases retained projects after queued work.
|
|
309
|
+
*
|
|
310
|
+
* @returns Completion of queued work and project cleanup.
|
|
311
|
+
* @throws If a retained project fails to close.
|
|
312
|
+
*/
|
|
313
|
+
async close() {
|
|
314
|
+
this.#closed = true;
|
|
315
|
+
this.#revision++;
|
|
316
|
+
await this.#queue;
|
|
317
|
+
await Promise.all(this.#projects.map((project) => project.close()));
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Checks whether a virtual identity names a stylesheet.
|
|
322
|
+
*
|
|
323
|
+
* @param id - Absolute virtual file path.
|
|
324
|
+
* @returns Whether the complete identity ends in `.css`, ignoring case.
|
|
325
|
+
*/
|
|
326
|
+
function isStylesheet(id) {
|
|
327
|
+
return /\.css$/i.test(id);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Checks a virtual path against a project's target globs and exclusions.
|
|
331
|
+
*
|
|
332
|
+
* @param config - Evaluated configuration with an absolute root.
|
|
333
|
+
* @param id - Absolute virtual file path.
|
|
334
|
+
* @returns Whether the path is under the root, outside node_modules, included, and not excluded.
|
|
335
|
+
*/
|
|
336
|
+
function includes(config, id) {
|
|
337
|
+
const name = relative(resolve(config.root), id);
|
|
338
|
+
return !name.startsWith("../") && !name.split("/").includes("node_modules") && config.files.some((pattern) => minimatch(name, pattern)) && !(config.exclude ?? []).some((pattern) => minimatch(name, pattern));
|
|
339
|
+
}
|
|
340
|
+
export { BrowserAnalysisWorkspace };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","names":[],"sources":["../src/browser.ts"],"sourcesContent":["import { captureProjectConfig, type AnalysisProjectConfig } from \"@stillwind/config\";\nimport {\n BrowserProject,\n virtualPath,\n type BrowserModuleCss,\n type BrowserStylesheetOutput,\n type EditorRequest,\n type PluginHost,\n} from \"@stillwind/host/browser\";\nimport { minimatch } from \"minimatch\";\nimport { relative, resolve } from \"pathe\";\n\nimport type {\n AnalysisWorkspaceService,\n WorkspaceEditorResult,\n WorkspaceResult,\n} from \"./workspace.ts\";\n\n/**\n * Browser workspace with original URIs and a complete virtual dependency inventory.\n */\nexport interface BrowserWorkspaceOptions {\n /** Configuration URI used to identify diagnostic groups. */\n config: string;\n /** Evaluated projects whose roots are absolute virtual paths. */\n projects: readonly AnalysisProjectConfig[];\n /** Saved source and dependency files, keyed by absolute virtual path. */\n files: ReadonlyMap<string, string>;\n /**\n * Maps virtual paths back to workspace URIs. Defaults to file URIs.\n *\n * @param path - Decoded absolute virtual path.\n * @returns Original URI used in diagnostics and source maps.\n */\n documentUri?(this: void, path: string): string;\n /**\n * Loads plugin packages and plugin files for `@plugin` statements. Omission limits the projects\n * to the plugins of their configurations.\n */\n plugins?: PluginHost;\n}\n\n/**\n * Shares snapshot compilation between LSP analysis and application builds.\n */\nexport class BrowserAnalysisWorkspace implements AnalysisWorkspaceService {\n /** Owned settings and saved inventory fixed when this service is created. */\n readonly #options: BrowserWorkspaceOptions;\n /** Open buffers keyed by decoded virtual path, applied over the saved inventory. */\n readonly #documents = new Map<\n string,\n {\n /** Complete original text of the open document. */\n source: string;\n /** Last accepted safe integer version for this open document. */\n version: number;\n }\n >();\n\n /** Change counter captured by analyses, editor queries, and application builds. */\n #revision = 0;\n /** Retained projects updated between compiler transactions and shared by queries and builds. */\n readonly #projects: BrowserProject[];\n /** Revision of the files installed in the projects. -1 means no installation yet. */\n #projectRevision = -1;\n /** Project indices whose targets have been prepared at projectRevision. */\n readonly #preparedProjects = new Set<number>();\n /** Prevents new analysis and invalidates queued editor queries during closure. */\n #closed = false;\n /** Serializes compiler operations and absorbs failures for subsequent operations. */\n #queue: Promise<unknown> = Promise.resolve();\n\n /**\n * Updates project files and prepares targets once per workspace revision.\n *\n * @param revision - Workspace revision captured with files before this operation was queued.\n * @param files - All saved files with the captured open buffers applied.\n * @param indices - Project indices whose script targets need preparation. Omission only updates files.\n * @returns Completion of file updates and target preparation. Repeated requests reuse that work.\n * @throws If a project's files cannot be replaced.\n */\n async #prepareProjects(\n revision: number,\n files: ReadonlyMap<string, string>,\n indices: readonly number[] = [],\n ): Promise<void> {\n if (this.#projectRevision !== revision) {\n await Promise.all(this.#projects.map((project) => project.replaceFiles(files)));\n this.#preparedProjects.clear();\n this.#projectRevision = revision;\n }\n for (const index of indices) {\n if (!this.#preparedProjects.has(index)) {\n await this.#projects[index].prepare(\n [...files.keys()].filter(\n (id) => includes(this.#options.projects[index], id) && !isStylesheet(id),\n ),\n );\n this.#preparedProjects.add(index);\n }\n }\n }\n\n /**\n * Creates the projects without loading CSS or compiling sources.\n *\n * @param options - Evaluated settings and saved files captured by this service.\n * Replace the service to apply new configuration or saved inventory. Open buffers use update.\n */\n constructor(options: BrowserWorkspaceOptions) {\n this.#options = {\n ...options,\n projects: options.projects.map(captureProjectConfig),\n files: new Map(options.files),\n };\n this.#projects = this.#options.projects.map(\n (config) =>\n new BrowserProject({\n root: config.root!,\n config,\n files: this.#options.files,\n documentUri: this.#options.documentUri,\n plugins: this.#options.plugins,\n }),\n );\n }\n\n /**\n * Reads the revision required when requesting an application build.\n *\n * @returns Change counter that increases after an effective buffer update or closure.\n */\n get revision(): number {\n return this.#revision;\n }\n\n /**\n * Stores an original buffer and increments the workspace revision when it changes.\n *\n * @param uri - Original document URI or virtual path, including dependency files outside target scopes.\n * @param source - Complete unsaved text.\n * @param version - Safe integer greater than the previous version. Identical text at the same version is accepted.\n * @throws If the service is closed or the version is invalid or does not increase.\n */\n update(uri: string, source: string, version: number): void {\n if (this.#closed) {\n throw new Error(\"Browser workspace is closed\");\n }\n\n const id = virtualPath(uri);\n\n const previous = this.#documents.get(id);\n if (previous?.version === version && previous.source === source) {\n return;\n }\n if (!Number.isSafeInteger(version) || (previous && version <= previous.version)) {\n throw new Error(\"Analysis document versions must increase\");\n }\n\n this.#documents.set(id, {\n source,\n version,\n });\n this.#revision++;\n }\n\n /**\n * Removes an open buffer and increments the revision only when that buffer existed.\n *\n * @param uri - Original URI or virtual path. Future snapshots use saved text for this path.\n */\n closeDocument(uri: string): void {\n if (this.#documents.delete(virtualPath(uri))) {\n this.#revision++;\n }\n }\n\n /**\n * Captures saved files with open buffers applied.\n *\n * @returns An independent map keyed by absolute virtual path. Later buffer changes do not alter it.\n */\n files(): ReadonlyMap<string, string> {\n return new Map([\n ...this.#options.files,\n ...[...this.#documents].map(([id, document]) => [id, document.source] as const),\n ]);\n }\n\n /**\n * Reads one file without copying the inventory.\n *\n * @param uri - Original URI identifying a saved file or open buffer.\n * @param revision - Revision captured when the application build started.\n * @returns Current buffer text, saved text, or undefined for an absent file.\n * @throws If the service is closed or the captured revision is obsolete.\n */\n readFile(uri: string, revision: number): string | undefined {\n if (this.#closed || revision !== this.#revision) {\n throw new Error(\"Browser build snapshot is obsolete\");\n }\n const id = virtualPath(uri);\n return this.#documents.get(id)?.source ?? this.#options.files.get(id);\n }\n\n /**\n * Analyzes the current buffers in each matching project, one queued request at a time.\n * Stylesheets match projects that lint them and return only stylesheet lint findings.\n *\n * @param uri - Original target URI or virtual path.\n * @param signal - Optional cancellation checked before and after compiler work.\n * @returns Results in project order. Compiler failures produce incomplete results, and obsolete\n * or cancelled results omit reports. Targets outside all scopes return an empty list.\n * @throws If the service is closed or its projects cannot be prepared.\n */\n analyze(uri: string, signal?: AbortSignal): Promise<WorkspaceResult[]> {\n const revision = this.#revision;\n const files = this.files();\n const id = virtualPath(uri);\n\n const task = this.#queue.then(async () => {\n if (this.#closed) {\n throw new Error(\"Browser workspace is closed\");\n }\n\n /**\n * Classifies work that can no longer publish results from the captured revision.\n *\n * @returns `cancelled` for an aborted signal, `stale` for a newer revision, or undefined.\n */\n const obsolete = () =>\n signal?.aborted\n ? (\"cancelled\" as const)\n : revision !== this.#revision\n ? (\"stale\" as const)\n : undefined;\n\n const results: WorkspaceResult[] = [];\n const stylesheet = isStylesheet(id);\n for (const [index, config] of this.#options.projects.entries()) {\n if (!includes(config, id) && !stylesheet) {\n continue;\n }\n\n await this.#prepareProjects(revision, files, stylesheet ? [] : [index]);\n const project = this.#projects[index];\n let result: WorkspaceResult[\"result\"] = {\n entry: uri,\n revision,\n status: \"incomplete\",\n reports: [],\n };\n try {\n if (stylesheet) {\n const lint = await project.stylesheetLint().catch(() => undefined);\n if (!lint?.sources.includes(id)) {\n continue;\n }\n result = {\n ...result,\n status: \"complete\",\n reports: lint.reports.filter(\n (report) => virtualPath(report.primary.location.uri) === id,\n ),\n };\n } else if (!obsolete()) {\n const graph = await project.analyze(id);\n const observations = structuredClone({\n reports: graph.batches\n .flatMap((batch) => batch.reports)\n .filter((report) => includes(config, virtualPath(report.primary.location.uri))),\n dependencies: graph.dependencies,\n unverified: graph.unverified,\n }) as Pick<WorkspaceResult[\"result\"], \"reports\" | \"dependencies\" | \"unverified\">;\n result = {\n ...result,\n ...observations,\n status:\n graph.unverified.length ||\n graph.dependencies.some(\n (dependency) =>\n dependency.status === \"unresolved\" || dependency.status === \"unsupported\",\n )\n ? \"incomplete\"\n : \"complete\",\n generation: graph.generation,\n };\n }\n } catch (error) {\n result.error = error instanceof Error ? error.message : String(error);\n }\n const status = obsolete();\n if (status) {\n result = {\n entry: uri,\n revision,\n status,\n reports: [],\n };\n }\n results.push({\n project: index,\n config: this.#options.config,\n result,\n });\n }\n return results;\n });\n\n this.#queue = task.catch(() => {});\n\n return task;\n }\n\n /**\n * Prepares script targets in the projects that include the requested documents.\n *\n * @param uris - Target URIs or absolute virtual paths. Stylesheets do not select a project here.\n * @param signal - Optional cancellation checked before queued work starts.\n * @returns Completion of preparation. Closed, cancelled, and outdated requests do no work.\n * Source failures are left for analyze to report.\n * @throws If project files cannot be replaced.\n */\n prepare(uris: readonly string[], signal?: AbortSignal): Promise<void> {\n const revision = this.#revision;\n const files = this.files();\n const task = this.#queue.then(async () => {\n if (!this.#closed && !signal?.aborted && revision === this.#revision) {\n const ids = uris.map(virtualPath).filter((id) => !isStylesheet(id));\n const indices = this.#options.projects.flatMap((config, index) =>\n ids.some((id) => includes(config, id)) ? [index] : [],\n );\n await this.#prepareProjects(revision, files, indices);\n }\n });\n this.#queue = task.catch(() => {});\n return task;\n }\n\n /**\n * Checks whether save or watch notifications need a new workspace.\n *\n * @param uris - Document URIs or absolute virtual paths reported by the notification.\n * @returns True when every file has an open buffer and none is the workspace configuration,\n * a tsconfig, or package.json. This method does not change files or reopen projects.\n */\n async refresh(uris: readonly string[]): Promise<boolean> {\n return uris.every(\n (uri) =>\n uri !== this.#options.config &&\n this.#documents.has(virtualPath(uri)) &&\n !/(?:^|\\/)(?:tsconfig(?:\\.[^/]+)?\\.json|package\\.json)$/.test(virtualPath(uri)),\n );\n }\n\n /**\n * Transforms a module for a browser application build.\n *\n * @param uri - Source URI in exactly one configured project.\n * @param revision - Workspace revision captured when the application build started.\n * @returns Transformed source, CSS, and reports.\n * Blocked graphs retain diagnostics and return empty CSS and CSS values.\n * @throws If project selection fails or the build revision became obsolete.\n */\n compile(\n uri: string,\n revision: number,\n ): Promise<{\n /** Transformed source graph, including diagnostic reports and generation eligibility. */\n graph: Awaited<ReturnType<BrowserProject[\"analyze\"]>>;\n /** Current combined CSS, empty when the graph blocks generation. */\n css: string;\n /** Naming fallbacks observed during document assembly. */\n rejectedNames: BrowserStylesheetOutput[\"rejectedNames\"];\n /** Module identity and its CSS record, empty when generation is blocked. */\n cssValues: [string, BrowserModuleCss][];\n }> {\n const files = this.files();\n const id = virtualPath(uri);\n\n const task = this.#queue.then(async () => {\n if (this.#closed || revision !== this.#revision) {\n throw new Error(\"Browser build snapshot is obsolete\");\n }\n\n const matches = this.#options.projects\n .map((config, index) => ({ config, index }))\n .filter(({ config }) => includes(config, id));\n if (matches.length !== 1) {\n throw new Error(`Expected one Stillwind project for ${uri}`);\n }\n\n await this.#prepareProjects(revision, files, [matches[0].index]);\n\n const project = this.#projects[matches[0].index];\n const graph = await project.analyze(id);\n if (revision !== this.#revision) {\n throw new Error(\"Browser build snapshot is obsolete\");\n }\n\n const stylesheet =\n graph.generation === \"complete\"\n ? project.css()\n : {\n css: \"\",\n rejectedNames: [],\n };\n return {\n graph,\n ...stylesheet,\n cssValues: graph.generation === \"complete\" ? [...project.cssValues()] : [],\n };\n });\n\n this.#queue = task.catch(() => {});\n\n return task;\n }\n\n /**\n * Queries retained projects against a captured inventory and discards obsolete answers.\n *\n * @param uri - Original target URI or virtual path.\n * @param request - Operation with offsets in the original UTF-16 document.\n * @param signal - Optional cancellation checked around project preparation and queries.\n * @returns Answers in project order, or an empty list after closure, cancellation, or a revision change.\n * @throws If project preparation or an editor query fails.\n */\n query(\n uri: string,\n request: EditorRequest,\n signal?: AbortSignal,\n ): Promise<WorkspaceEditorResult[]> {\n const revision = this.#revision;\n const files = this.files();\n const id = virtualPath(uri);\n const task = this.#queue.then(async () => {\n /**\n * Checks whether this query must discard its captured results.\n *\n * @returns Whether the service is closed, the signal is aborted, or the revision has changed.\n */\n const obsolete = () => this.#closed || signal?.aborted || revision !== this.#revision;\n if (obsolete()) {\n return [];\n }\n await this.#prepareProjects(revision, files);\n const results: WorkspaceEditorResult[] = [];\n for (const [index, config] of this.#options.projects.entries()) {\n if (!includes(config, id) && !isStylesheet(id)) {\n continue;\n }\n if (!isStylesheet(id)) {\n await this.#prepareProjects(revision, files, [index]);\n }\n const result = await this.#projects[index].query(id, request);\n if (obsolete()) {\n return [];\n }\n if (result) {\n results.push({ project: index, config: this.#options.config, result });\n }\n }\n return results;\n });\n this.#queue = task.catch(() => {});\n return task;\n }\n\n /**\n * Marks the service closed, invalidates captured revisions, and releases retained projects after queued work.\n *\n * @returns Completion of queued work and project cleanup.\n * @throws If a retained project fails to close.\n */\n async close(): Promise<void> {\n this.#closed = true;\n this.#revision++;\n await this.#queue;\n await Promise.all(this.#projects.map((project) => project.close()));\n }\n}\n\n/**\n * Checks whether a virtual identity names a stylesheet.\n *\n * @param id - Absolute virtual file path.\n * @returns Whether the complete identity ends in `.css`, ignoring case.\n */\nfunction isStylesheet(id: string): boolean {\n return /\\.css$/i.test(id);\n}\n\n/**\n * Checks a virtual path against a project's target globs and exclusions.\n *\n * @param config - Evaluated configuration with an absolute root.\n * @param id - Absolute virtual file path.\n * @returns Whether the path is under the root, outside node_modules, included, and not excluded.\n */\nfunction includes(config: AnalysisProjectConfig, id: string): boolean {\n const name = relative(resolve(config.root!), id);\n\n return (\n !name.startsWith(\"../\") &&\n !name.split(\"/\").includes(\"node_modules\") &&\n config.files.some((pattern) => minimatch(name, pattern)) &&\n !(config.exclude ?? []).some((pattern) => minimatch(name, pattern))\n );\n}\n"],"mappings":";;;;;;;;AA6CA,IAAa,2BAAb,MAA0E;;CAExE;;CAEA,6BAAsB,IAAI,IAQxB;;CAGF,YAAY;;CAEZ;;CAEA,mBAAmB;;CAEnB,oCAA6B,IAAI,IAAY;;CAE7C,UAAU;;CAEV,SAA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AqB;CACpE,MAAM,OAAO,SAAS,QAAQ,OAAO,IAAK,GAAG,EAAE;CAE/C,OACE,CAAC,KAAK,WAAW,KAAK,KACtB,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,KACxC,OAAO,MAAM,MAAM,YAAY,UAAU,MAAM,OAAO,CAAC,KACvD,EAAE,OAAO,WAAW,CAAC,EAAA,CAAG,MAAM,YAAY,UAAU,MAAM,OAAO,CAAC;AAEtE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { a as OpenAnalysisWorkspaces, c as WorkspaceResult, i as AnalysisWorkspaceService, n as AnalysisResult, o as OpenWorkspaces, r as AnalysisWorkspaceContext, s as WorkspaceEditorResult, t as AnalysisDependency } from "./workspace-BF46yPpm.js";
|
|
2
|
+
import { t as lintReports } from "./reports-BKeFV47o.js";
|
|
3
|
+
import { EditorRequest, EditorResult } from "@stillwind/host";
|
|
4
|
+
export { type AnalysisDependency, type AnalysisResult, type AnalysisWorkspaceContext, type AnalysisWorkspaceService, type EditorRequest, type EditorResult, type OpenAnalysisWorkspaces, type OpenWorkspaces, type WorkspaceEditorResult, type WorkspaceResult, lintReports };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as lintReports } from "./reports-nlgN4YL4.js";
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { i as AnalysisWorkspaceService, n as AnalysisResult } from "./workspace-BF46yPpm.js";
|
|
2
|
+
/** Compiler input captured from URI documents before asynchronous compilation starts. */
|
|
3
|
+
export interface MemoryAnalysisInput {
|
|
4
|
+
/** Requested target URI accepted by the embedding's includes callback. */
|
|
5
|
+
uri: string;
|
|
6
|
+
/** Workspace change counter captured when the request was queued. */
|
|
7
|
+
revision: number;
|
|
8
|
+
/** Original text of all open documents, keyed by URI. The snapshot is independent of later updates. */
|
|
9
|
+
documents: ReadonlyMap<string, string>;
|
|
10
|
+
/** Optional cancellation signal. The workspace also checks it before and after calling compile. */
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
/** Supplies the browser's WASM compiler, module loader, and type-facts service. */
|
|
14
|
+
export interface MemoryAnalysisOptions {
|
|
15
|
+
/** Identifies the project in diagnostics. It need not be a filesystem path. */
|
|
16
|
+
config: string;
|
|
17
|
+
/**
|
|
18
|
+
* Tests whether this workspace owns a target. Dependency buffers can be outside this scope.
|
|
19
|
+
*
|
|
20
|
+
* @param uri - Requested target URI.
|
|
21
|
+
* @returns Whether compile should run for this target.
|
|
22
|
+
*/
|
|
23
|
+
includes(uri: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Runs the embedding's compiler against one captured snapshot.
|
|
26
|
+
*
|
|
27
|
+
* @param input - Target, revision, open buffers, and optional cancellation signal.
|
|
28
|
+
* @returns Reports and coverage information for the captured revision. Complete describes analysis
|
|
29
|
+
* coverage. It does not imply that every report is successful.
|
|
30
|
+
* @throws If compiler or module services fail. The workspace returns the error as an incomplete result.
|
|
31
|
+
*/
|
|
32
|
+
compile(input: MemoryAnalysisInput): Promise<Pick<AnalysisResult, "reports" | "dependencies" | "unverified" | "generation" | "error"> & {
|
|
33
|
+
/** Coverage of the captured snapshot. Compiler error reports can still have complete coverage. */
|
|
34
|
+
status: "complete" | "incomplete";
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Releases resources after queued compilations finish. Called once during workspace closure.
|
|
38
|
+
*
|
|
39
|
+
* @returns Nothing, or a promise for asynchronous cleanup.
|
|
40
|
+
* @throws If resource cleanup fails. The workspace's close promise rejects.
|
|
41
|
+
*/
|
|
42
|
+
close?(): void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serializes in-memory analyses and discards reports from obsolete document revisions.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Project membership, compiler operation, and optional resource cleanup.
|
|
48
|
+
* @returns A URI-based service. It supplies snapshots to compile but performs no module resolution
|
|
49
|
+
* itself. Closing waits for queued work and calls the cleanup operation once.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createMemoryAnalysisWorkspace(options: MemoryAnalysisOptions): AnalysisWorkspaceService;
|
|
52
|
+
//# sourceMappingURL=memory.d.ts.map
|