Unload package when uninstalled

This commit is contained in:
Kevin Sawicki
2013-05-21 14:15:26 -07:00
parent 4277271992
commit 1fe576752b
3 changed files with 34 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ describe "the `atom` global", ->
window.rootView = new RootView
describe "package lifecycle methods", ->
describe ".loadPackage(id)", ->
describe ".loadPackage(name)", ->
describe "when the package has deferred deserializers", ->
it "requires the package's main module if one of its deferred deserializers is referenced", ->
pack = atom.loadPackage('package-with-activation-events')
@@ -19,6 +19,29 @@ describe "the `atom` global", ->
expect(object.constructor.name).toBe 'Foo'
expect(object.data).toBe 5
describe ".unloadPackage(name)", ->
describe "when the package is active", ->
it "throws an error", ->
pack = atom.activatePackage('package-with-main')
expect(atom.isPackageLoaded(pack.name)).toBeTruthy()
expect(atom.isPackageActive(pack.name)).toBeTruthy()
expect( -> atom.unloadPackage(pack.name)).toThrow()
expect(atom.isPackageLoaded(pack.name)).toBeTruthy()
expect(atom.isPackageActive(pack.name)).toBeTruthy()
describe "when the package is not loaded", ->
it "throws an error", ->
expect(atom.isPackageLoaded('unloaded')).toBeFalsy()
expect( -> atom.unloadPackage('unloaded')).toThrow()
expect(atom.isPackageLoaded('unloaded')).toBeFalsy()
describe "when the package is loaded", ->
it "no longers reports it as being loaded", ->
pack = atom.loadPackage('package-with-main')
expect(atom.isPackageLoaded(pack.name)).toBeTruthy()
atom.unloadPackage(pack.name)
expect(atom.isPackageLoaded(pack.name)).toBeFalsy()
describe ".activatePackage(id)", ->
describe "atom packages", ->
describe "when the package has a main module", ->

View File

@@ -79,6 +79,15 @@ _.extend atom,
else
throw new Error("Could not resolve '#{name}' to a package path")
unloadPackage: (name) ->
if @isPackageActive(name)
throw new Error("Tried to unload active package '#{name}'")
if pack = @getLoadedPackage(name)
delete @loadedPackages[pack.name]
else
throw new Error("No loaded package for name '#{name}'")
resolvePackagePath: (name) ->
return name if fsUtils.isDirectory(name)
path = fsUtils.resolve(config.packageDirPaths..., name)

View File

@@ -54,6 +54,7 @@ module.exports =
apmProcess = spawn(apm, ['uninstall', name])
apmProcess.on 'close', (code) =>
if code is 0
atom.unloadPackage(name)
callback()
else
callback(new Error("Uninstalling '#{name}' failed."))