Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle multilines in env files #1032

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

antongolub
Copy link
Collaborator

@antongolub antongolub commented Dec 24, 2024

continues #974

const multiline = `SIMPLE=xyz123
NON_INTERPOLATED='raw text without variable interpolation'
MULTILINE = """
long text here,
e.g. a private SSH key
"""
ENV=v1\nENV2=v2\n\n\n  ENV3  =    v3   \n   export ENV4=v4
`

assert.deepEqual(parseDotenv(multiline), {
  SIMPLE: 'xyz123',
  NON_INTERPOLATED: 'raw text without variable interpolation',
  MULTILINE: '\nlong text here,\ne.g. a private SSH key\n',
  ENV: 'v1',
  ENV2: 'v2',
  ENV3: 'v3',
  ENV4: 'v4',
})

fyi, @1e9y , @easymikey

  • Tests pass
  • Appropriate changes to README are included in PR

@antongolub antongolub requested a review from antonmedv December 24, 2024 13:12
src/util.ts Outdated Show resolved Hide resolved
src/util.ts Outdated
Comment on lines 363 to 368
const kr = /^[a-zA-Z_]+\w*$/
const sr = /\s/
const e: Record<string, string> = {}
let k = ''
let b = ''
let q = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use more readable variable names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minification challenge without any special reason.

(s)pace(r)egex
(k)ey(r)egex

(e)nv
(k)ey
(b)uffer
(q)oute
(i)gnore
(c)har

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make it contributor-friendly and leave minification for Vite plugin!

@antongolub
Copy link
Collaborator Author

antongolub commented Dec 24, 2024

dotenv requires ~10Kb extra

image

cjs without treeshaking
https://github.com/motdotla/dotenv/blob/3ca0fd0c3005b5f92d69b6ff4661e722394c1ab7/lib/main.js#L12

@antonmedv
Copy link
Collaborator

I’m against adding support for this feature.

@antongolub
Copy link
Collaborator Author

antongolub commented Dec 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants