Skip to content

feat: expose dotenv API#1032

Merged
antongolub merged 16 commits intogoogle:mainfrom
antongolub:dotenv-multiline
Dec 30, 2024
Merged

feat: expose dotenv API#1032
antongolub merged 16 commits intogoogle:mainfrom
antongolub:dotenv-multiline

Conversation

@antongolub
Copy link
Copy Markdown
Collaborator

@antongolub antongolub commented Dec 24, 2024

continues #974
relates #461

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
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

I’m against adding support for this feature.

@antongolub
Copy link
Copy Markdown
Collaborator Author

antongolub commented Dec 25, 2024

export { default as chalk, type ChalkInstance } from 'chalk'
export { default as which } from 'which'
export { default as ps } from '@webpod/ps'
export { parse as parseDotenv } from 'envapi'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, нou've put it in a separate package :)

@antongolub antongolub changed the title feat: handle multilines in env files feat: expose dotenv API Dec 30, 2024
@antongolub antongolub merged commit 109205b into google:main Dec 30, 2024
@antongolub antongolub deleted the dotenv-multiline branch December 30, 2024 09:53
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