sass / migrator

Tool for migrating stylesheets to new Sass versions
MIT License
89 stars 11 forks source link

Support loading files from load-paths and node_modules #77

Closed jathak closed 5 years ago

jathak commented 5 years ago

Fixes #58. Fixes #68.

This adds the --load-path option to the executable and also implements an approximation of the Webpack ~ syntax that resolves these URLs to stylesheets within node_modules directories that should be good enough to run the migrator with for most cases.

Wait to merge until after #76

jathak commented 5 years ago

Would something like this be acceptable?

<==> input/entrypoint.scss
@import "direct";

a {
  color: $variable;
}

<==> input/_direct.scss
@import "~module/indirect";

<==> input/node_modules/module/_indirect.scss
$variable: green;

<==> output/entrypoint.scss
@use "node_modules/module/indirect";
@use "direct";

a {
  color: indirect.$variable;
}

<==> output/_direct.scss
@use "~module/indirect";

I could change _absoluteUrlToDependency to add ~ URLs as one of its options, but would we want to generate those URLs even for users that weren't already using them?

nex3 commented 5 years ago

I don't love either of those options... could you track the original URLs for stylesheets and re-use them if they came from load paths or the Webpack importer?

jathak commented 5 years ago

Okay, I think that should be doable. For detecting whether the original URL was resolved by the Webpack importer, I can just check whether the importer returned by ImportCache.import was the NodeModulesImporter, but I'm not sure how best to detect a relative import vs one from a load path.

jathak commented 5 years ago

I'm going to merge this now. I opened #90 to use the original URLs for imports from load paths.