Skip to content

Fix Windows CI: normalize backslash paths in SCSS/Stylus alias resolution#69

Merged
Simon-He95 merged 3 commits intomainfrom
copilot/ci-fix-windows-test-issue
Mar 26, 2026
Merged

Fix Windows CI: normalize backslash paths in SCSS/Stylus alias resolution#69
Simon-He95 merged 3 commits intomainfrom
copilot/ci-fix-windows-test-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

path.resolve() and path.join() return backslash-separated paths on Windows. These get interpolated directly into SCSS @use/@import and Stylus @import statements, which the preprocessors cannot resolve.

// Before: @use "C:\tmp\src\styles\tokens" — Sass fails
// After:  @use "C:/tmp/src/styles/tokens" — Sass resolves correctly
finalPath = finalPath.replace(/\\/g, '/')
  • Normalize resolved alias paths to forward slashes before inserting into SCSS source in sassCompiler.ts
  • Apply the same forward-slash normalization to resolved alias paths in stylusCompiler.ts
Original prompt

This section details on the original issue you should resolve

<issue_title>ci windows test failed</issue_title>
<issue_description>ci windows test failed,下面是失败的原因,我猜测可能是windows上一些文件路径的问题

Run nr test

transform-to-unocss@0.1.24-beta.3 test D:\a\transformToUnoCSS\transformToUnoCSS
vitest

RUN v3.2.4 D:/a/transformToUnoCSS/transformToUnoCSS

✓ test/sass-mixed-decls.test.ts (5 tests) 519ms
✓ sassCompiler deprecation warnings fix > should compile SCSS with mixed declarations without warnings 445ms
stdout | test/complex-scss-for-loop.test.ts > Complex SCSS for-loop and variable syntax > should handle SCSS @for loops with variables correctly
Testing complex SCSS with @for loops and variables...
[DEBUG] transformCode started: {"filepath":"complex-scss-test.vue","isJsx":true,"codeLength":3103}
[DEBUG] transformCode detected type: vue, original type: undefined, filepath: complex-scss-test.vue
[DEBUG] transformCode: Processing as Vue file

stdout | test/complex-scss-for-loop.test.ts > Complex SCSS for-loop and variable syntax > should handle SCSS @for loops with variables correctly
[DEBUG] transformVue started: {
"filepath": "complex-scss-test.vue",
"isJsx": true,
"codeLength": 3103
}
[DEBUG] After inline style transformation
[DEBUG] transformMedia: No https://github.com/media queries found

stdout | test/complex-scss-for-loop.test.ts > Complex SCSS for-loop and variable syntax > should handle SCSS @for loops with variables correctly
[DEBUG] Processing styles: {
"stylesCount": 1
}
[transform-to-unocss] Compiling SCSS file: complex-scss-test.vue

stdout | test/complex-scss-for-loop.test.ts > Complex SCSS for-loop and variable syntax > should handle SCSS @for loops with variables correctly
[DEBUG] CSS compiled successfully: {
"styleIndex": 0,
"originalStyleLength": 2221,
"compiledCssLength": 4612,
"scoped": true
}

stdout | test/complex-scss-for-loop.test.ts > Complex SCSS for-loop and variable syntax > should handle SCSS @for loops with variables correctly
[DEBUG] importCss started: {
"filepath": "complex-scss-test.vue",
"styleLength": 4612,
"hasImports": false
}

color: $brand-color;
}
</style>
❯ test/transformAstro.test.ts:57:20
55| })
56|
57| expect(result).toContain('text-red')
| ^
58| expect(result).not.toContain('$brand-color')
59|

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Test Files 1 failed | 14 passed (15)
Tests 1 failed | 63 passed (64)
Start at 06:43:33
Duration 6.63s (transform 546ms, setup 0ms, collect 6.36s, tests 6.84s, environment 4ms, prepare 2.21s)

Error: AssertionError: expected '---\nexport const prerender = true;\n…' to contain 'text-red'

Expected
Received
text-red
export const prerender = true;
hi

<style> @use "@/styles/tokens" as *; .title { color: $brand-color; } </style>

❯ test/transformAstro.test.ts:57:20

 ELIFECYCLE  Test failed. See above for more details.
Error: Process completed with exit code 1.</issue_description>

Comments on the Issue (you are @copilot in this section)


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 26, 2026

Deploy Preview for to-unocss failed. Why did it fail? →

Name Link
🔨 Latest commit 5069899
🔍 Latest deploy log https://app.netlify.com/projects/to-unocss/deploys/69c4e5c89ab3580008e87686

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 26, 2026

Deploying transformtounocss with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5069899
Status: ✅  Deploy successful!
Preview URL: https://603a6d52.transformtounocss.pages.dev
Branch Preview URL: https://copilot-ci-fix-windows-test.transformtounocss.pages.dev

View logs

Copilot AI changed the title [WIP] Fix CI windows test failure due to file paths Fix Windows CI: normalize backslash paths in SCSS alias resolution Mar 26, 2026
Copilot AI requested a review from Simon-He95 March 26, 2026 07:40
@Simon-He95
Copy link
Copy Markdown
Owner

@copilot 这个路径只是我的猜测,另外你这个修复方法好吗

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 26, 2026

@copilot 这个路径只是我的猜测,另外你这个修复方法好吗

你的猜测是对的,确实是 Windows 路径问题。根本原因:在 sassCompiler.tsreplaceAliasImports 中,path.resolve() 在 Windows 上返回反斜杠路径(如 C:\tmp\src\styles\tokens),这些路径被直接插入到 SCSS @use 语句中。Sass 无法解析反斜杠路径,导致编译失败并回退返回原始 CSS($brand-color 未解析)。

修复方法是在将路径插入 SCSS 源码之前,用 finalPath.replace(/\\/g, '/') 将反斜杠转换为正斜杠。这是业界标准做法(Vite 的 normalizePath、npm 的 slash 包等都用同样的方式)。Sass 在所有平台上都能正确解析正斜杠路径。

5069899 中还修复了 stylusCompiler.ts 中同样的问题。

Copilot AI changed the title Fix Windows CI: normalize backslash paths in SCSS alias resolution Fix Windows CI: normalize backslash paths in SCSS/Stylus alias resolution Mar 26, 2026
@Simon-He95 Simon-He95 marked this pull request as ready for review March 26, 2026 09:03
@Simon-He95 Simon-He95 merged commit 8a43165 into main Mar 26, 2026
2 of 6 checks passed
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.

ci windows test failed

2 participants