@jondotsoy/envs 0.1.1 → 0.1.3
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/README.md +48 -46
- package/SECURITY.md +29 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
# @jondotsoy/envs
|
|
2
2
|
|
|
3
|
-
CLI
|
|
3
|
+
CLI that keeps the `.env` values of every git worktree in a single file (`.envs/values.yml`). Edit all values together and distribute them to each worktree, or collect them from the existing `.env` files.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Requires [Bun](https://bun.com) and git.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Installation
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
12
|
bun add -g @jondotsoy/envs
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Or without installing:
|
|
14
16
|
|
|
15
17
|
```bash
|
|
16
18
|
bunx @jondotsoy/envs help
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
##
|
|
21
|
+
## Usage
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
Run the commands inside the repo or any of its worktrees. Inside a worktree, `.envs/` always lives in the main repo.
|
|
22
24
|
|
|
23
|
-
|
|
|
25
|
+
| Command | What it does |
|
|
24
26
|
| --- | --- |
|
|
25
|
-
| `envs init` |
|
|
26
|
-
| `envs pull` |
|
|
27
|
-
| `envs push` |
|
|
28
|
-
| `envs lint` |
|
|
29
|
-
| `envs edit` |
|
|
30
|
-
| `envs help` |
|
|
27
|
+
| `envs init` | Creates `.envs/`, `.envs/.gitignore` (containing `*`) and an empty `.envs/values.yml`. Does not overwrite existing files. |
|
|
28
|
+
| `envs pull` | Reads the `.env` of the main repo and of each worktree and writes it to `values.yml`. Variables that are no longer in a `.env` are removed from `values.yml` for that worktree. |
|
|
29
|
+
| `envs push` | Writes `values.yml` to the `.env` of each worktree. Updates existing variables in place, appends new ones at the end, and keeps comments and variables that are not in `values.yml`. |
|
|
30
|
+
| `envs lint` | Checks security and prints a warning for each problem. Exits with code 1 if there is any (useful in CI). See below. |
|
|
31
|
+
| `envs edit` | Runs `pull`, opens `values.yml` with `code -w` and, when the editor closes, runs `push`. If the editor fails, it does not `push`. |
|
|
32
|
+
| `envs help` | Shows the help. |
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
Worktrees are identified by their branch name (or their folder name if they are in detached HEAD). The main repo uses its branch name, for example `main`.
|
|
33
35
|
|
|
34
36
|
### `envs lint`
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
It never prints values, only the variable and its location (`envs.DB_PASSWORD.main`).
|
|
37
39
|
|
|
38
|
-
|
|
|
40
|
+
| Rule | Detects |
|
|
39
41
|
| --- | --- |
|
|
40
|
-
| `tracked-values`, `unignored-values` | `values.yml`
|
|
41
|
-
| `tracked-dotenv`, `unignored-dotenv` |
|
|
42
|
-
| `open-permissions` | `values.yml`
|
|
43
|
-
| `executable-files` | `values.yml`
|
|
44
|
-
| `writable-files` | `values.yml`
|
|
45
|
-
| `weak-secret` |
|
|
46
|
-
| `shared-secret` |
|
|
47
|
-
| `secret-pattern` |
|
|
48
|
-
| `url-credentials`, `insecure-url` | URL
|
|
49
|
-
|
|
50
|
-
##
|
|
42
|
+
| `tracked-values`, `unignored-values` | `values.yml` is tracked by git or is not ignored. |
|
|
43
|
+
| `tracked-dotenv`, `unignored-dotenv` | A worktree's `.env` is tracked or is not ignored. |
|
|
44
|
+
| `open-permissions` | `values.yml` is readable by other users (use `chmod 600`). |
|
|
45
|
+
| `executable-files` | `values.yml` or a `.env` has the execute permission (use `chmod -x`). |
|
|
46
|
+
| `writable-files` | `values.yml` or a `.env` is writable by the group or other users (use `chmod go-w`). |
|
|
47
|
+
| `weak-secret` | Sensitive variable (`PASSWORD`, `TOKEN`, `SECRET`, `API_KEY`…) that is empty or has a typical value (`changeme`, `admin`…). |
|
|
48
|
+
| `shared-secret` | Sensitive variable in `defaults`, which is written to all worktrees. |
|
|
49
|
+
| `secret-pattern` | Value with a known secret format (AWS, GitHub, Slack, `sk-…`, private key). |
|
|
50
|
+
| `url-credentials`, `insecure-url` | Remote URL with an embedded password, or using `http://`, `ws://` or `ftp://`. |
|
|
51
|
+
|
|
52
|
+
## `values.yml` format
|
|
51
53
|
|
|
52
54
|
```yaml
|
|
53
55
|
defaults:
|
|
@@ -62,42 +64,42 @@ envs:
|
|
|
62
64
|
feature-x: "3001"
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
- `defaults`:
|
|
66
|
-
- `envs.<VARIABLE>.<worktree>`:
|
|
67
|
-
-
|
|
67
|
+
- `defaults`: default value of each variable. `push` writes it to the `.env` of all worktrees.
|
|
68
|
+
- `envs.<VARIABLE>.<worktree>`: value of the variable in that worktree. It overrides the value from `defaults`.
|
|
69
|
+
- Values can be strings, numbers or booleans (`PORT: 3000`, `DEBUG: true`); `push` writes them to the `.env` as text (`PORT=3000`, `DEBUG=true`). `pull` converts `true`/`false` and canonical numbers (`3000`, `0.5`) to booleans and numbers; anything else (`007`, `1e3`) stays a string.
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
The schema (JSON Schema) is at [`schema/values.schema.json`](schema/values.schema.json). To have VS Code validate the file with the YAML extension, add this at the top of `values.yml`:
|
|
70
72
|
|
|
71
73
|
```yaml
|
|
72
74
|
# yaml-language-server: $schema=../schema/values.schema.json
|
|
73
75
|
```
|
|
74
76
|
|
|
75
|
-
##
|
|
77
|
+
## Development
|
|
76
78
|
|
|
77
79
|
```bash
|
|
78
80
|
bun install
|
|
79
|
-
bun test #
|
|
80
|
-
bun test --coverage #
|
|
81
|
-
bun run build #
|
|
81
|
+
bun test # run the tests
|
|
82
|
+
bun test --coverage # with coverage
|
|
83
|
+
bun run build # generates dist/ (envs.js and package.json)
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
- `src/envs.ts`:
|
|
85
|
-
- `test/fixtures/workspace.ts`:
|
|
86
|
+
- `src/envs.ts`: command logic. `src/bin/envs.ts`: CLI entry point.
|
|
87
|
+
- `test/fixtures/workspace.ts`: `createWorkspace({ main, worktrees, files })` fixture, which creates a temporary git repo with worktrees, each in its own temporary folder.
|
|
86
88
|
|
|
87
|
-
##
|
|
89
|
+
## Publishing
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
The **Publish** workflow (Actions → Publish → Run workflow) bumps the version, builds and publishes `dist/` to npm via OIDC (trusted publishing). Inputs:
|
|
90
92
|
|
|
91
|
-
- `bump`: `major`, `minor`, `patch`
|
|
92
|
-
- `tag`: dist-tag
|
|
93
|
-
- `provenance`:
|
|
93
|
+
- `bump`: `major`, `minor`, `patch` or `prerelease`.
|
|
94
|
+
- `tag`: npm dist-tag (`latest`, `default`, `alpha` or `demo`). With a tag other than `latest` the version is a prerelease (`0.0.2-alpha.0`).
|
|
95
|
+
- `provenance`: publish with provenance. npm only accepts it if the repository is public.
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
After publishing, it creates the version commit and tag, and a GitHub release linking to the version on npm.
|
|
96
98
|
|
|
97
|
-
##
|
|
99
|
+
## Security
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
To report a vulnerability, see [SECURITY.md](SECURITY.md).
|
|
100
102
|
|
|
101
|
-
##
|
|
103
|
+
## License
|
|
102
104
|
|
|
103
105
|
[MIT](LICENSE)
|
package/SECURITY.md
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Security Policy
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Supported versions
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Only the latest version of `@jondotsoy/envs` published on npm is maintained. Security fixes are released in a new version.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Reporting a vulnerability
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Do not open a public issue to report a vulnerability. Report it privately through one of these channels:
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- GitHub's private vulnerability reporting: the repository's **Security** tab, **Report a vulnerability**.
|
|
12
|
+
- By email to [hi@jon.soy](mailto:hi@jon.soy).
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
If you can, include:
|
|
15
15
|
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
16
|
+
- the version of `@jondotsoy/envs` and of Bun you use;
|
|
17
|
+
- a description of the problem and its impact;
|
|
18
|
+
- the steps to reproduce it.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
I will reply as soon as possible and we will coordinate the fix and the disclosure of the issue.
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Files it modifies
|
|
23
23
|
|
|
24
|
-
`envs`
|
|
24
|
+
`envs` only reads and writes the files in this table. `<root>` is the main repo (inside a worktree, the parent repo) and `<worktree>` is the folder of each worktree listed by `git worktree list`, including the main repo, even if it is outside `<root>`.
|
|
25
25
|
|
|
26
|
-
|
|
|
26
|
+
| Command | Reads | Writes |
|
|
27
27
|
| --- | --- | --- |
|
|
28
|
-
| `envs init` | — |
|
|
29
|
-
| `envs pull` | `<worktree>/.env`
|
|
30
|
-
| `envs push` | `<
|
|
31
|
-
| `envs edit` |
|
|
28
|
+
| `envs init` | — | Creates `<root>/.envs/`, `<root>/.envs/.gitignore` and `<root>/.envs/values.yml`, only if they do not exist. Never overwrites. |
|
|
29
|
+
| `envs pull` | `<worktree>/.env` of each worktree | Rewrites `<root>/.envs/values.yml`. The file is serialized again, so YAML comments are lost. |
|
|
30
|
+
| `envs push` | `<root>/.envs/values.yml` | Creates or updates `<worktree>/.env` of each worktree that has values. Updates existing variables in place, appends new ones at the end and keeps the rest of the file. If there are `defaults`, this includes all worktrees. |
|
|
31
|
+
| `envs edit` | Same as `pull` and `push` | Same as `pull` and `push`. It also runs `code -w <root>/.envs/values.yml`. |
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Additionally:
|
|
34
34
|
|
|
35
|
-
-
|
|
36
|
-
- `envs edit`
|
|
37
|
-
-
|
|
35
|
+
- It runs `git rev-parse` and `git worktree list` to locate the root and the worktrees. These are read-only commands.
|
|
36
|
+
- `envs edit` runs the `code` program found in the `PATH`.
|
|
37
|
+
- It makes no network connections and does not modify other project files, not even your project's `.gitignore`.
|
|
38
38
|
|
|
39
|
-
##
|
|
39
|
+
## Handling secrets
|
|
40
40
|
|
|
41
|
-
`envs`
|
|
41
|
+
`envs` works with values that are often secrets:
|
|
42
42
|
|
|
43
|
-
- `.envs/values.yml`
|
|
44
|
-
- `envs init`
|
|
45
|
-
- `envs push`
|
|
46
|
-
-
|
|
43
|
+
- `.envs/values.yml` stores the values of all worktrees in plain text.
|
|
44
|
+
- `envs init` creates `.envs/.gitignore` with `*`, so the `.envs/` folder is not committed to git. Do not remove that file.
|
|
45
|
+
- `envs push` writes the values to the `.env` files of each worktree. Make sure `.env` is in your project's `.gitignore`.
|
|
46
|
+
- Do not share `values.yml` or paste it in issues or logs.
|