michaelficarra / commonjs-everywhere

:rainbow: minimal CommonJS browser bundler with aliasing, extensibility, and source maps
BSD 3-Clause "New" or "Revised" License
158 stars 21 forks source link

-w option does not work on windows #60

Closed krisnye closed 11 years ago

krisnye commented 11 years ago

Repro on Windows 7 with Nodjs 0.10.5:

Create file main.js

exports.hello = function(){
    console.log("hello");
}

run

cjsify main.js --output output.js -w

edit file main.js result:

WARNING: watched file C:\NewProjects\cjsifybug\main.js has disappeared

output.js is also not updated.

michaelficarra commented 11 years ago

What editor are you using?

krisnye commented 11 years ago

Same result with: Notepad, Sublime Text, and even when the files it's watching are js files compiled by coffee -c.

michaelficarra commented 11 years ago

@krisnye: That's odd because it's using polling, not inode (or whatever the NTFS equivalent is) watching. I'm thinking this might be a node bug. Or just lack of Windows support. Can you try watching a file with node's fs.watch API and see if you can get it to trigger more than once by touching/modifying/overwriting it?

krisnye commented 11 years ago

fs.watch specifically or fs.watchFile ok?

I know fs.watchFile works on windows fine, and I use it in my file watcher https://github.com/krisnye/watchdirectory The watch and compile option in coffeescript also works fine.

krisnye commented 11 years ago

watchFile current object looks like this on windows:

change { dev: 0,
  mode: 33206,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  ino: 0,
  size: 179,
  atime: Fri May 10 2013 12:25:21 GMT-0700 (US Mountain Standard Time),
  mtime: Fri May 10 2013 13:24:55 GMT-0700 (US Mountain Standard Time),
  ctime: Fri May 10 2013 12:25:21 GMT-0700 (US Mountain Standard Time) }
change { dev: 0,
  mode: 33206,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  ino: 0,
  size: 179,
  atime: Fri May 10 2013 12:25:21 GMT-0700 (US Mountain Standard Time),
  mtime: Fri May 10 2013 13:24:59 GMT-0700 (US Mountain Standard Time),
  ctime: Fri May 10 2013 12:25:21 GMT-0700 (US Mountain Standard Time) }

curr.ino is always 0, so your unless statement exits early.

instead of

      unless curr.ino
        console.error "WARNING: watched file #{file} has disappeared"
        return

maybe check existence

      unless curr.ino?
        console.error "WARNING: watched file #{file} has disappeared"
        return
krisnye commented 11 years ago

I just verified locally that adding the ? to the unless.curr.ino works and fixes the build watching system on windows.

michaelficarra commented 11 years ago

Ah, nice. Want to send over a pull request?

krisnye commented 11 years ago

There you go. I should note that I can't build this on windows, so I didn't run any unit tests.

Have you ever built this on windows, and/or do you intend for it to build on windows?

michaelficarra commented 11 years ago

Unfortunately, MS Windows is a non-free OS. So unless somebody is going to buy me a Windows license (assuming it allows for virtualisation), I won't have a Windows machine to test on.

vendethiel commented 11 years ago

I think I can get you one windows8 x64 pro license. Managed to install it on a vm

krisnye commented 11 years ago

This curr.ino problem is related to this bug:

https://github.com/joyent/node/issues/2670

krisnye commented 11 years ago

Updated the pull request to be platform specific to 'win32'. Travis CI builds work now.