mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[kbn/bootstrap] validate that certain deps don't ship in production (#80549)
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
cd9381c118
commit
07c1284e9d
23 changed files with 842 additions and 709 deletions
|
@ -131,10 +131,7 @@
|
|||
"@kbn/i18n": "1.0.0",
|
||||
"@kbn/interpreter": "1.0.0",
|
||||
"@kbn/logging": "1.0.0",
|
||||
"@kbn/pm": "1.0.0",
|
||||
"@kbn/std": "1.0.0",
|
||||
"@kbn/telemetry-tools": "1.0.0",
|
||||
"@kbn/test-subj-selector": "0.2.1",
|
||||
"@kbn/ui-framework": "1.0.0",
|
||||
"@kbn/ace": "1.0.0",
|
||||
"@kbn/monaco": "1.0.0",
|
||||
|
@ -247,8 +244,11 @@
|
|||
"@kbn/expect": "1.0.0",
|
||||
"@kbn/optimizer": "1.0.0",
|
||||
"@kbn/plugin-generator": "1.0.0",
|
||||
"@kbn/pm": "1.0.0",
|
||||
"@kbn/release-notes": "1.0.0",
|
||||
"@kbn/telemetry-tools": "1.0.0",
|
||||
"@kbn/test": "1.0.0",
|
||||
"@kbn/test-subj-selector": "0.2.1",
|
||||
"@kbn/utility-types": "1.0.0",
|
||||
"@microsoft/api-documenter": "7.7.2",
|
||||
"@microsoft/api-extractor": "7.7.0",
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
"type": "git",
|
||||
"url": "git+https://github.com/elastic/kibana.git"
|
||||
},
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Spencer Alger <email@spalger.com>",
|
||||
"license": "Apache-2.0",
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/plugin-proposal-export-namespace-from": "^7.10.4",
|
||||
|
|
|
@ -12,10 +12,8 @@
|
|||
"dependencies": {
|
||||
"@elastic/safer-lodash-set": "0.0.0",
|
||||
"@kbn/config-schema": "1.0.0",
|
||||
"@kbn/dev-utils": "1.0.0",
|
||||
"@kbn/logging": "1.0.0",
|
||||
"@kbn/std": "1.0.0",
|
||||
"@kbn/utility-types": "1.0.0",
|
||||
"js-yaml": "^3.14.0",
|
||||
"load-json-file": "^6.2.0",
|
||||
"lodash": "^4.17.20",
|
||||
|
@ -24,6 +22,8 @@
|
|||
"type-detect": "^4.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kbn/dev-utils": "1.0.0",
|
||||
"@kbn/utility-types": "1.0.0",
|
||||
"typescript": "4.0.2",
|
||||
"tsd": "^0.13.1"
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
"kbn:bootstrap": "yarn build",
|
||||
"kbn:watch": "yarn build --watch"
|
||||
},
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@kbn/utils": "1.0.0",
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"main": "target/index.js",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"kbn:bootstrap": "rm -rf target && tsc",
|
||||
"kbn:watch": "rm -rf target && tsc --watch"
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"private": true,
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"kbn:bootstrap": "node scripts/build",
|
||||
"kbn:watch": "node scripts/build --watch"
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
"version": "2.0.0",
|
||||
"main": "import_resolver_kibana.js",
|
||||
"license": "Apache-2.0",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/elastic/kibana/tree/master/packages/kbn-eslint-import-resolver-kibana"
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "6.8.0",
|
||||
"babel-eslint": "^10.0.3"
|
||||
|
|
|
@ -3,5 +3,8 @@
|
|||
"main": "./expect.js",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
"private": true,
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
}
|
||||
}
|
||||
|
|
1428
packages/kbn-pm/dist/index.js
vendored
1428
packages/kbn-pm/dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,9 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"private": true,
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"kbn:watch": "webpack --watch --progress",
|
||||
|
|
|
@ -26,7 +26,7 @@ import { ICommand } from './';
|
|||
import { getAllChecksums } from '../utils/project_checksums';
|
||||
import { BootstrapCacheFile } from '../utils/bootstrap_cache_file';
|
||||
import { readYarnLock } from '../utils/yarn_lock';
|
||||
import { validateYarnLock } from '../utils/validate_yarn_lock';
|
||||
import { validateDependencies } from '../utils/validate_dependencies';
|
||||
|
||||
export const BootstrapCommand: ICommand = {
|
||||
description: 'Install dependencies and crosslink projects',
|
||||
|
@ -59,7 +59,7 @@ export const BootstrapCommand: ICommand = {
|
|||
const yarnLock = await readYarnLock(kbn);
|
||||
|
||||
if (options.validate) {
|
||||
await validateYarnLock(kbn, yarnLock);
|
||||
await validateDependencies(kbn, yarnLock);
|
||||
}
|
||||
|
||||
await linkProjectExecutables(projects, projectGraph);
|
||||
|
|
|
@ -153,6 +153,10 @@ export class Project {
|
|||
return (this.json.kibana && this.json.kibana.clean) || {};
|
||||
}
|
||||
|
||||
public isFlaggedAsDevOnly() {
|
||||
return !!(this.json.kibana && this.json.kibana.devOnly);
|
||||
}
|
||||
|
||||
public hasScript(name: string) {
|
||||
return name in this.scripts;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ export function renderProjectsTree(rootPath: string, projects: Map<string, Proje
|
|||
return treeToString(createTreeStructure(projectsTree));
|
||||
}
|
||||
|
||||
interface ITree {
|
||||
export interface ITree {
|
||||
name?: string;
|
||||
children?: ITreeChildren;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ type DirOrProjectName = string | typeof projectKey;
|
|||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface IProjectsTree extends Map<DirOrProjectName, string | IProjectsTree> {}
|
||||
|
||||
function treeToString(tree: ITree) {
|
||||
export function treeToString(tree: ITree) {
|
||||
return [tree.name].concat(childrenToStrings(tree.children, '')).join('\n');
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,16 @@
|
|||
// @ts-expect-error published types are useless
|
||||
import { stringify as stringifyLockfile } from '@yarnpkg/lockfile';
|
||||
import dedent from 'dedent';
|
||||
import chalk from 'chalk';
|
||||
|
||||
import { writeFile } from './fs';
|
||||
import { Kibana } from './kibana';
|
||||
import { YarnLock } from './yarn_lock';
|
||||
import { log } from './log';
|
||||
import { Project } from './project';
|
||||
import { ITree, treeToString } from './projects_tree';
|
||||
|
||||
export async function validateYarnLock(kbn: Kibana, yarnLock: YarnLock) {
|
||||
export async function validateDependencies(kbn: Kibana, yarnLock: YarnLock) {
|
||||
// look through all of the packages in the yarn.lock file to see if
|
||||
// we have accidentally installed multiple lodash v4 versions
|
||||
const lodash4Versions = new Set<string>();
|
||||
|
@ -157,5 +159,45 @@ export async function validateYarnLock(kbn: Kibana, yarnLock: YarnLock) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
// look for packages that have the the `kibana.devOnly` flag in their package.json
|
||||
// and make sure they aren't included in the production dependencies of Kibana
|
||||
const devOnlyProjectsInProduction = getDevOnlyProductionDepsTree(kbn, 'kibana');
|
||||
if (devOnlyProjectsInProduction) {
|
||||
log.error(dedent`
|
||||
Some of the packages in the production dependency chain for Kibana and X-Pack are
|
||||
flagged with "kibana.devOnly" in their package.json. Please check changes made to
|
||||
packages and their dependencies to ensure they don't end up in production.
|
||||
|
||||
The devOnly dependencies that are being dependend on in production are:
|
||||
|
||||
${treeToString(devOnlyProjectsInProduction).split('\n').join('\n ')}
|
||||
`);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
log.success('yarn.lock analysis completed without any issues');
|
||||
}
|
||||
|
||||
function getDevOnlyProductionDepsTree(kbn: Kibana, projectName: string) {
|
||||
const project = kbn.getProject(projectName);
|
||||
const childProjectNames = [
|
||||
...Object.keys(project.productionDependencies).filter((name) => kbn.hasProject(name)),
|
||||
...(projectName === 'kibana' ? ['x-pack'] : []),
|
||||
];
|
||||
|
||||
const children = childProjectNames
|
||||
.map((n) => getDevOnlyProductionDepsTree(kbn, n))
|
||||
.filter((t): t is ITree => !!t);
|
||||
|
||||
if (!children.length && !project.isFlaggedAsDevOnly()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tree: ITree = {
|
||||
name: project.isFlaggedAsDevOnly() ? chalk.red.bold(projectName) : projectName,
|
||||
children,
|
||||
};
|
||||
|
||||
return tree;
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"main": "target/index.js",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"kbn:bootstrap": "tsc",
|
||||
"kbn:watch": "tsc --watch"
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
"build": "tsc",
|
||||
"kbn:bootstrap": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.20"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kbn/utility-types": "1.0.0",
|
||||
"typescript": "4.0.2",
|
||||
"tsd": "^0.13.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kbn/utility-types": "1.0.0",
|
||||
"lodash": "^4.17.20"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"main": "./target/index.js",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"dependencies": {
|
||||
"@kbn/dev-utils": "1.0.0",
|
||||
"@storybook/addon-actions": "^6.0.16",
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
"license": "Apache-2.0",
|
||||
"main": "./target/index.js",
|
||||
"private": true,
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts --source-maps=inline",
|
||||
"kbn:bootstrap": "yarn build",
|
||||
|
|
|
@ -5,5 +5,8 @@
|
|||
"main": "index.js",
|
||||
"keywords": [],
|
||||
"author": "Spencer Alger <email@spalger.com>",
|
||||
"license": "Apache-2.0"
|
||||
"license": "Apache-2.0",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
"kbn:bootstrap": "yarn build",
|
||||
"kbn:watch": "yarn build --watch"
|
||||
},
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.10.5",
|
||||
"@jest/types": "^26.5.2",
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
"license": "Apache-2.0",
|
||||
"main": "target",
|
||||
"types": "target/index.d.ts",
|
||||
"kibana": {
|
||||
"devOnly": true
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"kbn:bootstrap": "tsc",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue