Skip to content

Commit

Permalink
split up cache based on upstream branch
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Oct 3, 2020
1 parent 939047b commit 2504b82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { REPO_ROOT } from '@kbn/utils';
export * from '@kbn/utils';
export { withProcRunner, ProcRunner } from './proc_runner';
export * from './tooling_log';
export * from './serializers';
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/src/node/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import Path from 'path';

// @ts-expect-error no types available
import * as LmdbStore from 'lmdb-store';
import { REPO_ROOT } from '@kbn/dev-utils';
import { REPO_ROOT, UPSTREAM_BRANCH } from '@kbn/dev-utils';

const CACHE_DIR = Path.resolve(REPO_ROOT, 'data/node_auto_transpilation_cache');
const CACHE_DIR = Path.resolve(REPO_ROOT, 'data/node_auto_transpilation_cache', UPSTREAM_BRANCH);
const reportError = () => {
// right now I'm not sure we need to worry about errors, the cache isn't actually
// necessary, and if the cache is broken it should just rebuild on the next restart
Expand Down
50 changes: 31 additions & 19 deletions packages/kbn-utils/src/repo_root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,50 @@ import Fs from 'fs';

import loadJsonFile from 'load-json-file';

const isKibanaDir = (dir: string) => {
const readKibanaPkgJson = (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') {
return true;
return json;
}
} catch (error) {
if (error && error.code === 'ENOENT') {
return false;
return;
}

throw error;
}
};

// search for the kibana 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) {
if (isKibanaDir(cursor)) {
break;
}
const findKibanaPackageJson = () => {
// search for the kibana 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) {
return {
kibanaDir: cursor,
kibanaPkgJson: kibanaPkgJson as {
name: string;
branch: string;
},
};
}

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

const { kibanaDir, kibanaPkgJson } = findKibanaPackageJson();

export const REPO_ROOT = cursor;
export const REPO_ROOT = kibanaDir;
export const UPSTREAM_BRANCH = kibanaPkgJson.branch;

0 comments on commit 2504b82

Please sign in to comment.