mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* chore(NA): auto bootstrap after removing node modules manually (#134961)
* chore(NA): mechanism for autobootstrap when manually removing node_modules
* fix(NA): check folders with isDirectory
* fix(NA): check folders with isDirectory
* fix(NA): check folders with isDirectory
* docs(NA): update typo on code comment
(cherry picked from commit 9a1e1d00a4
)
# Conflicts:
# packages/kbn-pm/dist/index.js
# packages/kbn-pm/src/commands/bootstrap.ts
# packages/kbn-pm/src/utils/bazel/index.ts
* update kbn/pm dist
* refact(NA): missing comma
Co-authored-by: spalger <spencer@elastic.co>
This commit is contained in:
parent
a6a2a6e96c
commit
cd49631953
5 changed files with 96 additions and 32 deletions
34
packages/kbn-pm/dist/index.js
vendored
34
packages/kbn-pm/dist/index.js
vendored
|
@ -8910,9 +8910,11 @@ const BootstrapCommand = {
|
|||
const kibanaProjectPath = ((_projects$get = projects.get('kibana')) === null || _projects$get === void 0 ? void 0 : _projects$get.path) || '';
|
||||
const runOffline = (options === null || options === void 0 ? void 0 : options.offline) === true;
|
||||
const reporter = _kbn_dev_utils_ci_stats_reporter__WEBPACK_IMPORTED_MODULE_1__["CiStatsReporter"].fromEnv(_utils_log__WEBPACK_IMPORTED_MODULE_2__["log"]);
|
||||
const timings = []; // Force install is set in case a flag is passed into yarn kbn bootstrap
|
||||
const timings = []; // Force install is set in case a flag is passed into yarn kbn bootstrap or
|
||||
// our custom logic have determined there is a chance node_modules have been manually deleted and as such bazel
|
||||
// tracking mechanism is no longer valid
|
||||
|
||||
const forceInstall = !!options && options['force-install'] === true; // Install bazel machinery tools if needed
|
||||
const forceInstall = !!options && options['force-install'] === true || (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_9__["haveNodeModulesBeenManuallyDeleted"])(kibanaProjectPath)); // Install bazel machinery tools if needed
|
||||
|
||||
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_9__["installBazelTools"])(rootPath); // Setup remote cache settings in .bazelrc.cache if needed
|
||||
|
||||
|
@ -54857,8 +54859,10 @@ __webpack_require__.r(__webpack_exports__);
|
|||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "runIBazel", function() { return _run__WEBPACK_IMPORTED_MODULE_2__["runIBazel"]; });
|
||||
|
||||
/* harmony import */ var _yarn_integrity__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(547);
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeYarnIntegrityFileIfExists", function() { return _yarn_integrity__WEBPACK_IMPORTED_MODULE_3__["removeYarnIntegrityFileIfExists"]; });
|
||||
/* harmony import */ var _yarn__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(547);
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeYarnIntegrityFileIfExists", function() { return _yarn__WEBPACK_IMPORTED_MODULE_3__["removeYarnIntegrityFileIfExists"]; });
|
||||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "haveNodeModulesBeenManuallyDeleted", function() { return _yarn__WEBPACK_IMPORTED_MODULE_3__["haveNodeModulesBeenManuallyDeleted"]; });
|
||||
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
|
@ -61285,6 +61289,7 @@ function observeReadable(readable) {
|
|||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeYarnIntegrityFileIfExists", function() { return removeYarnIntegrityFileIfExists; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "haveNodeModulesBeenManuallyDeleted", function() { return haveNodeModulesBeenManuallyDeleted; });
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(252);
|
||||
|
@ -61296,6 +61301,7 @@ __webpack_require__.r(__webpack_exports__);
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
// yarn integrity file checker
|
||||
|
||||
async function removeYarnIntegrityFileIfExists(nodeModulesPath) {
|
||||
try {
|
||||
|
@ -61307,6 +61313,26 @@ async function removeYarnIntegrityFileIfExists(nodeModulesPath) {
|
|||
}
|
||||
} catch {// no-op
|
||||
}
|
||||
} // yarn and bazel integration checkers
|
||||
|
||||
async function areNodeModulesPresent(kbnRootPath) {
|
||||
try {
|
||||
return await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["isDirectory"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'node_modules'));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function haveBazelFoldersBeenCreatedBefore(kbnRootPath) {
|
||||
try {
|
||||
return (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["isDirectory"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'bazel-bin', 'packages'))) || (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["isDirectory"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'bazel-kibana', 'packages'))) || (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["isDirectory"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'bazel-out', 'host')));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function haveNodeModulesBeenManuallyDeleted(kbnRootPath) {
|
||||
return !(await areNodeModulesPresent(kbnRootPath)) && (await haveBazelFoldersBeenCreatedBefore(kbnRootPath));
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -17,7 +17,12 @@ import { ICommand } from './';
|
|||
import { readYarnLock } from '../utils/yarn_lock';
|
||||
import { sortPackageJson } from '../utils/sort_package_json';
|
||||
import { validateDependencies } from '../utils/validate_dependencies';
|
||||
import { installBazelTools, removeYarnIntegrityFileIfExists, runBazel } from '../utils/bazel';
|
||||
import {
|
||||
installBazelTools,
|
||||
haveNodeModulesBeenManuallyDeleted,
|
||||
removeYarnIntegrityFileIfExists,
|
||||
runBazel,
|
||||
} from '../utils/bazel';
|
||||
import { setupRemoteCache } from '../utils/bazel/setup_remote_cache';
|
||||
|
||||
export const BootstrapCommand: ICommand = {
|
||||
|
@ -37,8 +42,12 @@ export const BootstrapCommand: ICommand = {
|
|||
const reporter = CiStatsReporter.fromEnv(log);
|
||||
const timings = [];
|
||||
|
||||
// Force install is set in case a flag is passed into yarn kbn bootstrap
|
||||
const forceInstall = !!options && options['force-install'] === true;
|
||||
// Force install is set in case a flag is passed into yarn kbn bootstrap or
|
||||
// our custom logic have determined there is a chance node_modules have been manually deleted and as such bazel
|
||||
// tracking mechanism is no longer valid
|
||||
const forceInstall =
|
||||
(!!options && options['force-install'] === true) ||
|
||||
(await haveNodeModulesBeenManuallyDeleted(kibanaProjectPath));
|
||||
|
||||
// Install bazel machinery tools if needed
|
||||
await installBazelTools(rootPath);
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
export * from './get_cache_folders';
|
||||
export * from './install_tools';
|
||||
export * from './run';
|
||||
export * from './yarn_integrity';
|
||||
export * from './yarn';
|
||||
|
|
53
packages/kbn-pm/src/utils/bazel/yarn.ts
Normal file
53
packages/kbn-pm/src/utils/bazel/yarn.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { join, resolve } from 'path';
|
||||
import { isDirectory, isFile, tryRealpath, unlink } from '../fs';
|
||||
|
||||
// yarn integrity file checker
|
||||
export async function removeYarnIntegrityFileIfExists(nodeModulesPath: string) {
|
||||
try {
|
||||
const nodeModulesRealPath = await tryRealpath(nodeModulesPath);
|
||||
const yarnIntegrityFilePath = join(nodeModulesRealPath, '.yarn-integrity');
|
||||
|
||||
// check if the file exists and delete it in that case
|
||||
if (await isFile(yarnIntegrityFilePath)) {
|
||||
await unlink(yarnIntegrityFilePath);
|
||||
}
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
// yarn and bazel integration checkers
|
||||
async function areNodeModulesPresent(kbnRootPath: string) {
|
||||
try {
|
||||
return await isDirectory(resolve(kbnRootPath, 'node_modules'));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function haveBazelFoldersBeenCreatedBefore(kbnRootPath: string) {
|
||||
try {
|
||||
return (
|
||||
(await isDirectory(resolve(kbnRootPath, 'bazel-bin', 'packages'))) ||
|
||||
(await isDirectory(resolve(kbnRootPath, 'bazel-kibana', 'packages'))) ||
|
||||
(await isDirectory(resolve(kbnRootPath, 'bazel-out', 'host')))
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function haveNodeModulesBeenManuallyDeleted(kbnRootPath: string) {
|
||||
return (
|
||||
!(await areNodeModulesPresent(kbnRootPath)) &&
|
||||
(await haveBazelFoldersBeenCreatedBefore(kbnRootPath))
|
||||
);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { join } from 'path';
|
||||
import { isFile, tryRealpath, unlink } from '../fs';
|
||||
|
||||
export async function removeYarnIntegrityFileIfExists(nodeModulesPath: string) {
|
||||
try {
|
||||
const nodeModulesRealPath = await tryRealpath(nodeModulesPath);
|
||||
const yarnIntegrityFilePath = join(nodeModulesRealPath, '.yarn-integrity');
|
||||
|
||||
// check if the file exists and delete it in that case
|
||||
if (await isFile(yarnIntegrityFilePath)) {
|
||||
await unlink(yarnIntegrityFilePath);
|
||||
}
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue