-
Notifications
You must be signed in to change notification settings - Fork 207
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
feat(TS): auto-generate TypeScript definitions and add typecheck script #176
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"exclude": ["node_modules"], | ||
"include": ["../../src/**/*"], | ||
"compilerOptions": { | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"strict": true, | ||
"jsx": "react", | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": "../../src", | ||
"paths": { | ||
"*": ["*", "../tests/*"] | ||
}, | ||
"preserveWatchOutput": true, | ||
"incremental": true, | ||
"tsBuildInfoFile": "../.cache/kcd-scripts/.tsbuildinfo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ Available Scripts: | |
lint | ||
pre-commit | ||
test | ||
typecheck | ||
validate | ||
|
||
Options: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const spawn = require('cross-spawn') | ||
const {hasAnyDep, resolveBin, hasFile} = require('../utils') | ||
|
||
const args = process.argv.slice(2) | ||
|
||
if (!hasAnyDep('typescript')) { | ||
throw new Error( | ||
'Cannot use the "typecheck" script in a project that does not have typescript listed as a dependency (or devDependency).', | ||
) | ||
} | ||
|
||
if (!hasFile('tsconfig.json')) { | ||
throw new Error( | ||
'Cannot use the "typecheck" script in a project that does not have a tsconfig.json file.', | ||
) | ||
} | ||
|
||
const result = spawn.sync( | ||
resolveBin('typescript', {executable: 'tsc'}), | ||
['--build', ...args], | ||
{stdio: 'inherit'}, | ||
) | ||
|
||
process.exit(result.status) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I welcome feedback on this shared config. I think most folks should be able to simply do:
But I may be mistaken.
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.
I'd suggest adding
"forceConsistentCasingInFileNames": true
whichAnd
assumeChangesOnlyAffectDirectDependencies: true
whichThere 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.
I think the
include
can even be left out in project-specificts-config
if we include it inshared-tsconfig
, no? 🤔People can then override
include
if they want to in their project-specificts-config
if they want.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.
Thanks @eddyw,
Seems like it would be confusing if we enable this and someone runs typecheck once and gets some error messages, and then they run it again and they don't 🤔
I'm not sure I understand
forceConsistentCasingInFileNames
.Thank you @MichaelDeBoey,
I was worried that
include
would be relative to the shared config, not the extending config. I'll do a little test to be sure.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.
Yup, my suspicions were confirmed:
I suppose I could try
../../src/**/*
... That actually should work fine... I think I'll do that.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.
I'm going to enable
forceConsistentCasingInFileNames
but notassumeChangesOnlyAffectDirectDependencies
. We can alter that in the future if I learn to trust it.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.
It's like the most valuable option in tsconfig 😆 (joking)
It warns the developer if there is inconsistent casing in the filenames when
import
ing orrequire
For instance, if you have
thisExample.ts
but you doimport {} from './ThisExample.ts
, it'll warn because the casing of the filenames is inconsistent. While this code will likely run in Windows, it'll surely break in Linux / MacOS.The default value for
include
is**/*
iffiles
option isn't specified. Maybe it's a sane default and you could leave it as is?Also, I'd suggest removing
exclude
since the default value is actually better: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.
Thanks for that! I only want to
include
thesrc
files because those are the ones that I want to generate type defs for. People can override if they need.I'm pushing a fix to remove
exclude
. Thanks!