Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.

Conversation

@saschagehlich
Copy link
Contributor

@saschagehlich saschagehlich commented Jan 16, 2017

This allows you to @import files from specified includePaths in your .sass / .scss files. I also added a test suite (mocha) and a test for this feature.

A little description on what this actually does:

If an includePaths option is specified, the sass compiler calls Sass.importer and passes an importer method that correctly resolves the import requests by iterating over the include paths and resolving the request to the correct file name. It then writes the file content to emscripten's memory using Sass.writeFile and asks the sass compiler to use the specified path for the import.

@anaisbetts
Copy link
Contributor

Tests are all in electron-compile, put them there instead and use npm link to test your changes

src/css/sass.js Outdated

const { includePaths } = this.compilerOptions
if (includePaths) {
sass.importer(this.buildImporterCallback(includePaths))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix!

return (function (request, done) {
let file
if (request.file) {
done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/css/sass.js Outdated
if (file) {
const content = fs.readFileSync(file, { encoding: 'utf8' });
return sass.writeFile(file, content, () => {
done({ path: file })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return here too - even though we don't need it, just get in the habit of always writing return after a callback, it will save you much sanity in the long run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!stat.isFile()) return null;
return path;
} catch(e) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to debug log this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this - sass.js returns ~25 variations, each invalid one will fail here and trigger a debug log. In medium-sized projects with multiple sass files, this will generate a whole lot of unnecessary output. Correct me if I'm wrong :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saschagehlich Use the debug module, it will only log if a user set's their environment variables up explicitly to debug electron-compile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know about the debug module, but still, this would output 25 lines of debug information for every sass file that is being compiled. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, in that case we'll just hope that Sass provides enough debugging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If sass.js doesn't find an imported file, it reports an error anyway, so I guess that's fine

src/css/sass.js Outdated

fixWindowsPath(file) {
// Unfortunately, there's a bug in sass.js that seems to ignore the different
// path separators across platforms. We need to fix this.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give some examples of what gets passed in and what gets returned?

Copy link
Contributor Author

@saschagehlich saschagehlich Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ (see new commits)

@saschagehlich
Copy link
Contributor Author

While this PR works fine, it seems to break electron-compile's compiler-info.json.gz file, which does not include SassCompiler's compilerOptions anymore, causing the CompileCache to generate an incorrect digest when resolving a file from a packaged application. No idea where this comes from though. Any ideas @paulcbetts ?

@anaisbetts
Copy link
Contributor

@saschagehlich I'll look into it

@anaisbetts
Copy link
Contributor

Imma fix this up tomorrow, sorry it's taking foreverrrrr

@anaisbetts anaisbetts merged commit 2b50106 into electron-userland:master Jan 27, 2017
@anaisbetts
Copy link
Contributor

Hey @saschagehlich, sorry this took forever. Sass actually already had an option called paths which also keeps track of the seen directories, so I used that value instead. electron-compilers 5.4.0 has this change

@saschagehlich
Copy link
Contributor Author

@paulcbetts Cool, thanks! Were you able to reproduce the issue I mentioned above?

@anaisbetts
Copy link
Contributor

anaisbetts commented Jan 27, 2017

No, I tested it with an electron-forge demo app and it all worked (though I didn't try setting an explicit paths I don't see why it would be different), both dev and packaged modes

@saschagehlich
Copy link
Contributor Author

@paulcbetts I just started using electron-compile in a project again and it seems that paths is not a valid option for sass.js :(

@alexstrat
Copy link

Exactly the paths option is passed to the sass.js's compile and throw an error because not a valid option.

@alexstrat alexstrat mentioned this pull request Jun 16, 2017
@alexstrat
Copy link

Fixed in #75

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants