Skip to content

Commit f0a1483

Browse files
committed
feat: reexport envapi
1 parent 94356b5 commit f0a1483

14 files changed

+25
-48
lines changed

.size-limit.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
{
2424
"name": "vendor",
2525
"path": "build/vendor-*",
26-
"limit": "762 kB",
26+
"limit": "763 kB",
2727
"brotli": false,
2828
"gzip": false
2929
},
3030
{
3131
"name": "all",
3232
"path": "build/*",
33-
"limit": "843 kB",
33+
"limit": "844 kB",
3434
"brotli": false,
3535
"gzip": false
3636
}

docs/api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ console.log(YAML.parse('foo: bar').foo)
366366
```
367367

368368
## dotenv
369-
[dotenv](https://www.npmjs.com/package/dotenv)-like environment variables loading API
369+
The [envapi](https://www.npmjs.com/package/envapi) package.
370+
An API to interact with environment vars in [dotenv](https://www.npmjs.com/package/dotenv) format.
370371

371372
```js
372373
// parse

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"create-require": "^1.1.1",
109109
"depseek": "^0.4.1",
110110
"dts-bundle-generator": "^9.5.1",
111-
"envapi": "^0.0.0",
111+
"envapi": "^0.1.0",
112112
"esbuild": "^0.24.2",
113113
"esbuild-node-externals": "^1.16.0",
114114
"esbuild-plugin-entry-chunks": "^0.1.15",

scripts/build-dts.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const entries = [
4545
// '@webpod/ps',
4646
'@webpod/ingrid',
4747
'depseek',
48+
'envapi',
4849
], // args['external-inlines'],
4950
},
5051
output,
@@ -60,7 +61,6 @@ const entries = [
6061
'@webpod/ingrid',
6162
'chalk',
6263
'zurk',
63-
'envapi',
6464
], // args['external-inlines'],
6565
},
6666
output,

scripts/build-tests.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const modules = [
2626
['core', core],
2727
['cli', cli],
2828
['index', index],
29-
['vendor', vendor, ['chalk', 'depseek', 'fs', 'glob', 'minimist', 'ps', 'which', 'YAML',]],
29+
['vendor', vendor, ['chalk', 'depseek', 'dotenv', 'fs', 'glob', 'minimist', 'ps', 'which', 'YAML',]],
3030
]
3131
const root = path.resolve(new URL(import.meta.url).pathname, '../..')
3232
const filePath = path.resolve(root, `test/export.test.js`)

src/goods.ts

