code-complexity
code-complexity copied to clipboard
feat: DX improvements for programmable API
While trying to use this library in an existing CLI tool (importing it), I ran into a few issues:
- Types are not exposed as the dist file for it was missing
- There are no named exports for ESM-based usage
I fixed those issues, and the tests passed as no logic has changed, improving on #8: Support a programmable API.
While so far the default export could have been used, now it is nicely typed and can support both CommonJS and ESM usage:
// CommonJS
const complexity = require("code-complexity")
const results = await complexity.compute({
target: "some/file/path"
})
// ES Modules
import { analyze } from "code-complexity";
const results = await analyze({
target: "some/file/path"
})
For advanced usage, people can import Statistics, Churns, and Complexities and instantiate their own Analyzer.
I made some changes for the incoming v5, I'll take a look at this PR later (hopefully, it won't wait 2 years this time).