Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/script/generate-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function extractSdkFlags(command: Command): SdkFlagInfo[] {
flags.push({
name,
kind,
tsType,
tsType: def.variadic ? `Array<${tsType}>` : tsType,
optional,
default: def.default,
brief: def.brief,
Expand Down
33 changes: 33 additions & 0 deletions packages/cli/test/lib/sdk-flag-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Unit Tests for Generated SDK Flag Types
*
* Stricli passes variadic flags to a command as arrays, and the SDK forwards flags to the
* handler unchanged. The generator used to declare them with their element type, so
* `sdk.auth.login({ scope: "org:read" })` type-checked and then failed inside the handler
* (`flags.scope.flatMap is not a function`).
*/

import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { describe, expect, test } from "vitest";

const declarations = readFileSync(
fileURLToPath(new URL("../../src/sdk.generated.d.cts", import.meta.url)),
"utf-8"
);

function paramsType(name: string): string {
const start = declarations.indexOf(`export type ${name} = {`);
if (start === -1) {
throw new Error(`${name} is missing from the generated SDK declarations`);
}
return declarations.slice(start, declarations.indexOf("\n};", start));
}

describe("generated SDK flag types", () => {
test("declares variadic flags as arrays and keeps scalar flags scalar", () => {
const login = paramsType("AuthLoginParams");
expect(login).toContain("scope?: Array<string>;");
expect(login).toContain("token?: string;");
});
});
Loading