svelte-docinfo 0.8.1 → 0.9.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/README.md CHANGED
@@ -19,7 +19,7 @@ npm i -D svelte-docinfo
19
19
  ```
20
20
 
21
21
  Peer dependencies: `svelte` 5+, `svelte2tsx`, `typescript` 5.9+ or 6, and `zod` 4+
22
- (npm 7+ installs them automatically).
22
+ (npm 7+ installs them automatically), plus an optional `vite` 6+ for the Vite plugin.
23
23
 
24
24
  - [Quick start](#quick-start)
25
25
  - [Vite plugin](#vite-plugin)
@@ -92,7 +92,7 @@ export const add = (a: number, b: number): number => a + b;
92
92
 
93
93
  Three ways to integrate `svelte-docinfo`:
94
94
 
95
- 1. [Vite plugin](#vite-plugin) - recommended for SvelteKit and Vite projects. Serves a virtual module with HMR in dev mode:
95
+ 1. [Vite plugin](#vite-plugin) - recommended for SvelteKit and Vite projects. Serves a virtual module that stays current in dev mode:
96
96
 
97
97
  ```ts
98
98
  // vite.config.ts
@@ -192,6 +192,8 @@ You may also want to browse the [test fixtures](https://github.com/fuzdev/svelte
192
192
 
193
193
  ## Vite plugin
194
194
 
195
+ Requires Vite 6 or later.
196
+
195
197
  1. Add the plugin to `vite.config.ts`:
196
198
 
197
199
  ```ts
@@ -229,7 +231,7 @@ Plugin options:
229
231
  | `sourceOptions` | `{sourcePaths: ['src/lib'], …}` | Partial overrides for default source options (SvelteKit `src/lib` layout). |
230
232
  | `resolveDependencies` | `true` | Resolve import dependencies. When `false`, `dependencies`/`dependents` stay empty. |
231
233
  | `onDuplicates` | — | Dispatch on duplicate declaration names: `'throw'` \| `'warn'` \| callback. Diagnostic emits regardless of dispatch. |
232
- | `hmrDebounceMs` | `100` | HMR debounce delay in milliseconds. |
234
+ | `hmrDebounceMs` | `100` | Dev re-analysis debounce delay in milliseconds. |
233
235
 
234
236
  Source-scope notes (shared with the [CLI](#cli) and `analyzeFromFiles`):
235
237
 
@@ -286,7 +288,7 @@ All CLI options:
286
288
  The [Vite plugin](#vite-plugin)'s source-scope notes apply here too: explicit `--include` patterns widen the source scope (module paths become relative to the widened root, and a pattern with no base scopes the whole project root and logs an info line); `node_modules` and dot-directories below a source dir are always excluded regardless of `--exclude`; absolute paths and patterns inside the project root are accepted, and out-of-root ones fail loudly.
287
289
 
288
290
  Exit codes: 0 (success), 1 (analysis errors), 2 (CLI errors or a thrown analysis error, like a
289
- missing `tsconfig.json` or an `--on-duplicates throw` collision).
291
+ missing or unloadable `tsconfig.json` or an `--on-duplicates throw` collision).
290
292
 
291
293
  See [examples/cli/](examples/cli/README.md) for more usage patterns.
292
294
 
@@ -362,7 +364,7 @@ Known gaps:
362
364
  ## Documentation
363
365
 
364
366
  - [svelte-docinfo.fuz.dev](https://svelte-docinfo.fuz.dev/) - docs site with guides, options reference, and API docs
365
- - [examples/vite/](examples/vite/README.md) - Vite plugin with HMR
367
+ - [examples/vite/](examples/vite/README.md) - Vite plugin with live reload in dev
366
368
  - [examples/cli/](examples/cli/README.md) - CLI usage and piping
367
369
  - [examples/api/](examples/api/README.md) - API usage patterns
368
370
 
package/dist/analyze.d.ts CHANGED
@@ -63,7 +63,8 @@ export interface AnalyzeOptions {
63
63
  * @returns analyzed modules (sorted alphabetically) + concatenated ingest +
64
64
  * query diagnostics
65
65
  * @throws Error if `sourceOptions` validation fails or `tsconfig.json` is
66
- * missing at `projectRoot`. Also propagates `onDuplicates: 'throw'` errors.
66
+ * missing at `projectRoot` or can't be loaded (see `loadTsconfig`). Also
67
+ * propagates `onDuplicates: 'throw'` errors.
67
68
  */
68
69
  export declare const analyze: (options: AnalyzeOptions) => Promise<AnalyzeResultJson>;
69
70
  /**
@@ -135,9 +136,9 @@ export interface AnalyzeFromFilesOptions {
135
136
  * 3. **Analysis** — `session.query()`
136
137
  *
137
138
  * @returns analyzed modules + concatenated ingest, discovery, and query diagnostics
138
- * @throws Error on invalid or contradictory options, a missing `tsconfig.json`,
139
- * failed strict `'exports'` discovery, or a collision under
140
- * `onDuplicates: 'throw'`
139
+ * @throws Error on invalid or contradictory options, a missing or unloadable
140
+ * `tsconfig.json` (see `loadTsconfig`), failed strict `'exports'` discovery,
141
+ * or a collision under `onDuplicates: 'throw'`
141
142
  */
142
143
  export declare const analyzeFromFiles: (options: AnalyzeFromFilesOptions) => Promise<AnalyzeResultJson>;
143
144
  //# sourceMappingURL=analyze.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAEN,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;OAMG;IACH,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,sEAAsE;IACtE,aAAa,EAAE,mBAAmB,CAAC;IACnC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,GAAU,SAAS,cAAc,KAAG,OAAO,CAAC,iBAAiB,CAwBhF,CAAC;AAIF;;;;;GAKG;AACH,MAAM,WA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AW,cAAc;IAC9B;;;;;;OAMG;IACH,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,sEAAsE;IACtE,aAAa,EAAE,mBAAmB,CAAC;IACnC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,GAAU,SAAS,cAAc,KAAG,OAAO,CAAC,iBAAiB,CAwBhF,CAAC;AAIF;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACvC,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,2DAA2D;IAC3D,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC5B,SAAS,uBAAuB,KAC9B,OAAO,CAAC,iBAAiB,CAwH3B,CAAC"}
package/dist/analyze.js CHANGED
@@ -32,7 +32,8 @@ import { normalizeDiagnosticPaths } from './analyze-core.js';
32
32
  * @returns analyzed modules (sorted alphabetically) + concatenated ingest +
33
33
  * query diagnostics
34
34
  * @throws Error if `sourceOptions` validation fails or `tsconfig.json` is
35
- * missing at `projectRoot`. Also propagates `onDuplicates: 'throw'` errors.
35
+ * missing at `projectRoot` or can't be loaded (see `loadTsconfig`). Also
36
+ * propagates `onDuplicates: 'throw'` errors.
36
37
  */
37
38
  export const analyze = async (options) => {
38
39
  const session = createAnalysisSession({
@@ -70,9 +71,9 @@ export const analyze = async (options) => {
70
71
  * 3. **Analysis** — `session.query()`
71
72
  *
72
73
  * @returns analyzed modules + concatenated ingest, discovery, and query diagnostics
73
- * @throws Error on invalid or contradictory options, a missing `tsconfig.json`,
74
- * failed strict `'exports'` discovery, or a collision under
75
- * `onDuplicates: 'throw'`
74
+ * @throws Error on invalid or contradictory options, a missing or unloadable
75
+ * `tsconfig.json` (see `loadTsconfig`), failed strict `'exports'` discovery,
76
+ * or a collision under `onDuplicates: 'throw'`
76
77
  */
77
78
  export const analyzeFromFiles = async (options) => {
78
79
  const { projectRoot, include, exclude, resolveDependencies: shouldResolveDependencies = true, resolveImport, sourceOptions, onDuplicates, log, discovery, distDir } = options;
@@ -16,7 +16,8 @@
16
16
  * A few conditions still throw from the public entry points. These are
17
17
  * configuration and environment errors, not per-file failures: invalid or
18
18
  * contradictory options (see the `@throws` on `createSourceOptions` and
19
- * `discoverSourceFiles`), a missing `tsconfig.json`, Svelte <5, and failed
19
+ * `discoverSourceFiles`), a missing or unloadable `tsconfig.json` (including
20
+ * an unresolved `extends`, see `loadTsconfig`), Svelte <5, and failed
20
21
  * strict `'exports'` discovery. `onDuplicates: 'throw'` also throws, by
21
22
  * request. Wrap the top-level call to handle these.
22
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,K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K,CAAC,UAAU,CAAC,KAAG,OACX,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,aAAa,KAAK,CAAC,UAAU,CAAC,KAAG,OACX,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,aAAa,KAAK,CAAC,UAAU,CAAC,KAAG,KAAK,CAAC,UAAU,CACxB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,aAAa,KAAK,CAAC,UAAU,CAAC,KAAG,KAAK,CAAC,UAAU,CACxB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,cAAc,EAC9C,aAAa,KAAK,CAAC,UAAU,CAAC,EAC9B,MAAM,CAAC,KACL,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAC6C,CAAC;AAEvF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,UAAU,KAAG,MAMzD,CAAC"}
@@ -16,7 +16,8 @@
16
16
  * A few conditions still throw from the public entry points. These are
17
17
  * configuration and environment errors, not per-file failures: invalid or
18
18
  * contradictory options (see the `@throws` on `createSourceOptions` and
19
- * `discoverSourceFiles`), a missing `tsconfig.json`, Svelte <5, and failed
19
+ * `discoverSourceFiles`), a missing or unloadable `tsconfig.json` (including
20
+ * an unresolved `extends`, see `loadTsconfig`), Svelte <5, and failed
20
21
  * strict `'exports'` discovery. `onDuplicates: 'throw'` also throws, by
21
22
  * request. Wrap the top-level call to handle these.
22
23
  *
@@ -35,7 +35,8 @@ export interface LoadTsconfigOptions {
35
35
  */
36
36
  projectRoot?: string;
37
37
  /**
38
- * Path to tsconfig.json (relative to `projectRoot`).
38
+ * Path to tsconfig.json, relative to `projectRoot`; parent directories are
39
+ * searched when it isn't there.
39
40
  * @default 'tsconfig.json'
40
41
  */
41
42
  tsconfig?: string;
@@ -224,7 +225,26 @@ export interface AnalysisLanguageService {
224
225
  * Each call globs the tsconfig `include` to build `rootFileNames`; reuse the
225
226
  * result rather than calling per resolve.
226
227
  *
227
- * @throws Error if tsconfig.json (or the file named by `options.tsconfig`) is not found.
228
+ * The config is located like `tsc -p`: `options.tsconfig` relative to
229
+ * `projectRoot`, walking up through parent directories when it isn't there.
230
+ * Relative paths inside it (`extends`, `include`, path-valued options) resolve
231
+ * against the config file's own directory, not `projectRoot`.
232
+ *
233
+ * A config that can't be fully loaded throws rather than analyzing with a
234
+ * partial config: TypeScript reports a missing `extends` target as a
235
+ * diagnostic and carries on without the inherited options (`lib`, `types`,
236
+ * `paths`, `rootDirs`), so external types would silently degrade to `any`.
237
+ * SvelteKit's generated config is the common case (`$app/tsconfig`, or
238
+ * `.svelte-kit/tsconfig.json` before SvelteKit 3) — it exists only after
239
+ * `svelte-kit sync`. Option-level diagnostics (an unknown option, a bad
240
+ * value) and an `include` matching no files don't throw: TypeScript still
241
+ * applies the rest of the config, and the project's own typecheck reports
242
+ * them.
243
+ *
244
+ * @throws Error if tsconfig.json (or the file named by `options.tsconfig`) is
245
+ * not found or fails to parse, or a config in its `extends` chain is missing
246
+ * or fails to parse. A missing SvelteKit-generated target adds a hint to run
247
+ * `svelte-kit sync`.
228
248
  */
229
249
  export declare const loadTsconfig: (options?: LoadTsconfigOptions, log?: AnalysisLog) => {
230
250
  compilerOptions: ts.CompilerOptions;
@@ -240,7 +260,7 @@ export declare const loadTsconfig: (options?: LoadTsconfigOptions, log?: Analysi
240
260
  * @param options - configuration options for program creation
241
261
  * @param log - optional logger for info messages
242
262
  * @returns the TypeScript program
243
- * @throws Error if tsconfig.json is not found
263
+ * @throws Error if the tsconfig can't be loaded (see `loadTsconfig`)
244
264
  *
245
265
  * @example
246
266
  * ```ts
@@ -260,7 +280,7 @@ export declare const createAnalysisProgram: (options?: AnalysisProgramOptions, l
260
280
  * @param options - configuration options
261
281
  * @param log - optional logger for info messages
262
282
  * @returns the language service handle
263
- * @throws Error if tsconfig.json is not found
283
+ * @throws Error if the tsconfig can't be loaded (see `loadTsconfig`)
264
284
  *
265
285
  * @example
266
286
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"typescript-program.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/typescript-program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,KAAK,mBAAmB,EAAiB,MAAM,oBAAoB,CAAC;AAI7E;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC7B,sEAAsE;IACtE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,8DAA8D;IAC9D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mFAAmF;IACnF,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACd;AAED,iDAAiD;AACjD,eAAO,MAAM,mBAAmB,QAAO,aA8BtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,EAAE,CAAC,YAAY,EACrB,cAAc,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD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AK,CAAC,MAAM,CAAC,CAAA;CA6CrE,CAAC;AA6CF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,GACjC,UAAU,sBAAsB,EAChC,MAAM,WAAW,KACf,EAAE,CAAC,OAkBL,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,6BAA6B,GACzC,UAAU,8BAA8B,EACxC,MAAM,WAAW,KACf,uBAyJF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,KAAK,OAAO,CAAC;AAcpE;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,mBAAmB,KAAG,cAMnE,CAAC;AAKF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,mBAAmB,KAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAO7F,CAAC"}
@@ -121,6 +121,34 @@ export const applyVirtualFiles = (host, virtualFiles) => {
121
121
  }
122
122
  return entries;
123
123
  };
