Skip to content

Commit

Permalink
Merge e0a0094 into 13994c5
Browse files Browse the repository at this point in the history
  • Loading branch information
neverendingqs committed Feb 15, 2021
2 parents 13994c5 + e0a0094 commit 551f2b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ included in this log but can be reviewed on GitHub:

## Unreleased

## 3.5.x

* feat: now logs when incompatible configs are set. ([#124](https://github.com/neverendingqs/serverless-dotenv-plugin/pull/124))

## 3.4.x

* feat: new option to expect specific env vars to be set. ([#118](https://github.com/neverendingqs/serverless-dotenv-plugin/pull/118))
Expand Down
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ class ServerlessPlugin {
* @returns {string[]}
*/
resolveEnvFileNames(env) {
const basePath = (this.config && this.config.basePath) || ''

if (this.config && this.config.path) {
if (basePath) {
this.log('DOTENV (WARNING): if "path" is set, "basePath" is ignored.')
}

if (Array.isArray(this.config.path)) {
return this.config.path
}
Expand All @@ -65,9 +71,6 @@ class ServerlessPlugin {
`.env`,
]

const basePath =
this.config && this.config.basePath ? this.config.basePath : ''

const filesNames = dotenvFiles.map((file) => basePath + file)

return filesNames.filter((fileName) => fs.existsSync(fileName))
Expand Down Expand Up @@ -116,6 +119,10 @@ class ServerlessPlugin {
const exclude = (this.config && this.config.exclude) || []

if (include.length > 0) {
if (exclude) {
this.log('DOTENV (WARNING): if "include" is set, "exclude" is ignored.')
}

Object.keys(envVars)
.filter((key) => !include.includes(key))
.forEach((key) => {
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ describe('ServerlessPlugin', function () {

this.plugin.resolveEnvFileNames('env').should.deep.equal(path)
})

it('logs an error if basePath is also set', function () {
const path = '.env.unittest'
this.serverless.service.custom.dotenv.basePath = 'base/path/'
this.serverless.service.custom.dotenv.path = path

this.plugin.resolveEnvFileNames('env').should.deep.equal([path])
this.serverless.cli.log.should.have.been.calledWith(
sinon.match(/basePath/),
)
})
})

describe('with default dotenv paths', function () {
Expand Down Expand Up @@ -437,6 +448,10 @@ describe('ServerlessPlugin', function () {
env1: envVars.env1,
env2: envVars.env2,
})

this.serverless.cli.log.should.have.been.calledWith(
sinon.match(/exclude/),
)
})

it('does not use `dotenv-expand` when `variableExpansion` is set to `false`', function () {
Expand Down

0 comments on commit 551f2b4

Please sign in to comment.