Skip to content

Commit

Permalink
[Rename] kbn-uitls in packages directory to osd-utils (#38)
Browse files Browse the repository at this point in the history
* [Rename] kbn-uitls in packages directory to osd-utils

Signed-off-by: Mihir Soni <[email protected]>

* [Rename] in-corporate review comments

Signed-off-by: Mihir Soni <[email protected]>

* [Rename] in-corporate review comments

Signed-off-by: Mihir Soni <[email protected]>
  • Loading branch information
mihirsoni authored Mar 5, 2021
1 parent 19a5b2b commit 758ad15
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @kbn/utils
# @osd/utils

Shared server-side utilities shared across packages and plugins.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "@kbn/utils",
"name": "@osd/utils",
"main": "./target/index.js",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "tsc",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
"osd:bootstrap": "yarn build",
"osd:watch": "yarn build --watch"
},
"dependencies": {
"@kbn/config-schema": "1.0.0",
"@osd/config-schema": "1.0.0",
"load-json-file": "^6.2.0"
},
"devDependencies": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/

import path from 'path';
import { kibanaPackageJSON } from './';
import { opensearchDashboardsPackageJSON } from './';

it('parses package.json', () => {
expect(kibanaPackageJSON.name).toEqual('kibana');
expect(opensearchDashboardsPackageJSON.name).toEqual('opensearch-dashboards');
});

it('includes __dirname and __filename', () => {
const root = path.resolve(__dirname, '../../../../');
expect(kibanaPackageJSON.__filename).toEqual(path.resolve(root, 'package.json'));
expect(kibanaPackageJSON.__dirname).toEqual(root);
expect(opensearchDashboardsPackageJSON.__filename).toEqual(path.resolve(root, 'package.json'));
expect(opensearchDashboardsPackageJSON.__dirname).toEqual(root);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { dirname, resolve } from 'path';
import { REPO_ROOT } from '../repo_root';

export const kibanaPackageJSON = {
export const opensearchDashboardsPackageJSON = {
__filename: resolve(REPO_ROOT, 'package.json'),
__dirname: dirname(resolve(REPO_ROOT, 'package.json')),
...require(resolve(REPO_ROOT, 'package.json')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { accessSync, constants } from 'fs';
import { getConfigPath, getDataPath, getConfigDirectory } from './';

describe('Default path finder', () => {
it('should find a kibana.yml', () => {
it('should find a opensearch_dashboards.yml', () => {
const configPath = getConfigPath();
expect(() => accessSync(configPath, constants.R_OK)).not.toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@

import { join } from 'path';
import { accessSync, constants } from 'fs';
import { TypeOf, schema } from '@kbn/config-schema';
import { TypeOf, schema } from '@osd/config-schema';
import { REPO_ROOT } from '../repo_root';

const isString = (v: any): v is string => typeof v === 'string';

const CONFIG_PATHS = [
process.env.KBN_PATH_CONF && join(process.env.KBN_PATH_CONF, 'kibana.yml'),
process.env.KIBANA_PATH_CONF && join(process.env.KIBANA_PATH_CONF, 'kibana.yml'),
process.env.OSD_PATH_CONF && join(process.env.OSD_PATH_CONF, 'opensearch_dashboards.yml'),
process.env.OPENSEARCH_DASHBOARDS_PATH_CONF && join(process.env.OPENSEARCH_DASHBOARDS_PATH_CONF, 'opensearch_dashboards.yml'),
process.env.CONFIG_PATH, // deprecated
join(REPO_ROOT, 'config/kibana.yml'),
join(REPO_ROOT, 'config/opensearch_dashboards.yml'),
].filter(isString);

const CONFIG_DIRECTORIES = [
process.env.KBN_PATH_CONF,
process.env.KIBANA_PATH_CONF,
process.env.OSD_PATH_CONF,
process.env.OPENSEARCH_DASHBOARDS_PATH_CONF,
join(REPO_ROOT, 'config'),
'/etc/kibana',
'/etc/opensearch-dashboards',
].filter(isString);

const DATA_PATHS = [
process.env.DATA_PATH, // deprecated
join(REPO_ROOT, 'data'),
'/var/lib/kibana',
'/var/lib/opensearch-dashboards',
].filter(isString);

function findFile(paths: string[]) {
Expand All @@ -57,7 +57,7 @@ function findFile(paths: string[]) {
}

/**
* Get the path of kibana.yml
* Get the path of opensearch_dashboards.yml
* @internal
*/
export const getConfigPath = () => findFile(CONFIG_PATHS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import Fs from 'fs';

import loadJsonFile from 'load-json-file';

const readKibanaPkgJson = (dir: string) => {
const readOpenSearchDashboardsPkgJson = (dir: string) => {
try {
const path = Path.resolve(dir, 'package.json');
const json = loadJsonFile.sync(path);
if (json && typeof json === 'object' && 'name' in json && json.name === 'kibana') {
if (json && typeof json === 'object' && 'name' in json && json.name === 'opensearch-dashboards') {
return json;
}
} catch (error) {
Expand All @@ -38,19 +38,19 @@ const readKibanaPkgJson = (dir: string) => {
}
};

const findKibanaPackageJson = () => {
// search for the kibana directory, since this file is moved around it might
const findOpenSearchDashboardsPackageJson = () => {
// search for the opensearch-dashboards directory, since this file is moved around it might
// not be where we think but should always be a relatively close parent
// of this directory
const startDir = Fs.realpathSync(__dirname);
const { root: rootDir } = Path.parse(startDir);
let cursor = startDir;
while (true) {
const kibanaPkgJson = readKibanaPkgJson(cursor);
if (kibanaPkgJson) {
const opensearchDashboardsPkgJson = readOpenSearchDashboardsPkgJson(cursor);
if (opensearchDashboardsPkgJson) {
return {
kibanaDir: cursor,
kibanaPkgJson: kibanaPkgJson as {
opensearchDashboardsDir: cursor,
opensearchDashboardsPkgJson: opensearchDashboardsPkgJson as {
name: string;
branch: string;
},
Expand All @@ -59,13 +59,13 @@ const findKibanaPackageJson = () => {

const parent = Path.dirname(cursor);
if (parent === rootDir) {
throw new Error(`unable to find kibana directory from ${startDir}`);
throw new Error(`unable to find opensearch-dashboards directory from ${startDir}`);
}
cursor = parent;
}
};

const { kibanaDir, kibanaPkgJson } = findKibanaPackageJson();
const { opensearchDashboardsDir, opensearchDashboardsPkgJson } = findOpenSearchDashboardsPackageJson();

export const REPO_ROOT = kibanaDir;
export const UPSTREAM_BRANCH = kibanaPkgJson.branch;
export const REPO_ROOT = opensearchDashboardsDir;
export const UPSTREAM_BRANCH = opensearchDashboardsPkgJson.branch;
File renamed without changes.
File renamed without changes.

0 comments on commit 758ad15

Please sign in to comment.