-
Notifications
You must be signed in to change notification settings - Fork 4
rewrite components doc generator #58
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58 +/- ##
==========================================
- Coverage 95.41% 90.02% -5.40%
==========================================
Files 15 16 +1
Lines 436 461 +25
Branches 149 129 -20
==========================================
- Hits 416 415 -1
- Misses 20 44 +24
- Partials 0 2 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
272bb04 to
8eacf65
Compare
8eacf65 to
84993fb
Compare
c08a6b9 to
b382d76
Compare
| export type Columns = 1 | 2 | 3 | 4; | ||
| export type Widths = 25 | '50%' | 100 | '33%'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new test case on number-only and on mixed string+number union types.
We do not have a real use-case yet, but let's make sure it works anyway
| import * as React from 'react'; | ||
| import { TableProps } from './interfaces'; | ||
|
|
||
| export { TableProps }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new implementation is more strict, it checks that the interface is actually exported in the index file (which was our requirement all the time)
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { IconProps } from '../node_modules_mock/icon'; | ||
| import { IconProps } from 'icon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this test to more accurately represent node_modules resolution. node_modules_mock is a normal project folder, typescript has no special logic there.
| import ts from 'typescript'; | ||
| import pathe from 'pathe'; | ||
|
|
||
| function printDiagnostics(diagnostics: readonly ts.Diagnostic[]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Official docs for API used in this file: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API
| // deprecated, now unused | ||
| additionalInputFilePaths?: Array<string>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was added some time ago: #43
In the new implementation, the workaround is not needed. Imports from node_modules just work, as the updated test-case shows
| // disabled until migration is complete | ||
| // if (unknownExports.length > 0) { | ||
| // throw new Error(`Unexpected exports in ${componentName}: ${unknownExports.join(', ')}`); | ||
| // } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to fail the build if a button/index.tsx file exports anything other than ButtonProps and Button (as a default export).
But this will require additional work in downstream repositories. I will enable it after migration is completed.
| function stripUndefined(typeString: string) { | ||
| return typeString.replace(/\| undefined$/, '').trim(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried multiple options here
type.getNonNullableType()allows to remove bothundefinedandnull, but we want nulls still to be printed. Sadly,type.getNonUndefinedType()does not exist- Typedoc created a custom function for this use-case. But it mutates the type in-place which is concerning. Not an option.
That's how I landed on "fixing" the printed value as the safest and most future proof option which does not depend on any internals
| { | ||
| name: 'analyticsMetadata', | ||
| analyticsTag: 'View details in Analytics tab', | ||
| defaultValue: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When comparing values, Jest ignores undefined anyway. Removed them in a bunch of places to keep the assertions shorter, more readable
|
|
||
| test('should detect component which uses createPortals', () => { | ||
| expect(component.name).toEqual('SimplePortal'); | ||
| expect(component.description).toEqual('Component-level description'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated this feature
| import { bootstrapProject } from '../../src/bootstrap'; | ||
| import { TestUtilsDoc } from '../../src/test-utils/interfaces'; | ||
|
|
||
| // TODO: Move this file into common location, improve naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this TODO is not going to happen
| // istanbul ignore next | ||
| if (!moduleSymbol) { | ||
| throw new Error(`Unable to resolve module: ${sourceFile.fileName}`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript says the value could be undefined, but there is no real use-case for it.
Decided to throw an error just in case, but this code is not testable.
| isDefault: region.name === 'children', | ||
| visualRefreshTag: getCommentTag(region, 'visualrefresh'), | ||
| deprecatedTag: getCommentTag(region, 'deprecated'), | ||
| i18nTag: castI18nTag(getCommentTag(region, 'i18n')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have any cases where there is i18n support for regions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about anywhere in the components, but in this repo we have a unit test for it
documenter/fixtures/components/i18n-tag/example/index.tsx
Lines 17 to 22 in 5bc2709
| /** | |
| * Main content | |
| * @displayname content | |
| * @i18n | |
| */ | |
| children?: React.ReactNode; |
So I decided I keep it
e69f8ee to
0029258
Compare
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.