     timeEnd = @_timeEnd.bind this
     notify  = @_notify.bind this
 
-    manifests  = opts.manifests
-    watchingKd = no
+    manifests    = opts.manifests
+    watchingKd   = no
+    watchedGlobs = {}
 
     commons  = path.join opts.basedir, STYLES_COMMONS_GLOB
     includes = [ commons ]

SPRITES_TMPDIR              = '.sprites'
STYLES_KDJS_MODULE_NAME     = 'kd.js'
STYLES_KDJS_CSS_FILE        = 'dist/kd.css'
STYLES_COMMONS_GLOB         = 'app/lib/styl/commons/*.styl'
THROTTLE_WAIT               = 500

module.exports =


      styl manifest, globs


      if opts.watchCss and not watchedGlobs[globs.join()]
        watchedGlobs[globs.join()] = yes
        console.log "watching #{globs}"
        w = chokidar.watch globs, persistent: yes
        w.on 'ready', -> w.on 'raw', onRaw


    bunldeAllStyles = ->
      manifests.forEach (manifest) ->
        return  unless Array.isArray manifest.styles
        bundle manifest

    init = =>
      @on '_updated-sprites', bunldeAllStyles
      copyKd bunldeAllStyles

      commonsWatcher = chokidar.watch includes, persistent: yes
      commonRaw = (e, file) ->

        return  unless file

        if e in ['change','modified','deleted']
          console.log "updating all styles because common styles has changed!"
          bunldeAllStyles()

      commonsWatcher.on 'ready', -> commonsWatcher.on 'raw', throttle commonRaw, THROTTLE_WAIT


    if opts.sprites
      spriteSheets = path.join opts.spriteTmpCssOutdir, '*', \
        SPRITESMITH_CSS_NAME_PREFIX + '*x.' + SPRITESMITH_CSS_EXTENSION
      includes.push spriteSheets
      @once '_updated-sprites', init
    else
      init()



  _thirdparty: (done) ->
