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

extract css @import files #971

Open
onnoomg opened this issue Dec 3, 2024 · 4 comments
Open

extract css @import files #971

onnoomg opened this issue Dec 3, 2024 · 4 comments
Labels
enhancement this will make dependency-cruiser sweeter

Comments

@onnoomg
Copy link

onnoomg commented Dec 3, 2024

Hi @sverweij , I noticed cruise can detect import files. however, it cannot detect "@import" style files in a stardard option setting. Does it possible to extract @import style files eg. index.scss OR should I use another library to do this separately?

Environment

  • Version used: 16.6
  • Node version: 18.20
  • Operating System and version: macos
@sverweij
Copy link
Owner

sverweij commented Dec 3, 2024

Hi @onnoomg currently dependency-cruiser doesn't process (s)css or sass. As it looks like some of the frameworks directly import (s)css from javascript-(ish) modules, it might be a future feature, though.

Notes from a quick research

  • Possibly postcss is a reasonable option for parsing css (see this comparison between the parsers available in AST explorer.
  • css imports have some specification variants - so using brute force i.e. with a regex is bound to end in tears.
  • resolution might (likely does) work different from that for javascript. Network calls might be involved.

@onnoomg
Copy link
Author

onnoomg commented Dec 4, 2024

Hi @onnoomg currently dependency-cruiser doesn't process (s)css or sass. As it looks like some of the frameworks directly import (s)css from javascript-(ish) modules, it might be a future feature, though.

Notes from a quick research

  • Possibly postcss is a reasonable option for parsing css (see this comparison between the parsers available in AST explorer.
  • css imports have some specification variants - so using brute force i.e. with a regex is bound to end in tears.
  • resolution might (likely does) work different from that for javascript. Network calls might be involved.

Hi @sverweij, Since I only have the files of the vue framework at hand, I solved this problem specifically. According to your source code function vue3Transpile(pSource), there is a variable called 'descriptor' in the parsing result passed by vueTemplateCompiler, which has an attribute 'styles' containing what I want (that is, @import here). Hopefully, this way of calling the object generated by the library can become a way to handle @import, although it may be a bit too targeted. Anyway, thank you for your reply. Cheers :)

@johncrim
Copy link

johncrim commented Dec 5, 2024

Note that SCSS @import is deprecated in favor of @use and @forward and will be removed in the next major version; so while I like this idea I it should definitely include @use and @forward.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Dec 15, 2024
@sverweij sverweij added enhancement this will make dependency-cruiser sweeter and removed stale labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement this will make dependency-cruiser sweeter
Projects
None yet
Development

No branches or pull requests

3 participants