wing compile api
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 215
- Avg merge
- 2h 9m
- Merged PRs (30d)
- 27
Description
Summary
a compile api as part of @winglang/wing
Feature Spec
Alongside with wing cli, you can compile a wing program using @winglang/wing/compile API
import { compile } from '@winglang/wing';
const wsim = await compile('./hello.w', {
target: 'sim'
// any other compiler flag
});
const simulator = new sdk.testing.Simulator({simfile : wsim})
Use Cases
It allows developer to compile wing programs programmatically (without having to run the CLI)
Here is a concrete example discussed in #876 :
Imagine this e2e test from the simulator.
Given the following code:
code.w
bring cloud; let bucket = new cloud.Bucket(); inflight my_inflight(a:str): str{ bucket.put("file.txt", a); }; new cloud.Function(my_inflight);We can use the
compilecommand in the following jest testbasic.test.ts
import { compile } from '@winglang/wing'; import * as sdk from '@winglang/wingsdk'; let simulator : sdk.testing.Simulator describe('basic compiler tests', () => { beforeAll(async () => { const wsim = await compile('./code.w', { target: 'sim' }); }); beforeEach(async ()=> { simulator = new sdk.testing.Simulator({simfile : wsim}) await simulator.start() }); afterEach(async () => { await simulator.stop() }) test('test function writes to bucket', async () => { let bucket = simulator.getResourceByPath("root/cloud.Bucket") as sdk.sim.IBucketClient let fn = simulator.getResourceByPath("root/cloud.Function") as sdk.sim.IFunctionClient await fn.invoke("somevalue") let output = await bucket.get('file.txt') expect(output).toBe('somevalue') }); });
Implementation Notes
No response
Component
Compiler
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing wing CLI compiler entry point and the @winglang/wing package exports to determine where a compile API belongs. Use the provided basic.test.ts scenario and its Simulator setup as the acceptance path. Done means a Wing program can be compiled programmatically with a target such as sim and the resulting output can be passed to the simulator.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100