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

feat: use typescript with wing cli and worker thread for preflight #5247

Merged
merged 21 commits into from
Dec 20, 2023

Conversation

MarkMcCulloh
Copy link
Contributor

@MarkMcCulloh MarkMcCulloh commented Dec 18, 2023

General Vibe

  • This is an MVP of getting TS working via the wing cli (compile, run, and test). This is basically only usable for preflight
  • I wanted to change as little as possible in the SDK to avoid wasted work once resources are moved to winglibs
  • Does not address inflight stuff yet

The entrypoint TS experience is different than the existing issue/story:

import { main } from "ts4wing";

main((app) => {
  // stuff goes here
})

This was due to our usage of a "root" construct for testing isolation. The wing cli needs to have control over the instantiation of resources, so new App() is not really feasible because we don't want users to actually attach stuff at the app-level. It may be possible to get it working with new App() but the hacks needed didn't seem worth it.
An added benefit of this approach is that the user no longer needs to call app.synth()

Anecdotally, I have built an awscdk-based internal framework at a previous job that looked like this for a similar reason (to duplicate stuff across Stages) and it worked pretty well.

Indirect Changes

  • Made sure everything matches their @types/node version
  • preflight execution now happens in a worker thread instead of a VM
    • VM context did not allow data to be provided past the initially loaded file.
    • In a VM, process.env is useful but pollutes the parent process
    • The overloaded "require" was only useful for the initial file. Now I added a shim that overloads require everywhere to make sure the SDK is loaded properly

Fixes #3678

By submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.

@monadabot
Copy link
Contributor

Thanks for opening this pull request! 🎉
Please consult the contributing guidelines for details on how to contribute to this project.
If you need any assistence, don't hesitate to ping the relevant owner over Slack.

Topic Owner
Wing SDK and utility APIs @chriscbr
Wing Console @ainvoner, @skyrpex, @polamoros
JSON, structs, primitives and collections @hasanaburayyan
Platforms and plugins @hasanaburayyan
Frontend resources (website, react, etc) @tsuf239
Language design @eladb
VSCode extension and language server @markmcculloh
Compiler architecture, inflights, lifting @yoav-steinberg
Wing Testing Framework @tsuf239
Wing CLI @markmcculloh
Build system, dev environment, releases @markmcculloh
Library Ecosystem @chriscbr
Documentation @hasanaburayyan
SDK test suite @tsuf239
Examples @skorfmann
Wing Playground @eladcon

@monadabot
Copy link
Contributor

monadabot commented Dec 18, 2023

Console preview environment is available at https://wing-console-pr-5247.fly.dev 🚀

Last Updated (UTC) 2023-12-20 01:50

@monadabot
Copy link
Contributor

monadabot commented Dec 18, 2023

Benchmarks

Comparison to Baseline 🟩⬜⬜🟥⬜🟥⬜🟥⬜🟥🟥🟥🟥
Benchmark Before After Change
version 76ms±0.82 72ms±0.73 -4ms (-4.77%)🟩
jsii_big.test.w -t sim 3410ms±29.12 3362ms±14.6 -48ms (-1.41%)⬜
jsii_big.test.w -t tf-aws 3490ms±17.75 3475ms±14.99 -15ms (-0.42%)⬜
functions_1.test.w -t sim 563ms±4.6 623ms±8.09 +60ms (+10.64%)🟥
functions_1.test.w -t tf-aws 1550ms±21.49 1619ms±36.77 +70ms (+4.51%)⬜
hello_world.test.w -t sim 560ms±5.43 621ms±2.99 +60ms (+10.78%)🟥
hello_world.test.w -t tf-aws 4821ms±41.38 4846ms±32.5 +25ms (+0.53%)⬜
functions_10.test.w -t sim 620ms±3.9 681ms±6.96 +61ms (+9.79%)🟥
functions_10.test.w -t tf-aws 3337ms±37.55 3390ms±12.87 +53ms (+1.6%)⬜
jsii_small.test.w -t sim 524ms±3.51 591ms±6.94 +67ms (+12.76%)🟥
jsii_small.test.w -t tf-aws 649ms±4.97 707ms±6.52 +58ms (+8.89%)🟥
empty.test.w -t sim 527ms±3.37 591ms±4.56 +63ms (+12.01%)🟥
empty.test.w -t tf-aws 651ms±4.94 702ms±4.76 +52ms (+7.92%)🟥

