Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolving issue passing TMI. #42

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Dotenv {
let vars = {}
if (options.systemvars) {
Object.keys(process.env).map(key => {
vars[key] = JSON.stringify(process.env[key])
vars[key] = process.env[key]
})
}

Expand All @@ -50,13 +50,16 @@ class Dotenv {
if (!value && options.safe) {
throw new Error(`Missing environment variable: ${key}`)
} else {
vars[key] = JSON.stringify(value)
vars[key] = value
}
})

return new DefinePlugin({
'process.env': vars
})
const formatData = Object.keys(vars).reduce((obj, key) => {
obj[`process.env.${key}`] = JSON.stringify(vars[key])
return obj
}, {})

return new DefinePlugin(formatData)
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const envMissingOne = path.resolve(__dirname, './envs/.missingone')
const envMissingOneExample = path.resolve(__dirname, './envs/.missingone.example')

const envEmptyJson = {}
const envSimpleJson = {TEST: '"testing"'}
const envMissingOneJson = {TEST: '""', TEST2: '"Hello"'}
const envSimpleJson = {'process.env.TEST': '"testing"'}
const envMissingOneJson = {'process.env.TEST': '""', 'process.env.TEST2': '"Hello"'}

function runTests (Obj, name) {
function envTest (config) {
return new Obj(config).definitions['process.env']
return new Obj(config).definitions
}

/** @test {Dotenv} **/
Expand Down