@dotenvx/dotenvx 2.32.3 → 2.33.0

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +43 -55
  3. package/package.json +3 -11
  4. package/src/cli/actions/check.js +7 -12
  5. package/src/cli/actions/encrypt.js +2 -2
  6. package/src/cli/actions/get.js +3 -3
  7. package/src/cli/actions/init.js +11 -11
  8. package/src/cli/actions/policy.js +14 -0
  9. package/src/cli/actions/primitivesCheck.js +32 -0
  10. package/src/cli/actions/primitivesProfile.js +15 -0
  11. package/src/cli/actions/primitivesRedact.js +19 -0
  12. package/src/cli/actions/protectStdin.js +2 -2
  13. package/src/cli/actions/run.js +6 -34
  14. package/src/cli/actions/set.js +1 -1
  15. package/src/cli/commands/primitives.js +28 -1
  16. package/src/cli/dotenvx.js +10 -5
  17. package/src/lib/custodians/local/onepassword.js +3 -5
  18. package/src/lib/{envspec → envfile}/discovery/discoverEnvFiles.js +1 -1
  19. package/src/lib/{envspec → envfile}/discovery/scanSource.js +1 -1
  20. package/src/lib/{envspec/parsing/formatEnvspecSyntaxError.js → envfile/parsing/formatEnvfileSyntaxError.js} +1 -1
  21. package/src/lib/envfile/parsing/readEnvfile.js +43 -0
  22. package/src/lib/envfile/parsing/resolveEnvfilePath.js +5 -0
  23. package/src/lib/{envspec/rendering/normalizeEnvspec.js → envfile/rendering/normalizeEnvfile.js} +1 -1
  24. package/src/lib/{envspec/rendering/previewEnvspec.js → envfile/rendering/previewEnvfile.js} +7 -15
  25. package/src/lib/{envspec/rendering/renderEnvspec.js → envfile/rendering/renderEnvfile.js} +4 -4
  26. package/src/lib/{envspec/validation/protectEnvspec.js → envfile/validation/protectEnvfile.js} +8 -10
  27. package/src/lib/envfile/validation/validateEnvfile.js +14 -0
  28. package/src/lib/helpers/errors.js +3 -12
  29. package/src/lib/helpers/executeCommand.js +1 -2
  30. package/src/lib/helpers/parseWithDecryptor.js +1 -9
  31. package/src/lib/helpers/redactOutput.js +30 -32
  32. package/src/lib/helpers/redactProcessOutput.js +58 -0
  33. package/src/lib/helpers/redactedValues.js +2 -2
  34. package/src/lib/helpers/selectEnvfileEnvs.js +29 -0
  35. package/src/lib/main.d.ts +14 -5
  36. package/src/lib/main.js +13 -19
  37. package/src/lib/resolvers/envs.js +5 -15
  38. package/src/lib/resolvers/get.js +2 -2
  39. package/src/lib/services/init.js +7 -7
  40. package/src/lib/services/validate.js +20 -31
  41. package/src/lib/transforms/encrypt.js +5 -5
  42. package/src/lib/transforms/set.js +5 -3
  43. package/src/lib/envspec/parsing/envspec.peggy +0 -105
  44. package/src/lib/envspec/parsing/envspecParser.js +0 -2851
  45. package/src/lib/envspec/parsing/readEnvspec.js +0 -151
  46. package/src/lib/envspec/parsing/resolveEnvspecPath.js +0 -12
  47. package/src/lib/envspec/validation/encryptedSources.js +0 -15
  48. package/src/lib/envspec/validation/validate.js +0 -109
  49. package/src/lib/envspec/validation/validateEnvspec.js +0 -57
  50. package/src/lib/helpers/isValidEmail.js +0 -11
  51. package/src/lib/helpers/isValidUrl.js +0 -9
  52. package/src/lib/proxy/configureProxy.js +0 -55
  53. package/src/lib/proxy/eligibleHeaders.js +0 -16
  54. package/src/lib/proxy/prepareProxy.js +0 -24
  55. package/src/lib/proxy/proxyCertificates.js +0 -44
  56. package/src/lib/proxy/proxyForward.js +0 -65
  57. package/src/lib/proxy/proxyPreload.js +0 -21
  58. package/src/lib/proxy/proxyPreloadSource.js +0 -3
  59. package/src/lib/proxy/proxyServer.js +0 -175
  60. /package/src/lib/{envspec → envfile}/discovery/extractEnvKeys.js +0 -0
  61. /package/src/lib/{envspec → envfile}/validation/diagnosticLocation.js +0 -0
