@@ -3,6 +3,7 @@ import commonjs from '@rollup/plugin-commonjs';
33import typescript from '@rollup/plugin-typescript' ;
44import dts from 'rollup-plugin-dts' ;
55import json from '@rollup/plugin-json' ;
6+ import replace from '@rollup/plugin-replace' ;
67import builtins from 'builtin-modules' ;
78import { readFileSync } from 'fs' ;
89
@@ -15,43 +16,115 @@ const allDependencies = [
1516 ...builtins // Node.js built-in modules
1617] ;
1718
19+ // Node.js-specific dependencies to exclude from browser bundle
20+ const nodeDependencies = [
21+ 'file-type' ,
22+ 'ws' ,
23+ '@opentelemetry/sdk-logs'
24+ ] ;
25+
1826// Base plugins configuration
1927const createPlugins = ( isBrowser ) => [
2028 resolve ( {
2129 browser : isBrowser ,
2230 preferBuiltins : ! isBrowser
2331 } ) ,
24- commonjs ( ) ,
32+ commonjs ( {
33+ transformMixedEsModules : true
34+ } ) ,
35+ json ( ) ,
36+ typescript ( {
37+ tsconfig : './tsconfig.json' ,
38+ declaration : false ,
39+ sourceMap : false
40+ } )
41+ ] ;
42+
43+ // Browser-specific plugins with Node.js replacements
44+ const createBrowserPlugins = ( ) => [
45+ replace ( {
46+ preventAssignment : true ,
47+ values : {
48+ // Replace Node.js dynamic imports with empty promises for browser bundle
49+ "import('file-type')" : "Promise.resolve({})" ,
50+ "import('ws')" : "Promise.resolve({})" ,
51+ // Replace Node.js crypto require with Web Crypto API
52+ "const crypto = require('crypto')" : "const crypto = globalThis.crypto || window.crypto" ,
53+ "require('crypto')" : "globalThis.crypto || window.crypto"
54+ }
55+ } ) ,
56+ resolve ( {
57+ browser : true ,
58+ preferBuiltins : false
59+ } ) ,
60+ commonjs ( {
61+ transformMixedEsModules : true
62+ } ) ,
2563 json ( ) ,
2664 typescript ( {
2765 tsconfig : './tsconfig.json' ,
28- declaration : false
66+ declaration : false ,
67+ sourceMap : false
2968 } )
3069] ;
3170
3271const configs = [
33- // ESM bundle
72+ // ESM bundle (for Node.js and modern bundlers)
3473 {
3574 input : 'src/index.ts' ,
3675 output : {
37- file : 'dist/index.esm.js ' ,
76+ file : 'dist/index.mjs ' ,
3877 format : 'es'
3978 } ,
4079 plugins : createPlugins ( false ) ,
4180 external : allDependencies
4281 } ,
43- // CommonJS bundle
82+ // CommonJS bundle (for Node.js)
4483 {
4584 input : 'src/index.ts' ,
4685 output : {
47- file : 'dist/index.js ' ,
86+ file : 'dist/index.cjs ' ,
4887 format : 'cjs' ,
4988 exports : 'named'
5089 } ,
5190 plugins : createPlugins ( false ) ,
5291 external : allDependencies
5392 } ,
54- // Type definitions
93+ // UMD bundle (for browsers)
94+ {
95+ input : 'src/index.ts' ,
96+ output : {
97+ file : 'dist/index.umd.js' ,
98+ format : 'umd' ,
99+ name : 'UiPath' ,
100+ globals : {
101+ 'file-type' : 'FileType' ,
102+ 'ws' : 'WebSocket' ,
103+ '@opentelemetry/sdk-logs' : 'OpenTelemetry'
104+ }
105+ } ,
106+ plugins : createBrowserPlugins ( ) ,
107+ external : nodeDependencies // Exclude Node.js-specific deps
108+ } ,
109+ // Type definitions for ESM
110+ {
111+ input : 'src/index.ts' ,
112+ output : {
113+ file : 'dist/index.d.mts' ,
114+ format : 'es'
115+ } ,
116+ plugins : [ dts ( ) ]
117+ } ,
118+ // Type definitions for CommonJS
119+ {
120+ input : 'src/index.ts' ,
121+ output : {
122+ file : 'dist/index.d.cts' ,
123+ format : 'es'
124+ } ,
125+ plugins : [ dts ( ) ]
126+ } ,
127+ // Type definitions (main)
55128 {
56129 input : 'src/index.ts' ,
57130 output : {
0 commit comments