Skip to content

Commit baccc2c

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Generate component-friendly convex/_generated/api.ts file in initial codegen (#43140)
GitOrigin-RevId: 6678732c5535e42033e3162462fc381f0baa4ce2
1 parent 8b6b854 commit baccc2c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## Unreleased
44

5-
- When running `npx convex deploy`, the CLI will now ask for explicit confirmation
6-
before deleting large indexes. This change is helpful for avoiding situations
7-
where an index is accidentally deleted and backfilling it takes a long time.
5+
- When running `npx convex deploy`, the CLI will now ask for explicit
6+
confirmation before deleting large indexes. This change is helpful for
7+
avoiding situations where an index is accidentally deleted and backfilling it
8+
takes a long time.
89

910
## 1.29.0
1011

src/cli/lib/codegen.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import {
3131
} from "./config.js";
3232
import { recursivelyDelete } from "./fsUtils.js";
3333
import { componentServerTS } from "../codegen_templates/component_server.js";
34-
import { ComponentDirectory } from "./components/definition/directoryStructure.js";
34+
import {
35+
ComponentDirectory,
36+
isComponentDirectory,
37+
} from "./components/definition/directoryStructure.js";
3538
import { StartPushResponse } from "./deployApi/startPush.js";
3639
import {
3740
componentApiDTS,
@@ -65,8 +68,24 @@ export async function doCodegenForNewProject(ctx: Context) {
6568
const configPath = await configFilepath(ctx);
6669
const functionsPath = functionsDir(configPath, existingProjectConfig);
6770
await doInitCodegen(ctx, functionsPath, true);
68-
// Disable typechecking since there isn't any code yet.
69-
await doCodegen(ctx, functionsPath, "disable");
71+
72+
const componentDir = isComponentDirectory(ctx, functionsPath, true);
73+
if (componentDir.kind === "err") {
74+
return await ctx.crash({
75+
exitCode: 1,
76+
errorType: "invalid filesystem data",
77+
printedMessage: `Invalid component directory: ${componentDir.why}`,
78+
});
79+
}
80+
81+
if (componentDir.component.isRootWithoutConfig) {
82+
// Disable typechecking since there isn't any code yet.
83+
await doCodegen(ctx, functionsPath, "disable");
84+
} else {
85+
await withTmpDir(async (tmpDir) => {
86+
await doInitialComponentCodegen(ctx, tmpDir, componentDir.component);
87+
});
88+
}
7089
}
7190

7291
export async function doInitCodegen(

0 commit comments

Comments
 (0)