fix(plugin-ids): Lookup plugin id if pkg is not loaded

This commit is contained in:
Ben Gotow 2016-06-09 12:13:16 -07:00
parent 1e462a7cbf
commit a1995d4a15

View file

@ -48,6 +48,7 @@ class PackageManager
@packageDirPaths.push(path.join(configDirPath, "packages")) @packageDirPaths.push(path.join(configDirPath, "packages"))
@loadedPackages = {} @loadedPackages = {}
@cachedPackagePluginIds = {}
@packagesWithDatabaseObjects = [] @packagesWithDatabaseObjects = []
@activePackages = {} @activePackages = {}
@packageStates = {} @packageStates = {}
@ -56,9 +57,24 @@ class PackageManager
@registerPackageActivator(this, ['nylas']) @registerPackageActivator(this, ['nylas'])
pluginIdFor: (pluginName) => pluginIdFor: (packageName) =>
env = NylasEnv.config.get("env") env = NylasEnv.config.get("env")
return @loadedPackages[pluginName]?.metadata.appId?[env] cacheKey = "#{packageName}:#{env}"
if @cachedPackagePluginIds[cacheKey] is undefined
@cachedPackagePluginIds[cacheKey] = @_resolvePluginIdFor(packageName, env)
return @cachedPackagePluginIds[cacheKey]
_resolvePluginIdFor: (packageName, env) =>
metadata = @loadedPackages[packageName]?.metadata
unless metadata
packagePath = @resolvePackagePath(packageName)
return null unless packagePath
metadata = Package.loadMetadata(packagePath)
return metadata.appId[env] if metadata and metadata.appId instanceof Object
return null
### ###
Section: Event Subscription Section: Event Subscription