Skip to content

Commit

Permalink
Add dotenv package to cli-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
aswamy committed Feb 27, 2024
1 parent f9ff722 commit a9f3e00
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-beans-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': minor
---

Support parsing multiline environment variables in .env file
1 change: 1 addition & 0 deletions packages/cli-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"cross-zip": "4.0.0",
"deepmerge": "4.3.1",
"del": "6.1.1",
"dotenv": "^16.4.5",
"env-paths": "3.0.0",
"envfile": "6.18.0",
"execa": "7.2.0",
Expand Down
16 changes: 16 additions & 0 deletions packages/cli-kit/src/public/node/dot-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ describe('readAndParseDotEnv', () => {
expect(got.variables.FOO).toEqual('BAR')
})
})

test('ensures newline characters are parsed from .env file', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Given
const dotEnvPath = joinPath(tmpDir, '.env')

await writeFile(dotEnvPath, `FOO="BAR\nBAR\nBAR"`)

// When
const got = await readAndParseDotEnv(dotEnvPath)

// Then
expect(got.path).toEqual(dotEnvPath)
expect(got.variables.MOO).toEqual('BAR\nBAR\nBAR')
})
})
})

describe('writeDotEnv', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli-kit/src/public/node/dot-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {fileExists, readFile, writeFile} from './fs.js'
import {outputDebug, outputContent, outputToken} from '../../public/node/output.js'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {parse, stringify} from 'envfile'
import {stringify} from 'envfile'
import * as dotenv from 'dotenv'

/**
* This interface represents a .env file.
Expand Down Expand Up @@ -32,7 +33,7 @@ export async function readAndParseDotEnv(path: string): Promise<DotEnvFile> {
const content = await readFile(path)
return {
path,
variables: parse(content),
variables: dotenv.parse(content),
}
}

Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9f3e00

Please sign in to comment.