Skip to content

Commit

Permalink
fix: add import.meta.env support
Browse files Browse the repository at this point in the history
Has the some data as process.env

closes #549
  • Loading branch information
hugomrdias committed Jun 27, 2023
1 parent 718732a commit 8073767
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions mocks/test.mocha.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
// eslint-disable-next-line strict
const { is, ok } = require('uvu/assert')
const { is, ok, equal } = require('uvu/assert')
const debug = require('debug')('app')
const { good, bad } = require('./lib')

Expand All @@ -27,8 +27,12 @@ describe('Array', () => {
is(await bad(), 'bad')
})

it('should has import.meta', async () => {
it('should has import.meta.url', async () => {
ok(import.meta.url)
})

it('should has import.meta.env', async () => {
equal(import.meta.env, process.env)
})
})
})
10 changes: 6 additions & 4 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,25 @@ export async function build(runner, config = {}, tmpl = '', mode = 'bundle') {

// main script template
let infileContent = `
import { install } from '${sourceMapSupport.replace(/\\/g, '/')}'
import { install } from '${sourceMapSupport.replaceAll('\\', '/')}'
install()
process.env = ${JSON.stringify(runner.env)}
import.meta.env = ${JSON.stringify(runner.env)}
${tmpl}
`
// before script template
if (mode === 'before' && runner.options.before) {
infileContent = `
import { install } from '${sourceMapSupport.replace(/\\/g, '/')}'
import { install } from '${sourceMapSupport.replaceAll('\\', '/')}'
install()
process.env = ${JSON.stringify(runner.env)}
import.meta.env = ${JSON.stringify(runner.env)}
await import('${require.resolve('../../static/setup.js').replace(/\\/g, '/')}')
await import('${require.resolve('../../static/setup.js').replaceAll('\\', '/')}')
await import('${require
.resolve(path.join(runner.options.cwd, runner.options.before))
.replace(/\\/g, '/')}')
.replaceAll('\\', '/')}')
`
}

Expand Down

0 comments on commit 8073767

Please sign in to comment.