code-complexity icon indicating copy to clipboard operation
code-complexity copied to clipboard

feat: DX improvements for programmable API

Open adaliszk opened this issue 1 year ago • 1 comments

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.

adaliszk avatar Feb 18 '24 02:02 adaliszk

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).

simonrenoult avatar Aug 21 '25 23:08 simonrenoult