@@ -14,7 +14,12 @@ import type {
1414 Overwrite ,
1515} from './utils/types'
1616import type { Stats } from 'node:fs'
17- import type { InputOptions , ModuleFormat , OutputOptions } from 'rolldown'
17+ import type {
18+ InputOptions ,
19+ InternalModuleFormat ,
20+ ModuleFormat ,
21+ OutputOptions ,
22+ } from 'rolldown'
1823import type { Options as IsolatedDeclOptions } from 'unplugin-isolated-decl'
1924import type { Options as UnusedOptions } from 'unplugin-unused'
2025
@@ -43,6 +48,7 @@ export interface Options {
4348 define ?: Record < string , string >
4449 /** @default 'node' */
4550 platform ?: 'node' | 'neutral' | 'browser'
51+ shims ?: boolean
4652 /**
4753 * Enable dts generation with `isolatedDeclarations` (experimental)
4854 */
@@ -73,6 +79,10 @@ export interface Options {
7379export type Config = Arrayable < Omit < Options , 'config' > >
7480export type ResolvedConfig = Extract < Config , any [ ] >
7581
82+ export type NormalizedFormat =
83+ | Exclude < InternalModuleFormat , 'app' >
84+ | 'experimental-app'
85+
7686export type ResolvedOptions = Omit <
7787 Overwrite <
7888 MarkPartial <
@@ -87,7 +97,7 @@ export type ResolvedOptions = Omit<
8797 | 'external'
8898 | 'onSuccess'
8999 > ,
90- { format : ModuleFormat [ ] ; clean : string [ ] | false }
100+ { format : NormalizedFormat [ ] ; clean : string [ ] | false }
91101 > ,
92102 'config'
93103>
@@ -118,18 +128,18 @@ export async function resolveOptions(
118128 dts = false ,
119129 unused = false ,
120130 watch = false ,
131+ shims = false ,
121132 skipNodeModulesBundle = false ,
122133 } = subOptions
123134
124135 entry = await resolveEntry ( entry )
125- format = toArray ( format , 'es' )
126136 if ( clean === true ) clean = [ ]
127137
128138 return {
129139 ...subOptions ,
130140 entry,
131141 plugins,
132- format,
142+ format : normalizeFormat ( format ) ,
133143 outDir : path . resolve ( outDir ) ,
134144 clean,
135145 silent,
@@ -139,6 +149,7 @@ export async function resolveOptions(
139149 dts,
140150 unused,
141151 watch,
152+ shims,
142153 skipNodeModulesBundle,
143154 }
144155 } ) ,
@@ -147,6 +158,24 @@ export async function resolveOptions(
147158 ]
148159}
149160
161+ export function normalizeFormat (
162+ format : ModuleFormat | ModuleFormat [ ] ,
163+ ) : NormalizedFormat [ ] {
164+ return toArray < ModuleFormat > ( format , 'es' ) . map ( ( format ) : NormalizedFormat => {
165+ switch ( format ) {
166+ case 'es' :
167+ case 'esm' :
168+ case 'module' :
169+ return 'es'
170+ case 'cjs' :
171+ case 'commonjs' :
172+ return 'cjs'
173+ default :
174+ return format
175+ }
176+ } )
177+ }
178+
150179async function loadConfigFile (
151180 options : Options ,
152181) : Promise < [ config : ResolvedConfig , file ?: string ] > {
0 commit comments