124
+ // `ts.Diagnostics` isn't in the public typings, so the codes are literals
125
+ const TS_FILE_NOT_FOUND = 6053; // `extends` bare specifier that doesn't resolve
126
+ const TS_CANNOT_READ_FILE = 5083; // `extends` path that doesn't exist or can't be read
127
+ const TS_ROOT_NOT_OBJECT = 5092; // `extends` target whose root value isn't an object
128
+ /**
129
+ * Whether a `parseJsonConfigFileContent` diagnostic means a config in the
130
+ * `extends` chain didn't load: a target that's missing or unreadable, one that
131
+ * fails to parse (a syntax diagnostic, TypeScript's 1xxx range), or one whose
132
+ * root isn't an object.
133
+ */
134
+ const isConfigChainDiagnostic = (diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error &&
135
+ (diagnostic.code === TS_FILE_NOT_FOUND ||
136
+ diagnostic.code === TS_CANNOT_READ_FILE ||
137
+ diagnostic.code === TS_ROOT_NOT_OBJECT ||
138
+ (diagnostic.code >= 1000 && diagnostic.code < 2000));
139
+ /**
140
+ * Whether a chain diagnostic names a config SvelteKit generates during
141
+ * `svelte-kit sync`: `$app/tsconfig` (SvelteKit 3) or
142
+ * `.svelte-kit/tsconfig.json` (SvelteKit 2). Matched on the specifier alone,
143
+ * not the quotes around it, since localized messages may quote differently.
144
+ */
145
+ const isSvelteKitGeneratedConfigMessage = (message) => message.includes('$app/') || message.includes('.svelte-kit/tsconfig.json');
146
+ const formatConfigDiagnostic = (diagnostic, configPath) => {
147
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, ' ');
148
+ const file = diagnostic.file?.fileName;
149
+ const location = file && file !== configPath ? ` in ${file}` : '';
150
+ return `TS${diagnostic.code}${location}: ${message}`;
151
+ };
124
152
  /**
125
153
  * Load and parse tsconfig.json into compiler options + initial file list.
126
154
  *
@@ -133,18 +161,52 @@ export const applyVirtualFiles = (host, virtualFiles) => {
133
161
  * Each call globs the tsconfig `include` to build `rootFileNames`; reuse the
134
162
  * result rather than calling per resolve.
135
163
  *
136
- * @throws Error if tsconfig.json (or the file named by `options.tsconfig`) is not found.
164
+ * The config is located like `tsc -p`: `options.tsconfig` relative to
165
+ * `projectRoot`, walking up through parent directories when it isn't there.
166
+ * Relative paths inside it (`extends`, `include`, path-valued options) resolve
167
+ * against the config file's own directory, not `projectRoot`.
168
+ *
169
+ * A config that can't be fully loaded throws rather than analyzing with a
170
+ * partial config: TypeScript reports a missing `extends` target as a
171
+ * diagnostic and carries on without the inherited options (`lib`, `types`,
172
+ * `paths`, `rootDirs`), so external types would silently degrade to `any`.
173
+ * SvelteKit's generated config is the common case (`$app/tsconfig`, or
174
+ * `.svelte-kit/tsconfig.json` before SvelteKit 3) — it exists only after
175
+ * `svelte-kit sync`. Option-level diagnostics (an unknown option, a bad
176
+ * value) and an `include` matching no files don't throw: TypeScript still
177
+ * applies the rest of the config, and the project's own typecheck reports
178
+ * them.
179
+ *
180
+ * @throws Error if tsconfig.json (or the file named by `options.tsconfig`) is
181
+ * not found or fails to parse, or a config in its `extends` chain is missing
182
+ * or fails to parse. A missing SvelteKit-generated target adds a hint to run
183
+ * `svelte-kit sync`.
137
184
  */
138
185
  export const loadTsconfig = (options, log) => {
139
186
  const projectRoot = options?.projectRoot ?? process.cwd();
140
187
  const tsconfigName = options?.tsconfig ?? 'tsconfig.json';
141
188
  const configPath = ts.findConfigFile(projectRoot, ts.sys.fileExists, tsconfigName);
142
189
  if (!configPath) {
143
- throw new Error(`No ${tsconfigName} found in ${projectRoot}`);
190
+ throw new Error(`No ${tsconfigName} found in ${projectRoot} or its parent directories`);
144
191
  }
145
192
  log?.info(`using ${configPath}`);
146
193
  const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
147
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, projectRoot);
194
+ if (configFile.error) {
195
+ throw new Error(`Failed to read ${configPath}: ${formatConfigDiagnostic(configFile.error, configPath)}`);
196
+ }
197
+ // base path = the config's own dir (as `tsc -p` does), so relative
198
+ // `extends`/`include` still resolve when the config was found by walking up
199
+ // or `options.tsconfig` names a file in a subdirectory
200
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath), undefined, configPath);
201
+ const chainErrors = parsedConfig.errors.filter(isConfigChainDiagnostic);
202
+ if (chainErrors.length > 0) {
203
+ const messages = chainErrors.map((d) => formatConfigDiagnostic(d, configPath));
204
+ // the diagnostic text names the unresolved target, e.g. `File '$app/tsconfig' not found.`
205
+ const hint = messages.some(isSvelteKitGeneratedConfigMessage)
206
+ ? ' SvelteKit generates its tsconfig: run `svelte-kit sync` (or `gro sync`) first.'
207
+ : '';
208
+ throw new Error(`Failed to load the extends chain of ${configPath}: ${messages.join(' ')}${hint}`);
209
+ }
148
210
  const compilerOptions = options?.compilerOptions
149
211
  ? { ...parsedConfig.options, ...options.compilerOptions }
150
212
  : parsedConfig.options;
@@ -194,7 +256,7 @@ const createResolveModuleNameLiterals = (hasVirtual, resolutionHost) => (literal
194
256
  * @param options - configuration options for program creation
195
257
  * @param log - optional logger for info messages
196
258
  * @returns the TypeScript program
197
- * @throws Error if tsconfig.json is not found
259
+ * @throws Error if the tsconfig can't be loaded (see `loadTsconfig`)
198
260
  *
199
261
  * @example
200
262
  * ```ts
@@ -228,7 +290,7 @@ export const createAnalysisProgram = (options, log) => {
228
290
  * @param options - configuration options
229
291
  * @param log - optional logger for info messages
230
292
  * @returns the language service handle
231
- * @throws Error if tsconfig.json is not found
293
+ * @throws Error if the tsconfig can't be loaded (see `loadTsconfig`)
232
294
  *
233
295
  * @example
234
296
  * ```ts
package/dist/vite.d.ts CHANGED
@@ -6,8 +6,10 @@
6
6
  * `setFiles` + one `query` per debounce window — multi-file editor saves
7
7
  * collapse to a single re-analysis instead of N serialized round-trips.
8
8
  *
9
- * HMR invalidation keys on `setFiles`'s `changedIds`; the watcher gates on
10
- * `isSource(file) || session.has(file)`.
9
+ * A re-analysis that changes the output invalidates the virtual module and
10
+ * reloads the page (the module is data its importers derive state from, so
11
+ * there's no in-place HMR update); `setFiles`'s `changedIds` skip re-analysis
12
+ * when nothing changed. The watcher gates on `isSource(file) || session.has(file)`.
11
13
  *
12
14
  * Consumers import the analysis result:
13
15
  *
@@ -90,7 +92,7 @@ export interface VitePluginSvelteDocinfoOptions {
90
92
  /** Behavior when duplicate declaration names are found across modules. */
91
93
  onDuplicates?: OnDuplicates;
92
94
  /**
93
- * HMR debounce delay in milliseconds. Coalesces rapid file changes during dev.
95
+ * Dev re-analysis debounce delay in milliseconds. Coalesces rapid file changes.
94
96
  * @default 100
95
97
  */
96
98
  hmrDebounceMs?: number;
@@ -99,8 +101,9 @@ export interface VitePluginSvelteDocinfoOptions {
99
101
  * Vite plugin: analyzes TypeScript and Svelte source files via a persistent
100
102
  * `AnalysisSession` and serves the result as `virtual:svelte-docinfo`.
101
103
  *
102
- * In dev mode, watches source files and triggers debounced HMR updates on
103
- * changes via `setFiles` batches drained from a pending-changes Map.
104
+ * In dev mode, watches source files and re-analyzes on changes via `setFiles`
105
+ * batches drained from a pending-changes Map, reloading the page when the
106
+ * output changes.
104
107
  * In build mode, runs analysis once during `buildStart`.
105
108
  */
106
109
  declare const svelteDocinfo: (options?: VitePluginSvelteDocinfoOptions) => Plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/vite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,OAAO,KAAK,EAAwB,MAAM,EAAiB,MAAM,MAAM,CAAC;AAGxE,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAGN,KAAK,aAAa,EAElB,KAAK,sBAAsB,EAC3B,MAAM,oBAAoB,CAAC;AAU5B,mDAAmD;AACnD,MAAM,WAAW,8BAA8B;IAC9C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,aAAa,GAAI,UAAS,8BAAmC,KAAG,MA0YrE,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/vite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,KAAK,EAAqC,MAAM,EAAiB,MAAM,MAAM,CAAC;AAGrF,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAGN,KAAK,aAAa,EAElB,KAAK,sBAAsB,EAC3B,MAAM,oBAAoB,CAAC;AAU5B,mDAAmD;AACnD,MAAM,WAAW,8BAA8B;IAC9C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,QAAA,MAAM,aAAa,GAAI,UAAS,8BAAmC,KAAG,MAodrE,CAAC;AAEF,eAAe,aAAa,CAAC"}
package/dist/vite.js CHANGED
@@ -6,8 +6,10 @@
6
6
  * `setFiles` + one `query` per debounce window — multi-file editor saves
7
7
  * collapse to a single re-analysis instead of N serialized round-trips.
8
8
  *
9
- * HMR invalidation keys on `setFiles`'s `changedIds`; the watcher gates on
10
- * `isSource(file) || session.has(file)`.
9
+ * A re-analysis that changes the output invalidates the virtual module and
10
+ * reloads the page (the module is data its importers derive state from, so
11
+ * there's no in-place HMR update); `setFiles`'s `changedIds` skip re-analysis
12
+ * when nothing changed. The watcher gates on `isSource(file) || session.has(file)`.
11
13
  *
12
14
  * Consumers import the analysis result:
13
15
  *
@@ -52,8 +54,9 @@ const VITE_DEV_IDENTITY = 'vite-plugin-container';
52
54
  * Vite plugin: analyzes TypeScript and Svelte source files via a persistent
53
55
  * `AnalysisSession` and serves the result as `virtual:svelte-docinfo`.
54
56
  *
55
- * In dev mode, watches source files and triggers debounced HMR updates on
56
- * changes via `setFiles` batches drained from a pending-changes Map.
57
+ * In dev mode, watches source files and re-analyzes on changes via `setFiles`
58
+ * batches drained from a pending-changes Map, reloading the page when the
59
+ * output changes.
57
60
  * In build mode, runs analysis once during `buildStart`.
58
61
  */
59
62
  const svelteDocinfo = (options = {}) => {
@@ -61,23 +64,53 @@ const svelteDocinfo = (options = {}) => {
61
64
  let projectRoot;
62
65
  let resolvedSourceOptions;
63
66
  let logger = null;
64
- let isDev = false;
65
67
  let modulesJson = '[]';
66
68
  let diagnosticsJson = '[]';
67
69
  let cachedModuleCode = null;
70
+ // The dev server the session serves: the resolver, invalidation, and reloads
71
+ // go through it. `configureServer` only records a server as `pendingServer`,
72
+ // and its client environment's `buildStart` adopts it, which runs only once
73
+ // that server starts (in middleware mode during creation, otherwise at
74
+ // `listen`) or on the first resolve through its client environment, whichever
75
+ // comes first. A restart that reuses this plugin builds the new server before
76
+ // closing the old one, and when creating it fails (a later plugin's
77
+ // `configureServer` throws), Vite logs the failure and keeps the old server
78
+ // running. Adopting at `configureServer` would invalidate the dead server's
79
+ // graphs and reload its clients while the live server served stale output,
80
+ // and resolving through the dead server's plugin container would start it,
81
+ // re-running this `buildStart` against it. In middleware mode the new server
82
+ // starts during its creation, so a failure after that (another plugin's client
83
+ // `buildStart` throws) still leaves the plugin on the failed server: nothing
84
+ // signals it.
68
85
  let server = null;
86
+ let pendingServer = null;
87
+ // Every server ever adopted. Watcher events from a server never adopted (one
88
+ // whose creation failed, or one not yet started) are dropped; an adopted
89
+ // server's watcher keeps feeding the session until Vite closes it, so a
90
+ // middleware-mode restart, which adopts the new server before closing the
91
+ // old one, loses no event in between (the event sequence check and the
92
+ // session's content check make an event both watchers report harmless).
93
+ const adoptedServers = new WeakSet();
69
94
  let session = null;
95
+ // the environment whose `buildStart` created `session`, so only its `buildEnd` disposes it
96
+ let sessionEnvironment = null;
70
97
  // Discovery diagnostics survive across HMR cycles (the discovery pass only
71
98
  // runs at cold start). Tracked here because the session has no concept of
72
99
  // "discovery" — it ingests files the plugin hands to it.
73
100
  let discoveryDiagnostics = [];
74
101
  // Resolver wiring
75
- // Dev resolver: server.pluginContainer.resolveId. Stable identity across
76
- // the dev session — cache hits work across HMR cycles.
102
+ // Dev resolver: the client environment's `pluginContainer.resolveId`, which
103
+ // is what the mixed `server.pluginContainer` delegates to without `ssr`.
104
+ // Stable identity across the dev session — cache hits work across HMR cycles.
77
105
  const viteDevResolver = {
78
106
  resolve: async (specifier, fromFile) => {
107
+ // Outside the `try`: `configureServer` rejects servers without
108
+ // `environments`, and anything else unexpected here throws to the
109
+ // session, which records `resolver_failed` per specifier instead of
110
+ // reading it as "no dependency"
111
+ const { pluginContainer } = server.environments.client;
79
112
  try {
80
- const r = await server.pluginContainer.resolveId(specifier, fromFile);
113
+ const r = await pluginContainer.resolveId(specifier, fromFile);
81
114
  return r?.id ?? null;
82
115
  }
83
116
  catch {
@@ -117,18 +150,18 @@ const svelteDocinfo = (options = {}) => {
117
150
  return seq;
118
151
  };
119
152
  const isLatestEvent = (path, seq) => eventSeqs.get(path) === seq;
153
+ // No `import.meta.hot.accept()`: a self-accepting data module re-runs on
154
+ // update while its importers (e.g. a layout that builds a `Library` from
155
+ // `modules`) keep the old values, so a change reloads the page instead —
156
+ // see `invalidateAndReload`.
120
157
  const buildModuleCode = () => {
121
158
  if (cachedModuleCode !== null)
122
159
  return cachedModuleCode;
123
- const lines = [
160
+ cachedModuleCode = [
124
161
  `export const modules = ${modulesJson};`,
125
162
  `export const diagnostics = ${diagnosticsJson};`,
126
163
  `export default {modules, diagnostics};`
127
- ];
128
- if (isDev) {
129
- lines.push(`if (import.meta.hot) { import.meta.hot.accept(); }`);
130
- }
131
- cachedModuleCode = lines.join('\n');
164
+ ].join('\n');
132
165
  return cachedModuleCode;
133
166
  };
134
167
  const updateOutputFromQuery = (modules, queryDiagnostics) => {
@@ -151,30 +184,31 @@ const svelteDocinfo = (options = {}) => {
151
184
  cachedModuleCode = null;
152
185
  return true;
153
186
  };
154
- const sendHmrInvalidation = () => {
187
+ /**
188
+ * Invalidates the virtual module in every dev environment that loaded it,
189
+ * then reloads the browser. Each environment has its own module graph: the
190
+ * client one backs the browser, and a server one (SvelteKit's `ssr`, or one
191
+ * a framework or adapter names itself) backs SSR, so every environment is
192
+ * walked rather than a fixed pair. The module is plain data its importers
193
+ * derive state from, so there's no HMR boundary to update in place: only a
194
+ * full reload re-runs the importers. Only the client environment has
195
+ * browsers to reload, and the reload is skipped when no browser has loaded
196
+ * the module.
197
+ */
198
+ const invalidateAndReload = () => {
155
199
  if (!server)
156
200
  return;
157
- const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
158
- if (!mod)
201
+ for (const { moduleGraph } of Object.values(server.environments)) {
202
+ const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
203
+ if (mod)
204
+ moduleGraph.invalidateModule(mod);
205
+ }
206
+ const { client } = server.environments;
207
+ if (!client.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID))
159
208
  return;
160
- server.moduleGraph.invalidateModule(mod);
161
- // Hardcoded Vite URL encoding for the `\0` prefix on virtual modules.
162
- // Not a documented Vite public API — if Vite changes the encoding in a
163
- // future release, HMR silently stops firing (initial load still works
164
- // through the public resolveId/load hooks). Revisit if Vite exposes a
165
- // proper API for invalidating a virtual module by id.
166
- const hmrPath = '/@id/__x00__virtual:svelte-docinfo';
167
- server.hot.send({
168
- type: 'update',
169
- updates: [
170
- {
171
- type: 'js-update',
172
- path: hmrPath,
173
- acceptedPath: hmrPath,
174
- timestamp: Date.now()
175
- }
176
- ]
177
- });
209
+ // `path: '*'` is Vite's own form for a reload not tied to an HTML file;
210
+ // the client reloads unconditionally for any path not ending in `.html`
211
+ client.hot.send({ type: 'full-reload', path: '*' });
178
212
  };
179
213
  const errorLog = (err) => {
180
214
  const log = logger ?? { error: (msg) => console.error(msg) };
@@ -217,10 +251,18 @@ const svelteDocinfo = (options = {}) => {
217
251
  const flushBatch = async () => {
218
252
  if (initialPromise)
219
253
  await initialPromise;
220
- if (!session)
254
+ // After `buildEnd` there's no session to flush into: drop what's pending
255
+ // (discovery reads disk), or `scheduleFlush`'s loop never drains and
256
+ // spins on microtasks
257
+ if (!session) {
258
+ pendingChanges.clear();
221
259
  return;
260
+ }
222
261
  if (pendingChanges.size === 0)
223
262
  return;
263
+ // A `buildEnd` (server close or restart) can land at any await below;
264
+ // bail when it does rather than touching a disposed session
265
+ const current = session;
224
266
  // Drain. New events arriving during this flush land in pendingChanges
225
267
  // and are picked up by the surrounding while-loop in `scheduleFlush`.
226
268
  const drained = [...pendingChanges];
@@ -235,11 +277,16 @@ const svelteDocinfo = (options = {}) => {
235
277
  }
236
278
  // Apply deletions first so re-adds (rare but possible: unlink+add same
237
279
  // path within one debounce window) work correctly.
238
- for (const path of toDelete)
239
- await session.deleteFile(path);
280
+ for (const path of toDelete) {
281
+ await current.deleteFile(path);
282
+ if (session !== current)
283
+ return;
284
+ }
240
285
  let anyChanged = toDelete.length > 0;
241
286
  if (toAdd.length > 0) {
242
- const ingest = await session.setFiles(toAdd);
287
+ const ingest = await current.setFiles(toAdd);
288
+ if (session !== current)
289
+ return;
243
290
  if (ingest.changedIds.size > 0)
244
291
  anyChanged = true;
245
292
  }
@@ -248,10 +295,10 @@ const svelteDocinfo = (options = {}) => {
248
295
  // `updateOutputFromQuery` pulls the cumulative ingest diagnostics from
249
296
  // `session.allIngestDiagnostics()` itself — no per-batch survival
250
297
  // tracking needed at the plugin layer.
251
- const result = session.query({ onDuplicates, log: logger ?? undefined });
298
+ const result = current.query({ onDuplicates, log: logger ?? undefined });
252
299
  const updated = updateOutputFromQuery(result.modules, result.diagnostics);
253
300
  if (updated)
254
- sendHmrInvalidation();
301
+ invalidateAndReload();
255
302
  };
256
303
  const scheduleFlush = () => {
257
304
  if (hmrFlushPromise)
@@ -259,6 +306,9 @@ const svelteDocinfo = (options = {}) => {
259
306
  hmrFlushPromise = (async () => {
260
307
  await new Promise((r) => setTimeout(r, hmrDebounceMs));
261
308
  try {
309
+ // Progress invariant: every `flushBatch` either empties
310
+ // `pendingChanges` before its first await on the session (drain or
311
+ // drop) or throws, which exits the loop.
262
312
  while (pendingChanges.size > 0) {
263
313
  await flushBatch();
264
314
  }
@@ -288,7 +338,6 @@ const svelteDocinfo = (options = {}) => {
288
338
  // Assign the logger before widening — `createSourceOptionsWithInclude`
289
339
  // logs when an include pattern scopes the whole project root.
290
340
  logger = config.logger;
291
- isDev = config.command === 'serve';
292
341
  // `exclude` shortcut overrides `sourceOptions.exclude` (same precedence
293
342
  // as `analyzeFromFiles`).
294
343
  const mergedSourceOptions = exclude !== undefined ? { ...sourceOptions, exclude } : sourceOptions;
@@ -305,8 +354,16 @@ const svelteDocinfo = (options = {}) => {
305
354
  }
306
355
  },
307
356
  async buildStart() {
357
+ // In dev, the server whose client environment this is has started:
358
+ // adopt it (see `server`). Other environments' `buildStart` (under
359
+ // `perEnvironmentStartEndDuringDev`) adopt nothing.
360
+ if (pendingServer && this.environment === pendingServer.environments.client) {
361
+ server = pendingServer;
362
+ adoptedServers.add(pendingServer);
363
+ pendingServer = null;
364
+ }
308
365
  // Choose resolver based on mode; create the session here (after
309
- // configResolved set sourceOptions; for dev, after configureServer
366
+ // configResolved set sourceOptions; for dev, after the adoption above
310
367
  // set `server`).
311
368
  let sessionResolver;
312
369
  if (!resolveDependencies) {
@@ -339,11 +396,26 @@ const svelteDocinfo = (options = {}) => {
339
396
  resolveImport: sessionResolver,
340
397
  log: logger ?? undefined
341
398
  });
399
+ sessionEnvironment = this.environment;
342
400
  initialPromise = runInitialAnalysis().finally(() => {
343
401
  initialPromise = null;
344
402
  });
345
403
  await initialPromise;
346
404
  },
405
+ // Releases the session's language service. In dev, Vite runs this once
406
+ // (for the client environment) when the server closes, middleware mode
407
+ // included, where there's no `httpServer` to listen on. In build mode
408
+ // (no `server`) it runs after the bundle's `load` calls, and
409
+ // `buildStart` creates a fresh session for a `--watch` rebuild.
410
+ buildEnd() {
411
+ // Dispose only the session this environment's `buildStart` created: a
412
+ // middleware-mode restart that reuses this plugin runs the new server's
413
+ // `buildStart` before the old server's `buildEnd`
414
+ if (server && this.environment !== sessionEnvironment)
415
+ return;
416
+ session?.dispose();
417
+ session = null;
418
+ },
347
419
  resolveId(id) {
348
420
  if (id === VIRTUAL_ID)
349
421
  return RESOLVED_VIRTUAL_ID;
@@ -358,8 +430,17 @@ const svelteDocinfo = (options = {}) => {
358
430
  return buildModuleCode();
359
431
  },
360
432
  configureServer(devServer) {
361
- server = devServer;
433
+ // `server.environments` arrived in Vite 6; dev touches nothing else
434
+ if (!devServer.environments) {
435
+ throw new Error('svelte-docinfo: the Vite plugin requires Vite 6 or later');
436
+ }
437
+ // Adopted by this server's `buildStart` (see `server`); until then, and
438
+ // for good if its creation fails, its watcher's events are dropped
439
+ // (see `adoptedServers`)
440
+ pendingServer = devServer;
362
441
  devServer.watcher.on('change', (rawFile) => {
442
+ if (!adoptedServers.has(devServer))
443
+ return;
363
444
  // Watcher emits native-separator paths on Windows. Posixify at
364
445
  // the boundary so eventSeqs/pendingChanges keys, isWatchedFile
365
446
  // checks, and downstream session calls all share one canonical id.
@@ -376,7 +457,7 @@ const svelteDocinfo = (options = {}) => {
376
457
  // content (formatters saving idempotently) trigger spurious
377
458
  // events; the session's content-equality check in setFile
378
459
  // handles that case — `changed: false` short-circuits the
379
- // HMR invalidation.
460
+ // reload.
380
461
  let newContent;
381
462
  try {
382
463
  newContent = await readFile(file, 'utf-8');
@@ -396,6 +477,8 @@ const svelteDocinfo = (options = {}) => {
396
477
  })().catch(errorLog);
397
478
  });
398
479
  devServer.watcher.on('add', (rawFile) => {
480
+ if (!adoptedServers.has(devServer))
481
+ return;
399
482
  const file = toPosixPath(rawFile);
400
483
  if (!isWatchedFile(file))
401
484
  return;
@@ -413,6 +496,8 @@ const svelteDocinfo = (options = {}) => {
413
496
  })().catch(errorLog);
414
497
  });
415
498
  devServer.watcher.on('unlink', (rawFile) => {
499
+ if (!adoptedServers.has(devServer))
500
+ return;
416
501
  const file = toPosixPath(rawFile);
417
502
  // Use session.has() as the gate: paths outside source paths were
418
503
  // never owned, so nothing to do.
@@ -421,10 +506,6 @@ const svelteDocinfo = (options = {}) => {
421
506
  stampEvent(file);
422
507
  enqueueChange(file, null);
423
508
  });
424
- devServer.httpServer?.on('close', () => {
425
- session?.dispose();
426
- session = null;
427
- });
428
509
  }
429
510
  };
430
511
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-docinfo",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "static analysis for TypeScript and Svelte",
5
5
  "glyph": "📜",
6
6
  "logo": "logo.svg",
@@ -51,17 +51,23 @@
51
51
  "svelte": "^5.0.0",
52
52
  "svelte2tsx": "^0.7.30",
53
53
  "typescript": "^5.9.3 || ^6",
54
+ "vite": "^6 || ^7 || ^8",
54
55
  "zod": "^4"
55
56
  },
57
+ "peerDependenciesMeta": {
58
+ "vite": {
59
+ "optional": true
60
+ }
61
+ },
56
62
  "devDependencies": {
57
63
  "@fuzdev/blake3-wasm": "^0.2.0",
58
64
  "@fuzdev/fuz_code": "^0.50.0",
59
65
  "@fuzdev/fuz_css": "^0.66.1",
60
- "@fuzdev/fuz_ui": "^0.210.4",
66
+ "@fuzdev/fuz_ui": "^0.213.0",
61
67
  "@fuzdev/fuz_util": "^0.72.0",
62
- "@fuzdev/gro": "^0.214.0",
68
+ "@fuzdev/gro": "^0.215.1",
63
69
  "@fuzdev/mdz": "^0.4.0",
64
- "@ryanatkn/eslint-config": "^0.12.2",
70
+ "@ryanatkn/eslint-config": "^0.13.0",
65
71
  "@sveltejs/acorn-typescript": "^1.0.9",
66
72
  "@sveltejs/adapter-static": "^4.0.0",
67
73
  "@sveltejs/kit": "^3.0.1",