mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
chore(NA): adds support for bazel packages to live anywhere (#130833)
* chore(NA): creates a simple location free package * chore(NA): creates two more simple location free packages * chore(NA): add support on build tasks to build packages anywhere * chore(NA): add support for xpack * chore(NA): logic for discover bazel packages only with BUILD.bazel and package.json * chore(NA): do not allow child projects to have dependencies declared * chore(NA): create package on xpack folder * chore(NA): exclude bazel packages inside xpack plugins from xpack build * fix(NA): build copy and failing jest tests for @kbn/pm * chore(NA): exclude x-pack/package.json from being a bazel package * refact(NA): include normalized method on bazel-packages package * chore(NA): fix check ts projects task * chore(NA): impossible if so cli integartion test passes * chore(NA): fix jest tests for @kbn/pm * chore(NA): use created packages * chore(NA): discard dependencies on child projects * chore(NA): remove changes from cli * chore(NA): remove wrongly commented line on @kbn/pm * fix(NA): build tasks to exclude correct bazel package locations * chore(NA): include free packages on cli * chore(NA): update import resolver * chore(NA): removing location free plugins created for testing purposes * refact(NA): imports order on @kbn/bazel-packages * docs(NA): clarify notes around the changes to discoverBazelPackageLocations * refact(NA): remove redundant code from packages/kbn-import-resolver/src/import_resolver.ts * chore(NA): remove typo from previous commit * refact(NA): simplify clean task removing filter for dev packages * chore(NA): apply eslint lint fix * refact(NA): simplify discoverBazelPackageLocations logic * chore(NA): redo changes on import resolver checks Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
b7aa4b8e0d
commit
3099433056
21 changed files with 129 additions and 240 deletions
|
@ -6,9 +6,9 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import globby from 'globby';
|
||||
import Path from 'path';
|
||||
|
||||
import globby from 'globby';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import Path from 'path';
|
||||
|
||||
import globby from 'globby';
|
||||
import normalizePath from 'normalize-path';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
import { asyncMapWithLimit } from '@kbn/std';
|
||||
|
||||
|
@ -16,7 +17,7 @@ import { BazelPackage } from './bazel_package';
|
|||
import { BAZEL_PACKAGE_DIRS } from './bazel_package_dirs';
|
||||
|
||||
export function discoverBazelPackageLocations(repoRoot: string) {
|
||||
return globby
|
||||
const packagesWithPackageJson = globby
|
||||
.sync(
|
||||
BAZEL_PACKAGE_DIRS.map((dir) => `${dir}/*/package.json`),
|
||||
{
|
||||
|
@ -24,8 +25,26 @@ export function discoverBazelPackageLocations(repoRoot: string) {
|
|||
absolute: true,
|
||||
}
|
||||
)
|
||||
// NOTE: removing x-pack by default for now to prevent a situation where a BUILD.bazel file
|
||||
// needs to be added at the root of the folder which will make x-pack to be wrongly recognized
|
||||
// as a Bazel package in that case
|
||||
.filter((path) => !normalizePath(path).includes('x-pack/package.json'))
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((path) => Path.dirname(path));
|
||||
|
||||
const packagesWithBuildBazel = globby
|
||||
.sync(
|
||||
BAZEL_PACKAGE_DIRS.map((dir) => `${dir}/*/BUILD.bazel`),
|
||||
{
|
||||
cwd: repoRoot,
|
||||
absolute: true,
|
||||
}
|
||||
)
|
||||
.map((path) => Path.dirname(path));
|
||||
|
||||
// NOTE: only return as discovered packages the ones with a package.json + BUILD.bazel file.
|
||||
// In the future we should change this to only discover the ones declaring kibana.json.
|
||||
return packagesWithPackageJson.filter((pkg) => packagesWithBuildBazel.includes(pkg));
|
||||
}
|
||||
|
||||
export async function discoverBazelPackages(repoRoot: string = REPO_ROOT) {
|
||||
|
|
|
@ -25,9 +25,18 @@ const NODE_MODULE_SEG = Path.sep + 'node_modules' + Path.sep;
|
|||
export class ImportResolver {
|
||||
static create(repoRoot: string) {
|
||||
const pkgMap = new Map();
|
||||
for (const dir of discoverBazelPackageLocations(repoRoot)) {
|
||||
const pkg = JSON.parse(Fs.readFileSync(Path.resolve(dir, 'package.json'), 'utf8'));
|
||||
pkgMap.set(pkg.name, normalizePath(Path.relative(repoRoot, dir)));
|
||||
for (const dir of discoverBazelPackageLocations(REPO_ROOT)) {
|
||||
const relativeBazelPackageDir = Path.relative(REPO_ROOT, dir);
|
||||
const repoRootBazelPackageDir = Path.resolve(repoRoot, relativeBazelPackageDir);
|
||||
|
||||
if (!Fs.existsSync(Path.resolve(repoRootBazelPackageDir, 'package.json'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pkg = JSON.parse(
|
||||
Fs.readFileSync(Path.resolve(repoRootBazelPackageDir, 'package.json'), 'utf8')
|
||||
);
|
||||
pkgMap.set(pkg.name, normalizePath(relativeBazelPackageDir));
|
||||
}
|
||||
|
||||
return new ImportResolver(repoRoot, pkgMap, readPackageMap());
|
||||
|
|
46
packages/kbn-pm/dist/index.js
vendored
46
packages/kbn-pm/dist/index.js
vendored
|
@ -61563,32 +61563,6 @@ class Project {
|
|||
return this.json.name;
|
||||
}
|
||||
|
||||
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, `${__dirname}/../../../bazel-bin/packages/${path__WEBPACK_IMPORTED_MODULE_1___default.a.basename(project.path)}`));
|
||||
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, unless they are meant to be published externally
|
||||
|
||||
if (versionInPackageJson === expectedVersionInPackageJson || versionInPackageJson === expectedVersionInPackageJsonIfBazelPkg) {
|
||||
return;
|
||||
}
|
||||
|
||||
const updateMsg = 'Update its package.json to the expected value below.';
|
||||
const meta = {
|
||||
actual: `"${project.name}": "${versionInPackageJson}"`,
|
||||
expected: `"${project.name}": "${expectedVersionInPackageJson}" or "${project.name}": "${expectedVersionInPackageJsonIfBazelPkg}"`,
|
||||
package: `${this.name} (${this.packageJsonLocation})`
|
||||
};
|
||||
|
||||
if (Object(_package_json__WEBPACK_IMPORTED_MODULE_5__[/* isLinkDependency */ "a"])(versionInPackageJson)) {
|
||||
throw new _errors__WEBPACK_IMPORTED_MODULE_3__[/* CliError */ "a"](`[${this.name}] depends on [${project.name}] using 'link:', but the path is wrong. ${updateMsg}`, meta);
|
||||
}
|
||||
|
||||
throw new _errors__WEBPACK_IMPORTED_MODULE_3__[/* CliError */ "a"](`[${this.name}] depends on [${project.name}] but it's not using the local package. ${updateMsg}`, meta);
|
||||
}
|
||||
|
||||
getBuildConfig() {
|
||||
return this.json.kibana && this.json.kibana.build || {};
|
||||
}
|
||||
|
@ -61660,10 +61634,6 @@ class Project {
|
|||
return Object.values(this.allDependencies).every(dep => Object(_package_json__WEBPACK_IMPORTED_MODULE_5__[/* isLinkDependency */ "a"])(dep));
|
||||
}
|
||||
|
||||
} // We normalize all path separators to `/` in generated files
|
||||
|
||||
function normalizePath(path) {
|
||||
return path.replace(/[\\\/]+/g, '/');
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
@ -61685,7 +61655,8 @@ function normalizePath(path) {
|
|||
/* harmony import */ var util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("util");
|
||||
/* harmony import */ var util__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(util__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/errors.ts");
|
||||
/* harmony import */ var _project__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/utils/project.ts");
|
||||
/* harmony import */ var _log__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/utils/log.ts");
|
||||
/* harmony import */ var _project__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./src/utils/project.ts");
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
|
@ -61698,6 +61669,7 @@ function normalizePath(path) {
|
|||
|
||||
|
||||
|
||||
|
||||
const glob = Object(util__WEBPACK_IMPORTED_MODULE_2__["promisify"])(glob__WEBPACK_IMPORTED_MODULE_0___default.a);
|
||||
/** a Map of project names to Project instances */
|
||||
|
||||
|
@ -61716,7 +61688,7 @@ async function getProjects(rootPath, projectsPathsPatterns, {
|
|||
for (const filePath of pathsToProcess) {
|
||||
const projectConfigPath = normalize(filePath);
|
||||
const projectDir = path__WEBPACK_IMPORTED_MODULE_1___default.a.dirname(projectConfigPath);
|
||||
const project = await _project__WEBPACK_IMPORTED_MODULE_4__[/* Project */ "a"].fromPath(projectDir);
|
||||
const project = await _project__WEBPACK_IMPORTED_MODULE_5__[/* Project */ "a"].fromPath(projectDir);
|
||||
const excludeProject = exclude.includes(project.name) || include.length > 0 && !include.includes(project.name) || bazelOnly && !project.isBazelPackage();
|
||||
|
||||
if (excludeProject) {
|
||||
|
@ -61790,10 +61762,18 @@ function buildProjectGraph(projects) {
|
|||
const projectDeps = [];
|
||||
const dependencies = project.allDependencies;
|
||||
|
||||
if (!project.isSinglePackageJsonProject && Object.keys(dependencies).length > 0) {
|
||||
_log__WEBPACK_IMPORTED_MODULE_4__[/* log */ "a"].warning(`${project.name} is not allowed to hold local dependencies and they will be discarded. Please declare them at the root package.json`);
|
||||
}
|
||||
|
||||
if (!project.isSinglePackageJsonProject) {
|
||||
projectGraph.set(project.name, projectDeps);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const depName of Object.keys(dependencies)) {
|
||||
if (projects.has(depName)) {
|
||||
const dep = projects.get(depName);
|
||||
project.ensureValidProjectDependency(dep);
|
||||
projectDeps.push(dep);
|
||||
}
|
||||
}
|
||||
|
|
30
packages/kbn-pm/src/__snapshots__/run.test.ts.snap
generated
30
packages/kbn-pm/src/__snapshots__/run.test.ts.snap
generated
|
@ -4,14 +4,9 @@ exports[`excludes project if single \`exclude\` filter is specified 1`] = `
|
|||
Object {
|
||||
"graph": Object {
|
||||
"bar": Array [],
|
||||
"baz": Array [
|
||||
"bar",
|
||||
],
|
||||
"baz": Array [],
|
||||
"kibana": Array [],
|
||||
"quux": Array [
|
||||
"bar",
|
||||
"baz",
|
||||
],
|
||||
"quux": Array [],
|
||||
"with-additional-projects": Array [],
|
||||
},
|
||||
"projects": Array [
|
||||
|
@ -42,12 +37,8 @@ Object {
|
|||
exports[`includes only projects specified in multiple \`include\` filters 1`] = `
|
||||
Object {
|
||||
"graph": Object {
|
||||
"bar": Array [
|
||||
"foo",
|
||||
],
|
||||
"baz": Array [
|
||||
"bar",
|
||||
],
|
||||
"bar": Array [],
|
||||
"baz": Array [],
|
||||
"foo": Array [],
|
||||
},
|
||||
"projects": Array [
|
||||
|
@ -72,20 +63,13 @@ Object {
|
|||
exports[`passes all found projects to the command if no filter is specified 1`] = `
|
||||
Object {
|
||||
"graph": Object {
|
||||
"bar": Array [
|
||||
"foo",
|
||||
],
|
||||
"baz": Array [
|
||||
"bar",
|
||||
],
|
||||
"bar": Array [],
|
||||
"baz": Array [],
|
||||
"foo": Array [],
|
||||
"kibana": Array [
|
||||
"foo",
|
||||
],
|
||||
"quux": Array [
|
||||
"bar",
|
||||
"baz",
|
||||
],
|
||||
"quux": Array [],
|
||||
"with-additional-projects": Array [],
|
||||
},
|
||||
"projects": Array [
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
{
|
||||
"name": "bar",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"foo": "link:../foo"
|
||||
}
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
{
|
||||
"name": "quux",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"bar": "link:../../kibana/packages/bar",
|
||||
"baz": "link:../baz"
|
||||
}
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
{
|
||||
"name": "zorge",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"foo": "link:../../kibana/packages/foo"
|
||||
}
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`#ensureValidProjectDependency using link:, but with wrong path 1`] = `"[kibana] depends on [foo] using 'link:', but the path is wrong. Update its package.json to the expected value below."`;
|
||||
|
||||
exports[`#ensureValidProjectDependency using version instead of link: 1`] = `"[kibana] depends on [foo] but it's not using the local package. Update its package.json to the expected value below."`;
|
||||
|
||||
exports[`#getExecutables() throws CliError when bin is something strange 1`] = `"[kibana] has an invalid \\"bin\\" field in its package.json, expected an object or a string"`;
|
||||
|
|
|
@ -2,37 +2,28 @@
|
|||
|
||||
exports[`#buildProjectGraph builds full project graph 1`] = `
|
||||
Object {
|
||||
"bar": Array [
|
||||
"foo",
|
||||
],
|
||||
"bar": Array [],
|
||||
"baz": Array [],
|
||||
"foo": Array [],
|
||||
"kibana": Array [
|
||||
"foo",
|
||||
],
|
||||
"quux": Array [
|
||||
"bar",
|
||||
"baz",
|
||||
],
|
||||
"zorge": Array [
|
||||
"foo",
|
||||
],
|
||||
"quux": Array [],
|
||||
"zorge": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`#topologicallyBatchProjects batches projects topologically based on their project dependencies 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"bar",
|
||||
"foo",
|
||||
"baz",
|
||||
],
|
||||
Array [
|
||||
"kibana",
|
||||
"bar",
|
||||
"quux",
|
||||
"zorge",
|
||||
],
|
||||
Array [
|
||||
"quux",
|
||||
"kibana",
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
@ -43,10 +34,8 @@ Array [
|
|||
"kibana",
|
||||
"bar",
|
||||
"baz",
|
||||
"zorge",
|
||||
],
|
||||
Array [
|
||||
"quux",
|
||||
"zorge",
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
|
|
@ -50,65 +50,6 @@ test('fields', async () => {
|
|||
expect(kibana.hasScript('build')).toBe(false);
|
||||
});
|
||||
|
||||
describe('#ensureValidProjectDependency', () => {
|
||||
test('valid link: version', async () => {
|
||||
const root = createProjectWith({
|
||||
dependencies: {
|
||||
foo: 'link:packages/foo',
|
||||
},
|
||||
});
|
||||
|
||||
const foo = createProjectWith(
|
||||
{
|
||||
name: 'foo',
|
||||
},
|
||||
'packages/foo'
|
||||
);
|
||||
|
||||
expect(() => root.ensureValidProjectDependency(foo)).not.toThrow();
|
||||
});
|
||||
|
||||
test('using link:, but with wrong path', () => {
|
||||
const root = createProjectWith(
|
||||
{
|
||||
dependencies: {
|
||||
foo: 'link:wrong/path',
|
||||
},
|
||||
},
|
||||
rootPath
|
||||
);
|
||||
|
||||
const foo = createProjectWith(
|
||||
{
|
||||
name: 'foo',
|
||||
},
|
||||
'packages/foo'
|
||||
);
|
||||
|
||||
expect(() => root.ensureValidProjectDependency(foo)).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('using version instead of link:', () => {
|
||||
const root = createProjectWith(
|
||||
{
|
||||
dependencies: {
|
||||
foo: '1.0.0',
|
||||
},
|
||||
},
|
||||
rootPath
|
||||
);
|
||||
|
||||
const foo = createProjectWith(
|
||||
{
|
||||
name: 'foo',
|
||||
},
|
||||
'packages/foo'
|
||||
);
|
||||
|
||||
expect(() => root.ensureValidProjectDependency(foo)).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getExecutables()', () => {
|
||||
test('converts bin:string to an object with absolute paths', () => {
|
||||
const project = createProjectWith({
|
||||
|
|
|
@ -88,48 +88,6 @@ export class Project {
|
|||
return this.json.name;
|
||||
}
|
||||
|
||||
public ensureValidProjectDependency(project: Project) {
|
||||
const relativePathToProject = normalizePath(Path.relative(this.path, project.path));
|
||||
const relativePathToProjectIfBazelPkg = normalizePath(
|
||||
Path.relative(
|
||||
this.path,
|
||||
`${__dirname}/../../../bazel-bin/packages/${Path.basename(project.path)}`
|
||||
)
|
||||
);
|
||||
|
||||
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, unless they are meant to be published externally
|
||||
if (
|
||||
versionInPackageJson === expectedVersionInPackageJson ||
|
||||
versionInPackageJson === expectedVersionInPackageJsonIfBazelPkg
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const updateMsg = 'Update its package.json to the expected value below.';
|
||||
const meta = {
|
||||
actual: `"${project.name}": "${versionInPackageJson}"`,
|
||||
expected: `"${project.name}": "${expectedVersionInPackageJson}" or "${project.name}": "${expectedVersionInPackageJsonIfBazelPkg}"`,
|
||||
package: `${this.name} (${this.packageJsonLocation})`,
|
||||
};
|
||||
|
||||
if (isLinkDependency(versionInPackageJson)) {
|
||||
throw new CliError(
|
||||
`[${this.name}] depends on [${project.name}] using 'link:', but the path is wrong. ${updateMsg}`,
|
||||
meta
|
||||
);
|
||||
}
|
||||
|
||||
throw new CliError(
|
||||
`[${this.name}] depends on [${project.name}] but it's not using the local package. ${updateMsg}`,
|
||||
meta
|
||||
);
|
||||
}
|
||||
|
||||
public getBuildConfig(): BuildConfig {
|
||||
return (this.json.kibana && this.json.kibana.build) || {};
|
||||
}
|
||||
|
@ -206,8 +164,3 @@ export class Project {
|
|||
return Object.values(this.allDependencies).every((dep) => isLinkDependency(dep));
|
||||
}
|
||||
}
|
||||
|
||||
// We normalize all path separators to `/` in generated files
|
||||
function normalizePath(path: string) {
|
||||
return path.replace(/[\\\/]+/g, '/');
|
||||
}
|
||||
|
|
|
@ -249,6 +249,6 @@ describe('#includeTransitiveProjects', () => {
|
|||
const quux = projects.get('quux')!;
|
||||
const withTransitive = includeTransitiveProjects([quux], projects);
|
||||
|
||||
expect([...withTransitive.keys()]).toEqual(['quux', 'bar', 'baz', 'foo']);
|
||||
expect([...withTransitive.keys()]).toEqual(['quux']);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,6 +11,7 @@ import path from 'path';
|
|||
import { promisify } from 'util';
|
||||
|
||||
import { CliError } from './errors';
|
||||
import { log } from './log';
|
||||
import { Project } from './project';
|
||||
|
||||
const glob = promisify(globSync);
|
||||
|
@ -115,14 +116,23 @@ export function buildProjectGraph(projects: ProjectMap) {
|
|||
const projectGraph: ProjectGraph = new Map();
|
||||
|
||||
for (const project of projects.values()) {
|
||||
const projectDeps = [];
|
||||
const projectDeps: Project[] = [];
|
||||
const dependencies = project.allDependencies;
|
||||
|
||||
if (!project.isSinglePackageJsonProject && Object.keys(dependencies).length > 0) {
|
||||
log.warning(
|
||||
`${project.name} is not allowed to hold local dependencies and they will be discarded. Please declare them at the root package.json`
|
||||
);
|
||||
}
|
||||
|
||||
if (!project.isSinglePackageJsonProject) {
|
||||
projectGraph.set(project.name, projectDeps);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const depName of Object.keys(dependencies)) {
|
||||
if (projects.has(depName)) {
|
||||
const dep = projects.get(depName)!;
|
||||
project.ensureValidProjectDependency(dep);
|
||||
|
||||
projectDeps.push(dep);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,10 +80,11 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
|
|||
await run(Tasks.CreatePackageJson);
|
||||
await run(Tasks.InstallDependencies);
|
||||
await run(Tasks.GeneratePackagesOptimizedAssets);
|
||||
await run(Tasks.CleanPackages);
|
||||
await run(Tasks.DeleteBazelPackagesFromBuildRoot);
|
||||
await run(Tasks.CreateNoticeFile);
|
||||
await run(Tasks.UpdateLicenseFile);
|
||||
await run(Tasks.RemovePackageJsonDeps);
|
||||
await run(Tasks.CleanPackageManagerRelatedFiles);
|
||||
await run(Tasks.CleanTypescript);
|
||||
await run(Tasks.CleanExtraFilesFromModules);
|
||||
await run(Tasks.CleanEmptyFolders);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import cpy from 'cpy';
|
||||
import Path from 'path';
|
||||
|
||||
import { discoverBazelPackages } from '@kbn/bazel-packages';
|
||||
|
@ -53,9 +54,9 @@ export const BuildXpack: Task = {
|
|||
});
|
||||
|
||||
log.info('copying built x-pack into build dir');
|
||||
await scanCopy({
|
||||
source: config.resolveFromRepo('x-pack/build/plugin/kibana/x-pack'),
|
||||
destination: build.resolvePath('x-pack'),
|
||||
await cpy('**/{.,}*', build.resolvePath('x-pack'), {
|
||||
cwd: config.resolveFromRepo('x-pack/build/plugin/kibana/x-pack'),
|
||||
parents: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import minimatch from 'minimatch';
|
||||
|
||||
import { discoverBazelPackages } from '@kbn/bazel-packages';
|
||||
import { deleteAll, deleteEmptyFolders, scanDelete, Task, GlobalTask } from '../lib';
|
||||
|
||||
export const Clean: GlobalTask = {
|
||||
|
@ -26,14 +26,11 @@ export const Clean: GlobalTask = {
|
|||
},
|
||||
};
|
||||
|
||||
export const CleanPackages: Task = {
|
||||
description: 'Cleaning source for packages that are now installed in node_modules',
|
||||
export const CleanPackageManagerRelatedFiles: Task = {
|
||||
description: 'Cleaning package manager related files from the build folder',
|
||||
|
||||
async run(config, log, build) {
|
||||
await deleteAll(
|
||||
[build.resolvePath('packages'), build.resolvePath('yarn.lock'), build.resolvePath('.npmrc')],
|
||||
log
|
||||
);
|
||||
await deleteAll([build.resolvePath('yarn.lock'), build.resolvePath('.npmrc')], log);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -200,3 +197,16 @@ export const CleanEmptyFolders: Task = {
|
|||
]);
|
||||
},
|
||||
};
|
||||
|
||||
export const DeleteBazelPackagesFromBuildRoot: Task = {
|
||||
description:
|
||||
'Deleting bazel packages outputs from build folder root as they are now installed as node_modules',
|
||||
|
||||
async run(config, log, build) {
|
||||
const bazelPackagesOnBuildRoot = (await discoverBazelPackages()).map((pkg) =>
|
||||
build.resolvePath(pkg.normalizedRepoRelativeDir)
|
||||
);
|
||||
|
||||
await deleteAll(bazelPackagesOnBuildRoot, log);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { getAllRepoRelativeBazelPackageDirs } from '@kbn/bazel-packages';
|
||||
import normalizePath from 'normalize-path';
|
||||
import { discoverBazelPackages } from '@kbn/bazel-packages';
|
||||
|
||||
import { copyAll, Task } from '../lib';
|
||||
|
||||
|
@ -48,8 +47,8 @@ export const CopySource: Task = {
|
|||
'tsconfig*.json',
|
||||
'.i18nrc.json',
|
||||
'kibana.d.ts',
|
||||
// explicitly ignore all package roots, even if they're not selected by previous patterns
|
||||
...getAllRepoRelativeBazelPackageDirs().map((dir) => `!${normalizePath(dir)}/**`),
|
||||
// explicitly ignore all bazel package locations, even if they're not selected by previous patterns
|
||||
...(await discoverBazelPackages()).map((pkg) => `!${pkg.normalizedRepoRelativeDir}/**`),
|
||||
],
|
||||
});
|
||||
},
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { discoverBazelPackages } from '@kbn/bazel-packages';
|
||||
import { pipeline } from 'stream';
|
||||
import { promisify } from 'util';
|
||||
|
||||
|
@ -24,10 +25,10 @@ const transpileWithBabel = async (srcGlobs: string[], build: Build, preset: stri
|
|||
vfs.src(
|
||||
srcGlobs.concat([
|
||||
'!**/*.d.ts',
|
||||
'!packages/**',
|
||||
'!**/node_modules/**',
|
||||
'!**/bower_components/**',
|
||||
'!**/__tests__/**',
|
||||
...(await discoverBazelPackages()).map((pkg) => `!${pkg.normalizedRepoRelativeDir}/**`),
|
||||
]),
|
||||
{
|
||||
cwd: buildRoot,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import glob from 'glob';
|
||||
import globby from 'globby';
|
||||
import Path from 'path';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
import { BAZEL_PACKAGE_DIRS } from '@kbn/bazel-packages';
|
||||
|
@ -23,11 +23,8 @@ const createProject = (rootRelativePath: string, options: ProjectOptions = {}) =
|
|||
cache: PROJECT_CACHE,
|
||||
});
|
||||
|
||||
const findProjects = (pattern: string) =>
|
||||
// NOTE: using glob.sync rather than glob-all or globby
|
||||
// because it takes less than 10 ms, while the other modules
|
||||
// both took closer to 1000ms.
|
||||
glob.sync(pattern, { cwd: REPO_ROOT }).map((path) => createProject(path));
|
||||
const findProjects = (patterns: string[]) =>
|
||||
globby.sync(patterns, { cwd: REPO_ROOT }).map((path) => createProject(path));
|
||||
|
||||
export const PROJECTS = [
|
||||
createProject('tsconfig.json'),
|
||||
|
@ -73,16 +70,18 @@ export const PROJECTS = [
|
|||
disableTypeCheck: true,
|
||||
}),
|
||||
|
||||
...findProjects('src/plugins/*/tsconfig.json'),
|
||||
...findProjects('src/plugins/chart_expressions/*/tsconfig.json'),
|
||||
...findProjects('src/plugins/vis_types/*/tsconfig.json'),
|
||||
...findProjects('x-pack/plugins/*/tsconfig.json'),
|
||||
...findProjects('examples/*/tsconfig.json'),
|
||||
...findProjects('x-pack/examples/*/tsconfig.json'),
|
||||
...findProjects('test/plugin_functional/plugins/*/tsconfig.json'),
|
||||
...findProjects('test/interpreter_functional/plugins/*/tsconfig.json'),
|
||||
...findProjects('test/server_integration/__fixtures__/plugins/*/tsconfig.json'),
|
||||
...findProjects('packages/kbn-type-summarizer/tests/tsconfig.json'),
|
||||
|
||||
...BAZEL_PACKAGE_DIRS.flatMap((dir) => findProjects(`${dir}/*/tsconfig.json`)),
|
||||
// Glob patterns to be all search at once
|
||||
...findProjects([
|
||||
'src/plugins/*/tsconfig.json',
|
||||
'src/plugins/chart_expressions/*/tsconfig.json',
|
||||
'src/plugins/vis_types/*/tsconfig.json',
|
||||
'x-pack/plugins/*/tsconfig.json',
|
||||
'examples/*/tsconfig.json',
|
||||
'x-pack/examples/*/tsconfig.json',
|
||||
'test/plugin_functional/plugins/*/tsconfig.json',
|
||||
'test/interpreter_functional/plugins/*/tsconfig.json',
|
||||
'test/server_integration/__fixtures__/plugins/*/tsconfig.json',
|
||||
'packages/kbn-type-summarizer/tests/tsconfig.json',
|
||||
...BAZEL_PACKAGE_DIRS.map((dir) => `${dir}/*/tsconfig.json`),
|
||||
]),
|
||||
];
|
||||
|
|
|
@ -11,6 +11,7 @@ import { writeFileSync } from 'fs';
|
|||
import { promisify } from 'util';
|
||||
import { pipeline } from 'stream';
|
||||
|
||||
import { discoverBazelPackages } from '@kbn/bazel-packages';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
import { transformFileStream, transformFileWithBabel } from '@kbn/dev-utils';
|
||||
import { ToolingLog } from '@kbn/tooling-log';
|
||||
|
@ -49,6 +50,11 @@ async function reportTask() {
|
|||
}
|
||||
|
||||
async function copySourceAndBabelify() {
|
||||
// get bazel packages inside x-pack
|
||||
const xpackBazelPackages = (await discoverBazelPackages())
|
||||
.filter((pkg) => pkg.normalizedRepoRelativeDir.startsWith('x-pack/'))
|
||||
.map((pkg) => `${pkg.normalizedRepoRelativeDir.replace('x-pack/', '')}/**`);
|
||||
|
||||
// copy source files and apply some babel transformations in the process
|
||||
await asyncPipeline(
|
||||
vfs.src(
|
||||
|
@ -87,6 +93,7 @@ async function copySourceAndBabelify() {
|
|||
'plugins/apm/ftr_e2e/**',
|
||||
'plugins/apm/scripts/**',
|
||||
'plugins/lists/server/scripts/**',
|
||||
...xpackBazelPackages,
|
||||
],
|
||||
allowEmpty: true,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue