@@ -5,19 +5,38 @@ const {Parser: parser} = require('yargs/helpers');
55const argv = parser ( process . argv . slice ( 2 ) ) ;
66// The command the user would like to run, either 'accept' or 'test'
77const USER_COMMAND = argv . _ [ 0 ] ;
8+
9+ // Location of all packages that we'd need to process.
10+ const API_TARGETS_LOCATION = 'packages/...' ;
11+
812// The shell command to query for all Public API guard tests.
9- const BAZEL_PUBLIC_API_TARGET_QUERY_CMD = `yarn -s bazel query --output label 'kind(nodejs_test, ...) intersect attr("tags", "api_guard", ...)'` ;
13+ const BAZEL_PUBLIC_API_TARGET_QUERY_CMD =
14+ `yarn -s bazel query --output label 'kind(nodejs_test, ${ API_TARGETS_LOCATION } ) ` +
15+ `intersect attr("tags", "api_guard", ${ API_TARGETS_LOCATION } )'` ;
1016// Bazel targets for testing Public API goldens
11- process . stdout . write ( 'Gathering all Public API targets' ) ;
17+ process . stdout . write ( 'Gathering all Public API targets... ' ) ;
1218const ALL_PUBLIC_API_TESTS = exec ( BAZEL_PUBLIC_API_TARGET_QUERY_CMD , { silent : true } )
1319 . trim ( )
1420 . split ( '\n' )
1521 . map ( ( test ) => test . trim ( ) ) ;
1622process . stdout . clearLine ( ) ;
1723process . stdout . cursorTo ( 0 ) ;
24+
1825// Bazel targets for generating Public API goldens
1926const ALL_PUBLIC_API_ACCEPTS = ALL_PUBLIC_API_TESTS . map ( ( test ) => `${ test } .accept` ) ;
2027
28+ /** Builds all targets in parallel. */
29+ function buildTargets ( targets ) {
30+ process . stdout . write ( 'Building all public API targets...' ) ;
31+ const commandResult = exec ( `yarn -s bazel build ${ targets . join ( ' ' ) } ` , { silent : true } ) ;
32+ if ( commandResult . code ) {
33+ console . error ( commandResult . stdout || commandResult . stderr ) ;
34+ } else {
35+ process . stdout . clearLine ( ) ;
36+ process . stdout . cursorTo ( 0 ) ;
37+ }
38+ }
39+
2140/**
2241 * Run the provided bazel commands on each provided target individually.
2342 */
@@ -40,9 +59,11 @@ function runBazelCommandOnTargets(command, targets, present) {
4059
4160switch ( USER_COMMAND ) {
4261 case 'accept' :
62+ buildTargets ( ALL_PUBLIC_API_ACCEPTS ) ;
4363 runBazelCommandOnTargets ( 'run' , ALL_PUBLIC_API_ACCEPTS , 'Running' ) ;
4464 break ;
4565 case 'test' :
66+ buildTargets ( ALL_PUBLIC_API_TESTS ) ;
4667 runBazelCommandOnTargets ( 'test' , ALL_PUBLIC_API_TESTS , 'Testing' ) ;
4768 break ;
4869 default :
0 commit comments