mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -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
This commit is contained in:
parent
e5d73a1169
commit
9a1e1d00a4
5 changed files with 103 additions and 40 deletions
50
packages/kbn-pm/dist/index.js
vendored
50
packages/kbn-pm/dist/index.js
vendored
|
@ -61971,12 +61971,14 @@ const BootstrapCommand = {
|
|||
ms: Date.now() - start
|
||||
});
|
||||
}
|
||||
}; // Force install is set in case a flag is passed into yarn kbn bootstrap
|
||||
}; // 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_8__[/* haveNodeModulesBeenManuallyDeleted */ "c"])(kibanaProjectPath)); // Install bazel machinery tools if needed
|
||||
|
||||
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_8__[/* installBazelTools */ "c"])(rootPath); // Setup remote cache settings in .bazelrc.cache if needed
|
||||
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_8__[/* installBazelTools */ "d"])(rootPath); // Setup remote cache settings in .bazelrc.cache if needed
|
||||
|
||||
await Object(_utils_bazel_setup_remote_cache__WEBPACK_IMPORTED_MODULE_9__[/* setupRemoteCache */ "a"])(rootPath); // Bootstrap process for Bazel packages
|
||||
// Bazel is now managing dependencies so yarn install
|
||||
|
@ -61990,7 +61992,7 @@ const BootstrapCommand = {
|
|||
|
||||
if (forceInstall) {
|
||||
await time('force install dependencies', async () => {
|
||||
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_8__[/* removeYarnIntegrityFileIfExists */ "e"])(path__WEBPACK_IMPORTED_MODULE_0___default.a.resolve(kibanaProjectPath, 'node_modules'));
|
||||
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_8__[/* removeYarnIntegrityFileIfExists */ "f"])(path__WEBPACK_IMPORTED_MODULE_0___default.a.resolve(kibanaProjectPath, 'node_modules'));
|
||||
await Object(_kbn_bazel_runner__WEBPACK_IMPORTED_MODULE_2__["runBazel"])({
|
||||
bazelArgs: ['clean', '--expunge'],
|
||||
log: _utils_log__WEBPACK_IMPORTED_MODULE_3__[/* log */ "a"]
|
||||
|
@ -62171,7 +62173,7 @@ const CleanCommand = {
|
|||
} // Runs Bazel soft clean
|
||||
|
||||
|
||||
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_5__[/* isBazelBinAvailable */ "d"])(kbn.getAbsolute())) {
|
||||
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_5__[/* isBazelBinAvailable */ "e"])(kbn.getAbsolute())) {
|
||||
await Object(_kbn_bazel_runner__WEBPACK_IMPORTED_MODULE_4__["runBazel"])({
|
||||
bazelArgs: ['clean'],
|
||||
log: _utils_log__WEBPACK_IMPORTED_MODULE_7__[/* log */ "a"]
|
||||
|
@ -62331,7 +62333,7 @@ const ResetCommand = {
|
|||
} // Runs Bazel hard clean and deletes Bazel Cache Folders
|
||||
|
||||
|
||||
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_5__[/* isBazelBinAvailable */ "d"])(kbn.getAbsolute())) {
|
||||
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_5__[/* isBazelBinAvailable */ "e"])(kbn.getAbsolute())) {
|
||||
// Hard cleaning bazel
|
||||
await Object(_kbn_bazel_runner__WEBPACK_IMPORTED_MODULE_4__["runBazel"])({
|
||||
bazelArgs: ['clean', '--expunge'],
|
||||
|
@ -62799,12 +62801,14 @@ async function getBazelRepositoryCacheFolder() {
|
|||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "b", function() { return _get_cache_folders__WEBPACK_IMPORTED_MODULE_0__["b"]; });
|
||||
|
||||
/* harmony import */ var _install_tools__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/utils/bazel/install_tools.ts");
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "c", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["a"]; });
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "d", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["a"]; });
|
||||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "d", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["b"]; });
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "e", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["b"]; });
|
||||
|
||||
/* harmony import */ var _yarn_integrity__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/utils/bazel/yarn_integrity.ts");
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "e", function() { return _yarn_integrity__WEBPACK_IMPORTED_MODULE_2__["a"]; });
|
||||
/* harmony import */ var _yarn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/utils/bazel/yarn.ts");
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "c", function() { return _yarn__WEBPACK_IMPORTED_MODULE_2__["a"]; });
|
||||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "f", function() { return _yarn__WEBPACK_IMPORTED_MODULE_2__["b"]; });
|
||||
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
|
@ -63007,11 +63011,12 @@ async function setupRemoteCache(repoRootPath) {
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./src/utils/bazel/yarn_integrity.ts":
|
||||
/***/ "./src/utils/bazel/yarn.ts":
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return removeYarnIntegrityFileIfExists; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return removeYarnIntegrityFileIfExists; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return haveNodeModulesBeenManuallyDeleted; });
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("path");
|
||||
/* 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__("./src/utils/fs.ts");
|
||||
|
@ -63023,6 +63028,7 @@ async function setupRemoteCache(repoRootPath) {
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
// yarn integrity file checker
|
||||
|
||||
async function removeYarnIntegrityFileIfExists(nodeModulesPath) {
|
||||
try {
|
||||
|
@ -63034,6 +63040,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 */ "c"])(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 */ "c"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'bazel-bin', 'packages'))) || (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__[/* isDirectory */ "c"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kbnRootPath, 'bazel-kibana', 'packages'))) || (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__[/* isDirectory */ "c"])(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));
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -16,7 +16,11 @@ import { linkProjectExecutables } from '../utils/link_project_executables';
|
|||
import { ICommand } from '.';
|
||||
import { readYarnLock } from '../utils/yarn_lock';
|
||||
import { validateDependencies } from '../utils/validate_dependencies';
|
||||
import { installBazelTools, removeYarnIntegrityFileIfExists } from '../utils/bazel';
|
||||
import {
|
||||
installBazelTools,
|
||||
haveNodeModulesBeenManuallyDeleted,
|
||||
removeYarnIntegrityFileIfExists,
|
||||
} from '../utils/bazel';
|
||||
import { setupRemoteCache } from '../utils/bazel/setup_remote_cache';
|
||||
|
||||
export const BootstrapCommand: ICommand = {
|
||||
|
@ -46,8 +50,12 @@ export const BootstrapCommand: ICommand = {
|
|||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
|
||||
export * from './get_cache_folders';
|
||||
export * from './install_tools';
|
||||
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