Fix use of _atomModuleCache in getNativeModuleDependencyPaths

Previously, we weren’t converting the relative path from the module
cache and the test wasn’t strong enough to detect this fact.
This commit is contained in:
Nathan Sobo 2015-09-17 17:21:34 -06:00
parent 0717c1d377
commit 6b66bf7b0a
5 changed files with 23 additions and 9 deletions

View File

@ -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"
]
}
}
}

View File

@ -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": {

View File

@ -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')

View File

@ -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) =>