Skip to content

Commit 74b798d

Browse files
committed
🚀 1.3.0: Support [email protected]
1 parent 5f92672 commit 74b798d

File tree

7 files changed

+42
-40
lines changed

7 files changed

+42
-40
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Then add `rescript-envsafe` and `rescript-struct` to `bs-dependencies` in your `
3131
```diff
3232
{
3333
...
34-
+ "bs-dependencies": ["rescript-envsafe", "rescript-struct"]
34+
+ "bs-dependencies": ["rescript-envsafe", "rescript-struct"],
35+
+ "bsc-flags": ["-open RescriptStruct"],
3536
}
3637
```
3738

__tests__/EnvSafe_test.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ test("Successfully get defaulted value when env is missing", t => {
246246
t->Assert.is(
247247
envSafe->EnvSafe.get(
248248
~name="MISSING_ENV",
249-
~struct=S.string()->S.option->S.defaulted("Defaulted"),
249+
~struct=S.string()->S.option->S.default(() => "Defaulted"),
250250
(),
251251
),
252252
"Defaulted",
@@ -312,7 +312,7 @@ test(`Doesn't show input value when it's missing for invalid env`, t => {
312312
t->Assert.is(
313313
envSafe->EnvSafe.get(
314314
~name="MISSING_ENV",
315-
~struct=S.int()->S.option->S.refine(~parser=_ => S.Error.raise("User error"), ()),
315+
~struct=S.int()->S.option->S.refine(~parser=_ => S.fail("User error"), ()),
316316
(),
317317
),
318318
%raw(`undefined`),

bsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"namespace": false,
44
"bs-dev-dependencies": ["@dzakh/rescript-ava"],
55
"bs-dependencies": ["rescript-struct"],
6-
"bsc-flags": ["-open ReScriptStruct"],
6+
"bsc-flags": ["-open RescriptStruct"],
77
"suffix": ".bs.js",
88
"package-specs": {
99
"module": "commonjs",

package-lock.json

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rescript-envsafe",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "🔒 Makes sure you don't accidentally deploy apps with missing or invalid environment variables",
55
"homepage": "https://github.com/DZakh/rescript-envsafe#readme",
66
"keywords": [
@@ -40,11 +40,11 @@
4040
"devDependencies": {
4141
"@dzakh/rescript-ava": "2.1.0",
4242
"ava": "5.1.0",
43-
"rescript": "10.1.0",
44-
"rescript-struct": "3.0.0"
43+
"rescript": "10.1.4",
44+
"rescript-struct": "4.0.0"
4545
},
4646
"peerDependencies": {
4747
"rescript": "10.1.x",
48-
"rescript-struct": "3.0.x"
48+
"rescript-struct": "4.0.x"
4949
}
5050
}

src/EnvSafe.bs.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EnvSafe.res

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Lib = {
1+
module Stdlib = {
22
module Dict = {
33
@get_index external get: (Js.Dict.t<'a>, string) => option<'a> = ""
44
}
@@ -36,7 +36,8 @@ module Lib = {
3636

3737
module Error = {
3838
@inline
39-
let panic = message => Lib.Exn.raiseError(Lib.Exn.makeError(`[rescript-envsafe] ${message}`))
39+
let panic = message =>
40+
Stdlib.Exn.raiseError(Stdlib.Exn.makeError(`[rescript-envsafe] ${message}`))
4041
}
4142

4243
type env = Js.Dict.t<string>
@@ -84,7 +85,7 @@ let close = (envSafe, ()) => {
8485
let line = "========================================"
8586
let output = [line]
8687

87-
maybeInvalidIssues->Lib.Option.forEach(invalidIssues => {
88+
maybeInvalidIssues->Stdlib.Option.forEach(invalidIssues => {
8889
output->Js.Array2.push("❌ Invalid environment variables:")->ignore
8990
invalidIssues->Js.Array2.forEach(issue => {
9091
output
@@ -98,7 +99,7 @@ let close = (envSafe, ()) => {
9899
})
99100
})
100101

101-
maybeMissingIssues->Lib.Option.forEach(missingIssues => {
102+
maybeMissingIssues->Stdlib.Option.forEach(missingIssues => {
102103
output->Js.Array2.push("💨 Missing environment variables:")->ignore
103104
missingIssues->Js.Array2.forEach(issue => {
104105
output
@@ -117,8 +118,8 @@ let close = (envSafe, ()) => {
117118
}
118119

119120
Js.Console.error(text)
120-
Lib.Window.alert(text)
121-
Lib.Exn.raiseError(Lib.Exn.makeTypeError(text))
121+
Stdlib.Window.alert(text)
122+
Stdlib.Exn.raiseError(Stdlib.Exn.makeTypeError(text))
122123
}
123124
}
124125
}
@@ -187,13 +188,13 @@ let get = (
187188
}
188189
let input = switch maybeInlinedInput {
189190
| Some(inlinedInput) => inlinedInput
190-
| None => envSafe.env->Lib.Dict.get(name)
191+
| None => envSafe.env->Stdlib.Dict.get(name)
191192
}
192-
let parseResult = input->S.parseWith(prepareStruct(~struct, ~allowEmpty))
193+
let parseResult = input->S.parseAnyWith(prepareStruct(~struct, ~allowEmpty))
193194
switch (parseResult, maybeDevFallback) {
194195
| (Ok(v), _) => v
195196
| (Error({code: UnexpectedType({received: "Option"})}), Some(devFallback))
196-
if envSafe.env->Lib.Dict.get("NODE_ENV") !== Some("production") => devFallback
197+
if envSafe.env->Stdlib.Dict.get("NODE_ENV") !== Some("production") => devFallback
197198
| (Error(error), _) => {
198199
envSafe->mixinIssue({name, error, input})
199200
%raw(`undefined`)

0 commit comments

Comments
 (0)