Skip to content

Commit

Permalink
Don't prettierignore generated README and tsconfig.json (#29446)
Browse files Browse the repository at this point in the history
Stop prettierignore-ing generated README and tsconfig.json

GitOrigin-RevId: c7b3b807d2ac94a9e234b94814c152c19ef589d2
  • Loading branch information
thomasballinger authored and Convex, Inc. committed Sep 2, 2024
1 parent e3c4f00 commit e7b6853
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/cli/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export async function doFinalComponentCodegen(
serverContents,
"typescript",
serverDTSPath,
opts,
{ prettierIgnore: true, ...opts },
);

const apiDTSPath = path.join(codegenDir, "api.d.ts");
Expand All @@ -269,14 +269,10 @@ export async function doFinalComponentCodegen(
rootComponent,
componentDirectory,
);
await writeFormattedFile(
ctx,
tmpDir,
apiContents,
"typescript",
apiDTSPath,
opts,
);
await writeFormattedFile(ctx, tmpDir, apiContents, "typescript", apiDTSPath, {
prettierIgnore: true,
...opts,
});

if (opts?.generateCommonJSApi || projectConfig.generateCommonJSApi) {
const apiCjsDTSPath = path.join(codegenDir, "api_cjs.d.ts");
Expand All @@ -286,7 +282,7 @@ export async function doFinalComponentCodegen(
apiContents,
"typescript",
apiCjsDTSPath,
opts,
{ prettierIgnore: true, ...opts },
);
}
}
Expand Down Expand Up @@ -356,7 +352,7 @@ async function doDataModelCodegen(
schemaContent.DTS,
"typescript",
path.join(codegenDir, "dataModel.d.ts"),
opts,
{ prettierIgnore: true, ...opts },
);
return ["dataModel.d.ts"];
}
Expand All @@ -374,7 +370,7 @@ async function doServerCodegen(
serverContent.JS,
"typescript",
path.join(codegenDir, "server.js"),
opts,
{ prettierIgnore: true, ...opts },
);

await writeFormattedFile(
Expand All @@ -383,7 +379,7 @@ async function doServerCodegen(
serverContent.DTS,
"typescript",
path.join(codegenDir, "server.d.ts"),
opts,
{ prettierIgnore: true, ...opts },
);

return ["server.js", "server.d.ts"];
Expand All @@ -402,7 +398,7 @@ async function doInitialComponentServerCodegen(
componentServerJS(),
"typescript",
path.join(codegenDir, "server.js"),
opts,
{ prettierIgnore: true, ...opts },
);

// Don't write our stub if the file already exists: It probably
Expand All @@ -415,7 +411,7 @@ async function doInitialComponentServerCodegen(
componentServerStubDTS(isRoot),
"typescript",
path.join(codegenDir, "server.d.ts"),
opts,
{ prettierIgnore: true, ...opts },
);
}

Expand All @@ -437,7 +433,7 @@ async function doInitialComponentApiCodegen(
apiJS,
"typescript",
path.join(codegenDir, "api.js"),
opts,
{ prettierIgnore: true, ...opts },
);

// Don't write the `.d.ts` stub if it already exists.
Expand All @@ -450,7 +446,7 @@ async function doInitialComponentApiCodegen(
apiStubDTS,
"typescript",
apiDTSPath,
opts,
{ prettierIgnore: true, ...opts },
);
}

Expand All @@ -464,7 +460,7 @@ async function doInitialComponentApiCodegen(
apiCjsJS,
"typescript",
path.join(codegenDir, "api_cjs.cjs"),
opts,
{ prettierIgnore: true, ...opts },
);

const cjsStubPath = path.join(codegenDir, "api_cjs.d.cts");
Expand All @@ -475,7 +471,7 @@ async function doInitialComponentApiCodegen(
apiStubDTS,
"typescript",
cjsStubPath,
opts,
{ prettierIgnore: true, ...opts },
);
}
writtenFiles.push("api_cjs.cjs", "api_cjs.d.cts");
Expand All @@ -502,15 +498,15 @@ async function doApiCodegen(
apiContent.JS,
"typescript",
path.join(codegenDir, "api.js"),
opts,
{ prettierIgnore: true, ...opts },
);
await writeFormattedFile(
ctx,
tmpDir,
apiContent.DTS,
"typescript",
path.join(codegenDir, "api.d.ts"),
opts,
{ prettierIgnore: true, ...opts },
);
const writtenFiles = ["api.js", "api.d.ts"];

Expand All @@ -522,15 +518,15 @@ async function doApiCodegen(
apiCjsContent.JS,
"typescript",
path.join(codegenDir, "api_cjs.cjs"),
opts,
{ prettierIgnore: true, ...opts },
);
await writeFormattedFile(
ctx,
tmpDir,
apiCjsContent.DTS,
"typescript",
path.join(codegenDir, "api_cjs.d.cts"),
opts,
{ prettierIgnore: true, ...opts },
);
writtenFiles.push("api_cjs.cjs", "api_cjs.d.cts");
}
Expand All @@ -547,6 +543,7 @@ async function writeFormattedFile(
options?: {
dryRun?: boolean;
debug?: boolean;
prettierIgnore?: boolean;
},
) {
// Run prettier so we don't have to think about formatting!
Expand All @@ -558,11 +555,13 @@ async function writeFormattedFile(
pluginSearchDirs: false,
});
// Then add prettierignore comments so we don't fight with users' prettier configs
formattedContents = `/* prettier-ignore-start */
if (options?.prettierIgnore) {
formattedContents = `/* prettier-ignore-start */
${formattedContents}
/* prettier-ignore-end */
`;
}
if (options?.debug) {
// NB: The `test_codegen_projects_are_up_to_date` smoke test depends
// on this output format.
Expand Down

0 comments on commit e7b6853

Please sign in to comment.