@dotenvx/dotenvx 0.4.0 → 0.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs ADDED
@@ -0,0 +1,141 @@
1
+ const path = require('node:path')
2
+ const { fileURLToPath } = require('node:url')
3
+ const native = require('./native.cjs')
4
+ const { applyRedaction } = require('./lib/redaction.cjs')
5
+ const { validateOptions } = require('./lib/validateOptions.cjs')
6
+ const { resolveCli } = require('./lib/cli.cjs')
7
+
8
+ function environment (value) {
9
+ const result = Object.create(null)
10
+ for (const [key, item] of Object.entries(value)) {
11
+ if (item !== undefined && item !== null) result[key] = String(item)
12
+ }
13
+ return result
14
+ }
15
+
16
+ function filePath (value) {
17
+ if (value instanceof URL) return fileURLToPath(value)
18
+ if (typeof value !== 'string') throw new TypeError('dotenvx paths must be strings or file URLs')
19
+ return value
20
+ }
21
+
22
+ function optionsFor (options = {}, method = 'config') {
23
+ validateOptions(options, method)
24
+ const target = options.processEnv ?? process.env
25
+ if (!target || typeof target !== 'object' || Array.isArray(target)) throw new TypeError('processEnv must be an object')
26
+ const env = environment(target)
27
+ if (options.noArmor === true) env.DOTENVX_NO_ARMOR = 'true'
28
+ if (options.noNative === true) env.DOTENVX_NO_NATIVE = 'true'
29
+ if (options.no1Password === true) env.DOTENVX_NO_1PASSWORD = 'true'
30
+ if (options.noBitwarden === true) env.DOTENVX_NO_BITWARDEN = 'true'
31
+ if (options.token !== undefined) env.DOTENVX_ARMOR_TOKEN = String(options.token)
32
+ let sources = []
33
+ let implicit = true
34
+ const configuredPath = options.path ?? (!env.DOTENV_FILE && !env.DOTENV_PATH ? env.DOTENV_CONFIG_PATH : undefined)
35
+ if (options.envs !== undefined) {
36
+ if (!Array.isArray(options.envs)) throw new TypeError('envs must be an array')
37
+ implicit = false
38
+ sources = options.envs.map(source => {
39
+ if (source.type === 'envFile') return { type: 'file', value: filePath(source.value) }
40
+ if (source.type === 'env' && (typeof source.value === 'string' || Buffer.isBuffer(source.value))) return { type: 'inline', value: source.value.toString() }
41
+ throw new TypeError('envs must contain envFile paths or env strings/Buffers')
42
+ })
43
+ } else if (configuredPath !== undefined) {
44
+ implicit = false
45
+ sources = (Array.isArray(configuredPath) ? configuredPath : [configuredPath]).map(value => ({ type: 'file', value: filePath(value) }))
46
+ }
47
+ const keyFiles = options.envKeysFile ?? options.keyFiles
48
+ const input = {
49
+ cwd: path.resolve(options.cwd || process.cwd()),
50
+ process_env: env,
51
+ sources,
52
+ implicit_files: implicit,
53
+ overload: options.overload ?? options.override ?? env.DOTENV_CONFIG_OVERRIDE === 'true',
54
+ strict: options.strict ?? false,
55
+ ignore: typeof options.ignore === 'string' ? options.ignore.split(',') : options.ignore || [],
56
+ convention: options.convention,
57
+ environment_name: options.environment,
58
+ resolve_references: options.resolveReferences ?? false,
59
+ no_1password: options.no1Password === true,
60
+ no_bitwarden: options.noBitwarden === true
61
+ }
62
+ if (keyFiles !== undefined) input.key_files = (Array.isArray(keyFiles) ? keyFiles : [keyFiles]).map(filePath)
63
+ if (method !== 'parse') input.custody_cli = resolveCli({ env })
64
+ return { input, options, target, env }
65
+ }
66
+
67
+ function diagnosticError (diagnostic) {
68
+ const error = new Error(diagnostic.message)
69
+ error.code = diagnostic.code
70
+ if (diagnostic.path) error.path = diagnostic.path
71
+ return error
72
+ }
73
+
74
+ function report (loaded, prepared, summary = false) {
75
+ applyRedaction(loaded.secrets || [])
76
+ const { options, env } = prepared
77
+ const silent = options.logLevel === 'silent'
78
+ const quiet = options.quiet === true || (env.DOTENV_QUIET ?? env.DOTENV_CONFIG_QUIET) === 'true'
79
+ for (const diagnostic of loaded.diagnostics) {
80
+ if (!silent) process.stderr.write(`☠ ${diagnostic.message}\n`)
81
+ }
82
+ const error = loaded.diagnostics.length ? diagnosticError(loaded.diagnostics.at(-1)) : undefined
83
+ if (loaded.fatal) throw error || new Error('dotenvx loading failed')
84
+ if (summary && !quiet && !silent && !['error', 'warn'].includes(options.logLevel) && !loaded.error_count && loaded.files.length) {
85
+ process.stderr.write(`${loaded.inject_summary}\n`)
86
+ }
87
+ return error
88
+ }
89
+
90
+ function config (options = {}) {
91
+ const prepared = optionsFor(options, 'config')
92
+ const loaded = JSON.parse(native.loadEnvSync(JSON.stringify(prepared.input)))
93
+ const error = report(loaded, prepared, true)
94
+ for (const [key, value] of Object.entries(loaded.injected)) {
95
+ Object.defineProperty(prepared.target, key, { value, configurable: true, enumerable: true, writable: true })
96
+ }
97
+ return error ? { parsed: loaded.values, error } : { parsed: loaded.values }
98
+ }
99
+
100
+ function parse (source, options = {}) {
101
+ if (typeof source !== 'string' && !Buffer.isBuffer(source)) throw new TypeError('source must be a string or Buffer')
102
+ const prepared = optionsFor(options, 'parse')
103
+ const result = JSON.parse(native.parseEnv(source.toString(), JSON.stringify({
104
+ process_env: prepared.input.process_env,
105
+ private_key: options.privateKey,
106
+ overload: prepared.input.overload
107
+ })))
108
+ const ignored = new Set(prepared.input.ignore)
109
+ result.diagnostics = result.diagnostics.filter(error => !ignored.has(error.code))
110
+ report({ ...result, fatal: options.strict === true && result.diagnostics.length > 0 }, prepared)
111
+ return result.parsed
112
+ }
113
+
114
+ function getResult (key, loaded, prepared) {
115
+ report(loaded, prepared)
116
+ const values = prepared.options.all ? loaded.environment : loaded.values
117
+ if (key !== undefined) return Object.hasOwn(values, key) ? values[key] : undefined
118
+ const format = prepared.options.format
119
+ if (!format) return values
120
+ if (!['eval', 'eval-export', 'shell', 'colon'].includes(format)) throw new TypeError(`Unknown dotenvx output format: ${format}`)
121
+ const quote = value => `'${value.replaceAll("'", "'\\''")}'`
122
+ return Object.keys(values).sort().map(name => {
123
+ if (format === 'eval' || format === 'eval-export') {
124
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new TypeError(`Cannot export invalid shell variable name: ${name}`)
125
+ return `${format === 'eval-export' ? 'export ' : ''}${name}=${quote(values[name])}`
126
+ }
127
+ if (format === 'shell') return `${name}=${values[name]}`
128
+ if (format === 'colon') return `${name}:${values[name]}`
129
+ throw new TypeError(`Unknown dotenvx output format: ${format}`)
130
+ }).join(format === 'eval' || format === 'eval-export' ? '\n' : ' ')
131
+ }
132
+
133
+ function get (key, options = {}) {
134
+ if (key !== undefined && typeof key !== 'string') throw new TypeError('key must be a string')
135
+ const prepared = optionsFor(options, 'get')
136
+ return getResult(key, JSON.parse(native.loadEnvSync(JSON.stringify(prepared.input))), prepared)
137
+ }
138
+
139
+ const getSync = get
140
+
141
+ module.exports = { config, parse, get, getSync }
package/index.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ export type Environment = Record<string, string | undefined>;
2
+ export type Values = Record<string, string>;
3
+ export type EnvSource = { type: 'envFile'; value: string | URL } | { type: 'env'; value: string | Buffer };
4
+
5
+ export interface ConfigOptions {
6
+ path?: string | URL | Array<string | URL>;
7
+ envs?: EnvSource[];
8
+ cwd?: string;
9
+ processEnv?: Environment;
10
+ overload?: boolean;
11
+ override?: boolean;
12
+ strict?: boolean;
13
+ ignore?: string | string[];
14
+ envKeysFile?: string | URL | Array<string | URL>;
15
+ keyFiles?: string | URL | Array<string | URL>;
16
+ convention?: 'nextjs' | 'flow' | 'rails';
17
+ environment?: string;
18
+ encoding?: 'utf8' | 'utf-8';
19
+ quiet?: boolean;
20
+ logLevel?: 'error' | 'warn' | 'info' | 'silent';
21
+ resolveReferences?: boolean;
22
+ no1Password?: boolean;
23
+ noBitwarden?: boolean;
24
+ noArmor?: boolean;
25
+ noNative?: boolean;
26
+ token?: string;
27
+ }
28
+
29
+ export interface ParseOptions {
30
+ processEnv?: Environment;
31
+ privateKey?: string;
32
+ overload?: boolean;
33
+ override?: boolean;
34
+ strict?: boolean;
35
+ ignore?: string | string[];
36
+ logLevel?: ConfigOptions['logLevel'];
37
+ }
38
+
39
+ export interface GetOptions extends ConfigOptions {
40
+ all?: boolean;
41
+ format?: 'eval' | 'eval-export' | 'shell' | 'colon';
42
+ }
43
+
44
+ export interface DotenvError extends Error {
45
+ code: string;
46
+ path?: string;
47
+ }
48
+
49
+ export interface ConfigResult {
50
+ parsed: Values;
51
+ error?: DotenvError;
52
+ }
53
+
54
+ /** Resolve synchronously and populate process.env (or processEnv). Fatal errors throw before injection. */
55
+ export function config(options?: ConfigOptions): ConfigResult;
56
+ /** Parse/expand/decrypt a string or Buffer without reading files or mutating the environment. */
57
+ export function parse(source: string | Buffer, options?: ParseOptions): Values;
58
+ /** Resolve synchronously without mutating the environment. Blocks during file and custody lookups; failures throw synchronously. */
59
+ export function get(key: string, options?: GetOptions): string | undefined;
60
+ export function get(key?: undefined, options?: GetOptions & { format?: undefined }): Values;
61
+ export function get(key: undefined, options: GetOptions & { format: NonNullable<GetOptions['format']> }): string;
62
+ /** Alias of get; getSync === get. */
63
+ export const getSync: typeof get;
64
+
65
+ declare const dotenvx: { config: typeof config; parse: typeof parse; get: typeof get; getSync: typeof getSync };
66
+ export default dotenvx;
package/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import sdk from './index.cjs'
2
+ export const { config, parse, get, getSync } = sdk
3
+ export default sdk
package/lib/cli.cjs ADDED
@@ -0,0 +1,43 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { resolveNativeFile } = require('./native-package.cjs')
4
+
5
+ // Only standalone executables qualify. npm shims (including older dotenvx
6
+ // JavaScript CLIs) must not call another shim and recurse through PATH.
7
+ const nativeHeaders = new Set([
8
+ '7f454c46', // ELF
9
+ 'feedface', 'cefaedfe', 'feedfacf', 'cffaedfe', // Mach-O
10
+ 'cafebabe', 'bebafeca', 'cafebabf', 'bfbafeca' // Universal Mach-O
11
+ ])
12
+
13
+ function isStandalone (file) {
14
+ let fd
15
+ try {
16
+ fs.accessSync(file, fs.constants.X_OK)
17
+ if (!fs.statSync(file).isFile()) return false
18
+ fd = fs.openSync(file, 'r')
19
+ const header = Buffer.alloc(4)
20
+ if (fs.readSync(fd, header, 0, 4, 0) !== 4) return false
21
+ return header.subarray(0, 2).toString('hex') === '4d5a' || nativeHeaders.has(header.toString('hex'))
22
+ } catch {
23
+ return false
24
+ } finally {
25
+ if (fd !== undefined) fs.closeSync(fd)
26
+ }
27
+ }
28
+
29
+ function resolveCli ({ env = process.env, platform = process.platform, arch = process.arch, libc, root = path.resolve(__dirname, '..') } = {}) {
30
+ if (env.DOTENVX_CLI) return path.resolve(env.DOTENVX_CLI)
31
+ const searchPath = Object.entries(env).find(([key]) => platform === 'win32' ? key.toLowerCase() === 'path' : key === 'PATH')?.[1] || ''
32
+ const executable = platform === 'win32' ? 'dotenvx.exe' : 'dotenvx'
33
+ for (const directory of searchPath.split(platform === 'win32' ? ';' : ':')) {
34
+ if (!directory) continue
35
+ const candidate = path.resolve(directory, executable)
36
+ if (isStandalone(candidate)) return candidate
37
+ }
38
+
39
+ if (libc === undefined) libc = platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? '-gnu' : '-musl') : ''
40
+ return resolveNativeFile(executable, { platform: `${platform}-${arch}${libc}`, root })
41
+ }
42
+
43
+ module.exports = { resolveCli }
@@ -0,0 +1,21 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { createRequire } = require('node:module')
4
+ const { platforms, currentPlatform } = require('./platforms.cjs')
5
+
6
+ function resolveNativeFile (file, { platform = currentPlatform(), root = path.resolve(__dirname, '..') } = {}) {
7
+ const entry = platforms[platform]
8
+ if (!entry) throw new Error(`@dotenvx/dotenvx has no native package for ${platform}`)
9
+ const fromPackage = createRequire(path.join(root, 'package.json'))
10
+ try {
11
+ return fromPackage.resolve(`${entry.name}/${file}`)
12
+ } catch (cause) {
13
+ if (cause.code !== 'MODULE_NOT_FOUND') throw cause
14
+ // Local Forge builds work before platform packages have been published.
15
+ const local = path.join(root, 'native', file === 'dotenvx.node' ? `dotenvx-${platform}.node` : `dotenvx-cli-${platform}${file.endsWith('.exe') ? '.exe' : ''}`)
16
+ if (fs.existsSync(local)) return local
17
+ throw new Error(`Missing ${entry.name} for ${platform}. Reinstall @dotenvx/dotenvx with optional dependencies enabled (npm install --include=optional). In Forge, run npm run build:dotenvx-nodejs.`, { cause })
18
+ }
19
+ }
20
+
21
+ module.exports = { resolveNativeFile }
@@ -0,0 +1,18 @@
1
+ // Keep published names compatible with the existing standalone binary packages.
2
+ const platforms = {
3
+ 'darwin-arm64': { name: '@dotenvx/dotenvx-darwin-arm64', os: 'darwin', cpu: 'arm64', target: 'aarch64-apple-darwin', runner: 'macos-15' },
4
+ 'darwin-x64': { name: '@dotenvx/dotenvx-darwin-x86_64', os: 'darwin', cpu: 'x64', target: 'x86_64-apple-darwin', runner: 'macos-15-intel' },
5
+ 'linux-x64-gnu': { name: '@dotenvx/dotenvx-linux-x86_64', os: 'linux', cpu: 'x64', libc: 'glibc', target: 'x86_64-unknown-linux-gnu', runner: 'ubuntu-24.04', container: 'quay.io/pypa/manylinux_2_28_x86_64' },
6
+ 'linux-arm64-gnu': { name: '@dotenvx/dotenvx-linux-arm64', os: 'linux', cpu: 'arm64', libc: 'glibc', target: 'aarch64-unknown-linux-gnu', runner: 'ubuntu-24.04-arm', container: 'quay.io/pypa/manylinux_2_28_aarch64' },
7
+ 'linux-x64-musl': { name: '@dotenvx/dotenvx-linux-x86_64-musl', os: 'linux', cpu: 'x64', libc: 'musl', target: 'x86_64-unknown-linux-musl', runner: 'ubuntu-24.04', container: 'node:24-alpine' },
8
+ 'linux-arm64-musl': { name: '@dotenvx/dotenvx-linux-arm64-musl', os: 'linux', cpu: 'arm64', libc: 'musl', target: 'aarch64-unknown-linux-musl', runner: 'ubuntu-24.04-arm', container: 'node:24-alpine' },
9
+ 'win32-x64': { name: '@dotenvx/dotenvx-windows-x86_64', os: 'win32', cpu: 'x64', target: 'x86_64-pc-windows-msvc', runner: 'windows-2022' },
10
+ 'win32-arm64': { name: '@dotenvx/dotenvx-windows-arm64', os: 'win32', cpu: 'arm64', target: 'aarch64-pc-windows-msvc', runner: 'windows-11-arm' }
11
+ }
12
+
13
+ function currentPlatform () {
14
+ const libc = process.platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? '-gnu' : '-musl') : ''
15
+ return `${process.platform}-${process.arch}${libc}`
16
+ }
17
+
18
+ module.exports = { platforms, currentPlatform }
@@ -0,0 +1,72 @@
1
+ const { redact } = require('../native.cjs')
2
+ const { StringDecoder } = require('string_decoder')
3
+
4
+ function normalizedValues (values) {
5
+ return [...new Set((values || [])
6
+ .filter(value => value !== undefined && value !== null && `${value}`.length > 0)
7
+ .map(value => `${value}`))]
8
+ .sort((a, b) => b.length - a.length)
9
+ }
10
+
11
+ function partialMatchLength (value, sensitiveValues) {
12
+ let longest = 0
13
+
14
+ for (const sensitiveValue of sensitiveValues) {
15
+ const maxLength = Math.min(value.length, sensitiveValue.length - 1)
16
+ for (let length = maxLength; length > longest; length--) {
17
+ if (sensitiveValue.startsWith(value.slice(-length))) {
18
+ longest = length
19
+ break
20
+ }
21
+ }
22
+ }
23
+
24
+ return longest
25
+ }
26
+
27
+ function safeBoundary (value, boundary, sensitiveValues) {
28
+ let result = boundary
29
+ let changed = true
30
+
31
+ while (changed) {
32
+ changed = false
33
+ for (const sensitiveValue of sensitiveValues) {
34
+ let index = value.indexOf(sensitiveValue)
35
+ while (index !== -1) {
36
+ const end = index + sensitiveValue.length
37
+ if (index < result && end > result) {
38
+ result = index
39
+ changed = true
40
+ }
41
+ index = value.indexOf(sensitiveValue, index + 1)
42
+ }
43
+ }
44
+ }
45
+
46
+ return result
47
+ }
48
+
49
+ function createRedactor (sensitiveValues) {
50
+ const values = new Set(normalizedValues(sensitiveValues))
51
+ const decoder = new StringDecoder('utf8')
52
+ let pending = ''
53
+ return {
54
+ add: secrets => normalizedValues(secrets).forEach(secret => values.add(secret)),
55
+ write (chunk) {
56
+ pending += decoder.write(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
57
+ const secrets = [...values]
58
+ const boundary = safeBoundary(pending, pending.length - partialMatchLength(pending, secrets), secrets)
59
+ const output = redact(pending.slice(0, boundary), secrets)
60
+ pending = pending.slice(boundary)
61
+ return output
62
+ },
63
+ flush (maskPending = false) {
64
+ pending += decoder.end()
65
+ const output = maskPending && pending ? '[REDACTED]' : redact(pending, [...values])
66
+ pending = ''
67
+ return output
68
+ }
69
+ }
70
+ }
71
+
72
+ module.exports = { createRedactor }
@@ -0,0 +1,64 @@
1
+ const { formatWithOptions } = require('node:util')
2
+ const { createRedactor } = require('./redactOutput.cjs')
3
+ const { redact } = require('../native.cjs')
4
+
5
+ // Multiple SDK copies share output protection within the process.
6
+ const stateKey = Symbol.for('@dotenvx/dotenvx/redaction')
7
+ function state () {
8
+ if (!globalThis[stateKey]) globalThis[stateKey] = { values: new Set(), streams: [], consoles: new Map() }
9
+ return globalThis[stateKey]
10
+ }
11
+
12
+ function install (values) {
13
+ const shared = state()
14
+ // Keep old values protected during hot reload while old code can still log them.
15
+ for (const value of values) if (value !== undefined && value !== null && `${value}`) shared.values.add(`${value}`)
16
+ if (!shared.values.size) return
17
+
18
+ for (const stream of [process.stdout, process.stderr]) {
19
+ let entry = shared.streams.find(item => item.stream === stream)
20
+ if (!entry) {
21
+ const original = stream.write
22
+ const redactor = createRedactor([...shared.values])
23
+ const write = function (chunk, encoding, callback) {
24
+ if (typeof encoding === 'function') { callback = encoding; encoding = undefined }
25
+ const output = redactor.write(typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk)
26
+ if (output) return original.call(this, output, 'utf8', callback)
27
+ if (callback) process.nextTick(callback)
28
+ return true
29
+ }
30
+ entry = { stream, original, redactor, write }
31
+ shared.streams.push(entry)
32
+ stream.write = write
33
+ } else entry.redactor.add([...shared.values])
34
+ }
35
+
36
+ // Redact before React or another console wrapper captures arguments for replay.
37
+ for (const method of ['log', 'info', 'warn', 'error', 'debug', 'trace', 'dir']) {
38
+ const previous = shared.consoles.get(method)
39
+ if (previous === console[method]) continue
40
+ const original = console[method]
41
+ const wrapped = function (...args) {
42
+ const message = method === 'dir'
43
+ ? require('node:util').inspect(args[0], args[1])
44
+ : formatWithOptions({}, ...args)
45
+ return original.call(this, redact(message, [...shared.values]))
46
+ }
47
+ shared.consoles.set(method, wrapped)
48
+ console[method] = wrapped
49
+ }
50
+ if (!shared.flushInstalled) {
51
+ shared.flushInstalled = true
52
+ const flush = () => {
53
+ for (const { stream, original, redactor } of shared.streams) {
54
+ // A trailing prefix may be the beginning of a secret. Never reveal it.
55
+ const pending = redactor.flush(true)
56
+ if (pending) original.call(stream, pending)
57
+ }
58
+ }
59
+ process.on('beforeExit', flush)
60
+ process.on('exit', flush)
61
+ }
62
+ }
63
+
64
+ module.exports = { applyRedaction: install, refreshRedaction: () => install([]) }
@@ -0,0 +1,57 @@
1
+ const common = ['processEnv', 'overload', 'override', 'strict', 'ignore', 'logLevel']
2
+ const loading = [...common, 'path', 'envs', 'cwd', 'envKeysFile', 'keyFiles', 'convention', 'environment', 'encoding', 'quiet', 'resolveReferences', 'no1Password', 'noBitwarden', 'noArmor', 'noNative', 'token']
3
+ const allowed = {
4
+ config: new Set(loading),
5
+ parse: new Set([...common, 'privateKey']),
6
+ get: new Set([...loading, 'all', 'format'])
7
+ }
8
+ const sourceOptions = new Set(['type', 'value'])
9
+ const booleans = ['overload', 'override', 'strict', 'quiet', 'all', 'resolveReferences', 'no1Password', 'noBitwarden', 'noArmor', 'noNative']
10
+
11
+ function record (value, keys, context) {
12
+ if (!value || typeof value !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) {
13
+ throw new TypeError(`dotenvx ${context} must be an options object`)
14
+ }
15
+ for (const name of Reflect.ownKeys(value)) {
16
+ if (!keys.has(name)) throw new TypeError(`Unsupported dotenvx ${context} option: ${String(name)}`)
17
+ }
18
+ }
19
+
20
+ function validateOptions (options, method) {
21
+ record(options, allowed[method], method)
22
+ for (const name of booleans) {
23
+ if (options[name] !== undefined && typeof options[name] !== 'boolean') {
24
+ throw new TypeError(`dotenvx ${method} option ${name} must be a boolean`)
25
+ }
26
+ }
27
+ for (const name of ['privateKey', 'token', 'cwd', 'environment']) {
28
+ if (options[name] !== undefined && typeof options[name] !== 'string') {
29
+ throw new TypeError(`dotenvx ${method} option ${name} must be a string`)
30
+ }
31
+ }
32
+ if (options.processEnv !== undefined && (!options.processEnv || typeof options.processEnv !== 'object' || Array.isArray(options.processEnv))) {
33
+ throw new TypeError('processEnv must be an object')
34
+ }
35
+ if (options.ignore !== undefined && typeof options.ignore !== 'string' &&
36
+ !(Array.isArray(options.ignore) && options.ignore.every(code => typeof code === 'string'))) {
37
+ throw new TypeError(`dotenvx ${method} option ignore must be a string or an array of strings`)
38
+ }
39
+ for (const [name, values] of Object.entries({
40
+ logLevel: ['error', 'warn', 'info', 'silent'],
41
+ format: ['eval', 'eval-export', 'shell', 'colon'],
42
+ convention: ['nextjs', 'flow', 'rails']
43
+ })) {
44
+ if (options[name] !== undefined && !values.includes(options[name])) {
45
+ throw new TypeError(`dotenvx ${method} option ${name} must be one of: ${values.join(', ')}`)
46
+ }
47
+ }
48
+ if (options.encoding !== undefined && !['utf8', 'utf-8'].includes(options.encoding)) {
49
+ throw new TypeError('This beta supports UTF-8 env files (encoding: utf8 or utf-8)')
50
+ }
51
+ if (options.envs !== undefined) {
52
+ if (!Array.isArray(options.envs)) throw new TypeError('envs must be an array')
53
+ for (const [index, source] of options.envs.entries()) record(source, sourceOptions, `${method} envs[${index}]`)
54
+ }
55
+ }
56
+
57
+ module.exports = { validateOptions }
package/native.cjs ADDED
@@ -0,0 +1,23 @@
1
+ const { currentPlatform } = require('./lib/platforms.cjs')
2
+ const { resolveNativeFile } = require('./lib/native-package.cjs')
3
+
4
+ // Literal imports let deployment tracers discover the platform addon files.
5
+ const bindings = {
6
+ 'darwin-arm64': () => require('@dotenvx/dotenvx-darwin-arm64/dotenvx.node'),
7
+ 'darwin-x64': () => require('@dotenvx/dotenvx-darwin-x86_64/dotenvx.node'),
8
+ 'linux-x64-gnu': () => require('@dotenvx/dotenvx-linux-x86_64/dotenvx.node'),
9
+ 'linux-arm64-gnu': () => require('@dotenvx/dotenvx-linux-arm64/dotenvx.node'),
10
+ 'linux-x64-musl': () => require('@dotenvx/dotenvx-linux-x86_64-musl/dotenvx.node'),
11
+ 'linux-arm64-musl': () => require('@dotenvx/dotenvx-linux-arm64-musl/dotenvx.node'),
12
+ 'win32-x64': () => require('@dotenvx/dotenvx-windows-x86_64/dotenvx.node'),
13
+ 'win32-arm64': () => require('@dotenvx/dotenvx-windows-arm64/dotenvx.node')
14
+ }
15
+ const platform = currentPlatform()
16
+ if (!bindings[platform]) throw new Error(`@dotenvx/dotenvx has no native package for ${platform}`)
17
+ try {
18
+ module.exports = bindings[platform]()
19
+ } catch (cause) {
20
+ if (cause.code !== 'MODULE_NOT_FOUND') throw cause
21
+ // Local builds can use native/; published tarballs have no local fallback.
22
+ module.exports = require(resolveNativeFile('dotenvx.node'))
23
+ }
package/package.json CHANGED
@@ -1,46 +1,73 @@
1
1
  {
2
- "version": "0.4.0",
3
2
  "name": "@dotenvx/dotenvx",
4
- "description": "a better dotenv–from the creator of `dotenv`",
5
- "author": "@motdotla",
6
- "keywords": [
7
- "dotenv",
8
- "env"
9
- ],
10
- "homepage": "https://github.com/dotenvx/dotenvx",
11
- "repository": "dotenvx/dotenvx",
12
- "license": "MIT",
13
- "files": [
14
- "src/**/*"
15
- ],
16
- "main": "src/lib/main.js",
3
+ "version": "0.4.13",
4
+ "description": "a secure dotenv—from the creator of dotenv",
5
+ "license": "BSD-3-Clause",
6
+ "homepage": "https://dotenvx.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/dotenvx/forge.git",
10
+ "directory": "dotenvx-nodejs"
11
+ },
12
+ "main": "index.cjs",
13
+ "types": "index.d.ts",
17
14
  "bin": {
18
- "dotenvx": "./src/cli/dotenvx.js",
19
- "git-dotenvx": "./src/cli/dotenvx.js"
15
+ "dotenvx": "bin/dotenvx.cjs",
16
+ "dx": "bin/dotenvx.cjs"
20
17
  },
21
- "scripts": {
22
- "standard": "standard",
23
- "standard:fix": "standard --fix",
24
- "test": "jest"
18
+ "exports": {
19
+ ".": {
20
+ "types": "./index.d.ts",
21
+ "import": "./index.mjs",
22
+ "require": "./index.cjs"
23
+ },
24
+ "./config": {
25
+ "types": "./config.d.ts",
26
+ "import": "./config.mjs",
27
+ "require": "./config.cjs"
28
+ },
29
+ "./config.js": {
30
+ "types": "./config.d.ts",
31
+ "import": "./config.mjs",
32
+ "require": "./config.cjs"
33
+ },
34
+ "./package.json": "./package.json"
25
35
  },
26
- "dependencies": {
27
- "commander": "^11.1.0",
28
- "dotenv": "^16.3.1",
29
- "winston": "^3.11.0",
30
- "xxhashjs": "^0.2.2"
36
+ "files": [
37
+ "index.cjs",
38
+ "index.mjs",
39
+ "index.d.ts",
40
+ "config.cjs",
41
+ "config.mjs",
42
+ "config.d.ts",
43
+ "native.cjs",
44
+ "bin/",
45
+ "lib/",
46
+ "LICENSE",
47
+ "README.md"
48
+ ],
49
+ "engines": {
50
+ "node": ">=20"
31
51
  },
32
52
  "devDependencies": {
33
- "jest": "^29.7.0",
34
- "jest-mock-process": "^2.0.0",
35
- "pkg": "^5.8.1",
36
- "standard": "^17.1.0"
37
- },
38
- "standard": {
39
- "env": [
40
- "jest"
41
- ]
53
+ "@types/node": "^20.19.0",
54
+ "typescript": "^5.9.0"
42
55
  },
43
56
  "publishConfig": {
44
- "access": "public"
45
- }
57
+ "access": "public",
58
+ "tag": "next",
59
+ "registry": "https://registry.npmjs.org",
60
+ "provenance": false
61
+ },
62
+ "optionalDependencies": {
63
+ "@dotenvx/dotenvx-darwin-arm64": "0.4.13",
64
+ "@dotenvx/dotenvx-darwin-x86_64": "0.4.13",
65
+ "@dotenvx/dotenvx-linux-x86_64": "0.4.13",
66
+ "@dotenvx/dotenvx-linux-arm64": "0.4.13",
67
+ "@dotenvx/dotenvx-linux-x86_64-musl": "0.4.13",
68
+ "@dotenvx/dotenvx-linux-arm64-musl": "0.4.13",
69
+ "@dotenvx/dotenvx-windows-x86_64": "0.4.13",
70
+ "@dotenvx/dotenvx-windows-arm64": "0.4.13"
71
+ },
72
+ "private": false
46
73
  }