taskr icon indicating copy to clipboard operation
taskr copied to clipboard

task.source doesn't take effect after a yeild task

Open stkevintan opened this issue 6 years ago • 1 comments

I write a simple build task and a custom plugin usemin as following. I thought the files argument of the generator function in the usemin plugin should be .tmp/index.html but, I found that I'm wrong, it contains all the files which returned by the html task.

so why things become so weird? (maybe I should post this question on stackoverflow. sorry ....

export async function compile(task) {
  await task.start('clear');
  await task.parallel(['script', 'style', 'image', 'font', 'other', 'html']);
}
export async function build(task) {
  await task.start('compile');
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
}
module.exports = function (task, utils) {
 // ...
  task.plugin('usemin', { every: false }, function* (files, opts) {
    console.log(files.map(o=>o.dir).filter(o=>o.indexOf('.tmp')!==-1)); 
    // [] (empty array)
  });
}

stkevintan avatar Jul 24 '17 14:07 stkevintan

Hi! Unfortunately, this is the only quirky behavior that Taskr has. I haven't been able to spend time sorting it out yet.

Taskr's sub-tasks can get, uh, confused if trying to chain/start too many tasks from within tasks.

In this case, you can move task.start('compile') to after your usemin task:

export async function build(task) {
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
  await task.start('compile');
}

But I recommend keeping all tasks unqiue/simple and then running them from the CLI (or npm script) like this:

export async function build(task) {
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
}
// package.json
{
  "scripts": {
    "build": "taskr compile build"
  }
}

Either of those should work for you. Your plugin is fine 😄

lukeed avatar Jul 24 '17 18:07 lukeed