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

Add typescript plugin #1211

Merged
merged 4 commits into from
Oct 6, 2020
Merged

Add typescript plugin #1211

merged 4 commits into from
Oct 6, 2020

Conversation

FredKSchott
Copy link
Owner

Changes

  • Adds an official typescript plugin
  • adds tests for the plugin + the run-script plugin
  • updates docs and CSA templates

Testing

  • New tests added

Docs

  • Docs updated

@FredKSchott FredKSchott requested a review from a team as a code owner October 5, 2020 00:56
@vercel
Copy link

vercel bot commented Oct 5, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/mirgrxf5o
✅ Preview: https://snowpack-git-plugin-typescript.pikapkg.vercel.app

['WORKER_MSG', {level: 'log', msg: 'TEST_CLEAR_MESSAGE'}],
]);
});
});
Copy link
Collaborator

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}) {
Copy link
Collaborator

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)
Copy link
Collaborator

@drwpow drwpow Oct 5, 2020

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)?

Copy link
Owner Author

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' : ''}`, {
Copy link
Contributor

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?

Copy link
Owner Author

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.

Copy link
Contributor

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?

Copy link
Owner Author

Choose a reason for hiding this comment

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

👍 That's correct

Copy link
Owner Author

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

Copy link
Contributor

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.

Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants