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

build: add support for typescript to monorepo #7274

Merged
merged 11 commits into from
Feb 16, 2021
Merged

Conversation

mcous
Copy link
Contributor

@mcous mcous commented Jan 29, 2021

Overview

As discussed in 2021's inaugural JS Guild meeting, this PR enables TypeScript in our monorepo in advance of an effort to move off of Flow.

See #4087 for the original RFC and reasoning (which we still agree with!).

Changelog

  • Upgrade babel and friends to ensure best compatibility
  • Upgade eslint and friends to ensure best compatibility
    • Note: this surfaced a number of errors, which I switched over to warnings for the time being
  • Add TypeScript compilation via Babel
    • As noted in the RFC, going via Babel rather than tsc is our least disruptive option, given our existing Babel setup
  • Update webpack config to understand TypeScript imports

Still To Do

  • Integrate TS typechecking with CI

Review requests

The best way to test this PR is to start a conversion branch (or several) on top of this branch and make sure linting, typechecking, etc. all works!

I'll keep this PR in draft form until we have one or more of those going to verify.

Risk assessment

TS additions are pretty carefully scoped to ignore anything that doesn't have a .ts(x) extension, but the babel toolchain upgrades always carry some risk. Smoke tests (along with automated E2E tests) are prudent here.

@mcous mcous requested review from a team and IanLondon and removed request for a team January 29, 2021 23:46
@codecov
Copy link

codecov bot commented Jan 29, 2021

Codecov Report

Merging #7274 (4976377) into edge (f7e8283) will decrease coverage by 0.26%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #7274      +/-   ##
==========================================
- Coverage   80.90%   80.64%   -0.27%     
==========================================
  Files         267      277      +10     
  Lines       19265    20029     +764     
==========================================
+ Hits        15587    16153     +566     
- Misses       3678     3876     +198     
Impacted Files Coverage Δ
update-server/otupdate/buildroot/update.py 83.33% <0.00%> (ø)
update-server/otupdate/buildroot/config.py 92.50% <0.00%> (ø)
update-server/otupdate/buildroot/update_session.py 95.06% <0.00%> (ø)
...pdate-server/otupdate/buildroot/name_management.py 29.50% <0.00%> (ø)
update-server/otupdate/buildroot/control.py 91.30% <0.00%> (ø)
...te-server/otupdate/buildroot/ssh_key_management.py 80.64% <0.00%> (ø)
update-server/otupdate/buildroot/__init__.py 85.29% <0.00%> (ø)
update-server/otupdate/buildroot/file_actions.py 91.66% <0.00%> (ø)
update-server/otupdate/buildroot/constants.py 100.00% <0.00%> (ø)
update-server/otupdate/buildroot/__main__.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7e8283...4976377. Read the comment docs.

@mcous mcous self-assigned this Feb 4, 2021
@mcous mcous added the robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience). label Feb 4, 2021
@mcous mcous marked this pull request as ready for review February 6, 2021 19:30
@mcous mcous requested review from a team as code owners February 6, 2021 19:30
Copy link
Contributor

@IanLondon IanLondon left a comment

Choose a reason for hiding this comment

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

once I realized I had to update my node 12, this worked fine after merging it into a copy of my working branch as far as linting and Flow still working.

Weird thing: after running make setup-js, I have a 19-line diff in yarn.lock file

@mcous mcous added this to the CPX Sprint 26 milestone Feb 9, 2021
@@ -62,20 +67,17 @@ setup-py:
$(MAKE) -C $(SHARED_DATA_DIR) setup-py

# front-end dependecies handled by yarn
# TODO(mc, 2021-02-12): add `$(MAKE) build-ts` after `yarn` when we have TS
Copy link
Contributor Author

@mcous mcous Feb 12, 2021

Choose a reason for hiding this comment

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

#7309 removes this comment and adds build-ts as a dependency to check-js, instead

@@ -211,11 +224,6 @@ circular-dependencies-js:
madge $(and $(CI),--no-spinner --no-color) --circular labware-library/src/index.js
madge $(and $(CI),--no-spinner --no-color) --circular app/src/index.js

# upload coverage reports
.PHONY: coverage
coverage:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been replaced by codecov/codecov-action. This target was CI-only, so removing it mostly because I'm already touching this file

@@ -8,6 +8,7 @@ include ./scripts/python.mk
SHELL := bash

# add node_modules/.bin to PATH
# TODO(mc, 2021-02-12): remove in favor of `yarn run` directly
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per old thread in Slack. Based on that conversation and testing, there doesn't appear to be any remaining downsides to this


extends: [
'standard',
'standard-with-typescript',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a very nice config from the standard folks that includes all the normal standard stuff, and enables a bunch of other rules conditionally if the file being checked is TS

I definitely prefer this approach over having to decide and maintain a bunch of our own rules

@@ -35,6 +35,8 @@ untyped-type-import=error
[options]
module.name_mapper.extension='css' -> '@opentrons/components/interfaces/CSSModule.js'
module.ignore_non_literal_requires=true
module.system.node.main_field=flow:main
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows a module to specific a "flow:main" field in it's package.json for flow to check instead of main. This way, main can point at compiled JS, types can point at some *.d.ts declaration file for TS, and Flow can be shunted over to a shim that covers whatever type definitions we need while the conversion is in progress.

Technically, we could try simply placing a index.flow.js sibling to whatever main index.js file, and Flow would automatically look at that without any main_field setting, but Flow would then blow up if index.js didn't exist. Since our main files are compiled source (that may be cleaned), using main_field seemed like the more developer-friendly option

"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fun config that gives us full literal typing on .json imports

Copy link
Member

@shlokamin shlokamin left a comment

Choose a reason for hiding this comment

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

LGTM. And thanks for all the comments, I'm not as well versed in frontend ops as I should be so they made this PR easier to follow 😅

@mcous mcous merged commit 4542190 into edge Feb 16, 2021
@mcous mcous deleted the build_enable-typescript branch February 16, 2021 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS Tech Debt robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants