nathggns / node-compass

Compass middleware for node.js.
43 stars 13 forks source link

crash on node 0.12 #36

Closed hansmbakker closed 9 years ago

hansmbakker commented 9 years ago

using node-compass 0.2.3

On index.js@line 233 there is a loop over the properties of a files object.

However, on node 0.12 this files object is just an array - you can do a forEach here.

The code expecting an object crashes here:

/somepath/node_modules/node-compass/index.js:237
            if (last(file.split('.')) === 'css') {
                          ^
TypeError: undefined is not a function
    at /somepath/node_modules/node-compass/index.js:237:27
    at FSReqWrap.oncomplete (fs.js:99:15)
hansmbakker commented 9 years ago

solution: line 67:

files.forEach (function(file) {
        var parts = file.split('.');

        if (['scss', 'sass'].indexOf(last(parts)) === -1) return;

        var name = last(parts[0].split('/'));
        var fullPath = path.join(path.join(opts.project, opts.sass), file);
        var cssPath = path.join(path.join(opts.project, opts.css), name) + '.css';

        if (!cache[cssPath]) return;

        need++;

        fs.stat(fullPath, getSassFunction(fullPath, cssPath, doneFunction));
      });

line 232:

files.forEach(function(file) {
            if (last(file.split('.')) === 'css') {
              need++;
              var full = path.join(path.join(opts.project, opts.sass), file);

              fs.readFile(full, getCSSFunction(full, doneFunction));
            }
          });
nathggns commented 9 years ago

While this is in a current rewrite, I think I'll write a patch for the current version to fix this now.

nathggns commented 9 years ago

This has nothing to do with the node version I think.

I think the middleware can't find your compass project files.

Right now it just assumes they're there. I'll work on fixing that.

nathggns commented 9 years ago

Try now. This is fixed in node-compass@0.2.4 I believe it was actually failing because you've misconfigured it but it'll tell you that if it is. Regardless, I've incorporated your "fix" because its just nicer code.

hansmbakker commented 9 years ago

I did console.log(files) and it contained an array ['style.scss', 'style.css'] instead of the files object that version 0.2.3 expected.

I haven't changed any configuration about fs.readDir and as documented here http://nodejs.org/api/fs.html#fs_fs_readdir_path_callback, fs.readDir returns an array of filenames on v0.12.0.

Thank you for fixing it, though :)