Skip to content

💡 Entries may have unused exports #1442

@remcohaszing

Description

@remcohaszing

Suggest an idea for Knip

Knip treats the exports of all entries as used. However, not all exports are always used. For example, consider the following project:

// package.json
{
  "type": "module",
  "bin": "./lib/bin.js",
  "exports": "./lib/exports.js",
  "devDependencies": {
    "knip": "^5.0.0"
  }
}
// lib/exports.js
// This function is exported via `package.json` exports. So it’s actually used.
export function used() {}
// lib/bin.js
// This function is only exported via the `package.json` `bin` field. So it’s unused.
export function unused() {}
// knip.config.js
// This module is used by Knip. Only the default export is used.
export function unused() {}
export default {}

I imagine entry could be a mapping of file name patterns to export name patterns instead of an array. So this project structure would yield a Knip config equivalent to:

{
  "entry": {
    "lib/bin": [],
    "lib/exports": ["*"],
    "knip.config.js": ["default"]
  }
}

For backwards compatibility, an array could be equivalent to a mapping where each entry maps to a value of ["*"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions