{"action":"closed","issue":{"url":"https://api.github.com/repos/stylus/stylus/issues/376","labels_url":"https://api.github.com/repos/stylus/stylus/issues/376/labels{/name}","comments_url":"https://api.github.com/repos/stylus/stylus/issues/376/comments","events_url":"https://api.github.com/repos/stylus/stylus/issues/376/events","html_url":"https://github.com/stylus/stylus/issues/376","id":1469809,"number":376,"title":"middleware compile imporperly marks files present","user":{"login":"rmustacc","id":613773,"avatar_url":"https://avatars.githubusercontent.com/u/613773?v=3","gravatar_id":"","url":"https://api.github.com/users/rmustacc","html_url":"https://github.com/rmustacc","followers_url":"https://api.github.com/users/rmustacc/followers","following_url":"https://api.github.com/users/rmustacc/following{/other_user}","gists_url":"https://api.github.com/users/rmustacc/gists{/gist_id}","starred_url":"https://api.github.com/users/rmustacc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmustacc/subscriptions","organizations_url":"https://api.github.com/users/rmustacc/orgs","repos_url":"https://api.github.com/users/rmustacc/repos","events_url":"https://api.github.com/users/rmustacc/events{/privacy}","received_events_url":"https://api.github.com/users/rmustacc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2011-08-23T20:59:54Z","updated_at":"2015-09-12T13:19:26Z","closed_at":"2015-09-12T13:19:26Z","body":"The current middleware function for stylus improperly notes files as present. This happens when the transformation to CSS succeeds, but the writeFile fails due to something like EACCES. The problem is that we're marking ```imports[stylusPath] = paths;``` before the writeFile. This allows for whatever the older version of the file on disk is to be used instead of the proper one.\r\n\r\nA fix based only on intuition might be to do this as part of the callback to writeFile.\r\n\r\nFor reference here is the current compile function from lib/middleware.js's 'middleware' function:\r\n\r\n```js\r\n      // Compile to cssPath\r\n      function compile() {\r\n        if (debug) log('read', stylusPath);\r\n        fs.readFile(stylusPath, 'utf8', function(err, str){\r\n          if (err) return error(err);\r\n          var style = options.compile(str, stylusPath);\r\n          var paths = style.options._imports = [];\r\n          delete imports[stylusPath];\r\n          style.render(function(err, css, js){\r\n            if (err) return next(err);\r\n            if (debug) log('render', stylusPath);\r\n            imports[stylusPath] = paths;\r\n            fs.writeFile(cssPath, css, 'utf8', function(err){\r\n              if (err) return next(err);\r\n              if (!js) return next();\r\n            });\r\n          });\r\n        });\r\n      }\r\n```"}}