chore(NA): moving @elastic/datemath into bazel (#94665)

* chore(NA): majority of the changes needed to build elastic-datemath with bazel

* chore(NA): add missing bits on elastic-datemath package

* chore(NA): add missing build and watch scripts

* chore(NA): remove build scripts for elastic datemah

* chore(NA): remove typo from build baze production projects logs

* chore(NA): force install on CI

* chore(NA): introduce custom preserve symlinks resolver for jest

* chore(NA): update jest integration snapshot

* chore(NA): fix build for bazel packages

* chore(NA): correctly copy bazel built packages into final distributable build

* chore(NA): update kbn pm dist

* chore(NA): experimental new logic to handle bazel yarn rule rerun using yarn-integrity file

* chore(NA): update snapshots

* refact(NA): ensure yarn integrity exists into two methods

* chore(NA): fix ts error

* chore(NA): update snapshots

* chore(NA): update elastic-datemath build file to include ts_project rule

* chore(NA): update basic optimization test snapshots

* chore(NA): merge and solve conflicts cherry-pick from #96066

* chore(NA): update package.json and yarn.lock file

* chore(NA): update bazel/bin into bazel-bin on kbn-pm build bazel packages

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tiago Costa 2021-04-01 22:51:32 +01:00 committed by GitHub
parent 32f2409396
commit f424b9cbb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 368 additions and 60 deletions

View file

@ -82,7 +82,7 @@ test:debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999
run:debug --define=VERBOSE_LOGS=1 -- --node_options=--inspect-brk
# The following option will change the build output of certain rules such as terser and may not be desirable in all cases
# It will also output both the repo cache and action cache to a folder inside the repo
build:debug --compilation_mode=dbg --show_result=1 --disk_cache=bazel/disk-cache --repository_cache=bazel/repository-cache
build:debug --compilation_mode=dbg --show_result=1
# Turn off legacy external runfiles
# This prevents accidentally depending on this feature, which Bazel will remove.

View file

@ -2,6 +2,7 @@
# other packages builds and need to be included as inputs
exports_files(
[
"tsconfig.base.json",
"tsconfig.json",
"package.json"
],

View file

@ -98,7 +98,7 @@
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "26.1.0",
"@elastic/datemath": "link:packages/elastic-datemath",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath/npm_module",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.4",
"@elastic/ems-client": "7.12.0",
"@elastic/eui": "31.10.0",
@ -441,6 +441,7 @@
"@babel/traverse": "^7.12.12",
"@babel/types": "^7.12.12",
"@bazel/ibazel": "^0.14.0",
"@bazel/typescript": "^3.2.3",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",

View file

@ -2,5 +2,7 @@
# targets so we can build them all at once
filegroup(
name = "build",
srcs = [],
srcs = [
"//packages/elastic-datemath:build"
],
)

View file

@ -1,2 +1,3 @@
/index.test.js
/jest.config.js
/tsconfig.json
/__tests__

View file

@ -0,0 +1,76 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
PKG_BASE_NAME = "elastic-datemath"
PKG_REQUIRE_NAME = "@elastic/datemath"
SOURCE_FILES = [
"src/index.ts",
]
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = glob(SOURCE_FILES),
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md",
]
SRC_DEPS = [
"@npm//moment",
]
TYPES_DEPS = [
"@npm//@types/node",
]
DEPS = SRC_DEPS + TYPES_DEPS
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)
ts_project(
name = "tsc",
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_BASE_NAME,
srcs = [],
deps = [":tsc"] + DEPS,
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
srcs = NPM_MODULE_EXTRA_FILES,
deps = [
":%s" % PKG_BASE_NAME,
]
)
filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)

View file

@ -5,8 +5,7 @@
"license": "Apache-2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"scripts": {
"build": "../../node_modules/.bin/tsc",
"kbn:bootstrap": "yarn build"
"peerDependencies": {
"moment": "^2.24.0"
}
}

View file

