Skip to content
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

chore(react-menu): implement docs generation with ts path aliases #17449

Merged

Conversation

Hotell
Copy link
Contributor

@Hotell Hotell commented Mar 16, 2021

Pull request checklist

Description of changes

This is a temporary workaround to enable full dev workflow with no manual build needed (via lage --to) when working on convergence packages.

Before:

  • developer does some public api changes within/outside package boundaries
  • he needs to run lage built --to @fluentui/package-name and wait for api.md changes (same as on CI)

After:

  • developer does some public api changes within/outside package boundaries
  • to verify api changes on local, so one can verify that CI wont fail because of that, run yarn workspace @fluentui/package-name build:local

Focus areas to test

(optional)

@Hotell Hotell changed the title chore(react-menu): .... chore(react-menu): implement docs generation without ts path aliases Mar 16, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 16, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7fcac66:

Sandbox Source
Fluent UI Button Configuration
codesandbox-react-template Configuration
codesandbox-react-northstar-template Configuration

@@ -84,9 +84,13 @@
"@types/prettier": "1.19.1",
"@types/webpack-dev-middleware": "4.1.0",
"@types/webpack-env": "1.16.0",
"@microsoft/api-extractor": "7.7.1",
"@types/chalk": "2.2.0",
"@types/yargs": "13.0.11",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now explicit instead using this as a transient dependency

*
* @param {string[]} files
*/
function normalizeImports(files) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is very naive, but I don't think we need to go AST way for such a simple task :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just thankful that our folder names reflec the package name... otherwise this might have been a nightmare

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment somewhere that this just assumes the above fact and just replaces relative . dots with the @fluentui/scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm is that needed? I mean that's the only issue why is this needed - local package deps, besides that TS works as expected.

Also there are tests :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good point 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that the tests help with documentation, but it wouldn't hurt to mention the reason inline as well for anyone who comes across this later and isn't familiar with the whole scenario.

@Hotell Hotell force-pushed the hotell/16889/api-extractor-with-ts-path branch from 1bdbe63 to ee0a007 Compare March 18, 2021 11:40
@Hotell Hotell marked this pull request as ready for review March 18, 2021 11:51
@Hotell Hotell added the dependencies Pull requests that update a dependency file label Mar 18, 2021
@@ -0,0 +1,91 @@
// @ts-check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the other tests in the package use .test as an extension, might be good to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right.

I created RFC to start using proper naming suffix - .spec, as we are using behaviour driven approach. Once we agree upon consistency we can re-name in batch and add proper automation checks.

@@ -11,6 +11,8 @@
},
"license": "MIT",
"scripts": {
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
"build:local": "tsc -p . --module esnext --emitDeclarationOnly && node config/normalize-import --output dist/react-menu/src && yarn docs",
"build": "just-scripts build",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, so on CI, the relative type imports isn't an issue ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct. on CI lage takes the job of tsc dep resolution when running builds ordered by dep tree relationships.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more info documented in JSDoc + TS issue
image

@layershifter
Copy link
Member

  • developer does some public api changes within/outside package boundaries
  • to verify api changes yarn workspace @fluentui/package-name build:local

Can we you please clarify when we should use yarn workspace @fluentui/package-name docs?

@Hotell
Copy link
Contributor Author

Hotell commented Mar 18, 2021

  • developer does some public api changes within/outside package boundaries
  • to verify api changes yarn workspace @fluentui/package-name build:local

Can we you please clarify when we should use yarn workspace @fluentui/package-name docs?

currently this is a temporary placeholder (following what folks from web-components team do) so we don't have inlined the whole command within `"build:local" script -> calling it directly would throw error if one did any public api changes in particular package (because ts output was not re-generated), thus should not be used directly. again this is a temporary solution until we migrate all converged packages to this new stack and enable it on CI as well to to unify things.

maybe we can name it as docs:verify and remove build:local completely ? wdyt ? @ling1726

return filePath;
});

return allFiles.flat(Infinity);
Copy link
Member

