Repository navigation
fix(style-dependencies): use absolute paths from sys.readDir in collectTsxFiles - #17
Merged
Merged
Conversation
…ctTsxFiles Stencil's sys.readDir returns full normalized paths, not basenames, so path.join(dir, entry) doubled every path and made each sys.stat fail with ENOENT. The file list came back empty and getComponentStyleDependencies() always returned empty maps for every consumer. Use the entry directly. Also correct the test mocks, which previously returned basenames from readDir (contradicting the real contract) and so passed against the buggy implementation. Add a nested-directory regression case.
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.
Follow-up to #16 (v0.5.1). The seeding and re-export work shipped correctly, but
getComponentStyleDependencies()still returned empty maps (byComponent=0,byStyle=0) on every project — traced to a path bug incollectTsxFiles, independent of the seeding work.The bug
collectTsxFilesbuilt each child path withpath.join(dir, entry), but Stencil'ssys.readDir()already returns full normalized paths, not basenames (confirmed instencil-public-compiler.d.ts: "All return paths are full normalized paths, not just the basenames."). Sopath.joindoubled the path and everysys.statfailed withENOENT, leaving the file list empty — the map was always empty for every consumer.The fix
Use the entry directly, since
sys.readDiralready returns absolute paths:Tests
The existing
rebuildStyleMaptest mock returned basenames fromreadDir(['cmp.tsx']), contradicting the real contract — which is why it passed against the buggy code. Corrected the mocks to return absolute paths and added a nested-directory case (src/components/my-cmp/my-cmp.tsx) that exercises the recursion.Verified both updated tests fail against the pre-fix implementation and pass with the fix.
Test plan
pnpm exec vitest run test/(21 passing)pnpm lintpnpm build— confirmed compiledcollectTsxFilesusesconst fullPath = entry