Skip to content

Commit 4c272e4

Browse files
committed
Remove one extra dependency
1 parent 36de0fd commit 4c272e4

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

options-loader/index.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dotenv from 'dotenv'
1+
import { existsSync, readFileSync } from 'fs'
22
import pico from 'picocolors'
33

44
export function loadOptions(spec, process, env) {
@@ -18,7 +18,7 @@ export function loadOptions(spec, process, env) {
1818
}
1919

2020
let cliArgs = parseValues(spec, mapArgs(rawCliArgs, namesMap))
21-
let dotenvArgs = parseEnvArgs(env)
21+
let dotenvArgs = loadEnv(env)
2222
if (dotenvArgs) {
2323
dotenvArgs = Object.fromEntries(
2424
Object.entries(dotenvArgs).filter(([key]) =>
@@ -81,8 +81,23 @@ function parseValues(spec, args) {
8181
return parsed
8282
}
8383

84-
function parseEnvArgs(file) {
85-
return dotenv.config(file).parsed
84+
function loadEnv(file) {
85+
if (!file || !existsSync(file)) return undefined
86+
try {
87+
let lines = readFileSync(filePath, 'utf8').split('\n')
88+
for (let line of lines) {
89+
if (line.trim().startsWith('#') || !line.includes('=')) {
90+
continue
91+
}
92+
const [key, ...valueParts] = line.split('=')
93+
const value = valueParts
94+
.join('=')
95+
.trim()
96+
.replace(/(^"|"$|^'|'$)/g, '')
97+
}
98+
} catch (error) {
99+
return undefined
100+
}
86101
}
87102

88103
function mapArgs(parsedCliArgs, argsSpec) {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@logux/actions": "^0.4.0",
3636
"@logux/core": "^0.9.0",
3737
"cookie": "^1.0.2",
38-
"dotenv": "^17.2.0",
3938
"fastq": "^1.19.1",
4039
"nanoevents": "^9.1.0",
4140
"nanoid": "^5.1.5",

pnpm-lock.yaml

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

server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class Server extends BaseServer {
9797
let [help, options] = loadOptions(
9898
cliOptionsSpec,
9999
process,
100-
defaults.root ? { path: join(defaults.root, '.env') } : undefined
100+
defaults.root ? join(defaults.root, '.env') : undefined
101101
)
102102
if (help) {
103103
process.stdout.write(help + '\n')

0 commit comments

Comments
 (0)