Automatic analysis of libraries by default: report everything found, with its kind #52
Loading…
Reference in a new issue
No description provided.
Delete branch "evobug/auto-library-knowledge"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Automatic analysis of libraries is now the default way SAFE-TS knows what library calls throw or reject. Every package the program imports (resolving into
node_modules, listed in package.json or not) is analyzed from its JavaScript once per installed version, and everything found is reported, with its kind in the message:"infer": "all"(default),"real"(everything except argument checks),"documented"(the old behaviour: found and@throws),false.{ "level": "real", "exclude": [...] }combines both. Anything else warns.typeof,instanceof,=== undefined, comparisons,.length,Array.isArray,Number.isInteger, ...). A guard that calls something on the argument (isValid(date),re.test(s)) is validation, not an argument check. Through calls: still an argument check when the caller passes its own arguments,builtinwhen it passes a value it computed, dropped when it passes only constants.parse = _parse(ZodRealError)→ZodError),export */export * as ns, re-exports from and calls into other packages (vue → runtime-dom → runtime-core), CommonJS members and compiledObject.defineProperty(exports, ...), prototype methods, bundlers' class expressions, exported instances. Two precision fixes: closures stored for later no longer count as running in their creator, andcatch (e) { throw e }passes the try block's own failures through.new WebSocket(url).send()); on a value returned by a call (z.string().min(1).parse()) by name, only when every method of that name in the package fails. What it can't follow is counted bysafe-ts infer, never guessed.node_modules. Workspace packages that resolve to project source are project code (as in the project pass) and aren't analyzed.node_modules/.cache/safe-ts/(orSAFE_TS_CACHE_DIR;SAFE_TS_CACHE=0off). Key holds the analyzer version; an entry is re-analyzed when a dependency it followed into changes version; a package linked from outsidenode_modulesis also keyed by a fingerprint of its files (sizes, mtimes)."complete": trueon a module entry: automatic mode adds nothing for its specifiers. The zod pack sets it, so with the zod pack nothing changes for zod.safe-ts infer/coverageshow the kinds;infernames methodsClass#method, takes subpaths, lists followed packages, counts data exports apart.Why
Before, a failure was only reported when it was both found and documented with
@throws, so automatic mode found nothing for most packages (zod, ws, pixi.js, vue).This changes what existing projects see. CHANGELOG lists it under Changed, with the way back (
"infer": "documented").Measurements (functions/methods analyzed; failures by kind c/i/b/d/arg; exports not analyzable)
corenamespace, schema methods); 43/0/29/0/290; 22axios.getetc. are made in a loop: not guessed)pixi.js's 4 lost "contract" items were getters/setters, which aren't calls.
parse,parseAsync,schema.parse()found (ZodError, contract); schema builders (z.object,z.string,z.email, ...) are argument checks.safeParsereports$ZodAsyncError(sync parse of an async schema), real but noisy; the zod pack (complete) hides it.WebSocket#send/ping/pong→Error,WebSocketServer#handleUpgrade→Error(builtin). On the same program, the RTSS pack itself only catcheshandleUpgradewithimport WebSocket from "ws": it lacks"default": "WebSocket".checkof a file calling into pixi.js takes ~140 ms (65 ms reading pixi's 737 files), then ~25 ms from the cache. All 8 scratch packages cold: ~330 ms, warm: ~22 ms.app.init()(pixi.js, builtin), which rejects when no renderer is available.Verification
cargo nextest run --workspace: 187 passed. New fixture packages intests/infer/node_modules(factories, namespaces, a dependency, argument checks, stored closures, rethrows, CommonJS prototypes, class expressions, data exports), level fixturesauto/real,auto/documented. Theautofixture now imports its config subdirectories: before,off/andexcluded/were never checked.cargo clippy -q --workspace --all-targets: nothing new in changed code.npm run build,test:std,typecheck,typecheck:emit,node scripts/docs-typecheck.mjs,test:docs,test:vite: pass.Docs changed
README.md (section renamed to "Libraries: automatic analysis and feature packs", leading with automatic analysis), docs/guide/libraries.md (intro, automatic mode rewritten: levels, kinds, packages, cache, timings; coverage;
safe-ts inferwith measurements;completein the manifest), docs/index.md, docs/README.md, docs/rules/unhandled-failure.md, docs/guide/editor.md, docs/guide/adoption.md (cache), docs/guide/security.md, CHANGELOG.md.🤖 Generated with Claude Code
Every package the program imports (resolving into node_modules, listed in package.json or not; workspace packages stay project code) is analyzed from its JavaScript, and what its functions throw or reject is reported. Before, a failure had to be both found in the code and documented with @throws, so most packages reported nothing. - Levels: "infer": "all" (default), "real" (no argument checks), "documented" (the old behaviour), false; { "level", "exclude" } combined. Unknown values warn. - Each finding names its kind in the message: contract, internal, builtin, dynamic, and the new argument check (the guard only tests the function's own parameters). - The analysis follows factories' returned functions, export * / export * as ns, re-exports and calls into other packages, CommonJS members and compiled defineProperty exports, prototype methods, class expressions, exported instances; stored closures no longer count as running in their creator; catch-and-rethrow passes the try block's failures through. - Method calls are matched by the receiver's class where visible, else by name only when every method of that name fails; nothing is guessed. - Cache: one file per package, version and level in node_modules/.cache/safe-ts (or SAFE_TS_CACHE_DIR), keyed by the analyzer version, re-analyzed when a followed dependency changes version; linked packages also by a fingerprint of their files. - Packs win per member; a pack module entry can say "complete": true (the zod pack does). - safe-ts infer / coverage show the kinds; docs, README and CHANGELOG updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>