sass/migrator

Support refactoring out an intermediate dependency

Opened this issue · 0 comments

Assume a case where you have a set of files like:

<==> entrypoint.scss
@use "indirect";

a {
  color: indirect.$a-color;
  background: indirect.$b-color;
}

<==> _indirect.scss
@forward "a" as a-*;
@forward "b" as b-*;

<==> _a.scss
$color: red;

<==> _b.scss
$color: blue;

It would be nice to have a migrator that would let you refactor entrypoint.scss to directly depend on a and b instead of going through indirect, e.g.:

<==> entrypoint.scss
@use "a";
@use "b";

a {
  color: a.$color;
  background: b.$color;
}

The motivating use case here would be to get rid of use rules like @use "library.import", which we've been using as a temporary workaround when migrating an library that already has downstream users using @use. However, the generalized version could be useful for other refactoring.

To ease implementation, this should only support code that has already migrated to the module system, since that should make it possible to implement without fully analyzing the entire dependency graph.