@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": false,
"outDir": "./target",
"declaration": true,
"declarationMap": true,
"outDir": "target",
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../packages/elastic-datemath/src",
"types": [

View file

@ -209,7 +209,7 @@ async function run(argv) {
},
default: {
cache: true,
'force-install': true,
'force-install': false,
offline: false,
validate: true
},
@ -8910,8 +8910,11 @@ const BootstrapCommand = {
const nonBazelProjectsOnly = await Object(_utils_projects__WEBPACK_IMPORTED_MODULE_4__["getNonBazelProjectsOnly"])(projects);
const batchedNonBazelProjects = Object(_utils_projects__WEBPACK_IMPORTED_MODULE_4__["topologicallyBatchProjects"])(nonBazelProjectsOnly, projectGraph);
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 forceInstall = !!options && options['force-install'] === true; // Ensure we have a `node_modules/.yarn-integrity` file as we depend on it
const runOffline = (options === null || options === void 0 ? void 0 : options.offline) === true; // Force install is set in case a flag is passed or
// if the `.yarn-integrity` file is not found which
// will be indicated by the return of yarnIntegrityFileExists.
const forceInstall = !!options && options['force-install'] === true || !(await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_9__["yarnIntegrityFileExists"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kibanaProjectPath, 'node_modules'))); // Ensure we have a `node_modules/.yarn-integrity` file as we depend on it
// for bazel to know it has to re-install the node_modules after a reset or a clean
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_9__["ensureYarnIntegrityFileExists"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(kibanaProjectPath, 'node_modules')); // Install bazel machinery tools if needed
@ -8925,9 +8928,6 @@ const BootstrapCommand = {
// That way non bazel projects could depend on bazel projects but not the other way around
// That is only intended during the migration process while non Bazel projects are not removed at all.
//
// Until we have our first package build within Bazel we will always need to directly call the yarn rule
// otherwise yarn install won't trigger as we don't have any npm dependency within Bazel
// TODO: Change CLI default in order to not force install as soon as we have our first Bazel package being built
if (forceInstall) {
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_9__["runBazel"])(['run', '@nodejs//:yarn'], runOffline);
@ -9105,6 +9105,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isDirectory", function() { return isDirectory; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isFile", function() { return isFile; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createSymlink", function() { return createSymlink; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "tryRealpath", function() { return tryRealpath; });
/* harmony import */ var cmd_shim__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(132);
/* harmony import */ var cmd_shim__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(cmd_shim__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var del__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(143);
@ -9137,6 +9138,7 @@ const symlink = Object(util__WEBPACK_IMPORTED_MODULE_5__["promisify"])(fs__WEBPA
const chmod = Object(util__WEBPACK_IMPORTED_MODULE_5__["promisify"])(fs__WEBPACK_IMPORTED_MODULE_2___default.a.chmod);
const cmdShim = Object(util__WEBPACK_IMPORTED_MODULE_5__["promisify"])(cmd_shim__WEBPACK_IMPORTED_MODULE_0___default.a);
const mkdir = Object(util__WEBPACK_IMPORTED_MODULE_5__["promisify"])(fs__WEBPACK_IMPORTED_MODULE_2___default.a.mkdir);
const realpathNative = Object(util__WEBPACK_IMPORTED_MODULE_5__["promisify"])(fs__WEBPACK_IMPORTED_MODULE_2___default.a.realpath.native);
const mkdirp = async path => await mkdir(path, {
recursive: true
});
@ -9220,6 +9222,20 @@ async function forceCreate(src, dest, type) {
await symlink(src, dest, type);
}
async function tryRealpath(path) {
let calculatedPath = path;
try {
calculatedPath = await realpathNative(path);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}
return calculatedPath;
}
/***/ }),
/* 132 */
/***/ (function(module, exports, __webpack_require__) {
@ -22981,11 +22997,11 @@ class Project {
ensureValidProjectDependency(project) {
const relativePathToProject = normalizePath(path__WEBPACK_IMPORTED_MODULE_1___default.a.relative(this.path, project.path));
const relativePathToProjectIfBazelPkg = normalizePath(path__WEBPACK_IMPORTED_MODULE_1___default.a.relative(this.path, `bazel-bin/packages/${path__WEBPACK_IMPORTED_MODULE_1___default.a.basename(project.path)}`));
const relativePathToProjectIfBazelPkg = normalizePath(path__WEBPACK_IMPORTED_MODULE_1___default.a.relative(this.path, `${__dirname}/../../../bazel-bin/packages/${path__WEBPACK_IMPORTED_MODULE_1___default.a.basename(project.path)}/npm_module`));
const versionInPackageJson = this.allDependencies[project.name];
const expectedVersionInPackageJson = `link:${relativePathToProject}`;
const expectedVersionInPackageJsonIfBazelPkg = `link:${relativePathToProjectIfBazelPkg}`; // TODO: after introduce bazel to build all the packages and completely remove the support for kbn packages
// do not allow child projects to hold dependencies
// do not allow child projects to hold dependencies, unless they are meant to be published externally
if (versionInPackageJson === expectedVersionInPackageJson || versionInPackageJson === expectedVersionInPackageJsonIfBazelPkg) {
return;
@ -23170,7 +23186,7 @@ function transformDependencies(dependencies = {}) {
}
if (isBazelPackageDependency(depVersion)) {
newDeps[name] = depVersion.replace('link:bazel-bin/', 'file:');
newDeps[name] = depVersion.replace('link:bazel-bin/', 'file:').replace('/npm_module', '');
continue;
}
@ -48065,8 +48081,10 @@ function addProjectToTree(tree, pathParts, project) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _ensure_yarn_integrity_exists__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(373);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ensureYarnIntegrityFileExists", function() { return _ensure_yarn_integrity_exists__WEBPACK_IMPORTED_MODULE_0__["ensureYarnIntegrityFileExists"]; });
/* harmony import */ var _yarn_integrity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(373);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "yarnIntegrityFileExists", function() { return _yarn_integrity__WEBPACK_IMPORTED_MODULE_0__["yarnIntegrityFileExists"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ensureYarnIntegrityFileExists", function() { return _yarn_integrity__WEBPACK_IMPORTED_MODULE_0__["ensureYarnIntegrityFileExists"]; });
/* harmony import */ var _get_cache_folders__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(374);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getBazelDiskCacheFolder", function() { return _get_cache_folders__WEBPACK_IMPORTED_MODULE_1__["getBazelDiskCacheFolder"]; });
@ -48099,6 +48117,7 @@ __webpack_require__.r(__webpack_exports__);
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "yarnIntegrityFileExists", function() { return yarnIntegrityFileExists; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ensureYarnIntegrityFileExists", function() { return ensureYarnIntegrityFileExists; });
/* 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__);
@ -48112,9 +48131,27 @@ __webpack_require__.r(__webpack_exports__);
*/
async function yarnIntegrityFileExists(nodeModulesPath) {
try {
const nodeModulesRealPath = await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["tryRealpath"])(nodeModulesPath);
const yarnIntegrityFilePath = Object(path__WEBPACK_IMPORTED_MODULE_0__["join"])(nodeModulesRealPath, '.yarn-integrity'); // check if the file already exists
if (await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["isFile"])(yarnIntegrityFilePath)) {
return true;
}
} catch {// no-op
}
return false;
}
async function ensureYarnIntegrityFileExists(nodeModulesPath) {
try {
await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["writeFile"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["join"])(nodeModulesPath, '.yarn-integrity'), '', {
const nodeModulesRealPath = await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["tryRealpath"])(nodeModulesPath);
const yarnIntegrityFilePath = Object(path__WEBPACK_IMPORTED_MODULE_0__["join"])(nodeModulesRealPath, '.yarn-integrity'); // ensure node_modules folder is created
await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["mkdirp"])(nodeModulesRealPath); // write a blank file in case it doesn't exists
await Object(_fs__WEBPACK_IMPORTED_MODULE_1__["writeFile"])(yarnIntegrityFilePath, '', {
flag: 'wx'
});
} catch {// no-op
@ -63656,7 +63693,7 @@ async function buildBazelProductionProjects({
const projectNames = [...projects.values()].map(project => project.name);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].info(`Preparing Bazel projects production build for [${projectNames.join(', ')}]`);
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["runBazel"])(['build', '//packages:build']);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].info(`All Bazel projects production builds for [${projectNames.join(', ')}] are complete}]`);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].info(`All Bazel projects production builds for [${projectNames.join(', ')}] are complete`);
for (const project of projects.values()) {
await copyToBuild(project, kibanaRoot, buildRoot);
@ -63680,7 +63717,7 @@ async function copyToBuild(project, kibanaRoot, buildRoot) {
const relativeProjectPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["relative"])(kibanaRoot, project.path);
const buildProjectPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(buildRoot, relativeProjectPath);
await cpy__WEBPACK_IMPORTED_MODULE_0___default()(['**/*'], buildProjectPath, {
cwd: Object(path__WEBPACK_IMPORTED_MODULE_2__["join"])(kibanaRoot, 'bazel', 'bin', 'packages', Object(path__WEBPACK_IMPORTED_MODULE_2__["basename"])(buildProjectPath), 'npm_module'),
cwd: Object(path__WEBPACK_IMPORTED_MODULE_2__["join"])(kibanaRoot, 'bazel-bin', 'packages', Object(path__WEBPACK_IMPORTED_MODULE_2__["basename"])(buildProjectPath), 'npm_module'),
dot: true,
onlyFiles: true,
parents: true
@ -63702,12 +63739,12 @@ async function applyCorrectPermissions(project, kibanaRoot, buildRoot) {
const buildProjectPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(buildRoot, relativeProjectPath);
const allPluginPaths = await globby__WEBPACK_IMPORTED_MODULE_1___default()([`**/*`], {
onlyFiles: false,
cwd: Object(path__WEBPACK_IMPORTED_MODULE_2__["join"])(kibanaRoot, 'bazel', 'bin', 'packages', Object(path__WEBPACK_IMPORTED_MODULE_2__["basename"])(buildProjectPath), 'npm_module'),
cwd: buildProjectPath,
dot: true
});
for (const pluginPath of allPluginPaths) {
const resolvedPluginPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(buildRoot, pluginPath);
const resolvedPluginPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(buildProjectPath, pluginPath);
if (await Object(_utils_fs__WEBPACK_IMPORTED_MODULE_5__["isFile"])(resolvedPluginPath)) {
await Object(_utils_fs__WEBPACK_IMPORTED_MODULE_5__["chmod"])(resolvedPluginPath, 0o644);

View file

@ -75,7 +75,7 @@ export async function run(argv: string[]) {
},
default: {
cache: true,
'force-install': true,
'force-install': false,
offline: false,
validate: true,
},

View file

@ -17,7 +17,12 @@ import { getAllChecksums } from '../utils/project_checksums';
import { BootstrapCacheFile } from '../utils/bootstrap_cache_file';
import { readYarnLock } from '../utils/yarn_lock';
import { validateDependencies } from '../utils/validate_dependencies';
import { ensureYarnIntegrityFileExists, installBazelTools, runBazel } from '../utils/bazel';
import {
ensureYarnIntegrityFileExists,
installBazelTools,
runBazel,
yarnIntegrityFileExists,
} from '../utils/bazel';
export const BootstrapCommand: ICommand = {
description: 'Install dependencies and crosslink projects',
@ -33,7 +38,13 @@ export const BootstrapCommand: ICommand = {
const batchedNonBazelProjects = topologicallyBatchProjects(nonBazelProjectsOnly, projectGraph);
const kibanaProjectPath = projects.get('kibana')?.path || '';
const runOffline = options?.offline === true;
const forceInstall = !!options && options['force-install'] === true;
// Force install is set in case a flag is passed or
// if the `.yarn-integrity` file is not found which
// will be indicated by the return of yarnIntegrityFileExists.
const forceInstall =
(!!options && options['force-install'] === true) ||
!(await yarnIntegrityFileExists(resolve(kibanaProjectPath, 'node_modules')));
// Ensure we have a `node_modules/.yarn-integrity` file as we depend on it
// for bazel to know it has to re-install the node_modules after a reset or a clean
@ -51,9 +62,6 @@ export const BootstrapCommand: ICommand = {
// That way non bazel projects could depend on bazel projects but not the other way around
// That is only intended during the migration process while non Bazel projects are not removed at all.
//
// Until we have our first package build within Bazel we will always need to directly call the yarn rule
// otherwise yarn install won't trigger as we don't have any npm dependency within Bazel
// TODO: Change CLI default in order to not force install as soon as we have our first Bazel package being built
if (forceInstall) {
await runBazel(['run', '@nodejs//:yarn'], runOffline);
}

View file

@ -37,7 +37,7 @@ export async function buildBazelProductionProjects({
log.info(`Preparing Bazel projects production build for [${projectNames.join(', ')}]`);
await runBazel(['build', '//packages:build']);
log.info(`All Bazel projects production builds for [${projectNames.join(', ')}] are complete}]`);
log.info(`All Bazel projects production builds for [${projectNames.join(', ')}] are complete`);
for (const project of projects.values()) {
await copyToBuild(project, kibanaRoot, buildRoot);
@ -62,7 +62,7 @@ async function copyToBuild(project: Project, kibanaRoot: string, buildRoot: stri
const buildProjectPath = resolve(buildRoot, relativeProjectPath);
await copy(['**/*'], buildProjectPath, {
cwd: join(kibanaRoot, 'bazel', 'bin', 'packages', basename(buildProjectPath), 'npm_module'),
cwd: join(kibanaRoot, 'bazel-bin', 'packages', basename(buildProjectPath), 'npm_module'),
dot: true,
onlyFiles: true,
parents: true,
@ -88,12 +88,12 @@ async function applyCorrectPermissions(project: Project, kibanaRoot: string, bui
const buildProjectPath = resolve(buildRoot, relativeProjectPath);
const allPluginPaths = await globby([`**/*`], {
onlyFiles: false,
cwd: join(kibanaRoot, 'bazel', 'bin', 'packages', basename(buildProjectPath), 'npm_module'),
cwd: buildProjectPath,
dot: true,
});
for (const pluginPath of allPluginPaths) {
const resolvedPluginPath = resolve(buildRoot, pluginPath);
const resolvedPluginPath = resolve(buildProjectPath, pluginPath);
if (await isFile(resolvedPluginPath)) {
await chmod(resolvedPluginPath, 0o644);
}

View file

@ -11,6 +11,7 @@ Object {
"mkdirp": Array [],
"readFile": Array [],
"rmdirp": Array [],
"tryRealpath": Array [],
"unlink": Array [],
"writeFile": Array [],
}
@ -27,6 +28,7 @@ Object {
"mkdirp": Array [],
"readFile": Array [],
"rmdirp": Array [],
"tryRealpath": Array [],
"unlink": Array [],
"writeFile": Array [],
}

View file

@ -1,18 +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 { writeFile } from '../fs';
export async function ensureYarnIntegrityFileExists(nodeModulesPath: string) {
try {
await writeFile(join(nodeModulesPath, '.yarn-integrity'), '', { flag: 'wx' });
} catch {
// no-op
}
}

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
export * from './ensure_yarn_integrity_exists';
export * from './yarn_integrity';
export * from './get_cache_folders';
export * from './install_tools';
export * from './run';

View file

@ -0,0 +1,41 @@
/*
* 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, mkdirp, tryRealpath, writeFile } from '../fs';
export async function yarnIntegrityFileExists(nodeModulesPath: string) {
try {
const nodeModulesRealPath = await tryRealpath(nodeModulesPath);
const yarnIntegrityFilePath = join(nodeModulesRealPath, '.yarn-integrity');
// check if the file already exists
if (await isFile(yarnIntegrityFilePath)) {
return true;
}
} catch {
// no-op
}
return false;
}
export async function ensureYarnIntegrityFileExists(nodeModulesPath: string) {
try {
const nodeModulesRealPath = await tryRealpath(nodeModulesPath);
const yarnIntegrityFilePath = join(nodeModulesRealPath, '.yarn-integrity');
// ensure node_modules folder is created
await mkdirp(nodeModulesRealPath);
// write a blank file in case it doesn't exists
await writeFile(yarnIntegrityFilePath, '', { flag: 'wx' });
} catch {
// no-op
}
}

View file

@ -20,6 +20,7 @@ const symlink = promisify(fs.symlink);
export const chmod = promisify(fs.chmod);
const cmdShim = promisify<string, string>(cmdShimCb);
const mkdir = promisify(fs.mkdir);
const realpathNative = promisify(fs.realpath.native);
export const mkdirp = async (path: string) => await mkdir(path, { recursive: true });
export const rmdirp = async (path: string) => await del(path, { force: true });
export const unlink = promisify(fs.unlink);
@ -96,3 +97,17 @@ async function forceCreate(src: string, dest: string, type: string) {
await symlink(src, dest, type);
}
export async function tryRealpath(path: string): Promise<string> {
let calculatedPath = path;
try {
calculatedPath = await realpathNative(path);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}
return calculatedPath;
}

View file

@ -61,7 +61,7 @@ export function transformDependencies(dependencies: IPackageDependencies = {}) {
}
if (isBazelPackageDependency(depVersion)) {
newDeps[name] = depVersion.replace('link:bazel-bin/', 'file:');
newDeps[name] = depVersion.replace('link:bazel-bin/', 'file:').replace('/npm_module', '');
continue;
}

View file

@ -92,7 +92,10 @@ export class Project {
public ensureValidProjectDependency(project: Project) {
const relativePathToProject = normalizePath(Path.relative(this.path, project.path));
const relativePathToProjectIfBazelPkg = normalizePath(
Path.relative(this.path, `bazel-bin/packages/${Path.basename(project.path)}`)
Path.relative(
this.path,
`${__dirname}/../../../bazel-bin/packages/${Path.basename(project.path)}/npm_module`
)
);
const versionInPackageJson = this.allDependencies[project.name];
@ -100,7 +103,7 @@ export class Project {
const expectedVersionInPackageJsonIfBazelPkg = `link:${relativePathToProjectIfBazelPkg}`;
// TODO: after introduce bazel to build all the packages and completely remove the support for kbn packages
// do not allow child projects to hold dependencies
// do not allow child projects to hold dependencies, unless they are meant to be published externally
if (
versionInPackageJson === expectedVersionInPackageJson ||
versionInPackageJson === expectedVersionInPackageJsonIfBazelPkg

View file

@ -107,4 +107,7 @@ module.exports = {
'!**/*.d.ts',
'!**/index.{js,ts}',
],
// A custom resolver to preserve symlinks by default
resolver: '<rootDir>/packages/kbn-test/target/jest/setup/preserve_symlinks_resolver.js',
};

View file

@ -0,0 +1,30 @@
/*
* 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.
*/
// Inspired in a discussion found at https://github.com/facebook/jest/issues/5356 as Jest currently doesn't
// offer any other option to preserve symlinks.
//
// It would be available once https://github.com/facebook/jest/pull/9976 got merged.
const resolve = require('resolve');
module.exports = (request, options) => {
try {
return resolve.sync(request, {
basedir: options.basedir,
extensions: options.extensions,
preserveSymlinks: true,
});
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
return options.defaultResolver(request, options);
}
throw error;
}
};

View file

@ -37,7 +37,6 @@
"@kbn/utility-types": "link:../packages/kbn-utility-types"
},
"dependencies": {
"@elastic/datemath": "link:../packages/elastic-datemath",
"@elastic/safer-lodash-set": "link:../packages/elastic-safer-lodash-set",
"@kbn/config-schema": "link:../packages/kbn-config-schema",
"@kbn/i18n": "link:../packages/kbn-i18n",

View file

@ -5,4 +5,5 @@
* 2.0.
*/
require('../../src/setup_node_env/ensure_node_preserve_symlinks');
require('@kbn/test').runJest();

111
yarn.lock
View file

@ -1197,6 +1197,16 @@
resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.14.0.tgz#86fa0002bed2ce1123b7ad98d4dd4623a0d93244"
integrity sha512-s0gyec6lArcRDwVfIP6xpY8iEaFpzrSpyErSppd3r2O49pOEg7n6HGS/qJ8ncvme56vrDk6crl/kQ6VAdEO+rg==
"@bazel/typescript@^3.2.3":
version "3.2.3"
resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-3.2.3.tgz#6e40bdb7c5294e588bac3b7d1269e58b98a1856c"
integrity sha512-Q1Yin/AYdh9yrkSJo3H6nVn6mMaohr5syjLd0Df0w7WI4zerdJTxrY5nhoWZwO/S1rPj8/MedDwZudCqPDeDMA==
dependencies:
protobufjs "6.8.8"
semver "5.6.0"
source-map-support "0.5.9"
tsutils "2.27.2"
"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
@ -1375,7 +1385,7 @@
utility-types "^3.10.0"
uuid "^3.3.2"
"@elastic/datemath@link:packages/elastic-datemath":
"@elastic/datemath@link:bazel-bin/packages/elastic-datemath/npm_module":
version "0.0.0"
uid ""
@ -3441,6 +3451,59 @@
dependencies:
"@babel/runtime" "^7.0.0"
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf"
integrity sha1-m4sMxmPWaafY9vXQiToU00jzD78=
"@protobufjs/base64@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/base64/-/base64-1.1.2.tgz#4c85730e59b9a1f1f349047dbf24296034bb2735"
integrity sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==
"@protobufjs/codegen@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb"
integrity sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==
"@protobufjs/eventemitter@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz#355cbc98bafad5978f9ed095f397621f1d066b70"
integrity sha1-NVy8mLr61ZePntCV85diHx0Ga3A=
"@protobufjs/fetch@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/fetch/-/fetch-1.1.0.tgz#ba99fb598614af65700c1619ff06d454b0d84c45"
integrity sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=
dependencies:
"@protobufjs/aspromise" "^1.1.1"
"@protobufjs/inquire" "^1.1.0"
"@protobufjs/float@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@protobufjs/float/-/float-1.0.2.tgz#5e9e1abdcb73fc0a7cb8b291df78c8cbd97b87d1"
integrity sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=
"@protobufjs/inquire@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/inquire/-/inquire-1.1.0.tgz#ff200e3e7cf2429e2dcafc1140828e8cc638f089"
integrity sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=
"@protobufjs/path@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/path/-/path-1.1.2.tgz#6cc2b20c5c9ad6ad0dccfd21ca7673d8d7fbf68d"
integrity sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=
"@protobufjs/pool@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/pool/-/pool-1.1.0.tgz#09fd15f2d6d3abfa9b65bc366506d6ad7846ff54"
integrity sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=
"@protobufjs/utf8@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
"@reach/router@^1.3.3":
version "1.3.4"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.3.4.tgz#d2574b19370a70c80480ed91f3da840136d10f8c"
@ -5181,6 +5244,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.159.tgz#61089719dc6fdd9c5cb46efc827f2571d1517065"
integrity sha512-gF7A72f7WQN33DpqOWw9geApQPh4M3PxluMtaHxWHXEGSN12/WbcEk/eNSqWNQcQhF66VSZ06vCF94CrHwXJDg==
"@types/long@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"
integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==
"@types/lru-cache@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-5.1.0.tgz#57f228f2b80c046b4a1bd5cac031f81f207f4f03"
@ -5330,7 +5398,7 @@
dependencies:
"@types/node" "*"
"@types/node@*", "@types/node@14.14.14", "@types/node@8.10.54", "@types/node@>= 8", "@types/node@>=8.9.0", "@types/node@^12.0.2":
"@types/node@*", "@types/node@14.14.14", "@types/node@8.10.54", "@types/node@>= 8", "@types/node@>=8.9.0", "@types/node@^10.1.0", "@types/node@^12.0.2":
version "14.14.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae"
integrity sha512-UHnOPWVWV1z+VV8k6L1HhG7UbGBgIdghqF3l9Ny9ApPghbjICXkUJSd/b9gOgQfjM1r+37cipdw/HJ3F6ICEnQ==
@ -22915,6 +22983,25 @@ proto-list@~1.2.1:
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
protobufjs@6.8.8:
version "6.8.8"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.8.8.tgz#c8b4f1282fd7a90e6f5b109ed11c84af82908e7c"
integrity sha512-AAmHtD5pXgZfi7GMpllpO3q1Xw1OYldr+dMUlAnffGTAhqkg72WdmSY71uKBF/JuyiKs8psYbtKrhi0ASCD8qw==
dependencies:
"@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2"
"@protobufjs/codegen" "^2.0.4"
"@protobufjs/eventemitter" "^1.1.0"
"@protobufjs/fetch" "^1.1.0"
"@protobufjs/float" "^1.0.2"
"@protobufjs/inquire" "^1.1.0"
"@protobufjs/path" "^1.1.2"
"@protobufjs/pool" "^1.1.0"
"@protobufjs/utf8" "^1.1.0"
"@types/long" "^4.0.0"
"@types/node" "^10.1.0"
long "^4.0.0"
protocol-buffers-schema@^3.3.1:
version "3.3.2"
resolved "https://registry.yarnpkg.com/protocol-buffers-schema/-/protocol-buffers-schema-3.3.2.tgz#00434f608b4e8df54c59e070efeefc37fb4bb859"
@ -25437,6 +25524,11 @@ semver-greatest-satisfied-range@^1.1.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
semver@5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==
semver@7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
@ -25924,6 +26016,14 @@ source-map-resolve@^0.6.0:
atob "^2.1.2"
decode-uri-component "^0.2.0"
source-map-support@0.5.9:
version "0.5.9"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f"
integrity sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map-support@^0.3.2:
version "0.3.3"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.3.3.tgz#34900977d5ba3f07c7757ee72e73bb1a9b53754f"
@ -27859,6 +27959,13 @@ tslib@~2.1.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
tsutils@2.27.2:
version "2.27.2"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.27.2.tgz#60ba88a23d6f785ec4b89c6e8179cac9b431f1c7"
integrity sha512-qf6rmT84TFMuxAKez2pIfR8UCai49iQsfB7YWVjV1bKpy/d0PWT5rEOSM6La9PiHZ0k1RRZQiwVdVJfQ3BPHgg==
dependencies:
tslib "^1.8.1"
tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"