Skip to content

Commit 4d566e6

Browse files
committed
plugins docs, 1pass plugin, general cleanup
1 parent 9161687 commit 4d566e6

File tree

33 files changed

+758
-278
lines changed

33 files changed

+758
-278
lines changed

.cursor/rules/varlock.mdc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ actions:
2828

2929
1. File Structure:
3030
```
31-
.env.schema # Schema definition with decorators
32-
.env # Local development values
31+
.env.schema # Schema definition with decorators and default values
32+
.env.local # Local (git-ignored) development overrides
3333
.env.production # Production values
3434
.env.staging # Staging values
3535
```
@@ -41,7 +41,7 @@ actions:
4141
- Values can be strings, numbers, booleans, or function calls
4242

4343
3. Root Level Decorators:
44-
- @envFlag - Sets environment flag key
44+
- @currentEnv - Sets current environment env var (e.g., `@currentEnv=$APP_ENV`)
4545
- @defaultRequired - Sets default required state for all items
4646
- @defaultSensitive - Sets default sensitive state for all items
4747

@@ -52,7 +52,7 @@ actions:
5252
4. Item Level Decorators:
5353
- @required - Makes item required (omit if @defaultRequired=true)
5454
- @sensitive - Marks item as sensitive (omit if @defaultSensitive=true)
55-
- @type - Sets value type
55+
- @type - Sets value type (omit if basic string with no additional settings)
5656
- @example - Provides example value
5757
- @trim - Trims whitespace
5858
- @deindent - Trims leading whitespace
@@ -112,10 +112,18 @@ examples:
112112
- input: |
113113
# Bad: Missing type decorator
114114
PORT=3000
115+
# Bad: Unnecessary type decorator for basic string
116+
# @type=string
117+
BASIC_STRING
115118

116-
# Good: With type decorator
119+
# Good: With type decorators when necessary
117120
# @type=port
118121
PORT=3000
122+
# @type=string(startsWith=abc_)
123+
STRING_WITH_VALIDATION=
124+
# no @type necessary for basic strings
125+
BASIC_STRING=
126+
119127
output: "Environment variable with proper type"
120128

121129
metadata:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
## Varlock
1717
> add declarative schema to your .env files using @env-spec decorator comments
1818
19-
- 🛡️ validation, coercion, type safety w/ Intellisense
19+
- 🛡️ validation, coercion, type safety w/ IntelliSense
2020
- 🔏 protection for sensitive config values (log redaction, leak prevention)
2121
- 🌐 flexible multi-environment management
2222
- 💫 composition of values, functions, load from external sources
2323

2424
Your `.env.schema` is a declarative schema of your environment variables that lives within version control, so it will never be out of sync.
2525

2626
```bash
27-
# @defaultSensitive=false @defaultRequired=infer @envFlag=APP_ENV
27+
# @defaultSensitive=false @defaultRequired=infer @currentEnv=$APP_ENV
2828
# ---
2929
# our environment flag, will control automatic loading of `.env.xxx` files
3030
# @type=enum(development, preview, production, test

packages/integrations/nextjs/src/next-env-compat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function loadEnvConfig(
289289

290290
// we must match @next/env default behaviour for which .env.XXX files to load
291291
// which is based on the current command (`next dev` vs `next build`) and `NODE_ENV=test`
292-
// however we will pass it through and let the user ignore it by setting their own `@envFlag`
292+
// however we will pass it through and let the user ignore it by setting their own `@currentEnv`
293293
let envFromNextCommand = dev ? 'development' : 'production';
294294
if (process.env.NODE_ENV === 'test') envFromNextCommand = 'test';
295295
debug('Inferred env mode (to match @next/env):', envFromNextCommand);

packages/plugins/1password/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ OP_TOKEN=
2525
2626
# pull items from 1pass using new `op()` resolver
2727
XYZ_API_TOKEN=op("op://api-config/xyz/api-key")
28-
```
28+
```

packages/plugins/1password/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@varlock/1password-plugin",
3-
"description": "Varlock plugin to pull data from 1Password",
3+
"description": "Varlock plugin to pull data from 1password",
44
"version": "0.0.0",
55
"type": "module",
66
"repository": {

packages/plugins/1password/tsconfig.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/varlock-website/.env.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This .env file uses https://varlock.dev
22
#
33
# @defaultRequired=infer @defaultSensitive=false
4-
# @envFlag=APP_ENV
4+
# @currentEnv=$APP_ENV
55
# @generateTypes(lang='ts', path='env.d.ts')
66
# ---
77

packages/varlock-website/astro.config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default defineConfig({
3434
provider: fontProviders.google(),
3535
name: 'Inter',
3636
cssVariable: '--font-default',
37+
weights: ['300', '400', '700'],
3738
},
3839
],
3940
},
@@ -80,7 +81,8 @@ export default defineConfig({
8081
{ label: 'Schema', slug: 'guides/schema' },
8182
{ label: 'Secrets', slug: 'guides/secrets' },
8283
{ label: 'Environments', slug: 'guides/environments' },
83-
{ label: '@import', slug: 'guides/import' },
84+
{ label: 'Imports', slug: 'guides/import' },
85+
{ label: 'Plugins', slug: 'guides/plugins' },
8486
{ label: 'Migrate from dotenv', slug: 'guides/migrate-from-dotenv' },
8587
{ label: 'Telemetry', slug: 'guides/telemetry' },
8688
{ label: 'MCP', slug: 'guides/mcp', badge: 'new' },
@@ -102,6 +104,13 @@ export default defineConfig({
102104
{ label: 'GitHub Actions', slug: 'integrations/github-action' },
103105
],
104106
},
107+
{
108+
label: 'Plugins',
109+
items: [
110+
{ label: 'Overview', slug: 'plugins/overview' },
111+
{ label: '1Password', slug: 'plugins/1password' },
112+
],
113+
},
105114
{
106115
label: 'Reference',
107116
items: [
41.9 KB
Loading

packages/varlock-website/src/content/docs/env-spec/reference.mdx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BAZ= # @dec # this is @ignored too
5757

5858
### Decorators
5959

60-
Decorators are used within comments to attach structured data to specific config items, or within a standalone comment blockto alter a group of items or the entire document and loading process.
60+
Decorators are used within comments to attach structured data to specific config items, or within a standalone comment block to alter a group of items or the entire document and loading process.
6161

6262
- Each decorator has a name and optional value (`@name=value`) or is a bare function call `@func()`
6363
- Decorators with values may only be used once per comment block, while function calls may be used multiple times
@@ -91,7 +91,7 @@ A divider is a comment that serves as a separator, like a `<hr/>` in HTML.
9191
# ---
9292
ITEM1=
9393
ITEM2=
94-
# --- another divider ---
94+
# --- another divider ---
9595
ITEM3=
9696
```
9797

