fix(css): resolve Sass tsconfig path aliases - #2824
Conversation
commit: |
|
Performance benchmarksCompared 1 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
98bd893 to
625c601
Compare
625c601 to
131eb9c
Compare
131eb9c to
c59f0c1
Compare
|
/bigbonk review for issues |
There was a problem hiding this comment.
Review: fix(css): resolve Sass tsconfig path aliases
Reviewed head c59f0c1. Ran tests/sass-options.test.ts, tests/sass-tsconfig-paths.test.ts, tests/tsconfig-path-alias-resolution.test.ts, tests/tsconfig-paths-vite8.test.ts (all pass) and vp check on the touched source (clean). The implementation is solid and the regression coverage is thorough. No blocking issues found.
CodeQL alert (sass.ts — "replaces only the first occurrence of *")
This alert appears stale. The current head uses replacement.replaceAll("*", () => matchedStar) (sass.ts:152), not .replace(...), so all * occurrences are replaced. The function-replacer form is also the correct choice — it prevents $&/$1 in matchedStar from being interpreted as replacement patterns, which the test at tests/sass-options.test.ts:355-357 (@palette-$&-tokens) explicitly guards. Recommend dismissing the alert as "won't fix / already addressed" once the branch is re-scanned.
Correctness notes (all fine, documenting the reasoning)
-
Multiple
*in a replacement +replaceAll—replaceAll("*", ...)would substitute every*in a target, buthasZeroOrOneAsterisk(index.ts:804) guarantees each materialized target has at most one*before it reaches the importer, so this is safe in the real code path. The standalonecreateSassTsconfigPathImportersdoesn't re-enforce this, but its only production caller feeds it filtered data. -
matchedStar === nullimplies no literal*in replacement — whenfindhas no star, the(findHasStar || !target.includes("*"))filter (index.ts:834) drops any star-bearing target, so returningreplacementverbatim for exact matches is correct. -
Longest-prefix wildcard selection (
matchSassTsconfigPathAlias,sass.ts:72-93) mirrors TypeScript'sfindBestPatternMatch(longest prefix wins, first-wins on ties via<=). Suffix length isn't a tie-breaker, which also matches TS. -
node_modules isolation —
isSassAliasEligibleUrlblocks app aliases whencontainingUrlis undernode_modules(NODE_MODULES_PATH_REcorrectly matchesvendor/node_modules/...). Thedependency-tokensfixture verifies a dependency resolves its own package rather than the app alias. When Sass omitscontainingUrl(top-level entry) the guard correctly allows resolution. -
extendsmerge ordering — the sass merge (index.ts:942,959) uses the same later-overrides-earlier / own-overrides-parent ordering as the existingvitealias merge, keeping the two representations consistent. Note this key-by-key merge acrossextendsis not strictly TypeScript semantics (TS replacespathswholesale), but it matches vinext's pre-existingvitebehavior, so it's a consistent, non-regressing choice rather than a new divergence.
Minor / optional
- The PR body correctly flags this as intentionally broader than Next.js webpack (Next.js does not resolve tsconfig
pathsfrom Sass). Since this is a deliberate vinext-only capability, that divergence is documented in both the code comments (sass.ts:116-133) and the test file header — good adherence to the "document intentional divergences" guidance in AGENTS.md.
LGTM.
|
Review posted to PR #2824. SummaryReviewed PR #2824 ( Verdict: LGTM — no blocking issues. Key findings:
The regression coverage (dev + |
Summary
node_modulesThis is intentionally broader than current Next.js webpack behavior: Next.js does not resolve tsconfig
pathsfrom Sass. The implementation is a vinext migration convenience for applications that already share aliases between source modules and stylesheets.Regression coverage
createBuilder().buildApp()buildnode_modulesand verifies dependency Sass resolves its own package instead of consuming the application aliasmainbecause Vite does not apply the mappings to SassValidation
vp test run tests/sass-tsconfig-paths.test.ts tests/sass-options.test.ts tests/tsconfig-path-alias-resolution.test.ts tests/tsconfig-paths-vite8.test.ts(51 passed)vp checkfor all touched source, test, JSON, and Sass filesvp run vinext#buildIndependent review: clean on exact head
c59f0c1e2after the amended implementation and literal wildcard-capture regression.