This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolver] use webpack-resolver for core logic (#15)
* [resolver] use webpack-resolver for core logic * use better name for `fromRoot()` function * [resolver] add default aliases from test_bundle * remove trailing whitespace * enabled node eslint-env * always look in kibana plugins also observe the kibanaPath * add eslint-plugin-import * replace find-root with pkg-up * add options info to readme * use pluginName config, if provided recurse up paths until a package.json file with a matching name is found, if pluginName is provided. throw if none is found * break index into multiple module files * add debugging info to readme * switch pluginName to rootPackageName * switch pluginName to rootPackageName * rename rootPath to projectRoot * remove pkg-up dependency * move resolution caching back to index
- Loading branch information
Showing
10 changed files
with
202 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
module.exports = { | ||
"env": { | ||
"commonjs": true, | ||
"es6": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
env: { | ||
commonjs: true, | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:import/errors', | ||
'plugin:import/warnings', | ||
], | ||
plugins: [ | ||
'import', | ||
], | ||
rules: { | ||
indent: ['error', 2], | ||
'linebreak-style': ['error', 'unix'], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'], | ||
'import/no-unresolved': [2, { commonjs: true, amd: true }] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const debug = require('debug')('eslint-plugin-import:resolver:kibana'); | ||
|
||
module.exports = debug; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
kibanaPath: '../kibana', | ||
pluginDirs: [], | ||
pluginPaths: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { resolve } = require('path'); | ||
const debug = require('./debug'); | ||
const defaults = require('./defaults'); | ||
|
||
let kibanaPath; | ||
|
||
/* | ||
* Resolves the path to Kibana, either from default setting or config | ||
*/ | ||
module.exports = function getKibanaPath(config, projectRoot) { | ||
if (kibanaPath) return kibanaPath; | ||
|
||
const inConfig = config != null && config.kibanaPath; | ||
|
||
kibanaPath = (inConfig) | ||
? resolve(config.kibanaPath) | ||
: resolve(projectRoot, defaults.kibanaPath); | ||
|
||
debug(`Resolved Kibana path: ${kibanaPath}`); | ||
return kibanaPath; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { dirname, resolve } = require('path'); | ||
const glob = require('glob-all'); | ||
|
||
const defaults = require('./defaults'); | ||
|
||
module.exports = function getPlugins(config, kibanaPath, projectRoot) { | ||
const pluginDirs = [ | ||
...(config.pluginDirs || defaults.pluginDirs), | ||
resolve(kibanaPath, 'plugins'), | ||
resolve(kibanaPath, 'src', 'core_plugins'), | ||
]; | ||
|
||
const globPatterns = [ | ||
...pluginDirs.map(dir => `${dir}/*/package.json`), | ||
...(config.pluginPaths || defaults.pluginPaths).map(path => `${path}/package.json`), | ||
]; | ||
const globOptions = { cwd: projectRoot }; | ||
|
||
return glob.sync(globPatterns, globOptions).map(pkgJsonPath => { | ||
const path = dirname(pkgJsonPath); | ||
const pkg = require(pkgJsonPath); | ||
return { | ||
name: pkg.name, | ||
directory: path, | ||
publicDirectory: resolve(path, 'public'), | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { dirname, resolve, parse } = require('path'); | ||
const { accessSync, readFileSync } = require('fs'); | ||
const debug = require('./debug'); | ||
|
||
function getRootPackageDir(dirRoot, dir, rootPackageName) { | ||
if (dirRoot === dir) return null; | ||
const pkgFile = resolve(dir, 'package.json'); | ||
|
||
try { | ||
accessSync(pkgFile); | ||
|
||
// if rootPackageName is not provided, stop when package.json is found | ||
if (!rootPackageName) return dir; | ||
|
||
// if rootPackageName is provided, check for match | ||
const { name } = JSON.parse(readFileSync(pkgFile)); | ||
if (name === rootPackageName) return dir; | ||
|
||
// recurse until a matching package.json is found | ||
return getRootPackageDir(dirRoot, dirname(dir), rootPackageName); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') return getRootPackageDir(dirRoot, dirname(dir), rootPackageName); | ||
throw e; | ||
} | ||
} | ||
|
||
module.exports = function getProjectRoot(file, config) { | ||
const { root, dir } = parse(resolve(file)); | ||
const { rootPackageName } = config; | ||
|
||
projectRoot = getRootPackageDir(root, dir, rootPackageName); | ||
if (projectRoot === null) throw new Error('Failed to find plugin root'); | ||
|
||
debug(`Resolved project root: ${projectRoot}`); | ||
return projectRoot; | ||
}; |
Oops, something went wrong.