Skip to content

Commit

Permalink
Remove function config.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherakama committed May 3, 2024
1 parent 9f95e0b commit b5887dc
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ module.exports = {
netlifyConfig.functions['*'].external_node_modules = [];
}
netlifyConfig.functions['*'].external_node_modules.push('dotenv');

// Ensure that the .env file we are writing gets bundled with the func.
if (!Array.isArray(netlifyConfig.functions['*'].included_files)) {
netlifyConfig.functions['*'].included_files = [];
}
netlifyConfig.functions['*'].included_files.push('.env');
}

// Contextualize the secrets.
Expand All @@ -100,7 +94,6 @@ module.exports = {

let existingSecrets = '';
const envFilePath = path.resolve(process.cwd(), '.env');
const writeEnvFilePath = path.resolve(process.cwd(), '.env.vault');

// Read existing env file.
try {
Expand All @@ -112,7 +105,7 @@ module.exports = {
// Write new env file.
const vaultSecretsString = secretsToWrite.join('\n');
const allSecretsString = `${existingSecrets}\n${vaultSecretsString}`;
fs.writeFileSync(writeEnvFilePath, allSecretsString);
fs.writeFileSync(envFilePath, allSecretsString);

// Put the new vars back into the env.
dotenv.config();
Expand All @@ -122,17 +115,4 @@ module.exports = {
summary: `Added environment variables from vault to environment and LAMBDA`,
});
},
// Remove env file if on Netilfy.
async onPostBuild() {
const isNetlify = process.env.NETLIFY || false;
const envFilePath = path.resolve(process.cwd(), '.env');
const vaultEnvFilePath = path.resolve(process.cwd(), '.env.vault');
if (isNetlify) {
try {
fs.renameSync(vaultEnvFilePath, envFilePath);
} catch (err) {
console.error('Failed to rename .env.vault to .env', { err });
}
}
},
};

0 comments on commit b5887dc

Please sign in to comment.