-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Avoid importing typescript unless necessary #10185
Conversation
@RobbieMcKinstry brings up a question whether lazy-load technique taken from https://www.typescriptlang.org/docs/handbook/modules.html#optional-module-loading-and-other-advanced-loading-scenarios will be supported in all the needed module environments (CommonJS etc). |
Adding platform-team reviewers to seek out node expertise. Also hoping tests might help catch. |
After reviewing https://blog.bitsrc.io/javascript-require-vs-import-47827a361b77 I feel like its likely. |
Let me work through failing tests first. |
252d9a2
to
31670b1
Compare
My current intention is to remove closure in 4.0 and ship it as a separate package. |
That'd be good but the changes here still help since ts-node imports depend on typescript. I think I'd like to ship this. Concerns I've heard so far was:
|
@t0yv0 After digging into minification, I don't think it will slow down typescript builds, since we don't bundle. If we bundled, then a dynamic import would cause a disk read that otherwise wouldn't have occurred in the static import scenario. |
Ah so would bundling embed "typescript" and "ts-node" JavaScript code inside the "pulumi" bundle? I thought it's just a matter of whether pulumi specific modules are distributed in one or several files. With that being clarified it seems good for us not to bundle "typescript" since it is large and is not always used by the Pulumi code, it's optional in some scenarios. |
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 looks good to me - I don't think a delayed require()
will be a problem.
Yes, if the runtime doesn't use any dynamic imports, then adding bundling would (by default) bundle typescript and ts-node. Which I agree is something we'd like to avoid. |
Description
The key motivation for this change is speeding up startup of small JavaScript programs. That is:
This 300ms is simply is the cost of adding ts-node and typescript dependency to the imports.
Importing
"runtime"
directly considered harmful because it imports "typescript" indirectly via "closure" support.Fixes # (issue)
Checklist