fix: make exports prop of proxy point to exports object (#1260)

This commit is contained in:
Yuyao Nie 2022-05-09 21:07:38 +08:00 committed by GitHub
parent 030dd61bf2
commit cd4bed5ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

View File

@ -168,7 +168,7 @@ export class ViteNodeRunner {
exports.default = value
},
get exports() {
return exports.default
return exports
},
}

View File

@ -0,0 +1,2 @@
module.exports.a = 1
module.exports.b = 2

View File

@ -0,0 +1,3 @@
const c = 1
export default c
export const d = 2

View File

@ -0,0 +1,15 @@
import { expect, it } from 'vitest'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { a, b } from '../src/module-cjs'
import c, { d } from '../src/module-esm'
it('should work when using cjs module', () => {
expect(a).toBe(1)
expect(b).toBe(2)
})
it('should work when using esm module', () => {
expect(c).toBe(1)
expect(d).toBe(2)
})