@stillwind/host 0.3.0 → 0.4.1

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/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as PluginPathCompletion, D as EditorRequest, E as EditorEdit, O as EditorResult, S as defaultPluginExport, T as EditorCompletion, _ as TypeFactsBackend, b as PluginHost, g as TypeFactSource, h as SemanticInputs, p as AvailableFacts, r as ModuleAnalysis, t as EditorSnapshot, v as TypeFactsError, w as EditorColor, y as UnverifiedRange } from "./index-CprPvXxv.js";
1
+ import { A as PluginPathCompletion, C as TypeFactSource, D as PluginHost, E as UnverifiedRange, F as EditorResult, M as EditorCompletion, N as EditorEdit, P as EditorRequest, S as SemanticInputs, T as TypeFactsError, a as DesignSystemResult, b as AvailableFacts, c as queryDesignSystem, i as DesignSystemRequest, j as EditorColor, k as defaultPluginExport, n as DesignCandidate, o as DesignToken, r as DesignSystemContext, s as DesignTokenSource, t as EditorSnapshot, u as ModuleAnalysis, w as TypeFactsBackend } from "./index-DAGqsQ8n.js";
2
2
  import { t as resolveVirtualModule } from "./resolution-BI5eZllL.js";
3
3
  import { BindingRejectedIdentifier, BindingReport, NativeAssetRecord, NativeTypeFact } from "@stillwind/native";
4
4
  import ts from "typescript-6";
@@ -216,5 +216,5 @@ export declare class BrowserProject {
216
216
  * @throws If the URI or its percent encoding is invalid.
217
217
  */
218
218
  export declare function virtualPath(uri: string): string;
219
- export { type AvailableFacts, type BrowserCheckerOptions, type BrowserModuleAnalysis, type BrowserModuleCss, type BrowserProjectOptions, type BrowserStylesheetOutput, type EditorColor, type EditorCompletion, type EditorEdit, type EditorRequest, type EditorResult, EditorSnapshot, type PluginHost, type PluginPathCompletion, type TypeFactSource, type TypeFactsBackend, TypeFactsError, type UnverifiedRange, defaultPluginExport, resolveVirtualModule };
219
+ export { type AvailableFacts, type BrowserCheckerOptions, type BrowserModuleAnalysis, type BrowserModuleCss, type BrowserProjectOptions, type BrowserStylesheetOutput, type DesignCandidate, type DesignSystemContext, type DesignSystemRequest, type DesignSystemResult, type DesignToken, type DesignTokenSource, type EditorColor, type EditorCompletion, type EditorEdit, type EditorRequest, type EditorResult, EditorSnapshot, type PluginHost, type PluginPathCompletion, type TypeFactSource, type TypeFactsBackend, TypeFactsError, type UnverifiedRange, defaultPluginExport, queryDesignSystem, resolveVirtualModule };
220
220
  //# sourceMappingURL=browser.d.ts.map
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as prepareSourcePlugins, D as attachPlugins, E as TypeFactsError, T as fileSourceKind, _ as defaultPluginExport, a as pluginDirectory, b as analyzeModule, c as EditorSnapshot, d as withRequestedProbes, f as isStylesheet, h as loadEditorCssGraph, i as completePluginPaths, l as CheckerSource, m as loadCssGraph, n as cssEntrypoint, o as queryPluginPaths, r as StylesheetEditor, s as CompilationProject, t as compilerOptions, u as checkerId, y as finalizeCss } from "./options-BrXyddsL.js";
1
+ import { D as fileSourceKind, M as prepareSourcePlugins, O as TypeFactsError, S as analyzeModule, _ as loadEditorCssGraph, a as pluginDirectory, c as CheckerSource, d as CompilationProject, g as loadCssGraph, i as completePluginPaths, k as attachPlugins, l as checkerId, m as isStylesheet, n as cssEntrypoint, o as queryPluginPaths, p as queryDesignSystem, r as StylesheetEditor, s as EditorSnapshot, t as compilerOptions, u as withRequestedProbes, x as finalizeCss, y as defaultPluginExport } from "./options-BOutD9j7.js";
2
2
  import { t as resolveVirtualModule } from "./resolution-C3cvLPzx.js";
3
3
  import { NativeProjectSession, fingerprint } from "@stillwind/native";
4
4
  import ts from "typescript-6";
@@ -1061,6 +1061,6 @@ var BrowserProject = class {
1061
1061
  function virtualPath(uri) {
1062
1062
  return decodeURIComponent(new URL(uri).pathname);
1063
1063
  }
1064
- export { BrowserProject, BrowserTypeFactsService, EditorSnapshot, TypeFactsError, defaultPluginExport, resolveVirtualModule, virtualPath };
1064
+ export { BrowserProject, BrowserTypeFactsService, EditorSnapshot, TypeFactsError, defaultPluginExport, queryDesignSystem, resolveVirtualModule, virtualPath };
1065
1065
 
1066
1066
  //# sourceMappingURL=browser.js.map
@@ -76,6 +76,9 @@ type EditorRequest = {
76
76
  kind: "hover";
77
77
  /** Original UTF-16 cursor offset at the input to describe. */
78
78
  offset: number;
79
+ } | {
80
+ /** Requests CSS for every style call, declaration, and use in the source. */
81
+ kind: "previews";
79
82
  } | {
80
83
  /** Requests matching candidates and variant prefixes for an insertion point. */
81
84
  kind: "completion";
@@ -163,6 +166,21 @@ interface EditorResult {
163
166
  */
164
167
  runtimeNames?: string[];
165
168
  };
169
+ /** Formatted CSS at half-open original UTF-16 ranges, in ascending start order. Literal inputs
170
+ * and occurrences inside another listed occurrence are omitted.
171
+ */
172
+ previews?: {
173
+ /** Inclusive original UTF-16 boundary. */
174
+ start: number;
175
+ /** Exclusive original UTF-16 boundary. */
176
+ end: number;
177
+ /** Generated CSS with the required styles and global definitions. It can be empty. */
178
+ css: string;
179
+ /** False when the occurrence or a style that it requires failed to generate CSS. */
180
+ valid: boolean;
181
+ /** Authored runtime key expressions. Absent when the preview has none to explain. */
182
+ runtimeNames?: string[];
183
+ }[];
166
184
  /** Prefix-matching candidates with their full replacement ranges. CSS loads on resolve. */
167
185
  completions?: EditorCompletion[];
168
186
  /** Concrete colors resolved against the active design system. */
@@ -784,6 +802,90 @@ declare class PluginRuntime {
784
802
  */
785
803
  replay(session?: NativeProjectSession, intermediate?: boolean): NativeDesignSystemLoader;
786
804
  }
805
+ /**
806
+ * A question about one project's design system, independent of any source file.
807
+ */
808
+ type DesignSystemRequest = {
809
+ /** Requests theme tokens. */
810
+ kind: "theme";
811
+ /** Token names without or with the leading `--`, where `*` matches any text. */
812
+ targets: readonly string[];
813
+ /** Keeps tokens with this origin. Omission keeps every token. */
814
+ source?: DesignTokenSource;
815
+ } | {
816
+ /** Requests utilities, or variants, by exact candidate or pattern. */
817
+ kind: "utilities" | "variants";
818
+ /** Decoded candidates. A `*` outside brackets and parentheses makes a pattern. */
819
+ targets: readonly string[];
820
+ };
821
+ /**
822
+ * Origin of a token: the project's `@theme`, or a default that `@theme` can override.
823
+ */
824
+ type DesignTokenSource = "project" | "default";
825
+ /**
826
+ * An active theme token.
827
+ */
828
+ interface DesignToken {
829
+ /** Complete custom property name, including the leading `--`. */
830
+ name: string;
831
+ /** CSS value as written, including references to other tokens. */
832
+ value: string;
833
+ /** Origin of the active definition. */
834
+ source: DesignTokenSource;
835
+ /** Whether utilities write the value of the token instead of a reference to it. */
836
+ inline: boolean;
837
+ }
838
+ /**
839
+ * One utility, variant, or marker class, with its CSS.
840
+ */
841
+ interface DesignCandidate {
842
+ /** Decoded candidate. Variant names have no trailing colon. */
843
+ name: string;
844
+ /** Kind of input that the name selects. */
845
+ kind: "utility" | "variant" | "marker";
846
+ /** Whether the name resolves in this design system. */
847
+ valid: boolean;
848
+ /** Formatted CSS. It is empty for an invalid name and for a marker without CSS. */
849
+ css: string;
850
+ /** Closest valid spelling of an invalid name. Absent when no spelling is close enough. */
851
+ suggestion?: string;
852
+ /**
853
+ * Canonical spelling of a valid exact candidate. Absent for a canonical name, for a name without
854
+ * a replacement that produces the same CSS, and for a pattern match.
855
+ */
856
+ canonical?: string;
857
+ }
858
+ /**
859
+ * The answer to one design-system request.
860
+ */
861
+ interface DesignSystemResult {
862
+ /** Matching tokens in name order. */
863
+ tokens: DesignToken[];
864
+ /** Exact candidates in target order, then pattern matches in name order. */
865
+ candidates: DesignCandidate[];
866
+ /** Targets without a match. Exact candidates stay in candidates as invalid entries. */
867
+ unmatched: string[];
868
+ }
869
+ /**
870
+ * Everything a request reads from one loaded design system.
871
+ */
872
+ interface DesignSystemContext {
873
+ /** Query over the loaded design system. */
874
+ query: NativeEditorQuery;
875
+ /** Plugins that add dynamic candidates. */
876
+ plugins?: PluginRuntime;
877
+ /** Preview comment settings. */
878
+ annotations: Parameters<NativeEditorQuery["formatCss"]>[1];
879
+ }
880
+ /**
881
+ * Answers a question about a loaded design system.
882
+ *
883
+ * @param context - Loaded design system.
884
+ * @param request - Theme, utility, or variant request.
885
+ * @returns The answer. Invalid names and unmatched targets are data.
886
+ * @throws If a plugin fails or a matching utility definition is malformed.
887
+ */
888
+ declare function queryDesignSystem(context: DesignSystemContext, request: DesignSystemRequest): Promise<DesignSystemResult>;
787
889
  /**
788
890
  * Runs source editor requests and sorting diagnostics against captured compiler output.
789
891
  */
@@ -840,5 +942,5 @@ declare class EditorSnapshot {
840
942
  */
841
943
  query(id: string, request: EditorRequest): EditorResult | undefined;
842
944
  }
843
- export { PluginPathCompletion as C, EditorRequest as D, EditorEdit as E, EditorResult as O, defaultPluginExport as S, EditorCompletion as T, TypeFactsBackend as _, SemanticDependency as a, PluginHost as b, TypeScriptFactsStats as c, TypeScriptProject as d, resolveTypeFactsEnvironment as f, TypeFactSource as g, SemanticInputs as h, ModuleCompileOptions as i, TypeFactsEnvironment as l, CheckerSpan as m, PluginRuntime as n, TypeFact as o, AvailableFacts as p, ModuleAnalysis as r, TypeScriptFactsService as s, EditorSnapshot as t, TypeFactsInputs as u, TypeFactsError as v, EditorColor as w, TailwindSettings as x, UnverifiedRange as y };
844
- //# sourceMappingURL=index-CprPvXxv.d.ts.map
945
+ export { PluginPathCompletion as A, TypeFactSource as C, PluginHost as D, UnverifiedRange as E, EditorResult as F, EditorCompletion as M, EditorEdit as N, TailwindSettings as O, EditorRequest as P, SemanticInputs as S, TypeFactsError as T, TypeFactsInputs as _, DesignSystemResult as a, AvailableFacts as b, queryDesignSystem as c, ModuleCompileOptions as d, SemanticDependency as f, TypeFactsEnvironment as g, TypeScriptFactsStats as h, DesignSystemRequest as i, EditorColor as j, defaultPluginExport as k, PluginRuntime as l, TypeScriptFactsService as m, DesignCandidate as n, DesignToken as o, TypeFact as p, DesignSystemContext as r, DesignTokenSource as s, EditorSnapshot as t, ModuleAnalysis as u, TypeScriptProject as v, TypeFactsBackend as w, CheckerSpan as x, resolveTypeFactsEnvironment as y };
946
+ //# sourceMappingURL=index-DAGqsQ8n.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as PluginPathCompletion, D as EditorRequest, E as EditorEdit, O as EditorResult, S as defaultPluginExport, T as EditorCompletion, _ as TypeFactsBackend, a as SemanticDependency, b as PluginHost, c as TypeScriptFactsStats, d as TypeScriptProject, f as resolveTypeFactsEnvironment, g as TypeFactSource, h as SemanticInputs, i as ModuleCompileOptions, l as TypeFactsEnvironment, m as CheckerSpan, n as PluginRuntime, o as TypeFact, p as AvailableFacts, r as ModuleAnalysis, s as TypeScriptFactsService, t as EditorSnapshot, u as TypeFactsInputs, v as TypeFactsError, w as EditorColor, x as TailwindSettings, y as UnverifiedRange } from "./index-CprPvXxv.js";
1
+ import { A as PluginPathCompletion, C as TypeFactSource, D as PluginHost, E as UnverifiedRange, F as EditorResult, M as EditorCompletion, N as EditorEdit, O as TailwindSettings, P as EditorRequest, S as SemanticInputs, T as TypeFactsError, _ as TypeFactsInputs, a as DesignSystemResult, b as AvailableFacts, c as queryDesignSystem, d as ModuleCompileOptions, f as SemanticDependency, g as TypeFactsEnvironment, h as TypeScriptFactsStats, i as DesignSystemRequest, j as EditorColor, k as defaultPluginExport, l as PluginRuntime, m as TypeScriptFactsService, n as DesignCandidate, o as DesignToken, p as TypeFact, r as DesignSystemContext, s as DesignTokenSource, t as EditorSnapshot, u as ModuleAnalysis, v as TypeScriptProject, w as TypeFactsBackend, x as CheckerSpan, y as resolveTypeFactsEnvironment } from "./index-DAGqsQ8n.js";
2
2
  import { BindingDiagnostic, BindingOutput, BindingRejectedIdentifier, BindingReport, NativeAssetRecord, NativeCompilerOptions, NativeCssResource, NativeDesignSystemLoader, NativeDiagnosticBatch, NativeEditorQuery, NativeModuleSummary, NativeProjectSession, NativeSkippedCss, NativeTypeFact } from "@stillwind/native";
3
3
  import { PreparedSource as PreparedSource$1, ProjectInput, ScriptSyntax, SourceDocument } from "@stillwind/projection";
4
4
  import { EncodedSourceMap } from "@jridgewell/gen-mapping";
@@ -124,6 +124,8 @@ declare class CompilationProject {
124
124
  * @returns The shared source, or undefined when it has not been prepared. Do not mutate it.
125
125
  */
126
126
  source(id: string): PreparedSource$1 | undefined;
127
+ /** Returns the normalized identities of the prepared sources, as {@link sourceKey} defines them. */
128
+ sourceKeys(): string[];
127
129
  /** Returns the prepared documents' original text so plugins can find candidates together. */
128
130
  texts(): string[];
129
131
  /**
@@ -836,6 +838,14 @@ export declare class AnalysisProject {
836
838
  * provider. Unknown paths have no effect.
837
839
  */
838
840
  closeDocument(id: string): void;
841
+ /**
842
+ * Lists the files that analysis has observed, for comparison with paths in watch notifications.
843
+ *
844
+ * @returns Keys from `sourceKey` for prepared sources, files that CSS or plugins read, and paths
845
+ * that the checker read or tested, including missing paths. A custom semantic backend contributes
846
+ * nothing.
847
+ */
848
+ reads(): Set<string>;
839
849
  /** Makes pending results stale. The next transaction rebuilds CSS and backend caches. */
840
850
  invalidate(): void;
841
851
  /**
@@ -890,6 +900,14 @@ export declare class AnalysisProject {
890
900
  * @throws If preparing a CSS query fails or the editor query rejects a candidate or preview.
891
901
  */
892
902
  query(entry: string, request: EditorRequest, signal?: AbortSignal): Promise<EditorResult | undefined>;
903
+ /**
904
+ * Answers a question about the design system, using the current buffers.
905
+ *
906
+ * @param request - Theme, utility, or variant request.
907
+ * @returns The answer, or undefined when the captured buffers become outdated.
908
+ * @throws If the project is closed, CSS loading fails, or a plugin fails.
909
+ */
910
+ designSystem(request: DesignSystemRequest): Promise<DesignSystemResult | undefined>;
893
911
  /**
894
912
  * Marks the project closed, discards pending results, and waits for queued work before cleanup.
895
913
  * Repeated calls return without requesting further cleanup.
@@ -1118,7 +1136,8 @@ export declare class AnalysisWorkspace {
1118
1136
  *
1119
1137
  * @param project - Project whose root, include globs, and exclusions define membership.
1120
1138
  * @param file - Absolute file path to test.
1121
- * @returns Whether the path matches files without matching excludes, node_modules, or .git.
1139
+ * @returns Whether the path matches files without matching excludes, node_modules, or .git. A
1140
+ * declaration file that the host cannot analyze is outside the scope.
1122
1141
  * Dependency traversal does not use this filter.
1123
1142
  */
1124
1143
  includes(project: WorkspaceProject, file: string): boolean;
@@ -1149,6 +1168,19 @@ export declare class AnalysisWorkspace {
1149
1168
  /** Adds the stylesheets that the project lints, as {@link lintsStylesheet} selects them. */
1150
1169
  stylesheets?: boolean;
1151
1170
  }): Promise<string[]>;
1171
+ /**
1172
+ * Answers a question about the design system of each project.
1173
+ *
1174
+ * @param request - Theme, utility, or variant request.
1175
+ * @returns Answers in configuration order.
1176
+ * @throws If CSS loading or a plugin fails in any project.
1177
+ */
1178
+ designSystem(request: DesignSystemRequest): Promise<{
1179
+ /** Zero-based index into the configured projects. */
1180
+ project: number;
1181
+ /** Answer from that project's design system. */
1182
+ result: DesignSystemResult;
1183
+ }[]>;
1152
1184
  /**
1153
1185
  * Keeps editor answers separate when several projects include the same target.
1154
1186
  *
@@ -1184,11 +1216,21 @@ export declare class AnalysisWorkspace {
1184
1216
  */
1185
1217
  closeDocument(file: string): void;
1186
1218
  /**
1187
- * Checks whether save or watch notifications need a new workspace.
1219
+ * Checks whether file changes can change this workspace's results, without changing any state.
1220
+ * Analysis cannot depend on a file that it never read and that lies outside every target scope.
1221
+ *
1222
+ * @param files - File paths reported by a watch notification. Relative paths use the working
1223
+ * directory.
1224
+ * @returns Whether `refresh` would request reopening or invalidate a project for these files.
1225
+ */
1226
+ affects(files: readonly string[]): boolean;
1227
+ /**
1228
+ * Checks whether save or watch notifications need a new workspace, and invalidates each project
1229
+ * that a change to a closed file can affect.
1188
1230
  *
1189
1231
  * @param files - File paths reported by the notification. Relative paths use the working directory.
1190
- * @returns True when every file has an open buffer and none is a configuration dependency,
1191
- * a tsconfig, or package.json. This method does not read disk or reopen projects.
1232
+ * @returns False when the workspace must reopen, which leaves projects unchanged. Otherwise
1233
+ * returns true. This method does not read disk or reopen projects.
1192
1234
  */
1193
1235
  refresh(files: readonly string[]): boolean;
1194
1236
  /**
@@ -1239,5 +1281,5 @@ export declare class AnalysisWorkspace {
1239
1281
  */
1240
1282
  close(): Promise<void>;
1241
1283
  }
1242
- export { type AnalysisHost, type AnalysisResult, type AvailableFacts, type CheckerSpan, type CompilerHost, type CompilerMapping, type CssHost, type CssLocations, type CssPluginInputs, type CssSourceMapInput, type CssUpstreamMap, type DecodedCssSourceMap, type EditorAnalysis, type EditorColor, type EditorCompletion, type EditorCssGraph, type EditorDocument, type EditorEdit, type EditorRequest, type EditorResult, EditorSnapshot, type FinalizedModuleEdit, type LoadedCssGraph, type ModuleAnalysis, type ModuleCompileOptions, type ModuleDescriptor, type PluginHost, type PluginPathCompletion, PluginRuntime, type PreparedSource, type SemanticDependency, type SemanticInputs, type TailwindSettings, type TypeFact, type TypeFactSource, type TypeFactsBackend, type TypeFactsEnvironment, TypeFactsError, type TypeFactsInputs, TypeScriptFactsService, type TypeScriptFactsStats, type TypeScriptProject, type UnverifiedRange, type UpstreamSourceMap, type WorkspaceProject, type WorkspaceResult, defaultPluginExport, resolveTypeFactsEnvironment };
1284
+ export { type AnalysisHost, type AnalysisResult, type AvailableFacts, type CheckerSpan, type CompilerHost, type CompilerMapping, type CssHost, type CssLocations, type CssPluginInputs, type CssSourceMapInput, type CssUpstreamMap, type DecodedCssSourceMap, type DesignCandidate, type DesignSystemContext, type DesignSystemRequest, type DesignSystemResult, type DesignToken, type DesignTokenSource, type EditorAnalysis, type EditorColor, type EditorCompletion, type EditorCssGraph, type EditorDocument, type EditorEdit, type EditorRequest, type EditorResult, EditorSnapshot, type FinalizedModuleEdit, type LoadedCssGraph, type ModuleAnalysis, type ModuleCompileOptions, type ModuleDescriptor, type PluginHost, type PluginPathCompletion, PluginRuntime, type PreparedSource, type SemanticDependency, type SemanticInputs, type TailwindSettings, type TypeFact, type TypeFactSource, type TypeFactsBackend, type TypeFactsEnvironment, TypeFactsError, type TypeFactsInputs, TypeScriptFactsService, type TypeScriptFactsStats, type TypeScriptProject, type UnverifiedRange, type UpstreamSourceMap, type WorkspaceProject, type WorkspaceResult, defaultPluginExport, queryDesignSystem, resolveTypeFactsEnvironment };
1243
1285
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { A as prepareSourcePlugins, C as CompilationFailure, D as attachPlugins, E as TypeFactsError, O as compileWithPlugins, S as warnRejectedNames, T as fileSourceKind, _ as defaultPluginExport, a as pluginDirectory, b as analyzeModule, c as EditorSnapshot, d as withRequestedProbes, f as isStylesheet, g as PluginRuntime, h as loadEditorCssGraph, i as completePluginPaths, k as pluginLoader, l as CheckerSource, m as loadCssGraph, n as cssEntrypoint, o as queryPluginPaths, p as lintsStylesheet, r as StylesheetEditor, s as CompilationProject, t as compilerOptions, u as checkerId, v as cssBannerPrefix, w as cleanModuleId, x as compileModule, y as finalizeCss } from "./options-BrXyddsL.js";
2
- import { createRequire } from "node:module";
1
+ import { A as compileWithPlugins, C as compileModule, D as fileSourceKind, E as cleanModuleId, M as prepareSourcePlugins, O as TypeFactsError, S as analyzeModule, T as CompilationFailure, _ as loadEditorCssGraph, a as pluginDirectory, b as cssBannerPrefix, c as CheckerSource, d as CompilationProject, f as sourceKey, g as loadCssGraph, h as lintsStylesheet, i as completePluginPaths, j as pluginLoader, k as attachPlugins, l as checkerId, m as isStylesheet, n as cssEntrypoint, o as queryPluginPaths, p as queryDesignSystem, r as StylesheetEditor, s as EditorSnapshot, t as compilerOptions, u as withRequestedProbes, v as PluginRuntime, w as warnRejectedNames, x as finalizeCss, y as defaultPluginExport } from "./options-BOutD9j7.js";
2
+ import { createRequire, syncBuiltinESMExports } from "node:module";
3
3
  import { NativeProjectSession, fingerprint } from "@stillwind/native";
4
4
  import path, { isAbsolute, relative, resolve } from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -11,6 +11,7 @@ import { existsSync } from "node:fs";
11
11
  import process from "node:process";
12
12
  import { isCallExpression, isExportDeclaration, isExpression, isImportDeclaration, isSourceFile, isStringLiteral } from "typescript-7/unstable/ast/is";
13
13
  import { API, SignatureKind, TypeFlags } from "typescript-7/unstable/sync";
14
+ import childProcess from "node:child_process";
14
15
  import { captureProjectConfig } from "@stillwind/config";
15
16
  import { readFile, readdir, stat } from "node:fs/promises";
16
17
  import { evaluateModule, loadConfiguration, resolveProjectConfig } from "@stillwind/config/node";
@@ -502,6 +503,33 @@ function factsForSource(sourceFile, mapping, decoder, nodes, typesAt, unverified
502
503
  }
503
504
  return facts;
504
505
  }
