vite-plugin-env-file
Advanced tools
Comparing version 1.0.0 to 1.0.1
32
index.js
@@ -1,8 +0,8 @@ | ||
import Env from '@marknotton/env' | ||
const Env = require('@marknotton/env'); | ||
export default function updateEnvFile(envVars = {}, options = {}) { | ||
function updateEnvFile(envVars = {}, options = {}) { | ||
// Use default values for options if not provided | ||
const { prefix = 'VITE_', forceUpperCase = true, envFile = 'vite.env' } = options || {} | ||
const { prefix = 'VITE_', forceUpperCase = true, envFile = 'vite.env' } = options || {}; | ||
const envFileModule = new Env(envFile) | ||
const envFileModule = new Env(envFile); | ||
@@ -13,7 +13,9 @@ return { | ||
// Do nothing if envVars is falsy | ||
if (!envVars) return | ||
if (!envVars) return; | ||
// Convert keys to upper case if forceUpperCase is true | ||
if (forceUpperCase) { | ||
envVars = Object.fromEntries(Object.entries(envVars).map(([key, value]) => [key.toUpperCase(), value])) | ||
envVars = Object.fromEntries( | ||
Object.entries(envVars).map(([key, value]) => [key.toUpperCase(), value]) | ||
); | ||
} | ||
@@ -23,17 +25,19 @@ | ||
Object.keys(envVars).forEach((key) => { | ||
const envKey = prefix ? `${prefix}${key}` : key | ||
envFileModule.set(envKey, envVars[key]) | ||
}) | ||
const envKey = prefix ? `${prefix}${key}` : key; | ||
envFileModule.set(envKey, envVars[key]); | ||
}); | ||
}, | ||
async buildEnd() { | ||
// Do nothing if envVars is falsy | ||
if (!envVars) return | ||
if (!envVars) return; | ||
// Delete the set environment variables | ||
Object.keys(envVars).forEach((key) => { | ||
const envKey = prefix ? `${prefix}${key}` : key | ||
envFileModule.delete(envKey) | ||
}) | ||
const envKey = prefix ? `${prefix}${key}` : key; | ||
envFileModule.delete(envKey); | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
module.exports = updateEnvFile; |
{ | ||
"name": "vite-plugin-env-file", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Mark Notton <mark@marknotton.uk>", | ||
"license": "MIT", | ||
"public": true, | ||
"main": "index.js", | ||
"dependencies": { | ||
"@marknotton/env": "1.1.4" | ||
"@marknotton/env": "2.0.0" | ||
}, | ||
"main": "index.js", | ||
"module": "index.mjs", | ||
"types": "index.d.ts", | ||
"keywords": [ | ||
@@ -12,0 +14,0 @@ "vite-plugin" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6038
6
76
+ Added@marknotton/env@2.0.0(transitive)
- Removed@marknotton/env@1.1.4(transitive)
Updated@marknotton/env@2.0.0