@@ -13,10 +13,11 @@ use rspack_core::{
13
13
CssAutoGeneratorOptions , CssAutoParserOptions , CssGeneratorOptions , CssModuleGeneratorOptions ,
14
14
CssModuleParserOptions , CssParserOptions , DescriptionData , DynamicImportFetchPriority ,
15
15
DynamicImportMode , ExportPresenceMode , FuncUseCtx , GeneratorOptions , GeneratorOptionsMap ,
16
- JavascriptParserOptions , JavascriptParserOrder , JavascriptParserUrl , JsonGeneratorOptions ,
17
- JsonParserOptions , ModuleNoParseRule , ModuleNoParseRules , ModuleNoParseTestFn , ModuleOptions ,
18
- ModuleRule , ModuleRuleEffect , ModuleRuleEnforce , ModuleRuleUse , ModuleRuleUseLoader ,
19
- OverrideStrict , ParseOption , ParserOptions , ParserOptionsMap , TypeReexportPresenceMode ,
16
+ JavascriptParserCommonjsExportsOption , JavascriptParserCommonjsOptions , JavascriptParserOptions ,
17
+ JavascriptParserOrder , JavascriptParserUrl , JsonGeneratorOptions , JsonParserOptions ,
18
+ ModuleNoParseRule , ModuleNoParseRules , ModuleNoParseTestFn , ModuleOptions , ModuleRule ,
19
+ ModuleRuleEffect , ModuleRuleEnforce , ModuleRuleUse , ModuleRuleUseLoader , OverrideStrict ,
20
+ ParseOption , ParserOptions , ParserOptionsMap , TypeReexportPresenceMode ,
20
21
} ;
21
22
use rspack_error:: error;
22
23
use rspack_napi:: threadsafe_function:: ThreadsafeFunction ;
@@ -288,6 +289,8 @@ pub struct RawJavascriptParserOptions {
288
289
/// This option is experimental in Rspack only and subject to change or be removed anytime.
289
290
/// @experimental
290
291
pub require_resolve : Option < bool > ,
292
+ #[ napi( ts_type = "boolean | { exports?: boolean | 'skipInEsm' }" ) ]
293
+ pub commonjs : Option < Either < bool , RawJavascriptParserCommonjsOptions > > ,
291
294
/// This option is experimental in Rspack only and subject to change or be removed anytime.
292
295
/// @experimental
293
296
pub import_dynamic : Option < bool > ,
@@ -303,6 +306,20 @@ pub struct RawJavascriptParserOptions {
303
306
pub jsx : Option < bool > ,
304
307
}
305
308
309
+ #[ napi( object) ]
310
+ #[ derive( Debug ) ]
311
+ pub struct RawJavascriptParserCommonjsOptions {
312
+ #[ napi( ts_type = "boolean | 'skipInEsm'" ) ]
313
+ pub exports : Option < Either < bool , RawJavascriptParserCommonjsExports > > ,
314
+ }
315
+
316
+ #[ napi( string_enum) ]
317
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
318
+ pub enum RawJavascriptParserCommonjsExports {
319
+ #[ napi( value = "skipInEsm" ) ]
320
+ SkipInEsm ,
321
+ }
322
+
306
323
impl From < RawJavascriptParserOptions > for JavascriptParserOptions {
307
324
fn from ( value : RawJavascriptParserOptions ) -> Self {
308
325
Self {
@@ -344,6 +361,23 @@ impl From<RawJavascriptParserOptions> for JavascriptParserOptions {
344
361
require_as_expression : value. require_as_expression ,
345
362
require_dynamic : value. require_dynamic ,
346
363
require_resolve : value. require_resolve ,
364
+ commonjs : value. commonjs . map ( |commonjs| match commonjs {
365
+ Either :: A ( flag) => JavascriptParserCommonjsOptions {
366
+ exports : JavascriptParserCommonjsExportsOption :: from ( flag) ,
367
+ } ,
368
+ Either :: B ( options) => {
369
+ let exports = options
370
+ . exports
371
+ . map ( |exports| match exports {
372
+ Either :: A ( flag) => JavascriptParserCommonjsExportsOption :: from ( flag) ,
373
+ Either :: B ( RawJavascriptParserCommonjsExports :: SkipInEsm ) => {
374
+ JavascriptParserCommonjsExportsOption :: SkipInEsm
375
+ }
376
+ } )
377
+ . unwrap_or ( JavascriptParserCommonjsExportsOption :: Enable ) ;
378
+ JavascriptParserCommonjsOptions { exports }
379
+ }
380
+ } ) ,
347
381
import_dynamic : value. import_dynamic ,
348
382
commonjs_magic_comments : value. commonjs_magic_comments ,
349
383
inline_const : value. inline_const ,
0 commit comments