From 6d92c99c49c874fedd33d3a304c5dc4bcfdf4c44 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sun, 28 Oct 2018 19:05:20 +0100 Subject: [PATCH] build: add option to disable ts-api-guardian default angular tag rules (#26761) Since the API guardian can be also used by other projects, we should not set up the default Angular project tag rules unless specified explicitly through a given command option (`useAngularTagRules`) PR Close #26761 --- tools/ts-api-guardian/index.bzl | 13 ++++++++++++- tools/ts-api-guardian/lib/cli.ts | 26 ++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/ts-api-guardian/index.bzl b/tools/ts-api-guardian/index.bzl index 1a0556de49..07f7dfb99b 100644 --- a/tools/ts-api-guardian/index.bzl +++ b/tools/ts-api-guardian/index.bzl @@ -19,7 +19,15 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "nodejs_test") COMMON_MODULE_IDENTIFIERS = ["angular", "jasmine", "protractor"] -def ts_api_guardian_test(name, golden, actual, data = [], strip_export_pattern = ["^__", "^ɵ"], allow_module_identifiers = COMMON_MODULE_IDENTIFIERS, **kwargs): +def ts_api_guardian_test( + name, + golden, + actual, + data = [], + strip_export_pattern = ["^__", "^ɵ"], + allow_module_identifiers = COMMON_MODULE_IDENTIFIERS, + use_angular_tag_rules = True, + **kwargs): """Runs ts_api_guardian """ data += [ @@ -39,6 +47,9 @@ def ts_api_guardian_test(name, golden, actual, data = [], strip_export_pattern = for i in allow_module_identifiers: args += ["--allowModuleIdentifiers", i] + if use_angular_tag_rules: + args += ["--useAngularTagRules"] + nodejs_test( name = name, data = data, diff --git a/tools/ts-api-guardian/lib/cli.ts b/tools/ts-api-guardian/lib/cli.ts index 4a5c8115ca..44195ab75d 100644 --- a/tools/ts-api-guardian/lib/cli.ts +++ b/tools/ts-api-guardian/lib/cli.ts @@ -24,11 +24,28 @@ export function startCli() { const options: SerializationOptions = { stripExportPattern: [].concat(argv['stripExportPattern']), allowModuleIdentifiers: [].concat(argv['allowModuleIdentifiers']), - exportTags: {required: ['publicApi'], banned: ['experimental'], toCopy: ['deprecated']}, - memberTags: {required: [], banned: ['experimental', 'publicApi'], toCopy: ['deprecated']}, - paramTags: {required: [], banned: ['experimental', 'publicApi'], toCopy: ['deprecated']} }; + // Since the API guardian can be also used by other projects, we should not set up the default + // Angular project tag rules unless specified explicitly through a given option. + if (argv['useAngularTagRules']) { + options.exportTags = { + required: ['publicApi'], + banned: ['experimental'], + toCopy: ['deprecated'] + }; + options.memberTags = { + required: [], + banned: ['experimental', 'publicApi'], + toCopy: ['deprecated'] + }; + options.paramTags = { + required: [], + banned: ['experimental', 'publicApi'], + toCopy: ['deprecated'] + }; + } + for (const error of errors) { console.warn(error); } @@ -85,7 +102,7 @@ export function parseArguments(input: string[]): 'allowModuleIdentifiers' ], boolean: [ - 'help', + 'help', 'useAngularTagRules', // Options used by chalk automagically 'color', 'no-color' ], @@ -156,6 +173,7 @@ Options: --rootDir Specify the root directory of input files + --useAngularTagRules Whether the Angular specific tag rules should be used. --stripExportPattern Do not output exports matching the pattern --allowModuleIdentifiers Whitelist identifier for "* as foo" imports`);