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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SWC to transpile typescript projects #9049
Conversation
PR is now waiting for a maintainer to take action. Note for the maintainer: Commands available:
|
PR is now waiting for a maintainer to take action. Note for the maintainer: Commands available:
|
Nice! The performance improvements look great here.
This is the one biggest question I have here. This is a meaningful user experience change. Today, users get errors early in their deployment if there are TypeScript-level issues. With this change, they would not. We'd be relying on IDE tooling to capture errors before running
Previously there were "good defaults" for the case where there was not a tsconfig.json - what happens with these changes to the defaults being used for compilation? Do we still support projects with no tsconfig.json? What default compilation options get used? |
We've only just recently added the |
@lukehoban maybe there could be an option to include or not include this? We do a similar thing with webpack. disabling type checking during compilation makes a major different in speed. and most of the time the build step doesnt even run on a CI if the type checking fails |
Yeah I kinda wish I'd waited on merging that PR until I went through the full history here 馃槵 But for sure, I can update to make transpiling optional. So long as standard tsconfig.json setups are supported, that seems fine to me.
This is correct, with the additional comment that users can run
Totally fair I think. Do you have a preference on which is the default? Maybe if we want to have typechecking off by default, we leave it as on by default in this PR, and then change over the default during the next major version release?
I believe this section of ts-node's documentation covers this: https://github.com/TypeStrong/ts-node#tsconfigbases, where ts-node will selectively pick compiler option defaults based on the runtime being used, such as https://github.com/tsconfig/bases/blob/main/bases/node14.json for node14. I have not tested this fully though other than reading those docs. |
I think we'd want to keep the current behavior of typechecking by default. If you can think of a good way we could better advertise the |
PR is now waiting for a maintainer to take action. Note for the maintainer: Commands available:
|
@Frassle Makes sense, I'll leave the default as it was then. I just pushed up the code to make transpilation optional. You can see https://github.com/dmattia/pulumi-fork-perf-test/actions/runs/1900613729 for the new CI tests. If you look into the results, you can see that the time to run Using pulumi v3.25.0, PULUMI_NODEJS_TRANSPILE_ONLY=true: 7s, 8s, 9s From this, we can see that even with the ts-node v10, this branch should mantain at least even performance with previous branches. Of note, I would expect that SWC would show it's strength more with larger projects, which I have verified in my company's monorepo, but providing test cases for that is a bit trickier. |
PR is now waiting for a maintainer to take action. Note for the maintainer: Commands available:
|
|
||
// We provide reasonable defaults for many ts options, meaning you don't need to have a tsconfig.json present |
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 wonder if this needs to be saved for a major change version. There are potentially users who currently use pulumi with no tsconfig.json present and so get the default compiler options we currently set. With this change we are instead going to get ts-nodes default compiler options which I suppose is potentially breaking.
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.
Sure, I think #8199 is on the docket for release during the next major release as well, and the changes should build nicely off of each other.
This can be potentially closed in favor of #10122 now that newer versions of ts-node support |
ts-node and typescript are now optional peer dependencies. The npm package now includes bundled versions of these to fallback to if no peer dependencies are installed. If you add your own versions, these will be prioritised over the bundled versions. |
Description
I just went down an interesting rabbit hole following the history of the run.ts file that sets up the ts-node running of typescript pulumi programs, and believe that simplifying the existing code will better future-proof pulumi, while providing better performance, with lower maintenance, while supporting more Typescript setups.
Here's the history of this file as I understand it:
files
of that config file (Pulumi hangs when there is atsconfig.json
in parent folder (even for JavaScript projects)聽#1772)tsconfig.json
is not present in the CWD聽#1857 came along and said that pulumi would only check for tsconfig.json files in the project directory, solving Luke's problem, but creating an incompatibility with some fairly standard typescript layouts where the tsconfig file is up the chain.tsconfig.json
is not present in the CWD聽#1857 (comment) has not been answeredThis PR does a few things:
I created a test repo that uses these changes, comparing the performance on a plain
pulumi new aws-typescript
repo using the latest pulumi/pulumi and my fork: https://github.com/dmattia/pulumi-fork-perf-testIgnoring the CI setup time and yarn installation time, the
pulumi preview
step with pulumi v3.25.0 took:and using the fork took:
This is a significant performance increase, and I would encourage anyone interested to fork that repo and test for themselves on more operating systems, node versions, etc. if desired. Or, feel free to comment here what systems you're interested in and I will gladly update the job matrix to test using those options.
As for the lack of typechecking, this is where it gets a lot more into a matter of opinion, but my thought is this: If pulumi wants to typecheck by default, it should use standard typescript handling without custom handling of tsconfig.json files. Doing both of those things by default makes for a challenging onboarding experience for anyone in a custom-setup typescript repo that is not using
pulumi new
and doesn't just happen to have their tsconfig file in the correct place.There is also a middle ground here where we do not use the swc transpiler, turn on typechecking by default, and use
scope
andscopeDir
in ts-node to tell typescript to only typecheck the files in the pulumi working directory (see: https://github.com/TypeStrong/ts-node/blob/main/src/index.ts#L209-L218). These options, only available in ts-node v10.x and higher, would make the case where someone had a rogue tsconfig.json file in their home directory a non-issue (although they should really remove that 馃槵) as only the entry file (and other files in the same dir) would be typechecked.Fixes #4876
Suggested reviewers: @iwahbe, @lukehoban, as they have been involved in many of the above discussions
Checklist