@uipath/uipath-extensions-sdk 0.1.22 → 0.1.24
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 +70 -23
- package/dist/adopt.d.ts +6 -0
- package/dist/adopt.js +512 -104
- package/dist/adopt.js.map +1 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.js +7 -43
- package/dist/cli.js.map +1 -1
- package/dist/commands/check-project.d.ts +17 -0
- package/dist/commands/check-project.js +67 -0
- package/dist/commands/check-project.js.map +1 -0
- package/dist/commands/new.js +12 -20
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/pack.d.ts +14 -1
- package/dist/commands/pack.js +153 -95
- package/dist/commands/pack.js.map +1 -1
- package/dist/commands/submit.d.ts +14 -1
- package/dist/commands/submit.js +149 -40
- package/dist/commands/submit.js.map +1 -1
- package/dist/commands/upload.d.ts +10 -1
- package/dist/commands/upload.js +191 -43
- package/dist/commands/upload.js.map +1 -1
- package/dist/commands/validate-python.d.ts +15 -0
- package/dist/commands/validate-python.js +360 -0
- package/dist/commands/validate-python.js.map +1 -0
- package/dist/commands/validate.d.ts +1 -0
- package/dist/commands/validate.js +4 -2
- package/dist/commands/validate.js.map +1 -1
- package/dist/connector.js +14 -2
- package/dist/connector.js.map +1 -1
- package/dist/github.d.ts +1 -1
- package/dist/github.js +7 -4
- package/dist/github.js.map +1 -1
- package/dist/lib.d.ts +8 -3
- package/dist/lib.js +223 -23
- package/dist/lib.js.map +1 -1
- package/dist/pyproject.d.ts +1 -0
- package/dist/pyproject.js +16 -0
- package/dist/pyproject.js.map +1 -0
- package/dist/python-source.d.ts +25 -0
- package/dist/python-source.js +372 -0
- package/dist/python-source.js.map +1 -0
- package/dist/registrationFile.js +2 -2
- package/dist/registrationFile.js.map +1 -1
- package/dist/sourceWalk.d.ts +2 -1
- package/dist/sourceWalk.js +5 -3
- package/dist/sourceWalk.js.map +1 -1
- package/dist/uip.d.ts +1 -0
- package/dist/uip.js +11 -2
- package/dist/uip.js.map +1 -1
- package/dist/verdict.d.ts +6 -0
- package/dist/verdict.js +13 -0
- package/dist/verdict.js.map +1 -0
- package/package.json +3 -2
- package/dist/commands/build-check.d.ts +0 -34
- package/dist/commands/build-check.js +0 -121
- package/dist/commands/build-check.js.map +0 -1
package/dist/adopt.js
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { assetsProblem, CONNECTION_HELPER_PATH, CONNECTION_HELPER_SOURCE, connectionInputNames, DEFAULT_NODE_DESCRIPTION, DEFAULT_OPERATION_DESCRIPTION, FIXTURES_DIR, fixtureProblem, ICON_PATH, ICON_PATH_PATTERN, iconPathOf, isAllowedSourceDir, isAllowedSourcePath, isLocalOnlySource, MANIFEST_FILE, MAX_PACKAGE_NAME_LENGTH, PackedArchiveError, PYPROJECT, packageNameProblem, packedName, parsePacked, parseTomlText, readPackedEntries, readTomlFile, templateProblems, UV_LOCK, } from "@uipath/uipath-extensions-gates";
|
|
4
5
|
import { strFromU8 } from "fflate";
|
|
5
6
|
import { parse } from "yaml";
|
|
6
7
|
import { labelOf, TYPES_NODE_PACKAGE, TYPES_NODE_VERSION, } from "./commands/new.js";
|
|
7
|
-
import { PackError,
|
|
8
|
+
import { PACK_TIMEOUT_MS, PackError, projectKind, runUipPack, tail, } from "./commands/pack.js";
|
|
8
9
|
import { DEFAULT_INDEX_REPO } from "./commands/submit.js";
|
|
9
10
|
import { DEFAULT_ICON_BASE64 } from "./defaultIcon.js";
|
|
10
11
|
import { exists } from "./exists.js";
|
|
11
12
|
import { FIXTURE_PATH, starterFixtureText } from "./fixture.js";
|
|
12
13
|
import { GitHubError, ghClient } from "./github.js";
|
|
14
|
+
import { setProjectField } from "./pyproject.js";
|
|
15
|
+
import { checkPythonAdoptFiles, isPythonFunctionProject, isPythonFunctionVersion, PythonFunctionError, packConfig, pythonFunctions, validPythonFunctionTarget, } from "./python-source.js";
|
|
13
16
|
import { REGISTRATION_FILE } from "./registrationFile.js";
|
|
14
17
|
import { excludedNames, isSkippedEntry, offListRemedy, walkSources, } from "./sourceWalk.js";
|
|
15
18
|
import { symlinkProblem } from "./symlinkProblem.js";
|
|
16
19
|
import { UipMissingError } from "./uip.js";
|
|
17
|
-
const PACK_TIMEOUT_MS = 600_000;
|
|
18
|
-
const MAX_OUTPUT_CHARS = 2000;
|
|
19
20
|
const POLICY_FILE = "policy/gate-library.yaml";
|
|
20
21
|
const SCHEMA_KEY = "template_schema";
|
|
21
22
|
export const NAME_PREFIX = "uipath-extensions.";
|
|
22
23
|
export const MISSING_ID_ERROR = "pass <publisher>.<name>";
|
|
24
|
+
function idProblem(id) {
|
|
25
|
+
if (packageNameProblem(`${NAME_PREFIX}${id}`) === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
return `id "${id}" is not valid. The package name must be ${NAME_PREFIX}<publisher>.<name> in lowercase letters, digits and single hyphens, up to ${MAX_PACKAGE_NAME_LENGTH} characters. Pass the id as <publisher>.<name>`;
|
|
28
|
+
}
|
|
29
|
+
function chooseName(current, id) {
|
|
30
|
+
const adopted = typeof current === "string" && packageNameProblem(current) === undefined;
|
|
31
|
+
if (id === undefined) {
|
|
32
|
+
return adopted
|
|
33
|
+
? { name: current, write: false }
|
|
34
|
+
: { error: MISSING_ID_ERROR };
|
|
35
|
+
}
|
|
36
|
+
const problem = idProblem(id);
|
|
37
|
+
if (problem !== undefined)
|
|
38
|
+
return { error: problem };
|
|
39
|
+
const name = `${NAME_PREFIX}${id}`;
|
|
40
|
+
if (!adopted)
|
|
41
|
+
return { name, write: true };
|
|
42
|
+
if (current === name)
|
|
43
|
+
return { name, write: false };
|
|
44
|
+
const currentId = current.slice(NAME_PREFIX.length);
|
|
45
|
+
return {
|
|
46
|
+
error: `the project already has the id ${currentId}, not ${id}. Pass ${currentId} or no id`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
23
49
|
export class StaleAdoptPlanError extends Error {
|
|
24
50
|
path;
|
|
25
51
|
constructor(path) {
|
|
@@ -29,8 +55,6 @@ export class StaleAdoptPlanError extends Error {
|
|
|
29
55
|
}
|
|
30
56
|
}
|
|
31
57
|
const DEFAULT_LICENSE = "MIT";
|
|
32
|
-
const NODE_DESCRIPTION = "Describe what this node does in one sentence.";
|
|
33
|
-
const OPERATION_DESCRIPTION = "Describe what this operation does.";
|
|
34
58
|
const ICON_NAMES = ICON_PATH.split("/");
|
|
35
59
|
const iconExcludedProblem = (name) => `uipath.json packOptions excludes ${name}, so ${ICON_PATH} would not be packed, remove ${name} from packOptions, then run again`;
|
|
36
60
|
const iconReferenceGenerated = () => ({
|
|
@@ -61,6 +85,7 @@ const notAList = (key) => `uipath.json packOptions.${key} is not a list`;
|
|
|
61
85
|
const isJunk = (key, name) => JUNK[key].includes(name);
|
|
62
86
|
const LOGIN = "log in with gh auth login, then run again";
|
|
63
87
|
const INSTALL_GH = "install gh from https://cli.github.com, then run again";
|
|
88
|
+
const noAccess = (index) => `the gh account cannot read ${index}. Check gh auth status, or switch to an account that has access, then run again`;
|
|
64
89
|
const UPGRADE = "upgrade uip, then run again";
|
|
65
90
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
91
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
@@ -69,7 +94,6 @@ const jsonWriter = (text) => {
|
|
|
69
94
|
const newline = text.endsWith("\n") ? "\n" : "";
|
|
70
95
|
return (value) => `${JSON.stringify(value, null, indent)}${newline}`;
|
|
71
96
|
};
|
|
72
|
-
const tail = (text) => text.length > MAX_OUTPUT_CHARS ? `...${text.slice(-MAX_OUTPUT_CHARS)}` : text;
|
|
73
97
|
async function readText(path) {
|
|
74
98
|
try {
|
|
75
99
|
return await readFile(path, "utf8");
|
|
@@ -78,6 +102,26 @@ async function readText(path) {
|
|
|
78
102
|
return undefined;
|
|
79
103
|
}
|
|
80
104
|
}
|
|
105
|
+
// A lossy read is unsafe when init may write back the same file.
|
|
106
|
+
async function readPythonText(dir, file) {
|
|
107
|
+
let bytes;
|
|
108
|
+
try {
|
|
109
|
+
bytes = await readFile(join(dir, file));
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return error.code === "ENOENT"
|
|
113
|
+
? { text: undefined }
|
|
114
|
+
: { error: `${file}: file not readable` };
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return {
|
|
118
|
+
text: new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return { error: `${file} must be valid UTF-8` };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
81
125
|
function parseJson(text) {
|
|
82
126
|
try {
|
|
83
127
|
return JSON.parse(text);
|
|
@@ -105,31 +149,58 @@ function templateOperation(text) {
|
|
|
105
149
|
? first.name
|
|
106
150
|
: undefined;
|
|
107
151
|
}
|
|
108
|
-
async function outsideSourceList(root, excluded) {
|
|
152
|
+
async function outsideSourceList(root, excluded, kind = "function") {
|
|
109
153
|
const found = [];
|
|
154
|
+
const listed = [];
|
|
110
155
|
await walkSources(root, async (entry, path, dir) => {
|
|
111
|
-
if (isSkippedEntry(entry, dir, excluded) ||
|
|
112
|
-
(dir === "" && isLocalOnlySource(entry.name)) ||
|
|
156
|
+
if (isSkippedEntry(entry, dir, excluded, kind) ||
|
|
157
|
+
(dir === "" && isLocalOnlySource(entry.name, kind)) ||
|
|
113
158
|
(dir === "" && entry.isFile() && entry.name === REGISTRATION_FILE)) {
|
|
114
159
|
return false;
|
|
115
160
|
}
|
|
116
161
|
if (entry.isDirectory()) {
|
|
117
|
-
if (dir === "" && !isAllowedSourceDir(entry.name)) {
|
|
162
|
+
if (dir === "" && !isAllowedSourceDir(entry.name, kind)) {
|
|
118
163
|
found.push(`${path}/`);
|
|
119
164
|
return false;
|
|
120
165
|
}
|
|
121
166
|
return true;
|
|
122
167
|
}
|
|
123
|
-
if (!entry.isFile() || !isAllowedSourcePath(path))
|
|
168
|
+
if (!entry.isFile() || !isAllowedSourcePath(path, kind)) {
|
|
124
169
|
found.push(path);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
listed.push(path);
|
|
173
|
+
}
|
|
125
174
|
return false;
|
|
126
175
|
});
|
|
127
|
-
return found;
|
|
176
|
+
return { found, listed };
|
|
177
|
+
}
|
|
178
|
+
async function planSourceReports(plan, dir, excluded, kind = "function") {
|
|
179
|
+
const { found, listed } = await outsideSourceList(dir, excluded, kind);
|
|
180
|
+
for (const path of found) {
|
|
181
|
+
plan.reports.push({
|
|
182
|
+
path,
|
|
183
|
+
problem: `is not on the source list, ${offListRemedy(path)}`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const assets = assetsProblem([
|
|
187
|
+
...listed,
|
|
188
|
+
...plan.writes.map((write) => write.path),
|
|
189
|
+
]);
|
|
190
|
+
if (assets !== undefined) {
|
|
191
|
+
plan.reports.push({ path: "assets/", problem: `is refused, ${assets}` });
|
|
192
|
+
}
|
|
128
193
|
}
|
|
129
|
-
|
|
194
|
+
function templateIconPath(manifestText) {
|
|
195
|
+
const template = manifestText === undefined ? undefined : parseJson(manifestText);
|
|
196
|
+
const display = isRecord(template) ? template.display : undefined;
|
|
197
|
+
const icon = iconPathOf(isRecord(display) ? display : undefined);
|
|
198
|
+
return ICON_PATH_PATTERN.test(icon) ? icon : ICON_PATH;
|
|
199
|
+
}
|
|
200
|
+
async function junkNames(root, excluded, kind = "function") {
|
|
130
201
|
const found = new Set();
|
|
131
202
|
await walkSources(root, async (entry, _path, dir) => {
|
|
132
|
-
if (isSkippedEntry(entry, dir, excluded))
|
|
203
|
+
if (isSkippedEntry(entry, dir, excluded, kind))
|
|
133
204
|
return false;
|
|
134
205
|
const key = entry.isDirectory()
|
|
135
206
|
? "directoriesExcluded"
|
|
@@ -138,7 +209,8 @@ async function junkNames(root, excluded) {
|
|
|
138
209
|
found.add(entry.name);
|
|
139
210
|
return false;
|
|
140
211
|
}
|
|
141
|
-
return (entry.isDirectory() &&
|
|
212
|
+
return (entry.isDirectory() &&
|
|
213
|
+
(dir !== "" || isAllowedSourceDir(entry.name, kind)));
|
|
142
214
|
});
|
|
143
215
|
const keys = Object.keys(JUNK);
|
|
144
216
|
return keys
|
|
@@ -177,7 +249,7 @@ async function templateSchema(deps, index) {
|
|
|
177
249
|
let text;
|
|
178
250
|
try {
|
|
179
251
|
if ((await github.repository(index)) === undefined) {
|
|
180
|
-
return { error:
|
|
252
|
+
return { error: noAccess(index) };
|
|
181
253
|
}
|
|
182
254
|
text = await github.fileText(index, POLICY_FILE);
|
|
183
255
|
}
|
|
@@ -211,20 +283,25 @@ function newTemplate(schema, version, packageName, operation, icon, declaredLice
|
|
|
211
283
|
license: declaredLicense === undefined ? DEFAULT_LICENSE : declaredLicense,
|
|
212
284
|
display: {
|
|
213
285
|
label,
|
|
214
|
-
description:
|
|
286
|
+
description: DEFAULT_NODE_DESCRIPTION,
|
|
215
287
|
...(icon !== "none" && { icon: ICON_PATH }),
|
|
216
288
|
},
|
|
217
289
|
tags: [],
|
|
218
|
-
operations: [
|
|
290
|
+
operations: [
|
|
291
|
+
{ name: operation, description: DEFAULT_OPERATION_DESCRIPTION },
|
|
292
|
+
],
|
|
219
293
|
});
|
|
220
294
|
const generated = [
|
|
221
295
|
...(declaredLicense === undefined
|
|
222
296
|
? [{ field: "license", value: DEFAULT_LICENSE }]
|
|
223
297
|
: []),
|
|
224
298
|
{ field: "display.label", value: label },
|
|
225
|
-
{ field: "display.description", value:
|
|
299
|
+
{ field: "display.description", value: DEFAULT_NODE_DESCRIPTION },
|
|
226
300
|
{ field: "operations[0].name", value: operation },
|
|
227
|
-
{
|
|
301
|
+
{
|
|
302
|
+
field: "operations[0].description",
|
|
303
|
+
value: DEFAULT_OPERATION_DESCRIPTION,
|
|
304
|
+
},
|
|
228
305
|
{ field: "tags", value: "[]" },
|
|
229
306
|
...(icon === "default"
|
|
230
307
|
? [iconReferenceGenerated(), iconFileGenerated()]
|
|
@@ -274,36 +351,22 @@ function operationName(filePath) {
|
|
|
274
351
|
return /^[A-Za-z]/.test(name) ? name : "run";
|
|
275
352
|
}
|
|
276
353
|
async function runPack(deps, dir, nupkgName) {
|
|
277
|
-
let result;
|
|
278
354
|
try {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
355
|
+
return {
|
|
356
|
+
nupkg: await runUipPack({
|
|
357
|
+
projectDir: dir,
|
|
358
|
+
exec: deps.exec,
|
|
359
|
+
command: "uip function pack",
|
|
360
|
+
nupkgName,
|
|
361
|
+
}),
|
|
362
|
+
};
|
|
283
363
|
}
|
|
284
364
|
catch (error) {
|
|
285
|
-
if (error instanceof PackError)
|
|
365
|
+
if (error instanceof PackError || error instanceof UipMissingError) {
|
|
286
366
|
return { error: error.message };
|
|
287
|
-
if (error.code === "ENOENT") {
|
|
288
|
-
return { error: new UipMissingError().message };
|
|
289
367
|
}
|
|
290
368
|
throw error;
|
|
291
369
|
}
|
|
292
|
-
if (result.timedOut)
|
|
293
|
-
return { error: "uip function pack timed out" };
|
|
294
|
-
if (result.code !== 0) {
|
|
295
|
-
return {
|
|
296
|
-
error: `uip function pack exited with code ${result.code}: ${tail(result.stderr || result.stdout)}`,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
for (const where of [".uipath", ""]) {
|
|
300
|
-
const candidate = join(dir, where, nupkgName);
|
|
301
|
-
if (await exists(candidate))
|
|
302
|
-
return { nupkg: candidate };
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
error: `uip function pack finished but ${nupkgName} was not created in the project or in .uipath`,
|
|
306
|
-
};
|
|
307
370
|
}
|
|
308
371
|
function runtimeProblems(entries) {
|
|
309
372
|
const bytes = entries[packedName(entries, "operate.json")];
|
|
@@ -331,8 +394,375 @@ function undescribedInputs(input) {
|
|
|
331
394
|
property.description.trim() === "")
|
|
332
395
|
.map(([name]) => name);
|
|
333
396
|
}
|
|
397
|
+
export { isPythonFunctionProject } from "./python-source.js";
|
|
398
|
+
export async function pythonFunctionNeedsId(dir) {
|
|
399
|
+
if (!(await isPythonFunctionProject(dir)))
|
|
400
|
+
return false;
|
|
401
|
+
const result = await readTomlFile(join(dir, PYPROJECT));
|
|
402
|
+
const project = "value" in result && result.value.project;
|
|
403
|
+
return isRecord(project) && packageNameProblem(project.name) !== undefined;
|
|
404
|
+
}
|
|
405
|
+
function replaceProjectName(text, name) {
|
|
406
|
+
const lines = text.split("\n");
|
|
407
|
+
let inProject = false;
|
|
408
|
+
let changed = false;
|
|
409
|
+
for (const [i, line] of lines.entries()) {
|
|
410
|
+
if (/^\s*\[/.test(line)) {
|
|
411
|
+
inProject = /^\s*\[project\]\s*(?:#.*)?$/.test(line);
|
|
412
|
+
}
|
|
413
|
+
if (!inProject)
|
|
414
|
+
continue;
|
|
415
|
+
const match = /^(\s*name\s*=\s*)(?:"[^"\\]*"|'[^']*')(\s*(?:#.*)?)$/.exec(line);
|
|
416
|
+
if (!match)
|
|
417
|
+
continue;
|
|
418
|
+
if (changed)
|
|
419
|
+
return undefined;
|
|
420
|
+
lines[i] = `${match[1]}"${name}"${match[2]}`;
|
|
421
|
+
changed = true;
|
|
422
|
+
}
|
|
423
|
+
return changed ? lines.join("\n") : undefined;
|
|
424
|
+
}
|
|
425
|
+
async function planPythonFunction(opts, deps, uipath, uipathText, functions) {
|
|
426
|
+
const plan = { writes: [], reports: [], errors: [] };
|
|
427
|
+
const fail = (message) => ({
|
|
428
|
+
writes: [],
|
|
429
|
+
reports: [],
|
|
430
|
+
errors: [...plan.errors, message],
|
|
431
|
+
});
|
|
432
|
+
const entries = Object.entries(functions);
|
|
433
|
+
if (entries.length !== 1)
|
|
434
|
+
return fail("a node holds one function");
|
|
435
|
+
const [main, target] = entries[0];
|
|
436
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(main) ||
|
|
437
|
+
!validPythonFunctionTarget(target)) {
|
|
438
|
+
return fail("uipath.json must map a function name to a Python source file and function");
|
|
439
|
+
}
|
|
440
|
+
const projectText = await readPythonText(opts.dir, PYPROJECT);
|
|
441
|
+
if ("error" in projectText)
|
|
442
|
+
return fail(projectText.error);
|
|
443
|
+
const before = projectText.text;
|
|
444
|
+
if (before === undefined)
|
|
445
|
+
return fail(`${PYPROJECT}: file not readable`);
|
|
446
|
+
const parsed = parseTomlText(before);
|
|
447
|
+
if ("error" in parsed)
|
|
448
|
+
return fail(`${PYPROJECT}: ${parsed.error}`);
|
|
449
|
+
const project = parsed.value.project;
|
|
450
|
+
if (!isRecord(project) ||
|
|
451
|
+
typeof project.name !== "string" ||
|
|
452
|
+
typeof project.version !== "string") {
|
|
453
|
+
return fail(`${PYPROJECT} must have a [project] name and version`);
|
|
454
|
+
}
|
|
455
|
+
if (!isPythonFunctionVersion(project.version))
|
|
456
|
+
return fail(`${PYPROJECT} needs a plain x.y.z package version`);
|
|
457
|
+
const iconExclusion = [...ICON_NAMES, ICON_PATH].find((entry) => excludedNames(uipath).has(entry));
|
|
458
|
+
if (iconExclusion !== undefined)
|
|
459
|
+
return fail(iconExcludedProblem(iconExclusion));
|
|
460
|
+
let hasIcon;
|
|
461
|
+
try {
|
|
462
|
+
packConfig(uipath);
|
|
463
|
+
hasIcon = await checkPythonAdoptFiles(opts.dir, target.split(":")[0]);
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
if (error instanceof PythonFunctionError)
|
|
467
|
+
return fail(error.message);
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
470
|
+
const chosen = chooseName(project.name, opts.id);
|
|
471
|
+
if ("error" in chosen)
|
|
472
|
+
return fail(chosen.error);
|
|
473
|
+
const name = chosen.name;
|
|
474
|
+
if (chosen.write) {
|
|
475
|
+
const after = replaceProjectName(before, name);
|
|
476
|
+
if (after === undefined) {
|
|
477
|
+
return fail('place the project name on one standalone name = "..." line in [project]');
|
|
478
|
+
}
|
|
479
|
+
const updated = parseTomlText(after);
|
|
480
|
+
const nextProject = "value" in updated ? updated.value.project : undefined;
|
|
481
|
+
if ("error" in updated ||
|
|
482
|
+
!isRecord(nextProject) ||
|
|
483
|
+
!isDeepStrictEqual({ ...updated.value, project: { ...nextProject } }, { ...parsed.value, project: { ...project, name } })) {
|
|
484
|
+
return fail(`renaming the package would change another field in ${PYPROJECT}`);
|
|
485
|
+
}
|
|
486
|
+
plan.writes.push({ path: PYPROJECT, before, after, identity: true });
|
|
487
|
+
if (await exists(join(opts.dir, "uv.lock"))) {
|
|
488
|
+
plan.reports.push({
|
|
489
|
+
path: "uv.lock",
|
|
490
|
+
problem: "run uv lock after the Python project is renamed",
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const existingManifest = await readPythonText(opts.dir, MANIFEST_FILE);
|
|
495
|
+
if ("error" in existingManifest)
|
|
496
|
+
return fail(existingManifest.error);
|
|
497
|
+
const manifestText = existingManifest.text;
|
|
498
|
+
if (manifestText === undefined) {
|
|
499
|
+
if (project.license !== undefined &&
|
|
500
|
+
(typeof project.license !== "string" || project.license.trim() === "")) {
|
|
501
|
+
return fail(`${PYPROJECT} [project].license must be an SPDX string before generating the extension manifest; initialize with an explicit license instead of replacing the existing declaration`);
|
|
502
|
+
}
|
|
503
|
+
const found = opts.offline
|
|
504
|
+
? { schema: 2 }
|
|
505
|
+
: await templateSchema(deps, opts.index ?? DEFAULT_INDEX_REPO);
|
|
506
|
+
if ("error" in found)
|
|
507
|
+
return fail(found.error);
|
|
508
|
+
const template = newTemplate(found.schema, project.version, name, operationName(main), hasIcon ? "own" : "default", typeof project.license === "string" ? project.license : undefined);
|
|
509
|
+
plan.writes.push({
|
|
510
|
+
path: MANIFEST_FILE,
|
|
511
|
+
before: null,
|
|
512
|
+
after: template.text,
|
|
513
|
+
});
|
|
514
|
+
plan.generated = template.generated;
|
|
515
|
+
if (!hasIcon)
|
|
516
|
+
plan.writes.push(defaultIconWrite());
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
planExistingTemplateIcon(plan, {
|
|
520
|
+
text: manifestText,
|
|
521
|
+
hasIcon,
|
|
522
|
+
iconExclusion,
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
const plannedManifest = plan.writes.find(({ path }) => path === MANIFEST_FILE)?.after ??
|
|
526
|
+
manifestText;
|
|
527
|
+
const parsedManifest = plannedManifest === undefined ? undefined : parseJson(plannedManifest);
|
|
528
|
+
const problems = templateProblems(parsedManifest);
|
|
529
|
+
if (problems.length > 0)
|
|
530
|
+
return fail(`invalid ${MANIFEST_FILE}: ${problems.join("; ")}`);
|
|
531
|
+
const display = isRecord(parsedManifest) ? parsedManifest.display : undefined;
|
|
532
|
+
const options = uipath.packOptions;
|
|
533
|
+
if (options !== undefined && !isRecord(options)) {
|
|
534
|
+
return fail("uipath.json packOptions must be an object");
|
|
535
|
+
}
|
|
536
|
+
const files = options?.filesIncluded ?? [];
|
|
537
|
+
if (!Array.isArray(files) ||
|
|
538
|
+
!files.every((entry) => typeof entry === "string")) {
|
|
539
|
+
return fail("uipath.json packOptions.filesIncluded must be a list of filenames");
|
|
540
|
+
}
|
|
541
|
+
// The index packs the committed uipath.json, so it must keep uv.lock in and fixtures out.
|
|
542
|
+
const nextOptions = {
|
|
543
|
+
...options,
|
|
544
|
+
...(isRecord(display) &&
|
|
545
|
+
display.icon === ICON_PATH &&
|
|
546
|
+
!files.includes(ICON_PATH) && {
|
|
547
|
+
filesIncluded: [...files, ICON_PATH],
|
|
548
|
+
}),
|
|
549
|
+
includeUvLock: true,
|
|
550
|
+
directoriesExcluded: [FIXTURES_DIR],
|
|
551
|
+
};
|
|
552
|
+
if (!isDeepStrictEqual(nextOptions, options)) {
|
|
553
|
+
plan.writes.push({
|
|
554
|
+
path: "uipath.json",
|
|
555
|
+
before: uipathText,
|
|
556
|
+
after: jsonWriter(uipathText)({ ...uipath, packOptions: nextOptions }),
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
if ((await fixtureProblem(opts.dir)) !== undefined) {
|
|
560
|
+
const blocked = await starterFixtureBlocked(opts.dir);
|
|
561
|
+
if (blocked !== undefined)
|
|
562
|
+
return fail(blocked);
|
|
563
|
+
plan.writes.push({
|
|
564
|
+
path: FIXTURE_PATH,
|
|
565
|
+
before: null,
|
|
566
|
+
after: starterFixtureText(templateOperation(plannedManifest) ?? operationName(main)),
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
for (const { path } of plan.writes) {
|
|
570
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
571
|
+
if (problem !== undefined)
|
|
572
|
+
plan.errors.push(problem);
|
|
573
|
+
}
|
|
574
|
+
return plan;
|
|
575
|
+
}
|
|
576
|
+
async function planTemplate(plan, opts, deps, node) {
|
|
577
|
+
const { manifestText, hasIcon, iconExclusion } = node;
|
|
578
|
+
if (manifestText !== undefined) {
|
|
579
|
+
planExistingTemplateIcon(plan, {
|
|
580
|
+
text: manifestText,
|
|
581
|
+
hasIcon,
|
|
582
|
+
iconExclusion,
|
|
583
|
+
});
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const found = opts.offline
|
|
587
|
+
? { schema: 2 }
|
|
588
|
+
: await templateSchema(deps, opts.index ?? DEFAULT_INDEX_REPO);
|
|
589
|
+
if ("error" in found) {
|
|
590
|
+
plan.errors.push(found.error);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const skipIcon = iconExclusion !== undefined && found.schema === undefined;
|
|
594
|
+
if (iconExclusion !== undefined && !skipIcon) {
|
|
595
|
+
plan.errors.push(iconExcludedProblem(iconExclusion));
|
|
596
|
+
}
|
|
597
|
+
const template = newTemplate(found.schema, node.version, node.packageName, node.operation, skipIcon ? "none" : hasIcon ? "own" : "default", node.license);
|
|
598
|
+
plan.writes.push({
|
|
599
|
+
path: MANIFEST_FILE,
|
|
600
|
+
before: null,
|
|
601
|
+
after: template.text,
|
|
602
|
+
});
|
|
603
|
+
plan.generated = template.generated;
|
|
604
|
+
if (!hasIcon && !skipIcon)
|
|
605
|
+
plan.writes.push(defaultIconWrite());
|
|
606
|
+
}
|
|
607
|
+
const AGENT_OPERATION = "run";
|
|
608
|
+
const ENTRY_POINTS_FILE = "entry-points.json";
|
|
609
|
+
export const AGENT_INIT = "uipath.json and entry-points.json are missing. Run init, which runs uip codedagent init to write them";
|
|
610
|
+
export const AGENT_LOCK = `${UV_LOCK} is missing. Run init, which runs uv lock to write it`;
|
|
611
|
+
const missing = async (dir, name) => (await readText(join(dir, name))) === undefined;
|
|
612
|
+
const needsCodedAgentInit = async (dir) => (await missing(dir, "uipath.json")) ||
|
|
613
|
+
(await missing(dir, ENTRY_POINTS_FILE));
|
|
614
|
+
export async function needsAgentInit(dir) {
|
|
615
|
+
return ((await projectKind(dir)) === "agent" &&
|
|
616
|
+
((await needsCodedAgentInit(dir)) || (await missing(dir, UV_LOCK))));
|
|
617
|
+
}
|
|
618
|
+
async function runStep(exec, dir, command, args) {
|
|
619
|
+
const name = [command, ...args].join(" ");
|
|
620
|
+
let result;
|
|
621
|
+
try {
|
|
622
|
+
result = await exec(command, args, { cwd: dir, timeout: PACK_TIMEOUT_MS });
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
if (error.code === "ENOENT") {
|
|
626
|
+
return command === "uip"
|
|
627
|
+
? new UipMissingError().message
|
|
628
|
+
: `${command} was not found on the PATH. Install it, then run this command again.`;
|
|
629
|
+
}
|
|
630
|
+
throw error;
|
|
631
|
+
}
|
|
632
|
+
if (result.timedOut)
|
|
633
|
+
return `${name} timed out`;
|
|
634
|
+
return result.code === 0
|
|
635
|
+
? undefined
|
|
636
|
+
: `${name} exited with code ${result.code}: ${tail(result.stderr || result.stdout)}`;
|
|
637
|
+
}
|
|
638
|
+
export async function runAgentInit(dir, exec) {
|
|
639
|
+
if (await needsCodedAgentInit(dir)) {
|
|
640
|
+
const failure = await runStep(exec, dir, "uip", ["codedagent", "init"]);
|
|
641
|
+
if (failure !== undefined)
|
|
642
|
+
return failure;
|
|
643
|
+
if (await needsCodedAgentInit(dir)) {
|
|
644
|
+
return "uip codedagent init finished but did not write uipath.json and entry-points.json";
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (await missing(dir, UV_LOCK)) {
|
|
648
|
+
const failure = await runStep(exec, dir, "uv", ["lock"]);
|
|
649
|
+
if (failure !== undefined)
|
|
650
|
+
return failure;
|
|
651
|
+
if (await missing(dir, UV_LOCK)) {
|
|
652
|
+
return `uv lock finished but did not write ${UV_LOCK}`;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
function agentPackOptions(text, uipath, packsIcon, iconPath) {
|
|
658
|
+
const options = uipath.packOptions === undefined ? {} : uipath.packOptions;
|
|
659
|
+
if (!isRecord(options)) {
|
|
660
|
+
return { error: "uipath.json packOptions is not an object" };
|
|
661
|
+
}
|
|
662
|
+
const included = options.filesIncluded === undefined ? [] : options.filesIncluded;
|
|
663
|
+
if (!Array.isArray(included)) {
|
|
664
|
+
return { error: "uipath.json packOptions.filesIncluded is not a list" };
|
|
665
|
+
}
|
|
666
|
+
const listsIcon = !packsIcon || included.includes(iconPath);
|
|
667
|
+
if (listsIcon && options.includeUvLock === true)
|
|
668
|
+
return {};
|
|
669
|
+
return {
|
|
670
|
+
write: {
|
|
671
|
+
path: "uipath.json",
|
|
672
|
+
before: text,
|
|
673
|
+
after: jsonWriter(text)({
|
|
674
|
+
...uipath,
|
|
675
|
+
packOptions: {
|
|
676
|
+
...options,
|
|
677
|
+
...(!listsIcon && { filesIncluded: [...included, iconPath] }),
|
|
678
|
+
includeUvLock: true,
|
|
679
|
+
},
|
|
680
|
+
}),
|
|
681
|
+
},
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
async function planAgentAdopt(opts, deps, plan) {
|
|
685
|
+
const fail = (message) => {
|
|
686
|
+
plan.errors.push(message);
|
|
687
|
+
return plan;
|
|
688
|
+
};
|
|
689
|
+
const uipathText = await readText(join(opts.dir, "uipath.json"));
|
|
690
|
+
const entryText = await readText(join(opts.dir, ENTRY_POINTS_FILE));
|
|
691
|
+
if (uipathText === undefined || entryText === undefined) {
|
|
692
|
+
return fail(AGENT_INIT);
|
|
693
|
+
}
|
|
694
|
+
if (await missing(opts.dir, UV_LOCK))
|
|
695
|
+
return fail(AGENT_LOCK);
|
|
696
|
+
const uipath = parseJson(uipathText);
|
|
697
|
+
if (!isRecord(uipath))
|
|
698
|
+
return fail("uipath.json is not a valid JSON object");
|
|
699
|
+
const entry = parseJson(entryText);
|
|
700
|
+
const entryPoints = isRecord(entry) ? entry.entryPoints : undefined;
|
|
701
|
+
if (!Array.isArray(entryPoints) || entryPoints.length !== 1) {
|
|
702
|
+
return fail(`${ENTRY_POINTS_FILE} must list one entry point, a node holds one agent`);
|
|
703
|
+
}
|
|
704
|
+
const pyprojectText = await readText(join(opts.dir, PYPROJECT));
|
|
705
|
+
const toml = await readTomlFile(join(opts.dir, PYPROJECT));
|
|
706
|
+
if (pyprojectText === undefined || "error" in toml) {
|
|
707
|
+
return fail(`${PYPROJECT}: ${"error" in toml ? toml.error : "file not found"}`);
|
|
708
|
+
}
|
|
709
|
+
const { project } = toml.value;
|
|
710
|
+
if (!isRecord(project) || typeof project.version !== "string") {
|
|
711
|
+
return fail(`${PYPROJECT} needs a [project] table with a version`);
|
|
712
|
+
}
|
|
713
|
+
let packageName = String(project.name);
|
|
714
|
+
const chosen = chooseName(project.name, opts.id);
|
|
715
|
+
if ("error" in chosen) {
|
|
716
|
+
plan.errors.push(chosen.error);
|
|
717
|
+
}
|
|
718
|
+
else if (chosen.write) {
|
|
719
|
+
const after = setProjectField(pyprojectText, "name", chosen.name);
|
|
720
|
+
if (after === undefined) {
|
|
721
|
+
plan.errors.push(`${PYPROJECT} has no [project] name line to set`);
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
packageName = chosen.name;
|
|
725
|
+
plan.writes.push({
|
|
726
|
+
path: PYPROJECT,
|
|
727
|
+
before: pyprojectText,
|
|
728
|
+
after,
|
|
729
|
+
identity: true,
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const manifestText = await readText(join(opts.dir, MANIFEST_FILE));
|
|
734
|
+
const iconPath = templateIconPath(manifestText);
|
|
735
|
+
const hasIcon = await exists(join(opts.dir, iconPath));
|
|
736
|
+
const excluded = excludedNames(uipath);
|
|
737
|
+
await planTemplate(plan, opts, deps, {
|
|
738
|
+
manifestText,
|
|
739
|
+
version: project.version,
|
|
740
|
+
packageName,
|
|
741
|
+
operation: templateOperation(manifestText) ?? AGENT_OPERATION,
|
|
742
|
+
hasIcon,
|
|
743
|
+
iconExclusion: iconPath.split("/").find((name) => excluded.has(name)),
|
|
744
|
+
license: undefined,
|
|
745
|
+
});
|
|
746
|
+
const packOptions = agentPackOptions(uipathText, uipath, hasIcon || plan.writes.some((write) => write.path === ICON_PATH), iconPath);
|
|
747
|
+
if ("error" in packOptions) {
|
|
748
|
+
plan.errors.push(packOptions.error);
|
|
749
|
+
}
|
|
750
|
+
else if (packOptions.write) {
|
|
751
|
+
plan.writes.push(packOptions.write);
|
|
752
|
+
}
|
|
753
|
+
await planSourceReports(plan, opts.dir, excluded, "agent");
|
|
754
|
+
for (const { path } of plan.writes) {
|
|
755
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
756
|
+
if (problem !== undefined)
|
|
757
|
+
plan.errors.push(problem);
|
|
758
|
+
}
|
|
759
|
+
return plan;
|
|
760
|
+
}
|
|
334
761
|
export async function planAdopt(opts, deps) {
|
|
335
762
|
const plan = { writes: [], reports: [], errors: [] };
|
|
763
|
+
if ((await projectKind(opts.dir)) === "agent") {
|
|
764
|
+
return planAgentAdopt(opts, deps, plan);
|
|
765
|
+
}
|
|
336
766
|
const fail = (message) => {
|
|
337
767
|
plan.errors.push(message);
|
|
338
768
|
return plan;
|
|
@@ -345,8 +775,18 @@ export async function planAdopt(opts, deps) {
|
|
|
345
775
|
if (!isRecord(uipath))
|
|
346
776
|
return fail("uipath.json is not a valid JSON object");
|
|
347
777
|
const packageText = await readText(join(opts.dir, "package.json"));
|
|
348
|
-
if (packageText === undefined)
|
|
778
|
+
if (packageText === undefined) {
|
|
779
|
+
const functions = pythonFunctions(uipath);
|
|
780
|
+
if (functions !== undefined && (await isPythonFunctionProject(opts.dir))) {
|
|
781
|
+
const exact = await readPythonText(opts.dir, "uipath.json");
|
|
782
|
+
if ("error" in exact)
|
|
783
|
+
return fail(exact.error);
|
|
784
|
+
if (exact.text !== uipathText)
|
|
785
|
+
return fail("uipath.json changed while planning, run again");
|
|
786
|
+
return planPythonFunction(opts, deps, uipath, uipathText, functions);
|
|
787
|
+
}
|
|
349
788
|
return fail("package.json not found");
|
|
789
|
+
}
|
|
350
790
|
const pkg = parseJson(packageText);
|
|
351
791
|
if (!isRecord(pkg))
|
|
352
792
|
return fail("package.json is not a valid JSON object");
|
|
@@ -355,26 +795,18 @@ export async function planAdopt(opts, deps) {
|
|
|
355
795
|
}
|
|
356
796
|
const serialize = jsonWriter(packageText);
|
|
357
797
|
let nextPkg = pkg;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
plan.writes.push({
|
|
371
|
-
path: "package.json",
|
|
372
|
-
before: packageText,
|
|
373
|
-
after: serialize(nextPkg),
|
|
374
|
-
identity: true,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
798
|
+
const chosen = chooseName(pkg.name, opts.id);
|
|
799
|
+
if ("error" in chosen) {
|
|
800
|
+
plan.errors.push(chosen.error);
|
|
801
|
+
}
|
|
802
|
+
else if (chosen.write) {
|
|
803
|
+
nextPkg = { ...pkg, name: chosen.name };
|
|
804
|
+
plan.writes.push({
|
|
805
|
+
path: "package.json",
|
|
806
|
+
before: packageText,
|
|
807
|
+
after: serialize(nextPkg),
|
|
808
|
+
identity: true,
|
|
809
|
+
});
|
|
378
810
|
}
|
|
379
811
|
const packed = await runPack(deps, opts.dir, `${String(pkg.name)}.${pkg.version}.nupkg`);
|
|
380
812
|
if ("error" in packed)
|
|
@@ -402,36 +834,15 @@ export async function planAdopt(opts, deps) {
|
|
|
402
834
|
const iconExclusion = ICON_NAMES.find((name) => excluded.has(name));
|
|
403
835
|
const manifestText = await readText(join(opts.dir, MANIFEST_FILE));
|
|
404
836
|
const operation = templateOperation(manifestText) ?? operationName(entry.filePath);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
if (iconExclusion !== undefined && !skipIcon) {
|
|
415
|
-
plan.errors.push(iconExcludedProblem(iconExclusion));
|
|
416
|
-
}
|
|
417
|
-
const template = newTemplate(found.schema, pkg.version, String(nextPkg.name), operation, skipIcon ? "none" : hasIcon ? "own" : "default", pkg.license);
|
|
418
|
-
plan.writes.push({
|
|
419
|
-
path: MANIFEST_FILE,
|
|
420
|
-
before: null,
|
|
421
|
-
after: template.text,
|
|
422
|
-
});
|
|
423
|
-
plan.generated = template.generated;
|
|
424
|
-
if (!hasIcon && !skipIcon)
|
|
425
|
-
plan.writes.push(defaultIconWrite());
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
planExistingTemplateIcon(plan, {
|
|
430
|
-
text: manifestText,
|
|
431
|
-
hasIcon,
|
|
432
|
-
iconExclusion,
|
|
433
|
-
});
|
|
434
|
-
}
|
|
837
|
+
await planTemplate(plan, opts, deps, {
|
|
838
|
+
manifestText,
|
|
839
|
+
version: pkg.version,
|
|
840
|
+
packageName: String(nextPkg.name),
|
|
841
|
+
operation,
|
|
842
|
+
hasIcon,
|
|
843
|
+
iconExclusion,
|
|
844
|
+
license: pkg.license,
|
|
845
|
+
});
|
|
435
846
|
if ((await fixtureProblem(opts.dir)) !== undefined) {
|
|
436
847
|
const blocked = await starterFixtureBlocked(opts.dir);
|
|
437
848
|
if (blocked !== undefined) {
|
|
@@ -495,12 +906,7 @@ export async function planAdopt(opts, deps) {
|
|
|
495
906
|
skipped = new Set([...excluded, ...junk.flatMap(([, names]) => names)]);
|
|
496
907
|
}
|
|
497
908
|
}
|
|
498
|
-
|
|
499
|
-
plan.reports.push({
|
|
500
|
-
path,
|
|
501
|
-
problem: `is not on the source list, ${offListRemedy(path)}`,
|
|
502
|
-
});
|
|
503
|
-
}
|
|
909
|
+
await planSourceReports(plan, opts.dir, skipped);
|
|
504
910
|
for (const name of undescribedInputs(entry.input)) {
|
|
505
911
|
plan.reports.push({
|
|
506
912
|
path: "entry-points.json",
|
|
@@ -519,11 +925,13 @@ export async function applyAdopt(plan, opts) {
|
|
|
519
925
|
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
520
926
|
if (problem !== undefined)
|
|
521
927
|
throw new Error(problem);
|
|
522
|
-
if (before !== null
|
|
523
|
-
|
|
928
|
+
if (before !== null) {
|
|
929
|
+
const actual = await readFile(join(opts.dir, path)).catch(() => undefined);
|
|
930
|
+
if (!actual?.equals(Buffer.from(before, "utf8")))
|
|
931
|
+
throw new StaleAdoptPlanError(path);
|
|
524
932
|
}
|
|
525
933
|
}
|
|
526
|
-
const markers = new Set(["package.json", MANIFEST_FILE]);
|
|
934
|
+
const markers = new Set(["package.json", PYPROJECT, MANIFEST_FILE]);
|
|
527
935
|
const ordered = [
|
|
528
936
|
...plan.writes.filter(({ path }) => !markers.has(path)),
|
|
529
937
|
...plan.writes.filter(({ path }) => markers.has(path)),
|