@uipath/solution-packager 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1038 @@
1
+ // src/i18n/index.ts
2
+ import { I18nManager } from "@uipath/solutionpackager-tool-core";
3
+ // src/i18n/locales/de.json
4
+ var de_default = {
5
+ solutionpackager: {
6
+ solutionLoader: {
7
+ errors: {
8
+ pathRequired: "Solution directory path is required",
9
+ fileNotFound: "Solution file not found: {path}",
10
+ invalidSolution: "Invalid solution file: {path}",
11
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
12
+ invalidStorageFile: "Invalid {fileName} file"
13
+ }
14
+ },
15
+ optionsBuilder: {
16
+ errors: {
17
+ packageInfoRequired: "Package information is required for Pack command",
18
+ outputPathRequired: "Output path is required for Pack command",
19
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
20
+ }
21
+ }
22
+ }
23
+ };
24
+
25
+ // src/i18n/locales/en.ts
26
+ var en = {
27
+ solutionpackager: {
28
+ solutionLoader: {
29
+ errors: {
30
+ pathRequired: "Solution directory path is required",
31
+ fileNotFound: "Solution file not found: {path}",
32
+ invalidSolution: "Invalid solution file: {path}",
33
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
34
+ invalidStorageFile: "Invalid {fileName} file"
35
+ }
36
+ },
37
+ optionsBuilder: {
38
+ errors: {
39
+ packageInfoRequired: "Package information is required for Pack command",
40
+ outputPathRequired: "Output path is required for Pack command",
41
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
42
+ }
43
+ }
44
+ }
45
+ };
46
+ // src/i18n/locales/es.json
47
+ var es_default = {
48
+ solutionpackager: {
49
+ solutionLoader: {
50
+ errors: {
51
+ pathRequired: "Solution directory path is required",
52
+ fileNotFound: "Solution file not found: {path}",
53
+ invalidSolution: "Invalid solution file: {path}",
54
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
55
+ invalidStorageFile: "Invalid {fileName} file"
56
+ }
57
+ },
58
+ optionsBuilder: {
59
+ errors: {
60
+ packageInfoRequired: "Package information is required for Pack command",
61
+ outputPathRequired: "Output path is required for Pack command",
62
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
63
+ }
64
+ }
65
+ }
66
+ };
67
+ // src/i18n/locales/es-MX.json
68
+ var es_MX_default = {
69
+ solutionpackager: {
70
+ solutionLoader: {
71
+ errors: {
72
+ pathRequired: "Solution directory path is required",
73
+ fileNotFound: "Solution file not found: {path}",
74
+ invalidSolution: "Invalid solution file: {path}",
75
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
76
+ invalidStorageFile: "Invalid {fileName} file"
77
+ }
78
+ },
79
+ optionsBuilder: {
80
+ errors: {
81
+ packageInfoRequired: "Package information is required for Pack command",
82
+ outputPathRequired: "Output path is required for Pack command",
83
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
84
+ }
85
+ }
86
+ }
87
+ };
88
+ // src/i18n/locales/fr.json
89
+ var fr_default = {
90
+ solutionpackager: {
91
+ solutionLoader: {
92
+ errors: {
93
+ pathRequired: "Solution directory path is required",
94
+ fileNotFound: "Solution file not found: {path}",
95
+ invalidSolution: "Invalid solution file: {path}",
96
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
97
+ invalidStorageFile: "Invalid {fileName} file"
98
+ }
99
+ },
100
+ optionsBuilder: {
101
+ errors: {
102
+ packageInfoRequired: "Package information is required for Pack command",
103
+ outputPathRequired: "Output path is required for Pack command",
104
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
105
+ }
106
+ }
107
+ }
108
+ };
109
+ // src/i18n/locales/ja.json
110
+ var ja_default = {
111
+ solutionpackager: {
112
+ solutionLoader: {
113
+ errors: {
114
+ pathRequired: "Solution directory path is required",
115
+ fileNotFound: "Solution file not found: {path}",
116
+ invalidSolution: "Invalid solution file: {path}",
117
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
118
+ invalidStorageFile: "Invalid {fileName} file"
119
+ }
120
+ },
121
+ optionsBuilder: {
122
+ errors: {
123
+ packageInfoRequired: "Package information is required for Pack command",
124
+ outputPathRequired: "Output path is required for Pack command",
125
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
126
+ }
127
+ }
128
+ }
129
+ };
130
+ // src/i18n/locales/ko.json
131
+ var ko_default = {
132
+ solutionpackager: {
133
+ solutionLoader: {
134
+ errors: {
135
+ pathRequired: "Solution directory path is required",
136
+ fileNotFound: "Solution file not found: {path}",
137
+ invalidSolution: "Invalid solution file: {path}",
138
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
139
+ invalidStorageFile: "Invalid {fileName} file"
140
+ }
141
+ },
142
+ optionsBuilder: {
143
+ errors: {
144
+ packageInfoRequired: "Package information is required for Pack command",
145
+ outputPathRequired: "Output path is required for Pack command",
146
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
147
+ }
148
+ }
149
+ }
150
+ };
151
+ // src/i18n/locales/pt.json
152
+ var pt_default = {
153
+ solutionpackager: {
154
+ solutionLoader: {
155
+ errors: {
156
+ pathRequired: "Solution directory path is required",
157
+ fileNotFound: "Solution file not found: {path}",
158
+ invalidSolution: "Invalid solution file: {path}",
159
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
160
+ invalidStorageFile: "Invalid {fileName} file"
161
+ }
162
+ },
163
+ optionsBuilder: {
164
+ errors: {
165
+ packageInfoRequired: "Package information is required for Pack command",
166
+ outputPathRequired: "Output path is required for Pack command",
167
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
168
+ }
169
+ }
170
+ }
171
+ };
172
+ // src/i18n/locales/pt-BR.json
173
+ var pt_BR_default = {
174
+ solutionpackager: {
175
+ solutionLoader: {
176
+ errors: {
177
+ pathRequired: "Solution directory path is required",
178
+ fileNotFound: "Solution file not found: {path}",
179
+ invalidSolution: "Invalid solution file: {path}",
180
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
181
+ invalidStorageFile: "Invalid {fileName} file"
182
+ }
183
+ },
184
+ optionsBuilder: {
185
+ errors: {
186
+ packageInfoRequired: "Package information is required for Pack command",
187
+ outputPathRequired: "Output path is required for Pack command",
188
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
189
+ }
190
+ }
191
+ }
192
+ };
193
+ // src/i18n/locales/ro.json
194
+ var ro_default = {
195
+ solutionpackager: {
196
+ solutionLoader: {
197
+ errors: {
198
+ pathRequired: "Solution directory path is required",
199
+ fileNotFound: "Solution file not found: {path}",
200
+ invalidSolution: "Invalid solution file: {path}",
201
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
202
+ invalidStorageFile: "Invalid {fileName} file"
203
+ }
204
+ },
205
+ optionsBuilder: {
206
+ errors: {
207
+ packageInfoRequired: "Package information is required for Pack command",
208
+ outputPathRequired: "Output path is required for Pack command",
209
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
210
+ }
211
+ }
212
+ }
213
+ };
214
+ // src/i18n/locales/ru.json
215
+ var ru_default = {
216
+ solutionpackager: {
217
+ solutionLoader: {
218
+ errors: {
219
+ pathRequired: "Solution directory path is required",
220
+ fileNotFound: "Solution file not found: {path}",
221
+ invalidSolution: "Invalid solution file: {path}",
222
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
223
+ invalidStorageFile: "Invalid {fileName} file"
224
+ }
225
+ },
226
+ optionsBuilder: {
227
+ errors: {
228
+ packageInfoRequired: "Package information is required for Pack command",
229
+ outputPathRequired: "Output path is required for Pack command",
230
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
231
+ }
232
+ }
233
+ }
234
+ };
235
+ // src/i18n/locales/tr.json
236
+ var tr_default = {
237
+ solutionpackager: {
238
+ solutionLoader: {
239
+ errors: {
240
+ pathRequired: "Solution directory path is required",
241
+ fileNotFound: "Solution file not found: {path}",
242
+ invalidSolution: "Invalid solution file: {path}",
243
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
244
+ invalidStorageFile: "Invalid {fileName} file"
245
+ }
246
+ },
247
+ optionsBuilder: {
248
+ errors: {
249
+ packageInfoRequired: "Package information is required for Pack command",
250
+ outputPathRequired: "Output path is required for Pack command",
251
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
252
+ }
253
+ }
254
+ }
255
+ };
256
+ // src/i18n/locales/zh-CN.json
257
+ var zh_CN_default = {
258
+ solutionpackager: {
259
+ solutionLoader: {
260
+ errors: {
261
+ pathRequired: "Solution directory path is required",
262
+ fileNotFound: "Solution file not found: {path}",
263
+ invalidSolution: "Invalid solution file: {path}",
264
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
265
+ invalidStorageFile: "Invalid {fileName} file"
266
+ }
267
+ },
268
+ optionsBuilder: {
269
+ errors: {
270
+ packageInfoRequired: "Package information is required for Pack command",
271
+ outputPathRequired: "Output path is required for Pack command",
272
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
273
+ }
274
+ }
275
+ }
276
+ };
277
+ // src/i18n/locales/zh-TW.json
278
+ var zh_TW_default = {
279
+ solutionpackager: {
280
+ solutionLoader: {
281
+ errors: {
282
+ pathRequired: "Solution directory path is required",
283
+ fileNotFound: "Solution file not found: {path}",
284
+ invalidSolution: "Invalid solution file: {path}",
285
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
286
+ invalidStorageFile: "Invalid {fileName} file"
287
+ }
288
+ },
289
+ optionsBuilder: {
290
+ errors: {
291
+ packageInfoRequired: "Package information is required for Pack command",
292
+ outputPathRequired: "Output path is required for Pack command",
293
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
294
+ }
295
+ }
296
+ }
297
+ };
298
+ // src/i18n/locales/zu.json
299
+ var zu_default = {
300
+ solutionpackager: {
301
+ solutionLoader: {
302
+ errors: {
303
+ pathRequired: "Solution directory path is required",
304
+ fileNotFound: "Solution file not found: {path}",
305
+ invalidSolution: "Invalid solution file: {path}",
306
+ noSolutionFile: "No .uipx solution file found in directory: {path}",
307
+ invalidStorageFile: "Invalid {fileName} file"
308
+ }
309
+ },
310
+ optionsBuilder: {
311
+ errors: {
312
+ packageInfoRequired: "Package information is required for Pack command",
313
+ outputPathRequired: "Output path is required for Pack command",
314
+ invalidProjectIds: "The following project ids do not exist in the solution: {ids}"
315
+ }
316
+ }
317
+ }
318
+ };
319
+
320
+ // src/i18n/index.ts
321
+ I18nManager.registerTranslations("en", en);
322
+ I18nManager.registerTranslations("de", de_default);
323
+ I18nManager.registerTranslations("es", es_default);
324
+ I18nManager.registerTranslations("es-MX", es_MX_default);
325
+ I18nManager.registerTranslations("fr", fr_default);
326
+ I18nManager.registerTranslations("ja", ja_default);
327
+ I18nManager.registerTranslations("ko", ko_default);
328
+ I18nManager.registerTranslations("pt", pt_default);
329
+ I18nManager.registerTranslations("pt-BR", pt_BR_default);
330
+ I18nManager.registerTranslations("ro", ro_default);
331
+ I18nManager.registerTranslations("ru", ru_default);
332
+ I18nManager.registerTranslations("tr", tr_default);
333
+ I18nManager.registerTranslations("zh-CN", zh_CN_default);
334
+ I18nManager.registerTranslations("zh-TW", zh_TW_default);
335
+ I18nManager.registerTranslations("zu", zu_default);
336
+
337
+ // src/index.ts
338
+ import { RulesConfigFileType as RulesConfigFileType2 } from "@uipath/project-packager";
339
+ import {
340
+ BuildConfiguration as BuildConfiguration3,
341
+ LogLevel
342
+ } from "@uipath/solutionpackager-tool-core";
343
+
344
+ // src/browser-solution-packager-factory.ts
345
+ import { BrowserFileSystem } from "@uipath/filesystem/browser";
346
+ import {
347
+ setGlobalLogHandler,
348
+ ToolLogger as ToolLogger2
349
+ } from "@uipath/project-packager";
350
+ import { translate as translate3 } from "@uipath/solutionpackager-tool-core";
351
+ import {
352
+ BrowserContextStorage,
353
+ ConsoleTelemetryProvider,
354
+ TelemetryService
355
+ } from "@uipath/telemetry";
356
+
357
+ // src/services/solution-packager.ts
358
+ import {
359
+ GovernancePolicyService,
360
+ PackService,
361
+ ProjectToolExecutor,
362
+ ToolLogger,
363
+ ToolsFactory
364
+ } from "@uipath/project-packager";
365
+ import {
366
+ Path as Path4,
367
+ TargetFramework,
368
+ TemporaryStorageService,
369
+ ToolErrorCodes as ToolErrorCodes2,
370
+ ToolResult as ToolResult2,
371
+ toolsFactoryRepository,
372
+ ZipService
373
+ } from "@uipath/solutionpackager-tool-core";
374
+
375
+ // src/services/options-builder.ts
376
+ import {
377
+ BuildConfiguration,
378
+ Path,
379
+ translate
380
+ } from "@uipath/solutionpackager-tool-core";
381
+
382
+ class OptionsBuilder {
383
+ packageIdReader;
384
+ packService;
385
+ fileSystem;
386
+ constructor(packageIdReader, packService, fileSystem) {
387
+ this.packageIdReader = packageIdReader;
388
+ this.packService = packService;
389
+ this.fileSystem = fileSystem;
390
+ }
391
+ static FILES_DIRECTORY_NAME = "files";
392
+ async buildSolutionPackOptions(parameters, solution) {
393
+ if (!parameters.outputPath) {
394
+ throw new Error(translate.t("solutionpackager.optionsBuilder.errors.outputPathRequired"));
395
+ }
396
+ await this.createOutputFilesDirectoryAsync(parameters.outputPath);
397
+ const projectsToBuild = this.getProjectIdsToBuild(parameters, solution);
398
+ if (!parameters.package.id || parameters.package.id.trim() === "") {
399
+ parameters.package.id = solution.Name;
400
+ }
401
+ return {
402
+ solutionFilePath: solution.filePath,
403
+ outputPath: parameters.outputPath,
404
+ connection: parameters.connection,
405
+ configuration: parameters.configuration,
406
+ package: parameters.package,
407
+ publishId: parameters.publishInfo?.id,
408
+ projectsToBuild
409
+ };
410
+ }
411
+ async createOutputFilesDirectoryAsync(outputPath) {
412
+ const filesDir = Path.join(outputPath, OptionsBuilder.FILES_DIRECTORY_NAME);
413
+ await this.fileSystem.mkdir(filesDir);
414
+ }
415
+ async buildProjectPackOptions(solutionOptions, project) {
416
+ const solutionFolderPath = solutionOptions.inputPath;
417
+ const projectRelativePath = Path.dirname(project.ProjectRelativePath);
418
+ const projectPath = Path.join(solutionFolderPath, projectRelativePath);
419
+ const solutionName = solutionOptions.package.id || undefined;
420
+ const packageInfo = {
421
+ ...solutionOptions.package,
422
+ id: await this.packageIdReader.read(project, solutionOptions.inputPath, solutionName) || ""
423
+ };
424
+ if (!solutionOptions.outputPath) {
425
+ throw new Error(translate.t("solutionpackager.optionsBuilder.errors.outputPathRequired"));
426
+ }
427
+ const packageId = !packageInfo.id || packageInfo.id.trim() === "" ? Path.basename(projectPath) : packageInfo.id;
428
+ packageInfo.id = this.packService.sanitizePackageId(packageId);
429
+ return {
430
+ projectPath,
431
+ excludeConfiguredSources: solutionOptions.excludeConfiguredSources ?? false,
432
+ nuGetSourcesConfigPath: solutionOptions.nuGetSourcesConfigPath,
433
+ logLevel: solutionOptions.logLevel,
434
+ skipAnalyze: solutionOptions.validateOptions.skipAnalyze,
435
+ skipValidate: false,
436
+ projectStorageId: project.StorageId,
437
+ detailedLogPath: solutionOptions.detailedLogPath,
438
+ policyFilePath: solutionOptions.validateOptions.governanceFilePath,
439
+ policyFileType: solutionOptions.validateOptions.governanceFileType,
440
+ outputPath: await this.buildProjectOutputPath(solutionOptions.outputPath, project),
441
+ outputType: undefined,
442
+ projectType: project.Type,
443
+ package: packageInfo,
444
+ skipDependencyOptimization: solutionOptions.packOptions?.skipDependencyOptimization ?? false,
445
+ includeSources: solutionOptions.packOptions?.includeSources ?? false,
446
+ splitPackages: solutionOptions.packOptions?.splitPackages ?? false
447
+ };
448
+ }
449
+ async buildProjectOutputPath(solutionOutputPath, project) {
450
+ const filesDir = Path.join(solutionOutputPath, OptionsBuilder.FILES_DIRECTORY_NAME);
451
+ const projectOutputPath = Path.join(filesDir, project.Id);
452
+ await this.fileSystem.mkdir(projectOutputPath);
453
+ return projectOutputPath;
454
+ }
455
+ getProjectIdsToBuild(parameters, solution) {
456
+ const solutionProjectIds = solution.Projects.map((p) => p.Id);
457
+ if (parameters.projectsToBuild === null || parameters.projectsToBuild === undefined || parameters.projectsToBuild.length === 0) {
458
+ return parameters.configuration === BuildConfiguration.Release ? solutionProjectIds : [];
459
+ }
460
+ const invalidProjectIds = parameters.projectsToBuild.filter((id) => !solutionProjectIds.includes(id));
461
+ if (invalidProjectIds.length > 0) {
462
+ console.warn(translate.t("solutionpackager.optionsBuilder.errors.invalidProjectIds", {
463
+ ids: invalidProjectIds.join(",")
464
+ }));
465
+ return solutionProjectIds.filter((id) => parameters.projectsToBuild?.includes(id));
466
+ }
467
+ return parameters.projectsToBuild;
468
+ }
469
+ }
470
+
471
+ // src/services/package-id-reader.ts
472
+ import { Path as Path2 } from "@uipath/solutionpackager-tool-core";
473
+ var legacySolutionResourcesFileName = "resources.json";
474
+
475
+ class PackageIdReader {
476
+ fileSystem;
477
+ packService;
478
+ projectTypesToFolderNameMapping = {
479
+ processorchestration: "processOrchestration",
480
+ casemanagement: "caseManagement",
481
+ agent: "agent",
482
+ api: "api",
483
+ webapp: "webApp",
484
+ process: "process"
485
+ };
486
+ static projectTypeMap = {
487
+ process: "Rpa",
488
+ library: "Lib",
489
+ tests: "Tests",
490
+ webapp: "App",
491
+ processorchestration: "Agentic",
492
+ casemanagement: "Case",
493
+ api: "Api",
494
+ agent: "Agent"
495
+ };
496
+ constructor(fileSystem, packService) {
497
+ this.fileSystem = fileSystem;
498
+ this.packService = packService;
499
+ }
500
+ async read(project, solutionPath, solutionName) {
501
+ try {
502
+ if (!solutionPath || solutionPath.trim() === "") {
503
+ return this.defaultToProjectFolder(project, solutionPath, solutionName);
504
+ }
505
+ return await this.readFromResourcesDirectory(project, solutionPath) || await this.readFromLegacyResourcesJson(project, solutionPath) || this.defaultToProjectFolder(project, solutionPath, solutionName);
506
+ } catch (ex) {
507
+ console.error("Error reading package ID:", ex);
508
+ return this.defaultToProjectFolder(project, solutionPath, solutionName);
509
+ }
510
+ }
511
+ defaultToProjectFolder(project, solutionPath, solutionName) {
512
+ const projectFolderName = Path2.dirname(project.ProjectRelativePath);
513
+ const id = this.packService.sanitizePackageId(projectFolderName);
514
+ return this.getPackageId(id, project, solutionPath, solutionName);
515
+ }
516
+ getPackageId(rootPackageId, project, solutionPath, solutionName) {
517
+ const packageId = this.composePackageId(rootPackageId, project, solutionPath, solutionName);
518
+ return this.packService.sanitizePackageId(packageId);
519
+ }
520
+ composePackageId(rootPackageId, project, solutionPath, solutionName) {
521
+ if (!solutionName && (!solutionPath || solutionPath.trim() === "")) {
522
+ return rootPackageId;
523
+ }
524
+ const resolvedSolutionName = solutionName || this.deriveSolutionName(solutionPath);
525
+ const parts = [resolvedSolutionName];
526
+ if (project.Type) {
527
+ parts.push(PackageIdReader.normalizeProjectType(project.Type));
528
+ }
529
+ parts.push(rootPackageId);
530
+ return parts.join(".");
531
+ }
532
+ static normalizeProjectType(projectType) {
533
+ const normalizedKey = projectType.toLowerCase();
534
+ return PackageIdReader.projectTypeMap[normalizedKey] || projectType;
535
+ }
536
+ deriveSolutionName(solutionPath) {
537
+ const ext = Path2.extname(solutionPath);
538
+ const base = Path2.basename(solutionPath);
539
+ return ext ? base.substring(0, base.length - ext.length) : base;
540
+ }
541
+ async readFromLegacyResourcesJson(project, solutionPath) {
542
+ const resourcesFilePath = Path2.join(solutionPath, legacySolutionResourcesFileName);
543
+ const exists = await this.fileSystem.exists(resourcesFilePath);
544
+ if (!exists) {
545
+ return null;
546
+ }
547
+ const data = await this.fileSystem.readFile(resourcesFilePath);
548
+ if (!data) {
549
+ return null;
550
+ }
551
+ const json = new TextDecoder().decode(data);
552
+ return this.getProjectIdFromJson(project, json);
553
+ }
554
+ getProjectIdFromJson(project, json) {
555
+ try {
556
+ const jsonObject = JSON.parse(json);
557
+ const resources = this.getProperty(jsonObject, "resources");
558
+ if (!Array.isArray(resources)) {
559
+ return null;
560
+ }
561
+ const resource = resources.find((r) => {
562
+ const projectKey = this.getProperty(r, "projectKey");
563
+ const kind = this.getProperty(r, "kind");
564
+ return projectKey === project.Id && kind?.toLowerCase() === "process";
565
+ });
566
+ if (!resource) {
567
+ return null;
568
+ }
569
+ const spec = this.getProperty(resource, "spec");
570
+ if (!spec) {
571
+ return null;
572
+ }
573
+ const packageName = this.getProperty(spec, "packageName");
574
+ if (!packageName || typeof packageName !== "string" || packageName.trim() === "") {
575
+ return null;
576
+ }
577
+ return packageName;
578
+ } catch (ex) {
579
+ console.error("Error parsing legacy resources JSON:", ex);
580
+ return null;
581
+ }
582
+ }
583
+ async readFromResourcesDirectory(project, solutionPath) {
584
+ const projectTypeLower = project.Type.toLowerCase();
585
+ const projectTypeFolder = this.projectTypesToFolderNameMapping[projectTypeLower] || Path2.dirname(project.ProjectRelativePath);
586
+ const processDirectory = Path2.join(solutionPath, "resources", "solution_folder", "process", projectTypeFolder);
587
+ const stats = await this.fileSystem.stat(processDirectory);
588
+ if (!stats?.isDirectory()) {
589
+ return null;
590
+ }
591
+ const files = await this.fileSystem.readdir(processDirectory);
592
+ const jsonFiles = files.filter((f) => f.endsWith(".json")).map((f) => Path2.join(processDirectory, f));
593
+ for (const jsonFile of jsonFiles) {
594
+ try {
595
+ const data = await this.fileSystem.readFile(jsonFile);
596
+ if (!data) {
597
+ continue;
598
+ }
599
+ const json = new TextDecoder().decode(data);
600
+ const jsonObject = JSON.parse(json);
601
+ const resource = this.getProperty(jsonObject, "resource");
602
+ const projectKey = this.getProperty(resource, "projectKey");
603
+ if (projectKey === project.Id) {
604
+ const spec = this.getProperty(resource, "spec");
605
+ let packageName = this.getProperty(spec, "packageName");
606
+ if (!packageName || typeof packageName !== "string" || packageName.trim() === "") {
607
+ packageName = null;
608
+ }
609
+ return packageName;
610
+ }
611
+ } catch (ex) {
612
+ console.error("Error reading resource file:", jsonFile, ex);
613
+ }
614
+ }
615
+ return null;
616
+ }
617
+ getProperty(obj, propertyName) {
618
+ if (!obj || typeof obj !== "object") {
619
+ return null;
620
+ }
621
+ const keys = Object.keys(obj);
622
+ const matchingKey = keys.find((key) => key.toLowerCase() === propertyName.toLowerCase());
623
+ return matchingKey ? obj[matchingKey] : null;
624
+ }
625
+ }
626
+
627
+ // src/services/solution-loader.ts
628
+ import { Path as Path3, translate as translate2 } from "@uipath/solutionpackager-tool-core";
629
+
630
+ class SolutionLoader {
631
+ fileSystem;
632
+ static SolutionStorageFileName = ".storage";
633
+ constructor(fileSystem) {
634
+ this.fileSystem = fileSystem;
635
+ }
636
+ async loadSolution(solutionPath) {
637
+ if (!solutionPath) {
638
+ throw new Error(translate2.t("solutionpackager.solutionLoader.errors.pathRequired"));
639
+ }
640
+ const solutionFilePath = await this.getSolutionFilePathAsync(solutionPath);
641
+ const fileContent = await this.fileSystem.readFile(solutionFilePath);
642
+ if (!fileContent) {
643
+ throw new Error(translate2.t("solutionpackager.solutionLoader.errors.fileNotFound", {
644
+ path: solutionFilePath
645
+ }));
646
+ }
647
+ const json = typeof fileContent === "string" ? fileContent : new TextDecoder("utf-8").decode(fileContent);
648
+ const solution = JSON.parse(json);
649
+ if (!solution?.Projects) {
650
+ throw new Error(translate2.t("solutionpackager.solutionLoader.errors.invalidSolution", {
651
+ path: solutionFilePath
652
+ }));
653
+ }
654
+ const loadedSolution = {
655
+ ...solution,
656
+ Name: GetSolutionName(),
657
+ filePath: solutionFilePath
658
+ };
659
+ for (const project of loadedSolution.Projects) {
660
+ const projectRelativeDir = Path3.dirname(project.ProjectRelativePath);
661
+ project.ProjectPath = Path3.join(solutionPath, projectRelativeDir);
662
+ }
663
+ await this.populateStorageIds(loadedSolution, solutionPath);
664
+ return loadedSolution;
665
+ function GetSolutionName() {
666
+ const uipxFileName = Path3.basename(solutionFilePath);
667
+ return uipxFileName.replace(/\.uipx$/i, "");
668
+ }
669
+ }
670
+ async getSolutionFilePathAsync(solutionPath) {
671
+ const files = await this.fileSystem.readdir(solutionPath);
672
+ const uipxFile = files.find((file) => file.endsWith(".uipx"));
673
+ if (!uipxFile) {
674
+ throw new Error(translate2.t("solutionpackager.solutionLoader.errors.noSolutionFile", {
675
+ path: solutionPath
676
+ }));
677
+ }
678
+ return Path3.join(solutionPath, uipxFile);
679
+ }
680
+ async populateStorageIds(solution, rootDirectory) {
681
+ const storageFile = Path3.join(rootDirectory, SolutionLoader.SolutionStorageFileName);
682
+ const exists = await this.fileSystem.exists(storageFile);
683
+ if (!exists) {
684
+ return;
685
+ }
686
+ const fileContent = await this.fileSystem.readFile(storageFile);
687
+ if (!fileContent) {
688
+ return;
689
+ }
690
+ const json = typeof fileContent === "string" ? fileContent : new TextDecoder("utf-8").decode(fileContent);
691
+ const storage = JSON.parse(json);
692
+ if (!storage?.Projects) {
693
+ throw new Error(translate2.t("solutionpackager.solutionLoader.errors.invalidStorageFile", {
694
+ fileName: SolutionLoader.SolutionStorageFileName
695
+ }));
696
+ }
697
+ for (const project of solution.Projects) {
698
+ const storageProject = storage.Projects.find((sp) => sp.ProjectRelativePath === project.ProjectRelativePath);
699
+ if (storageProject) {
700
+ project.StorageId = storageProject.ProjectId;
701
+ }
702
+ }
703
+ }
704
+ }
705
+
706
+ // src/services/solution-pack-options-validator.ts
707
+ import {
708
+ PackagerParametersValidator
709
+ } from "@uipath/project-packager";
710
+
711
+ class SolutionPackOptionsValidator extends PackagerParametersValidator {
712
+ async validateAsync(options, _cancellationToken) {
713
+ const destinationResult = this.validateDestinationPath(options.destinationPath);
714
+ if (!destinationResult.isSuccess) {
715
+ return destinationResult;
716
+ }
717
+ return await this.validateGovernanceOptions(options.validateOptions);
718
+ }
719
+ }
720
+
721
+ // src/services/solution-pack-service.ts
722
+ import {
723
+ ToolErrorCodes,
724
+ ToolResult
725
+ } from "@uipath/solutionpackager-tool-core";
726
+ class SolutionPackService {
727
+ optionsBuilder;
728
+ toolsFactory;
729
+ projectExecutor;
730
+ zipService;
731
+ fileSystem;
732
+ telemetry;
733
+ constructor(optionsBuilder, toolsFactory, projectExecutor, zipService, fileSystem, telemetry) {
734
+ this.optionsBuilder = optionsBuilder;
735
+ this.toolsFactory = toolsFactory;
736
+ this.projectExecutor = projectExecutor;
737
+ this.zipService = zipService;
738
+ this.fileSystem = fileSystem;
739
+ this.telemetry = telemetry;
740
+ }
741
+ async packAsync(parameters, solution, context, cancellationToken) {
742
+ const solutionOptions = await this.optionsBuilder.buildSolutionPackOptions(parameters, solution);
743
+ const solutionTool = await this.toolsFactory.createSolutionToolAsync(solution.SolutionId);
744
+ try {
745
+ return await this.telemetry.trackDependencyOperation("SolutionPackager.Solution.Pack" /* SolutionPack */, "pack", async () => {
746
+ const [restoreResult, ...projectResults] = await Promise.all([
747
+ solutionTool.restoreAsync(solutionOptions, cancellationToken),
748
+ ...this.packAllProjectsAsync(parameters, solution.Projects, context, cancellationToken)
749
+ ]);
750
+ const restoreAndPackResults = [
751
+ restoreResult,
752
+ ...projectResults
753
+ ];
754
+ if (this.hasFailedResults(restoreAndPackResults)) {
755
+ return ToolResult.error(ToolErrorCodes.InternalError, `Solution pack failed: ${this.getFailedResultsMessage(restoreAndPackResults)}`);
756
+ }
757
+ const buildResult = await solutionTool.buildAsync(solutionOptions, cancellationToken);
758
+ if (!buildResult.isSuccess) {
759
+ return ToolResult.error(buildResult.errorCode, `Solution build failed: ${buildResult.message || "Unknown error"}`);
760
+ }
761
+ if (!solutionOptions.outputPath) {
762
+ return ToolResult.error(ToolErrorCodes.InternalError, "Solution output path is not defined");
763
+ }
764
+ const archivePath = await this.compressSolutionAsync(parameters, solutionOptions.outputPath);
765
+ return new ToolResult(ToolErrorCodes.Success, undefined, [
766
+ archivePath
767
+ ]);
768
+ }, { solutionId: solution.SolutionId });
769
+ } finally {
770
+ const disposeResult = solutionTool.dispose();
771
+ if (disposeResult instanceof Promise) {
772
+ await disposeResult;
773
+ }
774
+ }
775
+ }
776
+ packAllProjectsAsync(parameters, projects, context, cancellationToken) {
777
+ return projects.map((project) => this.packSingleProjectAsync(parameters, project, context, cancellationToken));
778
+ }
779
+ async packSingleProjectAsync(parameters, project, context, cancellationToken) {
780
+ try {
781
+ const projectOptions = await this.optionsBuilder.buildProjectPackOptions(parameters, project);
782
+ return await this.projectExecutor.packAsync(projectOptions, project, context, parameters.signingInfo, cancellationToken);
783
+ } catch (error) {
784
+ const errorMessage = error instanceof Error ? error.message : String(error);
785
+ return ToolResult.error(ToolErrorCodes.InternalError, errorMessage);
786
+ }
787
+ }
788
+ hasFailedResults(results) {
789
+ return results.some((result) => !result.isSuccess);
790
+ }
791
+ getFailedResultsMessage(results) {
792
+ const failedResults = results.filter((result) => !result.isSuccess);
793
+ return failedResults.map((r) => r.message || "Unknown error").join(", ");
794
+ }
795
+ async compressSolutionAsync(parameters, outputPath) {
796
+ return await this.telemetry.trackDependencyOperation("SolutionPackager.Solution.Compress" /* SolutionCompress */, "compress", async () => {
797
+ const packageName = parameters.package.id || "solution";
798
+ const version = parameters.package.version || "1.0.0";
799
+ const archiveFileName = `${packageName}_${version}.zip`;
800
+ const archivePath = `${parameters.destinationPath}/${archiveFileName}`;
801
+ const zipData = await this.zipService.compressAsync(outputPath);
802
+ await this.fileSystem.writeFile(archivePath, zipData);
803
+ return archivePath;
804
+ });
805
+ }
806
+ }
807
+
808
+ // src/services/solution-packager.ts
809
+ class SolutionPackager {
810
+ fileSystem;
811
+ telemetryService;
812
+ packageSignService;
813
+ repository;
814
+ temporaryStorage;
815
+ zipService;
816
+ logger;
817
+ optionsBuilder;
818
+ toolsFactory;
819
+ projectExecutor;
820
+ solutionLoader;
821
+ solutionPackService;
822
+ optionsValidator;
823
+ governancePolicyService;
824
+ constructor(fileSystem, telemetryService, packageSignService) {
825
+ this.fileSystem = fileSystem;
826
+ this.telemetryService = telemetryService;
827
+ this.packageSignService = packageSignService;
828
+ this.repository = toolsFactoryRepository;
829
+ this.temporaryStorage = new TemporaryStorageService(this.fileSystem);
830
+ this.zipService = new ZipService(this.fileSystem);
831
+ this.logger = new ToolLogger("SolutionPackager", "PackSolution");
832
+ this.optionsValidator = new SolutionPackOptionsValidator(this.logger, this.fileSystem);
833
+ const packService = new PackService;
834
+ const packageIdReader = new PackageIdReader(this.fileSystem, packService);
835
+ this.optionsBuilder = new OptionsBuilder(packageIdReader, packService, this.fileSystem);
836
+ this.toolsFactory = new ToolsFactory(this.repository, this.fileSystem);
837
+ this.projectExecutor = new ProjectToolExecutor(this.toolsFactory, this.telemetryService, this.packageSignService);
838
+ this.solutionLoader = new SolutionLoader(this.fileSystem);
839
+ this.governancePolicyService = new GovernancePolicyService(this.fileSystem, this.temporaryStorage);
840
+ this.solutionPackService = new SolutionPackService(this.optionsBuilder, this.toolsFactory, this.projectExecutor, this.zipService, this.fileSystem, this.telemetryService);
841
+ }
842
+ async canPackSolutionAsync(solutionPath) {
843
+ const solution = await this.solutionLoader.loadSolution(solutionPath);
844
+ for (const project of solution.Projects) {
845
+ if (!project.ProjectPath) {
846
+ return false;
847
+ }
848
+ const canHandle = this.repository.canHandleProject(project.Type);
849
+ if (!canHandle) {
850
+ return false;
851
+ }
852
+ }
853
+ return true;
854
+ }
855
+ async setupAsync(input, operationId) {
856
+ this.telemetryService.setOperationId(operationId);
857
+ await this.temporaryStorage.cleanup();
858
+ if (typeof input === "string") {
859
+ return input;
860
+ }
861
+ const inputPath = await this.temporaryStorage.getTempSubfolderPathAsync("input");
862
+ await this.zipService.extractAsync(input, inputPath);
863
+ const entries = await this.fileSystem.readdir(inputPath);
864
+ if (entries.length === 1) {
865
+ const innerPath = Path4.join(inputPath, entries[0]);
866
+ const stat = await this.fileSystem.stat(innerPath);
867
+ if (stat?.isDirectory()) {
868
+ return innerPath;
869
+ }
870
+ }
871
+ return inputPath;
872
+ }
873
+ async setupWithUrlAsync(downloadUrl, accessToken, operationId) {
874
+ const headers = {};
875
+ if (accessToken) {
876
+ headers.Authorization = `Bearer ${accessToken}`;
877
+ }
878
+ const response = await fetch(downloadUrl, { headers });
879
+ if (!response.ok) {
880
+ throw new Error(`Failed to download solution: ${response.status} ${response.statusText}`);
881
+ }
882
+ const arrayBuffer = await response.arrayBuffer();
883
+ const zipData = new Uint8Array(arrayBuffer);
884
+ return this.setupAsync(zipData, operationId);
885
+ }
886
+ async packSolutionAsync(options, cancellationToken) {
887
+ return await this.telemetryService.trackRequest("SolutionPackager.PackSolution" /* SolutionPackagerPackSolution */, async () => {
888
+ try {
889
+ await this.governancePolicyService.resolveGovernancePolicyAsync(options.validateOptions, options.connection, cancellationToken);
890
+ let result = await this.optionsValidator.validateAsync(options, cancellationToken);
891
+ if (!result.isSuccess) {
892
+ return result;
893
+ }
894
+ if (!options.outputPath) {
895
+ options.outputPath = await this.temporaryStorage.getTempSubfolderPathAsync("output");
896
+ }
897
+ const solution = await this.solutionLoader.loadSolution(options.inputPath);
898
+ const context = this.createOperationContext(options, solution);
899
+ result = await this.solutionPackService.packAsync(options, solution, context, cancellationToken);
900
+ if (result.isSuccess) {
901
+ this.logger.info(`Solution pack completed successfully. Packages: ${result.packages.join(", ")}`);
902
+ } else {
903
+ this.logger.error(`Solution pack failed with error code ${result.errorCode}: ${result.message}`);
904
+ }
905
+ return result;
906
+ } catch (error) {
907
+ const errorMessage = error instanceof Error ? error.message : String(error);
908
+ this.logger.error(`Processing error: ${errorMessage}`);
909
+ return ToolResult2.error(ToolErrorCodes2.InternalError, `Solution pack failed: ${errorMessage}`);
910
+ } finally {
911
+ await this.temporaryStorage.cleanup();
912
+ }
913
+ });
914
+ }
915
+ createOperationContext(options, solution) {
916
+ return {
917
+ id: crypto.randomUUID(),
918
+ solution,
919
+ downloadUrl: options.downloadUrl,
920
+ configuration: options.configuration,
921
+ targetFramework: options.targetFramework ?? TargetFramework.Portable,
922
+ connection: options.connection,
923
+ logger: this.logger,
924
+ workflowCompilerVersion: options.workflowCompilerVersion
925
+ };
926
+ }
927
+ async getPackageStreamsAsync(result) {
928
+ if (!result.isSuccess) {
929
+ throw new Error(`Cannot get package streams from failed result. Error code: ${result.errorCode}, message: ${result.message}`);
930
+ }
931
+ if (!result.packages || result.packages.length === 0) {
932
+ return [];
933
+ }
934
+ const packageStreams = [];
935
+ for (const packagePath of result.packages) {
936
+ const data = await this.fileSystem.readFile(packagePath);
937
+ if (!data) {
938
+ throw new Error(`Failed to read package file: ${packagePath}`);
939
+ }
940
+ const name = packagePath.split(/[\\/]/).pop() || packagePath;
941
+ packageStreams.push({ name, data });
942
+ }
943
+ return packageStreams;
944
+ }
945
+ }
946
+
947
+ // src/browser-solution-packager-factory.ts
948
+ var sharedFileSystem = null;
949
+ var GLOBAL_FS_KEY = "__uipath_sharedFileSystem";
950
+
951
+ class BrowserSolutionPackagerFactory {
952
+ async createAsync(config) {
953
+ const logger = new ToolLogger2("SolutionPackagerFactory", "Create");
954
+ this.configureLanguage(config);
955
+ this.configureLogHandler(config);
956
+ logger.info("Creating SolutionPackager instance...");
957
+ const fileSystem = await this.getOrCreateFileSystem(config);
958
+ const telemetryService = this.getOrCreateTelemetryService(config);
959
+ const solutionPackager = new SolutionPackager(fileSystem, telemetryService);
960
+ logger.info("SolutionPackager created successfully.");
961
+ return solutionPackager;
962
+ }
963
+ async getOrCreateFileSystem(config) {
964
+ if (config?.fileSystem) {
965
+ return config.fileSystem;
966
+ }
967
+ if (!sharedFileSystem) {
968
+ sharedFileSystem = globalThis[GLOBAL_FS_KEY] ?? null;
969
+ }
970
+ if (!sharedFileSystem) {
971
+ const fs = new BrowserFileSystem;
972
+ try {
973
+ await fs.init();
974
+ } catch (error) {
975
+ if (error instanceof Error && error.message.includes("Mount point is already in use")) {
976
+ fs.initialized = true;
977
+ } else {
978
+ throw error;
979
+ }
980
+ }
981
+ sharedFileSystem = fs;
982
+ globalThis[GLOBAL_FS_KEY] = fs;
983
+ }
984
+ return sharedFileSystem;
985
+ }
986
+ getOrCreateTelemetryService(config) {
987
+ if (config?.telemetryService) {
988
+ return config.telemetryService;
989
+ }
990
+ const provider = new ConsoleTelemetryProvider;
991
+ const contextStorage = new BrowserContextStorage;
992
+ return new TelemetryService(provider, contextStorage);
993
+ }
994
+ configureLogHandler(config) {
995
+ if (config?.logHandler) {
996
+ setGlobalLogHandler(config.logHandler);
997
+ }
998
+ }
999
+ configureLanguage(config) {
1000
+ const language = config?.language ?? "en";
1001
+ translate3.setLocale(language);
1002
+ }
1003
+ }
1004
+ async function createBrowserSolutionPackager(options) {
1005
+ const factory = new BrowserSolutionPackagerFactory;
1006
+ return factory.createAsync(options);
1007
+ }
1008
+ // src/models/solution-pack-options.ts
1009
+ import {
1010
+ PackagerParameters,
1011
+ RulesConfigFileType
1012
+ } from "@uipath/project-packager";
1013
+ import {
1014
+ BuildConfiguration as BuildConfiguration2
1015
+ } from "@uipath/solutionpackager-tool-core";
1016
+
1017
+ class SolutionPackOptions extends PackagerParameters {
1018
+ downloadUrl;
1019
+ destinationPath;
1020
+ projectsToBuild;
1021
+ validateOptions = {
1022
+ skipAnalyze: false,
1023
+ governanceFileType: RulesConfigFileType.Default
1024
+ };
1025
+ package;
1026
+ configuration = BuildConfiguration2.Release;
1027
+ signingInfo;
1028
+ packOptions;
1029
+ publishInfo;
1030
+ }
1031
+ export {
1032
+ createBrowserSolutionPackager,
1033
+ SolutionPackager,
1034
+ SolutionPackOptions,
1035
+ RulesConfigFileType2 as RulesConfigFileType,
1036
+ LogLevel,
1037
+ BuildConfiguration3 as BuildConfiguration
1038
+ };