Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
ensure link-ts-references script prettiers files after writing them
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch committed Jun 20, 2023
1 parent 978fee4 commit beee952
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs/assets/launch.json linguist-language=JSON5
tsconfig-base.json linguist-language=JSON5
tsconfig.json linguist-language=JSON5
.nycrc linguist-language=JSON
.prettierrc linguist-language=JSON
src/packages/ganache/api-extractor.json linguist-language=JSON5
Expand Down
14 changes: 12 additions & 2 deletions scripts/link-ts-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { readFileSync, existsSync, writeFileSync } from "fs-extra";
import { resolve, join, relative, sep } from "path";
import prettier from "prettier";

// using `require` because everything in scripts uses typescript's default
// compiler settings, and these two modules require enabling `esModuleInterop`
Expand Down Expand Up @@ -133,11 +134,20 @@ function updateConfigs(configs: PackageInfo[]) {
configs.forEach(updateConfig);
}

function saveConfigs(configs: PackageInfo[]) {
async function saveConfigs(configs: PackageInfo[]) {
const prettierConfig = await prettier.resolveConfig(process.cwd());
configs.forEach(({ modified, path, tsConfig }) => {
if (modified) {
const tsConfigFile = join(path, "tsconfig.json");
writeFileSync(tsConfigFile, JSON5.stringify(tsConfig, null, 2));
writeFileSync(
tsConfigFile,
prettier.format(JSON5.stringify(tsConfig, null, 2), {
...prettierConfig,
// neccessary as json5's default is to strip quotes
quoteProps: "preserve",
parser: "json5"
})
);
}
});
}
Expand Down

0 comments on commit beee952

Please sign in to comment.