diff --git a/spec/fixtures/packages/package-with-cached-incompatible-native-module/main.js b/spec/fixtures/packages/package-with-cached-incompatible-native-module/main.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/fixtures/packages/package-with-cached-incompatible-native-module/package.json b/spec/fixtures/packages/package-with-cached-incompatible-native-module/package.json new file mode 100644 index 000000000..1db0a0a9d --- /dev/null +++ b/spec/fixtures/packages/package-with-cached-incompatible-native-module/package.json @@ -0,0 +1,12 @@ +{ + "name": "package-with-cached-incompatible-native-module", + "version": "1.0.0", + "main": "./main.js", + "_atomModuleCache": { + "extensions": { + ".node": [ + "node_modules/native-module/build/Release/native.node" + ] + } + } +} diff --git a/spec/fixtures/packages/package-with-ignored-incompatible-native-module/package.json b/spec/fixtures/packages/package-with-ignored-incompatible-native-module/package.json index 70de63b9d..4f6206828 100644 --- a/spec/fixtures/packages/package-with-ignored-incompatible-native-module/package.json +++ b/spec/fixtures/packages/package-with-ignored-incompatible-native-module/package.json @@ -1,5 +1,5 @@ { - "name": "package-with-incompatible-native-module-and-atom-module-cache", + "name": "package-with-ignored-incompatible-native-module", "version": "1.0.0", "main": "./main.js", "_atomModuleCache": { diff --git a/spec/package-spec.coffee b/spec/package-spec.coffee index 8f7f2c0bf..e73782219 100644 --- a/spec/package-spec.coffee +++ b/spec/package-spec.coffee @@ -19,13 +19,16 @@ describe "Package", -> expect(pack.incompatibleModules[0].name).toBe 'native-module' expect(pack.incompatibleModules[0].path).toBe path.join(packagePath, 'node_modules', 'native-module') - it "utilizes _atomModuleCache to get native modules and skips traversing through submodules", -> + it "utilizes _atomModuleCache if present to determine the package's native dependencies", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-ignored-incompatible-native-module') pack = new Package(packagePath) - # Since `_atomModuleCache` exists and it doesn't have the record of the - # incompatible native module, this package is recognized as compatible. + expect(pack.getNativeModuleDependencyPaths().length).toBe(1) # doesn't see the incompatible module expect(pack.isCompatible()).toBe true + packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-cached-incompatible-native-module') + pack = new Package(packagePath) + expect(pack.isCompatible()).toBe false + it "caches the incompatible native modules in local storage", -> packagePath = atom.project.getDirectories()[0]?.resolve('packages/package-with-incompatible-native-module') diff --git a/src/package.coffee b/src/package.coffee index c38ea08f7..6170a645e 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -598,11 +598,10 @@ class Package nativeModulePaths = [] if @metadata._atomModuleCache? - nativeModuleBindingPaths = @metadata._atomModuleCache.extensions?['.node'] ? [] - for nativeModuleBindingPath in nativeModuleBindingPaths - # The `.node` file lies in nativeModulePath/build/Release/ folder. - nativeModulePath = path.join(path.dirname(nativeModuleBindingPath), '..', '..') - nativeModulePaths.push(nativeModulePath) if @isNativeModule(nativeModulePath) + relativeNativeModuleBindingPaths = @metadata._atomModuleCache.extensions?['.node'] ? [] + for relativeNativeModuleBindingPath in relativeNativeModuleBindingPaths + nativeModulePath = path.join(@path, relativeNativeModuleBindingPath, '..', '..', '..') + nativeModulePaths.push(nativeModulePath) return nativeModulePaths traversePath = (nodeModulesPath) =>