2024-06-03 21:06:06 +03:00
# Developer guide
2024-05-14 00:11:35 +03:00
This section goes over the setup of the repo for development.
## Repo setup
2021-11-19 18:52:17 +03:00
2023-11-22 20:49:36 +03:00
- Install [Node.js ](https://nodejs.org/ ) 20 LTS
2024-01-27 02:02:45 +03:00
- Install [pnpm ](https://pnpm.io/ )
2021-10-23 00:31:45 +03:00
2022-05-10 18:02:40 +03:00
```bash
2024-01-27 02:02:45 +03:00
npm install -g pnpm
2021-10-23 00:31:45 +03:00
```
2024-05-14 00:11:35 +03:00
- Install dependencies
2021-11-19 18:52:17 +03:00
2022-05-10 18:02:40 +03:00
```bash
2024-01-27 02:02:45 +03:00
pnpm install
2021-10-23 00:31:45 +03:00
```
2024-05-14 00:11:35 +03:00
- Build the dependencies
2021-11-19 18:52:17 +03:00
2022-05-10 18:02:40 +03:00
```bash
2024-01-27 02:02:45 +03:00
pnpm build
2021-10-23 00:31:45 +03:00
```
2021-11-19 18:52:17 +03:00
2024-05-14 00:11:35 +03:00
- (Optional) Install [Playwright ](https://playwright.dev/ ) browsers for UI testing
2021-11-19 18:52:17 +03:00
2022-05-10 18:02:40 +03:00
```bash
2024-05-14 00:11:35 +03:00
npx playwright install
2021-10-23 00:31:45 +03:00
```
2022-05-10 18:02:40 +03:00
2024-05-14 00:11:35 +03:00
- Start the build in watch mode to automatically rebuild on save
2022-05-10 18:02:40 +03:00
```bash
2024-05-14 00:11:35 +03:00
pnpm run watch
2022-05-10 18:02:40 +03:00
```
2024-05-14 00:11:35 +03:00
## Using command line
2022-05-10 18:02:40 +03:00
2024-05-14 00:11:35 +03:00
**If you are not at the root of the repo you have to use `-w` option to specify you want to run the command for the workspace. `pnpm -w <command>` .**
Those commands can be run on the workspace or in a specific package(`cd ./packages/< pkg > `).
| Command | Description |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pnpm build` | Build |
| `pnpm test` | Test |
| `pnpm test:watch` | Run test in watch mode(only when inside a package) |
| `pnpm watch` | Build in watch mode, Starting this command will rebuild the typescript files on save. |
| `pnpm clean` | Clean, sometimes there are ghost files left in the dist folder (common when renaming or deleting a TypeScript file), running this will get a clean state. |
| `pnpm format` | Format |
| `pnpm format:check` | Validate files are formatted |
| `pnpm gen-extern-signature` | Regenerate TypeScript signature for decorators(except compiler) |
| `pnpm change add` | Add a change description |
| `pnpm lint` | Run linters |
| `pnpm lint:fix` | Fix autofixable issues |
| `pnpm regen-samples` | Regen the samples(when the samples test fail) |
| `pnpm regen-docs` | Regen the reference docs |
### Verbose test logging
2021-10-23 00:31:45 +03:00
Tests sometimes log extra info using `logVerboseTestOutput` To see
this output on the command line, set environment variable
2023-02-16 01:37:39 +03:00
TYPESPEC_VERBOSE_TEST_OUTPUT=true.
2021-10-23 00:31:45 +03:00
2024-03-20 02:08:59 +03:00
**For the compiler you will need to run it manually or run the whole workspace build. This is because for the tool to run it needs the compiler to build first.**
2024-05-14 00:11:35 +03:00
## Using VS Code
2022-05-10 18:02:40 +03:00
2024-05-14 00:11:35 +03:00
### Recommended extensions
2022-05-10 18:02:40 +03:00
2024-05-14 00:11:35 +03:00
1. [Vitest Test Explorer ](https://marketplace.visualstudio.com/items?itemName=vitest.explorer ): Run tests from the IDE.
2. [Prettier ](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode ): Automatically keep code formatted correctly on save.
3. [ESLint ](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint ): Show eslint errors in warnings in UI.
4. [Code Spell Checker ](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker ): Show spell check errors in document.
2022-08-22 20:16:12 +03:00
2024-05-14 00:11:35 +03:00
### Opening the repo as workspace
2021-10-23 00:31:45 +03:00
Always open the root of the repo as the workspace. Things are setup to
allow easy development across packages rather than opening one package
at a time in the IDE.
2023-02-16 01:37:39 +03:00
- File -> Open Workspace, select root folder where the TypeSpec repo was
2021-11-19 18:52:17 +03:00
cloned
- Or run `code /path/to/repo/root` on the command line
2021-10-23 00:31:45 +03:00
2024-05-14 00:11:35 +03:00
### Building
2021-11-19 18:52:17 +03:00
- Terminal -> Run Build Task (`Ctrl+Shift+B`)
2021-10-23 00:31:45 +03:00
This will setup a an incremental watching build for the whole
repo. From there on, your changes will be built whenever you save.
2022-09-09 22:54:18 +03:00
Problems will be reported in the Problems pane automatically and the
2021-10-23 00:31:45 +03:00
Terminal pane will have three parallel watch tasks running:
2022-09-09 22:54:18 +03:00
- `watch-source` : tsc process that recompile on TypeScript changes
2021-11-19 18:52:17 +03:00
- `watch-spec` : process that regenerates spec.html when
spec.emu.html changes
2023-02-16 01:37:39 +03:00
- `watch-tmlanguage` : process that regenerates typespec.tmlanguage when
2021-11-19 18:52:17 +03:00
tmlanguage.ts changes
2021-10-23 00:31:45 +03:00
2024-05-14 00:11:35 +03:00
### Testing
2021-11-19 18:52:17 +03:00
2024-01-02 22:40:29 +03:00
```bash
# Run all the tests
2024-01-27 02:02:45 +03:00
pnpm test
2024-01-02 22:40:29 +03:00
# Run in a specific package tests in watch mode
2024-05-14 00:11:35 +03:00
pnpm test:watch
2024-01-02 22:40:29 +03:00
```
2021-10-23 00:31:45 +03:00
2024-05-14 00:11:35 +03:00
### Debugging
2021-11-19 18:52:17 +03:00
2021-10-23 00:31:45 +03:00
There are several "Run and Debug" tasks set up. Click on the Run and
Debug icon on the sidebar, pick one from its down, and press F5 to
debug the last one you chose.
1. **VS Code Extension** : This will run and debug an experimental
2023-02-16 01:37:39 +03:00
instance of VS Code with the TypeSpec extension for VS Code and TypeSpec
2022-09-09 22:54:18 +03:00
language server running live with any of your changes. It will
2021-10-23 00:31:45 +03:00
attach to both the VS Code client process and the language server
process automatically.
2. **Compile Scratch** : Use this to debug compiling
2023-08-04 20:19:02 +03:00
`packages/samples/scratch/*.tsp` . The TypeSpec source code in that
2023-02-16 01:37:39 +03:00
folder is excluded from source control by design. Create TypeSpec files
2021-10-23 00:31:45 +03:00
there to experiment and debug how the compiler reacts.
3. **Compile Scratch (nostdlib)** : Same as above, but skips parsing
2023-02-16 01:37:39 +03:00
and evaluating the TypeSpec standard library. Sometimes it's easier to
2021-10-23 00:31:45 +03:00
4. **Attach to Default Port** : Use this to attach to a manually run
`node --debug` command.
5. **Attach to Language Server** : Use this to attach to the language
server process of an already running client process. Useful if you
want to debug the language server in VS Code while debugging the VS
client in VS.
6. **Regenerate .tmlanguage** : This runs the code that produces the
2023-02-16 01:37:39 +03:00
typespec.tmlanguage file that provides syntax highlighting of TypeSpec in VS
2021-10-23 00:31:45 +03:00
and VS Code. Select this to debug its build process.
2024-05-14 00:11:35 +03:00
## Developing the Visual Studio Extension
2021-10-23 00:31:45 +03:00
2024-05-14 00:11:35 +03:00
### Prerequisites
2021-11-19 18:52:17 +03:00
2023-02-09 23:04:58 +03:00
Install [Visual Studio ](https://visualstudio.microsoft.com/vs/ ) 17.0
2021-11-19 18:52:17 +03:00
or later. It is not currently possible to build the VS extension
2021-10-23 00:31:45 +03:00
without it, and of course you'll need Visual Studio to run and debug
the Visual Studio extension.
2024-05-14 00:11:35 +03:00
### Build VS extension on the command line
2021-11-19 18:52:17 +03:00
2021-10-23 00:31:45 +03:00
See the command line build steps above. If you have VS installed,
the VS extension will be included in your command line full repo
builds automatically.
If you do not have VS installed the command line build steps above
will simply skip building the VS extension and only build the VS Code
extension.
2024-05-14 00:11:35 +03:00
### Build VS extension in VS
2021-11-19 18:52:17 +03:00
2023-02-16 01:37:39 +03:00
- Open packages/typespec-vs/Microsoft.TypeSpec.VisualStudio.sln in Visual Studio
2021-11-19 18:52:17 +03:00
- Build -> Build solution (`Ctrl+Shift+B`)
2021-10-23 00:31:45 +03:00
Unlike TypeScript in VS Code above, this is not a watching build, but
it is relatively fast to run. Press Ctrl+Shift+B again to build any
changes after you make them.
2024-05-14 00:11:35 +03:00
### Debug VS extension
2021-11-19 18:52:17 +03:00
- Click on the play icon in the toolbar or press `F5`
2021-10-23 00:31:45 +03:00
This will run and debug an experimental instance of VS with a version
2023-02-16 01:37:39 +03:00
of the TypeSpec extension for VS Code running live with any of your changes
to the extension or the TypeSpec language server.
2021-10-23 00:31:45 +03:00
The VS debugger will attach only to the VS client process. Use "Attach
2022-09-09 22:54:18 +03:00
to Language Server" described above to debug the language server in
2021-10-23 00:31:45 +03:00
VS Code.
2024-05-14 00:11:35 +03:00
### Installing your build
2021-11-19 18:52:17 +03:00
2024-05-14 00:11:35 +03:00
```bash
2024-01-27 02:02:45 +03:00
pnpm dogfood
2021-10-23 00:31:45 +03:00
```
2023-02-16 01:37:39 +03:00
This will globally install the @typespec/compiler package, putting your
build of `typespec` on PATH, and install the VS Code extension if VS Code
2021-10-23 00:31:45 +03:00
is installed.
Note the important difference between this and the steps to run and
debug the VS Code extension above: the `dogfood` command installs the
2023-02-16 01:37:39 +03:00
TypeSpec extension with your changes in regular, non-experimental instance
2021-10-23 00:31:45 +03:00
of VS Code, meaning you will have it always, and not only when running
2023-02-16 01:37:39 +03:00
the debug steps above. This is exactly like using `tsp vscode install` ,
2021-11-19 18:52:17 +03:00
only instead of downloading the latest release, it uses a build with your
changes applied.
2021-10-23 00:31:45 +03:00
There is no automatic `dogfood` process for installing the VS
2023-02-16 01:37:39 +03:00
extension non-experimentally, but if you build the typespec-vs project from
2021-10-23 00:31:45 +03:00
the command line following the steps above, or build its Release
configuration in Visual Studio, then you can install it by
2023-02-16 01:37:39 +03:00
double-clicking on packages/typespec-vs/Microsoft.TypeSpec.VisualStudio.vsix
2021-10-23 00:31:45 +03:00
that gets produced.
2022-04-19 19:29:35 +03:00
2024-05-14 00:11:35 +03:00
## TypeSpec website
### Run locally
Go to `packages/website` and run the command:
```bash
pnpm start
```
2022-04-19 19:29:35 +03:00
# Pull request
2023-02-16 01:37:39 +03:00
## Trigger TypeSpec Playground Try It build
2022-04-19 19:29:35 +03:00
For contributors of the repo the build will trigger automatically but for other's forks it will need a manual trigger from a contributor.
2024-01-25 21:40:16 +03:00
As a contributor you can run the following command to trigger the build and create a TypeSpec playground link for this PR.
2022-04-19 19:29:35 +03:00
2024-05-14 00:11:35 +03:00
```bash
/azp run typespec - pr tools
2022-04-19 19:29:35 +03:00
```
2022-09-21 21:30:49 +03:00
2024-05-14 00:11:35 +03:00
# Issue and Pr processes
2022-10-25 01:30:51 +03:00
2024-05-17 01:55:52 +03:00
## Triage process
Each team might use their own way of triaging issues however figuring out the area is a common process.
```mermaid
flowchart TD
classDef bot fill:#69f
classDef user fill:#9c6
subgraph "Legend"
a([User action])
b[\Automation detect/]:::bot
c[Automation action]:::bot
d{{state}}
end
subgraph "Issue creation"
select_template([User select template])
select_template --> bug_template
select_template --> feature_template
select_template --> plain
bug_template([Bug]) --> add_bug_label[🤖 add `bug` label]:::bot --> start
feature_template([Feature]) --> add_feature_label["🤖 add `feature` label"]:::bot --> start
plain([Plain]) --> start
start{{"✅ Issue created"}}
end
subgraph "Area triage"
auto-triage[\🤖 Detect if issue has area checkbox/]:::bot
add-needs-area[🤖 label 'needs-area']:::bot
auto-area-label["🤖 label '{area}'"]:::bot
add-area-label(["Issue is labelled with {area}"])
remove-needs-area[🤖 Remove 'needs-area']:::bot
end
subgraph "Team triage"
team-triage{{Issue Labeled with Team area}}
team-triage -- wrong area --> remove_area([Remove area label])
team-triage -- correct area --> triage([Triage/add to project])
end
start --> auto-triage
auto-triage -- no --> add-needs-area
auto-triage -- yes --> auto-area-label
auto-area-label --> remove-needs-area
add-needs-area --> add-area-label
add-area-label --> remove-needs-area
remove-needs-area ---> team-triage
remove_area --> add-needs-area
```
2024-05-14 00:11:35 +03:00
## Labels
2022-10-25 01:30:51 +03:00
2024-05-14 00:11:35 +03:00
TypeSpec repo use labels to help categorize and manage issues and PRs. The following is a list of labels and their descriptions.
2022-10-25 01:30:51 +03:00
2024-05-14 00:11:35 +03:00
<!-- LABEL GENERATED REF START -->
2024-05-17 01:55:52 +03:00
<!-- DO NOT EDIT: This section is automatically generated by eng/common/scripts/sync - labels.ts, update eng/common/config/labels.ts run pnpm sync - labels to update -->
2022-09-21 21:30:49 +03:00
2024-05-14 00:11:35 +03:00
### Labels reference
2022-12-28 06:33:45 +03:00
2024-05-14 00:11:35 +03:00
#### area
Area of the codebase
2024-09-04 20:58:53 +03:00
| Name | Color | Description |
| ---------------------------- | ------- | ----------------------------------------------------------------- |
| `compiler:core` | #453261 | Issues for @typespec/compiler |
| `compiler:emitter-framework` | #453261 | Issues for the emitter framework |
| `ide` | #846da1 | Issues for VS, VSCode, Monaco, etc. |
| `lib:http` | #c7aee6 | |
| `lib:openapi` | #c7aee6 | |
| `lib:rest` | #c7aee6 | |
| `lib:versioning` | #c7aee6 | |
| `meta:blog` | #007dc8 | Blog updates |
| `meta:website` | #007dc8 | TypeSpec.io updates |
| `tspd` | #004185 | Issues for the tspd tool |
| `emitter:client:csharp` | #e1b300 | Issue for the C# client emitter: @typespec/http -client-csharp |
| `emitter:client:java` | #e1b300 | Issue for the Java client emitter: @typespec/http -client-java |
| `emitter:client:python` | #e1b300 | Issue for the Python client emitter: @typespec/http -client-python |
| `emitter:json-schema` | #957300 | |
| `emitter:protobuf` | #957300 | The protobuf emitter |
| `emitter:openapi3` | #957300 | Issues for @typespec/openapi3 emitter |
| `openapi3:converter` | #957300 | Issues for @typespec/openapi3 openapi to typespec converter |
| `emitter:service:csharp` | #967200 | |
| `emitter:service:js` | #967200 | |
2024-11-04 22:48:51 +03:00
| `emitter:service:java` | #967200 | Issue for Java service emitter |
2024-09-04 20:58:53 +03:00
| `eng` | #65bfff | |
| `ui:playground` | #3256a8 | |
| `ui:type-graph-viewer` | #3256a8 | |
2024-05-14 00:11:35 +03:00
2024-05-23 20:01:14 +03:00
#### issue_kinds
Issue kinds
| Name | Color | Description |
| --------- | ------- | ------------------------------------------ |
| `bug` | #d93f0b | Something isn't working |
| `feature` | #cccccc | New feature or request |
| `docs` | #cccccc | Improvements or additions to documentation |
| `epic` | #cccccc | |
2024-05-14 00:11:35 +03:00
#### breaking-change
Labels around annotating issues and PR if they contain breaking change or deprecation
| Name | Color | Description |
| ----------------- | ------- | ---------------------------------------------------------------------------------- |
| `breaking-change` | #B60205 | A change that might cause specs or code to break |
| `deprecation` | #760205 | A previously supported feature will now report a warning and eventually be removed |
#### design-issues
Design issue management
| Name | Color | Description |
| ----------------- | ------- | ------------------------------------------------------ |
| `design:accepted` | #1a4421 | Proposal for design has been discussed and accepted. |
| `design:needed` | #96c499 | A design request has been raised that needs a proposal |
| `design:proposed` | #56815a | Proposal has been added and ready for discussion |
#### process
Process labels
| Name | Color | Description |
| -------------- | ------- | --------------------------------------------------------------------------------- |
2024-05-17 01:55:52 +03:00
| `needs-area` | #ffffff | |
2024-05-14 00:11:35 +03:00
| `needs-info` | #ffffff | Mark an issue that needs reply from the author or it will be closed automatically |
| `triaged:core` | #5319e7 | |
#### misc
Misc labels
2022-12-28 06:33:45 +03:00
2024-05-14 00:11:35 +03:00
| Name | Color | Description |
| -------------------------- | ------- | ------------------ |
| `Client Emitter Migration` | #FD92F0 | |
| `good first issue` | #7057ff | Good for newcomers |
2022-09-21 21:30:49 +03:00
2024-05-14 00:11:35 +03:00
<!-- LABEL GENERATED REF END -->
2022-09-21 21:30:49 +03:00
2024-05-14 00:11:35 +03:00
### Updating labels
2022-09-21 21:30:49 +03:00
2024-06-11 01:19:18 +03:00
Labels are configured in `eng/common/config/labels.ts` . To update labels, edit this file and run `pnpm sync-labels` .
**If you create a new label in github UI without updating the `labels.ts` file, it WILL be automatically removed**
2024-04-05 00:04:03 +03:00
# TypeSpec Emitters
The various language emitters will live in the in the repo under the following directory structure
- `packages/{protocol}-{client|server}-{language}` - Contains the `@typespec/{protocol}-{client|server}-{language}` package which is intended to be consumed by customers in their tsconfig.yaml file.
- `packages/{protocol}-{client|server}-{language}-generator` - Contains the `@typespec/{protocol}-{client|server}-{language}-generator` package which is the backend implementation of for a given emitter and usually contains code
languages such as .NET, Python, or Java. This package is only intended to be used as a dependency of the root emitter package.
- `packages/{protocol}-{client|server}-{language}-generator\**` - This directory will contain whatever is needed to build the backend emitter code generator. It will contain whatever folder structure is needed to build
that specific native code. It will also contain an isolated ci.yml file which will be the build pipeline for this package.
There is a goal to be able to ship these emitter packages independent from the rest of the packages in this repo as such they by default be excluded from the root pnpm workspace. Any npm package work
will be isolated to those directories with a goal of eventually moving to a consistent model so that we can both work in isolation as well as work as a E2E.
For language specific contributing information look for the contributing.md file in that specific lanague emitter folder.