lukeed / taskr

A fast, concurrency-focused task automation tool.
MIT License
2.53k stars 75 forks source link

Duplication of files (in wrong dirs) when doing multiple dir copies #310

Open tmarshall opened 6 years ago

tmarshall commented 6 years ago

I have a taskfile that has a portion like this:

module.exports.copyProcs = async function copyProcs(task) {
  await task.source('procs/**/*.js').target('dist/procs')
  await task.source('procs/**/.*').target('dist/procs')
}

module.exports.copyConf = async function copyConf(task) {
  await task.source('conf/**/.*').target('dist/conf')
}

module.exports.copyDirs = async function copyDirs(task) {
  await task.parallel(['copyProcs', 'copyConf'])
}

module.exports.build = async function build(task) {
  // compile is not necessary to show
  await task.serial(['compile', 'copyDirs'])
} 

taskr build is my yarn build

This should copy all .js files and . files (specifically .gitignore) from procs to dist/procs

It should also copy all . files (specifically .eslintrc and .jscsrc) from conf to dist/conf

When run, it is copying .eslintrc and .jscsrc to both dist/conf and dist/procs.

If I change the content of function copyDirs to await task.serial(['copyProcs', 'copyConf']) it works as expected.

Not sure what the reason it.

tmarshall commented 6 years ago

^ full taskfile content (with serial fix) here: https://github.com/ConjureLabs/hob/blob/master/taskfile.js

hzlmn commented 6 years ago

Hi, i guess it is known issue, this is because when you run run tasks in parallel they started at the same time and share same internal context. That's why some internal vars polluted. Simple fix will be just to use serial in copyDirs task.

tmarshall commented 6 years ago

@hzlmn did that, but seems non-intuitive. Can't scope context per job?