@amaster.ai/cli 1.1.38 → 1.1.40
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/cli.cjs +33 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +33 -4
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -599,6 +599,9 @@ function validateMembers(manifest) {
|
|
|
599
599
|
if (!resolveMemberSourcePath(member)) {
|
|
600
600
|
throw new Error(`addon.json member ${member.name} missing source.path`);
|
|
601
601
|
}
|
|
602
|
+
if (member.type === "settings" && resolveMemberTargetPath(member)) {
|
|
603
|
+
throw new Error(`Settings member ${member.name} does not support target.path`);
|
|
604
|
+
}
|
|
602
605
|
}
|
|
603
606
|
}
|
|
604
607
|
function validateDisplayAssets(manifest) {
|
|
@@ -830,6 +833,13 @@ function resolveMemberSourcePath(member) {
|
|
|
830
833
|
}
|
|
831
834
|
return null;
|
|
832
835
|
}
|
|
836
|
+
function resolveMemberTargetPath(member) {
|
|
837
|
+
const targetPath = member.target?.path;
|
|
838
|
+
if (typeof targetPath === "string" && targetPath.trim()) {
|
|
839
|
+
return normalizeRelativePath(targetPath, "member target path");
|
|
840
|
+
}
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
833
843
|
function normalizeRelativePath(value, fieldName = "path") {
|
|
834
844
|
if (isAbsolute(value)) {
|
|
835
845
|
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
@@ -1263,6 +1273,11 @@ function isExistingNpmDependencyCompatible(existingVersion, requestedVersion) {
|
|
|
1263
1273
|
}
|
|
1264
1274
|
return gte(existingMinimum, requestedMinimum);
|
|
1265
1275
|
}
|
|
1276
|
+
function isSameOrInsidePath(path, parentPath) {
|
|
1277
|
+
const normalizedPath = resolve("/", path);
|
|
1278
|
+
const normalizedParent = resolve("/", parentPath);
|
|
1279
|
+
return normalizedPath === normalizedParent || normalizedPath.startsWith(`${normalizedParent}/`);
|
|
1280
|
+
}
|
|
1266
1281
|
async function collectDirectoryFiles(sourceDir) {
|
|
1267
1282
|
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
1268
1283
|
const files = [];
|
|
@@ -1276,16 +1291,18 @@ async function collectDirectoryFiles(sourceDir) {
|
|
|
1276
1291
|
}
|
|
1277
1292
|
return files.sort();
|
|
1278
1293
|
}
|
|
1279
|
-
async function planCopyMember(sourceRoot, sourceRelativePath, targetBaseRelativeDir, member) {
|
|
1294
|
+
async function planCopyMember(sourceRoot, sourceRelativePath, targetBaseRelativeDir, member, targetRelativePath) {
|
|
1280
1295
|
const sourceAbsolutePath = join(sourceRoot, sourceRelativePath);
|
|
1281
1296
|
const sourceStat = await stat(sourceAbsolutePath);
|
|
1282
1297
|
const plannedFiles = [];
|
|
1283
1298
|
const targetPaths = [];
|
|
1299
|
+
const defaultTargetPath = join(targetBaseRelativeDir, basename(sourceRelativePath)).replace(/\\/g, "/");
|
|
1300
|
+
const memberTargetPath = targetRelativePath ?? defaultTargetPath;
|
|
1284
1301
|
if (sourceStat.isDirectory()) {
|
|
1285
1302
|
const sourceFiles = await collectDirectoryFiles(sourceAbsolutePath);
|
|
1286
1303
|
for (const sourceFile of sourceFiles) {
|
|
1287
1304
|
const nestedRelativePath = relative(sourceAbsolutePath, sourceFile);
|
|
1288
|
-
const targetPath = join(
|
|
1305
|
+
const targetPath = join(memberTargetPath, nestedRelativePath).replace(/\\/g, "/");
|
|
1289
1306
|
const sourcePackagePath = join(sourceRelativePath, nestedRelativePath).replace(/\\/g, "/");
|
|
1290
1307
|
plannedFiles.push({
|
|
1291
1308
|
sourcePath: sourceFile,
|
|
@@ -1297,7 +1314,7 @@ async function planCopyMember(sourceRoot, sourceRelativePath, targetBaseRelative
|
|
|
1297
1314
|
targetPaths.push(targetPath);
|
|
1298
1315
|
}
|
|
1299
1316
|
} else {
|
|
1300
|
-
const targetPath =
|
|
1317
|
+
const targetPath = memberTargetPath;
|
|
1301
1318
|
plannedFiles.push({
|
|
1302
1319
|
sourcePath: sourceAbsolutePath,
|
|
1303
1320
|
sourceRelativePath,
|
|
@@ -1381,7 +1398,19 @@ async function buildInstallPlan(options) {
|
|
|
1381
1398
|
default:
|
|
1382
1399
|
throw new Error(`Unsupported addon member type: ${member.type}`);
|
|
1383
1400
|
}
|
|
1384
|
-
const
|
|
1401
|
+
const targetRelativePath = resolveMemberTargetPath(member);
|
|
1402
|
+
if (targetRelativePath && !isSameOrInsidePath(targetRelativePath, targetBaseRelativeDir)) {
|
|
1403
|
+
throw new Error(
|
|
1404
|
+
`Member ${member.name} target.path must stay inside ${targetBaseRelativeDir}: ${targetRelativePath}`
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1407
|
+
const planned = await planCopyMember(
|
|
1408
|
+
options.extractedDir,
|
|
1409
|
+
sourceRelativePath,
|
|
1410
|
+
targetBaseRelativeDir,
|
|
1411
|
+
member,
|
|
1412
|
+
targetRelativePath
|
|
1413
|
+
);
|
|
1385
1414
|
files.push(...planned.files);
|
|
1386
1415
|
const installedMember = {
|
|
1387
1416
|
name: member.name,
|