svelte-docinfo 0.4.1 → 0.5.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 +21 -12
- package/dist/analyze-core.d.ts +19 -12
- package/dist/analyze-core.d.ts.map +1 -1
- package/dist/analyze-core.js +40 -17
- package/dist/declaration-build.d.ts +16 -19
- package/dist/declaration-build.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/postprocess.d.ts +118 -28
- package/dist/postprocess.d.ts.map +1 -1
- package/dist/postprocess.js +279 -31
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +47 -3
- package/dist/types.d.ts +145 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +115 -1
- package/dist/typescript-exports.d.ts +3 -1
- package/dist/typescript-exports.d.ts.map +1 -1
- package/dist/typescript-exports.js +237 -158
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
> static analysis for TypeScript and Svelte 📜
|
|
6
6
|
> [**svelte-docinfo.fuz.dev**](https://svelte-docinfo.fuz.dev/)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
svelte-docinfo extracts JSON describing the exports
|
|
9
9
|
of TypeScript and Svelte modules for open-ended use cases
|
|
10
10
|
like docs, code search, and dev tools.
|
|
11
11
|
It uses
|
|
12
12
|
[svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx)
|
|
13
|
-
and the TypeScript compiler API to resolve types, track exports, and extract semantic details.
|
|
13
|
+
and the TypeScript compiler API to resolve types, track exports+imports, and extract semantic details.
|
|
14
14
|
It includes a Vite plugin, CLI, and programmatic API
|
|
15
15
|
in the [npm package](https://www.npmjs.com/package/svelte-docinfo).
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm
|
|
18
|
+
npm i -D svelte-docinfo
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
- [Quick start](#quick-start)
|
|
@@ -27,11 +27,6 @@ npm install svelte-docinfo -D
|
|
|
27
27
|
- [Credits](#credits)
|
|
28
28
|
- [License](#license)
|
|
29
29
|
|
|
30
|
-
Dependencies are minimal and the tool's scope is limited to data, not presentation.
|
|
31
|
-
The [docs website](https://svelte-docinfo.fuz.dev/docs/api)
|
|
32
|
-
for svelte-docinfo is made using itself
|
|
33
|
-
and [fuz_ui](https://github.com/fuzdev/fuz_ui) components.
|
|
34
|
-
|
|
35
30
|
svelte-docinfo is largely inspired by [`sveld`](https://github.com/carbon-design-system/sveld),
|
|
36
31
|
but instead of AST-only inspection it uses the TypeScript compiler API for richer information,
|
|
37
32
|
and also analyzes TypeScript modules.
|
|
@@ -42,6 +37,11 @@ but you may find gaps and flaws -- please open issues for bugs
|
|
|
42
37
|
and [discussions](https://github.com/fuzdev/svelte-docinfo/discussions)
|
|
43
38
|
for everything else!
|
|
44
39
|
|
|
40
|
+
Dependencies are minimal and the tool's scope is limited to data, not presentation.
|
|
41
|
+
The [docs website](https://svelte-docinfo.fuz.dev/docs/api)
|
|
42
|
+
for svelte-docinfo is made using itself
|
|
43
|
+
and [fuz_ui](https://github.com/fuzdev/fuz_ui) components.
|
|
44
|
+
|
|
45
45
|
**AI disclosure:** the code and docs beyond the intro
|
|
46
46
|
were mostly written by Claude Code with uneven human guidance.
|
|
47
47
|
The first release took 5 months of intermittent work and ~500 manual commits.
|
|
@@ -174,7 +174,11 @@ All three produce the same JSON shape:
|
|
|
174
174
|
}
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
For
|
|
177
|
+
For examples of source input paired with the exact JSON `svelte-docinfo` emits:
|
|
178
|
+
|
|
179
|
+
- see svelte-docinfo's own source code's extracted JSON at
|
|
180
|
+
[svelte-docinfo.fuz.dev/demo/extraction](https://svelte-docinfo.fuz.dev/demo/extraction)
|
|
181
|
+
- browse the [test fixtures](https://github.com/fuzdev/svelte-docinfo/tree/main/src/test/fixtures)
|
|
178
182
|
|
|
179
183
|
## Vite plugin
|
|
180
184
|
|
|
@@ -314,14 +318,19 @@ See the [API docs](https://svelte-docinfo.fuz.dev/docs/api) for the full referen
|
|
|
314
318
|
- **Enums**: regular and const, with member values and per-member JSDoc
|
|
315
319
|
- **Function overloads**: all public overload signatures with per-overload JSDoc
|
|
316
320
|
- **Dependency graphs**: tracks imports between modules and computes dependents
|
|
317
|
-
- **Re-export tracking**: `alsoExportedFrom` arrays, `aliasOf` for renames, `starExports` for `export * from './x'`
|
|
321
|
+
- **Re-export tracking**: `alsoExportedFrom` arrays on canonical declarations plus the forward view `ModuleJson.reExports` (so barrels are self-describing), `aliasOf` for renames, `starExports` for `export * from './x'`, and `externalReExports`/`externalStarExports` for direct re-exports from packages — with `resolveExportSurface()` to combine them all into a module's full export surface using ES star semantics
|
|
318
322
|
- **Namespace re-exports**: `export * as ns from './x'` synthesized as `kind: 'namespace'`
|
|
319
323
|
- **Source locations**: file and line for every declaration
|
|
320
324
|
- **Build-tool agnostic**: works with any source: file system, build pipeline, or in-memory
|
|
321
325
|
- **Diagnostic collection**: accumulates warnings and errors without halting; `partial: true` flags incomplete declarations
|
|
322
326
|
|
|
323
|
-
Known gaps:
|
|
324
|
-
|
|
327
|
+
Known gaps:
|
|
328
|
+
|
|
329
|
+
- context tracking (transitive detection of common patterns seems tractable)
|
|
330
|
+
- standalone `namespace Foo {}` declarations and decorators are not yet supported
|
|
331
|
+
- Svelte 4 legacy features (slots, events, `$restProps`) are out of scope — Svelte 5 snippets and callback props replace most of them
|
|
332
|
+
|
|
333
|
+
[Issues](https://github.com/fuzdev/svelte-docinfo/issues) for bugs and
|
|
325
334
|
[discussions](https://github.com/fuzdev/svelte-docinfo/discussions) are welcome!
|
|
326
335
|
|
|
327
336
|
## Documentation
|
package/dist/analyze-core.d.ts
CHANGED
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
import ts from 'typescript';
|
|
29
29
|
import { z } from 'zod';
|
|
30
30
|
import { ModuleJson, type ModuleJsonInput } from './types.js';
|
|
31
|
-
import type { ReExportInfo } from './declaration-build.js';
|
|
32
31
|
import { Diagnostic } from './diagnostics.js';
|
|
33
32
|
import type { AnalysisLog } from './log.js';
|
|
34
33
|
import { type SvelteVirtualFile } from './svelte.js';
|
|
@@ -1145,6 +1144,20 @@ export declare const AnalyzeResultJson: z.ZodObject<{
|
|
|
1145
1144
|
dependencies: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1146
1145
|
dependents: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1147
1146
|
starExports: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1147
|
+
reExports: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1148
|
+
name: z.ZodString;
|
|
1149
|
+
module: z.ZodString;
|
|
1150
|
+
typeOnly: z.ZodDefault<z.ZodBoolean>;
|
|
1151
|
+
sourceLine: z.ZodOptional<z.ZodNumber>;
|
|
1152
|
+
}, z.core.$strict>>>;
|
|
1153
|
+
externalReExports: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1154
|
+
name: z.ZodString;
|
|
1155
|
+
specifier: z.ZodString;
|
|
1156
|
+
originalName: z.ZodOptional<z.ZodString>;
|
|
1157
|
+
typeOnly: z.ZodDefault<z.ZodBoolean>;
|
|
1158
|
+
sourceLine: z.ZodOptional<z.ZodNumber>;
|
|
1159
|
+
}, z.core.$strict>>>;
|
|
1160
|
+
externalStarExports: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1148
1161
|
partial: z.ZodDefault<z.ZodBoolean>;
|
|
1149
1162
|
}, z.core.$strict>>>;
|
|
1150
1163
|
diagnostics: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -1347,16 +1360,6 @@ export interface AnalyzeResultJsonWire {
|
|
|
1347
1360
|
modules: Array<ModuleJsonInput>;
|
|
1348
1361
|
diagnostics: Array<Diagnostic>;
|
|
1349
1362
|
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Result of analyzing a single module.
|
|
1352
|
-
*
|
|
1353
|
-
* `alsoExportedFrom` on declarations is always empty from this path —
|
|
1354
|
-
* cross-module re-export resolution requires all modules.
|
|
1355
|
-
*/
|
|
1356
|
-
export interface ModuleAnalyzeResult {
|
|
1357
|
-
module: ModuleJson;
|
|
1358
|
-
reExports: Array<ReExportInfo>;
|
|
1359
|
-
}
|
|
1360
1363
|
/**
|
|
1361
1364
|
* Analyze a single non-Svelte source file and extract module metadata.
|
|
1362
1365
|
*
|
|
@@ -1373,10 +1376,14 @@ export interface ModuleAnalyzeResult {
|
|
|
1373
1376
|
*
|
|
1374
1377
|
* Returns `undefined` when the file is skipped; the diagnostic is added to
|
|
1375
1378
|
* `diagnostics` so the caller can keep iterating.
|
|
1379
|
+
*
|
|
1380
|
+
* `alsoExportedFrom` on returned declarations is always empty from this path —
|
|
1381
|
+
* cross-module re-export resolution requires all modules (`mergeReExports`
|
|
1382
|
+
* consumes the returned module's `reExports` in phase 2).
|
|
1376
1383
|
*/
|
|
1377
1384
|
export declare const analyzeModule: (sourceFile: SourceFileInfo & {
|
|
1378
1385
|
dependents?: ReadonlyArray<string>;
|
|
1379
|
-
}, program: ts.Program, options: ModuleSourceOptions, diagnostics: Array<Diagnostic>, log?: AnalysisLog) =>
|
|
1386
|
+
}, program: ts.Program, options: ModuleSourceOptions, diagnostics: Array<Diagnostic>, log?: AnalysisLog) => ModuleJson | undefined;
|
|
1380
1387
|
/**
|
|
1381
1388
|
* Inputs to `analyzeCore`. The caller (one-shot wrapper or session.query)
|
|
1382
1389
|
* is responsible for normalizing `sourceOptions`, obtaining the program,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze-core.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/analyze-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAC,CAAC,E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G;AACH,eAAO,MAAM,wBAAwB,GACpC,aAAa,KAAK,CAAC,UAAU,CAAC,EAC9B,aAAa,MAAM,KACjB,IAgBF,CAAC"}
|
package/dist/analyze-core.js
CHANGED
|
@@ -34,7 +34,7 @@ import { analyzeSvelteModule } from './svelte.js';
|
|
|
34
34
|
import { stripVirtualSuffix, getComponentName } from './source.js';
|
|
35
35
|
import { extractPath, extractDependencies } from './source-config.js';
|
|
36
36
|
import { toPosixPath } from './paths.js';
|
|
37
|
-
import { sortModules, findDuplicates, mergeReExports, resolveComponentAliases, } from './postprocess.js';
|
|
37
|
+
import { sortModules, findDuplicates, mergeReExports, resolveComponentAliases, compareStrings, } from './postprocess.js';
|
|
38
38
|
/**
|
|
39
39
|
* Convenience `OnDuplicatesCallback` that throws on any duplicate.
|
|
40
40
|
*
|
|
@@ -121,17 +121,38 @@ export const AnalyzeResultJson = z.strictObject({
|
|
|
121
121
|
modules: z.array(ModuleJson).default([]),
|
|
122
122
|
diagnostics: z.array(Diagnostic).default([]),
|
|
123
123
|
});
|
|
124
|
-
const
|
|
124
|
+
const toModuleJson = (raw) => {
|
|
125
125
|
const filtered = raw.declarations.filter((d) => !d.nodocs).map((d) => d.declaration);
|
|
126
|
-
|
|
126
|
+
// sorted for deterministic, environment-independent output —
|
|
127
|
+
// getExportsOfModule order is a TS implementation detail. Module tie-break
|
|
128
|
+
// because names can collide: a Svelte default-slot re-export re-keys to
|
|
129
|
+
// the component name, which a same-name re-export from another module may
|
|
130
|
+
// also use. The same re-keying can produce exact-duplicate edges
|
|
131
|
+
// (component + same-name script-module export from one file) — deduped on
|
|
132
|
+
// `(name, module)` so those pairs stay unique; the sourceLine tie-break
|
|
133
|
+
// makes the dedup deterministic (smallest line survives)
|
|
134
|
+
const reExports = raw.reExports
|
|
135
|
+
.slice()
|
|
136
|
+
.sort((a, b) => compareStrings(a.name, b.name) ||
|
|
137
|
+
compareStrings(a.module, b.module) ||
|
|
138
|
+
(a.sourceLine ?? 0) - (b.sourceLine ?? 0))
|
|
139
|
+
.filter((r, i, arr) => i === 0 || r.name !== arr[i - 1].name || r.module !== arr[i - 1].module);
|
|
140
|
+
const externalReExports = raw.externalReExports
|
|
141
|
+
.slice()
|
|
142
|
+
.sort((a, b) => compareStrings(a.name, b.name) ||
|
|
143
|
+
compareStrings(a.specifier, b.specifier) ||
|
|
144
|
+
(a.sourceLine ?? 0) - (b.sourceLine ?? 0));
|
|
145
|
+
return ModuleJson.parse({
|
|
127
146
|
path: raw.path,
|
|
128
147
|
declarations: filtered,
|
|
129
148
|
dependencies: raw.dependencies,
|
|
130
149
|
dependents: raw.dependents,
|
|
131
150
|
starExports: raw.starExports,
|
|
151
|
+
reExports,
|
|
152
|
+
externalReExports,
|
|
153
|
+
externalStarExports: raw.externalStarExports,
|
|
132
154
|
...(raw.moduleComment ? { moduleComment: raw.moduleComment } : {}),
|
|
133
155
|
});
|
|
134
|
-
return { module, reExports: raw.reExports };
|
|
135
156
|
};
|
|
136
157
|
// ── Module dispatch ──────────────────────────────────────────────────────────
|
|
137
158
|
/**
|
|
@@ -150,6 +171,10 @@ const toModuleAnalyzeResult = (raw) => {
|
|
|
150
171
|
*
|
|
151
172
|
* Returns `undefined` when the file is skipped; the diagnostic is added to
|
|
152
173
|
* `diagnostics` so the caller can keep iterating.
|
|
174
|
+
*
|
|
175
|
+
* `alsoExportedFrom` on returned declarations is always empty from this path —
|
|
176
|
+
* cross-module re-export resolution requires all modules (`mergeReExports`
|
|
177
|
+
* consumes the returned module's `reExports` in phase 2).
|
|
153
178
|
*/
|
|
154
179
|
export const analyzeModule = (sourceFile, program, options, diagnostics, log) => {
|
|
155
180
|
const checker = program.getTypeChecker();
|
|
@@ -191,6 +216,8 @@ export const analyzeModule = (sourceFile, program, options, diagnostics, log) =>
|
|
|
191
216
|
dependents,
|
|
192
217
|
starExports: [],
|
|
193
218
|
reExports: [],
|
|
219
|
+
externalReExports: [],
|
|
220
|
+
externalStarExports: [],
|
|
194
221
|
};
|
|
195
222
|
}
|
|
196
223
|
else {
|
|
@@ -204,7 +231,7 @@ export const analyzeModule = (sourceFile, program, options, diagnostics, log) =>
|
|
|
204
231
|
log?.warn(`No analyzer for file: ${sourceFile.id}`);
|
|
205
232
|
return undefined;
|
|
206
233
|
}
|
|
207
|
-
return
|
|
234
|
+
return toModuleJson(raw);
|
|
208
235
|
};
|
|
209
236
|
/**
|
|
210
237
|
* Run the two-phase analysis loop on pre-prepared inputs.
|
|
@@ -228,8 +255,7 @@ export const analyzeCore = (inputs) => {
|
|
|
228
255
|
const checker = program.getTypeChecker();
|
|
229
256
|
const diagnostics = [];
|
|
230
257
|
const modules = [];
|
|
231
|
-
|
|
232
|
-
// Phase 1: analyze every module, collect re-exports
|
|
258
|
+
// Phase 1: analyze every module (forward re-export edges land on `ModuleJson.reExports`)
|
|
233
259
|
for (const sourceFile of sourceFiles) {
|
|
234
260
|
// Failed-transform Svelte file: synthesize placeholder ModuleJson so
|
|
235
261
|
// the modules array reflects the full owned set. The originating
|
|
@@ -250,30 +276,27 @@ export const analyzeCore = (inputs) => {
|
|
|
250
276
|
log?.warn(`Svelte component ${componentName} marked partial (transform failed at ingest)`);
|
|
251
277
|
continue;
|
|
252
278
|
}
|
|
253
|
-
let
|
|
279
|
+
let mod;
|
|
254
280
|
const virtualFile = svelteVirtualFiles.get(sourceFile.id);
|
|
255
281
|
if (virtualFile) {
|
|
256
282
|
const modulePath = extractPath(sourceFile.id, sourceOptions);
|
|
257
283
|
const raw = analyzeSvelteModule(sourceFile, modulePath, checker, sourceOptions, diagnostics, program, virtualFile);
|
|
258
284
|
if (raw) {
|
|
259
|
-
|
|
285
|
+
mod = toModuleJson(raw);
|
|
260
286
|
}
|
|
261
287
|
else {
|
|
262
288
|
log?.error(`Svelte module analysis failed: ${sourceFile.id}`);
|
|
263
289
|
}
|
|
264
290
|
}
|
|
265
291
|
else {
|
|
266
|
-
|
|
292
|
+
mod = analyzeModule(sourceFile, program, sourceOptions, diagnostics, log);
|
|
267
293
|
}
|
|
268
|
-
if (!
|
|
294
|
+
if (!mod)
|
|
269
295
|
continue;
|
|
270
|
-
modules.push(
|
|
271
|
-
for (const reExport of result.reExports) {
|
|
272
|
-
collectedReExports.push({ reExportingModule: result.module.path, reExport });
|
|
273
|
-
}
|
|
296
|
+
modules.push(mod);
|
|
274
297
|
}
|
|
275
|
-
// Phase 2a: build alsoExportedFrom arrays
|
|
276
|
-
mergeReExports(modules
|
|
298
|
+
// Phase 2a: build alsoExportedFrom arrays from the modules' forward edges
|
|
299
|
+
mergeReExports(modules);
|
|
277
300
|
// Phase 2b: fill component-only fields on renamed component aliases —
|
|
278
301
|
// canonical components are only fully populated after phase 1 finishes.
|
|
279
302
|
resolveComponentAliases(modules);
|
|
@@ -13,23 +13,7 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
-
import type { DeclarationKind, DeclarationModifier, GenericParamJson, MemberKind, ParameterJson, OverloadJsonInput, ComponentPropJsonInput, Reactivity } from './types.js';
|
|
17
|
-
/**
|
|
18
|
-
* Information about a same-name re-export.
|
|
19
|
-
*
|
|
20
|
-
* Collected during phase 1 of analysis and passed to `mergeReExports`
|
|
21
|
-
* in phase 2 to build `alsoExportedFrom` arrays on canonical declarations.
|
|
22
|
-
*/
|
|
23
|
-
export interface ReExportInfo {
|
|
24
|
-
/**
|
|
25
|
-
* Name of the re-exported declaration. `'default'` for default-slot
|
|
26
|
-
* re-exports (`export {default} from './x'`) — that's the canonical's
|
|
27
|
-
* actual symbol name in the original module.
|
|
28
|
-
*/
|
|
29
|
-
name: string;
|
|
30
|
-
/** Module path (relative to `sourceRoot`) where the declaration is originally declared. */
|
|
31
|
-
originalModule: string;
|
|
32
|
-
}
|
|
16
|
+
import type { DeclarationKind, DeclarationModifier, GenericParamJson, MemberKind, ParameterJson, OverloadJsonInput, ComponentPropJsonInput, Reactivity, ReExportJsonInput, ExternalReExportJsonInput } from './types.js';
|
|
33
17
|
/**
|
|
34
18
|
* Permissive type for constructing members incrementally before Zod validation.
|
|
35
19
|
*
|
|
@@ -141,10 +125,23 @@ export interface ModuleExportsAnalysis {
|
|
|
141
125
|
moduleComment?: string;
|
|
142
126
|
/** All exported declarations with `@nodocs` flags — consumer filters based on policy. */
|
|
143
127
|
declarations: Array<DeclarationAnalysis>;
|
|
144
|
-
/**
|
|
145
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Same-name re-exports. Published as `ModuleJson.reExports` and consumed
|
|
130
|
+
* by `mergeReExports` in phase 2 to build `alsoExportedFrom` arrays on
|
|
131
|
+
* canonical declarations. Unsorted here and may contain exact duplicates
|
|
132
|
+
* (Svelte default-slot re-keying) — ordering and dedup are applied at
|
|
133
|
+
* publication in `analyze-core.ts`.
|
|
134
|
+
*/
|
|
135
|
+
reExports: Array<ReExportJsonInput>;
|
|
146
136
|
/** Star exports (`export * from './module'`) — module paths that are fully re-exported. */
|
|
147
137
|
starExports: Array<string>;
|
|
138
|
+
/**
|
|
139
|
+
* Direct re-exports from external packages. Published as
|
|
140
|
+
* `ModuleJson.externalReExports`; unsorted here, sorted at publication.
|
|
141
|
+
*/
|
|
142
|
+
externalReExports: Array<ExternalReExportJsonInput>;
|
|
143
|
+
/** External star exports (`export * from 'pkg'`) — specifiers as written. */
|
|
144
|
+
externalStarExports: Array<string>;
|
|
148
145
|
}
|
|
149
146
|
/**
|
|
150
147
|
* Result of analyzing a module (TypeScript or Svelte).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration-build.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/declaration-build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EACX,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"declaration-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,MAAM,CAAC;IACb,8EAA8E;IAC9E,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,gFAAgF;IAChF,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC1B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,13 +17,13 @@ export { createAnalysisSession } from './session.js';
|
|
|
17
17
|
export type { AnalysisSession, AnalysisSessionOptions, SetFileOptions, SetFileResult, SetFilesResult, QueryOptions, } from './session.js';
|
|
18
18
|
export { normalizeResolveImport } from './dep-resolver.js';
|
|
19
19
|
export type { ImportResolver, ResolveImport, ResolveImportFn } from './dep-resolver.js';
|
|
20
|
-
export { DeclarationKind, DeclarationModifier, MemberKind, Reactivity, GenericParamJson, ParameterJson, ComponentPropJson, OverloadJson, FunctionMemberJson, VariableMemberJson, ConstructorMemberJson, MemberJson, FunctionDeclarationJson, ClassDeclarationJson, InterfaceDeclarationJson, TypeDeclarationJson, VariableDeclarationJson, EnumDeclarationJson, ComponentDeclarationJson, SnippetDeclarationJson, NamespaceDeclarationJson, DeclarationJson, ModuleJson, } from './types.js';
|
|
20
|
+
export { DeclarationKind, DeclarationModifier, MemberKind, Reactivity, GenericParamJson, ParameterJson, ComponentPropJson, OverloadJson, FunctionMemberJson, VariableMemberJson, ConstructorMemberJson, MemberJson, FunctionDeclarationJson, ClassDeclarationJson, InterfaceDeclarationJson, TypeDeclarationJson, VariableDeclarationJson, EnumDeclarationJson, ComponentDeclarationJson, SnippetDeclarationJson, NamespaceDeclarationJson, DeclarationJson, ReExportJson, ExternalReExportJson, ModuleJson, } from './types.js';
|
|
21
21
|
export { getDisplayName, generateImport, compactReplacer, isKind, findTypeReferences, buildTypeReferencePatterns, } from './declaration-helpers.js';
|
|
22
22
|
export type { SourceFileInfo, AnalyzerType } from './source.js';
|
|
23
23
|
export { createSourceOptions, DEFAULT_SOURCE_OPTIONS } from './source-config.js';
|
|
24
24
|
export type { ModuleSourceOptions, SourceOptionsDefaults } from './source-config.js';
|
|
25
|
-
export { findDuplicates, mergeReExports, resolveComponentAliases } from './postprocess.js';
|
|
26
|
-
export type { DuplicateDeclaration,
|
|
25
|
+
export { findDuplicates, mergeReExports, resolveComponentAliases, resolveExportSurface, } from './postprocess.js';
|
|
26
|
+
export type { DuplicateDeclaration, ExportSurface, ExportSurfaceEntry } from './postprocess.js';
|
|
27
27
|
export { deriveIncludePatterns } from './files.js';
|
|
28
28
|
export { discoverSourceFiles } from './discovery.js';
|
|
29
29
|
export type { Discovery, DiscoverSourceFilesOptions, DiscoverSourceFilesResult, } from './discovery.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACvD,YAAY,EAAC,cAAc,EAAE,uBAAuB,EAAC,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACvE,YAAY,EAAC,qBAAqB,EAAE,YAAY,EAAE,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAC,qBAAqB,EAAC,MAAM,cAAc,CAAC;AACnD,YAAY,EACX,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,cAAc,EACd,YAAY,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,sBAAsB,EAAC,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAC,cAAc,EAAE,aAAa,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAItF,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,UAA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core.js';
|
|
|
15
15
|
export { createAnalysisSession } from './session.js';
|
|
16
16
|
export { normalizeResolveImport } from './dep-resolver.js';
|
|
17
17
|
// ── Types (Zod schemas + TypeScript interfaces) ─────────────────────────────
|
|
18
|
-
export { DeclarationKind, DeclarationModifier, MemberKind, Reactivity, GenericParamJson, ParameterJson, ComponentPropJson, OverloadJson, FunctionMemberJson, VariableMemberJson, ConstructorMemberJson, MemberJson, FunctionDeclarationJson, ClassDeclarationJson, InterfaceDeclarationJson, TypeDeclarationJson, VariableDeclarationJson, EnumDeclarationJson, ComponentDeclarationJson, SnippetDeclarationJson, NamespaceDeclarationJson, DeclarationJson, ModuleJson, } from './types.js';
|
|
18
|
+
export { DeclarationKind, DeclarationModifier, MemberKind, Reactivity, GenericParamJson, ParameterJson, ComponentPropJson, OverloadJson, FunctionMemberJson, VariableMemberJson, ConstructorMemberJson, MemberJson, FunctionDeclarationJson, ClassDeclarationJson, InterfaceDeclarationJson, TypeDeclarationJson, VariableDeclarationJson, EnumDeclarationJson, ComponentDeclarationJson, SnippetDeclarationJson, NamespaceDeclarationJson, DeclarationJson, ReExportJson, ExternalReExportJson, ModuleJson, } from './types.js';
|
|
19
19
|
// ── Declaration helpers ────────────────────────────────────────────────────
|
|
20
20
|
export { getDisplayName, generateImport, compactReplacer, isKind, findTypeReferences, buildTypeReferencePatterns, } from './declaration-helpers.js';
|
|
21
21
|
// ── Source options ──────────────────────────────────────────────────────────
|
|
22
22
|
export { createSourceOptions, DEFAULT_SOURCE_OPTIONS } from './source-config.js';
|
|
23
23
|
// ── Post-processing ────────────────────────────────────────────────────────
|
|
24
|
-
export { findDuplicates, mergeReExports, resolveComponentAliases } from './postprocess.js';
|
|
24
|
+
export { findDuplicates, mergeReExports, resolveComponentAliases, resolveExportSurface, } from './postprocess.js';
|
|
25
25
|
// ── File system constants ──────────────────────────────────────────────────
|
|
26
26
|
export { deriveIncludePatterns } from './files.js';
|
|
27
27
|
// ── File discovery ──────────────────────────────────────────────────────────
|
package/dist/postprocess.d.ts
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
import type { DeclarationJson, ModuleJson } from './types.js';
|
|
16
|
-
import type { ReExportInfo } from './declaration-build.js';
|
|
17
16
|
import type { SourceFileInfo } from './source.js';
|
|
18
17
|
/**
|
|
19
18
|
* A duplicate declaration with its full metadata and module path.
|
|
@@ -27,6 +26,14 @@ export interface DuplicateDeclaration {
|
|
|
27
26
|
/**
|
|
28
27
|
* Find duplicate declaration names across modules.
|
|
29
28
|
*
|
|
29
|
+
* A duplicate is two *different things* sharing a name in the flat namespace.
|
|
30
|
+
* Occurrences are compared by canonical identity — `aliasOf` chains are
|
|
31
|
+
* resolved first, so an alias and its canonical (or two aliases of the same
|
|
32
|
+
* canonical) are one thing, not a collision. Documenting a same-name re-export
|
|
33
|
+
* (which synthesizes an alias) or re-exporting a component under its own name
|
|
34
|
+
* (`export {default as Foo} from './Foo.svelte'`) therefore doesn't flag.
|
|
35
|
+
* When a name does flag, all occurrences are reported, aliases included.
|
|
36
|
+
*
|
|
30
37
|
* Callers can decide how to handle duplicates (throw, warn, ignore).
|
|
31
38
|
*
|
|
32
39
|
* @returns `Map` of declaration names to their `DuplicateDeclaration` occurrences (only includes duplicates)
|
|
@@ -46,59 +53,59 @@ export interface DuplicateDeclaration {
|
|
|
46
53
|
* ```
|
|
47
54
|
*/
|
|
48
55
|
export declare const findDuplicates: (modules: Array<ModuleJson>) => Map<string, Array<DuplicateDeclaration>>;
|
|
56
|
+
/**
|
|
57
|
+
* Code-unit string comparator for deterministic output ordering.
|
|
58
|
+
*
|
|
59
|
+
* Unlike `localeCompare` (host-locale/ICU-dependent, so byte-identical input
|
|
60
|
+
* can serialize in different orders on different machines), code-unit order is
|
|
61
|
+
* environment-independent — and it matches the default `Array.prototype.sort`
|
|
62
|
+
* used for `alsoExportedFrom`, `dependencies`, and `dependents`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const compareStrings: (a: string, b: string) => number;
|
|
49
65
|
/**
|
|
50
66
|
* Sort modules alphabetically by path for deterministic output and cleaner diffs.
|
|
51
67
|
*
|
|
68
|
+
* Code-unit order (`compareStrings`) so the output is environment-independent.
|
|
69
|
+
*
|
|
52
70
|
* @param modules - the modules to sort
|
|
53
71
|
* @returns a new sorted array (does not mutate input)
|
|
54
72
|
*/
|
|
55
73
|
export declare const sortModules: (modules: Array<ModuleJson>) => Array<ModuleJson>;
|
|
56
74
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* Used during the two-phase re-export resolution:
|
|
60
|
-
* 1. Phase 1: Collect re-exports from each module during analysis
|
|
61
|
-
* 2. Phase 2: Group by original module and merge into `alsoExportedFrom`
|
|
62
|
-
*/
|
|
63
|
-
export interface ReExportEntry {
|
|
64
|
-
/** The module that re-exports the declaration. */
|
|
65
|
-
reExportingModule: string;
|
|
66
|
-
/** The re-export info (name and original module). */
|
|
67
|
-
reExport: ReExportInfo;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Build `alsoExportedFrom` arrays from collected re-export data.
|
|
71
|
-
*
|
|
72
|
-
* This function resolves the two-phase re-export problem:
|
|
75
|
+
* Build `alsoExportedFrom` arrays from the modules' forward re-export edges.
|
|
73
76
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* Each module carries its same-name re-export edges as `ModuleJson.reExports`
|
|
78
|
+
* (collected in phase 1); this phase-2 pass inverts them onto the canonical
|
|
79
|
+
* declarations so both directions of the same fact are queryable. Edges whose
|
|
80
|
+
* canonical module or declaration is absent from `modules` are skipped — the
|
|
81
|
+
* forward entry remains without a back-link (see `ReExportJson` for the
|
|
82
|
+
* presence caveats).
|
|
80
83
|
*
|
|
81
84
|
* Component-only fields on renamed component aliases (`props`,
|
|
82
85
|
* `acceptsChildren`, etc.) are populated separately by `resolveComponentAliases`
|
|
83
86
|
* — call it after this function. They split because they touch disjoint fields
|
|
84
87
|
* and have different inputs.
|
|
85
88
|
*
|
|
86
|
-
* @param modules - the modules array with all modules (will be mutated)
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
+
* @param modules - the modules array with all modules (will be mutated).
|
|
90
|
+
* Must be parsed `ModuleJson`s — wire JSON strips empty arrays, so run
|
|
91
|
+
* raw JSON through `AnalyzeResultJson.parse` first or `reExports` may be
|
|
92
|
+
* `undefined`
|
|
93
|
+
* @mutates modules - unions re-exporters into `declaration.alsoExportedFrom`
|
|
89
94
|
* (deduped + sorted), so a second call with the same inputs is a no-op
|
|
90
95
|
*
|
|
91
96
|
* @example
|
|
92
97
|
* ```ts
|
|
93
98
|
* // helpers.ts exports: foo, bar
|
|
94
|
-
* // index.ts does: export {foo, bar} from './
|
|
99
|
+
* // index.ts does: export {foo, bar} from './helpers.js'
|
|
100
|
+
* // (so index.ts's ModuleJson carries reExports:
|
|
101
|
+
* // [{name: 'foo', module: 'helpers.ts'}, {name: 'bar', module: 'helpers.ts'}])
|
|
95
102
|
* //
|
|
96
103
|
* // After processing:
|
|
97
104
|
* // - helpers.ts foo declaration gets: alsoExportedFrom: ['index.ts']
|
|
98
105
|
* // - helpers.ts bar declaration gets: alsoExportedFrom: ['index.ts']
|
|
99
106
|
* ```
|
|
100
107
|
*/
|
|
101
|
-
export declare const mergeReExports: (modules: Array<ModuleJson
|
|
108
|
+
export declare const mergeReExports: (modules: Array<ModuleJson>) => void;
|
|
102
109
|
/**
|
|
103
110
|
* Copy props/acceptsChildren/lang/etc. from canonical component declarations
|
|
104
111
|
* onto synthesized component-aliased declarations.
|
|
@@ -142,4 +149,87 @@ export declare const resolveComponentAliases: (modules: Array<ModuleJson>) => vo
|
|
|
142
149
|
export declare const computeDependents: (files: ReadonlyArray<SourceFileInfo>) => Array<SourceFileInfo & {
|
|
143
150
|
dependents?: ReadonlyArray<string>;
|
|
144
151
|
}>;
|
|
152
|
+
/**
|
|
153
|
+
* One name on a module's resolved export surface.
|
|
154
|
+
*/
|
|
155
|
+
export interface ExportSurfaceEntry {
|
|
156
|
+
/**
|
|
157
|
+
* Exported name, in the docinfo model's terms — Svelte components appear
|
|
158
|
+
* under their filename-derived name (the model's convention for default
|
|
159
|
+
* exports of `.svelte` files), not `'default'`.
|
|
160
|
+
*/
|
|
161
|
+
name: string;
|
|
162
|
+
/**
|
|
163
|
+
* How the name reaches this module's surface: an own declaration
|
|
164
|
+
* (including synthesized aliases), a same-name re-export edge, a direct
|
|
165
|
+
* external re-export, or projection through `export * from './x'`.
|
|
166
|
+
*/
|
|
167
|
+
via: 'declaration' | 'reExport' | 'external' | 'star';
|
|
168
|
+
/** Canonical module path, when known (`undefined` for external entries). */
|
|
169
|
+
module?: string;
|
|
170
|
+
/** The canonical declaration, when present in the analyzed set. */
|
|
171
|
+
declaration?: DeclarationJson;
|
|
172
|
+
/** Package specifier for external entries (as written in the statement). */
|
|
173
|
+
specifier?: string;
|
|
174
|
+
/** Name inside the external package when renamed. */
|
|
175
|
+
originalName?: string;
|
|
176
|
+
/** Type-only re-export — the name is erased at runtime. */
|
|
177
|
+
typeOnly?: boolean;
|
|
178
|
+
/** For star-projected entries: the `starExports` target the name arrived through. */
|
|
179
|
+
starFrom?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A module's resolved export surface — see `resolveExportSurface`.
|
|
183
|
+
*/
|
|
184
|
+
export interface ExportSurface {
|
|
185
|
+
/** Surface entries, sorted by `name` (code-unit order). */
|
|
186
|
+
entries: Array<ExportSurfaceEntry>;
|
|
187
|
+
/**
|
|
188
|
+
* Star targets (own or transitive) absent from the analyzed set — their
|
|
189
|
+
* projected names are unknown, so the surface is incomplete.
|
|
190
|
+
*/
|
|
191
|
+
unresolvedStarExports: Array<string>;
|
|
192
|
+
/**
|
|
193
|
+
* External star specifiers reachable from this module (own or transitive)
|
|
194
|
+
* — their projected names are unknowable without analyzing the package.
|
|
195
|
+
*/
|
|
196
|
+
externalStarExports: Array<string>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Resolve a module's full export surface from the analyzed model, applying
|
|
200
|
+
* ES module semantics to star exports.
|
|
201
|
+
*
|
|
202
|
+
* Combines the module's own `declarations` (including synthesized aliases),
|
|
203
|
+
* `reExports` edges, `externalReExports`, and transitively-resolved
|
|
204
|
+
* `starExports` into one deduped, name-sorted list. The ES rules applied to
|
|
205
|
+
* star projection:
|
|
206
|
+
*
|
|
207
|
+
* - explicit exports (declarations, edges, externals) shadow star-projected
|
|
208
|
+
* names
|
|
209
|
+
* - a name projected by two stars that resolve to *different* canonicals is
|
|
210
|
+
* ambiguous and excluded (same canonical through a diamond is included
|
|
211
|
+
* once)
|
|
212
|
+
* - `default` is never star-projected — including canonical Svelte component
|
|
213
|
+
* declarations, which represent their file's default export. (Caveat: a
|
|
214
|
+
* star-projected re-export edge whose canonical is a component is treated
|
|
215
|
+
* as a default-slot re-export and skipped; a `<script module>` const
|
|
216
|
+
* sharing the component's exact name would be skipped with it.)
|
|
217
|
+
*
|
|
218
|
+
* A Position-3 alias and its `reExports` edge are the same fact — the
|
|
219
|
+
* declaration entry wins, inheriting the edge's `typeOnly`.
|
|
220
|
+
*
|
|
221
|
+
* Cyclic star graphs terminate by contributing nothing along the back-edge
|
|
222
|
+
* (an approximation of ES fixpoint resolution — fine in practice). Surfaces
|
|
223
|
+
* resolved inside a cycle are path-relative and not memoized, so sibling
|
|
224
|
+
* star paths resolve independently rather than inheriting them. Star
|
|
225
|
+
* targets missing from `modules` are reported in `unresolvedStarExports`
|
|
226
|
+
* rather than guessed at; `externalStarExports` aggregates external star
|
|
227
|
+
* specifiers reachable from the module, whose names are unknowable.
|
|
228
|
+
*
|
|
229
|
+
* @param modules - the analyzed modules (parsed `ModuleJson`s — run wire
|
|
230
|
+
* JSON through `AnalyzeResultJson.parse` first)
|
|
231
|
+
* @param path - the module to resolve, as a `ModuleJson.path` value
|
|
232
|
+
* @returns the resolved surface, or `null` when `path` isn't in `modules`
|
|
233
|
+
*/
|
|
234
|
+
export declare const resolveExportSurface: (modules: Array<ModuleJson>, path: string) => ExportSurface | null;
|
|
145
235
|
//# sourceMappingURL=postprocess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postprocess.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/postprocess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAA2B,eAAe,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;AACtF,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"postprocess.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/postprocess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAA2B,eAAe,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;AACtF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,aAAa,CAAC;AAuBhD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,qCAAqC;IACrC,WAAW,EAAE,eAAe,CAAC;IAC7B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;CACf;AA6CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,cAAc,GAC1B,SAAS,KAAK,CAAC,UAAU,CAAC,KACxB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAwCzC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAAsC,CAAC;AAE7F;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,KAAK,CAAC,UAAU,CAAC,KAAG,KAAK,CAAC,UAAU,CAExE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,KAAK,CAAC,UAAU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