-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: add CI check to ensure consistent exports for MDC packages #20960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| export const config = { | ||
| // The MDC sidenav hasn't been implemented yet. | ||
| skippedPackages: ['mdc-sidenav'], | ||
| skippedExports: { | ||
| 'mdc-chips': [ | ||
| // These components haven't been implemented for MDC due to a different accessibility pattern. | ||
| 'MatChipListChange', | ||
| 'MatChipList' | ||
| ], | ||
| 'mdc-autocomplete': [ | ||
| // Private base classes that are only exported for MDC. | ||
| '_MatAutocompleteBase', | ||
| '_MatAutocompleteTriggerBase', | ||
| '_MatAutocompleteOriginBase' | ||
| ], | ||
| 'mdc-core': [ | ||
| // Private base classes that are only exported for MDC. | ||
| '_MatOptionBase', | ||
| '_MatOptgroupBase' | ||
| ], | ||
| 'mdc-dialog': [ | ||
| // Private base classes and utility function that are only exported for MDC. | ||
| '_MatDialogBase', | ||
| '_MatDialogContainerBase', | ||
| '_closeDialogVia', | ||
| ], | ||
| 'mdc-input': [ | ||
| // TODO: an MDC version of this directive has to be implemented. | ||
| 'MatTextareaAutosize' | ||
| ], | ||
| 'mdc-menu': [ | ||
| // Private base class that is only exported for MDC. | ||
| '_MatMenuBase' | ||
| ], | ||
| 'mdc-paginator': [ | ||
| // Private base class that is only exported for MDC. | ||
| '_MatPaginatorBase' | ||
| ], | ||
| 'mdc-radio': [ | ||
| // Private base classes that are only exported for MDC. | ||
| '_MatRadioGroupBase', | ||
| '_MatRadioButtonBase', | ||
| ], | ||
| 'mdc-select': [ | ||
| // Private base class that is only exported for MDC. | ||
| '_MatSelectBase' | ||
| ], | ||
| 'mdc-slide-toggle': [ | ||
| // Private module used to provide some common functionality. | ||
| '_MatSlideToggleRequiredValidatorModule' | ||
| ], | ||
| 'mdc-snack-bar': [ | ||
| // Private interface used to ensure consistency for MDC package. | ||
| '_SnackBarContainer' | ||
| ], | ||
| 'mdc-tabs': [ | ||
| // Private base classes that are only exported for MDC. | ||
| '_MatTabBodyBase', | ||
| '_MatTabHeaderBase', | ||
| '_MatTabNavBase', | ||
| '_MatTabLinkBase', | ||
| '_MatTabGroupBase' | ||
| ] | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import {join} from 'path'; | ||
| import {readdirSync, existsSync} from 'fs'; | ||
| import * as ts from 'typescript'; | ||
| import chalk from 'chalk'; | ||
| import {config} from './check-mdc-exports-config'; | ||
|
|
||
| // Script which ensures that a particular MDC package exports all of the same symbols as its | ||
| // non-MDC counterparts. Only looks at symbol names, not their signatures. Exceptions | ||
| // can be configured through the `check-mdc-exports-config.ts` file. | ||
|
|
||
| let hasFailed = false; | ||
|
|
||
| readdirSync(join(__dirname, '../src/material'), {withFileTypes: true}) | ||
| .filter(entity => entity.isDirectory()) | ||
| .map(entity => entity.name) | ||
| .filter(name => !config.skippedPackages.includes(`mdc-${name}`)) | ||
| .filter(hasCorrespondingMdcPackage) | ||
| .forEach(name => { | ||
| const missingSymbols = getMissingSymbols(name, config.skippedExports[`mdc-${name}`] || []); | ||
|
|
||
| if (missingSymbols.length) { | ||
| console.log(chalk.redBright(`\nMissing symbols from mdc-${name}:`)); | ||
| console.log(missingSymbols.join('\n')); | ||
| hasFailed = true; | ||
| } | ||
| }); | ||
|
|
||
| if (hasFailed) { | ||
| console.log(chalk.redBright( | ||
| '\nDetected one or more MDC packages that do not export the same set of symbols from\n' + | ||
| 'public-api.ts as their non-MDC counterpart.\nEither implement the missing symbols or ' + | ||
| 're-export them from the Material package,\nor add them to the `skippedExports` list in ' + | ||
| `scripts/check-mdc-exports-config.ts.` | ||
| )); | ||
| process.exit(1); | ||
| } else { | ||
| console.log(chalk.green( | ||
| 'All MDC packages export the same public API symbols as their non-MDC counterparts.')); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the names of symbols that are present in a Material package, | ||
| * but not its MDC counterpart. | ||
| */ | ||
| function getMissingSymbols(name: string, skipped: string[]): string[] { | ||
| const mdcExports = getExports(`material-experimental/mdc-${name}`); | ||
| const materialExports = getExports(`material/${name}`); | ||
|
|
||
| if (!mdcExports.length) { | ||
| throw Error(`Could not resolve exports in mdc-${name}`); | ||
| } | ||
|
|
||
| if (!materialExports.length) { | ||
| throw Error(`Could not resolve exports in ${name}`); | ||
| } | ||
|
|
||
| return materialExports.filter(exportName => { | ||
| return !skipped.includes(exportName) && !mdcExports.includes(exportName); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the name of the exported symbols from a particular package. | ||
| * Based on https://github.com/angular/angular/blob/master/tools/ts-api-guardian/lib/serializer.ts | ||
| */ | ||
| function getExports(name: string): string[] { | ||
| const entryPoint = join(__dirname, '../src', name, 'public-api.ts'); | ||
| const program = ts.createProgram([entryPoint], { | ||
| // This is a bit faster than the default and seems to produce identical results. | ||
| moduleResolution: ts.ModuleResolutionKind.Classic | ||
| }); | ||
| const sourceFile = program.getSourceFiles().find(f => f.fileName.endsWith('public-api.ts'))!; | ||
| const typeChecker = program.getTypeChecker(); | ||
| const mainSymbol = typeChecker.getSymbolAtLocation(sourceFile); | ||
|
|
||
| return (mainSymbol ? (typeChecker.getExportsOfModule(mainSymbol) || []) : []).map(symbol => { | ||
| // tslint:disable-next-line:no-bitwise | ||
| if (symbol.flags & ts.SymbolFlags.Alias) { | ||
| const resolvedSymbol = typeChecker.getAliasedSymbol(symbol); | ||
| return (!resolvedSymbol.valueDeclaration && !resolvedSymbol.declarations) ? | ||
| symbol : resolvedSymbol; | ||
| } else { | ||
| return symbol; | ||
| } | ||
| }).map(symbol => symbol.name); | ||
| } | ||
|
|
||
| /** Checks whether a particular Material package has an MDC-based equivalent. */ | ||
| function hasCorrespondingMdcPackage(name: string): boolean { | ||
| return existsSync(join(__dirname, '../src/material-experimental', 'mdc-' + name)); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,17 +6,21 @@ | |
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| export { | ||
| MAT_FORM_FIELD, | ||
| MatFormFieldControl, | ||
| getMatFormFieldDuplicatedHintError, | ||
| getMatFormFieldMissingControlError, | ||
| } from '@angular/material/form-field'; | ||
|
|
||
| export * from './directives/label'; | ||
| export * from './directives/error'; | ||
| export * from './directives/hint'; | ||
| export * from './directives/prefix'; | ||
| export * from './directives/suffix'; | ||
| export * from './form-field'; | ||
| export * from './module'; | ||
|
|
||
| export { | ||
| MAT_FORM_FIELD, | ||
| MatFormFieldControl, | ||
| getMatFormFieldDuplicatedHintError, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, these don't have an underscore but they are
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we have things like this in a bunch of packages, but we just have to live with it and eventually deprecate them.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, if we decide to keep these we should at least move them under a TODO to get rid of them later
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, at this point anything without an underscore would have to go through the normal process. I would like to explore removing "library internal" symbols from our npm packages via transformation at some point, but that's probably not going to happen soon. |
||
| getMatFormFieldMissingControlError, | ||
| getMatFormFieldPlaceholderConflictError, | ||
| _MAT_HINT, | ||
| MatPlaceholder, | ||
| matFormFieldAnimations, | ||
| } from '@angular/material/form-field'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,5 @@ export { | |
| MenuPositionX, | ||
| MenuPositionY, | ||
| transformMenu, | ||
| MAT_MENU_CONTENT, | ||
| } from '@angular/material/menu'; | ||
Uh oh!
There was an error while loading. Please reload this page.