Commit 759dcf6 1 parent 36b42d8 commit 759dcf6 Copy full SHA for 759dcf6
File tree 3 files changed +26
-15
lines changed
3 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -119,17 +119,14 @@ zx --cwd=/foo/bar script.mjs
119
119
```
120
120
121
121
## --env
122
- Specify a env file.
122
+ Specify an env file.
123
123
124
124
``` bash
125
125
zx --env=/path/to/some.env script.mjs
126
126
```
127
127
128
- When cwd option is specified, it will used as base path: ` --cwd='/foo/bar' --env='../.env' ` → ` /foo/.env `
129
-
130
- ``` bash
131
- zx --cwd=/foo/bar --env=/path/to/some.env script.mjs
132
- ```
128
+ When ` cwd ` option is specified, it will be used as base path:
129
+ ` --cwd='/foo/bar' --env='../.env' ` → ` /foo/.env `
133
130
134
131
## --ext
135
132
Original file line number Diff line number Diff line change @@ -358,14 +358,15 @@ export const toCamelCase = (str: string) =>
358
358
export const parseBool = ( v : string ) : boolean | string =>
359
359
( { true : true , false : false } ) [ v ] ?? v
360
360
361
- export const parseDotenv = ( content : string ) : NodeJS . ProcessEnv => {
362
- return content . split ( / \r ? \n / ) . reduce < NodeJS . ProcessEnv > ( ( r , line ) => {
363
- const [ k ] = line . trim ( ) . split ( '=' , 1 )
364
- const v = line . trim ( ) . slice ( k . length + 1 )
361
+ export const parseDotenv = ( content : string ) : NodeJS . ProcessEnv =>
362
+ content . split ( / \r ? \n / ) . reduce < NodeJS . ProcessEnv > ( ( r , line ) => {
363
+ if ( line . startsWith ( 'export ' ) ) line = line . slice ( 7 )
364
+ const i = line . indexOf ( '=' )
365
+ const k = line . slice ( 0 , i ) . trim ( )
366
+ const v = line . slice ( i + 1 ) . trim ( )
365
367
if ( k && v ) r [ k ] = v
366
368
return r
367
369
} , { } )
368
- }
369
370
370
371
export const readEnvFromFile = (
371
372
filepath : string ,
Original file line number Diff line number Diff line change @@ -143,11 +143,24 @@ describe('util', () => {
143
143
} )
144
144
145
145
test ( 'parseDotenv()' , ( ) => {
146
- assert . deepEqual ( parseDotenv ( 'ENV=value1\nENV2=value24' ) , {
147
- ENV : 'value1' ,
148
- ENV2 : 'value24' ,
149
- } )
146
+ assert . deepEqual (
147
+ parseDotenv ( 'ENV=v1\nENV2=v2\n\n\n ENV3 = v3 \nexport ENV4=v4' ) ,
148
+ {
149
+ ENV : 'v1' ,
150
+ ENV2 : 'v2' ,
151
+ ENV3 : 'v3' ,
152
+ ENV4 : 'v4' ,
153
+ }
154
+ )
150
155
assert . deepEqual ( parseDotenv ( '' ) , { } )
156
+
157
+ // TBD: multiline
158
+ const multiline = `SIMPLE=xyz123
159
+ NON_INTERPOLATED='raw text without variable interpolation'
160
+ MULTILINE = """
161
+ long text here,
162
+ e.g. a private SSH key
163
+ """`
151
164
} )
152
165
153
166
describe ( 'readEnvFromFile()' , ( ) => {
You can’t perform that action at this time.
0 commit comments