Repository: atom/atom
File: src/package.js (JavaScript)

Code before:
  //
  // First try to get this information from
  // @metadata._atomModuleCache.extensions. If @metadata._atomModuleCache doesn't
  // exist, recurse through all dependencies.
  // @return {Map<string, string>} a map of all the module paths to the `.node` files
  getNativeModuleDependencyPaths() {
    const nativeModulePaths = new Map();

    if (this.metadata._atomModuleCache) {
      const relativeNativeModuleBindingPaths =
        (this.metadata._atomModuleCache.extensions &&
          this.metadata._atomModuleCache.extensions['.node']) ||
        [];
      for (let relativeNativeModuleBindingPath of relativeNativeModuleBindingPaths) {
        const nativeModulePath = path.join(
          this.path,
          relativeNativeModuleBindingPath,
          '..',
          '..',
          '..'
        );
        const nodeFilePaths = nativeModulePaths.get(nativeModulePath) || [];
        nativeModulePaths.set(
          nativeModulePath,
          nodeFilePaths.push(relativeNativeModuleBindingPath)
        );
      }
      return nativeModulePaths;
    }

    var traversePath = nodeModulesPath => {
      try {
        for (let modulePath of fs.listSync(nodeModulesPath)) {
          const modulePathNodeFiles = this.isNativeModule(modulePath);
          if (modulePathNodeFiles) {
            nativeModulePaths.set(modulePath, modulePathNodeFiles);
          }
          traversePath(path.join(modulePath, 'node_modules'));
        }
      } catch (error) {}
    };

    traversePath(path.join(this.path, 'node_modules'));

    return nativeModulePaths;
  }

  /*
  Section: Native Module Compatibility
  */


Review comment (performance):
We need to be able to get the `.node` file path, but I cannot understand how this part of the code works. Atom never gets in this path when I run it in `--dev` mode (`this.metadata._atomModuleCache` is always false). So, not sure if this part is correct or even how to trigger Atom to come in this code path.

Code after:
        ['.node']
      );
      return modulePathNodeFiles;
    } catch (error) {
      return [];
    }
  }

  // Get a Map of all the native modules => the `.node` files that this package depends on.
  //
  // First try to get this information from
  // @metadata._atomModuleCache.extensions. If @metadata._atomModuleCache doesn't
  // exist, recurse through all dependencies.
  getNativeModuleDependencyPathsMap() {
    const nativeModulePaths = new Map();

    if (this.metadata._atomModuleCache) {
      const nodeFilePaths = [];
      const relativeNativeModuleBindingPaths =
        (this.metadata._atomModuleCache.extensions &&
          this.metadata._atomModuleCache.extensions['.node']) ||
        [];
      for (let relativeNativeModuleBindingPath of relativeNativeModuleBindingPaths) {
        const nodeFilePath = path.join(
          this.path,
          relativeNativeModuleBindingPath,
          '..',
          '..',
          '..'
        );
        nodeFilePaths.push(nodeFilePath);
      }
      nativeModulePaths.set(this.path, nodeFilePaths);
      return nativeModulePaths;
    }

    var traversePath = nodeModulesPath => {
      try {
        for (let modulePath of fs.listSync(nodeModulesPath)) {
          const modulePathNodeFiles = this.getModulePathNodeFiles(modulePath);
          if (modulePathNodeFiles) {
            nativeModulePaths.set(modulePath, modulePathNodeFiles);
          }
          traversePath(path.join(modulePath, 'node_modules'));
        }
      } catch (error) {}
    };

    traversePath(path.join(this.path, 'node_modules'));

    return nativeModulePaths;