Skip to content

Commit 9c63b2a

Browse files
committed
more wip
1 parent 7958d29 commit 9c63b2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2793
-972
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PRs are always welcome.
1+
PRs are always welcome.
22

33
**First, please read our [Code of Conduct](CODE_OF_CONDUCT.md).**
44

@@ -31,7 +31,11 @@ pnpm build:libs
3131
- [packages/vscode-plugin](./packages/vscode-plugin) - VSCode extension for @env-spec
3232
- [packages/integrations/nextjs](./packages/integrations/nextjs) - Next.js integration for varlock
3333

34-
> See the README.md for each package for more details.
34+
> See the README.md for each package for more details.
3535
3636

37+
## Debugging
3738

39+
It is often useful to enable source maps in traces during local development.
40+
41+
To do so run `export NODE_OPTIONS=--enable-source-maps` in your active terminal.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ APP_ENV=development # default value, can override
3232

3333
# API port
3434
# @type=port @example=3000
35-
API_PORT=
35+
API_PORT=
3636

3737
# API url including _expansion_ referencing another env var
3838
# @required @type=url
39-
API_URL=http://localhost:${API_PORT}
39+
API_URL=http://localhost:${API_PORT}
4040

4141
# API key with validation, securely fetched from 1Password
4242
# @required @sensitive @type=string(startsWith=sk-)
@@ -49,7 +49,7 @@ SOME_SERVICE_API_URL=https://api.someservice.com
4949

5050
## Installation
5151

52-
You can get started with varlock by installing the CLI:
52+
You can get started with varlock by installing the CLI:
5353

5454
```bash
5555
# Run the installation wizard, which will install as a dependency in a JavaScript project
@@ -67,13 +67,13 @@ See the full [installation docs](https://varlock.dev/getting-started/installatio
6767

6868
## Workflow
6969

70-
Validate your `.env.schema` and pretty print your environment variables with:
70+
Validate your `.env.schema` and pretty print your environment variables with:
7171

7272
```bash
7373
varlock load
7474
```
7575

76-
If you need to pass resolved env vars into another process, you can run:
76+
If you need to pass resolved env vars into another process, you can run:
7777

7878
```bash
7979
varlock run -- python script.py
@@ -85,7 +85,7 @@ Or you can integrate more deeply with one of our [integrations](https://varlock.
8585

8686
Varlock is built on top of @env-spec, a new DSL for attaching a schema and additional functionality to .env files using JSDoc style comments. The @env-spec package contains a parser and info about the spec itself.
8787

88-
- @env-spec [docs](https://varlock.dev/env-spec/overview/)
88+
- @env-spec [docs](https://varlock.dev/env-spec/overview/)
8989
- @env-spec [RFC](https://github.com/dmno-dev/varlock/discussions/17)
9090

9191

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# @plugin(./node_modules/@varlock/1password-plugin)
3+
# # @initPlugin(@varlock/1password-plugin, id=1pass, token=$OP_TOKEN, allowAppAuth=false)
4+
#
5+
# # @plugin(https://varlock-plugins-registry.dmno.workers.dev/varlock-1password-plugin-0.0.0.tgz)
6+
# @initOpVault(id=v1, account=dmnoinc, token=$OP_TOKEN, allowAppAuth=forEnv(dev))
7+
# # @initOpVault(id=v2, account=dmnoinc, token=$OP_TOKEN, allowAppAuth=true)
8+
#
9+
#
10+
# @defaultRequired=infer @defaultSensitive=false
11+
# ---
12+
13+
14+
# @sensitive @type=opServiceAccountToken
15+
OP_TOKEN=
16+
17+
OP_VAULT_NAME=example
18+
19+
OP1=op(v1, "op://dev test/${OP_VAULT_NAME}/credential")
20+
# OP2=op(v2, "op://dev test/${OP_VAULT_NAME}/staging")
21+
OP3=op(v1, "op://dev test/${OP_VAULT_NAME}/production")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
z# @defaultRequired=infer @defaultSensitive=false
2+
# @generateTypes(lang=ts, path=env.d.ts)
3+
#
4+
# @currentEnv=$APP_ENV
5+
# # @envFlag=APP_ENV
6+
# # @badDecorator
7+
#
8+
# @import(./.env.op)
9+
# ---
10+
11+
# our environment flag
12+
# @type=enum(dev, preview, prod, test)
13+
# @docsUrl=https://example.com/docs/app_env
14+
APP_ENV=dev
15+
16+
# some description
17+
# @required=true
18+
# @docs(https://example1.com)
19+
# @docs("Link label", https://example1.com)
20+
# @icon="streamline-block:smileys-sad"
21+
ITEM1=foo
22+
23+
FOR_ENV_CHECK=forEnv(dev)
24+
25+
EQ_CHECK=eq(1, 2)
26+
27+
IF_EQ_CHECK=if(eq(1, 1), "yes", "no")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "plugin-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"load": "varlock load"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"@varlock/1password-plugin": "link:../../../packages/plugins/1password",
15+
"varlock": "link:../../../packages/varlock"
16+
},
17+
"packageManager": "pnpm@10.14.0"
18+
}

example-monorepo/pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@
4444
"node": ">=22",
4545
"pnpm": ">=10"
4646
},
47-
"packageManager": "pnpm@10.14.0"
47+
"packageManager": "pnpm@10.18.3+sha512.bbd16e6d7286fd7e01f6b3c0b3c932cda2965c06a908328f74663f10a9aea51f1129eea615134bf992831b009eabe167ecb7008b597f40ff9bc75946aadfb08d"
4848
}

