 path = require 'path'
 
 _ = require 'underscore-plus'
-EmitterMixin = require('emissary').Emitter
 {Emitter} = require 'event-kit'
 fs = require 'fs-plus'
 Q = require 'q'

  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidLoadInitialPackages: (callback) ->
    @emitter.on 'did-load-initial-packages', callback
    @emitter.on 'did-load-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone

  onDidLoadAll: (callback) ->
    Grim.deprecate("Use `::onDidLoadInitialPackages` instead.")
    @onDidLoadInitialPackages(callback)

  # Public: Invoke the given callback when all packages have been activated.
  #

    stack = "#{error.stack}\n  at #{metadataPath}:1:1"
    message = "Failed to load the #{path.basename(packagePath)} package"
    atom.notifications.addError(message, {stack, detail, dismissable: true})

if Grim.includeDeprecations
  PackageManager::onDidLoadAll = (callback) ->
    Grim.deprecate("Use `::onDidLoadInitialPackages` instead.")
    @onDidLoadInitialPackages(callback)

  PackageManager::onDidActivateAll = (callback) ->
    Grim.deprecate("Use `::onDidActivateInitialPackages` instead.")
    @onDidActivateInitialPackages(callback)

  EmitterMixin = require('emissary').Emitter
  EmitterMixin.includeInto(PackageManager)
  PackageManager::on = (eventName) ->
    switch eventName
      when 'loaded'
        Grim.deprecate 'Use PackageManager::onDidLoadInitialPackages instead'
      when 'activated'
        Grim.deprecate 'Use PackageManager::onDidActivateInitialPackages instead'
      else
        Grim.deprecate 'PackageManager::on is deprecated. Use event subscription methods instead.'
    EmitterMixin::on.apply(this, arguments)
