Skip to content

Commit

Permalink
feat: should allow overwrite boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Aug 15, 2023
1 parent 7eec3d7 commit 6688f30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/vite-node/src/utils.ts
Expand Up @@ -215,5 +215,16 @@ export function createImportMetaEnvProxy() {
return !!process.env[key]
return process.env[key]
},
set(_, key, value) {
if (typeof key !== 'string')
return true

if (booleanKeys.includes(key))
process.env[key] = value ? '1' : ''
else
process.env[key] = value

return true
},
})
}
3 changes: 3 additions & 0 deletions test/core/test/env.test.ts
Expand Up @@ -58,4 +58,7 @@ test('PROD, DEV, SSR should be boolean', () => {
expect(typeof import.meta.env.PROD).toEqual('boolean')
expect(typeof import.meta.env.DEV).toEqual('boolean')
expect(typeof import.meta.env.SSR).toEqual('boolean')

import.meta.env.SSR = false
expect(import.meta.env.SSR).toEqual(false)
})

0 comments on commit 6688f30

Please sign in to comment.