From d47348e8f9ee0e3726db68f361a0433fedb3799a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 25 Jul 2014 15:34:03 -0700 Subject: [PATCH] Cache incompatible modules in local storage --- spec/package-spec.coffee | 19 +++++++++++++++++++ src/package.coffee | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/package-spec.coffee b/spec/package-spec.coffee index 70469d367..d54a9097a 100644 --- a/spec/package-spec.coffee +++ b/spec/package-spec.coffee @@ -12,6 +12,25 @@ describe "Package", -> expect(pack.incompatibleModules[0].name).toBe 'native-module' expect(pack.incompatibleModules[0].path).toBe path.join(packagePath, 'node_modules', 'native-module') + it "caches the incompatible native modules in local storage", -> + packagePath = atom.project.resolve('packages/package-with-incompatible-native-module') + cacheKey = null + cacheItem = null + + spyOn(global.localStorage, 'setItem').andCallFake (key, item) -> + cacheKey = key + cacheItem = item + spyOn(global.localStorage, 'getItem').andCallFake (key) -> + return cacheItem if cacheKey is key + + expect(new Package(packagePath).isCompatible()).toBe false + expect(global.localStorage.getItem.callCount).toBe 1 + expect(global.localStorage.setItem.callCount).toBe 1 + + expect(new Package(packagePath).isCompatible()).toBe false + expect(global.localStorage.getItem.callCount).toBe 2 + expect(global.localStorage.setItem.callCount).toBe 1 + describe "theme", -> theme = null diff --git a/src/package.coffee b/src/package.coffee index 64ddf1204..4f90132f6 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -362,8 +362,11 @@ class Package nativeModulePaths getIncompatibleNativeModules: -> - incompatibleNativeModules = [] + localStorageKey = "installed-packages:#{@name}:#{@metadata.version}" + {incompatibleNativeModules} = global.localStorage.getItem(localStorageKey) ? {} + return incompatibleNativeModules if incompatibleNativeModules? + incompatibleNativeModules = [] for nativeModulePath in @getNativeModuleDependencyPaths() try require(nativeModulePath) @@ -373,6 +376,7 @@ class Package name: path.basename(nativeModulePath) error: error + global.localStorage.setItem(localStorageKey, {incompatibleNativeModules}) incompatibleNativeModules # Public: Is this package compatible with this version of Atom?