-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Description
There seems to be a bug in the typegen tool where running it with multiple schema configurations results in only the last layout being exported in the client/index.ts file. All previous layouts' exports are lost.
The Problem
In the generateTypedClientsSingle function in packages/typegen/src/typegen.ts, the client/index.ts file is deleted at the beginning of each configuration processing:
// Current code (line 126-127)
const clientIndexFilePath = path.join(rootDir, "client", "index.ts");
fs.rmSync(clientIndexFilePath, { force: true }); // ensure clean slate for this fileThis means when processing multiple configurations, each one deletes the index.ts file that was just populated by the previous configuration.
Reproduction Steps
- Create a configuration with multiple schemas:
[
{
"clientSuffix": "Layout",
"path": "./src/schema",
"clearOldFiles": false,
"envNames": {
"auth": {
"username": "FM_USERNAME",
"password": "FM_PASSWORD"
},
"server": "MyFMServer",
"db": "FM_DATABASE_AB"
},
"layouts": [
{
"schemaName": "MySchema",
"layoutName": "MyLayout"
}
],
"validator": "zod/v3"
},
{
"clientSuffix": "Layout",
"path": "./src/schema",
"clearOldFiles": false,
"envNames": {
"auth": {
"username": "FM_USERNAME",
"password": "FM_PASSWORD"
},
"server": "MyFMServer",
"db": "FM_DATABASE_CD"
},
"layouts": [
{
"schemaName": "MySchema3",
"layoutName": "MyLayout3"
}
],
"validator": "zod/v3"
}
]- Run typegen
- Check
src/schema/client/index.ts
Current Behavior
The generated index.ts file contains only:
export { client as MySchema3Layout } from "./MySchema3.js";The export for MySchemaLayout is missing.
Expected Behavior
The generated index.ts file should contain exports for all layouts:
export { client as MySchemaLayout } from "./MySchema.js";
export { client as MySchema3Layout } from "./MySchema3.js";Root Cause
The issue occurs because:
generateTypedClientsloops through each config and callsgenerateTypedClientsSingle- Each call to
generateTypedClientsSingledeletes theclient/index.tsfile at the start - Previous exports are lost when the file is deleted
Proposed Solution
Move the index.ts deletion to the top-level generateTypedClients function to ensure it's only deleted once at the beginning of the entire process:
- In
generateTypedClients, delete the index.ts files once for all unique paths before processing any configs - Remove the
fs.rmSync(clientIndexFilePath, { force: true })line fromgenerateTypedClientsSingle
Related Code Lines
proofkit/packages/typegen/src/typegen.ts
Line 26 in f8e4711
export const generateTypedClients = async ( proofkit/packages/typegen/src/typegen.ts
Line 129 in f8e4711
fs.rmSync(clientIndexFilePath, { force: true }); // ensure clean slate for this file