Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(getCssExports): adds support for SCSS/SASS partials via aliases #251

Merged
merged 4 commits into from
Feb 11, 2024

Conversation

rmachado-studocu
Copy link
Contributor

@rmachado-studocu rmachado-studocu commented Jan 30, 2024

What does this PR do:

  • Changes getCssExports.ts to try a partial url/path or an _index if newUrl returns undefined.

In practice, with the introduction of tsconfig-paths in #105 led to the requirement that the import line must point to a file in the filesystem.

So if your file is called _colors.scss and you're doing @import './colors'; it would fail...
This PR changes the logic to first test the normal behaviour of searching for a file colors.{sass,scss} ... if it cannot find, then it'll try to prefix the filename with _ and search for _colors.{sass,scss} in the aliases directories...

There was also the request to support index files (see below @lochstar 's comment). After looking at SASS' documentation, I realized that it would make sense to support it, so as a fallback in case it cannot find the partial, it'll try to resolve an index file. Using the above example, if colors is a directory, then it'll search for colors/_index.{sass,scss}.

Attempts to solve #221

@rmachado-studocu
Copy link
Contributor Author

I hope you're accepting PRs 😄 @mrmckeb

Given it's my first PR here, LMK if something is missing! Thank you for your time reviewing!

@lochstar
Copy link

lochstar commented Feb 8, 2024

@rmachado-studocu Would this handle _index.scss files as well?

Fails

@use '@src/styles' as *;

Works

@use '@src/styles/_index' as *;

@rmachado-studocu
Copy link
Contributor Author

rmachado-studocu commented Feb 8, 2024

@lochstar in the current implementation no.

But I can adapt it to work as such too ... basically if when checking if the _${filename} doesn't exist we can try the _index...

Would it be something you'd like to see implemented?

@lochstar
Copy link

lochstar commented Feb 8, 2024

@rmachado-studocu Definitely 👍🏻

@rmachado-studocu
Copy link
Contributor Author

rmachado-studocu commented Feb 8, 2024

@lochstar I've added the support ... I've also added some tests to verify the changes.

If you try it, LMK if it works for you 👍

Copy link
Owner

@mrmckeb mrmckeb left a comment

Choose a reason for hiding this comment

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

Thank you! It looks like you've both tested that this resolves the issues you had, so I'm happy to merge. Thanks!

@mrmckeb mrmckeb merged commit 1b0cc06 into mrmckeb:main Feb 11, 2024
1 check passed
@mrmckeb
Copy link
Owner

mrmckeb commented Feb 11, 2024

This has now shipped in v5.1.0. Thanks again!

@lochstar
Copy link

Awesome, thanks @rmachado-studocu & @mrmckeb !

@rmachado-studocu
Copy link
Contributor Author

Thank you @mrmckeb and @lochstar for the reviews 👍

davydkov referenced this pull request in likec4/likec4 Feb 24, 2024
#586)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[typescript-plugin-css-modules](https://togithub.com/mrmckeb/typescript-plugin-css-modules)
| [`^5.0.2` ->
`^5.1.0`](https://renovatebot.com/diffs/npm/typescript-plugin-css-modules/5.0.2/5.1.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/typescript-plugin-css-modules/5.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/typescript-plugin-css-modules/5.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/typescript-plugin-css-modules/5.0.2/5.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/typescript-plugin-css-modules/5.0.2/5.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>mrmckeb/typescript-plugin-css-modules
(typescript-plugin-css-modules)</summary>

###
[`v5.1.0`](https://togithub.com/mrmckeb/typescript-plugin-css-modules/releases/tag/v5.1.0)

[Compare
Source](https://togithub.com/mrmckeb/typescript-plugin-css-modules/compare/v5.0.2...v5.1.0)

#### What's Changed

- chore: update dependencies by
[@&#8203;mrmckeb](https://togithub.com/mrmckeb) in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/255](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/255)
- feat: add env var to disable plugin by
[@&#8203;ekilah](https://togithub.com/ekilah) in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/244](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/244)
- docs: update README regexp by
[@&#8203;mrmckeb](https://togithub.com/mrmckeb) in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/256](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/256)
- feat(getCssExports): adds support for SCSS/SASS partials via aliases
by [@&#8203;rmachado-studocu](https://togithub.com/rmachado-studocu) in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/251](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/251)
- feat: customRender return sourceMap support by
[@&#8203;qyzzzz](https://togithub.com/qyzzzz) in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/249](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/249)

#### New Contributors

- [@&#8203;rmachado-studocu](https://togithub.com/rmachado-studocu) made
their first contribution in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/251](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/251)
- [@&#8203;qyzzzz](https://togithub.com/qyzzzz) made their first
contribution in
[https://github.com/mrmckeb/typescript-plugin-css-modules/pull/249](https://togithub.com/mrmckeb/typescript-plugin-css-modules/pull/249)

**Full Changelog**:
mrmckeb/typescript-plugin-css-modules@v5.0.2...v5.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/likec4/likec4).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

3 participants