Skip to content

Commit

Permalink
Add try catches to parsing and reference du5rte/create-secret-file
Browse files Browse the repository at this point in the history
  • Loading branch information
du5rte committed Dec 1, 2020
1 parent 9fbaacf commit 98f58cb
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 5,025 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ BASIC=basic

# previous line intentionally left blank
AFTER_LINE=after_line
EMPTY=
SINGLE_QUOTES='single_quotes'
DOUBLE_QUOTES="double_quotes"
SPACED_OUT = "spaced_out"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules

# Mac system files
.DS_Store
.yarn-error.log
2 changes: 2 additions & 0 deletions .invalid.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMPTY=
EQUAL_SIGNS=equals==
1 change: 1 addition & 0 deletions .secrets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SECRETS_BASIC=secrets_basic
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,10 @@ app.listen(process.env.PORT, function () {
})
```

In ES6
Verify environment variables are loaded in `process.env`

```javascript
// setups entries in process.env
import 'secrets'
// bind process.env to exports
import { PORT } from 'secrets'

...
app.listen(PORT, () => {
console.log(`Server running on localhost:${PORT}`)
});
secret.verify('PORT', 'SECRET') // throw error if it's missing
```

## Babel Plugin
Expand All @@ -83,6 +75,9 @@ module.exports = {
}
```

## Github Action
To create secret `.env` environment files on demands on your github actions checkout [du5rte/create-secret-file](https://github.com/du5rte/create-secret-file)

## Location

Secrets should be place in the root of the project but it searches for `.env` files the same way node searches for `node_modules` folders, the closer to the root the higher the priority.
Expand Down
6 changes: 4 additions & 2 deletions babel-plugin-secrets/plugin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { readEnvs } = require('../src/core')
const core = require('../src/core')

const secrets = core.search()

module.exports = function babelPluginSecrets({
types: { valueToNode, logicalExpression, identifier },
}) {
return {
name: 'babel-plugin-secrets',
pre() {
this.values = readEnvs()
this.values = secrets
},
visitor: {
MemberExpression(node) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "secrets",
"version": "1.0.0",
"version": "1.1.5",
"description": "Secret handler for Node.js 🗝️",
"main": "src",
"scripts": {
Expand Down
Loading

0 comments on commit 98f58cb

Please sign in to comment.