Skip to content

Commit 40b11f6

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Change legacyJavaScriptFileType: true to fileType: "js/dts" in convex.json (#42889)
GitOrigin-RevId: 53c5e48d40b881c42afebcfd9eb2a188be40956e
1 parent 05edb8d commit 40b11f6

File tree

9 files changed

+27
-25
lines changed

9 files changed

+27
-25
lines changed

npm-packages/convex/schemas/convex.schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@
5454
"type": "object",
5555
"description": "Configuration for Convex code generation.",
5656
"properties": {
57-
"legacyJavaScriptFileType": {
58-
"type": "boolean",
59-
"description": "When true (or omitted, default is true), generates separate .js and .d.ts files for the Convex API. When false generates combined .ts files instead. The .ts format is more modern and recommended for TypeScript projects.\n\nNote: This option must be true when using generateCommonJSApi.",
60-
"default": true
57+
"fileType": {
58+
"type": "string",
59+
"enum": ["ts", "js/dts"],
60+
"description": "The file format of generated code. \"ts\" generates combined .ts files (recommended for TypeScript projects), \"js/dts\" generates separate .js and .d.ts files.\n\nNote: \"js/dts\" must be used when using generateCommonJSApi.",
61+
"default": "js/dts"
6162
},
6263
"legacyComponentApi": {
6364
"type": "boolean",

npm-packages/convex/src/cli/lib/config.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface ProjectConfig {
7777
staticApi: boolean;
7878
staticDataModel: boolean;
7979
legacyComponentApi?: boolean;
80-
legacyJavaScriptFileType?: boolean;
80+
fileType?: "ts" | "js/dts";
8181
};
8282
}
8383

@@ -102,7 +102,7 @@ const DEFAULT_FUNCTIONS_PATH = "convex/";
102102

103103
/** Whether .ts file extensions should be used for generated code (default is false). */
104104
export function usesTypeScriptCodegen(projectConfig: ProjectConfig): boolean {
105-
return projectConfig.codegen.legacyJavaScriptFileType === false;
105+
return projectConfig.codegen.fileType === "ts";
106106
}
107107

108108
/** Whether the new component API import style should be used (default is false) */
@@ -215,29 +215,27 @@ export async function parseProjectConfig(
215215
}
216216

217217
if (
218-
typeof obj.codegen.legacyJavaScriptFileType !== "undefined" &&
219-
typeof obj.codegen.legacyJavaScriptFileType !== "boolean"
218+
typeof obj.codegen.fileType !== "undefined" &&
219+
obj.codegen.fileType !== "ts" &&
220+
obj.codegen.fileType !== "js/dts"
220221
) {
221222
return await ctx.crash({
222223
exitCode: 1,
223224
errorType: "invalid filesystem data",
224225
printedMessage:
225-
"Expected `codegen.legacyJavaScriptFileType` in `convex.json` to be true or false",
226+
'Expected `codegen.fileType` in `convex.json` to be "ts" or "js/dts"',
226227
});
227228
}
228229

229-
// Validate that generateCommonJSApi is not true when legacyJavaScriptFileType is false
230-
if (
231-
obj.generateCommonJSApi &&
232-
obj.codegen.legacyJavaScriptFileType === false
233-
) {
230+
// Validate that generateCommonJSApi is not true when using TypeScript codegen
231+
if (obj.generateCommonJSApi && obj.codegen.fileType === "ts") {
234232
return await ctx.crash({
235233
exitCode: 1,
236234
errorType: "invalid filesystem data",
237235
printedMessage:
238-
"Cannot use `generateCommonJSApi: true` with `codegen.legacyJavaScriptFileType: false`. " +
236+
'Cannot use `generateCommonJSApi: true` with `codegen.fileType: "ts"`. ' +
239237
"CommonJS modules require JavaScript generation. " +
240-
"Either set `codegen.legacyJavaScriptFileType: true` or remove `generateCommonJSApi`.",
238+
'Either set `codegen.fileType: "js/dts"` or remove `generateCommonJSApi`.',
241239
});
242240
}
243241

@@ -676,8 +674,11 @@ function stripDefaults(projectConfig: ProjectConfig): any {
676674
if (stripped.codegen.staticDataModel === false) {
677675
delete stripped.codegen.staticDataModel;
678676
}
679-
// legacyJavaScriptFileType and legacyComponentApi are optional and undefined by default,
680-
// so they'll only be present if explicitly set - we don't need to strip them
677+
678+
// `"fileType"` and `"legacyComponentApi"` are optional and undefined by
679+
// default, and the behavior of undefined may change in the future for these
680+
// so we don't want to strip them.
681+
681682
if (Object.keys(stripped.codegen).length === 0) {
682683
delete stripped.codegen;
683684
}

npm-packages/private-demos/actions/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"externalPackages": ["*"]
55
},
66
"codegen": {
7-
"legacyJavaScriptFileType": false
7+
"fileType": "ts"
88
}
99
}

npm-packages/private-demos/components-api-import-ts/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "../../convex/schemas/convex.schema.json",
33
"codegen": {
44
"legacyComponentApi": false,
5-
"legacyJavaScriptFileType": false
5+
"fileType": "ts"
66
}
77
}

npm-packages/private-demos/components-api-import/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "../../convex/schemas/convex.schema.json",
33
"codegen": {
44
"legacyComponentApi": false,
5-
"legacyJavaScriptFileType": true
5+
"fileType": "js/dts"
66
}
77
}

npm-packages/private-demos/components-legacy-ts/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "../../convex/schemas/convex.schema.json",
33
"codegen": {
44
"legacyComponentApi": true,
5-
"legacyJavaScriptFileType": false
5+
"fileType": "ts"
66
}
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../convex/schemas/convex.schema.json",
33
"codegen": {
4-
"legacyJavaScriptFileType": true,
4+
"fileType": "js/dts",
55
"legacyComponentApi": true
66
}
77
}

npm-packages/private-demos/components-ts-alias/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "../../convex/schemas/convex.schema.json",
33
"codegen": {
44
"legacyComponentApi": false,
5-
"legacyJavaScriptFileType": false
5+
"fileType": "ts"
66
}
77
}

npm-packages/private-demos/static-codegen-ts/convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"codegen": {
44
"staticApi": true,
55
"staticDataModel": true,
6-
"legacyJavaScriptFileType": false
6+
"fileType": "ts"
77
}
88
}

0 commit comments

Comments
 (0)