Skip to content

Commit

Permalink
fix(rollup): handle stubbing multiple exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 10, 2022
1 parent 26635e8 commit f215525
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builder/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function rollupBuild (ctx: BuildContext) {
`/** @type {import(${JSON.stringify(resolvedEntryWithoutExt)})} */`,
`const _module = jiti(null, { interopDefault: true, esmResolve: true })(${JSON.stringify(resolvedEntry)});`,
hasDefaultExport ? '\nexport default _module;' : '',
namedExports.map(name => `export const ${name} = _module.${name};`)
...namedExports.filter(name => name !== 'default').map(name => `export const ${name} = _module.${name};`)
].join('\n'))

// DTS Stub
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineBuildConfig } from '../../src'

export default defineBuildConfig({
preset: './build.preset',
rollup: {
emitCJS: true
},
entries: [
'src/index',
{ input: 'src/schema', builder: 'untyped' }
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import('os').then(os => console.log(os.arch()))
import('./test.html').then(console.log)

export const foo = 'bar'
export const baz = '123'
export default 'default'

// Failing test
// export * from 'defu'

0 comments on commit f215525

Please sign in to comment.