506
+ // src/semantics/node/hidden-spawn.ts
507
+ /**
508
+ * Runs a function while `child_process.spawn` hides the console windows of new processes.
509
+ *
510
+ * The TypeScript API starts its checker with `spawn` and has no option for `windowsHide`. Under
511
+ * Electron, `Code.exe` is a Windows GUI program that has no console, so Windows opens a visible
512
+ * console for `tsc.exe` unless the spawn call hides it.
513
+ *
514
+ * @param action - Synchronous function that starts processes. Asynchronous work after it returns
515
+ * uses the original `spawn`.
516
+ * @returns The function's return value. `spawn` is restored before the return or the throw.
517
+ * @throws If the function throws.
518
+ */
519
+ function withHiddenSpawnWindows(action) {
520
+ const { spawn } = childProcess;
521
+ childProcess.spawn = ((command, args, options) => spawn(command, args, {
522
+ ...options,
523
+ windowsHide: true
524
+ }));
525
+ syncBuiltinESMExports();
526
+ try {
527
+ return action();
528
+ } finally {
529
+ childProcess.spawn = spawn;
530
+ syncBuiltinESMExports();
531
+ }
532
+ }
505
533
  // src/semantics/node/checker.ts
506
534
  /**
507
535
  * Owns the Node checker process, snapshots, and answers cached within each snapshot.
@@ -642,7 +670,7 @@ var NodeChecker = class {
642
670
  */
