Commit 94356b5 1 parent 24441a6 commit 94356b5 Copy full SHA for 94356b5
File tree 3 files changed +21
-24
lines changed
3 files changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import {
28
28
fs ,
29
29
minimist ,
30
30
nodeFetch ,
31
+ parseDotenv ,
31
32
type RequestInfo ,
32
33
type RequestInit ,
33
34
} from './vendor.js'
@@ -224,18 +225,7 @@ export async function spinner<T>(
224
225
* Read env files and collects it into environment variables
225
226
*/
226
227
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
239
229
240
230
const _load = (
241
231
read : ( file : string ) => string ,
Original file line number Diff line number Diff line change 15
15
import os from 'node:os'
16
16
import path from 'node:path'
17
17
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'
24
19
import { inspect } from 'node:util'
25
20
26
21
export { isStringLiteral , parseDotenv } from './vendor-core.js'
@@ -362,4 +357,3 @@ export const toCamelCase = (str: string) =>
362
357
363
358
export const parseBool = ( v : string ) : boolean | string =>
364
359
( { true : true , false : false } ) [ v ] ?? v
365
-
Original file line number Diff line number Diff line change @@ -176,6 +176,7 @@ describe('goods', () => {
176
176
177
177
describe ( 'dotenv' , ( ) => {
178
178
test ( 'parse()' , ( ) => {
179
+ assert . deepEqual ( dotenv . parse ( '' ) , { } )
179
180
assert . deepEqual (
180
181
dotenv . parse ( 'ENV=v1\nENV2=v2\n\n\n ENV3 = v3 \nexport ENV4=v4' ) ,
181
182
{
@@ -185,15 +186,27 @@ describe('goods', () => {
185
186
ENV4 : 'v4' ,
186
187
}
187
188
)
188
- assert . deepEqual ( dotenv . parse ( '' ) , { } )
189
189
190
- // TBD: multiline
191
190
const multiline = `SIMPLE=xyz123
192
- NON_INTERPOLATED='raw text without variable interpolation'
191
+ # comment ###
192
+ NON_INTERPOLATED='raw text without variable interpolation'
193
193
MULTILINE = """
194
- long text here,
194
+ long text here, # not-comment
195
195
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
+ } )
197
210
} )
198
211
199
212
describe ( 'load()' , ( ) => {
You can’t perform that action at this time.
0 commit comments