es128 / progeny

:baby: Recursively finds dependencies of style and template source files
MIT License
29 stars 15 forks source link

coerce buffer to string in parseDeps #2

Closed davidchambers closed 11 years ago

davidchambers commented 11 years ago

@antigoliath and I have been testing the fix for brunch/sass-brunch#17. We ran into an issue whereby parseDeps sometimes receives a buffer rather than a string as its first argument. This pull request fixes the problem by coercing the value to a string before splitting on \n.

es128 commented 11 years ago

Interesting. Passing encoding: 'utf8' to fs.readFile is supposed to take care of this. Can you tell anything distinct about the source files this is happening with?

Will merge regardless, this can't hurt anything.

davidchambers commented 11 years ago

I added console.log(Object.prototype.toString.call(data)) while investigating the problem:

$ brunch build
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object String]
[object Object]

/Users/dc/repos/fits/node_modules/sass-brunch/node_modules/progeny/lib/index.js:45
    deps = data.split('\n').map(function(line) {
                ^
TypeError: Object /* ==========================================================================
   Mixins for use in other stylesheets
   ========================================================================== */

@mixin fully-grown-child {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
 has no method 'split'
    at module.exports.parseDeps (/Users/dc/repos/fits/node_modules/sass-brunch/node_modules/progeny/lib/index.js:45:17)
    at module.exports.parseDeps (/Users/dc/repos/fits/node_modules/sass-brunch/node_modules/progeny/lib/index.js:114:20)
    at fs.readFile (fs.js:176:14)
    at /usr/local/lib/node_modules/brunch/node_modules/init-skeleton/node_modules/rimraf/node_modules/graceful-fs/graceful-fs.js:103:5
    at Object.oncomplete (fs.js:297:15)
make: *** [all] Error 1

This may shed some light on the issue.

es128 commented 11 years ago

Nah, I can't tell from that why this file decided to be an Object instead of a String. Oh well.