jakejs / jake

JavaScript build tool, similar to Make or Rake. Built to work with Node.js.
http://jakejs.com
Apache License 2.0
1.97k stars 190 forks source link

Error: ENOENT from File task #336

Closed BurtHarris closed 7 years ago

BurtHarris commented 7 years ago

I'm really just getting started with jake, but seem to be running into a wall repeatedly. I'm wondering if this is a windows-specific bug. I see similar error mentioned in issue #151, which also seems to be using Windows-style C:\... paths.

Am I doing something wrong? My jakefile:

const process = require('process')

const jarFile = `./tool/target/antlr4-typescript-4.6-SNAPSHOT-complete.jar`

const toolSources = new jake.FileList()
    .include(`tool/**`)
    .exclude(`tool/target/**`);

file(jarFile, toolSources, function () {
    console.log("building jar");
    process.chdir('tool')
    jake.exec(['npm i'])
})

task('default', [jarFile])

When the jarFile doesn't exist, then jake aborts...

C:\code\antlr4ts>jake --trace
building jar
jake aborted.
Error: ENOENT: no such file or directory, stat 'C:\code\antlr4ts\tool\tool\target\antlr4-typescript-4.6-SNAPSHOT-complete.jar'
    at Object.fs.statSync (fs.js:968:11)
    at FileTask.FileBase.updateModTime (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\file_task.js:82:20)
    at FileTask.FileBase.complete (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\file_task.js:89:12)
    at FileTask.TaskBase.run (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:290:12)
    at FileTask.TaskBase.runPrereqs (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:174:12)
    at FileTask.TaskBase.invoke (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:110:10)
    at TaskBase.nextPrereq (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:208:26)
    at TaskBase.runPrereqs (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:170:14)
    at TaskBase.invoke (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:110:10)
    at TaskBase.nextPrereq (C:\Users\Burt_\AppData\Roaming\nvm\v7.10.0\node_modules\jake\lib\task\task.js:208:26)
BurtHarris commented 7 years ago

Timing bug. If I single step through it, it seems to work. Seems like Jake may think the child process is complete before it really is.

mde commented 7 years ago

From a quick glance at your Jakefile, it looks like it is likely an async problem. The jake.exec in involves an async child-process operation, and you aren't waiting for it to get finished. The docs (http://jakejs.com/) have a lot of examples of how to use either async tasks, or evented tasks.

mde commented 7 years ago

Also worth noting that jake.exec was implemented circa Node version 0.3 because callbacks with Node's async exec were annoying to work with. Node now has execSync which is probably preferable to use.

BurtHarris commented 7 years ago

Thanks. Have I got this right? The simple approach is to use execSync, but I gather that won't achieve as much concurrency (not a particularly big issue for my case, everything else depends on building the tool sub-directory.

mde commented 7 years ago

That's right. Node folks can be really dogmatic about wanting everything async and streaming, but for a build tool manipulating stuff that's on local disk, async/streaming doesn't buy you a lot, and just makes your code needlessly complicated.