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

Better support for migrating libraries #15

Open
jathak opened this Issue Mar 14, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@jathak
Copy link
Contributor

jathak commented Mar 14, 2019

Right now, the migrator pretty much assumes that the entrypoint(s) and all dependencies will be migrated together, which only really works when all stylesheets are local to one project. The migrator should have a mode designed for migrating libraries without breaking anything downstream.

This should support the following:

  • When migrating library.scss, the migrator should also create a library.import.scss file that maintains the pre-migration behavior but warns when imported.
  • If a library previously explicitly namespaced its members with a prefix (e.g. lib-foo), the migrator should be able to automatically remove the prefixes and instead rely on the module namespace (e.g. library.foo)
  • When migrating a stylesheet that depends on a previously migrated library, the migrator should be able to remove those prefixes, ideally without the user having to explicitly specify the prefixes to be removed.
@jathak

This comment has been minimized.

Copy link
Contributor Author

jathak commented Mar 14, 2019

One idea for how this might work:

Original library.scss:

$lib-background: blue;
$lib-foreground: yellow;

Running migrator with module_migrator library.scss --unprefix 'lib-' should result in:

Migrated library.scss:

$background: blue;
$foreground: yellow;

Generated library.import.scss:

$_prefix: "lib-";
@warn "You are importing a library that has been migrated to @use.";
$lib-background: blue;
$lib-foreground: yellow;

Now, if that entrypoint.scss depends on this library

@import "library";
a {
  background-color: $lib-background;
  color: $lib-foreground;
}

and the user runs the migrator, it should be able to detect the prefix automatically by looking at the $_prefix variable in library.import.scss, resulting in:

@use "library";
a {
  background-color: $library.background;
  color: $library.foreground;
}
@jathak

This comment has been minimized.

Copy link
Contributor Author

jathak commented Mar 14, 2019

@nex3, thoughts on this?

@nex3

This comment has been minimized.

Copy link

nex3 commented Mar 15, 2019

Generally, this sounds good. I think I wouldn't add the warning on import, since I expect most library authors won't care that much if their downstream users are using @use and thus may not want the warning cluttering up the UX.

You can also generate a much simpler library.import.scss by forwarding library.scss with a prefix:

@forward "library" as lib-*;

That way you won't have to duplicate all the definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.