mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Unload package when uninstalled
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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."))
|
||||
|
||||
Reference in New Issue
Block a user