kristerkari / react-native-sass-transformer

Use Sass to style your React Native apps.
MIT License
219 stars 19 forks source link

add application root to places to look for imports for importing othe… #6

Closed tim-steele closed 6 years ago

tim-steele commented 6 years ago

If I have a module in node_modules folder with a .scss extension that live inside of a name space, I am unable to reliably reference another node module in the node_modules folder without the root application directory being including in the search for imports.

Example:

node_modules/
    - @my-modules/
        - my-module-with-sass-import
    - module-with-sass
tim-steele commented 6 years ago

Here is an actual example of code I have that is breaking without this:

@import 'node_modules/sassfp/SassFP.scss';
@import './variables';
@import './properties';
kristerkari commented 6 years ago

Thanks for this!

I did not consider the case of importing from a top level folder, so I think that this fix will be useful.

tim-steele commented 6 years ago

Excellent. Thanks @kristerkari! Let me know when you have this merged in and a new version published so I can pull it in to our project.

kristerkari commented 6 years ago

I was looking at stack overflow and thinking that would it be better to do this to avoid the dependency?

var path = require('path');
var appDir = path.dirname(require.main.filename);

That stack overflow answer says that it should work for almost all cases.

From: https://stackoverflow.com/a/18721515

kristerkari commented 6 years ago

What do you think about that @tim-steele?

tim-steele commented 6 years ago

Ha! Yes. I was reading the same answer. If you scroll down you will see the app-root-path method he talks about, and the module he built to try and handle all the situations as a sum of all of these. Let me know if you want me to use the one as I can make the change, or if you are fine using that person's node_module.

image

kristerkari commented 6 years ago

Using require.main.filename might be enough, as the description says:

This will work great most of the time, but if you're running your app with a launcher like pm2 or running mocha tests, this method will fail.

We are not running the code in any test environment or with pm2, so it should work. If it doesn't, we can change back to the app-root-path module :)

tim-steele commented 6 years ago

Sounds good @kristerkari. I updated the PR.

kristerkari commented 6 years ago

Great!

kristerkari commented 6 years ago

released as version 1.1.2