Skip to content

Commit 98768b9

Browse files
chore: Remove getPkgJson test function (#47)
* chore: remove debug log * chore: Remove getPkgJson test function
1 parent c001f7b commit 98768b9

File tree

6 files changed

+118
-137
lines changed

6 files changed

+118
-137
lines changed

src/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface PackageMeta {
1212

1313
export async function getPackageMeta(pkg: JsrPackage): Promise<PackageMeta> {
1414
const url = `${JSR_URL}/@${pkg.scope}/${pkg.name}/meta.json`;
15-
console.log("FETCH", url);
1615
const res = await fetch(url);
1716
if (!res.ok) {
1817
// cancel unconsumed body to avoid memory leak

src/utils.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,40 @@ export function getNewLineChars(source: string) {
227227
}
228228
return "\n";
229229
}
230+
231+
export async function readJson<T>(file: string): Promise<T> {
232+
const content = await fs.promises.readFile(file, "utf-8");
233+
return JSON.parse(content);
234+
}
235+
236+
export interface PkgJson {
237+
name?: string;
238+
version?: string;
239+
license?: string;
240+
241+
dependencies?: Record<string, string>;
242+
devDependencies?: Record<string, string>;
243+
optionalDependencies?: Record<string, string>;
244+
exports?: string | Record<string, string | Record<string, string>>;
245+
scripts?: Record<string, string>;
246+
}
247+
248+
export async function writeJson<T>(file: string, data: T): Promise<void> {
249+
try {
250+
await fs.promises.mkdir(path.dirname(file), { recursive: true });
251+
} catch (_) {}
252+
await fs.promises.writeFile(file, JSON.stringify(data, null, 2), "utf-8");
253+
}
254+
255+
export async function readTextFile(file: string): Promise<string> {
256+
return fs.promises.readFile(file, "utf-8");
257+
}
258+
export async function writeTextFile(
259+
file: string,
260+
content: string,
261+
): Promise<void> {
262+
try {
263+
await fs.promises.mkdir(path.dirname(file), { recursive: true });
264+
} catch (_) {}
265+
await fs.promises.writeFile(file, content, "utf-8");
266+
}

0 commit comments

Comments
 (0)