{"action":"created","issue":{"url":"https://api.github.com/repos/substack/watchify/issues/239","labels_url":"https://api.github.com/repos/substack/watchify/issues/239/labels{/name}","comments_url":"https://api.github.com/repos/substack/watchify/issues/239/comments","events_url":"https://api.github.com/repos/substack/watchify/issues/239/events","html_url":"https://github.com/substack/watchify/issues/239","id":91599235,"number":239,"title":"Multiple file change events","user":{"login":"caspervonb","id":157787,"avatar_url":"https://avatars.githubusercontent.com/u/157787?v=3","gravatar_id":"","url":"https://api.github.com/users/caspervonb","html_url":"https://github.com/caspervonb","followers_url":"https://api.github.com/users/caspervonb/followers","following_url":"https://api.github.com/users/caspervonb/following{/other_user}","gists_url":"https://api.github.com/users/caspervonb/gists{/gist_id}","starred_url":"https://api.github.com/users/caspervonb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caspervonb/subscriptions","organizations_url":"https://api.github.com/users/caspervonb/orgs","repos_url":"https://api.github.com/users/caspervonb/repos","events_url":"https://api.github.com/users/caspervonb/events{/privacy}","received_events_url":"https://api.github.com/users/caspervonb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-06-28T13:23:10Z","updated_at":"2015-07-22T19:31:36Z","closed_at":null,"body":"*Watchify* seems to be doing something *different* internally when writing its output stream than *other compilers*, for example\r\n\r\n```js\r\nvar chokidar = require('chokidar');\r\nvar child = require('child_process');\r\nvar fs = require('fs');\r\nvar util = require('util');\r\n\r\nvar watcher = chokidar.watch('{output.js}', {\r\n  alwaysStat: true\r\n});\r\n\r\nwatcher.on('change', function (filename, stat) {\r\n  console.log('change %s (size: %s)', filename, util.inspect(stat.size));\r\n});\r\n\r\nvar ps = child.spawn('watchify', ['--outfile', 'output.js', 'index.js', '--verbose']);\r\nps.stdout.pipe(process.stdout);\r\nps.stderr.pipe(process.stderr);\r\n\r\nsetInterval(function() {\r\n  console.log('touch');\r\n\r\n  var input = fs.readFileSync('index.js', 'utf-8') + ' ';\r\n  fs.writeFileSync('index.js', input, 'utf-8');\r\n}, 1000);\r\n\r\nsetTimeout(function() {\r\n  process.exit(0);\r\n}, 10000);\r\n```\r\n```sh\r\n$ node watchify.js \r\ntouch\r\nchange output.js (size: 0)\r\n124676 bytes written to output.js (0.04 seconds)\r\nchange output.js (size: 124676)\r\n```\r\n\r\nWhere-as webpack in with the same use case results in a single change event\r\n```js\r\nvar chokidar = require('chokidar');\r\nvar child = require('child_process');\r\nvar fs = require('fs');\r\nvar util = require('util');\r\n\r\nvar watcher = chokidar.watch('{output.js}', {\r\n  alwaysStat: true\r\n});\r\n\r\nwatcher.on('change', function (filename, stat) {\r\n  console.log('change %s (size: %s)', filename, util.inspect(stat.size));\r\n});\r\n\r\nvar ps = child.spawn('webpack', ['--watch', '--output-file', 'output.js', 'index.js']);\r\nps.stdout.pipe(process.stdout);\r\nps.stderr.pipe(process.stderr);\r\n\r\nsetInterval(function() {\r\n  console.log('touch');\r\n\r\n  var input = fs.readFileSync('index.js', 'utf-8') + ' ';\r\n  fs.writeFileSync('index.js', input, 'utf-8');\r\n}, 1000);\r\n\r\nsetTimeout(function() {\r\n  process.exit(0);\r\n}, 10000);\r\n```\r\n```sh\r\n$ node webpack.js\r\n\r\ntouch\r\nHash: 0bd844fa25ecb086e1d9\r\nVersion: webpack 1.10.0\r\nTime: 21ms\r\n    Asset    Size  Chunks             Chunk Names\r\noutput.js  130 kB       0  [emitted]  main\r\n   [0] ./index.js 132 bytes {0} [built]\r\n    + 23 hidden modules\r\nchange output.js (size: 129664)\r\n```\r\n\r\nTreating size 0 as an edge case is somewhat trivial, but have also run into cases where change events are emitted 3-4 times when the file is in a fragmented state, babel, coffee and tsc don't seem to exhibit this behaviour either. Have not been able to reproduce this directly with fs.writeFile or fs.createWriteStream either.\r\n\r\nAny idea why is watchify behaving so differently from the rest? "},"comment":{"url":"https://api.github.com/repos/substack/watchify/issues/comments/123836903","html_url":"https://github.com/substack/watchify/issues/239#issuecomment-123836903","issue_url":"https://api.github.com/repos/substack/watchify/issues/239","id":123836903,"user":{"login":"zertosh","id":830952,"avatar_url":"https://avatars.githubusercontent.com/u/830952?v=3","gravatar_id":"","url":"https://api.github.com/users/zertosh","html_url":"https://github.com/zertosh","followers_url":"https://api.github.com/users/zertosh/followers","following_url":"https://api.github.com/users/zertosh/following{/other_user}","gists_url":"https://api.github.com/users/zertosh/gists{/gist_id}","starred_url":"https://api.github.com/users/zertosh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zertosh/subscriptions","organizations_url":"https://api.github.com/users/zertosh/orgs","repos_url":"https://api.github.com/users/zertosh/repos","events_url":"https://api.github.com/users/zertosh/events{/privacy}","received_events_url":"https://api.github.com/users/zertosh/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T19:31:36Z","updated_at":"2015-07-22T19:31:36Z","body":"> Implementation detail, With streams3, we could just cork the bundle stream I think?\r\n\r\n`cork` would be equivalent to just passing a callback to `bundle()`. So to be clear, the problem isn't the delay between writes - it's the delay between the creation of the write stream and the first output write. \r\n\r\nUsing your test, waiting for the bundle stream to emit `readable` and then creating the output stream seems to work. I'm testing a few more ideas."}}