@dotenvx/dotenvx
Advanced tools
Comparing version 1.34.0 to 1.35.0
@@ -5,4 +5,13 @@ # Changelog | ||
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.34.0...main) | ||
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.35.0...main) | ||
## [1.35.0](https://github.com/dotenvx/dotenvx/compare/v1.34.0...v1.35.0) | ||
### Added | ||
* `npx dotenvx precommit` support as a convenience ([#523](https://github.com/dotenvx/dotenvx/pull/523)) | ||
* `main.get` method ([#524](https://github.com/dotenvx/dotenvx/pull/524)) | ||
The addition of `main.get` facilitates what we term Decryption at Access, a concept explored in greater detail in our [whitepaper](https://dotenvx.com/dotenvx.pdf). | ||
## [1.34.0](https://github.com/dotenvx/dotenvx/compare/v1.33.0...v1.34.0) | ||
@@ -9,0 +18,0 @@ |
{ | ||
"version": "1.34.0", | ||
"version": "1.35.0", | ||
"name": "@dotenvx/dotenvx", | ||
@@ -4,0 +4,0 @@ "description": "a better dotenv–from the creator of `dotenv`", |
@@ -22,3 +22,3 @@ [![dotenvx](https://dotenvx.com/better-banner.png)](https://dotenvx.com) | ||
require('@dotenvx/dotenvx').config() | ||
// or import('@dotenvx/dotenvx/config') if you're using esm | ||
// or import '@dotenvx/dotenvx/config' // for esm | ||
@@ -25,0 +25,0 @@ console.log(`Hello ${process.env.HELLO}`) |
@@ -6,4 +6,9 @@ const fsx = require('./fsx') | ||
if ! command -v dotenvx 2>&1 >/dev/null | ||
if command -v dotenvx 2>&1 >/dev/null | ||
then | ||
dotenvx ext precommit | ||
elif npx dotenvx -V >/dev/null 2>&1 | ||
then | ||
npx dotenvx ext precommit | ||
else | ||
echo "[dotenvx][precommit] 'dotenvx' command not found" | ||
@@ -14,5 +19,4 @@ echo "[dotenvx][precommit] ? install it with [curl -fsS https://dotenvx.sh | sh]" | ||
fi | ||
` | ||
dotenvx ext precommit` | ||
class InstallPrecommitHook { | ||
@@ -19,0 +23,0 @@ constructor () { |
@@ -197,2 +197,9 @@ import type { URL } from 'url'; | ||
convention?: string; | ||
/** | ||
* Specify whether the variable has to be encrypted | ||
* @default true | ||
* @example require('@dotenvx/dotenvx').config(key, value, { encrypt: false } }) | ||
*/ | ||
encrypt?: boolean; | ||
} | ||
@@ -199,0 +206,0 @@ |
@@ -12,2 +12,3 @@ // @ts-check | ||
const Sets = require('./services/sets') | ||
const Get = require('./services/get') | ||
const Keypair = require('./services/keypair') | ||
@@ -61,3 +62,2 @@ const Genexample = require('./services/genexample') | ||
const parsedAll = {} | ||
for (const processedEnv of processedEnvs) { | ||
@@ -239,2 +239,54 @@ if (processedEnv.type === 'envVaultFile') { | ||
/* @type {import('./main').get} */ | ||
const get = function (key, options = {}) { | ||
const envs = buildEnvs(options) | ||
// ignore | ||
const ignore = options.ignore || [] | ||
const { parsed, errors } = new Get(key, envs, options.overload, process.env.DOTENV_KEY, options.all, options.envKeysFile).run() | ||
for (const error of errors || []) { | ||
if (options.strict) throw error // throw immediately if strict | ||
if (ignore.includes(error.code)) { | ||
continue // ignore error | ||
} | ||
console.error(error.message) | ||
if (error.help) { | ||
console.error(error.help) | ||
} | ||
} | ||
if (key) { | ||
const single = parsed[key] | ||
if (single === undefined) { | ||
return undefined | ||
} else { | ||
return single | ||
} | ||
} else { | ||
if (options.format === 'eval') { | ||
let inline = '' | ||
for (const [key, value] of Object.entries(parsed)) { | ||
inline += `${key}=${escape(value)}\n` | ||
} | ||
inline = inline.trim() | ||
return inline | ||
} else if (options.format === 'shell') { | ||
let inline = '' | ||
for (const [key, value] of Object.entries(parsed)) { | ||
inline += `${key}=${value} ` | ||
} | ||
inline = inline.trim() | ||
return inline | ||
} else { | ||
return parsed | ||
} | ||
} | ||
} | ||
/** @type {import('./main').ls} */ | ||
@@ -266,2 +318,3 @@ const ls = function (directory, envFile, excludeEnvFile) { | ||
set, | ||
get, | ||
ls, | ||
@@ -268,0 +321,0 @@ keypair, |
248591
4018
30
11