fix: discover npm components declared in webui-press config#371
Merged
Conversation
External components declared as npm packages in a webui-press `config.json` `components` array (e.g. `"@mai-ui"`) failed to build with either: Component path not found: <project>/@mai-ui or, once the name reached discovery intact: Component discovery error: Could not find node_modules/ directory (searched upward from /var/folders/.../webui-press-404-...) Two coupled causes: 1. webui-press prefixed every configured component source with the working directory (`cwd.join(source)`), turning the npm specifier `@mai-ui` into an absolute path. `webui-discovery` then classified it as a local filesystem path and failed to find it. 2. npm discovery anchors its `node_modules` walk-up at the build app directory. webui-press renders each docs page from a synthesized scratch directory in the system temp folder, which has no `node_modules` ancestor, so even a correctly-bare `@scope` specifier could not be resolved. Fixes: - webui-discovery: add `find_node_modules_with_fallback`, used by `resolve`, which walks up from the app directory first and then from the process working directory (the project root the command was run in). Normal CLI builds are unaffected because the app directory is already inside the project. - webui-discovery: expose `is_local_source` as the single source of truth for path-vs-npm classification (`classify_source` now delegates to it). - webui-press: resolve configured component sources through `is_local_source` so npm names/scopes stay bare while local paths are still made absolute against the project root. Adds unit tests for the fallback resolver, the shared classifier, and the webui-press config source resolution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
akroshg
approved these changes
Jun 25, 2026
janechu
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #370.
Problem
External components declared as npm packages in a
webui-pressconfig.jsoncomponentsarray (e.g."@mai-ui") were never discovered — the build failed with eitherComponent path not found: /<project>/@mai-uiorCould not find node_modules/ directory (searched upward from /var/folders/...).Two coupled causes:
current_dir().join(source), turning the npm specifier@mai-uiinto an absolute path/<project>/@mai-ui.webui-discoverythen classified it as a local path and failed.node_modules/from the build app directory.webui-pressrenders each page from a synthesized scratch dir in the system temp folder, which has nonode_modulesancestor — so even a correctly-bare@scopecould not be resolved.Changes
webui-discoveryfind_node_modules_with_fallback(primary, fallback), used byresolve(): walk up from the app directory first, then from the process working directory (the project root the command was invoked in). The primary error is preserved when both fail. Normalwebui build/serveis unaffected — the app dir is already inside the project, so the fallback never triggers there.pub fn is_local_source(&str) -> boolas the single source of truth for path-vs-npm classification;classify_sourcenow delegates to it.webui-presswebui_discovery::is_local_source: npm names/scopes stay bare (so discovery resolves them fromnode_modules), while local paths are still made absolute against the project root. Addsmicrosoft-webui-discoveryas a direct dependency.Why this approach
Discovery already receives the app directory; the only gap is that
webui-press's app dir is a throwaway scratch dir outside the project. A cwd fallback fixes that at the source without a newBuildOptionsfield and without relocating scratch into the project tree (which would otherwise need to be git-ignored and watcher-ignored).Testing
cargo test -p microsoft-webui-discovery(34 passed) and-p microsoft-webui-press(45 passed), including new tests for the fallback resolver,is_local_source, and webui-press config source resolution.cargo fmt+cargo clippyclean on both crates."@mai-ui"in config now builds and renders all 15<mai-*>tags (button, link, text-input, spinner, divider, dropdown, listbox, menu-button, menu-item, menu-list, option, tab, tablist, tree, tree-item).Compatibility
Behavior-preserving for existing builds. The fallback only adds a resolution path when the primary walk-up finds no
node_modules; it never overrides a successful primary match.is_local_sourceis purely a refactor of existing classification logic.