-34
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
fs,
2929
minimist,
3030
nodeFetch,
31-
parseDotenv,
3231
type RequestInfo,
3332
type RequestInit,
3433
} from './vendor.js'
@@ -220,36 +219,3 @@ export async function spinner<T>(
220219
}
221220
})
222221
}
223-
224-
/**
225-
* Read env files and collects it into environment variables
226-
*/
227-
export const dotenv = (() => {
228-
const parse = parseDotenv
229-
230-
const _load = (
231-
read: (file: string) => string,
232-
...files: string[]
233-
): NodeJS.ProcessEnv =>
234-
files
235-
.reverse()
236-
.reduce((m, f) => Object.assign(m, parse(read(path.resolve(f)))), {})
237-
const load = (...files: string[]): NodeJS.ProcessEnv =>
238-
_load((file) => fs.readFileSync(file, 'utf8'), ...files)
239-
const loadSafe = (...files: string[]): NodeJS.ProcessEnv =>
240-
_load(
241-
(file: string): string =>
242-
fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '',
243-
...files
244-
)
245-
246-
const config = (def = '.env', ...files: string[]): NodeJS.ProcessEnv =>
247-
Object.assign(process.env, loadSafe(def, ...files))
248-
249-
return {
250-
parse,
251-
load,
252-
loadSafe,
253-
config,
254-
}
255-
})()

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from './goods.js'
2020
export {
2121
minimist,
2222
chalk,
23+
dotenv,
2324
fs,
2425
which,
2526
YAML,

src/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fs from 'node:fs'
1818
import { chalk, type RequestInfo, type RequestInit } from './vendor-core.js'
1919
import { inspect } from 'node:util'
2020

21-
export { isStringLiteral, parseDotenv } from './vendor-core.js'
21+
export { isStringLiteral } from './vendor-core.js'
2222

2323
export function tempdir(prefix: string = `zx-${randomId()}`): string {
2424
const dirpath = path.join(os.tmpdir(), prefix)

src/vendor-core.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ export type RequestInit = Parameters<typeof globalThis.fetch>[1]
2626
export { default as chalk, type ChalkInstance } from 'chalk'
2727
export { default as which } from 'which'
2828
export { default as ps } from '@webpod/ps'
29-
export { parse as parseDotenv } from 'envapi'

src/vendor-extra.ts

+1
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ export const fs: typeof import('fs-extra') = _fs
116116

117117
export { depseekSync as depseek } from 'depseek'
118118
export { default as minimist } from 'minimist'
119+
export { default as dotenv } from 'envapi'

test/export.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ describe('index', () => {
159159
assert.equal(typeof index.dotenv.load, 'function', 'index.dotenv.load')
160160
assert.equal(typeof index.dotenv.loadSafe, 'function', 'index.dotenv.loadSafe')
161161
assert.equal(typeof index.dotenv.parse, 'function', 'index.dotenv.parse')
162+
assert.equal(typeof index.dotenv.stringify, 'function', 'index.dotenv.stringify')
162163
assert.equal(typeof index.echo, 'function', 'index.echo')
163164
assert.equal(typeof index.expBackoff, 'function', 'index.expBackoff')
164165
assert.equal(typeof index.fetch, 'function', 'index.fetch')
@@ -420,6 +421,12 @@ describe('vendor', () => {
420421
assert.equal(typeof vendor.chalk, 'function', 'vendor.chalk')
421422
assert.equal(typeof vendor.chalk.level, 'number', 'vendor.chalk.level')
422423
assert.equal(typeof vendor.depseek, 'function', 'vendor.depseek')
424+
assert.equal(typeof vendor.dotenv, 'object', 'vendor.dotenv')
425+
assert.equal(typeof vendor.dotenv.config, 'function', 'vendor.dotenv.config')
426+
assert.equal(typeof vendor.dotenv.load, 'function', 'vendor.dotenv.load')
427+
assert.equal(typeof vendor.dotenv.loadSafe, 'function', 'vendor.dotenv.loadSafe')
428+
assert.equal(typeof vendor.dotenv.parse, 'function', 'vendor.dotenv.parse')
429+
assert.equal(typeof vendor.dotenv.stringify, 'function', 'vendor.dotenv.stringify')
423430
assert.equal(typeof vendor.fs, 'object', 'vendor.fs')
424431
assert.equal(typeof vendor.fs.Dir, 'function', 'vendor.fs.Dir')
425432
assert.equal(typeof vendor.fs.Dirent, 'function', 'vendor.fs.Dirent')

test/goods.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import assert from 'node:assert'
1616
import { test, describe, after } from 'node:test'
17-
import { $, chalk, fs, tempfile } from '../build/index.js'
18-
import { echo, sleep, parseArgv, dotenv } from '../build/goods.js'
17+
import { $, chalk, fs, tempfile, dotenv } from '../build/index.js'
18+
import { echo, sleep, parseArgv } from '../build/goods.js'
1919

2020
describe('goods', () => {
2121
function zx(script) {

test/index.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ProcessOutput,
3131
ProcessPromise,
3232
defaults,
33+
dotenv,
3334
minimist,
3435
chalk,
3536
fs,
@@ -106,6 +107,7 @@ describe('index', () => {
106107
assert(which)
107108
assert(YAML)
108109
assert(ps)
110+
assert(dotenv)
109111

110112
// utils
111113
assert(quote)

0 commit comments

Comments
 (0)