Skip to content

Commit 94356b5

Browse files
committed
chore: rebase
1 parent 24441a6 commit 94356b5

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/goods.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
fs,
2929
minimist,
3030
nodeFetch,
31+
parseDotenv,
3132
type RequestInfo,
3233
type RequestInit,
3334
} from './vendor.js'
@@ -224,18 +225,7 @@ export async function spinner<T>(
224225
* Read env files and collects it into environment variables
225226
*/
226227
export const dotenv = (() => {
227-
const parse = (content: string | Buffer): NodeJS.ProcessEnv =>
228-
content
229-
.toString()
230-
.split(/\r?\n/)
231-
.reduce<NodeJS.ProcessEnv>((r, line) => {
232-
if (line.startsWith('export ')) line = line.slice(7)
233-
const i = line.indexOf('=')
234-
const k = line.slice(0, i).trim()
235-
const v = line.slice(i + 1).trim()
236-
if (k && v) r[k] = v
237-
return r
238-
}, {})
228+
const parse = parseDotenv
239229

240230
const _load = (
241231
read: (file: string) => string,

src/util.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
import os from 'node:os'
1616
import path from 'node:path'
1717
import fs from 'node:fs'
18-
import {
19-
chalk,
20-
type RequestInfo,
21-
type RequestInit,
22-
parseDotenv,
23-
} from './vendor-core.js'
18+
import { chalk, type RequestInfo, type RequestInit } from './vendor-core.js'
2419
import { inspect } from 'node:util'
2520

2621
export { isStringLiteral, parseDotenv } from './vendor-core.js'
@@ -362,4 +357,3 @@ export const toCamelCase = (str: string) =>
362357

363358
export const parseBool = (v: string): boolean | string =>
364359
({ true: true, false: false })[v] ?? v
365-

test/goods.test.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe('goods', () => {
176176

177177
describe('dotenv', () => {
178178
test('parse()', () => {
179+
assert.deepEqual(dotenv.parse(''), {})
179180
assert.deepEqual(
180181
dotenv.parse('ENV=v1\nENV2=v2\n\n\n ENV3 = v3 \nexport ENV4=v4'),
181182
{
@@ -185,15 +186,27 @@ describe('goods', () => {
185186
ENV4: 'v4',
186187
}
187188
)
188-
assert.deepEqual(dotenv.parse(''), {})
189189

190-
// TBD: multiline
191190
const multiline = `SIMPLE=xyz123
192-
NON_INTERPOLATED='raw text without variable interpolation'
191+
# comment ###
192+
NON_INTERPOLATED='raw text without variable interpolation'
193193
MULTILINE = """
194-
long text here,
194+
long text here, # not-comment
195195
e.g. a private SSH key
196-
"""`
196+
"""
197+
ENV=v1\nENV2=v2\n\n\n\t\t ENV3 = v3 \n export ENV4=v4
198+
ENV5=v5 # comment
199+
`
200+
assert.deepEqual(dotenv.parse(multiline), {
201+
SIMPLE: 'xyz123',
202+
NON_INTERPOLATED: 'raw text without variable interpolation',
203+
MULTILINE: 'long text here, # not-comment\ne.g. a private SSH key',
204+
ENV: 'v1',
205+
ENV2: 'v2',
206+
ENV3: 'v3',
207+
ENV4: 'v4',
208+
ENV5: 'v5',
209+
})
197210
})
198211

199212
describe('load()', () => {

0 commit comments

Comments
 (0)