packages/env-spec-parser/grammar.peggy

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ ConfigItem =
4040
});
4141
}
4242

43-
ConfigItemKey =
44-
$([a-zA-Z_] [a-zA-Z0-9_.-]*)
43+
ConfigItemKey = $([a-zA-Z_] [a-zA-Z0-9_.-]*)
4544

4645
ConfigItemValue = FunctionCall / multiLineString / quotedString / unquotedString
4746

48-
49-
5047
CommentBlock =
5148
// not sure if we want to treat these as decorators if within comment block?
5249
comments:(@(IgnoredDecoratorComment / DecoratorComment / Comment) _n)+
@@ -59,7 +56,7 @@ CommentBlock =
5956
})
6057
}
6158

62-
Comment =
59+
Comment =
6360
!(Divider)
6461
"#" leadingSpace:$_ contents:$(
6562
// $("@" [a-zA-Z]+ ":"? __ [a-zA-Z] [^@\n]*)
@@ -98,17 +95,17 @@ DecoratorComment =
9895
})
9996
}
10097

101-
Decorator =
98+
Decorator =
10299
"@" name:DecoratorName
103-
valueOrFnArgs:(
104-
"()" { return new ParsedEnvSpecFunctionArgs({ values: [] })}
105-
/ ("(" @FunctionArgs? ")")
106-
/ ("=" @(DecoratorValue))
100+
val:(
101+
FunctionArgs
102+
/ "=" DecoratorValue
107103
)?
108104
{
109105
return new ParsedEnvSpecDecorator({
110106
name,
111-
valueOrFnArgs,
107+
value: Array.isArray(val) ? val[1] : val,
108+
isBareFnCall: val && !Array.isArray(val),
112109
_location: location(),
113110
})
114111
}
@@ -121,36 +118,44 @@ DecoratorValue = FunctionCall / quotedString / unquotedStringWithoutSpaces
121118

122119

123120
FunctionCall =
124-
name:FunctionName "(" _ args:FunctionArgs? _ ")"
121+
name:FunctionName
122+
args:FunctionArgs // includes the parens
125123
{
126124
return new ParsedEnvSpecFunctionCall({
127125
name,
128-
args: args || new ParsedEnvSpecFunctionArgs({ values: [] }),
126+
args,
129127
_location: location(),
130128
});
131129
}
130+
132131
FunctionName = $([a-zA-Z] [a-zA-Z0-9_]*)
132+
133+
// function args are a list, can be either array, or key/value, or mixed
134+
// fn(arr1, arry2, key=val, key2=val2)
133135
FunctionArgs =
136+
"(" _
134137
values:(
135138
(
136139
(key:FunctionArgKeyName "=" val:FunctionArgValue { return new ParsedEnvSpecKeyValuePair({ key, val })})
137140
/ FunctionArgValue
138141
)|1.., _ "," _|
139-
)
142+
)?
143+
_ ")"
140144
{
141145
return new ParsedEnvSpecFunctionArgs({
142-
values,
146+
values: values || [],
143147
_location: location(),
144148
});
145149
}
150+
146151
FunctionArgKeyName = $([a-zA-Z] [a-zA-Z0-9_]*)
147152
FunctionArgValue =
148153
FunctionCall
149154
/ quotedString
150155
// slightly different here - can contain "#", cannot contain ")" or ","
151-
/ $([^ \n,)]+) { return new ParsedEnvSpecStaticValue({ rawValue: text(), _location: location() }) }
156+
/ $([^ \n,)]+) { return new ParsedEnvSpecStaticValue({ rawValue: text(), _location: location() }) }
152157

153-
Divider =
158+
Divider =
154159
"#" leadingSpace:$_ contents:$([-=*#]|3..| [^\n]*) _n
155160
{
156161
return new ParsedEnvSpecDivider({

0 commit comments

Comments
 (0)