package/CHANGELOG.md CHANGED
@@ -2,7 +2,25 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.32.3...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.33.0...main)
6
+
7
+ ## [2.33.0](https://github.com/dotenvx/dotenvx/compare/v2.32.4...v2.33.0) (2026-10-05)
8
+
9
+ ### Added
10
+
11
+ * Add Envfile profiles for selecting .env file combinations with `--profile` or `DOTENV_ENV`.
12
+ * Automatically redact stdout/stderr from `config()` when an Envfile is present.
13
+
14
+ ### Changed
15
+
16
+ * Move Envfile processing into `@dotenvx/primitives`.
17
+ * First file wins when combining Envfile rules. `run` and `check` validate final values; encryption rules apply to `encrypt`, `set`, and `protect`.
18
+
19
+ ## [2.32.4](https://github.com/dotenvx/dotenvx/compare/v2.32.3...v2.32.4) (2026-10-01)
20
+
21
+ ### Changed
22
+
23
+ * Make `Envfile` the filename. Final decision. ([#1003](https://github.com/dotenvx/dotenvx/pull/1003))
6
24
 
7
25
  ## [2.32.3](https://github.com/dotenvx/dotenvx/compare/v2.32.2...v2.32.3) (2026-09-30)
8
26
 
package/README.md CHANGED
@@ -1305,9 +1305,9 @@ Hello String
1305
1305
  ```
1306
1306
 
1307
1307
  </details>
1308
- <details><summary>`run with Dotenvspec redaction`</summary><br>
1308
+ <details><summary>`run with Envfile redaction`</summary><br>
1309
1309
 
1310
- Run any command with real environment variables while automatically redacting values selected by your Dotenvspec from stdout and stderr.
1310
+ Run any command with real environment variables while automatically redacting values selected by your Envfile from stdout and stderr.
1311
1311
 
1312
1312
  ```sh
1313
1313
  $ echo "SECRET=super-secret-value" > .env
@@ -1319,9 +1319,9 @@ $ dotenvx run --quiet -- node index.js
1319
1319
  [REDACTED] visible-value
1320
1320
  ```
1321
1321
 
1322
- With a Dotenvspec, all values are redacted by default. Use `redacted: false` on individual declarations to leave those values visible. `spec` generates these settings, including public-name exceptions. If an existing environment variable takes precedence, its effective value follows the same rules. Matching is exact, so transformed or derived values are not redacted.
1322
+ With an Envfile, all values are redacted by default. Use `redacted: false` on individual declarations to leave those values visible. `spec` generates these settings, including public-name exceptions. If an existing environment variable takes precedence, its effective value follows the same rules. Matching is exact, so transformed or derived values are not redacted.
1323
1323
 
1324
- Without a Dotenvspec, `dotenvx run --redact -- yourcommand` redacts loaded values except recognized public names (containing `PUBLIC` or starting with `VITE`, case-sensitive). `_PLAIN` values are redacted too. Without either a Dotenvspec or `--redact`, output is not redacted. A Dotenvspec always takes precedence: its rules apply automatically, even when `--redact` is passed.
1324
+ Without an Envfile, `dotenvx run --redact -- yourcommand` redacts loaded values except recognized public names (containing `PUBLIC` or starting with `VITE`, case-sensitive). `_PLAIN` values are redacted too. Without either an Envfile or `--redact`, output is not redacted. An Envfile always takes precedence: its rules apply automatically, even when `--redact` is passed.
1325
1325
 
1326
1326
  When stdin, stdout, and stderr are attached to a terminal, dotenvx preserves interactive behavior on macOS and Linux systems with `script` available. Piped and redirected commands continue to use normal stdin, stdout, and stderr streams.
1327
1327
 
@@ -1567,24 +1567,14 @@ Hello production
1567
1567
  Available log levels are `error, warn, info, verbose, debug, silly` ([source](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1568
1568
 
1569
1569
  </details>
1570
- <details><summary>`run with a Dotenvspec`</summary><br>
1570
+ <details><summary>`run with an Envfile`</summary><br>
1571
1571
 
1572
- `Dotenvspec` is the default policy filename. `Envspec` is also supported as a shorthand when `Dotenvspec` is absent. `Dotenvxspec` is accepted as a final fallback when neither exists. Only the first matching file is read; an invalid or unreadable policy never falls back to another filename. This precedence applies to `run`, `check`, `config()`, encryption, and Git protection.
1572
+ `Envfile` is like a Dockerfile for your secrets.
1573
1573
 
1574
- Set `DOTENV_SPEC` to inline policy text to use it instead of a policy file:
1575
-
1576
- ```sh
1577
- DOTENV_SPEC='env "PORT", type: "port", encrypted: false, redacted: false' dotenvx run -- node index.js
1578
- ```
1579
-
1580
- The precedence is `DOTENV_SPEC` → `Dotenvspec` → `Envspec` → `Dotenvxspec`. The variable contains the policy itself, not a file path, and supports multiline declarations and file blocks. File block paths are relative to the current working directory. Invalid inline policy fails without falling back to a file; an explicitly empty value selects an empty policy with the usual default rules. Unset the variable to resume file discovery.
1581
-
1582
- Inline policy is read from the incoming environment before loading `.env` files or `--env` values. For `config({ processEnv })`, put `DOTENV_SPEC` in that object. The same override applies to `check`, encryption, and Git protection. `dotenvx spec` still generates `Dotenvspec` from its selected inputs.
1583
-
1584
- When a `Dotenvspec` is present, `run` and `check` validate the same requirements: required values, types, enums, ranges, and storage encryption. No validation flag is needed. `run` performs validation before starting your command.
1574
+ When an `Envfile` is present, `run` and `check` validate the same requirements: required values, types, enums, and ranges. No validation flag is needed. `run` performs validation before starting your command.
1585
1575
 
1586
1576
  ```ruby
1587
- # Dotenvspec
1577
+ # Envfile
1588
1578
  env "DATABASE_URL", type: "url"
1589
1579
  env "API_KEY"
1590
1580
  env "SENTRY_DSN", optional: true
@@ -1595,11 +1585,11 @@ $ dotenvx run -- node index.js
1595
1585
  [INVALID_ENV] DATABASE_URL is required; API_KEY is required
1596
1586
  ```
1597
1587
 
1598
- Dotenvspec validation failures, including unencrypted values, warn by default; `run --strict` stops before launching the command. A `strict true` setting in Dotenvspec, at the root or in an active file block, also makes its validation failures fatal. `check` always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Dotenvspec syntax always stops execution.
1588
+ Envfile validation failures warn by default; `run --strict` stops before launching the command. A `strict true` setting in Envfile, at the root or in an active file block, also makes its validation failures fatal. `check` always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Envfile syntax always stops execution.
1599
1589
 
1600
- Dotenvspec values default to `redacted: true`: `run` masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set `redacted: false` for values that may appear in output. This is independent of `encrypted: true`, which requires an encrypted source.
1590
+ Envfile values default to `redacted: true`: `run` masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set `redacted: false` for values that may appear in output. This is independent of `encrypted: true`, which controls encryption in `encrypt`, `set`, and `protect`.
1601
1591
 
1602
- The synchronous `dotenvx.config()` API also reads `Dotenvspec` from the current working directory and validates the final resolved values using the same rules, including selected file blocks and storage encryption. Validation failures warn and are returned in `{ parsed, error }`; `config({ strict: true })` or an applicable Dotenvspec `strict true` setting makes failures throw. `ignore: ['INVALID_ENV']` suppresses validation failures. Invalid Dotenvspec syntax always throws before loading values. Dotenvspec redaction applies to dotenvx's own resolved-value debug logs; application output and returned values retain their real values. Active proxy declarations throw before loading values because synchronous `config()` cannot start the proxy; use `dotenvx run -- yourcommand` for those policies.
1592
+ The synchronous `dotenvx.config()` API also reads `Envfile` from the current working directory and validates the final resolved values using the same rules, including selected file blocks. Validation failures warn and are returned in `{ parsed, error }`; `config({ strict: true })` or an applicable Envfile `strict true` setting makes failures throw. `ignore: ['INVALID_ENV']` suppresses validation failures. Invalid Envfile syntax always throws before loading values. With an Envfile, `config()` automatically redacts subsequent writes through Node's stdout/stderr streams, including existing `console.log` and `console.error` calls. Environment values and returned values stay unchanged. Repeated calls retain earlier secrets and add newly loaded ones. An unfinished secret prefix is masked at shutdown. Direct native writes and child processes inheriting file descriptors bypass these wrappers; use `dotenvx run` to capture child output.
1603
1593
 
1604
1594
  ```ruby
1605
1595
  file ".env.development" do
@@ -1612,17 +1602,17 @@ end
1612
1602
 
1613
1603
  `spec` infers `redacted: false` for names starting with `PUBLIC`, `VITE`, `NEXT_PUBLIC`, or `NUXT_PUBLIC`, or containing `PUBLIC` anywhere (case-sensitive). This affects visibility only; public names still require encryption unless explicitly exempted. Other names, including those ending in `_PLAIN`, remain redacted.
1614
1604
 
1615
- `dotenvx spec` always generates `Dotenvspec`, including with `--overwrite` or `--stdout`. Existing `Envspec` and `Dotenvxspec` files are left untouched; creating `Dotenvspec` makes it the active policy.
1605
+ `dotenvx spec` always generates `Envfile` with `strict true` at the top, including with `--overwrite` or `--stdout`. Generated policies stop commands on validation failures. Existing policies that omit `strict` continue to warn.
1616
1606
 
1617
- If a Dotenvspec already exists, `spec` leaves it untouched and prints `○ Dotenvspec already exists [edit or run: spec --overwrite]`. Use `spec --overwrite` to regenerate it from the selected inputs, replacing custom rules, comments, and blocks for files absent from this machine. Interactive overwrite runs show the full file-and-code checklist with the prompt `Recreate Dotenvspec from .env files and code`. Noninteractive runs use `.env.example` and `.env`, or the file selected with `-f`. Input validation finishes before the old Dotenvspec is replaced; cancelled selection leaves it untouched. Symlinked Dotenvspecs cannot be overwritten.
1607
+ If an Envfile already exists, `spec` leaves it untouched and prints `○ Envfile already exists [edit or run: spec --overwrite]`. Use `spec --overwrite` to regenerate it from the selected inputs, replacing custom rules, comments, and blocks for files absent from this machine. Interactive overwrite runs show the full file-and-code checklist with the prompt `Recreate Envfile from .env files and code`. Noninteractive runs use `.env.example` and `.env`, or the file selected with `-f`. Input validation finishes before the old Envfile is replaced; cancelled selection leaves it untouched. Symlinked Envfiles cannot be overwritten.
1618
1608
 
1619
- Use `dotenvx spec --stdout` to print the generated Dotenvspec without writing it, or `dotenvx spec --stdout -f .env.production` to select an input file. This works even when a Dotenvspec already exists; `--stdout` leaves it untouched even with `--overwrite`. Prompts and progress stay on stderr so stdout contains only the generated content.
1609
+ Use `dotenvx spec --stdout` to print the generated Envfile without writing it, or `dotenvx spec --stdout -f .env.production` to select an input file. This works even when an Envfile already exists; `--stdout` leaves it untouched even with `--overwrite`. Prompts and progress stay on stderr so stdout contains only the generated content.
1620
1610
 
1621
- Root and file-level `redacted` settings are not supported. Use per-key `redacted: false` to permit output visibility. When selected file policies disagree about a variable, redaction wins. `check` shows individual issues or a compact success summary without displaying values.
1611
+ Root and file-level `redacted` settings are not supported. Use per-key `redacted: false` to permit output visibility. When selected files specify conflicting options, the first file's explicit option wins. `check` previews values with policy-driven redaction and reports issues per key.
1622
1612
 
1623
1613
 
1624
1614
  </details>
1625
- <details><summary>`run with Dotenvspec file rules`</summary><br>
1615
+ <details><summary>`run with Envfile file rules`</summary><br>
1626
1616
 
1627
1617
  Use exact file blocks to override rules for selected files:
1628
1618
 
@@ -1637,37 +1627,46 @@ file ".env.production" do
1637
1627
  end
1638
1628
  ```
1639
1629
 
1640
- Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. A block's `encrypted` directive applies to all inherited and newly declared variables; a per-variable `encrypted:` option inside that block overrides it.
1630
+ Profiles select file combinations:
1631
+
1632
+ ```ruby
1633
+ profile "development", files: [".env.local", ".env"]
1634
+ profile "production", files: [".env.production"]
1635
+ ```
1641
1636
 
1642
- Paths in file blocks are relative to the Dotenvspec. They match the selected paths exactly after path normalization (`./.env.production` matches `.env.production`); they are not basename matches or globs. Directory inputs and `DOTENV_FILE` use their resolved file paths.
1637
+ Selection order is explicit `-f`, `--profile`, `DOTENV_FILE` / `DOTENV_PATH` / `DOTENV_F`, then `DOTENV_ENV`, `APP_ENV`, `RAILS_ENV`, `RACK_ENV`, `MIX_ENV`, and `NODE_ENV`. Without a selector, the development profile is used if declared; otherwise `.env`. Explicit unknown profiles fail.
1643
1638
 
1644
- When no file block matches, top-level rules apply. When one or more blocks match, each matching block's inherited rules must hold for the final resolved environment. Shell values, fallback files, and `--overload` cannot bypass them. A selected missing file still activates its block. Multiple matching blocks cannot cancel each other's restrictions; conflicting proxy domains are rejected. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1639
+ Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. Encryption and redaction are specified per key.
1640
+
1641
+ Paths in file blocks are relative to the Envfile. They match the selected paths exactly after path normalization (`./.env.production` matches `.env.production`); they are not basename matches or globs. Directory inputs and `DOTENV_FILE` use their resolved file paths.
1642
+
1643
+ When no file block matches, top-level rules apply. Selected file blocks override explicit options in file order: the first file wins. Policy selection is independent of where the final value comes from, including shell values and `--overload`. A selected missing file still activates its block. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1645
1644
 
1646
1645
  </details>
1647
1646
  <details><summary>`check`</summary><br>
1648
1647
 
1649
- Validate the final resolved environment against your Dotenvspec, using the same loader and precedence as `run`:
1648
+ Validate the final resolved environment against your Envfile, using the same loader and precedence as `run`:
1650
1649
 
1651
1650
  ```sh
1652
1651
  $ dotenvx check -f .env.local -f .env
1653
- ▣ valid (.env.local, .env)
1652
+ ✔ PORT=3000 # .env.local:1
1654
1653
 
1655
1654
  $ dotenvx check -f .env.production
1656
- ☠ TOKEN_SECRET not encrypted (.env.production:4)
1655
+ ☠ PORT=bad # .env.production:4 !port
1657
1656
  ```
1658
1657
 
1659
- Dotenvspec `file` blocks define policy; they do not select files to load. By default, `check` uses the same `.env` selection as `run`, including configured paths and private-key-based filename inference. Use repeated `-f` flags or `--convention` to select layers. `DOTENV_FILE` and its aliases are also supported.
1658
+ Envfile `file` blocks define policy; they do not select files to load. By default, `check` uses the same profile and file selection as `run`. Use repeated `-f` flags or `--convention` to select layers. `DOTENV_FILE` and its aliases are also supported.
1660
1659
 
1661
- All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and `--overload` lets later sources override earlier values. Partial files can satisfy the schema together. Encryption requirements apply to the source of the winning value, not to every overridden assignment on disk. Each selected file block's inherited rules must hold for the final environment, just as with `run`.
1660
+ All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and `--overload` lets later sources override earlier values. Partial files can satisfy the schema together. Validation checks final values; encryption requirements are enforced separately by `encrypt`, `set`, and `protect`. Rules are combined independently, with the first explicit file option winning.
1662
1661
 
1663
1662
  Missing files explicitly selected with `-f` or `DOTENV_FILE` (and its aliases) fail the check. Missing optional convention layers and implicit default files are reported as `○ skipped (filename)`. `check` has no `--strict` flag. Required values must still resolve; shell or inline values can satisfy the schema without a local file. A check with no readable files, inline values, or declared shell values fails rather than reporting an empty success.
1664
1663
 
1665
- On interactive terminals, a single progress line updates with the key being checked. CI and redirected output have no animation. All check output goes to stderr. Success names the loaded sources; validation failures use one diagnostic per issue with the winning source location where available. Shell and inline overrides are identified separately. Failed checks exit with code 1.
1664
+ The preview shows redacted values and per-key diagnostics on stdout, with source locations where available. Loading errors go to stderr. `--quiet` suppresses the preview. Failed checks exit with code 1.
1666
1665
 
1667
1666
  </details>
1668
- <details><summary>`protect with a Dotenvspec`</summary><br>
1667
+ <details><summary>`protect with an Envfile`</summary><br>
1669
1668
 
1670
- The Git protection filter reads `Dotenvspec` in the same directory as the file being staged. Encryption is required by default. Keys explicitly marked `encrypted: false` may be committed as plaintext:
1669
+ The Git protection filter reads `Envfile` in the same directory as the file being staged. Encryption is required by default. Keys explicitly marked `encrypted: false` may be committed as plaintext:
1671
1670
 
1672
1671
  ```ruby
1673
1672
  env "BASE_URL", encrypted: false
@@ -1676,11 +1675,11 @@ env "TOKEN_SECRET"
1676
1675
 
1677
1676
  This permits plaintext `BASE_URL` while requiring `TOKEN_SECRET` and undeclared keys to be encrypted. Only keys explicitly marked `encrypted: false` may remain plaintext. `redacted` only controls output visibility.
1678
1677
 
1679
- Without a Dotenvspec, protection keeps its existing rules, including exemptions for `.env.example`, `.env.vault`, and `.env.x`. A `_PLAIN` suffix alone does not permit plaintext through Git protection.
1678
+ Without an Envfile, protection keeps its existing rules, including exemptions for `.env.example`, `.env.vault`, and `.env.x`. A `_PLAIN` suffix alone does not permit plaintext through Git protection.
1680
1679
 
1681
1680
  Protection inspects every assignment in the incoming Git blob, including duplicates. It does not merge files, use shell overrides, or decrypt values. Empty values, public encryption keys, and `op://` / `bw://` references remain allowed. Private-key files (`.env.keys*`) and nonempty plaintext `DOTENV_PRIVATE_KEY` values remain blocked even with `encrypted: false`.
1682
1681
 
1683
- The policy is read from the working-tree Dotenvspec beside the staged file, even if that policy itself is unstaged. Parent directories are not searched. Invalid or unreadable policies block staging with an error. Dotenvspec encryption rules also apply to otherwise exempt files such as `.env.example`.
1682
+ The policy is read from the working-tree Envfile beside the staged file, even if that policy itself is unstaged. If no adjacent Envfile exists, the Git repository root is checked. Invalid or unreadable policies block staging with an error. Envfile encryption rules also apply to otherwise exempt files such as `.env.example`.
1684
1683
 
1685
1684
  Accepted blobs pass through byte-for-byte. This integration applies to Git protection, not `protect --docker`.
1686
1685
 
@@ -2288,7 +2287,7 @@ $ dotenvx set HELLO_PLAIN World
2288
2287
  set HELLO_PLAIN (.env)
2289
2288
  ```
2290
2289
 
2291
- Keys ending in `_PLAIN` are not encrypted by `dotenvx set`. `dotenvx encrypt` also skips these keys when there is no Dotenvspec; with a Dotenvspec, its encryption rules take precedence.
2290
+ Without an Envfile, `dotenvx set` and `dotenvx encrypt` skip keys ending in `_PLAIN`. With an Envfile, its per-key encryption rules take precedence.
2292
2291
 
2293
2292
  </details>
2294
2293
  <details><summary>`set KEY value --no-native`</summary><br>
@@ -2347,7 +2346,7 @@ $ dotenvx del HELLO -f .env.production
2347
2346
 
2348
2347
  Encrypt the contents of a `.env` file to an encrypted `.env` file.
2349
2348
 
2350
- When the current directory contains a Dotenvspec, `encrypt` encrypts all keys except those explicitly marked `encrypted: false` in the applicable declarations. Values with effective `encrypted: false` remain unchanged, including any existing ciphertext. Undeclared keys require encryption too; both `run` and `check` validate loaded keys and their shell overrides without checking unrelated host environment variables. `run` warns on validation failures by default and refuses to launch when strictness is enabled; `check` exits with failure. The policy applies even with `--key` or `--stdout`; `--exclude-key` can further narrow the selection. If no values need encryption, no keypair is generated. Invalid Dotenvspecs fail rather than falling back to encrypting everything. The Dotenvspec itself is never modified.
2349
+ When the current directory contains an Envfile, `encrypt` encrypts all keys except those explicitly marked `encrypted: false` in the applicable declarations. Values with effective `encrypted: false` remain unchanged, including any existing ciphertext. Undeclared keys require encryption too; both `run` and `check` validate loaded keys and their shell overrides without checking unrelated host environment variables. `run` warns on validation failures by default and refuses to launch when strictness is enabled; `check` exits with failure. The policy applies even with `--key` or `--stdout`; `--exclude-key` can further narrow the selection. If no values need encryption, no keypair is generated. Invalid Envfiles fail rather than falling back to encrypting everything. The Envfile itself is never modified.
2351
2350
 
2352
2351
  ```sh
2353
2352
  $ echo "HELLO=World" > .env
@@ -3260,7 +3259,6 @@ DOTENV_CONVENTION= # set to a default convention like 'nextjs' or 'flow'
3260
3259
  DOTENV_FILE= # path to your env file; comma-separate multiple paths
3261
3260
  DOTENV_PATH= # synonym for DOTENV_FILE
3262
3261
  DOTENV_F= # synonym for DOTENV_FILE
3263
- DOTENV_SPEC= # inline Dotenvspec policy text; overrides Dotenvspec, Envspec, and Dotenvxspec files
3264
3262
  DOTENV_IGNORE= # MISSING_ENV_FILE,OTHER
3265
3263
  DOTENV_QUIET= # set to "true" to default to --quiet
3266
3264
 
@@ -3303,7 +3301,7 @@ INVALID_PUBLIC_KEY= # a public key is malformed or otherwise invalid
3303
3301
  MALFORMED_ENCRYPTED_DATA= # the encrypted value is malformed
3304
3302
  MISPAIRED_PRIVATE_KEY= # a private key does not match the existing public key
3305
3303
  MISSING_DIRECTORY= # the requested directory does not exist
3306
- ENVSPEC_REQUIRED= # the required Dotenvspec does not exist
3304
+ ENVSPEC_REQUIRED= # the required Envfile does not exist
3307
3305
  MISSING_ENV_FILE= # a requested environment file does not exist
3308
3306
  MISSING_ENV_FILES= # no .env* files were found
3309
3307
  MISSING_ENV_KEYS_FILE= # the requested .env.keys file does not exist
@@ -3315,8 +3313,8 @@ MISSING_REQUIRED= # validation detail for which required variables are missing;
3315
3313
  MISSING_VALUE= # no value was supplied for a key
3316
3314
  NOT_FOUND= # a private key was not found in the native secret store
3317
3315
  PRECOMMIT_HOOK_MODIFY_FAILED= # dotenvx could not update the pre-commit hook
3318
- INVALID_ENV= # resolved values do not satisfy Dotenvspec rules
3319
- MALFORMED_ENVSPEC= # Dotenvspec syntax or configuration is invalid
3316
+ INVALID_ENV= # resolved values do not satisfy Envfile rules
3317
+ MALFORMED_ENVSPEC= # Envfile syntax or configuration is invalid
3320
3318
  WRONG_PRIVATE_KEY= # the supplied private key cannot decrypt the value
3321
3319
  ```
3322
3320
 
@@ -3324,16 +3322,6 @@ WRONG_PRIVATE_KEY= # the supplied private key cannot decrypt the value
3324
3322
 
3325
3323
  &nbsp;
3326
3324
 
3327
- ## Membership
3328
-
3329
- [![dotenvx](https://dotenvx.com/membership.png?v2)](https://dotenvx.com/membership)
3330
-
3331
- <p align="center">Dotenvx Membership. Be part of the .env story.</p>
3332
-
3333
- <p align="center"><a href="https://dotenvx.com/membership">Membership Benefits →</a></p>
3334
-
3335
- &nbsp;
3336
-
3337
3325
  ## FAQ
3338
3326
 
3339
3327
  <details><summary>How does encryption work?</summary><br>
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.32.3",
2
+ "version": "2.33.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -49,15 +49,13 @@
49
49
  "testshell": "shellspec --shell /bin/bash",
50
50
  "release:check": "npm test && npm run testshell",
51
51
  "prerelease": "npm run release:check",
52
- "release": "npm run release:check && standard-version",
53
- "build:envspec": "peggy --format commonjs -o src/lib/envspec/parsing/envspecParser.js src/lib/envspec/parsing/envspec.peggy"
52
+ "release": "npm run release:check && standard-version"
54
53
  },
55
54
  "funding": "https://dotenvx.com",
56
55
  "dependencies": {
57
- "@dotenvx/primitives": "^3.0.3",
56
+ "@dotenvx/primitives": "^3.1.0",
58
57
  "@dotenvx/tooling": "^1.0.3",
59
58
  "global-agent": "^3.0.0",
60
- "node-forge": "^1.4.0",
61
59
  "undici": "^6.28.1",
62
60
  "yocto-spinner": "^1.2.1"
63
61
  },
@@ -65,7 +63,6 @@
65
63
  "@yao-pkg/pkg": "^6.12.0",
66
64
  "capture-console": "^1.0.2",
67
65
  "esbuild": "^0.28.1",
68
- "peggy": "^5.1.0",
69
66
  "proxyquire": "^2.1.3",
70
67
  "sinon": "^14.0.1",
71
68
  "standard": "^17.1.2",
@@ -79,10 +76,5 @@
79
76
  "publishConfig": {
80
77
  "access": "public",
81
78
  "provenance": true
82
- },
83
- "standard": {
84
- "ignore": [
85
- "src/lib/envspec/parsing/envspecParser.js"
86
- ]
87
79
  }
88
80
  }
@@ -2,12 +2,12 @@ const { logger } = require('./../../shared/logger')
2
2
  const catchAndLog = require('./../../lib/helpers/catchAndLog')
3
3
  const createSpinner = require('../../lib/helpers/createSpinner')
4
4
  const prepareValidatedEnv = require('../../lib/services/validate')
5
- const diagnosticLocations = require('../../lib/envspec/validation/diagnosticLocation')
5
+ const diagnosticLocations = require('../../lib/envfile/validation/diagnosticLocation')
6
6
  const normalizeDotenvConfigQuiet = require('../../lib/helpers/normalizeDotenvConfigQuiet')
7
7
  const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
8
8
  const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
9
9
  const path = require('node:path')
10
- const previewEnvspec = require('../../lib/envspec/rendering/previewEnvspec')
10
+ const previewEnvfile = require('../../lib/envfile/rendering/previewEnvfile')
11
11
 
12
12
  async function check () {
13
13
  const options = normalizeDotenvConfigIgnore(normalizeDotenvConfigConvention(normalizeDotenvConfigQuiet(this.opts())))
@@ -25,16 +25,15 @@ async function check () {
25
25
  }
26
26
 
27
27
  try {
28
- const { processedEnvs, readableFilepaths, requiredFilepaths, proxyError, validationError, schema, processEnv, proxyCredentials } = await prepareValidatedEnv({
28
+ const { processedEnvs, readableFilepaths, requiredFilepaths, validationError, schema, checked: checkedValues } = await prepareValidatedEnv({
29
29
  envs: this.envs,
30
30
  options,
31
- onStatus: text => { if (spinner && text) spinner.text = text },
32
- onKey: key => { if (spinner) spinner.text = `checking ${key}` }
31
+ onStatus: text => { if (spinner && text) spinner.text = text }
33
32
  })
34
33
  checked.push(...readableFilepaths)
35
34
  if (processedEnvs.some(row => row.type === 'env' && Object.keys(row.parsed || {}).length)) checked.push('--env')
36
- if (checked.length === 0 && [...schema.redactionRules.keys()].some(key => processEnv[key] !== undefined)) checked.push('shell environment')
37
- const location = diagnosticLocations(processedEnvs, checked.join(', ') || 'Dotenvspec')
35
+ if (checked.length === 0 && Object.keys(schema.keys).some(key => checkedValues[key] !== undefined)) checked.push('shell environment')
36
+ const location = diagnosticLocations(processedEnvs, checked.join(', ') || 'Envfile')
38
37
  for (const row of processedEnvs) {
39
38
  for (const error of row.errors || []) {
40
39
  if (ignore.includes(error.code)) continue
@@ -46,10 +45,6 @@ async function check () {
46
45
  report('error', error.messageWithHelp || error.message)
47
46
  }
48
47
  }
49
- if (proxyError) {
50
- errorCount++
51
- report('error', proxyError.message)
52
- }
53
48
  if (validationError && !ignore.includes(validationError.code)) {
54
49
  errorCount++
55
50
  for (const diagnostic of showPreview ? [] : validationError.diagnostics) {
@@ -61,7 +56,7 @@ async function check () {
61
56
  if (spinner) spinner.stop()
62
57
  if (showPreview) {
63
58
  const diagnostics = validationError && !ignore.includes(validationError.code) ? validationError.diagnostics : []
64
- const preview = previewEnvspec(processedEnvs, schema, processEnv, proxyCredentials, diagnostics)
59
+ const preview = previewEnvfile(processedEnvs, schema, checkedValues, diagnostics)
65
60
  if (preview) {
66
61
  for (const line of preview.split('\n')) logger.info(line)
67
62
  }
@@ -28,7 +28,7 @@ async function encryptAction () {
28
28
 
29
29
  // stdout - should not have a try so that exit codes can surface to stdout
30
30
  if (options.stdout) {
31
- const { processedEnvs } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
31
+ const { processedEnvs } = await encryptTransform({ profile: options.profile, envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
32
32
 
33
33
  if (spinner) spinner.stop()
34
34
  for (const processedEnv of processedEnvs) {
@@ -45,7 +45,7 @@ async function encryptAction () {
45
45
  }
46
46
 
47
47
  try {
48
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
48
+ const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ profile: options.profile, envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
49
49
 
50
50
  if (keysSrc) {
51
51
  await fsx.writeKeyFile(fk, keysSrc)
@@ -7,8 +7,6 @@ const Session = require('../../db/session')
7
7
  const getResolver = require('./../../lib/resolvers/get')
8
8
  const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
9
9
  const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
10
- const normalizeDotenvConfigPath = require('../../lib/helpers/normalizeDotenvConfigPath')
11
- const buildCommandEnvs = require('../../lib/helpers/buildCommandEnvs')
12
10
  const resolveEnvKeysFile = require('../../lib/helpers/resolveEnvKeysFile')
13
11
  const mask = require('../../lib/helpers/mask')
14
12
  const filterKeys = require('../../lib/helpers/filterKeys')
@@ -27,7 +25,7 @@ async function get (key) {
27
25
  const ignore = options.ignore || []
28
26
  let errorCount = 0
29
27
 
30
- const envs = buildCommandEnvs(normalizeDotenvConfigPath(this.envs), options.convention)
28
+ const envs = this.envs
31
29
 
32
30
  try {
33
31
  const sesh = new Session()
@@ -36,6 +34,8 @@ async function get (key) {
36
34
  const { parsed: resolved, errors } = await getResolver({
37
35
  key,
38
36
  envs,
37
+ profile: options.profile,
38
+ convention: options.convention,
39
39
  overload: options.overload,
40
40
  all: options.all,
41
41
  envKeysFile: resolveEnvKeysFile(options.envKeysFile),
@@ -1,9 +1,9 @@
1
1
  const fs = require('node:fs')
2
2
  const process = require('node:process')
3
3
  const prompts = require('../../lib/helpers/prompts')
4
- const initEnvspec = require('../../lib/services/init')
5
- const scanSource = require('../../lib/envspec/discovery/scanSource')
6
- const discoverEnvFiles = require('../../lib/envspec/discovery/discoverEnvFiles')
4
+ const initEnvfile = require('../../lib/services/init')
5
+ const scanSource = require('../../lib/envfile/discovery/scanSource')
6
+ const discoverEnvFiles = require('../../lib/envfile/discovery/discoverEnvFiles')
7
7
  const createSpinner = require('../../lib/helpers/createSpinner')
8
8
  const { logger } = require('../../shared/logger')
9
9
  const catchAndLog = require('../../lib/helpers/catchAndLog')
@@ -17,12 +17,12 @@ module.exports = async function spec () {
17
17
  let spinner
18
18
 
19
19
  try {
20
- const existing = stdout ? undefined : fs.lstatSync('Dotenvspec', { throwIfNoEntry: false })
20
+ const existing = stdout ? undefined : fs.lstatSync('Envfile', { throwIfNoEntry: false })
21
21
  if (existing && !overwrite) {
22
- logger.info('○ Dotenvspec already exists [edit or run: spec --overwrite]')
22
+ logger.info('○ Envfile already exists [edit or run: spec --overwrite]')
23
23
  return
24
24
  }
25
- if (existing && !existing.isFile()) throw new Error('Cannot replace Dotenvspec: expected a regular file')
25
+ if (existing && !existing.isFile()) throw new Error('Cannot replace Envfile: expected a regular file')
26
26
 
27
27
  let envFiles
28
28
  let sourceKeys = []
@@ -33,8 +33,8 @@ module.exports = async function spec () {
33
33
  if (interactive && !envFile) {
34
34
  const candidates = discoverEnvFiles()
35
35
  const selected = await prompts.multiselect({
36
- message: existing ? 'Recreate Dotenvspec from .env files and code' : 'Create Dotenvspec from .env files and code',
37
- submitLabel: existing ? 'Recreate Dotenvspec' : 'Create Dotenvspec',
36
+ message: existing ? 'Recreate Envfile from .env files and code' : 'Create Envfile from .env files and code',
37
+ submitLabel: existing ? 'Recreate Envfile' : 'Create Envfile',
38
38
  choices: [...candidates, { name: 'code ./**/* (env references)', value: '__scan_source' }],
39
39
  initial: [...candidates, '__scan_source']
40
40
  })
@@ -49,16 +49,16 @@ module.exports = async function spec () {
49
49
  sourceKeys = keys
50
50
  }
51
51
 
52
- const { created, replaced, content } = initEnvspec({ envFile, envFiles, sourceKeys, overwrite, stdout, onFile })
52
+ const { created, replaced, content } = initEnvfile({ envFile, envFiles, sourceKeys, overwrite, stdout, onFile })
53
53
  if (spinner) spinner.stop()
54
54
  if (stdout) {
55
55
  process.stdout.write(content)
56
56
  return
57
57
  }
58
58
  if (created) {
59
- logger.success(replaced ? '◈ recreated (Dotenvspec)' : '◈ created (Dotenvspec)')
59
+ logger.success(replaced ? '◈ recreated (Envfile)' : '◈ created (Envfile)')
60
60
  logger.help('⮕ next run [dotenvx check]')
61
- } else logger.info('○ Dotenvspec already exists [edit or run: spec --overwrite]')
61
+ } else logger.info('○ Envfile already exists [edit or run: spec --overwrite]')
62
62
  } catch (error) {
63
63
  if (spinner) spinner.stop()
64
64
  catchAndLog(error)
@@ -0,0 +1,14 @@
1
+ const fs = require('node:fs')
2
+ const { profile, policy } = require('@dotenvx/primitives')
3
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
4
+
5
+ module.exports = function policyAction () {
6
+ try {
7
+ const source = fs.readFileSync('Envfile')
8
+ const file = profile(source, { f: this.opts().file ?? '.env' })
9
+ process.stdout.write(JSON.stringify(policy(source, file), null, 2) + '\n')
10
+ } catch (error) {
11
+ catchAndLog(error)
12
+ return { exitCode: 1, error }
13
+ }
14
+ }
@@ -0,0 +1,32 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { profile, policy, parse, check } = require('@dotenvx/primitives')
4
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
5
+
6
+ module.exports = async function primitivesCheck () {
7
+ try {
8
+ const source = fs.readFileSync('Envfile')
9
+ const file = profile(source, { f: this.opts().file ?? '.env' })
10
+ const rules = policy(source, file)
11
+ const processEnv = { ...process.env }
12
+ const keys = new Set(Object.keys(rules.keys))
13
+ for (const filename of file === '' ? [] : file.split(',')) {
14
+ const { parsed, injected, errors } = await parse(fs.readFileSync(filename), {
15
+ processEnv,
16
+ fk: path.join(path.dirname(filename), '.env.keys')
17
+ })
18
+ if (errors.length) throw new Error('Could not decrypt selected environment files')
19
+ for (const key of Object.keys(parsed)) keys.add(key)
20
+ for (const [key, value] of Object.entries(injected)) {
21
+ Object.defineProperty(processEnv, key, { value, enumerable: true, writable: true, configurable: true })
22
+ }
23
+ }
24
+ const finalEnv = Object.fromEntries([...keys].filter(key => Object.hasOwn(processEnv, key)).map(key => [key, processEnv[key]]))
25
+ const result = check(rules, finalEnv)
26
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n')
27
+ return { exitCode: result.errors.length ? 1 : 0 }
28
+ } catch (error) {
29
+ catchAndLog(error)
30
+ return { exitCode: 1, error }
31
+ }
32
+ }
@@ -0,0 +1,15 @@
1
+ const fs = require('node:fs')
2
+ const { profile } = require('@dotenvx/primitives')
3
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
4
+
5
+ module.exports = function primitivesProfile () {
6
+ try {
7
+ const source = fs.readFileSync('Envfile')
8
+ const options = this.opts()
9
+ const file = profile(source, { f: options.file, profile: options.profile, processEnv: process.env })
10
+ process.stdout.write(file + '\n')
11
+ } catch (error) {
12
+ catchAndLog(error)
13
+ return { exitCode: 1, error }
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ const { redact } = require('@dotenvx/primitives')
2
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
3
+
4
+ module.exports = async function primitivesRedact (text) {
5
+ try {
6
+ const options = this.opts()
7
+ if (options.stdin) {
8
+ if (text !== undefined) throw new Error('Cannot combine a text argument with --stdin')
9
+ process.stdin.setEncoding('utf8')
10
+ text = ''
11
+ for await (const chunk of process.stdin) text += chunk
12
+ }
13
+ if (text === undefined) throw new Error('Provide text or use --stdin')
14
+ process.stdout.write(redact(text, options.secret))
15
+ } catch (error) {
16
+ catchAndLog(error)
17
+ return { exitCode: 1, error }
18
+ }
19
+ }
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const plaintextKeys = require('../../lib/helpers/plaintextKeys')
4
- const protectEnvspec = require('../../lib/envspec/validation/protectEnvspec')
4
+ const protectEnvfile = require('../../lib/envfile/validation/protectEnvfile')
5
5
  const { logger } = require('../../shared/logger')
6
6
  const createProtectSpinner = require('../../lib/helpers/createProtectSpinner')
7
7
  const logProtectedFiles = require('../../lib/helpers/logProtectedFiles')
@@ -26,7 +26,7 @@ function check (filepath, content, beforeError = () => {}) {
26
26
  let rejected = null
27
27
  if (!privateKeyFile) {
28
28
  try {
29
- rejected = protectEnvspec(filepath, content.toString('utf8'))
29
+ rejected = protectEnvfile(filepath, content.toString('utf8'))
30
30
  } catch (error) {
31
31
  beforeError()
32
32
  logger.error(error.message)