Skip to content

Commit b150168

Browse files
Copilotfuxingloh
andauthored
feat: produce build/bin.js for Node.js runtime (#8)
* Initial plan * Add Node.js compatible build producing build/bin.js Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com> * simplify build to single Node.js target Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com>
1 parent 59d8801 commit b150168

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/use-agently/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"author": "AgentlyHQ",
1313
"type": "module",
1414
"bin": {
15-
"use-agently": "build/use-agently"
15+
"use-agently": "build/bin.js"
1616
},
1717
"files": [
1818
"build"
1919
],
2020
"scripts": {
21-
"build": "bun build src/bin.ts --compile --outfile build/use-agently",
21+
"build": "bun build src/bin.ts --target node --outfile build/bin.js",
2222
"clean": "rm -rf build",
2323
"dev": "bun run src/bin.ts",
2424
"lint": "eslint"

packages/use-agently/src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bun
1+
#!/usr/bin/env node
22

33
import { cli } from "./cli";
44

packages/use-agently/src/config.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { homedir } from "node:os";
22
import { join } from "node:path";
3-
import { mkdir, rename } from "node:fs/promises";
3+
import { mkdir, rename, readFile, writeFile } from "node:fs/promises";
44

55
const CONFIG_DIR = join(homedir(), ".use-agently");
66
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
@@ -15,16 +15,24 @@ export interface Config {
1515
}
1616

1717
export async function loadConfig(): Promise<Config | undefined> {
18-
const file = Bun.file(CONFIG_PATH);
19-
if (!(await file.exists())) {
18+
let contents: string;
19+
try {
20+
contents = await readFile(CONFIG_PATH, "utf8");
21+
} catch {
2022
return undefined;
2123
}
22-
return (await file.json()) as Promise<Config>;
24+
try {
25+
return JSON.parse(contents) as Config;
26+
} catch {
27+
throw new Error(
28+
`Config file at ${CONFIG_PATH} contains invalid JSON. Please fix or delete it and run \`use-agently init\`.`,
29+
);
30+
}
2331
}
2432

2533
export async function saveConfig(config: Config): Promise<void> {
2634
await mkdir(CONFIG_DIR, { recursive: true });
27-
await Bun.write(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n");
35+
await writeFile(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n", "utf8");
2836
}
2937

3038
export async function backupConfig(): Promise<string> {

0 commit comments

Comments
 (0)