Skip to content

Commit 2476d1d

Browse files
Copilotnzakas
andauthored
fix: Drop dotenv package and use native process.loadEnvFile (#152)
* Initial plan * Replace dotenv with native process.loadEnvFile Co-authored-by: nzakas <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: nzakas <[email protected]>
1 parent 5ef5ed7 commit 2476d1d

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Claude will then create a `claude_desktop_config.json` file. Open it and add the
295295

296296
This example enables Mastodon and LinkedIn so the `env` key contains the environment variables necessary to post to those services. You can customize the services by passing different command line arguments as you would using the CLI.
297297

298-
If you'd prefer not to put your environment variables directly into the JSON file, you can create a [`.env` file](https://www.npmjs.com/package/dotenv) and use the `CROSSPOST_DOTENV` environment variable to point to it:
298+
If you'd prefer not to put your environment variables directly into the JSON file, you can create a `.env` file and use the `CROSSPOST_DOTENV` environment variable to point to it:
299299

300300
```json
301301
{

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
"@modelcontextprotocol/sdk": "^1.8.0",
9898
"@noble/secp256k1": "^3.0.0",
9999
"bech32": "^2.0.0",
100-
"dotenv": "^16.6.1",
101100
"tlds": "^1.255.0",
102101
"twitter-api-v2": "^1.20.2",
103102
"zod": "^3.24.2"

src/bin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import fs from "node:fs";
1212
import { parseArgs } from "node:util";
13-
import * as dotenv from "dotenv";
1413
import { Env } from "@humanwhocodes/env";
1514
import {
1615
Client,
@@ -134,10 +133,16 @@ if (
134133
// load environment variables from .env file if present
135134
if (process.env.CROSSPOST_DOTENV) {
136135
const filePath =
137-
process.env.CROSSPOST_DOTENV === "1"
138-
? undefined
139-
: process.env.CROSSPOST_DOTENV;
140-
dotenv.config({ path: filePath });
136+
process.env.CROSSPOST_DOTENV === "1" ? ".env" : process.env.CROSSPOST_DOTENV;
137+
try {
138+
process.loadEnvFile(filePath);
139+
} catch (err) {
140+
// Ignore if file doesn't exist, similar to dotenv behavior
141+
const error = /** @type {NodeJS.ErrnoException} */ (err);
142+
if (error.code !== "ENOENT") {
143+
throw error;
144+
}
145+
}
141146
}
142147

143148
const env = new Env();

0 commit comments

Comments
 (0)