Skip to content

Commit 6c5c08e

Browse files
devversionmmalerba
authored andcommitted
build: enforce golden files and lint entry-point configuration (#18092)
* build: enforce golden files for configured entry points * build: add linting to ensure entry-points are configured
1 parent ecbccce commit 6c5c08e

File tree

11 files changed

+133
-6
lines changed

11 files changed

+133
-6
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ jobs:
285285
bazel build //:rollup_globals
286286
yarn check-rollup-globals $(bazel info bazel-bin)/rollup_globals.json
287287
288+
- run:
289+
name: Checking entry-points configuration
290+
command: |
291+
bazel build //:entry_points_manifest
292+
yarn check-entry-point-setup $(bazel info bazel-bin)/entry_points_manifest.json
293+
288294
- run: ./scripts/circleci/lint-bazel-files.sh
289295
- run: yarn ownerslint
290296
- run: yarn stylelint

BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package(default_visibility = ["//visibility:public"])
22

33
load("//:rollup-globals.bzl", "ROLLUP_GLOBALS")
4+
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
5+
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_ENTRYPOINTS")
6+
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS", "MATERIAL_TESTING_ENTRYPOINTS")
7+
load("//src/material-experimental:config.bzl", "MATERIAL_EXPERIMENTAL_ENTRYPOINTS", "MATERIAL_EXPERIMENTAL_TESTING_ENTRYPOINTS")
48

59
exports_files([
610
"LICENSE",
@@ -12,3 +16,14 @@ genrule(
1216
outs = ["rollup_globals.json"],
1317
cmd = "echo '%s' > $@" % ROLLUP_GLOBALS,
1418
)
19+
20+
entryPoints = ["cdk/%s" % e for e in CDK_ENTRYPOINTS] + \
21+
["cdk-experimental/%s" % e for e in CDK_EXPERIMENTAL_ENTRYPOINTS] + \
22+
["material/%s" % e for e in MATERIAL_ENTRYPOINTS + MATERIAL_TESTING_ENTRYPOINTS] + \
23+
["material-experimental/%s" % e for e in MATERIAL_EXPERIMENTAL_ENTRYPOINTS + MATERIAL_EXPERIMENTAL_TESTING_ENTRYPOINTS]
24+
25+
genrule(
26+
name = "entry_points_manifest",
27+
outs = ["entry_points_manifest.json"],
28+
cmd = "echo '%s' > $@" % entryPoints,
29+
)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
"gulp": "gulp",
2929
"stage-release": "ts-node --project tools/release/ tools/release/stage-release.ts",
3030
"publish-release": "ts-node --project tools/release/ tools/release/publish-release.ts",
31+
"check-entry-point-setup": "node ./scripts/check-entry-point-setup.js",
3132
"check-release-output": "ts-node --project tools/release tools/release/check-release-output.ts",
33+
"check-rollup-globals": "ts-node --project scripts/ scripts/check-rollup-globals.ts",
3234
"changelog": "ts-node --project tools/release tools/release/changelog.ts",
3335
"preinstall": "node ./tools/npm/check-npm.js",
3436
"format:ts": "git-clang-format HEAD $(git diff HEAD --name-only | grep -v \"\\.d\\.ts\")",
3537
"format:bazel": "yarn -s bazel:buildifier --lint=fix --mode=fix",
3638
"format": "yarn -s format:ts && yarn -s format:bazel",
3739
"cherry-pick-patch": "ts-node --project tools/cherry-pick-patch/ tools/cherry-pick-patch/cherry-pick-patch.ts",
38-
"check-rollup-globals": "ts-node --project scripts/ scripts/check-rollup-globals.ts",
3940
"ownerslint": "ts-node --project scripts/ scripts/ownerslint.ts",
4041
"tslint": "tslint -c tslint.json --project ./tsconfig.json",
4142
"stylelint": "stylelint \"src/**/*.+(css|scss)\" --config .stylelintrc.json --syntax scss"

scripts/check-entry-point-setup.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script that detects and validates entry-points. The script walks through all
5+
* source files in the code base and ensures that determined entry-points are
6+
* configured. The list of configured entry-points in Starlark is passed to the
7+
* script through a manifest file (generated by Bazel)
8+
*/
9+
10+
const {join, dirname} = require('path');
11+
const {sync: globSync} = require('glob');
12+
const minimatch = require('minimatch');
13+
const fs = require('fs');
14+
const chalk = require('chalk');
15+
16+
const [entryPointManifest] = process.argv.slice(2);
17+
const entryPoints = JSON.parse(fs.readFileSync(entryPointManifest, 'utf8'));
18+
const packagesDir = join(__dirname, '../src');
19+
20+
/**
21+
* Globs that matches directories which should never be considered
22+
* as entry-points.
23+
*/
24+
const excludeGlobs = [
25+
'cdk/testing/private',
26+
'*/schematics/**',
27+
];
28+
29+
/** List of detected entry-points which are not properly configured. */
30+
const nonConfigured = [];
31+
32+
// We require a minimum depth of two. This ensures that we only check entry-points and
33+
// do not check package names (like "cdk"). There is no validation for package names yet.
34+
globSync('*/*/**/public-api.ts', {cwd: packagesDir}).forEach(filePath => {
35+
const entryPointName = dirname(filePath);
36+
37+
if (!excludeGlobs.some(pattern => minimatch(entryPointName, pattern)) &&
38+
!entryPoints.includes(entryPointName)) {
39+
nonConfigured.push(entryPointName);
40+
}
41+
});
42+
43+
if (nonConfigured.length) {
44+
console.error(chalk.red('Found entry-points which are not configured. Add the following ' +
45+
'entry-points to the package-specific "config.bzl" file:\n'));
46+
nonConfigured.forEach(e => console.warn(chalk.yellow(` - ${e}`)));
47+
process.exit(1);
48+
} else {
49+
console.log(chalk.green('All detected entry-points are configured properly.'));
50+
}

src/material-experimental/config.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ entryPoints = [
1212
"mdc-menu",
1313
"mdc-menu/testing",
1414
"mdc-progress-bar",
15+
"mdc-progress-bar/testing",
1516
"mdc-radio",
1617
"mdc-select",
1718
"mdc-sidenav",
1819
"mdc-slide-toggle",
1920
"mdc-slide-toggle/testing",
2021
"mdc-slider",
21-
"mdc-tabs",
22+
"mdc-slider/testing",
23+
"mdc-snackbar",
2224
"mdc-table",
25+
"mdc-tabs",
2326
"popover-edit",
2427
]
2528

src/material-experimental/mdc-snackbar/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "ng_module", "sass_binary", "sass_library")
54

65
ng_module(
76
name = "mdc-snackbar",
@@ -20,7 +19,7 @@ ng_module(
2019
)
2120

2221
sass_library(
23-
name = "snackbar_scss_lib",
22+
name = "mdc_snackbar_scss_lib",
2423
srcs = glob(["**/_*.scss"]),
2524
deps = [
2625
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",

src/material/config.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ entryPoints = [
2424
"expansion/testing",
2525
"form-field",
2626
"grid-list",
27+
"grid-list/testing",
2728
"icon",
2829
"input",
2930
"list",

tools/public_api_guard/BUILD.bazel

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
4+
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS", "MATERIAL_TESTING_ENTRYPOINTS")
35
load(":generate-guard-tests.bzl", "generate_test_targets")
46

7+
golden_files = ["cdk/%s.d.ts" % e for e in CDK_ENTRYPOINTS] + \
8+
["material/%s.d.ts" % e for e in MATERIAL_ENTRYPOINTS + MATERIAL_TESTING_ENTRYPOINTS] + [
9+
# Primary entry-points.
10+
"cdk/cdk.d.ts",
11+
"material/material.d.ts",
12+
"youtube-player/youtube-player.d.ts",
13+
"google-maps/google-maps.d.ts",
14+
]
15+
516
# Generate the API guard test targets for each golden file in the current package.
6-
generate_test_targets(glob(["**/*.d.ts"]))
17+
generate_test_targets(golden_files)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface BottomSheetHarnessFilters extends BaseHarnessFilters {
2+
}
3+
4+
export declare class MatBottomSheetHarness extends ComponentHarness {
5+
dismiss(): Promise<void>;
6+
getAriaLabel(): Promise<string | null>;
7+
static hostSelector: string;
8+
static with(options?: BottomSheetHarnessFilters): HarnessPredicate<MatBottomSheetHarness>;
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export declare abstract class MatFormFieldControlHarness extends ComponentHarness {
2+
}

0 commit comments

Comments
 (0)