1- import resolve from '@rollup/plugin-node-resolve' ;
2- import commonjs from '@rollup/plugin-commonjs' ;
3- import typescript from '@rollup/plugin-typescript' ;
4- import dts from 'rollup-plugin-dts' ;
5- import json from '@rollup/plugin-json' ;
6- import builtins from 'builtin-modules' ;
7- import { readFileSync } from 'fs' ;
1+ import resolve from '@rollup/plugin-node-resolve' ; // Resolves node_modules dependencies
2+ import commonjs from '@rollup/plugin-commonjs' ; // Converts CommonJS modules to ES6
3+ import typescript from '@rollup/plugin-typescript' ; // Compiles TypeScript to JavaScript
4+ import dts from 'rollup-plugin-dts' ; // Generates TypeScript declaration files
5+ import json from '@rollup/plugin-json' ; // Imports JSON files as ES6 modules
6+ import builtins from 'builtin-modules' ; // List of Node.js built-in modules (fs, crypto, etc.)
7+ import { readFileSync } from 'fs' ;
88
99const pkg = JSON . parse ( readFileSync ( new URL ( './package.json' , import . meta. url ) , 'utf8' ) ) ;
1010
11- // Get all dependencies from package.json
1211const allDependencies = [
1312 ...Object . keys ( pkg . dependencies || { } ) ,
14- ...Object . keys ( pkg . peerDependencies || { } ) ,
15- ...builtins // Node.js built-in modules
13+ ...Object . keys ( pkg . optionalDependencies || { } ) ,
14+ ...builtins // Node.js built-in modules - part of Node.js core, no installation needed (crypto, fs, path, etc.)
1615] ;
1716
18- // Base plugins configuration
17+ // Base plugins configuration for Node.js and ESM/CJS builds
1918const createPlugins = ( isBrowser ) => [
2019 resolve ( {
21- browser : isBrowser ,
22- preferBuiltins : ! isBrowser
20+ browser : isBrowser , // When true: resolve browser-compatible versions of modules (e.g., polyfills)
21+ preferBuiltins : ! isBrowser // When false: prefer Node.js built-ins (crypto, fs) over browser polyfills
22+ } ) ,
23+ commonjs ( {
24+ transformMixedEsModules : true , // Handle packages that mix ESM and CommonJS
25+ ignoreTryCatch : false // Don't ignore try-catch when transforming
26+ } ) ,
27+ json ( ) , // Allow importing JSON files as modules
28+ typescript ( {
29+ tsconfig : './tsconfig.json' ,
30+ declaration : false ,
31+ sourceMap : false ,
32+ declarationMap : false
33+ } )
34+ ] ;
35+
36+ // Browser-specific plugins for UMD build
37+ const createBrowserPlugins = ( ) => [
38+ resolve ( {
39+ browser : true ,
40+ preferBuiltins : false
41+ } ) ,
42+ commonjs ( {
43+ transformMixedEsModules : true ,
44+ ignoreTryCatch : false
2345 } ) ,
24- commonjs ( ) ,
2546 json ( ) ,
2647 typescript ( {
2748 tsconfig : './tsconfig.json' ,
28- declaration : false
49+ declaration : false ,
50+ sourceMap : false ,
51+ declarationMap : false
2952 } )
3053] ;
3154
55+ // Rollup build configurations for different output formats
3256const configs = [
33- // ESM bundle
57+ // ESM bundle (for Node.js and modern bundlers like Vite, Webpack etc.)
3458 {
35- input : 'src/index.ts' ,
59+ input : 'src/index.ts' , // Entry point of the SDK
3660 output : {
37- file : 'dist/index.esm.js' ,
38- format : 'es'
61+ file : 'dist/index.mjs' , // Output as .mjs for explicit ESM
62+ format : 'es' ,
63+ inlineDynamicImports : true
3964 } ,
4065 plugins : createPlugins ( false ) ,
4166 external : allDependencies
4267 } ,
43- // CommonJS bundle
68+
69+ // CommonJS bundle (for Node.js and older bundlers)
4470 {
45- input : 'src/index.ts' ,
71+ input : 'src/index.ts' , // Entry point of the SDK
4672 output : {
47- file : 'dist/index.js' ,
73+ file : 'dist/index.cjs' , // Output as .cjs for explicit CommonJS
4874 format : 'cjs' ,
49- exports : 'named'
75+ exports : 'named' ,
76+ inlineDynamicImports : true
5077 } ,
5178 plugins : createPlugins ( false ) ,
5279 external : allDependencies
5380 } ,
54- // Type definitions
81+
82+ // UMD bundle (for browsers via script tag or older bundlers)
83+ {
84+ input : 'src/index.ts' , // Entry point of the SDK
85+ output : {
86+ file : 'dist/index.umd.js' , // Output as UMD for universal compatibility
87+ format : 'umd' , // Universal Module Definition format
88+ name : 'UiPath' , // Global variable name when loaded via script tag
89+ inlineDynamicImports : true
90+ } ,
91+ plugins : createBrowserPlugins ( )
92+ } ,
93+
94+ // Type definitions for ESM (.mts extension for ESM types)
95+ {
96+ input : 'src/index.ts' , // Entry point for types
97+ output : {
98+ file : 'dist/index.d.mts' , // TypeScript declaration file for ESM
99+ format : 'es'
100+ } ,
101+ plugins : [ dts ( ) ]
102+ } ,
103+
104+ // Type definitions for CommonJS (.cts extension for CJS types)
105+ {
106+ input : 'src/index.ts' , // Entry point for types
107+ output : {
108+ file : 'dist/index.d.cts' , // TypeScript declaration file for CJS
109+ format : 'es'
110+ } ,
111+ plugins : [ dts ( ) ]
112+ } ,
113+
114+ // Main type definitions (for legacy TypeScript and package.json "types" field)
55115 {
56- input : 'src/index.ts' ,
116+ input : 'src/index.ts' , // Entry point for types
57117 output : {
58- file : 'dist/index.d.ts' ,
118+ file : 'dist/index.d.ts' , // Main TypeScript declaration file
59119 format : 'es'
60120 } ,
61121 plugins : [ dts ( ) ]
62122 }
63123] ;
64124
125+ // Export all build configurations
65126export default configs ;
0 commit comments