-
Notifications
You must be signed in to change notification settings - Fork 920
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
Add typescript plugin #1211
Add typescript plugin #1211
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/mirgrxf5o |
['WORKER_MSG', {level: 'log', msg: 'TEST_CLEAR_MESSAGE'}], | ||
]); | ||
}); | ||
}); |
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.
Amazing! 💯
function typescriptPlugin() { | ||
return { | ||
name: '@snowpack/plugin-typescript', | ||
async run({isDev, log}) { |
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 really liking the evolution of this humble run()
method. On the one hand, it’s just a wrapper around a CLI command. But on the other, it does provide a pretty clean experience to leverage libraries without Snowpack having to do to much. I’m into it!
@@ -35,6 +35,7 @@ For starter apps and templates, see [create-snowpack-app](./create-snowpack-app) | |||
### Dev Environment | |||
|
|||
- [@snowpack/plugin-dotenv](./plugins/plugin-dotenv) | |||
- [@snowpack/plugin-typescript](./plugins/plugin-typescript) |
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.
Is this more of a “build” plugin (not in method called, but to the user)?
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.
Since this is only doing type checking, it felt like a "dev environment" plugin. Maybe make this more clear? Maybe add a new "Lint" section?
return { | ||
name: '@snowpack/plugin-typescript', | ||
async run({isDev, log}) { | ||
const workerPromise = execa.command(`tsc --noEmit ${isDev ? '--watch' : ''}`, { |
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.
Would you like to use the programmatic API instead of parsing the output?
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 opposed to the JS API, but in the past I know that the project has always treated the JS API as secondary to the CLI itself.
On top of that, the CLI gives us the formatted output for free. Since the dev console just wants formatted output and a simple pass/fail, the tsc CLI is enough for our use-case and lets the tsc CLI handle all of the complexity of config loading, file watching, etc.
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.
So tsc is only used for type checking, not file emitting?
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.
👍 That's correct
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.
reading over the README, we could probably make that difference even more clear
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.
Oh I noticed the --noEmit. IMO it's a bit wasty to use multiple tool to parse the source code. In my project I mainly don't use babel and do everything only with TypeScript compiler.
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.
If you wanted to build a typescript build plugin, that would be exciting to see!
Snowpack doesn't run the TypeScript compiler as a part of the default build step, we use esbuild which can parse TS code successfully. So this plugin only exists to do that typechecking for you.
Changes
Testing
Docs