@outfitter/tooling 0.3.0 → 0.3.4

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.
Files changed (53) hide show
  1. package/.markdownlint-cli2.jsonc +55 -55
  2. package/README.md +21 -21
  3. package/dist/bun-version-compat.d.ts +2 -0
  4. package/dist/bun-version-compat.js +10 -0
  5. package/dist/cli/check-boundary-invocations.js +2 -2
  6. package/dist/cli/check-bunup-registry.js +2 -2
  7. package/dist/cli/check-changeset.js +2 -2
  8. package/dist/cli/check-clean-tree.js +2 -2
  9. package/dist/cli/check-exports.js +2 -2
  10. package/dist/cli/check-markdown-links.d.ts +42 -0
  11. package/dist/cli/check-markdown-links.js +13 -0
  12. package/dist/cli/check-readme-imports.d.ts +2 -3
  13. package/dist/cli/check-readme-imports.js +4 -4
  14. package/dist/cli/check-tsdoc.js +2 -2
  15. package/dist/cli/check.js +2 -2
  16. package/dist/cli/fix.js +2 -2
  17. package/dist/cli/index.js +49 -1221
  18. package/dist/cli/init.js +2 -2
  19. package/dist/cli/pre-push.d.ts +13 -1
  20. package/dist/cli/pre-push.js +5 -3
  21. package/dist/cli/upgrade-bun.js +3 -2
  22. package/dist/index.d.ts +6 -186
  23. package/dist/index.js +4 -42
  24. package/dist/registry/build.d.ts +1 -3
  25. package/dist/registry/build.js +187 -58
  26. package/dist/registry/index.js +1 -13
  27. package/dist/registry/schema.js +22 -6
  28. package/dist/shared/@outfitter/{tooling-9errkcvk.js → tooling-1hez6j9d.js} +1 -1
  29. package/dist/shared/@outfitter/{tooling-cj5vsa9k.js → tooling-6cxfdx0q.js} +21 -18
  30. package/dist/shared/@outfitter/{tooling-qk5xgmxr.js → tooling-875svjnz.js} +5 -4
  31. package/dist/shared/@outfitter/{tooling-mxwc1n8w.js → tooling-9ram55dd.js} +4 -3
  32. package/dist/shared/@outfitter/{tooling-0x5q15ec.js → tooling-a4bfx4be.js} +1 -1
  33. package/dist/shared/@outfitter/{tooling-r9976n43.js → tooling-amrbp7cm.js} +6 -4
  34. package/dist/shared/@outfitter/{tooling-2n2dpsaa.js → tooling-d363b88r.js} +38 -12
  35. package/dist/shared/@outfitter/{tooling-1y8w5ahg.js → tooling-gcdvsqqp.js} +7 -4
  36. package/dist/shared/@outfitter/{tooling-enjcenja.js → tooling-h04te11c.js} +6 -4
  37. package/dist/shared/@outfitter/tooling-ja1zg5yc.js +214 -0
  38. package/dist/shared/@outfitter/tooling-mkynjra9.js +23 -0
  39. package/dist/shared/@outfitter/{tooling-9yzd08v1.js → tooling-pq47jv6t.js} +72 -5
  40. package/dist/shared/@outfitter/tooling-vjmhvpjq.d.ts +29 -0
  41. package/dist/shared/@outfitter/{tooling-t17gnh9b.js → tooling-wwm97f47.js} +8 -5
  42. package/dist/version.js +1 -1
  43. package/package.json +134 -130
  44. package/registry/registry.json +18 -11
  45. package/tsconfig.preset.bun.json +5 -5
  46. package/tsconfig.preset.json +33 -33
  47. package/biome.json +0 -81
  48. package/dist/shared/@outfitter/tooling-kcvs6mys.js +0 -1
  49. package/dist/shared/@outfitter/tooling-wv09k6hr.js +0 -23
  50. package/dist/shared/chunk-3s189drz.js +0 -4
  51. package/dist/shared/chunk-7tdgbqb0.js +0 -197
  52. package/dist/shared/chunk-cmde0fwx.js +0 -421
  53. /package/dist/shared/@outfitter/{tooling-dvwh9qve.js → tooling-jnrs9rqd.js} +0 -0
