From 414e3b201bf2fc0aeadcbc37c15549bfbc379547 Mon Sep 17 00:00:00 2001 From: Chenjie Shi Date: Tue, 4 Jun 2024 08:47:01 +0800 Subject: [PATCH] [tcgc] support new typespec emitter naming rule (#947) resolve: https://github.com/Azure/typespec-azure/issues/937 --- .chronus/changes/emitter_name-2024-5-3-22-57-49.md | 7 +++++++ .../src/internal-utils.ts | 2 +- .../test/internal-utils.test.ts | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/emitter_name-2024-5-3-22-57-49.md 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 e2a7902d93..70c1d96ee2 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"); + }); + }); });