643
671
  #startApi() {
644
672
  this.stats.starts += 1;
645
- return new API({
673
+ return withHiddenSpawnWindows(() => new API({
646
674
  cwd: this.#projectRoot,
647
675
  collectTiming: true,
648
676
  fs: {
@@ -663,7 +691,7 @@ var NodeChecker = class {
663
691
  return overlay;
664
692
  }
665
693
  }
666
- });
694
+ }));
667
695
  }
668
696
  /**
669
697
  * Disposes the previous snapshot and API, then replaces the API without clearing virtual files or
@@ -1450,6 +1478,10 @@ var AnalysisCss = class {
1450
1478
  affects(id) {
1451
1479
  return isStylesheet(id) || [...this.#dependencies].some((file) => sameFile(file, id));
1452
1480
  }
1481
+ /** Returns the files that CSS or plugins have read. */
1482
+ get dependencies() {
1483
+ return this.#dependencies;
1484
+ }
1453
1485
  /**
1454
1486
  * Discards loaders and the native session while keeping plugins available for the next load.
1455
1487
  */
@@ -1484,6 +1516,19 @@ var AnalysisCss = class {
1484
1516
  return this.#loader;
1485
1517
  }
1486
1518
  /**
1519
+ * Loads the design system for questions that read no source file.
1520
+ *
1521
+ * @returns A query over the definitions of the latest plugin load, and the plugin runtime.
1522
+ * @throws If resolving, reading, or loading the CSS graph fails.
1523
+ */
1524
+ async designSystem() {
1525
+ const loader = await this.load();
1526
+ return {
1527
+ query: (pluginLoader(this.#session) ?? loader).editorQuery(),
1528
+ plugins: this.#plugins
1529
+ };
1530
+ }
1531
+ /**
1487
1532
  * Selects the plugins of the project's CSS graph.
1488
1533
  *
1489
1534
  * @returns Configured plugins, the project root, and the runtime of the last load.
@@ -1661,6 +1706,16 @@ var AnalysisProject = class {
1661
1706
  this.#cssDirty ||= this.#css.affects(id);
1662
1707
  }
1663
1708
  }
1709
+ /**
1710
+ * Lists the files that analysis has observed, for comparison with paths in watch notifications.
1711
+ *
1712
+ * @returns Keys from `sourceKey` for prepared sources, files that CSS or plugins read, and paths
1713
+ * that the checker read or tested, including missing paths. A custom semantic backend contributes
1714
+ * nothing.
1715
+ */
1716
+ reads() {
1717
+ return /* @__PURE__ */ new Set([...this.#compilation.sourceKeys(), ...[...this.#css.dependencies, ...this.#facts?.dependencies ?? []].map(sourceKey)]);
1718
+ }
1664
1719
  /** Makes pending results stale. The next transaction rebuilds CSS and backend caches. */
1665
1720
  invalidate() {
1666
1721
  this.#compilation.invalidate();
@@ -1809,6 +1864,27 @@ var AnalysisProject = class {
1809
1864
  return task;
1810
1865
  }
1811
1866
  /**
1867
+ * Answers a question about the design system, using the current buffers.
1868
+ *
1869
+ * @param request - Theme, utility, or variant request.
1870
+ * @returns The answer, or undefined when the captured buffers become outdated.
1871
+ * @throws If the project is closed, CSS loading fails, or a plugin fails.
1872
+ */
1873
+ designSystem(request) {
1874
+ const revision = this.#revision;
1875
+ const documents = new Map([...this.#documents].map(([id, document]) => [id, document.source]));
1876
+ const task = this.#queue.then(async () => {
1877
+ if (this.#closed) throw new Error("Analysis project is closed");
1878
+ if (!await this.#installDocuments(documents, revision)) return;
1879
+ return queryDesignSystem({
1880
+ ...await this.#css.designSystem(),
1881
+ annotations: this.host.config.preview
1882
+ }, request);
1883
+ });
1884
+ this.#queue = task.catch(() => {});
1885
+ return task;
1886
+ }
1887
+ /**
1812
1888
  * Marks the project closed, discards pending results, and waits for queued work before cleanup.
1813
1889
  * Repeated calls return without requesting further cleanup.
1814
1890
  *
@@ -2400,6 +2476,17 @@ function createFileSystemAnalysisHost(config, directory) {
2400
2476
  };
2401
2477
  }
2402
2478
  // src/project/workspace.ts
2479
+ /**
2480
+ * Recognizes a declaration file that a target glob such as `*.ts` selects by accident. Other files
2481
+ * that the host cannot analyze stay in scope, so their analysis reports the wrong `files` entry.
2482
+ *
2483
+ * @param project - Project whose host decides what it can analyze.
2484
+ * @param file - Absolute file path.
2485
+ * @returns Whether the file is a declaration file that the host cannot analyze.
2486
+ */
2487
+ function skipsDeclaration(project, file) {
2488
+ return /.d.[cm]?ts$/i.test(file) && !project.analysis.host.supports(file);
2489
+ }
2403
2490
  /** Owns every project in one evaluated configuration and keeps overlapping scopes independent. */
2404
2491
  var AnalysisWorkspace = class AnalysisWorkspace {
2405
2492
  /** Absolute paths with open buffers, including paths outside the configured target globs. */
@@ -2454,7 +2541,8 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2454
2541
  *
2455
2542
  * @param project - Project whose root, include globs, and exclusions define membership.
2456
2543
  * @param file - Absolute file path to test.
2457
- * @returns Whether the path matches files without matching excludes, node_modules, or .git.
2544
+ * @returns Whether the path matches files without matching excludes, node_modules, or .git. A
2545
+ * declaration file that the host cannot analyze is outside the scope.
2458
2546
  * Dependency traversal does not use this filter.
2459
2547
  */
2460
2548
  includes(project, file) {
@@ -2465,7 +2553,7 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2465
2553
  * @returns Whether the normalized path matches the pattern.
2466
2554
  */
2467
2555
  const matches = (pattern) => minimatch(name, pattern, { dot: true });
2468
- return project.config.files.some(matches) && ![
2556
+ return !skipsDeclaration(project, file) && project.config.files.some(matches) && ![
2469
2557
  "**/node_modules/**",
2470
2558
  "**/.git/**",
2471
2559
  ...project.config.exclude ?? []
@@ -2502,7 +2590,7 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2502
2590
  if (path.isAbsolute(pattern)) return { file: path.normalize(pattern) };
2503
2591
  return { pattern: pattern.replace(/^(\.\/)+/, "") };
2504
2592
  });
2505
- const files = await glob(project.config.files, {
2593
+ const files = (await glob(project.config.files, {
2506
2594
  cwd: project.analysis.host.root,
2507
2595
  absolute: true,
2508
2596
  onlyFiles: true,
@@ -2512,11 +2600,24 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2512
2600
  "**/.git/**",
2513
2601
  ...project.config.exclude ?? []
2514
2602
  ]
2515
- });
2603
+ })).filter((file) => !skipsDeclaration(project, file));
2516
2604
  if (options.stylesheets) files.push(...await project.analysis.stylesheets().catch(() => []));
2517
2605
  return files.filter((file, index) => files.findIndex((other) => sameFile(other, file)) === index && (!filters?.length || filters.some((filter) => filter.file !== void 0 ? path.normalize(file) === filter.file : minimatch(path.relative(project.analysis.host.root, file).replaceAll("\\", "/"), filter.pattern, { dot: true })))).sort();
2518
2606
  }
2519
2607
  /**
2608
+ * Answers a question about the design system of each project.
2609
+ *
2610
+ * @param request - Theme, utility, or variant request.
2611
+ * @returns Answers in configuration order.
2612
+ * @throws If CSS loading or a plugin fails in any project.
2613
+ */
2614
+ async designSystem(request) {
2615
+ return (await Promise.all(this.projects.map((project) => project.analysis.designSystem(request)))).flatMap((result, project) => result ? [{
2616
+ project,
2617
+ result
2618
+ }] : []);
2619
+ }
2620
+ /**
2520
2621
  * Keeps editor answers separate when several projects include the same target.
2521
2622
  *
2522
2623
  * @param file - Absolute target path used for independent scope checks.
@@ -2568,14 +2669,55 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2568
2669
  for (const project of this.projects) project.analysis.closeDocument(file);
2569
2670
  }
2570
2671
  /**
2571
- * Checks whether save or watch notifications need a new workspace.
2672
+ * Checks whether a change to a file requires a new workspace.
2673
+ *
2674
+ * @param file - Changed file path.
2675
+ * @param reads - Result of `AnalysisProject.reads` for each project, in project order.
2676
+ * @returns True for a configuration dependency, and for a tsconfig or package.json that a project
2677
+ * read or that lies directly in a project root. Module resolution can read these files without
2678
+ * recording them, so the project root is checked as well.
2679
+ */
2680
+ #reopens(file, reads) {
2681
+ if (this.#configurationDependencies.some((dependency) => sameFile(dependency, file))) return true;
2682
+ return /(?:^|[/\\])(?:tsconfig(?:\.[^/\\]+)?\.json|package\.json)$/.test(file) && this.projects.some((project, index) => reads[index].has(sourceKey(file)) || sameFile(path.dirname(path.resolve(file)), project.analysis.host.root));
2683
+ }
2684
+ /**
2685
+ * Checks whether the disk content of a file can change a project's analysis.
2686
+ *
2687
+ * @param index - Project index.
2688
+ * @param file - Changed file path.
2689
+ * @param reads - Result of `AnalysisProject.reads` for each project, in project order.
2690
+ * @returns True when the file has no open buffer and the project read it or its target scope
2691
+ * contains it. Scope membership covers a new file that no analysis has read.
2692
+ */
2693
+ #stale(index, file, reads) {
2694
+ return ![...this.#openDocuments].some((open) => sameFile(open, file)) && (reads[index].has(sourceKey(file)) || this.includes(this.projects[index], path.resolve(file)));
2695
+ }
2696
+ /**
2697
+ * Checks whether file changes can change this workspace's results, without changing any state.
2698
+ * Analysis cannot depend on a file that it never read and that lies outside every target scope.
2699
+ *
2700
+ * @param files - File paths reported by a watch notification. Relative paths use the working
2701
+ * directory.
2702
+ * @returns Whether `refresh` would request reopening or invalidate a project for these files.
2703
+ */
2704
+ affects(files) {
2705
+ const reads = this.projects.map((project) => project.analysis.reads());
2706
+ return files.some((file) => this.#reopens(file, reads) || this.projects.some((_, i) => this.#stale(i, file, reads)));
2707
+ }
2708
+ /**
2709
+ * Checks whether save or watch notifications need a new workspace, and invalidates each project
2710
+ * that a change to a closed file can affect.
2572
2711
  *
2573
2712
  * @param files - File paths reported by the notification. Relative paths use the working directory.
2574
- * @returns True when every file has an open buffer and none is a configuration dependency,
2575
- * a tsconfig, or package.json. This method does not read disk or reopen projects.
2713
+ * @returns False when the workspace must reopen, which leaves projects unchanged. Otherwise
2714
+ * returns true. This method does not read disk or reopen projects.
2576
2715
  */
2577
2716
  refresh(files) {
2578
- return files.every((file) => [...this.#openDocuments].some((open) => sameFile(open, file)) && !this.#configurationDependencies.some((dependency) => sameFile(dependency, file)) && !/(?:^|[/\\])(?:tsconfig(?:\.[^/\\]+)?\.json|package\.json)$/.test(file));
2717
+ const reads = this.projects.map((project) => project.analysis.reads());
2718
+ if (files.some((file) => this.#reopens(file, reads))) return false;
2719
+ for (const [index, project] of this.projects.entries()) if (files.some((file) => this.#stale(index, file, reads))) project.analysis.invalidate();
2720
+ return true;
2579
2721
  }
2580
2722
  /**
2581
2723
  * Advances every project revision and requests CSS and resolver cache refresh before its next analysis.
@@ -2667,6 +2809,6 @@ var AnalysisWorkspace = class AnalysisWorkspace {
2667
2809
  if (errors.length) throw new AggregateError(errors, "Failed to close Stillwind analysis hosts");
2668
2810
  }
2669
2811
  };
2670
- export { AnalysisProject, AnalysisWorkspace, CompilationFailure, EditorProject, EditorSnapshot, PluginRuntime, TypeFactsError, TypeScriptFactsService, analyzeModule, attachPlugins, cleanModuleId, compileModule, compileWithPlugins, compilerModuleId, compilerOptions, composeCarrierSourceMap, composeFrameworkSourceMap, composeModuleSourceMap, createFileSystemAnalysisHost, createStylesheetResolver, cssEntrypoint, cssWithSourceMap, decodeCssSourceMap, defaultPluginExport, fileModuleDescriptor, fileSourceKind, finalizeCss, finalizeModuleWithMap, isStylesheet, lintsStylesheet, loadCssGraph, loadEditorCssGraph, moduleSourceMap, nodePluginHost, pluginLoader, resolveTypeFactsEnvironment, warnRejectedNames };
2812
+ export { AnalysisProject, AnalysisWorkspace, CompilationFailure, EditorProject, EditorSnapshot, PluginRuntime, TypeFactsError, TypeScriptFactsService, analyzeModule, attachPlugins, cleanModuleId, compileModule, compileWithPlugins, compilerModuleId, compilerOptions, composeCarrierSourceMap, composeFrameworkSourceMap, composeModuleSourceMap, createFileSystemAnalysisHost, createStylesheetResolver, cssEntrypoint, cssWithSourceMap, decodeCssSourceMap, defaultPluginExport, fileModuleDescriptor, fileSourceKind, finalizeCss, finalizeModuleWithMap, isStylesheet, lintsStylesheet, loadCssGraph, loadEditorCssGraph, moduleSourceMap, nodePluginHost, pluginLoader, queryDesignSystem, resolveTypeFactsEnvironment, warnRejectedNames };
2671
2813
 
2672
2814
  //# sourceMappingURL=index.js.map