Skip to content

feat: DX improvements for programmable API #57

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adaliszk
Copy link

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.

Exposing the various types and classes for programatical usage
with a shortcut for the complexity calculation. This should
give a decent support for functional or object-oriented support
while keeping the changes low.

refs: simonrenoult#8
@adaliszk adaliszk changed the title Quick fixes for DX feat: DX improvements for programmable API Feb 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant