@uipath/packager-tool-functions 1.204.0 → 1.205.0-preview.258
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/README.md +5 -2
- package/dist/functions-tool.d.ts +23 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +105 -42
- package/dist/language-detection.d.ts +18 -0
- package/dist/language-detection.js +61 -0
- package/dist/types.d.ts +10 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ CLI: uip function pack (Python)
|
|
|
26
26
|
|
|
27
27
|
`FunctionsTool` implements `ProjectTool` for `ProjectType.Function`. On `buildAsync`:
|
|
28
28
|
|
|
29
|
-
1.
|
|
29
|
+
1. Probes the project: its name from `project.uiproj` (`Name`), and its language through `detectProjectLanguage` (also exported from `./language-detection`, which the `uip function` dispatcher uses). A project with no language signal is reported as not initialized, by name, and nothing is built.
|
|
30
30
|
2. **JS/TS**: delegates to `buildFunctionsPackage(fs, options)` from `@uipath/coded-functions-js-packager` (externally-published library, shared with the `uipath-functions` CLI).
|
|
31
31
|
3. **Python**: delegates to the local `buildPyFunctionsPackage(fs, options)` implementation in [`src/py/`](src/py/).
|
|
32
32
|
|
|
@@ -36,8 +36,11 @@ CLI: uip function pack (Python)
|
|
|
36
36
|
|---|---|
|
|
37
37
|
| `uipath.json` functions map extension `.ts`/`.js`/`.mjs` | javascript |
|
|
38
38
|
| `uipath.json` functions map extension `.py` | python |
|
|
39
|
+
| `package.json` present | javascript (fallback) |
|
|
39
40
|
| `pyproject.toml` present | python (fallback) |
|
|
40
|
-
|
|
|
41
|
+
| None of the above | not initialized — `Function project '<name>' is not initialized: ...` |
|
|
42
|
+
|
|
43
|
+
There is no language in `project.uiproj`, so the files the project's init wrote are the only signal. Build, pack and manifest-generation failures name the project and keep the inner error: `<stage> failed for Function project '<name>' (<language>): <error>`.
|
|
41
44
|
|
|
42
45
|
## Python build pipeline
|
|
43
46
|
|
package/dist/functions-tool.d.ts
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import type { IProjectBuildOptions, IProjectPackOptions, IProjectRestoreOptions, IProjectValidateOptions } from "@uipath/solutionpackager-tool-core";
|
|
2
2
|
import { type IFileSystem, type IToolLogger, ProjectTool, ToolResult } from "@uipath/solutionpackager-tool-core";
|
|
3
|
-
import { type
|
|
3
|
+
import { type FunctionsProjectProbe } from "./types.js";
|
|
4
4
|
export declare class FunctionsTool extends ProjectTool {
|
|
5
5
|
private readonly _temporaryStorage;
|
|
6
6
|
constructor(fileSystem: IFileSystem, logger: IToolLogger);
|
|
7
7
|
restoreAsync(_options: IProjectRestoreOptions, _cancellationToken?: AbortSignal): Promise<ToolResult>;
|
|
8
8
|
validateAsync(_options: IProjectValidateOptions, _cancellationToken?: AbortSignal): Promise<ToolResult>;
|
|
9
|
-
buildAsync(options: IProjectBuildOptions,
|
|
9
|
+
buildAsync(options: IProjectBuildOptions, cancellationToken?: AbortSignal): Promise<ToolResult>;
|
|
10
10
|
packAsync(options: IProjectPackOptions, cancellationToken?: AbortSignal): Promise<ToolResult>;
|
|
11
11
|
dispose(): Promise<void>;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Runs between the probe and the build. The base tool has nothing to
|
|
14
|
+
* prepare; a host that must touch the project first (the Node CLI
|
|
15
|
+
* regenerates JS/TS manifests from the sources) overrides this and gets
|
|
16
|
+
* the probe the build will use, so the project is read once.
|
|
17
|
+
*/
|
|
18
|
+
protected prepareBuildAsync(_probe: FunctionsProjectProbe, _options: IProjectBuildOptions, _cancellationToken?: AbortSignal): Promise<ToolResult>;
|
|
19
|
+
protected probeProject(projectPath: string): Promise<FunctionsProjectProbe>;
|
|
20
|
+
/**
|
|
21
|
+
* The failure to return when {@link probeProject} found no language:
|
|
22
|
+
* names the project and what was looked for, and says what to do,
|
|
23
|
+
* instead of guessing a language and failing inside its build.
|
|
24
|
+
*/
|
|
25
|
+
protected uninitializedProjectResult(probe: FunctionsProjectProbe, projectPath: string): ToolResult;
|
|
26
|
+
/**
|
|
27
|
+
* The failure to return when a stage of the pack throws: names the stage,
|
|
28
|
+
* the project and its language, and carries the inner error's message so
|
|
29
|
+
* the cause reaches the caller instead of only the log.
|
|
30
|
+
*/
|
|
31
|
+
protected failureResult(probe: FunctionsProjectProbe, stage: string, error: unknown): ToolResult;
|
|
32
|
+
private resolveProjectName;
|
|
13
33
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { FunctionsTool } from "./functions-tool.js";
|
|
2
2
|
export { FunctionsToolFactory } from "./functions-tool-factory.js";
|
|
3
|
-
export {
|
|
3
|
+
export { detectProjectLanguage, languageFromFunctionsMap, } from "./language-detection.js";
|
|
4
|
+
export { type FunctionsProjectProbe, type Language, Languages, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var Languages = {
|
|
3
|
+
JavaScript: "javascript",
|
|
4
|
+
Python: "python"
|
|
5
|
+
};
|
|
6
|
+
var LanguageLabels = {
|
|
7
|
+
[Languages.JavaScript]: "JS/TS",
|
|
8
|
+
[Languages.Python]: "Python"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/language-detection.ts
|
|
12
|
+
var EXTENSION_TO_LANGUAGE = {
|
|
13
|
+
".ts": Languages.JavaScript,
|
|
14
|
+
".js": Languages.JavaScript,
|
|
15
|
+
".mjs": Languages.JavaScript,
|
|
16
|
+
".py": Languages.Python
|
|
17
|
+
};
|
|
18
|
+
function languageFromFunctionsMap(functions) {
|
|
19
|
+
const firstEntry = Object.values(functions ?? {})[0];
|
|
20
|
+
if (!firstEntry) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const filePath = firstEntry.split(":")[0] ?? "";
|
|
24
|
+
const dot = filePath.lastIndexOf(".");
|
|
25
|
+
return dot >= 0 ? EXTENSION_TO_LANGUAGE[filePath.slice(dot)] : undefined;
|
|
26
|
+
}
|
|
27
|
+
async function detectProjectLanguage(fileSystem, projectPath) {
|
|
28
|
+
const fromManifest = await languageFromUipathJson(fileSystem, projectPath);
|
|
29
|
+
if (fromManifest) {
|
|
30
|
+
return fromManifest;
|
|
31
|
+
}
|
|
32
|
+
if (await fileSystem.exists(fileSystem.path.join(projectPath, "package.json"))) {
|
|
33
|
+
return Languages.JavaScript;
|
|
34
|
+
}
|
|
35
|
+
if (await fileSystem.exists(fileSystem.path.join(projectPath, "pyproject.toml"))) {
|
|
36
|
+
return Languages.Python;
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
async function languageFromUipathJson(fileSystem, projectPath) {
|
|
41
|
+
const uipathJsonPath = fileSystem.path.join(projectPath, "uipath.json");
|
|
42
|
+
if (!await fileSystem.exists(uipathJsonPath)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const content = await fileSystem.readFile(uipathJsonPath, "utf-8");
|
|
46
|
+
if (!content) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const uipathJson = JSON.parse(content);
|
|
51
|
+
return languageFromFunctionsMap(uipathJson.functions);
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
1
57
|
// src/functions-tool.ts
|
|
2
58
|
import {
|
|
3
59
|
ensureProjectId,
|
|
@@ -425,16 +481,6 @@ function addFileToDescriptor(packageDescriptor, key, fileName) {
|
|
|
425
481
|
const relativePath = Path.join(NugetConstants.ContentFolderName, fileName);
|
|
426
482
|
packageDescriptor.files[key] = relativePath;
|
|
427
483
|
}
|
|
428
|
-
// src/types.ts
|
|
429
|
-
var Languages = {
|
|
430
|
-
JavaScript: "javascript",
|
|
431
|
-
Python: "python"
|
|
432
|
-
};
|
|
433
|
-
var LanguageLabels = {
|
|
434
|
-
[Languages.JavaScript]: "JS/TS",
|
|
435
|
-
[Languages.Python]: "Python"
|
|
436
|
-
};
|
|
437
|
-
|
|
438
484
|
// src/functions-tool.ts
|
|
439
485
|
class FunctionsTool extends ProjectTool {
|
|
440
486
|
_temporaryStorage;
|
|
@@ -450,14 +496,20 @@ class FunctionsTool extends ProjectTool {
|
|
|
450
496
|
this.logger.info("Validate not required for Functions projects.");
|
|
451
497
|
return ToolResult.success();
|
|
452
498
|
}
|
|
453
|
-
async buildAsync(options,
|
|
454
|
-
const
|
|
499
|
+
async buildAsync(options, cancellationToken) {
|
|
500
|
+
const probe = await this.probeProject(options.projectPath);
|
|
501
|
+
if (probe.language === undefined) {
|
|
502
|
+
return this.uninitializedProjectResult(probe, options.projectPath);
|
|
503
|
+
}
|
|
504
|
+
const prepared = await this.prepareBuildAsync(probe, options, cancellationToken);
|
|
505
|
+
if (!prepared.isSuccess) {
|
|
506
|
+
return prepared;
|
|
507
|
+
}
|
|
455
508
|
const tempFolder = await this._temporaryStorage.getTempFolderPath();
|
|
456
509
|
const localBuildFolder = Path2.join(tempFolder, NugetConstants2.OutputFolderName);
|
|
457
|
-
const build = language === Languages.Python ? buildPyFunctionsPackage : buildJsFunctionsPackage;
|
|
458
|
-
const languageLabel = LanguageLabels[language];
|
|
510
|
+
const build = probe.language === Languages.Python ? buildPyFunctionsPackage : buildJsFunctionsPackage;
|
|
459
511
|
try {
|
|
460
|
-
this.logger.progress(`Building ${
|
|
512
|
+
this.logger.progress(`Building ${LanguageLabels[probe.language]} Functions package...`);
|
|
461
513
|
const projectStorageId = options.projectStorageId ?? await ensureProjectId(options.projectPath, this.fileSystem);
|
|
462
514
|
await build(this.fileSystem, {
|
|
463
515
|
projectPath: options.projectPath,
|
|
@@ -466,9 +518,7 @@ class FunctionsTool extends ProjectTool {
|
|
|
466
518
|
});
|
|
467
519
|
return new ToolResult(ToolErrorCodes.Success, "Build completed successfully.", [localBuildFolder]);
|
|
468
520
|
} catch (error) {
|
|
469
|
-
|
|
470
|
-
this.logger.error(errorMessage);
|
|
471
|
-
return ToolResult.error(ToolErrorCodes.InternalError, `Build failed for ${languageLabel} Functions project.`);
|
|
521
|
+
return this.failureResult(probe, "Build", error);
|
|
472
522
|
}
|
|
473
523
|
}
|
|
474
524
|
async packAsync(options, cancellationToken) {
|
|
@@ -486,9 +536,8 @@ class FunctionsTool extends ProjectTool {
|
|
|
486
536
|
this.logger.progress("Package created successfully.");
|
|
487
537
|
return new ToolResult(ToolErrorCodes.Success, "Pack completed successfully.", [result.outputPath]);
|
|
488
538
|
} catch (error) {
|
|
489
|
-
const
|
|
490
|
-
this.
|
|
491
|
-
return ToolResult.error(ToolErrorCodes.InternalError, "Pack failed for Functions project.");
|
|
539
|
+
const probe = await this.probeProject(options.projectPath);
|
|
540
|
+
return this.failureResult(probe, "Pack", error);
|
|
492
541
|
}
|
|
493
542
|
}
|
|
494
543
|
async dispose() {
|
|
@@ -497,28 +546,40 @@ class FunctionsTool extends ProjectTool {
|
|
|
497
546
|
await this._temporaryStorage.cleanup();
|
|
498
547
|
} catch {}
|
|
499
548
|
}
|
|
500
|
-
async
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
549
|
+
async prepareBuildAsync(_probe, _options, _cancellationToken) {
|
|
550
|
+
return ToolResult.success();
|
|
551
|
+
}
|
|
552
|
+
async probeProject(projectPath) {
|
|
553
|
+
const [name, language] = await Promise.all([
|
|
554
|
+
this.resolveProjectName(projectPath),
|
|
555
|
+
detectProjectLanguage(this.fileSystem, projectPath)
|
|
556
|
+
]);
|
|
557
|
+
return { name, language };
|
|
558
|
+
}
|
|
559
|
+
uninitializedProjectResult(probe, projectPath) {
|
|
560
|
+
const message = `${describeProject(probe)} is not initialized: ${projectPath} has no uipath.json functions map, no package.json and no pyproject.toml.`;
|
|
561
|
+
this.logger.error(message);
|
|
562
|
+
return ToolResult.error(ToolErrorCodes.InternalError, message, "Initialize the project, then pack again.");
|
|
563
|
+
}
|
|
564
|
+
failureResult(probe, stage, error) {
|
|
565
|
+
const inner = error instanceof Error ? error.message : String(error);
|
|
566
|
+
const languageLabel = probe.language === undefined ? "" : ` (${LanguageLabels[probe.language]})`;
|
|
567
|
+
const message = `${stage} failed for ${describeProject(probe)}${languageLabel}: ${inner}`;
|
|
568
|
+
this.logger.error(error instanceof Error ? error.toString() : String(error));
|
|
569
|
+
return ToolResult.error(ToolErrorCodes.InternalError, message);
|
|
570
|
+
}
|
|
571
|
+
async resolveProjectName(projectPath) {
|
|
572
|
+
try {
|
|
573
|
+
const uiProject = await this.getUiProjectAsync(projectPath);
|
|
574
|
+
return uiProject?.Name?.trim() ?? "";
|
|
575
|
+
} catch {
|
|
576
|
+
return "";
|
|
515
577
|
}
|
|
516
|
-
const pyprojectStat = await this.fileSystem.stat(Path2.join(projectPath, "pyproject.toml"));
|
|
517
|
-
if (pyprojectStat?.isFile())
|
|
518
|
-
return Languages.Python;
|
|
519
|
-
return Languages.JavaScript;
|
|
520
578
|
}
|
|
521
579
|
}
|
|
580
|
+
function describeProject(probe) {
|
|
581
|
+
return probe.name ? `Function project '${probe.name}'` : "Function project";
|
|
582
|
+
}
|
|
522
583
|
// src/functions-tool-factory.ts
|
|
523
584
|
import {
|
|
524
585
|
ProjectTypes
|
|
@@ -532,7 +593,9 @@ class FunctionsToolFactory {
|
|
|
532
593
|
export {
|
|
533
594
|
FunctionsTool,
|
|
534
595
|
FunctionsToolFactory,
|
|
535
|
-
Languages
|
|
596
|
+
Languages,
|
|
597
|
+
detectProjectLanguage,
|
|
598
|
+
languageFromFunctionsMap
|
|
536
599
|
};
|
|
537
600
|
|
|
538
|
-
//# debugId=
|
|
601
|
+
//# debugId=DBEEA31CD635E59F64756E2164756E21
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IFileSystem } from "@uipath/solutionpackager-tool-core";
|
|
2
|
+
import { type Language } from "./types.js";
|
|
3
|
+
export type { Language } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* The language a uipath.json functions map declares, read off the first
|
|
6
|
+
* entry's file extension, or `undefined` when the map is missing, empty or
|
|
7
|
+
* points at an extension no runtime owns.
|
|
8
|
+
*/
|
|
9
|
+
export declare function languageFromFunctionsMap(functions?: Record<string, string>): Language | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The language of the Functions project at `projectPath`, from what its
|
|
12
|
+
* files declare. There is no language in project.uiproj, so this is the one
|
|
13
|
+
* place the CLI dispatcher and the solution packager read it from:
|
|
14
|
+
* 1. uipath.json functions map extension (.ts/.js/.mjs → javascript, .py → python)
|
|
15
|
+
* 2. package.json → javascript; pyproject.toml → python
|
|
16
|
+
* 3. neither → `undefined`: the project has not been initialized
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectProjectLanguage(fileSystem: IFileSystem, projectPath: string): Promise<Language | undefined>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var Languages = {
|
|
3
|
+
JavaScript: "javascript",
|
|
4
|
+
Python: "python"
|
|
5
|
+
};
|
|
6
|
+
var LanguageLabels = {
|
|
7
|
+
[Languages.JavaScript]: "JS/TS",
|
|
8
|
+
[Languages.Python]: "Python"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/language-detection.ts
|
|
12
|
+
var EXTENSION_TO_LANGUAGE = {
|
|
13
|
+
".ts": Languages.JavaScript,
|
|
14
|
+
".js": Languages.JavaScript,
|
|
15
|
+
".mjs": Languages.JavaScript,
|
|
16
|
+
".py": Languages.Python
|
|
17
|
+
};
|
|
18
|
+
function languageFromFunctionsMap(functions) {
|
|
19
|
+
const firstEntry = Object.values(functions ?? {})[0];
|
|
20
|
+
if (!firstEntry) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const filePath = firstEntry.split(":")[0] ?? "";
|
|
24
|
+
const dot = filePath.lastIndexOf(".");
|
|
25
|
+
return dot >= 0 ? EXTENSION_TO_LANGUAGE[filePath.slice(dot)] : undefined;
|
|
26
|
+
}
|
|
27
|
+
async function detectProjectLanguage(fileSystem, projectPath) {
|
|
28
|
+
const fromManifest = await languageFromUipathJson(fileSystem, projectPath);
|
|
29
|
+
if (fromManifest) {
|
|
30
|
+
return fromManifest;
|
|
31
|
+
}
|
|
32
|
+
if (await fileSystem.exists(fileSystem.path.join(projectPath, "package.json"))) {
|
|
33
|
+
return Languages.JavaScript;
|
|
34
|
+
}
|
|
35
|
+
if (await fileSystem.exists(fileSystem.path.join(projectPath, "pyproject.toml"))) {
|
|
36
|
+
return Languages.Python;
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
async function languageFromUipathJson(fileSystem, projectPath) {
|
|
41
|
+
const uipathJsonPath = fileSystem.path.join(projectPath, "uipath.json");
|
|
42
|
+
if (!await fileSystem.exists(uipathJsonPath)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const content = await fileSystem.readFile(uipathJsonPath, "utf-8");
|
|
46
|
+
if (!content) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const uipathJson = JSON.parse(content);
|
|
51
|
+
return languageFromFunctionsMap(uipathJson.functions);
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
detectProjectLanguage,
|
|
58
|
+
languageFromFunctionsMap
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//# debugId=47785DEAEF1EDBB764756E2164756E21
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,16 @@ export declare const Languages: {
|
|
|
5
5
|
};
|
|
6
6
|
export type Language = (typeof Languages)[keyof typeof Languages];
|
|
7
7
|
export declare const LanguageLabels: Record<Language, string>;
|
|
8
|
+
/**
|
|
9
|
+
* What `FunctionsTool.probeProject` learns about a project before building
|
|
10
|
+
* it. `name` is project.uiproj's Name, or "" when it declares none.
|
|
11
|
+
* `language` is `undefined` for a project nothing on disk identifies — one
|
|
12
|
+
* that has been created but not initialized.
|
|
13
|
+
*/
|
|
14
|
+
export interface FunctionsProjectProbe {
|
|
15
|
+
name: string;
|
|
16
|
+
language: Language | undefined;
|
|
17
|
+
}
|
|
8
18
|
export interface BuildPackageOptions {
|
|
9
19
|
projectPath: string;
|
|
10
20
|
outputPath: string;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/packager-tool-functions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.205.0-preview.258",
|
|
4
4
|
"description": "UiPath Functions tool implementation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./dist/index.js"
|
|
7
|
+
".": "./dist/index.js",
|
|
8
|
+
"./language-detection": "./dist/language-detection.js"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
"author": "UiPath",
|
|
22
23
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
23
24
|
"peerDependencies": {
|
|
24
|
-
"@uipath/solutionpackager-tool-core": "1.
|
|
25
|
+
"@uipath/solutionpackager-tool-core": "1.205.0"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "8f629ee9fa89abf94f197436a60cb3b9620f8b27"
|
|
27
28
|
}
|