Skip to content

Commit

Permalink
[kbn/pm] throw an error if package doesn't have a script (#89438)
Browse files Browse the repository at this point in the history
* [kbn/pm] throw an error if package doesn't have a script

* actually add the kbn/es build script 🤦‍♂️

Co-authored-by: spalger <spalger@users.noreply.github.com>
  • Loading branch information
Spencer and spalger authored Jan 27, 2021
1 parent 96e4bdc commit 3c60443
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .ci/teamcity/tests/test_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -euo pipefail
source "$(dirname "${0}")/../util.sh"

checks-reporter-with-killswitch "Test Projects" \
yarn kbn run test --exclude kibana --oss --skip-kibana-plugins
yarn kbn run test --exclude kibana --oss --skip-kibana-plugins --skip-missing
1 change: 1 addition & 0 deletions packages/kbn-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"devOnly": true
},
"scripts": {
"build": "node scripts/build",
"kbn:bootstrap": "node scripts/build",
"kbn:watch": "node scripts/build --watch"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-pm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ e.g. `build` or `test`. Instead of jumping into each package and running
`yarn build` you can run:

```
yarn kbn run build
yarn kbn run build --skip-missing
```

And if needed, you can skip packages in the same way as for bootstrapping, e.g.
with `--exclude` and `--skip-kibana-plugins`:

```
yarn kbn run build --exclude kibana
yarn kbn run build --exclude kibana --skip-missing
```

### Watching
Expand Down
26 changes: 18 additions & 8 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ function help() {
--debug Set log level to debug
--quiet Set log level to error
--silent Disable log output

"run" options:
--skip-missing Ignore packages which don't have the requested script
` + '\n');
}

async function run(argv) {
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].setLogLevel(Object(_kbn_dev_utils_tooling_log__WEBPACK_IMPORTED_MODULE_3__["pickLevelFromFlags"])(getopts__WEBPACK_IMPORTED_MODULE_1___default()(argv, {
boolean: ['verbose', 'debug', 'quiet', 'silent']
boolean: ['verbose', 'debug', 'quiet', 'silent', 'skip-missing']
}))); // We can simplify this setup (and remove this extra handling) once Yarn
// starts forwarding the `--` directly to this script, see
// https://github.com/yarnpkg/yarn/blob/b2d3e1a8fe45ef376b716d597cc79b38702a9320/src/cli/index.js#L174-L182
Expand Down Expand Up @@ -52620,7 +52623,8 @@ const RunCommand = {
name: 'run',

async run(projects, projectGraph, {
extraArgs
extraArgs,
options
}) {
const batchedProjects = Object(_utils_projects__WEBPACK_IMPORTED_MODULE_3__["topologicallyBatchProjects"])(projects, projectGraph);

Expand All @@ -52631,13 +52635,19 @@ const RunCommand = {
const scriptName = extraArgs[0];
const scriptArgs = extraArgs.slice(1);
await Object(_utils_parallelize__WEBPACK_IMPORTED_MODULE_2__["parallelizeBatches"])(batchedProjects, async project => {
if (project.hasScript(scriptName)) {
_utils_log__WEBPACK_IMPORTED_MODULE_1__["log"].info(`[${project.name}] running "${scriptName}" script`);
await project.runScriptStreaming(scriptName, {
args: scriptArgs
});
_utils_log__WEBPACK_IMPORTED_MODULE_1__["log"].success(`[${project.name}] complete`);
if (!project.hasScript(scriptName)) {
if (!!options['skip-missing']) {
return;
}

throw new _utils_errors__WEBPACK_IMPORTED_MODULE_0__["CliError"](`[${project.name}] no "${scriptName}" script defined. To skip packages without the "${scriptName}" script pass --skip-missing`);
}

_utils_log__WEBPACK_IMPORTED_MODULE_1__["log"].info(`[${project.name}] running "${scriptName}" script`);
await project.runScriptStreaming(scriptName, {
args: scriptArgs
});
_utils_log__WEBPACK_IMPORTED_MODULE_1__["log"].success(`[${project.name}] complete`);
});
}

Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-pm/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function help() {
--debug Set log level to debug
--quiet Set log level to error
--silent Disable log output
"run" options:
--skip-missing Ignore packages which don't have the requested script
` + '\n'
);
}
Expand All @@ -49,7 +52,7 @@ export async function run(argv: string[]) {
log.setLogLevel(
pickLevelFromFlags(
getopts(argv, {
boolean: ['verbose', 'debug', 'quiet', 'silent'],
boolean: ['verbose', 'debug', 'quiet', 'silent', 'skip-missing'],
})
)
);
Expand Down
22 changes: 15 additions & 7 deletions packages/kbn-pm/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const RunCommand: ICommand = {
description: 'Run script defined in package.json in each package that contains that script.',
name: 'run',

async run(projects, projectGraph, { extraArgs }) {
async run(projects, projectGraph, { extraArgs, options }) {
const batchedProjects = topologicallyBatchProjects(projects, projectGraph);

if (extraArgs.length === 0) {
Expand All @@ -27,13 +27,21 @@ export const RunCommand: ICommand = {
const scriptArgs = extraArgs.slice(1);

await parallelizeBatches(batchedProjects, async (project) => {
if (project.hasScript(scriptName)) {
log.info(`[${project.name}] running "${scriptName}" script`);
await project.runScriptStreaming(scriptName, {
args: scriptArgs,
});
log.success(`[${project.name}] complete`);
if (!project.hasScript(scriptName)) {
if (!!options['skip-missing']) {
return;
}

throw new CliError(
`[${project.name}] no "${scriptName}" script defined. To skip packages without the "${scriptName}" script pass --skip-missing`
);
}

log.info(`[${project.name}] running "${scriptName}" script`);
await project.runScriptStreaming(scriptName, {
args: scriptArgs,
});
log.success(`[${project.name}] complete`);
});
},
};
2 changes: 1 addition & 1 deletion test/scripts/checks/test_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source src/dev/ci_setup/setup_env.sh

checks-reporter-with-killswitch "Test Projects" \
yarn kbn run test --exclude kibana --oss --skip-kibana-plugins
yarn kbn run test --exclude kibana --oss --skip-kibana-plugins --skip-missing

0 comments on commit 3c60443

Please sign in to comment.