{"action":"created","issue":{"url":"https://api.github.com/repos/flyjs/fly/issues/193","repository_url":"https://api.github.com/repos/flyjs/fly","labels_url":"https://api.github.com/repos/flyjs/fly/issues/193/labels{/name}","comments_url":"https://api.github.com/repos/flyjs/fly/issues/193/comments","events_url":"https://api.github.com/repos/flyjs/fly/issues/193/events","html_url":"https://github.com/flyjs/fly/issues/193","id":171866523,"number":193,"title":"`fly.clear` is executed early / not awaited","user":{"login":"frantic1048","id":3102803,"avatar_url":"https://avatars.githubusercontent.com/u/3102803?v=3","gravatar_id":"","url":"https://api.github.com/users/frantic1048","html_url":"https://github.com/frantic1048","followers_url":"https://api.github.com/users/frantic1048/followers","following_url":"https://api.github.com/users/frantic1048/following{/other_user}","gists_url":"https://api.github.com/users/frantic1048/gists{/gist_id}","starred_url":"https://api.github.com/users/frantic1048/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frantic1048/subscriptions","organizations_url":"https://api.github.com/users/frantic1048/orgs","repos_url":"https://api.github.com/users/frantic1048/repos","events_url":"https://api.github.com/users/frantic1048/events{/privacy}","received_events_url":"https://api.github.com/users/frantic1048/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/flyjs/fly/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-18T10:14:53Z","updated_at":"2016-08-19T03:38:14Z","closed_at":null,"body":"versions:\r\n\r\n**Platform:** Arch Linux 4.6.5-1-zen x86_64 latest\r\n**Node:**  v6.4.0\r\n**Fly version:** 1.3.1\r\n\r\nIt's a little hard to describe the issue. First of all, I will explain what the sample contains. And then I describe the operations and what's weird.\r\n\r\n# sample project\r\n\r\noverall sturcture:\r\n\r\n```plain\r\n.\r\n├── dist            // output path\r\n├── flyfile.js\r\n├── node_modules\r\n├── package.json\r\n└── src             // source path\r\n    ├── a\r\n    │   ├── a1.txt\r\n    │   ├── a2.txt\r\n    │   ├── a3.txt\r\n    │   └── a4.txt\r\n    └── b\r\n        ├── b1.txt\r\n        ├── b2.txt\r\n        ├── b3.txt\r\n        └── b4.txt\r\n```\r\n\r\n**flyfile.js** : just some copy/paste tasks and a clean task, and two top-level task to run tasks in serial/parallel.\r\n\r\n```js\r\nconst paths = {\r\n  a: {\r\n    source: 'src/a/*.txt',\r\n    target: 'dist/a'\r\n  },\r\n  b: {\r\n    source: 'src/b/*.txt',\r\n    target: 'dist/b'\r\n  },\r\n  all: {target: 'dist'}\r\n}\r\n\r\nexports.clean = function * () {\r\n  yield this.clear(paths.all.target)\r\n}\r\n\r\nexports.a = function * () {\r\n  yield this\r\n    .source(paths.a.source)\r\n    .target(paths.a.target)\r\n}\r\n\r\nexports.b = function * () {\r\n  yield this\r\n    .source(paths.b.source)\r\n    .target(paths.b.target)\r\n}\r\n\r\nexports.serial = function * () {\r\n  yield this.start('clean')\r\n  yield this.start('a')\r\n  yield this.start('b')\r\n}\r\n\r\nexports.parallel = function * () {\r\n  yield this.start('clean')\r\n  yield this.start(['a', 'b'], {parallel: true})\r\n}\r\n```\r\n\r\n**package.json** : the only dependency is fly, just `npm i` to install it.\r\n\r\n```json\r\n{\r\n  \"name\": \"fly-missing-file\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"\",\r\n  \"main\": \"index.js\",\r\n  \"scripts\": {\r\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\",\r\n    \"cc\": \"fly clean\",\r\n    \"s\": \"DEBUG=\\\"fly*\\\" fly serial\",\r\n    \"p\": \"DEBUG=\\\"fly*\\\" fly parallel\"\r\n  },\r\n  \"keywords\": [],\r\n  \"author\": \"\",\r\n  \"license\": \"ISC\",\r\n  \"devDependencies\": {\r\n    \"fly\": \"^1.3.1\"\r\n  }\r\n}\r\n```\r\n\r\n**.txt** : every .txt file is just *Lorem ipsum* . Other content also is ok.\r\n\r\n```plain\r\nLorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam, iste, iure, quod voluptates soluta quidem commodi animi recusandae unde obcaecati amet eaque facere similique. Necessitatibus, iusto possimus minima numquam modi.\r\n```\r\n\r\n# reproducing operation\r\n\r\nEnsure you have runned `npm install` to get the dependencies ready.\r\n\r\nNow, the `dist` folder is empty, we run paralleled task.\r\n\r\n```bash\r\nnpm run p\r\n```\r\n\r\nThen `dist` becomes:\r\n\r\n```plain\r\ndist/\r\n├── a\r\n│   ├── a1.txt\r\n│   ├── a2.txt\r\n│   ├── a3.txt\r\n│   └── a4.txt\r\n└── b\r\n    ├── b1.txt\r\n    ├── b2.txt\r\n    ├── b3.txt\r\n    └── b4.txt\r\n```\r\n\r\nEvery thing works great. Then we run the paralled task the second time.\r\n\r\n```bash\r\nnpm run p\r\n```\r\n\r\nThen whole `dist` disappeared, even the `dist` folder itself. While debug log shows all the *.txt were written.\r\n\r\nWe can type `npm run p` again, then all the files are back. This time we delete some of the output file:\r\n\r\n```plain\r\ndist/\r\n├── a\r\n│   ├── a1.txt\r\n│   └── a2.txt\r\n└── b\r\n    └── b4.txt\r\n```\r\n\r\nThen type `npm run p`, we get:\r\n\r\n```plain\r\ndist/\r\n├── a\r\n│   ├── a3.txt\r\n│   └── a4.txt\r\n└── b\r\n    ├── b1.txt\r\n    ├── b2.txt\r\n    └── b3.txt\r\n```\r\n\r\nIt just like all the output are \"inverted\", this situation also happens replacing all the `npm run p` by `npm run s`(serial version).\r\n\r\nAnd every time running `npm run p`, the debug log shows every output file was written, log like:\r\n\r\n```plain\r\n[frantic@RabbitHouseCafe fly-missing-file]$ npm run p\r\n\r\n> fly-missing-file@1.0.0 p /home/frantic/work/demoo/fly-missing-file\r\n> DEBUG=\"fly*\" fly parallel\r\n\r\n  fly:find find this file: flyfile.js +0ms\r\n  fly:plugins beginning to look for plugins +5ms\r\n  fly:find find this file: package.json +1ms\r\n  fly:read read this file: /home/frantic/work/demoo/fly-missing-file/package.json +0ms\r\n  fly:plugins parse fly-* plugins from `package.json` +2ms\r\n  fly chdir '/home/frantic/work/demoo/fly-missing-file' +1ms\r\n  fly:log Flying with /home/frantic/work/demoo/fly-missing-file/flyfile.js... +2ms\r\n  fly start [ 'parallel' ] in sequence +0ms\r\n  fly run 'parallel' +2ms\r\n  fly:log Starting parallel +0ms\r\n  fly start [ 'clean' ] in sequence +0ms\r\n  fly run 'clean' +0ms\r\n  fly:log Starting clean +0ms\r\n  fly clear [ 'dist' ] +0ms\r\n  fly:log Finished clean in 4 ms +4ms\r\n  fly start [ 'a', 'b' ] in parallel +0ms\r\n  fly run 'a' +0ms\r\n  fly:log Starting a +0ms\r\n  fly source [ 'src/a/*.txt' ] +0ms\r\n  fly run 'b' +3ms\r\n  fly:log Starting b +0ms\r\n  fly source [ 'src/b/*.txt' ] +0ms\r\n  fly:read read this file: src/a/a1.txt +6ms\r\n  fly:read read this file: src/a/a2.txt +0ms\r\n  fly:read read this file: src/a/a3.txt +0ms\r\n  fly:read read this file: src/a/a4.txt +0ms\r\n  fly:read read this file: src/b/b1.txt +1ms\r\n  fly:read read this file: src/b/b2.txt +0ms\r\n  fly:read read this file: src/b/b3.txt +0ms\r\n  fly:read read this file: src/b/b4.txt +0ms\r\n  fly:write write this file: dist/a/a1.txt +2ms\r\n  fly:write write this file: dist/a/a2.txt +1ms\r\n  fly:write write this file: dist/a/a3.txt +0ms\r\n  fly:write write this file: dist/a/a4.txt +0ms\r\n  fly:log Finished a in 13 ms +0ms\r\n  fly:write write this file: dist/b/b1.txt +1ms\r\n  fly:write write this file: dist/b/b2.txt +0ms\r\n  fly:write write this file: dist/b/b3.txt +0ms\r\n  fly:write write this file: dist/b/b4.txt +0ms\r\n  fly:log Finished b in 11 ms +0ms\r\n  fly:log Finished parallel in 18 ms +1ms\r\n```\r\n\r\ni.e. I haven't seen any file to output is missing in the log.\r\n\r\nSorry for such long text ~(>\\_<~)\r\n"},"comment":{"url":"https://api.github.com/repos/flyjs/fly/issues/comments/240919782","html_url":"https://github.com/flyjs/fly/issues/193#issuecomment-240919782","issue_url":"https://api.github.com/repos/flyjs/fly/issues/193","id":240919782,"user":{"login":"lukeed","id":5855893,"avatar_url":"https://avatars.githubusercontent.com/u/5855893?v=3","gravatar_id":"","url":"https://api.github.com/users/lukeed","html_url":"https://github.com/lukeed","followers_url":"https://api.github.com/users/lukeed/followers","following_url":"https://api.github.com/users/lukeed/following{/other_user}","gists_url":"https://api.github.com/users/lukeed/gists{/gist_id}","starred_url":"https://api.github.com/users/lukeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukeed/subscriptions","organizations_url":"https://api.github.com/users/lukeed/orgs","repos_url":"https://api.github.com/users/lukeed/repos","events_url":"https://api.github.com/users/lukeed/events{/privacy}","received_events_url":"https://api.github.com/users/lukeed/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T03:38:13Z","updated_at":"2016-08-19T03:38:13Z","body":"Well, the problem is that `fly.clear` isn't awaited. The command itself \"finishes\" but not its method. Aka, `fly.clear` was run but not _completed_ before your task starts. It's a simple `yield` missing somewhere, I bet.\r\n\r\nWe use `fs.writeFile` ([docs](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)), so the destination file is entirely replaced.\r\n\r\nThe only time this doesn't work is if you delete a source file -- the destination copy will still be there.... However, I do the same practice you do in my own projects. I don't have this problem. I have to look closely to see what's different."}}
{"actor":{"display_login":"lukeed"}}