diff --git a/.chronus/changes/emitter_name-2024-5-3-22-57-49.md b/.chronus/changes/emitter_name-2024-5-3-22-57-49.md new file mode 100644 index 0000000000..4ff152d8fe --- /dev/null +++ b/.chronus/changes/emitter_name-2024-5-3-22-57-49.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +support new typespec emitter naming rule \ No newline at end of file diff --git a/packages/typespec-client-generator-core/src/internal-utils.ts b/packages/typespec-client-generator-core/src/internal-utils.ts index af56cc92f7..fd6d1f212c 100644 --- a/packages/typespec-client-generator-core/src/internal-utils.ts +++ b/packages/typespec-client-generator-core/src/internal-utils.ts @@ -62,7 +62,7 @@ export function parseEmitterName( ); return diagnostics.wrap("none"); } - const regex = /(?:cadl|typespec)-([^\\/]*)/; + const regex = /(?:cadl|typespec|client|server)-([^\\/-]*)/; const match = emitterName.match(regex); if (!match || match.length < 2) return diagnostics.wrap("none"); const language = match[1]; diff --git a/packages/typespec-client-generator-core/test/internal-utils.test.ts b/packages/typespec-client-generator-core/test/internal-utils.test.ts index 68ee5afdc1..03cdc2a1f2 100644 --- a/packages/typespec-client-generator-core/test/internal-utils.test.ts +++ b/packages/typespec-client-generator-core/test/internal-utils.test.ts @@ -51,4 +51,17 @@ describe("typespec-client-generator-core: internal-utils", () => { strictEqual(docHelper.details, "This is a description"); }); }); + describe("parseEmitterName", () => { + it("@azure-tools/typespec-{language}", async () => { + const runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-csharp" }); + await runner.compile(""); + strictEqual(runner.context.emitterName, "csharp"); + }); + + it("@typespec/{protocol}-{client|server}-{language}-generator", async () => { + const runner = await createSdkTestRunner({ emitterName: "@typespec/http-client-csharp" }); + await runner.compile(""); + strictEqual(runner.context.emitterName, "csharp"); + }); + }); });