serverless-dotenv-plugin
Advanced tools
Comparing version 1.1.5 to 1.2.0
77
index.js
@@ -1,21 +0,14 @@ | ||
'use strict'; | ||
'use strict' | ||
const fs = require('fs'); | ||
const dotenv = require('dotenv'); | ||
const dotenvExpand = require('dotenv-expand'); | ||
const chalk = require('chalk'); | ||
const dotenv = require('dotenv') | ||
const dotenvExpand = require('dotenv-expand') | ||
const chalk = require('chalk') | ||
class ServerlessPlugin { | ||
constructor(serverless, options) { | ||
this.serverless = serverless; | ||
this.env = {}; | ||
this.serverless.service.provider.environment = this.serverless.service.provider.environment || {}; | ||
this.hooks = { | ||
"before:offline:start:init": this.loadEnv.bind(this), | ||
"before:offline:start": this.loadEnv.bind(this), | ||
"before:invoke:local:invoke": this.loadEnv.bind(this), | ||
"before:deploy:resources": this.loadEnv.bind(this), | ||
"before:deploy:functions": this.loadEnv.bind(this), | ||
"before:package:initialize": this.loadEnv.bind(this), | ||
} | ||
this.serverless = serverless | ||
this.env = {} | ||
this.serverless.service.provider.environment = | ||
this.serverless.service.provider.environment || {} | ||
this.loadEnv() | ||
} | ||
@@ -25,32 +18,40 @@ | ||
try { | ||
this.serverless.cli.log('DOTENV: Loading environment variables:'); | ||
var config = this.serverless.service.custom && this.serverless.service.custom['dotenv']; | ||
var envPath = (config && config.path) || '.env'; | ||
this.env = dotenvExpand(dotenv.config({path: envPath})).parsed; | ||
var config = | ||
this.serverless.service.custom && | ||
this.serverless.service.custom['dotenv'] | ||
var envPath = (config && config.path) || '.env' | ||
this.env = dotenvExpand(dotenv.config({ path: envPath })).parsed | ||
var include = false; | ||
var include = false | ||
if (config && config.include) { | ||
include = config.include; | ||
include = config.include | ||
} | ||
if (include) { | ||
Object.keys(this.env) | ||
.filter((key) => !include.includes(key)) | ||
.forEach((key) => { | ||
delete this.env[key] | ||
}) | ||
if (this.env) { | ||
this.serverless.cli.log('DOTENV: Loading environment variables:') | ||
if (include) { | ||
Object.keys(this.env) | ||
.filter(key => !include.includes(key)) | ||
.forEach(key => { | ||
delete this.env[key] | ||
}) | ||
} | ||
Object.keys(this.env).forEach(key => { | ||
this.serverless.cli.log('\t - ' + key) | ||
this.serverless.service.provider.environment[key] = this.env[key] | ||
}) | ||
} else { | ||
this.serverless.cli.log('DOTENV: Could no find .env file.') | ||
} | ||
Object.keys(this.env) | ||
.forEach((key) => { | ||
this.serverless.cli.log("\t - " + key); | ||
this.serverless.service.provider.environment[key] = this.env[key]; | ||
}) | ||
} catch (e) { | ||
console.error(chalk.red('\n Serverless Plugin Error --------------------------------------\n')) | ||
console.error(chalk.red(' ' + e.message)); | ||
console.error( | ||
chalk.red( | ||
'\n Serverless Plugin Error --------------------------------------\n' | ||
) | ||
) | ||
console.error(chalk.red(' ' + e.message)) | ||
} | ||
} | ||
} | ||
module.exports = ServerlessPlugin; | ||
module.exports = ServerlessPlugin |
{ | ||
"name": "serverless-dotenv-plugin", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"description": "Preload Environment Variables with Dotenv into Serverless Edit", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
50
0
5490