Skip to content

Commit

Permalink
Require user opt-in to typecheck components (#30327)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ba30721ddf11ea3adea02b1a4bf1b083412d1b62
  • Loading branch information
sujayakar authored and Convex, Inc. committed Oct 4, 2024
1 parent ecbf352 commit 96c5f6f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions npm-packages/convex/src/cli/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export const deploy = new Command("deploy")
.choices(["enable", "try", "disable"] as const)
.default("try" as const),
)
.option(
"--typecheck-components",
"Check TypeScript files within component implementations with `tsc --noEmit`.",
false,
)
.addOption(
new Option(
"--codegen <mode>",
Expand Down Expand Up @@ -167,6 +172,7 @@ async function deployToNewPreviewDeployment(
cmd?: string | undefined;
verbose?: boolean | undefined;
typecheck: "enable" | "try" | "disable";
typecheckComponents: boolean;
codegen: "enable" | "disable";

debug?: boolean | undefined;
Expand Down Expand Up @@ -228,6 +234,7 @@ async function deployToNewPreviewDeployment(
verbose: !!options.verbose,
dryRun: false,
typecheck: options.typecheck,
typecheckComponents: options.typecheckComponents,
debug: !!options.debug,
debugBundlePath: options.debugBundlePath,
codegen: options.codegen === "enable",
Expand Down Expand Up @@ -265,6 +272,7 @@ async function deployToExistingDeployment(
dryRun?: boolean | undefined;
yes?: boolean | undefined;
typecheck: "enable" | "try" | "disable";
typecheckComponents: boolean;
codegen: "enable" | "disable";
cmd?: string | undefined;
cmdUrlEnvVarName?: string | undefined;
Expand Down Expand Up @@ -323,6 +331,7 @@ async function deployToExistingDeployment(
verbose: !!options.verbose,
dryRun: !!options.dryRun,
typecheck: options.typecheck,
typecheckComponents: options.typecheckComponents,
debug: !!options.debug,
debugBundlePath: options.debugBundlePath,
codegen: options.codegen === "enable",
Expand Down
6 changes: 6 additions & 0 deletions npm-packages/convex/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const dev = new Command("dev")
.choices(["enable", "try", "disable"] as const)
.default("try" as const),
)
.option(
"--typecheck-components",
"Check TypeScript files within component implementations with `tsc --noEmit`.",
false,
)
.addOption(
new Option("--codegen <mode>", "Regenerate code in `convex/_generated/`")
.choices(["enable", "disable"] as const)
Expand Down Expand Up @@ -196,6 +201,7 @@ export const dev = new Command("dev")
verbose: !!cmdOptions.verbose,
dryRun: false,
typecheck: cmdOptions.typecheck,
typecheckComponents: !!cmdOptions.typecheckComponents,
debug: false,
debugBundlePath: cmdOptions.debugBundlePath,
codegen: cmdOptions.codegen === "enable",
Expand Down
8 changes: 6 additions & 2 deletions npm-packages/convex/src/cli/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function runCodegen(ctx: Context, options: CodegenOptions) {
verbose: options.dryRun,
codegen: true,
liveComponentSources: options.liveComponentSources,
typecheckComponents: false,
},
);
} else {
Expand Down Expand Up @@ -140,6 +141,7 @@ async function startComponentsPushAndCodegen(
configPath: string,
options: {
typecheck: TypeCheckMode;
typecheckComponents: boolean;
adminKey: string;
url: string;
verbose: boolean;
Expand Down Expand Up @@ -331,8 +333,10 @@ async function startComponentsPushAndCodegen(
changeSpinner(ctx, "Running TypeScript...");
await parentSpan.enterAsync("typeCheckFunctionsInMode", async () => {
await typeCheckFunctionsInMode(ctx, options.typecheck, rootComponent.path);
for (const directory of components.values()) {
await typeCheckFunctionsInMode(ctx, options.typecheck, directory.path);
if (options.typecheckComponents) {
for (const directory of components.values()) {
await typeCheckFunctionsInMode(ctx, options.typecheck, directory.path);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/lib/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type PushOptions = {
verbose: boolean;
dryRun: boolean;
typecheck: "enable" | "try" | "disable";
typecheckComponents: boolean;
debug: boolean;
debugBundlePath?: string;
codegen: boolean;
Expand Down
6 changes: 6 additions & 0 deletions npm-packages/convex/src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const run = new Command("run")
.choices(["enable", "try", "disable"] as const)
.default("try" as const),
)
.option(
"--typecheck-components",
"Check TypeScript files within component implementations with `tsc --noEmit`.",
false,
)
.addOption(
new Option("--codegen <mode>", "Regenerate code in `convex/_generated/`")
.choices(["enable", "disable"] as const)
Expand Down Expand Up @@ -84,6 +89,7 @@ export const run = new Command("run")
verbose: false,
dryRun: false,
typecheck: options.typecheck,
typecheckComponents: options.typecheckComponents,
debug: false,
codegen: options.codegen === "enable",
url: deploymentUrl,
Expand Down

0 comments on commit 96c5f6f

Please sign in to comment.