⬜ Within 1.5 standard deviations
🟩 Faster, Above 1.5 standard deviations
🟥 Slower, Above 1.5 standard deviations

Benchmarks may vary outside of normal expectations, especially when running in GitHub Actions CI.

Results
name mean min max moe sd
version 72ms 71ms 74ms 1ms 1ms
jsii_big.test.w -t sim 3362ms 3331ms 3402ms 15ms 20ms
jsii_big.test.w -t tf-aws 3475ms 3427ms 3504ms 15ms 21ms
functions_1.test.w -t sim 623ms 602ms 641ms 8ms 11ms
functions_1.test.w -t tf-aws 1619ms 1566ms 1741ms 37ms 51ms
hello_world.test.w -t sim 621ms 616ms 629ms 3ms 4ms
hello_world.test.w -t tf-aws 4846ms 4786ms 4923ms 33ms 45ms
functions_10.test.w -t sim 681ms 670ms 695ms 7ms 10ms
functions_10.test.w -t tf-aws 3390ms 3349ms 3417ms 13ms 18ms
jsii_small.test.w -t sim 591ms 576ms 604ms 7ms 10ms
jsii_small.test.w -t tf-aws 707ms 693ms 728ms 7ms 9ms
empty.test.w -t sim 591ms 581ms 599ms 5ms 6ms
empty.test.w -t tf-aws 702ms 690ms 711ms 5ms 7ms
Last Updated (UTC) 2023-12-20 01:58

libs/ts4wing/src/index.ts Outdated Show resolved Hide resolved
examples/tests/sdk_tests/util/env.test.w Outdated Show resolved Hide resolved
examples/ts-fixture/src/main.ts Show resolved Hide resolved
libs/ts4wing/src/compiler.ts Outdated Show resolved Hide resolved
@Chriscbr
Copy link
Contributor

import { wing } from "ts4wing";

wing((app) => {
  // stuff goes here
})

Interesting... the API reminds me a little bit of React's createRoot / root.render().

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Ship it!

examples/ts-fixture/src/main.ts Outdated Show resolved Hide resolved
libs/ts4wing/README.md Outdated Show resolved Hide resolved
libs/ts4wing/src/compiler.ts Outdated Show resolved Hide resolved
libs/ts4wing/src/compiler.ts Outdated Show resolved Hide resolved
libs/ts4wing/src/compiler.ts Outdated Show resolved Hide resolved
libs/ts4wing/src/index.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Show resolved Hide resolved
libs/ts4w/src/internal.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Show resolved Hide resolved
@MarkMcCulloh MarkMcCulloh marked this pull request as ready for review December 19, 2023 19:21
@MarkMcCulloh MarkMcCulloh requested a review from a team as a code owner December 19, 2023 19:21
libs/ts4w/tsup.config.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
libs/wingcompiler/src/compile.ts Outdated Show resolved Hide resolved
Copy link
Contributor

mergify bot commented Dec 20, 2023

Thanks for contributing, @MarkMcCulloh! This PR will now be added to the merge queue, or immediately merged if mark/ts-cli-2 is up-to-date with main and the queue is empty.

@mergify mergify bot merged commit e6e06a0 into main Dec 20, 2023
24 checks passed
@mergify mergify bot deleted the mark/ts-cli-2 branch December 20, 2023 02:10
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.53.3.

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

Successfully merging this pull request may close these issues.

running multiple compilations simultaneously in the same node process
4 participants