Skip to content

Commit bbb09f3

Browse files
trivikrkuhe
andauthored
fix(scripts): skip files with stripped comments containing incorrect JavaScript (#3937)
Co-authored-by: George Fu <[email protected]>
1 parent 5d7ef10 commit bbb09f3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/downlevel-dts/downlevelWorkspace.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { exec } from "child_process";
33
import { access, readFile, writeFile } from "fs/promises";
44
import { join } from "path";
5+
import prettier from "prettier";
56
import stripComments from "strip-comments";
67
import { promisify } from "util";
78

@@ -39,7 +40,13 @@ export const downlevelWorkspace = async (workspacesDir, workspaceName) => {
3940
for (const downlevelTypesFilepath of files) {
4041
try {
4142
const content = await readFile(downlevelTypesFilepath, "utf8");
42-
await writeFile(downlevelTypesFilepath, stripComments(content));
43+
const strippedContent = stripComments(content);
44+
try {
45+
const formatted = prettier.format(strippedContent, { parser: "typescript" });
46+
await writeFile(downlevelTypesFilepath, formatted);
47+
} catch (error) {
48+
console.warn(`Failed to format "${downlevelTypesFilepath}". Skipping...`);
49+
}
4350
} catch (error) {
4451
console.error(`Error while stripping comments from "${downlevelTypesFilepath.replace(process.cwd(), "")}"`);
4552
console.error(error);

0 commit comments

Comments
 (0)