Skip to content

fix(css): @import with .css in node_modules importing a different package failed to resolve - #15000

Merged
patak-cat merged 6 commits into
vitejs:mainfrom
smeng9:fix-scss-deep-resolve
Jan 8, 2024
Merged

patak-cat merged 6 commits into
vitejs:mainfrom
smeng9:fix-scss-deep-resolve

Conversation

@smeng9

@smeng9 smeng9 commented Nov 15, 2023 •

Copy link
Copy Markdown
Contributor

Description

fixes #12227
refs #9681

Additional context

The cause of the bug is when performing sass style preprocessing, it's trying to rewrite the @import lines in the code using sass render with internalImporter.

The internalImporter resolve the url and then tries to perform a rebase of the url. The rebaseUrls is not correctly performing rebase if we try to perform another import from a different package.

So instead of calling path.resolve, we have to try the corresponding resolver first with id and importer.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@smeng9 smeng9 changed the title fix(css): deep css import resolve fix(css): deep scss/sass import resolve Nov 21, 2023

@sapphi-red sapphi-red left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried yet, but IIUC this rebaseUrl function only rewrites @import with css extension. The issue is about @import with less extension. Does this work?

Also would you add a test?

@smeng9

smeng9 commented Dec 7, 2023

Copy link
Copy Markdown
Contributor Author

Hi @sapphi-red,

I have tested this fix by linking vite against the failing case https://stackblitz.com/edit/vite-sass-transitive-import?file=src%2Fstyle.scss in #12227 and now the file can be correctly resolved. The less version should work the same.

I have tried to write a test case for that, but it seems the issue only happens for npm instead of pnpm package manager. I can't make the test case fail without this fix.

@smeng9
smeng9 requested a review from sapphi-red December 9, 2023 00:12
@sapphi-red

Copy link
Copy Markdown
Member

I see. It seems #9681 and #12227 is caused by a different reason. I mistakenly said #12227 is a duplicate.

I have tried to write a test case for that, but it seems the issue only happens for npm instead of pnpm package manager. I can't make the test case fail without this fix.

I guess it would fail if you use file: instead of link:.

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Dec 9, 2023
@smeng9

smeng9 commented Dec 17, 2023

Copy link
Copy Markdown
Contributor Author

Hi @sapphi-red a test cases is added with your method to use file instead of link.

Can we merge this soon? Thanks!

There are some flaky tests on node-20, macos-latest however it passes on my development mac

Comment thread playground/css/__tests__/css.spec.ts Resolved
Comment thread playground/css/index.html Resolved
sapphi-red
sapphi-red previously approved these changes Dec 30, 2023
@sapphi-red sapphi-red changed the title fix(css): deep scss/sass import resolve fix(css): @import with .css in node_modules importing a different package failed to resolve Dec 30, 2023
Comment thread playground/css/index.html Resolved
@sapphi-red
sapphi-red requested a review from bluwy January 2, 2024 08:06
@patak-cat
patak-cat merged commit 8ccf722 into vitejs:main Jan 8, 2024
@smeng9
smeng9 deleted the fix-scss-deep-resolve branch January 9, 2024 01:18
jbabin91 added a commit to oakoss/claude-plugins that referenced this pull request Sep 25, 2026
…onflict markers, and pin skill contracts (#94)

Fixes two pr-kit skill defects from the 2026-09-17 audit and adds
pr-kit's first tests. Every command claim below was measured in scratch
repos or against live PRs.

## Changes

- **`get-pr-comments` keeps open threads (cpl-0ye).** It skipped every
outdated thread, but outdated means only that a later push changed the
code the comment was left on. Outdated but unresolved threads now appear
under **Possibly stale — verify**, located by `originalLine` (`line` is
null on them — measured on vitejs/vite#15000, #11228, #2432 and
cli/cli#14475).
- **`get-pr-comments` pages for real (cpl-0ye).** The thread query
declares `$endCursor`, which `gh api --paginate` requires; `--slurp`
returns every page. A `node(id)` follow-up re-reads a thread with more
than 50 comments. Measured with `first:2`: 5 pages, 9 threads;
`--paginate` follows the thread cursor even when a nested comments page
has more.
- **`fix-merge-conflicts` checks the whole tree (cpl-r73).** `git diff
--cached --check` missed a conflicted file left unstaged and failed on
trailing whitespace. It is replaced by `git diff --name-only
--diff-filter=U` plus two `git grep` marker searches with `-- ':/'`: one
over the working tree, one over the index (`--cached`). The pattern
covers diff3 `|||||||` and markers longer than 7; exit 128 is a failed
search.
- **`fix-merge-conflicts` states that a rebase swaps sides (cpl-r73).**
A table and sentence: during `git rebase`, `ours` is the upstream and
`theirs` is your commit; check `git status` for `rebase in progress`
first.
- **`fix-merge-conflicts` handles conflicts that leave no markers.**
Binaries, symlinks, and paths one side deleted or both sides renamed
pass every marker check once staged, with `git add` silently keeping the
working-tree copy (the upstream, during a rebase). The skill now has the
agent keep a side or `git rm` the path explicitly and report it.
Submodule conflicts are out of scope: `git checkout --ours/--theirs`
exits 0 on them and changes nothing.
- **pr-kit prose-anchor tests (cpl-k3s).**
`plugins/pr-kit/tests/skill-contracts.spec.ts`, 16 vitest tests, pinning
the fixes above plus the earlier audit's contracts: the
`make-pr-easy-to-review` tree guard, the `fix-ci` round cap, no skill
invoking a model-disabled skill, every gh field a skill fills in being
fetched, and the README's `gh` requirement matching the skills that call
`gh`. Each of 42 literal mutations fails its own test.
- **Release note:** `.changeset/pr-kit-audit-findings.md` (pr-kit
patch).

cpl-121 (README `gh` claim) was already fixed on main by #54 and is
closed with no code change.

## Review

`/review-cycle:review` converged in 5 iterations (Codex, code-reviewer,
pr-test-analyzer, silent-failure-hunter; then spec conformance and a
maintainability audit). Spec conformance found no missing or wrong
requirements.

## Follow-ups

- cpl-yxo — deferred anchor and marker-check gaps (CRLF `=======`,
slashless skill references, `True` in frontmatter, a submodule cue, nine
test-tightening suggestions).
- cpl-crj — share anchor helpers across plugins and run the
model-disabled-reference check repo-wide (3 unchecked references in
review-cycle today).

## Test plan

- `pnpm test` — 727 passed
- `pnpm lint`, `pnpm format:check`, markdownlint — clean
- `claude plugin validate ./plugins/pr-kit --strict` — passed
- `pnpm exec oakum check --strict` — exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing an SCSS file from an npm package that transitively imports an SCSS file from a different package fails

3 participants