Skip to content

Commit

Permalink
Pass encoding into readFile
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Aug 9, 2024
1 parent 3cf3ecb commit 7bffb28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 4 additions & 5 deletions packages/tools/src/expandPackageGlobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ export async function expandPackageGlobs(
const discoveredPackages: Array<Package | undefined> = await Promise.all(
directories.map((dir) =>
fsp
.readFile(path.join(dir, "package.json"))
.readFile(path.join(dir, "package.json"), "utf-8")
.catch((err) => {
if (err && (err as { code: string }).code === "ENOENT") {
return undefined;
}
throw err;
})
.then((result: Buffer | undefined) => {
const s = result?.toString();
if (s) {
.then((result) => {
if (result) {
return {
dir: path.resolve(dir),
relativeDir: path.relative(directory, dir),
packageJson: JSON.parse(s),
packageJson: JSON.parse(result),
};
}
})
Expand Down
10 changes: 6 additions & 4 deletions packages/tools/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import fsp from "fs/promises";
import path from "path";

export const readJson = async (directory: string, file: string) => JSON.parse((await fsp.readFile(
path.join(directory, file)
)).toString());
path.join(directory, file),
"utf-8"
)));

export const readJsonSync = (directory: string, file: string) => JSON.parse(fs.readFileSync(
path.join(directory, file)
).toString());
path.join(directory, file),
"utf-8"
));

0 comments on commit 7bffb28

Please sign in to comment.