const ES6_IMPORT_FROM_REGEX = /import\s+.*\s+from\s+['"](.*)['"]/;
const CJS_IMPORT_FROM_REGEX = /require\(['"](.*)['"]\)/;

const path = require('path');
const fs = require('fs');
const PATH_SLASH = process.platform === 'win32' ? '\\' : '/';

const escapeRegExp = require('lodash.escaperegexp');
const parseModule = require('esm-exports').module;
const parseFile = require('esm-exports').file;

const getRealExportPrefix = (prefix, line) => {
  try {
    const es6ExportPrefixRegex = new RegExp(`(?:import\\s+{|import)\\s+((?:.+?)*${escapeRegExp(prefix)})`);
    const cjsExportPrefixRegex = new RegExp(`(?:var|const|let)\\s+\\{((?:.+?)*${escapeRegExp(prefix)})`, 'i');
    const exportMatch = es6ExportPrefixRegex.exec(line) || cjsExportPrefixRegex.exec(line);
    if (!exportMatch) {
      return false;
    }
    const exportPrefix = exportMatch[1];
    return exportPrefix.substring(exportPrefix.lastIndexOf(',') + 1).trim();
  } catch (e) {
    return false;
  }
}

const getImportModule = (textRow) => {
  try {
    let importMatch = ES6_IMPORT_FROM_REGEX.exec(textRow) || CJS_IMPORT_FROM_REGEX.exec(textRow);
    if (!importMatch) {
      return false;
    }
    return importMatch[1];
  } catch (e) {
    return false;
  }
}

const getExports = (activePanePath, prefix, importModule) => {
  return importModule[0] !== '.' ?
      lookupGlobal(importModule, activePanePath) :
      lookupLocal(importModule, activePanePath);
};

const lookupGlobal = (importModule, activePanePath) => {
  const projectPath = getProjectPath(activePanePath);
  return parseModule(importModule, {basedir: projectPath})
    .then(results => {
      if (results.length > 0) {
        return results.map(entry => entry.name);
      }
      const nodeModulePath = path.normalize(`${projectPath}/node_modules/${importModule}`);
      const mainfile = getMainFileName(nodeModulePath);
      return lookupCommonJs(mainfile, nodeModulePath);
    });
};

const getMainFileName = (nodeModulePath) => {
  const content = fs.readFileSync(path.resolve(nodeModulePath, 'package.json'), {encoding: 'utf8'});
  const mainFile = JSON.parse(content).main || 'index';
  return mainFile.substring(0, mainFile.lastIndexOf('.'));
};

const getProjectPath = (activePanePath) => {
  const [projectPath] = atom.project.relativizePath(activePanePath);
  return projectPath;
}

const lookupLocal  = (importModule, activePanePath) => {
  const filePath = activePanePath.substring(0, activePanePath.lastIndexOf(PATH_SLASH));
  return parseFile(importModule, {basedir: filePath})
    .then(results => results.length > 0 ?
      results.map(entry => entry.name) :
      lookupCommonJs(importModule, filePath))
    .catch(() => {
      return lookupCommonJs(importModule, filePath);
    });
};

const lookupCommonJs = (importModule, projectPath) => {
  const absoluteFile = path.resolve(projectPath, `${importModule}.js`);
  return Object.keys(require(path.normalize(absoluteFile)));
}

module.exports = {
  getRealExportPrefix,
  getImportModule,
  getExports
};

@@ -1965,32 +1965,58 @@
 odulePath) =%3E %7B%0A
+  let mainFile;%0A  try %7B%0A  
   const content 
@@ -2102,21 +2102,17 @@
 8'%7D);%0A  
-const
+ 
  mainFil
@@ -2154,23 +2154,153 @@
 dex';%0A  
-return 
+%7D%0A  catch(_e) %7B%0A    // if failed it must not a package root but a file.%0A    return path.resolve(%60$%7BnodeModulePath%7D.js%60);%0A  %7D%0A  return %60$%7B
 mainFile
@@ -2339,16 +2339,21 @@
 Of('.'))
+%7D.js%60
 ;%0A%7D;%0A%0Aco
@@ -2784,32 +2784,35 @@
  lookupCommonJs(
+%60$%7B
 importModule, fi
@@ -2799,32 +2799,37 @@
 (%60$%7BimportModule
+%7D.js%60
 , filePath))%0A   
@@ -2872,16 +2872,19 @@
 ommonJs(
+%60$%7B
 importMo
@@ -2887,16 +2887,21 @@
 rtModule
+%7D.js%60
 , filePa
@@ -2943,28 +2943,26 @@
 Js = (import
-Modu
+Fi
 le, projectP
@@ -3024,52 +3024,43 @@
 th, 
-%60$%7B
 import
-Module%7D.js%60);%0A  return Object.keys(
+File);%0A  const importedObj = 
 requ
@@ -3092,17 +3092,166 @@
 teFile))
-)
+;%0A  return (typeof importedObj === %22object%22) ? Object.keys(importedObj)%0A    : (typeof importedObj === %22function%22) ? %5BimportedObj.name%5D : %5BimportedObj%5D
 ;%0A%7D%0A%0Amod

Handle imports of JS files