opencode.env 0.0.0 → 0.0.1
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 +53 -55
- package/dist/index.mjs +19 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
# opencode
|
|
1
|
+
# opencode.env
|
|
2
2
|
|
|
3
|
-
OpenCode plugin that
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
OpenCode plugin that loads `.env` files and direnv environment variables into
|
|
4
|
+
every shell invocation.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **`.env` file loading** — Load one or more `.env` files and inject them into every shell invocation.
|
|
9
|
+
- **Direnv integration** — Automatically pulls environment variables from [direnv](https://direnv.net/).
|
|
10
|
+
- **Inline variable definitions** — Define `KEY: "value"` pairs directly in config.
|
|
11
|
+
- **Multi-layer config** — Global (`~/.opencode.env.json`), project (`.opencode.env.json`), and opencode (`.opencode/env.json`) layers merged together.
|
|
12
|
+
- **CWD support** — Automatically loads `.env` files from the current working directory when different from the project root.
|
|
13
|
+
- **Selective disabling** — Independently disable global config, CWD loading, or direnv.
|
|
6
14
|
|
|
7
15
|
## Usage
|
|
8
16
|
|
|
@@ -10,7 +18,7 @@ Add to your OpenCode config (`opencode.json`):
|
|
|
10
18
|
|
|
11
19
|
```json
|
|
12
20
|
{
|
|
13
|
-
"plugin": ["opencode
|
|
21
|
+
"plugin": ["opencode.env"]
|
|
14
22
|
}
|
|
15
23
|
```
|
|
16
24
|
|
|
@@ -19,72 +27,62 @@ Add to your OpenCode config (`opencode.json`):
|
|
|
19
27
|
Create a config file in any of these locations. Layers are merged in this order
|
|
20
28
|
(later wins and merged instead of replacing):
|
|
21
29
|
|
|
22
|
-
1. `~/.opencode
|
|
23
|
-
2. `./.opencode
|
|
24
|
-
3. `./.opencode/
|
|
30
|
+
1. `~/.opencode.env.json` — global
|
|
31
|
+
2. `./.opencode.env.json` — project root
|
|
32
|
+
3. `./.opencode/env.json` — project root
|
|
25
33
|
|
|
26
34
|
```json
|
|
27
35
|
{
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"message": "Blocked: `{{COMMAND}}` (matched `{{PATTERN}}`)",
|
|
32
|
-
"blacklist": {
|
|
33
|
-
"commands": ["custom-pattern"],
|
|
34
|
-
"disableDefaults": false,
|
|
35
|
-
"disableGlobal": false
|
|
36
|
-
},
|
|
37
|
-
"whitelist": {
|
|
38
|
-
"commands": ["vitest"],
|
|
39
|
-
"disableDefaults": false,
|
|
40
|
-
"disableGlobal": false
|
|
41
|
-
}
|
|
36
|
+
"files": [".env", ".env.local"],
|
|
37
|
+
"define": {
|
|
38
|
+
"NODE_ENV": "development"
|
|
42
39
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"disableDefaults": false,
|
|
47
|
-
"disableGlobal": false,
|
|
48
|
-
"disableCwd": false
|
|
49
|
-
},
|
|
50
|
-
"command": {
|
|
51
|
-
"before": { "command": "set -e", "comment": "Fail fast" },
|
|
52
|
-
"after": { "command": "echo done", "comment": "Notify" }
|
|
53
|
-
}
|
|
40
|
+
"disableDirenv": false,
|
|
41
|
+
"disableGlobal": false,
|
|
42
|
+
"disableCwd": false
|
|
54
43
|
}
|
|
55
44
|
```
|
|
56
45
|
|
|
57
|
-
### `
|
|
46
|
+
### `files`
|
|
47
|
+
|
|
48
|
+
Array of `.env`-style file paths to load (resolved relative to the project root,
|
|
49
|
+
or `~/` for home directory). Variables are merged in order — later files
|
|
50
|
+
override earlier ones.
|
|
51
|
+
|
|
52
|
+
### `define`
|
|
53
|
+
|
|
54
|
+
Inline `KEY: "value"` map of environment variables. These are merged over
|
|
55
|
+
file-based variables, so they take precedence.
|
|
56
|
+
|
|
57
|
+
### `disableDirenv`
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
whitespace-normalized.
|
|
59
|
+
Set to `true` to skip loading environment variables from [direnv](https://direnv.net/).
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
- `blacklist` / `whitelist` — `commands` are substring patterns. `disableDefaults` skips the built-in list; `disableGlobal` skips the global config's list.
|
|
64
|
-
- `message` — custom block error. Placeholders: `{{COMMAND}}`, `{{PATTERN}}`.
|
|
61
|
+
### `disableGlobal`
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
`yarn start`, `npx vite`, `npx next`, `npx nodemon`, `npx tsx watch`,
|
|
68
|
-
`node --watch`, `pm2 start`. `npx next lint` is allowed by default.
|
|
63
|
+
Set to `true` to ignore the global config's `files` and `define` settings.
|
|
69
64
|
|
|
70
|
-
### `
|
|
65
|
+
### `disableCwd`
|
|
71
66
|
|
|
72
|
-
|
|
67
|
+
By default, `.env` files from the current working directory are also loaded
|
|
68
|
+
(if different from the project root). Set to `true` to load only from the
|
|
69
|
+
project root.
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
- `files` — additional `.env`-style files to load (resolved relative to project root, or `~/` for home).
|
|
76
|
-
- `disableDefaults` — skip the built-in `.env` file list.
|
|
77
|
-
- `disableGlobal` — skip the global config's `define` and `files`.
|
|
78
|
-
- `disableCwd` — by default, `.env` files from the current working directory are also loaded. Set to `true` to load only from the project root.
|
|
71
|
+
## How it works
|
|
79
72
|
|
|
80
|
-
|
|
73
|
+
The plugin hooks into OpenCode's `shell.env` lifecycle. Before every bash
|
|
74
|
+
invocation, it resolves environment variables from:
|
|
81
75
|
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
1. Inline `define` values from config (global → project → opencode)
|
|
77
|
+
2. `.env` files listed in config
|
|
78
|
+
3. Current working directory `.env` files (unless `disableCwd`)
|
|
79
|
+
4. [direnv](https://direnv.net/) output (unless `disableDirenv`)
|
|
84
80
|
|
|
85
|
-
|
|
81
|
+
All resolved variables are injected into the shell environment so they are
|
|
82
|
+
available to your commands.
|
|
86
83
|
|
|
87
84
|
## Debugging
|
|
88
85
|
|
|
89
|
-
Set `
|
|
90
|
-
`os.tmpdir()/.opencode-
|
|
86
|
+
Set `OPENCODE_ENV_LOG_ENABLED=true` to write logs to
|
|
87
|
+
`os.tmpdir()/.opencode.env-logs/`. Use `OPENCODE_ENV_LOG_PATH` to specify a
|
|
88
|
+
custom log directory.
|