Skip to content

Add optional import and component resolution hooks - #85

Open
ezemacchi wants to merge 1 commit into
moroshko:masterfrom
ezemacchi:feat/resolve-hooks
Open

ezemacchi wants to merge 1 commit into
moroshko:masterfrom
ezemacchi:feat/resolve-hooks

Conversation

@ezemacchi

Copy link
Copy Markdown

Applications that already maintain a TypeScript program or another symbol resolver cannot currently report an unused import or supply the canonical identity of a JSX tag imported through a barrel. The file-local import lookup can also attribute a shadowed identifier to the imported component.

This adds two optional synchronous hooks, keeping current behavior when neither is configured:

  • resolveImport({ filePath, node, specifier, importInfo }) returns { componentName, importRecord } to append caller-defined import evidence to the raw report, including imports with no JSX. Returning a falsy value skips that import record.
  • resolveComponent({ filePath, node, name }) returns { componentName, importInfo } from an external resolver. Returning a falsy value excludes the tag without falling back to its local import name. Existing JSX filters still apply to the resolved identity.

For example, an external resolver can identify <Alias /> from a local barrel as Button from example-ui, while rejecting a same-named parameter. An import-record callback can preserve the specifier's file, line and column even if the imported component is never rendered. Import records remain separate from JSX instances; no runtime evaluation or wrapper-prop propagation is added.

The README documents the arguments, return values, filter behavior and examples. Eleven generic tests cover unused and type-only imports, specifier locations, nested records, resolver exclusion, module/component filters, option forwarding and callback validation. No application-specific resolver or registry is included.

Validation on Node 24.19.0 with the existing dependency lock:

  • npm test: 70 tests passed.
  • npm run lint: passed.
  • npm run test:coverage: passed, with 100% statements, branches, functions and lines.
  • Prettier check of the changed files: passed.

Dependency versions, the package lock and LICENSE are unchanged. Parser upgrades can be considered separately; they are outside this focused contribution. Opening as a draft for review of the hook API and raw-report shape.

@ezemacchi

Copy link
Copy Markdown
Author

hi @moroshko! just to note, it's completly "vibe-coded"

I'm working on adding Storybook on my react app, and wanted to build a "Catalog UI" with 2 actions "IDE-like" "Go to implementation"/"Go to definition". Claude found your repo, but it didn't recognize some components, not even sure which ones, but I think the "aliased" ones, so I guess it was because this repo is old and didn't support that

So, the idea behind, is to add a community addon, that use the react-scanner json output, to build this "Catalog-UI"

I made a fork and add that for my project, but I think it could be nice to use your repo on the community addon that I would like to add on Storybook Addons: https://storybook.js.org/addons/

I also think, there is a lot of potential here "unexplored" to use Storybook as a TDD like implementation for Agents

@ezemacchi
ezemacchi marked this pull request as ready for review October 2, 2026 11:00
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.

1 participant