-
Notifications
You must be signed in to change notification settings - Fork 361
Feature: tspconfig project with entrypoint #10548
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
base: main
Are you sure you want to change the base?
Changes from all commits
6df027a
fa06569
22a705a
233b1aa
bf34001
8f3085f
b7dac91
4bea19e
fa8e0fe
6353917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/compiler" | ||
| --- | ||
|
|
||
| Add `kind: project` and `entrypoint` support to `tspconfig.yaml` for defining project boundaries and entrypoint resolution. See [Project Configuration](https://typespec.io/docs/handbook/configuration/configuration#project-configuration) for more details. | ||
|
|
||
| ```yaml title=tspconfig.yaml | ||
| kind: project | ||
| entrypoint: src/service.tsp | ||
| emit: | ||
| - "@typespec/openapi3" | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { loadTypeSpecConfigForPath } from "../config/config-loader.js"; | ||
| import { formatDiagnostic } from "../core/logger/console-sink.js"; | ||
| import { getDirectoryPath, joinPaths } from "../core/path-utils.js"; | ||
| import { SystemHost, Diagnostic as TypeSpecDiagnostic } from "../core/types.js"; | ||
|
|
@@ -27,6 +28,19 @@ export async function resolveEntrypointFile( | |
| } | ||
|
|
||
| while (true) { | ||
| // Check for project tspconfig first (highest priority) | ||
| const config = await loadTypeSpecConfigForPath(host, dir, false, false); | ||
| if (config.kind === "project") { | ||
| const entrypoint = config.entrypoint ?? "main.tsp"; | ||
| const candidate = await existingFile(dir, entrypoint); | ||
| logDebug({ | ||
| level: "debug", | ||
| message: `project tspconfig found in ${dir}, entrypoint: ${entrypoint}`, | ||
| }); | ||
| // Project boundary found — stop walking regardless of whether entrypoint exists | ||
| return candidate ?? (isFilePath ? path : undefined); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this going to override a passed-in entryPoint path? It seems like the command line entry point should override config settings.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hhm yeah good point
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and I bevlive this is the source of your other comment. It would be I think the plan that we add that for every project in azure rest api specs repo but not sure I see it as a requirement yet.
which means in specs repo we should be fine having the same structure just with added kind: project
entrypoint: ./main.tsp # if we want to be explicittsp compile ./specification/foo/bar # compiles main.tsp
tsp compile ./specific/foo/bar/client.tsp # compile client.tsp
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and actually this is fine, the behavior in this file is just for LSP, we use a different logic for tsp compile |
||
| } | ||
|
|
||
| let pkg: any; | ||
| const pkgPath = joinPaths(dir, "package.json"); | ||
| const cached = await fileSystemCache?.get(pkgPath); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| # extends: ../tspconfig.yaml # Extend another config file | ||
| # emit: # Emitter name | ||
| kind: project | ||
| # entrypoint: main.tsp # Main TypeSpec file (default: main.tsp) | ||
| # extends: ../tspconfig.yaml # Extend another config file | ||
| # emit: # Emitter name | ||
| # - "<emitter-name" | ||
| # options: # Emitter options | ||
| # options: # Emitter options | ||
| # <emitter-name>: | ||
| # "<option-name>": "<option-value>" | ||
| # environment-variables: # Environment variables which can be used to interpolate emitter options | ||
| # environment-variables: # Environment variables which can be used to interpolate emitter options | ||
| # <variable-name>: | ||
| # default: "<variable-default>" | ||
| # parameters: # Parameters which can be used to interpolate emitter options | ||
| # parameters: # Parameters which can be used to interpolate emitter options | ||
| # <param-name>: | ||
| # default: "<param-default>" | ||
| # trace: # Trace areas to enable tracing | ||
| # trace: # Trace areas to enable tracing | ||
| # - "<trace-name>" | ||
| # warn-as-error: true # Treat warnings as errors | ||
| # output-dir: "{project-root}/_generated" # Configure the base output directory for all emitters | ||
| # warn-as-error: true # Treat warnings as errors | ||
| # output-dir: "{project-root}/_generated" # Configure the base output directory for all emitters |
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.
Is this just defense in depth? what is the context in which we could be loading config and it's not from a tspconfig file, since we are already checking that --config provided config cannot be project config?
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.
yeah didn't think that it probably doesn't seem possible via compile but might be via ide(you open a tspconfig.foo.yaml with kind: project)