-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrollup.config.js
More file actions
288 lines (271 loc) · 8.1 KB
/
Copy pathrollup.config.js
File metadata and controls
288 lines (271 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import resolve from '@rollup/plugin-node-resolve'; // Resolves node_modules dependencies
import commonjs from '@rollup/plugin-commonjs'; // Converts CommonJS modules to ES6
import typescript from '@rollup/plugin-typescript'; // Compiles TypeScript to JavaScript
import dts from 'rollup-plugin-dts'; // Generates TypeScript declaration files
import json from '@rollup/plugin-json'; // Imports JSON files as ES6 modules
import alias from '@rollup/plugin-alias'; // Path alias support (@/ -> src/)
import builtins from 'builtin-modules'; // List of Node.js built-in modules (fs, crypto, etc.)
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';
// Get __dirname equivalent in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Custom plugin to rewrite import paths in .d.ts files
// This normalizes core import paths to '../core/index' for cleaner output
function rewriteDtsImports() {
return {
name: 'rewrite-dts-imports',
renderChunk(code) {
return code.replace(
/from ['"](?:(?:\.\.\/)+|@\/)core\/(?:types|uipath|index)['"]/g,
"from '../core/index'"
);
}
};
}
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
const allDependencies = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
...builtins // Node.js built-in modules - part of Node.js core, no installation needed (crypto, fs, path, etc.)
];
// Path alias configuration (@/ -> src/)
const aliasConfig = {
entries: [
{ find: /^@\/(.*)/, replacement: path.resolve(__dirname, 'src/$1') }
]
};
// Base plugins configuration for Node.js and ESM/CJS builds
const createPlugins = (isBrowser) => [
alias(aliasConfig), // Path alias resolution (@/ -> src/)
resolve({
browser: isBrowser, // When true: resolve browser-compatible versions of modules (e.g., polyfills)
preferBuiltins: !isBrowser // When false: prefer Node.js built-ins (crypto, fs) over browser polyfills
}),
commonjs({
transformMixedEsModules: true, // Handle packages that mix ESM and CommonJS
ignoreTryCatch: false // Don't ignore try-catch when transforming
}),
json(), // Allow importing JSON files as modules
typescript({
tsconfig: './tsconfig.json',
declaration: false,
sourceMap: false,
declarationMap: false
})
];
// Browser-specific plugins for UMD build
const createBrowserPlugins = () => [
alias(aliasConfig), // Path alias resolution (@/ -> src/)
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
transformMixedEsModules: true,
ignoreTryCatch: false
}),
json(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
sourceMap: false,
declarationMap: false
})
];
// Rollup build configurations for different output formats
const configs = [
// ESM bundle (for Node.js and modern bundlers like Vite, Webpack etc.)
{
input: 'src/index.ts', // Entry point of the SDK
output: {
file: 'dist/index.mjs', // Output as .mjs for explicit ESM
format: 'es',
inlineDynamicImports: true
},
plugins: createPlugins(false),
external: allDependencies
},
// CommonJS bundle (for Node.js and older bundlers)
{
input: 'src/index.ts', // Entry point of the SDK
output: {
file: 'dist/index.cjs', // Output as .cjs for explicit CommonJS
format: 'cjs',
exports: 'named',
inlineDynamicImports: true
},
plugins: createPlugins(false),
external: allDependencies
},
// UMD bundle (for browsers via script tag or older bundlers)
{
input: 'src/index.ts', // Entry point of the SDK
output: {
file: 'dist/index.umd.js', // Output as UMD for universal compatibility
format: 'umd', // Universal Module Definition format
name: 'UiPath', // Global variable name when loaded via script tag
inlineDynamicImports: true
},
plugins: createBrowserPlugins()
},
// Main type definitions
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'es'
},
plugins: [alias(aliasConfig), dts()]
}
];
// Service-level entry points for modular imports
const serviceEntries = [
{
name: 'core',
input: 'src/core/index.ts',
output: 'core/index'
},
{
name: 'entities',
input: 'src/services/data-fabric/index.ts',
output: 'entities/index'
},
{
name: 'tasks',
input: 'src/services/action-center/index.ts',
output: 'tasks/index'
},
{
name: 'assets',
input: 'src/services/orchestrator/assets/index.ts',
output: 'assets/index'
},
{
name: 'jobs',
input: 'src/services/orchestrator/jobs/index.ts',
output: 'jobs/index'
},
{
name: 'attachments',
input: 'src/services/orchestrator/attachments/index.ts',
output: 'attachments/index'
},
{
name: 'queues',
input: 'src/services/orchestrator/queues/index.ts',
output: 'queues/index'
},
{
name: 'buckets',
input: 'src/services/orchestrator/buckets/index.ts',
output: 'buckets/index'
},
{
name: 'processes',
input: 'src/services/orchestrator/processes/index.ts',
output: 'processes/index'
},
{
name: 'cases',
input: 'src/services/maestro/cases/index.ts',
output: 'cases/index'
},
{
name: 'maestro-processes',
input: 'src/services/maestro/processes/index.ts',
output: 'maestro-processes/index'
},
{
name: 'conversational-agent',
input: 'src/services/conversational-agent/index.ts',
output: 'conversational-agent/index'
},
{
name: 'feedback',
input: 'src/services/agents/feedback/index.ts',
output: 'feedback/index'
},
{
name: 'agent-memory',
input: 'src/services/agents/memory/index.ts',
output: 'agent-memory/index'
},
{
name: 'traces',
input: 'src/services/observability/traces/index.ts',
output: 'traces/index'
},
{
name: 'document-understanding',
input: 'src/models/document-understanding/index.ts',
output: 'document-understanding/index'
},
{
name: 'orchestrator-du-module',
input: 'src/services/orchestrator/du-module/index.ts',
output: 'orchestrator-du-module/index'
},
{
name: 'agents',
input: 'src/services/agents/index.ts',
output: 'agents/index'
},
{
name: 'governance',
input: 'src/services/governance/index.ts',
output: 'governance/index'
},
{
name: 'notifications',
input: 'src/services/notification/index.ts',
output: 'notifications/index'
},
{
name: 'functions',
input: 'src/services/orchestrator/functions/index.ts',
output: 'functions/index'
},
{
name: 'platform',
input: 'src/services/platform/index.ts',
output: 'platform/index'
},
{
name: 'business-apps',
input: 'src/services/maestro/business-apps/index.ts',
output: 'business-apps/index'
}
];
// Generate ESM, CJS, and DTS builds for each service entry
serviceEntries.forEach(({ name, input, output }) => {
// ESM bundle
configs.push({
input,
output: { file: `dist/${output}.mjs`, format: 'es', inlineDynamicImports: true },
plugins: createPlugins(false),
external: allDependencies
});
// CommonJS bundle
configs.push({
input,
output: { file: `dist/${output}.cjs`, format: 'cjs', exports: 'named', inlineDynamicImports: true },
plugins: createPlugins(false),
external: allDependencies
});
// Type definitions
// Mark core types as external to avoid duplication (cleaner output, smaller files)
const isCore = name === 'core';
const dtsExternal = isCore ? [] : [/src\/core\//, /\.\.\/core/, /^@\/core/];
configs.push({
input,
output: { file: `dist/${output}.d.ts`, format: 'es' },
plugins: isCore
? [alias(aliasConfig), dts()]
: [alias(aliasConfig), dts(), rewriteDtsImports()],
external: dtsExternal
});
});
// Export all build configurations
export default configs;