Skip to content

Commit

Permalink
chore: Remove getPkgJson test function (#47)
Browse files Browse the repository at this point in the history
* chore: remove debug log

* chore: Remove getPkgJson test function
  • Loading branch information
marvinhagemeister authored Mar 7, 2024
1 parent c001f7b commit 98768b9
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 137 deletions.
1 change: 0 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface PackageMeta {

export async function getPackageMeta(pkg: JsrPackage): Promise<PackageMeta> {
const url = `${JSR_URL}/@${pkg.scope}/${pkg.name}/meta.json`;
console.log("FETCH", url);
const res = await fetch(url);
if (!res.ok) {
// cancel unconsumed body to avoid memory leak
Expand Down
37 changes: 37 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,40 @@ export function getNewLineChars(source: string) {
}
return "\n";
}

export async function readJson<T>(file: string): Promise<T> {
const content = await fs.promises.readFile(file, "utf-8");
return JSON.parse(content);
}

export interface PkgJson {
name?: string;
version?: string;
license?: string;

dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
exports?: string | Record<string, string | Record<string, string>>;
scripts?: Record<string, string>;
}

export async function writeJson<T>(file: string, data: T): Promise<void> {
try {
await fs.promises.mkdir(path.dirname(file), { recursive: true });
} catch (_) {}
await fs.promises.writeFile(file, JSON.stringify(data, null, 2), "utf-8");
}

export async function readTextFile(file: string): Promise<string> {
return fs.promises.readFile(file, "utf-8");
}
export async function writeTextFile(
file: string,
content: string,
): Promise<void> {
try {
await fs.promises.mkdir(path.dirname(file), { recursive: true });
} catch (_) {}
await fs.promises.writeFile(file, content, "utf-8");
}
Loading

0 comments on commit 98768b9

Please sign in to comment.