Skip to content

fix: resolve Sass alias imports via loadPaths instead of absolute paths for Windows compatibility#70

Merged
Simon-He95 merged 3 commits into
mainfrom
copilot/fix-ci-windows-test-error
Mar 26, 2026
Merged

fix: resolve Sass alias imports via loadPaths instead of absolute paths for Windows compatibility#70
Simon-He95 merged 3 commits into
mainfrom
copilot/fix-ci-windows-test-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Windows CI fails because Sass misinterprets drive letters (C:) in absolute @use paths as URL schemes, producing "Can't find stylesheet to import" errors.

From CI logs:

@use "C:/Users/RUNNER~1/AppData/Local/Temp/.../src/styles/tokens" as *;
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Can't find stylesheet to import.

Change

When resolveAlias matches an import like @/styles/tokens:

  • Before: Rewrites to absolute path → @use "C:/Users/.../src/styles/tokens" (breaks on Windows)
  • After: Adds alias root to Sass loadPaths and rewrites to relative suffix → @use "styles/tokens"
// New: resolve alias via loadPaths (cross-platform)
const aliasResult = tryResolveViaAlias(impPath)
if (aliasResult) {
  const { suffix, aliasRoot } = aliasResult
  compileOptions.loadPaths.push(aliasRoot)
  return `@${kw} ${quote}${suffix}${quote}`
}

Also extracted duplicated getAliasSuffix helper into a shared function.

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>

<agent_instructions>这个问题没有修复,还是存在</agent_instructions>

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

@Simon-He95 @copilot 问题仍然存在

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@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 493a07d
🔍 Latest deploy log https://app.netlify.com/projects/to-unocss/deploys/69c4fbd64620190008fa16cc

…n on Windows

On Windows, absolute paths like C:/Users/... in @use statements cause Sass
to misinterpret the drive letter (C:) as a URL scheme, resulting in
"Can't find stylesheet to import" errors.

Fix: when resolveAlias matches, add the alias root directory to Sass's
loadPaths and rewrite the import to use the relative suffix instead of
an absolute path. This works cross-platform since Sass searches loadPaths
for non-absolute, non-relative imports.

Co-authored-by: Simon-He95 <57086651+Simon-He95@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Simon-He95/transformToUnoCSS/sessions/61fc13c4-5fa8-44a4-a16a-598c17a36bd4
@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: 493a07d
Status: ✅  Deploy successful!
Preview URL: https://be7df814.transformtounocss.pages.dev
Branch Preview URL: https://copilot-fix-ci-windows-test.transformtounocss.pages.dev

View logs

Copilot AI changed the title [WIP] Fix CI Windows test failure due to file path issues fix: resolve Sass alias imports via loadPaths instead of absolute paths for Windows compatibility Mar 26, 2026
Copilot AI requested a review from Simon-He95 March 26, 2026 09:28
@Simon-He95 Simon-He95 marked this pull request as ready for review March 26, 2026 09:33
@Simon-He95 Simon-He95 merged commit e1e38ac 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