@ecraig12345 ecraig12345 Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this means we've implicitly dropped support for Node 10 (that's why the lib reference was needed). Practically speaking that's probably okay at this point (given that it will be officially unsupported after next month) but I'd prefer to do it separately with a more intentional/coordinated approach: updating the @types/node version, updating docs, and announcing to contributors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • AFAIK we support node 12 and up
  • there are no restrictions on node on yarn set by tooling (missing engines field completely) ( CI uses 12 :) )
  • @ling1726 what node are you using (as you're the only consumer for now)?

We should address all of this in different PR/sprint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version 12, as it says in our contributing guide

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here's what is written in our official setup guide
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "verify your environment" section goes into more detail about current requirements.

node -v: Should be 12.x.x or 14.x.x (where "x" is some number). 10.x should still work for now. Newer versions may not work.

Again, I don't think that dropping 10 is a problem at this point, I would just prefer for it to happen in a more coordinated manner.

* @type {Console['log']}
*/
// eslint-disable-next-line no-console
const log = console.log.bind(console);
Copy link
Member

@ecraig12345 ecraig12345 Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for doing this, rather than using console.log directly and disabling the lint rule for the file? (edit: or add an override to disable no-console for the config directory)

Copy link
Contributor Author

@Hotell Hotell Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • a good rule of thumb is to not turn off rules for whole file
  • log is shorter - instead of having console.log all over the place
  • ideally we should use robust and common logging solution - like debug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see nothing wrong with turning off a rule which is clearly irrelevant for a given file (or ideally disabling this rule for all config files). Making an alias for a common method decreases clarity and is a micro-optimization, and IMO not really worth it especially if your main goal is just to get around a lint rule.

Copy link
Member

@ecraig12345 ecraig12345 Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of the no-console rule is to minimize console logs in component/other browser code files. It shouldn't be enabled for config files to begin with. So the best short-term workaround (either in this PR or a follow-up) would be to update the shared eslint config to ensure that it uses appropriate rules on config files. Agreed that a proper logger would be nice but that's an entirely separate problem.

@ecraig12345
Copy link
Member

  • developer does some public api changes within/outside package boundaries
  • to verify api changes yarn workspace @fluentui/package-name build:local

Can we you please clarify when we should use yarn workspace @fluentui/package-name docs?

currently this is a temporary placeholder (following what folks from web-components team do) so we don't have inlined the whole command within `"build:local" script -> calling it directly would throw error if one did any public api changes in particular package (because ts output was not re-generated), thus should not be used directly. again this is a temporary solution until we migrate all converged packages to this new stack and enable it on CI as well to to unify things.

maybe we can name it as docs:verify and remove build:local completely ? wdyt ?

Not quite following here--the docs command as currently defined has --local, which means it will update the API file rather than throwing errors. So adding verify to the name doesn't really make sense.

@Hotell Hotell changed the title chore(react-menu): implement docs generation without ts path aliases chore(react-menu): implement docs generation with ts path aliases Mar 19, 2021
@Hotell
Copy link
Contributor Author

Hotell commented Mar 19, 2021

  • developer does some public api changes within/outside package boundaries
  • to verify api changes yarn workspace @fluentui/package-name build:local

Can we you please clarify when we should use yarn workspace @fluentui/package-name docs?

currently this is a temporary placeholder (following what folks from web-components team do) so we don't have inlined the whole command within "build:local" script -> calling it directly would throw error if one did any public api changes in particular package (because ts output was not re-generated), thus should not be used directly. again this is a temporary solution until we migrate all converged packages to this new stack and enable it on CI as well to to unify things. maybe we can name it as docs:verifyand removebuild:local` completely ? wdyt ?

Not quite following here--the docs command as currently defined has --local, which means it will update the API file rather than throwing errors. So adding verify to the name doesn't really make sense.

  • what do you propose ?
  • can we get this merged this week?

updated description a bit
image

@ecraig12345
Copy link
Member

Not quite following here--the docs command as currently defined has --local, which means it will update the API file rather than throwing errors. So adding verify to the name doesn't really make sense.

  • what do you propose ?
  • can we get this merged this week?

updated description a bit
image

The PR description update helps, thanks. (Previously I wasn't clear on where this command fit into the workflow, and the suggestion of "verify" made it seem like there might be some misunderstanding of what the API Extractor command would do.)

build:local could be an okay name. My other suggestion would be update-api since v7/8 developers are already used to running that in a similar scenario, from back when we didn't update the API files automatically as part of a build.

@ecraig12345 ecraig12345 reopened this Mar 20, 2021
@DustyTheBot
Copy link

DustyTheBot commented Mar 20, 2021

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.

Generated by 🚫 dangerJS against 7fcac66

@fabricteam
Copy link
Collaborator

fabricteam commented Mar 20, 2021

Perf Analysis

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 909 904 5000
BaseButton mount 891 884 5000
Breadcrumb mount 43150 43534 5000
ButtonNext mount 555 569 5000
Checkbox mount 1509 1540 5000
CheckboxBase mount 1259 1297 5000
ChoiceGroup mount 4708 4693 5000
ComboBox mount 946 972 1000
CommandBar mount 10022 10055 1000
ContextualMenu mount 6195 6172 1000
DefaultButton mount 1117 1106 5000
DetailsRow mount 3668 3659 5000
DetailsRowFast mount 3661 3624 5000
DetailsRowNoStyles mount 3432 3480 5000
Dialog mount 1425 1464 1000
DocumentCardTitle mount 1840 1817 1000
Dropdown mount 3232 3201 5000
FocusTrapZone mount 1801 1772 5000
FocusZone mount 1769 1773 5000
IconButton mount 1713 1731 5000
Label mount 342 340 5000
Layer mount 1751 1783 5000
Link mount 466 469 5000
MakeStyles mount 1769 1787 50000
MenuButton mount 1451 1446 5000
MessageBar mount 1986 2004 5000
Nav mount 3210 3270 1000
OverflowSet mount 1027 1033 5000
Panel mount 1407 1418 1000
Persona mount 812 820 1000
Pivot mount 1380 1417 1000
PrimaryButton mount 1269 1300 5000
Rating mount 7603 7638 5000
SearchBox mount 1286 1302 5000
Shimmer mount 2477 2529 5000
Slider mount 1969 1966 5000
SpinButton mount 4916 4955 5000
Spinner mount 409 421 5000
SplitButton mount 3127 3055 5000
Stack mount 498 497 5000
StackWithIntrinsicChildren mount 1542 1565 5000
StackWithTextChildren mount 4500 4475 5000
SwatchColorPicker mount 10148 10093 5000
Tabs mount 1382 1434 1000
TagPicker mount 2416 2402 5000
TeachingBubble mount 11658 11715 5000
Text mount 409 414 5000
TextField mount 1357 1351 5000
ThemeProvider mount 1164 1171 5000
ThemeProvider virtual-rerender 587 604 5000
ThemeProviderNext mount 9153 9125 5000
Toggle mount 790 795 5000
buttonNative mount 109 120 5000

Perf Analysis (Fluent)

Perf comparison
Status Scenario Fluent TPI Fabric TPI Ratio Iterations Ticks
🦄 Avatar.Fluent 0.16 0.48 0.33:1 2000 329
🦄 Button.Fluent 0.11 0.2 0.55:1 5000 532
🔧 Checkbox.Fluent 0.62 0.35 1.77:1 1000 624
🎯 Dialog.Fluent 0.15 0.21 0.71:1 5000 740
🔧 Dropdown.Fluent 3.1 0.39 7.95:1 1000 3100
🔧 Icon.Fluent 0.12 0.06 2:1 5000 609
🦄 Image.Fluent 0.07 0.13 0.54:1 5000 373
🔧 Slider.Fluent 1.58 0.47 3.36:1 1000 1577
🔧 Text.Fluent 0.07 0.03 2.33:1 5000 362
🦄 Tooltip.Fluent 0.14 0.9 0.16:1 5000 699

🔧 Needs work     🎯 On target     🦄 Amazing

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
AccordionMinimalPerf.default 173 150 1.15:1
AvatarMinimalPerf.default 215 202 1.06:1
ButtonMinimalPerf.default 182 172 1.06:1
RefMinimalPerf.default 263 247 1.06:1
SkeletonMinimalPerf.default 374 353 1.06:1
AttachmentMinimalPerf.default 169 161 1.05:1
LabelMinimalPerf.default 399 379 1.05:1
ButtonSlotsPerf.default 583 561 1.04:1
CardMinimalPerf.default 569 547 1.04:1
CarouselMinimalPerf.default 483 465 1.04:1
ChatMinimalPerf.default 634 608 1.04:1
ReactionMinimalPerf.default 396 381 1.04:1
Text.Fluent 362 348 1.04:1
ButtonUseCssNestingPerf.default 1089 1057 1.03:1
ChatDuplicateMessagesPerf.default 306 298 1.03:1
DropdownManyItemsPerf.default 691 672 1.03:1
GridMinimalPerf.default 355 345 1.03:1
LayoutMinimalPerf.default 378 368 1.03:1
ListMinimalPerf.default 512 497 1.03:1
MenuButtonMinimalPerf.default 1590 1544 1.03:1
PortalMinimalPerf.default 178 172 1.03:1
TextMinimalPerf.default 369 358 1.03:1
VideoMinimalPerf.default 631 610 1.03:1
FlexMinimalPerf.default 299 293 1.02:1
InputMinimalPerf.default 1284 1265 1.02:1
LoaderMinimalPerf.default 712 695 1.02:1
TreeWith60ListItems.default 185 181 1.02:1
Dialog.Fluent 740 728 1.02:1
ButtonUseCssPerf.default 809 804 1.01:1
CheckboxMinimalPerf.default 2764 2743 1.01:1
FormMinimalPerf.default 407 401 1.01:1
HeaderSlotsPerf.default 763 759 1.01:1
PopupMinimalPerf.default 722 713 1.01:1
RadioGroupMinimalPerf.default 448 443 1.01:1
AlertMinimalPerf.default 286 285 1:1
AnimationMinimalPerf.default 419 417 1:1
ButtonOverridesMissPerf.default 1702 1698 1:1
DatepickerMinimalPerf.default 44877 44977 1:1
DialogMinimalPerf.default 739 737 1:1
DropdownMinimalPerf.default 3095 3103 1:1
EmbedMinimalPerf.default 4148 4156 1:1
ItemLayoutMinimalPerf.default 1259 1255 1:1
ListWith60ListItems.default 664 664 1:1
ProviderMinimalPerf.default 1005 1004 1:1
SegmentMinimalPerf.default 359 358 1:1
SliderMinimalPerf.default 1607 1607 1:1
StatusMinimalPerf.default 696 693 1:1
CustomToolbarPrototype.default 3831 3839 1:1
Checkbox.Fluent 624 621 1:1
Dropdown.Fluent 3100 3089 1:1
Tooltip.Fluent 699 697 1:1
AttachmentSlotsPerf.default 1142 1150 0.99:1
BoxMinimalPerf.default 365 368 0.99:1
ChatWithPopoverPerf.default 388 392 0.99:1
DividerMinimalPerf.default 367 369 0.99:1
HeaderMinimalPerf.default 364 367 0.99:1
RosterPerf.default 1162 1176 0.99:1
ProviderMergeThemesPerf.default 1675 1691 0.99:1
SplitButtonMinimalPerf.default 3712 3731 0.99:1
IconMinimalPerf.default 621 626 0.99:1
TextAreaMinimalPerf.default 497 501 0.99:1
TooltipMinimalPerf.default 958 966 0.99:1
Image.Fluent 373 375 0.99:1
Slider.Fluent 1577 1599 0.99:1
ImageMinimalPerf.default 374 380 0.98:1
MenuMinimalPerf.default 881 895 0.98:1
TableManyItemsPerf.default 1882 1913 0.98:1
ToolbarMinimalPerf.default 930 948 0.98:1
TreeMinimalPerf.default 784 800 0.98:1
TableMinimalPerf.default 409 421 0.97:1
Avatar.Fluent 329 339 0.97:1
Button.Fluent 532 546 0.97:1
Icon.Fluent 609 627 0.97:1
ListCommonPerf.default 623 646 0.96:1
ListNestedPerf.default 537 563 0.95:1

@size-auditor
Copy link

size-auditor bot commented Mar 20, 2021

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: d471952c96f813c4faa1a9b721c908f155b53e4a (build)

Copy link
Member

@ecraig12345 ecraig12345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a PR #17594 fixing the build issue with API Extractor.

Re: #17449 (comment) I'd probably prefer update-api as the name for the new command since it follows a convention at least people from v7/8 are used to (conventions from web-components are less relevant due to lack of overlap) but would also be okay with sticking with build:local.

I'd still very strongly prefer not to implicitly drop Node 10 (explicitly dropping it by updating our types version and docs would be fine), but not going to block on it.

@JustSlone
Copy link
Collaborator

@chrisdholt or @EisenbergEffect can you take a quick look and sign off on the changes to the web-components files?

Copy link
Contributor

@EisenbergEffect EisenbergEffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval pending some agreement that we can update API Extractor when an upcoming version is released with the features we've been working with them on to enable better documentation of components.

@ecraig12345
Copy link
Member

Approval pending some agreement that we can update API Extractor when an upcoming version is released with the features we've been working with them on to enable better documentation of components.

@EisenbergEffect API Extractor is pretty tightly tied to a certain TS version generally, so @joschect will be upgrading it for most of the repo as part of the upgrade to TS 4.1 that he's working on. However we probably won't be changing the TS version for web-components (it's up to you all when to do that), so if the new API Extractor version doesn't work with the current TS version in web-components, it may be necessary to add back a separate API Extractor version for just web-components and let you upgrade it later.

@EisenbergEffect
Copy link
Contributor

@ecraig12345 Just as long as we have that open for the future since the new API extractor features will greatly improve our doc generation capabilities.

@Hotell Hotell force-pushed the hotell/16889/api-extractor-with-ts-path branch from ee0a007 to 7fcac66 Compare April 19, 2021 13:06
@Hotell Hotell requested a review from a team as a code owner April 19, 2021 13:06
@Hotell Hotell merged commit c12557d into microsoft:master Apr 20, 2021
@msft-fluent-ui-bot
Copy link
Collaborator

🎉@fluentui/[email protected] has been released which incorporates this pull request.:tada:

Handy links:

miroslavstastny pushed a commit to miroslavstastny/fluentui that referenced this pull request May 5, 2021
… local build (microsoft#17449)

* chore: move chalk,api-extractor,yargs,tmp to single version policy
* chore(react-menu): implement docs generation without ts path aliases
* Change files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Build System dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.