mde/jake — Issue #90: file-task callback order Error: ENOENT, no such file or directory
Author: krunkosaurus
Created: 2012-01-06 04:59:50+00:00
State: open

I'm unclear if this is a bug or just the way it works. But it was bothering me for a few hours until I fully understood what was going on.

Say you have a directory of files:

old1.txt old2.txt

If you run this script:

```javascript
exec = require('child_process').exec;

file('new.txt', ['old.txt', 'old2.txt'], function(){
console.log('new is out of date!');
exec('touch new.txt');
});

task('default', ['new.txt'], function(){
console.log('Done with tasks.');
});

```

You will get this error:

> $ jake
> new is out of date!
> jake aborted.
> Error: ENOENT, no such file or directory 'new.txt'
> at Object.statSync (fs.js:414:18)
> (See full trace by running task with --trace)

But if you write it like this:

```javascript
exec = require('child_process').exec;

file('new.txt', ['old.txt', 'old2.txt'], function(){
exec('touch new.txt');
console.log('new is out of date!');
});

task('default', ['new.txt'], function(){
console.log('Done with tasks.');
});

```

It works fine. (Note that the exec was moved to the first line instead of the console log.)