@@ -1,421 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-3s189drz.js";
4
-
5
- // src/cli/check-tsdoc.ts
6
- import { resolve } from "node:path";
7
- import ts from "typescript";
8
- import { z } from "zod";
9
- var coverageLevelSchema = z.enum([
10
- "documented",
11
- "partial",
12
- "undocumented"
13
- ]);
14
- var declarationCoverageSchema = z.object({
15
- name: z.string(),
16
- kind: z.string(),
17
- level: coverageLevelSchema,
18
- file: z.string(),
19
- line: z.number()
20
- });
21
- var coverageSummarySchema = z.object({
22
- documented: z.number(),
23
- partial: z.number(),
24
- undocumented: z.number(),
25
- total: z.number(),
26
- percentage: z.number()
27
- });
28
- var packageCoverageSchema = z.object({
29
- name: z.string(),
30
- path: z.string(),
31
- declarations: z.array(declarationCoverageSchema),
32
- documented: z.number(),
33
- partial: z.number(),
34
- undocumented: z.number(),
35
- total: z.number(),
36
- percentage: z.number()
37
- });
38
- var tsDocCheckResultSchema = z.object({
39
- ok: z.boolean(),
40
- packages: z.array(packageCoverageSchema),
41
- summary: coverageSummarySchema
42
- });
43
- function isExportedDeclaration(node) {
44
- if (ts.isExportDeclaration(node))
45
- return false;
46
- if (ts.isExportAssignment(node))
47
- return false;
48
- const isDeclaration = ts.isFunctionDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node) || ts.isVariableStatement(node);
49
- if (!isDeclaration)
50
- return false;
51
- const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
52
- if (!modifiers)
53
- return false;
54
- return modifiers.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword);
55
- }
56
- function getDeclarationName(node) {
57
- if (ts.isVariableStatement(node)) {
58
- const decl = node.declarationList.declarations[0];
59
- if (decl && ts.isIdentifier(decl.name)) {
60
- return decl.name.text;
61
- }
62
- return;
63
- }
64
- if (ts.isFunctionDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node)) {
65
- return node.name?.text;
66
- }
67
- return;
68
- }
69
- function getDeclarationKind(node) {
70
- if (ts.isFunctionDeclaration(node))
71
- return "function";
72
- if (ts.isInterfaceDeclaration(node))
73
- return "interface";
74
- if (ts.isTypeAliasDeclaration(node))
75
- return "type";
76
- if (ts.isClassDeclaration(node))
77
- return "class";
78
- if (ts.isEnumDeclaration(node))
79
- return "enum";
80
- if (ts.isVariableStatement(node))
81
- return "variable";
82
- return "unknown";
83
- }
84
- function hasJSDocComment(node, sourceFile) {
85
- const sourceText = sourceFile.getFullText();
86
- const ranges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
87
- if (!ranges)
88
- return false;
89
- return ranges.some((range) => {
90
- if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia)
91
- return false;
92
- const text = sourceText.slice(range.pos, range.end);
93
- return text.startsWith("/**");
94
- });
95
- }
96
- function memberHasJSDoc(member, sourceFile) {
97
- const sourceText = sourceFile.getFullText();
98
- const ranges = ts.getLeadingCommentRanges(sourceText, member.getFullStart());
99
- if (!ranges)
100
- return false;
101
- return ranges.some((range) => {
102
- if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia)
103
- return false;
104
- const text = sourceText.slice(range.pos, range.end);
105
- return text.startsWith("/**");
106
- });
107
- }
108
- function classifyDeclaration(node, sourceFile) {
109
- const hasDoc = hasJSDocComment(node, sourceFile);
110
- if (!hasDoc)
111
- return "undocumented";
112
- if (ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) {
113
- const members = node.members;
114
- if (members.length > 0) {
115
- const allMembersDocumented = members.every((member) => memberHasJSDoc(member, sourceFile));
116
- if (!allMembersDocumented)
117
- return "partial";
118
- }
119
- }
120
- return "documented";
121
- }
122
- function analyzeSourceFile(sourceFile) {
123
- const results = [];
124
- for (const statement of sourceFile.statements) {
125
- if (!isExportedDeclaration(statement))
126
- continue;
127
- const name = getDeclarationName(statement);
128
- if (!name)
129
- continue;
130
- const kind = getDeclarationKind(statement);
131
- const level = classifyDeclaration(statement, sourceFile);
132
- const { line } = sourceFile.getLineAndCharacterOfPosition(statement.getStart(sourceFile));
133
- results.push({
134
- name,
135
- kind,
136
- level,
137
- file: sourceFile.fileName,
138
- line: line + 1
139
- });
140
- }
141
- return results;
142
- }
143
- function calculateCoverage(declarations) {
144
- const total = declarations.length;
145
- if (total === 0) {
146
- return {
147
- documented: 0,
148
- partial: 0,
149
- undocumented: 0,
150
- total: 0,
151
- percentage: 100
152
- };
153
- }
154
- const documented = declarations.filter((d) => d.level === "documented").length;
155
- const partial = declarations.filter((d) => d.level === "partial").length;
156
- const undocumented = declarations.filter((d) => d.level === "undocumented").length;
157
- const score = documented + partial * 0.5;
158
- const percentage = Math.round(score / total * 100);
159
- return { documented, partial, undocumented, total, percentage };
160
- }
161
- var COLORS = {
162
- reset: "\x1B[0m",
163
- red: "\x1B[31m",
164
- green: "\x1B[32m",
165
- yellow: "\x1B[33m",
166
- blue: "\x1B[34m",
167
- dim: "\x1B[2m",
168
- bold: "\x1B[1m"
169
- };
170
- function resolveJsonMode(options = {}) {
171
- return options.json ?? process.env["OUTFITTER_JSON"] === "1";
172
- }
173
- function bar(percentage, width = 20) {
174
- const filled = Math.round(percentage / 100 * width);
175
- const empty = width - filled;
176
- const color = percentage >= 80 ? COLORS.green : percentage >= 50 ? COLORS.yellow : COLORS.red;
177
- return `${color}${"█".repeat(filled)}${COLORS.dim}${"░".repeat(empty)}${COLORS.reset}`;
178
- }
179
- function discoverPackages(cwd) {
180
- const packages = [];
181
- const seenEntryPoints = new Set;
182
- for (const pattern of ["packages/*/src/index.ts", "apps/*/src/index.ts"]) {
183
- const glob = new Bun.Glob(pattern);
184
- for (const match of glob.scanSync({ cwd, dot: false })) {
185
- const parts = match.split("/");
186
- const rootDir = parts[0];
187
- const pkgDir = parts[1];
188
- if (!rootDir || !pkgDir)
189
- continue;
190
- const entryPoint = resolve(cwd, match);
191
- if (seenEntryPoints.has(entryPoint)) {
192
- continue;
193
- }
194
- seenEntryPoints.add(entryPoint);
195
- const pkgRoot = resolve(cwd, rootDir, pkgDir);
196
- let pkgName = pkgDir;
197
- try {
198
- const pkgJson = JSON.parse(__require("node:fs").readFileSync(resolve(pkgRoot, "package.json"), "utf-8"));
199
- if (pkgJson.name)
200
- pkgName = pkgJson.name;
201
- } catch {}
202
- packages.push({
203
- name: pkgName,
204
- path: pkgRoot,
205
- entryPoint
206
- });
207
- }
208
- }
209
- if (packages.length === 0) {
210
- const entryPoint = resolve(cwd, "src/index.ts");
211
- try {
212
- __require("node:fs").accessSync(entryPoint);
213
- let pkgName = "root";
214
- try {
215
- const pkgJson = JSON.parse(__require("node:fs").readFileSync(resolve(cwd, "package.json"), "utf-8"));
216
- if (pkgJson.name)
217
- pkgName = pkgJson.name;
218
- } catch {}
219
- packages.push({
220
- name: pkgName,
221
- path: cwd,
222
- entryPoint
223
- });
224
- seenEntryPoints.add(entryPoint);
225
- } catch {}
226
- }
227
- return packages.sort((a, b) => a.name.localeCompare(b.name));
228
- }
229
- function collectReExportedSourceFiles(sourceFile, program, pkgPath) {
230
- const result = [];
231
- const seen = new Set;
232
- for (const statement of sourceFile.statements) {
233
- if (!ts.isExportDeclaration(statement))
234
- continue;
235
- if (!statement.moduleSpecifier)
236
- continue;
237
- if (!ts.isStringLiteral(statement.moduleSpecifier))
238
- continue;
239
- const specifier = statement.moduleSpecifier.text;
240
- if (!specifier.startsWith("."))
241
- continue;
242
- const resolvedModule = ts.resolveModuleName(specifier, sourceFile.fileName, program.getCompilerOptions(), ts.sys);
243
- const resolvedFileName = resolvedModule.resolvedModule?.resolvedFileName;
244
- if (!resolvedFileName)
245
- continue;
246
- if (!resolvedFileName.startsWith(pkgPath))
247
- continue;
248
- if (seen.has(resolvedFileName))
249
- continue;
250
- seen.add(resolvedFileName);
251
- const sf = program.getSourceFile(resolvedFileName);
252
- if (sf)
253
- result.push(sf);
254
- }
255
- return result;
256
- }
257
- function analyzePackage(pkg, workspaceCwd) {
258
- try {
259
- __require("node:fs").accessSync(pkg.entryPoint);
260
- } catch {
261
- return {
262
- name: pkg.name,
263
- path: pkg.path,
264
- declarations: [],
265
- documented: 0,
266
- partial: 0,
267
- undocumented: 0,
268
- total: 0,
269
- percentage: 0
270
- };
271
- }
272
- let tsconfigPath = resolve(pkg.path, "tsconfig.json");
273
- try {
274
- __require("node:fs").accessSync(tsconfigPath);
275
- } catch {
276
- tsconfigPath = resolve(workspaceCwd, "tsconfig.json");
277
- }
278
- const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
279
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, pkg.path);
280
- const program = ts.createProgram({
281
- rootNames: [pkg.entryPoint],
282
- options: parsedConfig.options,
283
- host: ts.createCompilerHost(parsedConfig.options)
284
- });
285
- const sourceFile = program.getSourceFile(pkg.entryPoint);
286
- if (!sourceFile) {
287
- return {
288
- name: pkg.name,
289
- path: pkg.path,
290
- declarations: [],
291
- documented: 0,
292
- partial: 0,
293
- undocumented: 0,
294
- total: 0,
295
- percentage: 0
296
- };
297
- }
298
- const declarations = analyzeSourceFile(sourceFile);
299
- const reExportedFiles = collectReExportedSourceFiles(sourceFile, program, pkg.path);
300
- for (const sf of reExportedFiles) {
301
- declarations.push(...analyzeSourceFile(sf));
302
- }
303
- const stats = calculateCoverage(declarations);
304
- return {
305
- name: pkg.name,
306
- path: pkg.path,
307
- declarations,
308
- ...stats
309
- };
310
- }
311
- function analyzeCheckTsdoc(options = {}) {
312
- const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
313
- const minCoverage = options.minCoverage ?? 0;
314
- let packages;
315
- if (options.paths && options.paths.length > 0) {
316
- packages = options.paths.map((p) => {
317
- const absPath = resolve(cwd, p);
318
- const entryPoint = resolve(absPath, "src/index.ts");
319
- let name = p;
320
- try {
321
- const pkgJson = JSON.parse(__require("node:fs").readFileSync(resolve(absPath, "package.json"), "utf-8"));
322
- if (pkgJson.name)
323
- name = pkgJson.name;
324
- } catch {}
325
- return { name, path: absPath, entryPoint };
326
- });
327
- } else {
328
- packages = discoverPackages(cwd);
329
- }
330
- if (packages.length === 0) {
331
- return null;
332
- }
333
- const packageResults = [];
334
- for (const pkg of packages) {
335
- packageResults.push(analyzePackage(pkg, cwd));
336
- }
337
- const allDeclarations = packageResults.flatMap((p) => p.declarations);
338
- const summary = calculateCoverage(allDeclarations);
339
- const ok = !options.strict || summary.percentage >= minCoverage;
340
- return {
341
- ok,
342
- packages: packageResults,
343
- summary
344
- };
345
- }
346
- function printCheckTsdocHuman(result, options) {
347
- process.stdout.write(`
348
- ${COLORS.bold}TSDoc Coverage Report${COLORS.reset}
349
-
350
- `);
351
- for (const pkg of result.packages) {
352
- const color = pkg.percentage >= 80 ? COLORS.green : pkg.percentage >= 50 ? COLORS.yellow : COLORS.red;
353
- process.stdout.write(` ${color}${pkg.percentage.toString().padStart(3)}%${COLORS.reset} ${bar(pkg.percentage)} ${pkg.name}
354
- `);
355
- if (pkg.total > 0) {
356
- const parts = [];
357
- if (pkg.documented > 0)
358
- parts.push(`${COLORS.green}${pkg.documented} documented${COLORS.reset}`);
359
- if (pkg.partial > 0)
360
- parts.push(`${COLORS.yellow}${pkg.partial} partial${COLORS.reset}`);
361
- if (pkg.undocumented > 0)
362
- parts.push(`${COLORS.red}${pkg.undocumented} undocumented${COLORS.reset}`);
363
- process.stdout.write(` ${COLORS.dim}${pkg.total} declarations:${COLORS.reset} ${parts.join(", ")}
364
- `);
365
- } else {
366
- process.stdout.write(` ${COLORS.dim}no exported declarations${COLORS.reset}
367
- `);
368
- }
369
- }
370
- const { summary } = result;
371
- process.stdout.write(`
372
- ${COLORS.bold}Summary:${COLORS.reset} ${summary.percentage}% coverage (${summary.documented} documented, ${summary.partial} partial, ${summary.undocumented} undocumented of ${summary.total} total)
373
- `);
374
- const minCoverage = options?.minCoverage ?? 0;
375
- if (options?.strict && summary.percentage < minCoverage) {
376
- process.stderr.write(`
377
- ${COLORS.red}Coverage ${summary.percentage}% is below minimum threshold of ${minCoverage}%${COLORS.reset}
378
- `);
379
- }
380
- process.stdout.write(`
381
- `);
382
- }
383
- async function runCheckTsdoc(options = {}) {
384
- const result = analyzeCheckTsdoc(options);
385
- if (!result) {
386
- process.stderr.write(`No packages found with src/index.ts entry points.
387
- ` + `Searched: packages/*/src/index.ts, apps/*/src/index.ts, src/index.ts
388
- ` + `Use --package <path> to specify a package path explicitly.
389
- `);
390
- process.exit(1);
391
- }
392
- if (resolveJsonMode(options)) {
393
- process.stdout.write(`${JSON.stringify(result, null, 2)}
394
- `);
395
- } else {
396
- printCheckTsdocHuman(result, {
397
- strict: options.strict,
398
- minCoverage: options.minCoverage
399
- });
400
- }
401
- process.exit(result.ok ? 0 : 1);
402
- }
403
-
404
- // src/version.ts
405
- import { readFileSync } from "node:fs";
406
- import { createRequire } from "node:module";
407
- var DEFAULT_VERSION = "0.0.0";
408
- function readPackageVersion() {
409
- try {
410
- const require2 = createRequire(import.meta.url);
411
- const pkgPath = require2.resolve("@outfitter/tooling/package.json");
412
- const packageJson = JSON.parse(readFileSync(pkgPath, "utf8"));
413
- if (typeof packageJson.version === "string" && packageJson.version.length > 0) {
414
- return packageJson.version;
415
- }
416
- } catch {}
417
- return DEFAULT_VERSION;
418
- }
419
- var VERSION = readPackageVersion();
420
-
421
- export { coverageLevelSchema, declarationCoverageSchema, packageCoverageSchema, tsDocCheckResultSchema, analyzeSourceFile, calculateCoverage, analyzeCheckTsdoc, printCheckTsdocHuman, runCheckTsdoc, VERSION };