electron-userland / electron-compilers

DEPRECATED: Compiler implementations for electron-compile
35 stars 55 forks source link

Ignored includePaths option #2

Closed parro-it closed 9 years ago

parro-it commented 9 years ago

Hi, I'm trying to use electron-compile to compile a sass file. I have to import bootstrap-sass, so I pass includePaths option to electron-compile

require('electron-compile').initWithOptions({
  cacheDir: join(__dirname, '/cache'),
  compilerOpts: {
    // Compiler options are a map of extension <=> options for compiler
    js: { stage: 0},
    scss: { includePaths: [
       join(__dirname, 'node_modules/bootstrap-sass/assets/stylesheets'),
        ]};
  }
});

But it appear that the option is just ignored... Digging in source files, I think I found that the problem is in electron-compilers/src/css/scss.js.

In method compile, you are overriding the includePaths option:

compile(sourceCode, filePath) {
    let paths = Object.keys(this.seenFilePaths);
    paths.unshift('.');

    let opts = _.extend({}, this.compilerInformation, {
      data: sourceCode,
      indentedSyntax: filePath.match(/\.sass$/i),
      sourceMapRoot: filePath,
      includePaths: paths,
      filename: path.basename(filePath)
    });

    let result = scss.renderSync(opts);
    return result.css.toString('utf8');
  }

I solved the problem by do a concat with the given option, saved in constructor:

compile(sourceCode, filePath) {
    let paths = Object.keys(this.seenFilePaths);
    paths.unshift('.');

   /////////////////////   /////////////////////   /////////////////////  
    paths = paths.concat(this.compilerInformation.includePaths);
   /////////////////////   /////////////////////   /////////////////////  
    let opts = _.extend({}, this.compilerInformation, {
      data: sourceCode,
      indentedSyntax: filePath.match(/\.sass$/i),
      sourceMapRoot: filePath,
      includePaths: paths,
      filename: path.basename(filePath)
    });

    let result = scss.renderSync(opts);
    return result.css.toString('utf8');
  }

If you think my solution it's ok, I can prepare a PR

anaisbetts commented 9 years ago

@parro-it Oops, I think you're right! Can you send a PR?

parro-it commented 9 years ago

Yes, sure, I'll prepare it soon.

anaisbetts commented 9 years ago

Fixed in #3