Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rename] kbn-uitls in packages directory to osd-utils #38

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
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'),
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
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) => {
}
};

mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
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.