@@ -100,9 +100,9 @@ ITEM3=
100100
### Config Item Comments
101101
Comment lines directly preceeding an item will be attached to that item, along with the decorators contained within.
102102

103-
- A blank line or a divider will break the above comments from being attached to the item
103+
- A blank line or a divider will break the above comments from being attached to the item below
104104
- Both decorator and regular comment lines may be interspersed
105-
- Post-value comments may also contain decorators, but is not recommended
105+
- Post-value comments may also contain decorators, but should be used sparingly
106106

107107
```env-spec
108108
# these comments are attached to ITEM1 below
@@ -162,6 +162,7 @@ Values are interpreted similarly for config item values, decorator values, and v
162162
- A value in quotes is _always_ treated as a string -- `@d1="with spaces"`, `@trueString="true"`, `@numStr="123"`
163163
- All quote styles ``[`'"]`` are ok -- ``@dq="c" @bt=`b` @sq='a'``
164164
- Escaped quotes matching the wrapping quote style are ok -- `@ok="escaped\"quote"`
165+
- Single quote wrapped strings do not support [expansion (see below)](#expansion)
165166
- In `"` or `` ` `` wrapped values, the string `\n` will be converted to an actual newline
166167
- Multi-line strings may be wrapped in ``(```|"""|"|')``
167168
- only available for config item values, not decorators or within function args
@@ -175,7 +176,7 @@ In each case, much of the handling is the same.
175176
- a value must not be wrapped in quotes to be interpreted as a function call
176177
- function names must start with a letter, and can then contain letters, numbers, and underscores `/[a-ZA-Z][a-ZA-Z0-9_]*/`
177178
- you can pass no args, a single arg, or multiple args
178-
- you may also pass key value pairs at the end of the list, and they will be combined into a single object at the end of the array
179+
- you may also pass key value pairs at the end of the list
179180
- each value will be interpreted using common value-handling rules (see above)
180181

181182
```env-spec
@@ -184,4 +185,28 @@ SINGLE_ARG=fn(asdf)
184185
MULTIPLE_ARGS=fn(one, "two", three, 123.456)
185186
KEY_VALUE_ARGS=fn(key1=v1, key2="v2", key3=true)
186187
MIXED_ARGS=fn(item1, item2, key1=v1, key2="v2", key3=true)
188+
NOT_FN_CALL="fn()" # treated as string
187189
```
190+
191+
### String expansion ||expansion||
192+
While the parser itself does not include any implemention of specific functions, it does handle _expansion_ of strings - and it uses several function calls under the hood to do so. This means a few basic function calls, while not implemented, have specific inherent meaning and must be implemented similarly across all tools that support this spec.
193+
194+
Expansion can be used within item values, decorator values, and function call arguments.
195+
196+
_Note that single quote wrapped strings are NOT expanded._
197+
198+
- `$ITEM_NAME` -> `ref(ITEM_NAME)`
199+
- `${ITEM_NAME}` -> `ref(ITEM_NAME)`
200+
- `pre${ITEM_NAME}post` -> `concat("pre", ref(ITEM_NAME), "post")`
201+
- `${ITEM_NAME:-defaultval}` -> `fallback(ref(ITEM_NAME), "defaultval")`
202+
- `${ITEM_NAME-defaultval}` -> `fallback(ref(ITEM_NAME), "defaultval")`
203+
- `$(my-cli arg --arg2)` -> `exec("my-cli arg --arg2")`
204+
205+
:::note[Keep it simple]
206+
We recommend using expansion only for simple refs `$ITEM`/`${ITEM}` and skipping the rest.
207+
208+
- Use bracketed version within a larger string - `fn("${ENV}_db")`
209+
- Skip the brackets otherwise - `fn($ENV)`
210+
211+
The rest is implemented to match other popular tools, but we do not recommend using them, as intent can be more clearly expressed using function calls directly.
212+
:::

0 commit comments

Comments
 (0)