-
Notifications
You must be signed in to change notification settings - Fork 72
Feature: Add report Function for Import Analysis Output #450
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
base: main
Are you sure you want to change the base?
Conversation
…ing to alter output content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, but I don't think the printing logic belongs to unimport
. Ideally, we should have an API to retrieve the matched data in a structured format, and leave it to the users to decide how to consume the data. Printing to the terminal and a very niche and opinionated need, we don't want to introduce extra dependencies/logics for that either.
Thanks for the review. Now I learnt that unimport as a Nuxt dependency would have to stayed streamlined to provide limited functions. (Correct me if I'm wrong...) Honestly, I held doubt that the additional dependency of
I'd like to hear your voices over the APIs to provide for the data consumption before proceeding with further changes.
Unimport.vite({
dirs: ['./composables/**/*'],
reportMatched(imports) {
// your own process here
},
}) |
Another way to do that might be: Unimport.vite({
dirs: ['./composables/**/*'],
onInited(unimport) {
// users's own logic to the instance, for example
setTimeout(() => {
console.log(unimport.getMatchedImports())
}, 1000)
},
}) |
Okay. No issue with keeping it verbose.
For my part, a list generated after all imported modules being resolved would be enough. Thus, the "report" I implemented was put under the I assume the For instance, However, unimport didn't provide the hooks yet... (Don't think the Vite hook would be the targeted ones...) Is hooks design already on the roadmap? |
Summary
This PR introduces a new
report
function to the unimport package, enabling users to output, format, and persist matched import analysis results. The function supports multiple output formats, printing to the console, and writing to files, with customizable options.Implementation
report
function that accepts matched imports and an options object.table
,json
, andcompact
.printOut
), writing to a file (outputToFile
), or both.printFormat
andoutputFormat
options.printFn
option for custom output handling.Tests
report
function, covering:reportMatched
in the unimport contextresolves #449