webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
6.53k stars 150 forks source link

How can I ignore this error of unresolved import for an automation test? #122

Closed tal-rofe closed 1 year ago

tal-rofe commented 1 year ago

I have the following file in my project, ./automation/main.spec.cjs:

/**
 * * Testing there is no ESM compiled module in the distribution artifact
 * * As "commitizen" is yet to support ESM adapters, we must not use any ESM-only packages as dependencies
 * * If this "require" statement fails, probably the distribution artifact depends on ESM package
 * * This will cause a "commitizen" failure if it is dependent on ESM package
 */
require('../dist/index.cjs');

process.exit(0);

When running knip in the project, I get an error:

Unresolved imports (1)
../dist/index.cjs  automation/main.spec.cjs

Well, yes, ../dist/index.cjs indeed does not exist. But "I DONT CARE". Is there an option to ignore this error?

webpro commented 1 year ago

You can't really suppress such an error, but you can add automation/main.spec.cjs to the list of ignore: [] patterns.

tal-rofe commented 1 year ago

You can't really suppress such an error, but you can add automation/main.spec.cjs to the list of ignore: [] patterns. I tried, it didn't help. Got same error again

webpro commented 1 year ago

Not sure what I can do without seeing the thing. Do you happen to have a public repo or reproducible test case?

tal-rofe commented 1 year ago

Not sure what I can do without seeing the thing. Do you happen to have a public repo or reproducible test case?

yes, here: https://github.com/Exlint/cz-vinyl/actions/runs/4772280090/jobs/8484693564

again, I did configured: ignores: ['automation/main.spec.cjs'] but it did not help (go exact same error)

webpro commented 1 year ago

:rocket: This issue has been resolved in v2.10.2. See Release 2.10.2 for release notes.

webpro commented 1 year ago

The bug was caused by file dependencies resolved from npm scripts not going through the ignore filter. That should be fixed now.