docspack 0.3.0 → 0.4.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/dist/build.d.ts.map +1 -1
- package/dist/build.js +58 -9
- package/dist/build.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +46 -3
- package/dist/doctor.js.map +1 -1
- package/dist/document.d.ts +2 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +7 -3
- package/dist/document.js.map +1 -1
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -2
- package/dist/search.js.map +1 -1
- package/dist/spec.d.ts +6 -0
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +12 -3
- package/dist/spec.js.map +1 -1
- package/dist/verify.js +54 -26
- package/dist/verify.js.map +1 -1
- package/package.json +1 -1
- package/src/build.ts +84 -10
- package/src/doctor.ts +48 -4
- package/src/document.ts +13 -4
- package/src/search.ts +12 -4
- package/src/spec.ts +21 -3
- package/src/verify.ts +56 -26
package/src/verify.ts
CHANGED
|
@@ -196,8 +196,12 @@ async function verifyPackage(
|
|
|
196
196
|
): Promise<VerifiedPackage> {
|
|
197
197
|
const empty = { id, checked: 0, matched: 0, unrecognised: 0, findings: [] };
|
|
198
198
|
|
|
199
|
-
const
|
|
200
|
-
|
|
199
|
+
const packageLibraries = await documentedLibraries(packageDir, manifest);
|
|
200
|
+
// A chunk may name its own libraries, which is how a monorepo says that one chunk describes
|
|
201
|
+
// `@acme/api@1.2.0` and its neighbour describes `@acme/cli@3.0.0`. Those are what that chunk
|
|
202
|
+
// is checked against; the package's list covers every chunk that names none.
|
|
203
|
+
const scopes = manifest.chunks.map((chunk) => chunk.documents ?? packageLibraries);
|
|
204
|
+
if (packageLibraries.length === 0 && scopes.every((scope) => scope.length === 0)) {
|
|
201
205
|
return {
|
|
202
206
|
...empty,
|
|
203
207
|
status: "skipped",
|
|
@@ -205,39 +209,52 @@ async function verifyPackage(
|
|
|
205
209
|
};
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
const documents =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
const documents = [
|
|
213
|
+
...new Set([...packageLibraries, ...scopes.flat()].map(formatDocumentedLibrary)),
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
// One resolution per library, however many chunks name it: reading a type surface is the
|
|
217
|
+
// expensive part, and a monorepo pack names the same eighteen libraries throughout.
|
|
218
|
+
const surfaces = new Map<string, ReadonlySet<string>>();
|
|
219
|
+
const resolve = async (library: DocumentedLibrary): Promise<ReadonlySet<string>> => {
|
|
220
|
+
const cached = surfaces.get(library.name);
|
|
221
|
+
if (cached !== undefined) return cached;
|
|
222
|
+
|
|
214
223
|
const libraryDir =
|
|
215
224
|
(await resolvePackageDir(library.name, packageDir)) ??
|
|
216
225
|
(await resolvePackageDir(library.name, cwd));
|
|
217
226
|
const surface = libraryDir === undefined ? undefined : await readExportSurface(libraryDir);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
for (const name of surface.names) names.add(name);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (names.size === 0) {
|
|
226
|
-
return {
|
|
227
|
-
...empty,
|
|
228
|
-
status: "skipped",
|
|
229
|
-
documents,
|
|
230
|
-
reason: `${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not installed, or ship no type declarations`,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
227
|
+
const names = surface?.names ?? new Set<string>();
|
|
228
|
+
surfaces.set(library.name, names);
|
|
229
|
+
return names;
|
|
230
|
+
};
|
|
233
231
|
|
|
234
|
-
const declared = new Set([...names].map(normalize));
|
|
235
232
|
const findings: DriftFinding[] = [];
|
|
233
|
+
const missing = new Set<string>();
|
|
236
234
|
let checked = 0;
|
|
237
235
|
let matched = 0;
|
|
238
236
|
let unrecognised = 0;
|
|
237
|
+
let readAny = false;
|
|
238
|
+
|
|
239
|
+
for (const [index, chunk] of manifest.chunks.entries()) {
|
|
240
|
+
const scope = scopes[index] ?? packageLibraries;
|
|
241
|
+
if (scope.length === 0) continue;
|
|
242
|
+
|
|
243
|
+
// An entity is fine if any library in scope declares it: a monorepo documents eighteen
|
|
244
|
+
// packages from one surface, and a name belongs to whichever of them exports it.
|
|
245
|
+
const names = new Set<string>();
|
|
246
|
+
for (const library of scope) {
|
|
247
|
+
const surface = await resolve(library);
|
|
248
|
+
if (surface.size === 0) {
|
|
249
|
+
missing.add(library.name);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const name of surface) names.add(name);
|
|
253
|
+
}
|
|
254
|
+
if (names.size === 0) continue;
|
|
255
|
+
readAny = true;
|
|
239
256
|
|
|
240
|
-
|
|
257
|
+
const declared = new Set([...names].map(normalize));
|
|
241
258
|
for (const entity of chunk.entities) {
|
|
242
259
|
const symbol = checkableSymbol(entity);
|
|
243
260
|
if (symbol === undefined) continue;
|
|
@@ -266,11 +283,24 @@ async function verifyPackage(
|
|
|
266
283
|
}
|
|
267
284
|
}
|
|
268
285
|
|
|
286
|
+
if (!readAny) {
|
|
287
|
+
const unread = [...missing];
|
|
288
|
+
return {
|
|
289
|
+
...empty,
|
|
290
|
+
status: "skipped",
|
|
291
|
+
documents,
|
|
292
|
+
reason:
|
|
293
|
+
unread.length === 0
|
|
294
|
+
? "has no chunk naming a library to check against"
|
|
295
|
+
: `${unread.join(", ")} ${unread.length === 1 ? "is" : "are"} not installed, or ship no type declarations`,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
269
299
|
return {
|
|
270
300
|
id,
|
|
271
301
|
status: "verified",
|
|
272
302
|
documents,
|
|
273
|
-
...(missing.
|
|
303
|
+
...(missing.size === 0 ? {} : { unchecked: [...missing] }),
|
|
274
304
|
checked,
|
|
275
305
|
matched,
|
|
276
306
|
unrecognised,
|