Skip to content

Commit 39d6325

Browse files
jordanhunt22Convex, Inc.
authored andcommitted
Update
GitOrigin-RevId: defb3f5240237e9a949797d447ec6735e4333bf8
1 parent 2bc4433 commit 39d6325

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

src/cli/codegen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const codegen = new Command("codegen")
3535
"Generate CommonJS modules (CJS) instead of ECMAScript modules, the default. Bundlers typically take care of this conversion while bundling, so this setting is generally only useful for projects which do not use a bundler, typically Node.js projects. Convex functions can be written with either syntax.",
3636
).hideHelp(),
3737
)
38+
// Only for doing codegen on system UDFs
39+
.addOption(new Option("--system-udfs").hideHelp())
3840
.action(async (options) => {
3941
const ctx = await oneoffContext(options);
4042
const deploymentSelection = await getDeploymentSelection(ctx, options);
@@ -49,5 +51,6 @@ export const codegen = new Command("codegen")
4951
adminKey: options.adminKey,
5052
liveComponentSources: !!options.liveComponentSources,
5153
debugNodeApis: false,
54+
systemUdfs: !!options.systemUdfs,
5255
});
5356
});

src/cli/lib/codegen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type CodegenOptions = {
4747
commonjs: boolean;
4848
liveComponentSources: boolean;
4949
debugNodeApis: boolean;
50+
systemUdfs: boolean;
5051
};
5152

5253
export async function doCodegenForNewProject(ctx: Context) {
@@ -317,7 +318,7 @@ export async function doFinalComponentCodegen(
317318
);
318319

319320
if (opts?.generateCommonJSApi || projectConfig.generateCommonJSApi) {
320-
const apiCjsDTSPath = path.join(codegenDir, "api_cjs.d.ts");
321+
const apiCjsDTSPath = path.join(codegenDir, "api_cjs.d.cts");
321322
await writeFormattedFile(
322323
ctx,
323324
tmpDir,

src/cli/lib/components.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@ export async function runCodegen(
8989
functionsDirectoryPath,
9090
);
9191

92-
if (ctx.fs.exists(componentRootPath)) {
92+
if (options.init) {
93+
await doInitCodegen(ctx, functionsDirectoryPath, false, {
94+
dryRun: options.dryRun,
95+
debug: options.debug,
96+
});
97+
}
98+
99+
if (
100+
(ctx.fs.exists(componentRootPath) ||
101+
process.env.USE_LEGACY_PUSH === undefined) &&
102+
!options.systemUdfs
103+
) {
93104
// Early exit for a better error message trying to use a preview key.
94105
if (deploymentSelection.kind === "preview") {
95106
return await ctx.crash({
@@ -126,13 +137,6 @@ export async function runCodegen(
126137
},
127138
);
128139
} else {
129-
if (options.init) {
130-
await doInitCodegen(ctx, functionsDirectoryPath, false, {
131-
dryRun: options.dryRun,
132-
debug: options.debug,
133-
});
134-
}
135-
136140
if (options.typecheck !== "disable") {
137141
logMessage(chalk.gray("Running TypeScript typecheck…"));
138142
}
@@ -150,12 +154,12 @@ export async function runPush(ctx: Context, options: PushOptions) {
150154
const convexDir = functionsDir(configPath, projectConfig);
151155
const componentRootPath = await findComponentRootPath(ctx, convexDir);
152156
if (
153-
ctx.fs.exists(componentRootPath) ||
154-
process.env.USE_COMPONENTS_PUSH === "true"
157+
!ctx.fs.exists(componentRootPath) &&
158+
process.env.USE_LEGACY_PUSH !== undefined
155159
) {
156-
await runComponentsPush(ctx, options, configPath, projectConfig);
157-
} else {
158160
await runNonComponentsPush(ctx, options, configPath, projectConfig);
161+
} else {
162+
await runComponentsPush(ctx, options, configPath, projectConfig);
159163
}
160164
}
161165

src/cli/lib/components/definition/bundle.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function virtualConfig({
5555
async (_args) => {
5656
return {
5757
contents: VIRTUAL_CONFIG_CONTENTS,
58-
resolveDir: rootComponentDirectory.path,
58+
resolveDir: path.dirname(rootComponentDirectory.path),
5959
};
6060
},
6161
);
@@ -296,8 +296,7 @@ export async function componentGraph(
296296
});
297297
}
298298
for (const warning of result.warnings) {
299-
// eslint-disable-next-line no-console
300-
console.log(chalk.yellow(`esbuild warning: ${warning.text}`));
299+
logWarning(chalk.yellow(`esbuild warning: ${warning.text}`));
301300
}
302301
return await findComponentDependencies(ctx, result.metafile);
303302
}
@@ -435,8 +434,7 @@ export async function bundleDefinitions(
435434
});
436435
}
437436
for (const warning of result.warnings) {
438-
// eslint-disable-next-line no-console
439-
console.log(chalk.yellow(`esbuild warning: ${warning.text}`));
437+
logWarning(chalk.yellow(`esbuild warning: ${warning.text}`));
440438
}
441439

442440
const outputs: {

0 commit comments

Comments
 (0)