-
Notifications
You must be signed in to change notification settings - Fork 67
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
Implement selective typecheck #2321
Implement selective typecheck #2321
Conversation
🦋 Changeset detectedLatest commit: 4ae9bcc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (tsConfig.compilerOptions && rest.compilerOptions?.jsx) { | ||
tsConfig.compilerOptions.jsx = rest.compilerOptions.jsx; | ||
// Where the user has defined allowlist-supported compiler options, apply them | ||
for (const item of COMPILER_OPTIONS_ALLOW_LIST) { |
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 block is currently uncovered, worth adding a test case for it (essentially, using the jsx option)
@@ -56,9 +56,10 @@ async function getPackageMetadata() { | |||
// validate tsconfig | |||
// Extract configuration from config file and parse JSON, | |||
// after removing comments. Just a fancier JSON.parse | |||
const userTsConfigPath = path.join(modularRoot, typescriptConfigFilename); |
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 is a bugfix. The second argument was previously reading tsconfig.json
from the cwd()
, since no modular root was being used. This is not consistent with the first argument, where the modular root is used.
That said, in practice, there was no actual way for users to be affected by this bug - since commands are supposed to be run in the root already (so not using the modular root resulted in the correct file being used), and preflight errors actually get in the way first if you try to run something like typecheck
from the non-root dir.
The bugfix here is needed so that we can effectively test the code in test, i.e. use a faked modular root and have it respected.
Selective TypeCheck
--ancestors
,--descendants
,--changed
and--compareBranch
options tomodular typecheck
modular typecheck
tsconfig.json
files, plus docs for the new optionstypecheck
to use a new approach, and cover new casesNew unit testing approach: calling commands directly
A side mission during this PR was to call
typecheck()
directly from test code, instead of rely onexeca
as is very common in the project. Theexeca
approach is (a) slow and (b) breaks the tracking of test coverage.typecheck.test.ts
demonstrates a new approach:getModularRoot
in tests, which is used extensively throughout the projectgetModularRoot
clone calledgetRealModularRootInTest
that is designed to be used in test code, i.e. avoid any mocks that might be applicableactionPreflightCheck
, which complicates the mocking (it contains a call togetModularRoot
) and slows things down. Plus, this check has no value in test (it can be tested in isolation).It should be noted that I've used
jest.doMock
which avoids jest's default hoisting behaviour. In other words, it lets us mock the modular root just before importing and calling a modular command. To work with this approach, I dynamically import thetypecheck
command. It may also be possible to use a more static setup.Not only is this approach faster and simpler, the coverage for the test command has gone from
0
to>90%
.TODO