Comments (14)
This is interesting. I think I understand what you're trying to accomplish -- but first off, using a fake "force" no-op task to cause your download of bar-file to happen seems less than optimal. Also, if it's actually downloaded each time, won't it always overwrite what's on the filesystem? It's always going to appear to be a newer file. Or are you handling this in the task somewhere? Looks like what you want is some sort of etags-aware, remote file-task. Am I understanding this correctly?
from jake.
Exactly! I didn't think it could be a feature built into jake.
You are right about bar-file being etag-aware. I wrote a custom node script that downloads bar-file. It checks etag (and fallbacks to last-modified if etag is not supported) for the file's freshness, and only downloads a new copy when necessary.
If jake could support remote file-task, that would be awesome!
I'd also like to elaborate on my previous sample Jakefile. Since it's a valid Jakefile, I believe it exhibits some defect jake currently has.
Here is my another take on the file:
var fs = require('fs');
task('default', ['foo-file'], function() {});
file('foo-file', ['bar-file'], function() {
console.log('building foo-file');
fs.writeFile('./foo-file', 'foo-file content');
});
file('bar-file', ['force'], function() {
console.log('building bar-file');
try {
fs.statSync('./bar-file');
} catch (e) {
fs.writeFile('./bar-file', 'bar-file content');
}
});
task('force', function() {});
If both foo-file and bar-file don't exist before this jakefile is executed, the output should be building bar-file
building foo-file
on its first execution, and just building bar-file
on its second execution (since bar-file is older than foo-file, the foo-file task doesn't need to be run).
However, with jake 0.1.12, the output is building bar-file
building foo-file
for both executions.
from jake.
Okay, I've verified that this behavior is exactly what Rake does. It makes sense that if any file task has a non-file dependency, it will always run. If that task runs, any tasks that depends on it will run too. Also made the task-action callback optional. Now you can just define task('foo'); and it will be a no-op.
from jake.
If that task runs, any tasks that depends on it will run too
I'm not sure it's a correct behavior.
It's a file task, which means the task is supposed to generate/modify a file. When other tasks depend on this task, they actually depend on the file the task generates/modifies, not the task itself, so whether the task will always run shouldn't affect how these task run. These task should only check the file's existence or mtime. For they depend on a file, not a task.
What do you think?
from jake.
Okay, I've taken another look at this -- looks like Rake is doing the right thing, but Jake is not. Our problem is that Jake parses the dependency-tree all up-front for file tasks, whereas it ought to do it incrementally as execution occurs .This will require a substantial change to how dependency-parsing and task-running works. I'll leave this issue open, but it will take a while for this to get fixed.
from jake.
Thanks for deciding to fix it. :)
from jake.
Fixed in master 88690ff. Please verify, and I'll do a release.
from jake.
Just tested against 7fa59fa with this Jakefile, and it throws Error: ENOENT, No such file or directory 'foo-file'
. Looks like jake needs to use try & catch to check file's existence in jake.js line 266, not sure though.
var fs = require('fs');
task({default: ['foo-file']});
file({"foo-file": ['bar-file']}, function() {
console.log('building foo-file');
});
file({"bar-file": ['force']}, function() {
console.log('building bar-file');
});
task('force');
from jake.
Yes, I was assuming that the file-task should actually end up generating a file, and throw if it doesn't. But maybe you're right, a more reasonable behavior would be just to treat it like a normal task that has to run every time, and use the current time as the mod-time for the purposes of any file tasks higher up the tree. The fix is in 0278c80.
from jake.
Tested against 0278c80 with this Jakefile. On first execution, foo-file
task is executed, but not bar-file
task. On second execution, none is executed.
var fs = require('fs');
task({default: ['foo-file']});
file({"foo-file": ['bar-file']}, function() {
console.log('building foo-file');
fs.writeFile('foo-file', 'foo-file content');
});
file({"bar-file": ['force']}, function() {
console.log('building bar-file');
try {
fs.statSync('bar-file');
} catch (e) {
fs.writeFile('bar-file', 'bar-file content');
}
});
task('force');
from jake.
Do you think I should fire another issue for adding remote file task support?
from jake.
Okay, I've verified with HEAD (5c0a7f9) that it runs both bar and foo the first time, and only bar subsequent times:
mdes-mbp:jake mde$ node ./bin/cli.js -f ./tests/Jakefile4 -t -C /Users/mde/work/jake
building bar-file
building foo-file
mdes-mbp:jake mde$ node ./bin/cli.js -f ./tests/Jakefile4 -t -C /Users/mde/work/jake
building bar-file
As for remote files -- you can sure add another issue, but there's so much I still have to do with PackageTask that I'm not sure how long it'll be before I can get to it.
You could use this trick of modifying a local stub-file when the remote file has changed, or if you want, you could try doing an implementation of remoteFile yourself. :) I'm happy to give you some direction on where to look in the code if you'd like to take a stab at it.
from jake.
I'm definitely interested in implementing it. Where should I start to look?
(Should we head to some irc channel?)
from jake.
The globalized API calls (task, file, etc.) are defined in lib/api.js. Maybe take a look at how file defers to createTask, and think about how to implement a new task-type. In the longer term, I'm planning on changing from generic Task instances with a type property, to Task with sub-classing, e.g., FileTask, DirectoryTask, etc. I've starte a #jake IRC channel on Freenode, if you want to talk more.
from jake.
Related Issues (20)
- jake --tasks includes Symbol.for("nodejs.rejection")
- Jake is not recognized as cndket/function/script or more,please check the spelling of names HOT 5
- No output for .execSync on Windows HOT 2
- Using import in jakefile HOT 9
- fix file task not working as expect HOT 1
- Security issue
- Possible command injection in jake with publishTask HOT 4
- Can A Rule Be An Async Function?
- Cannot find module 'jake'. WHHAATT!? HOT 9
- Concurrency and invoke() cause prerequisites to be skipped HOT 1
- When can we see the latest version of jakejs published to NPM ? HOT 2
- ChainAlert: npm package release (10.8.3) has no matching tag in this repo
- Error `Cannot read property '1' of null` when running `jake -T` HOT 4
- Update "async": Security vulnerability, prototype pollution HOT 14
- Crash when running a ES6 Jakefile
- Security issue HOT 1
- FileList glob expressions containing * or ** do not match any files on Windows
- Jake fails to properly use environment variables passed as arguments when value contains equal sign HOT 4
- File task dependency handling buggy
- --tasks print source code of jakefile.js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jake.