css-modules / postcss-modules-resolve-imports

Resolves ICSS imports
MIT License
9 stars 6 forks source link

root option #26

Closed carlhopf closed 6 years ago

carlhopf commented 6 years ago

by setting a custom root (f.ex. process.cwd) all resolved paths are relative to this directory.

this is useful if runner.process() is called for different entry points, which reference the same module.css file, which then will be resolved to the same path relative to root.

as an example, locally scoped classnames remain the same (as they are generated from the file path) between process runs

sullenor commented 6 years ago

as an example, locally scoped classnames remain the same (as they are generated from the file path) between process runs

As far as I remember the scoped classnames are generated with generateScopedName function in the other package: https://github.com/css-modules/postcss-icss-selectors/blob/master/src/index.js#L166 So the current change will affect only inlined comments with imports.

carlhopf commented 6 years ago

Thanks for the review!

The commit will not only change the inserted comments, but also the { from: absDependencyPath } passed to processor.process().

This path is then used as the file path by postcss plugins, f.ex. postcss-icss-selectors^2.0.0

generateScopedName defaults to "[name]__[local]---[hash:base64:5]", where name is the complete file name/path.

As a result local hashed scope names can be different for the same :imported file, depending on the top-level file.

The root option ensures all resolved paths are relative to the same directory.

I'll update the test case to postcss-icss-selectors^2.0.0 in a moment, to make this more clear.

What do you think?

carlhopf commented 6 years ago

Sorry, please disregard my last comment.

Rewriting the test cases I noticed that the path naming issue has mostly been resolved by preserve-symlinks already.

Closing this pull request until I find a case where a root option would remain useful.

sullenor commented 6 years ago

Sure,

thank you for you work!