Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

output line in package.json file #874

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

Conversation

jdeniau
Copy link
Contributor

@jdeniau jdeniau commented Jan 8, 2024

Add the dependency line number in the standard output. See #872 for more about this PR.

I choose to modify only the cli output for now as it does not break public API nor internal representation.
To do so, I look at the package.json file pretty late in the process. It might be nice to get the line number earlier in the process, but it might change the result object, which may be more intrusive.

Capture d’écran 2024-01-09 à 00 26 36

Fixes #872

@rumpl
Copy link
Member

rumpl commented Jan 11, 2024

Quick question, in terminals that do know how to parse this, is it cmd/ctrl clickable so that the file opens on that line in an IDE?

@jdeniau
Copy link
Contributor Author

jdeniau commented Jan 11, 2024

Tried in VSCode, it does seems to work great (see video).
Do you have another editor in mind ?

2024-01-11.15-25-13.mp4

@rumpl
Copy link
Member

rumpl commented Jan 11, 2024

No other in mind no, ok this is great, thanks, now I have to review the code :)

Copy link
Contributor Author

@jdeniau jdeniau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ! I commented on github directly to help you understand the code if needed.

Comment on lines +68 to +69
rootDir = null,
printJsonLineInKey = null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added two parameters here:

  • rootDir to open the package.jsonfile,
  • printJsonLineInKey is to find the extra dependency in either "dependencies" or "devDependencies"

Comment on lines +75 to +78
const packageJson =
rootDir && printJsonLineInKey
? fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8')
: null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open the package.json if needed (only on default output)

May be optimised to avoid memory consumption with a lot of unused deps (but the purpose of depcheck is to have a few unused deps, so extra optimization may be overkill ?)

findLineInFile(packageJson, printJsonLineInKey, dep);

return `* ${dep}${
lineNumber !== null ? ` (package.json:${lineNumber})` : ''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the line number if needed

@jdeniau
Copy link
Contributor Author

jdeniau commented Feb 28, 2024

Hi! Do you need any help from me to get this done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report package.json line number in output
2 participants