@prompd/core 0.5.1 → 0.5.3

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.cjs CHANGED
@@ -3395,11 +3395,19 @@ var MAX_PACKAGE_SIZE = 50 * 1024 * 1024;
3395
3395
  function slugify(name) {
3396
3396
  return name.toLowerCase().replace(/[@/]+/g, "-").replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
3397
3397
  }
3398
- function resolvePackageDir(root, type, name) {
3399
- return joinPosix(root, ".prompd", getInstallDirForType(type), name);
3398
+ var DEFAULT_INSTALL_DIR = ".prompd";
3399
+ function checkInstallDir(dir) {
3400
+ const d = dir ?? DEFAULT_INSTALL_DIR;
3401
+ if (!/^\.[A-Za-z0-9][A-Za-z0-9._-]*$/.test(d)) {
3402
+ throw new Error(`Invalid installDir "${d}": expected a single dot-directory name like ".prompd".`);
3403
+ }
3404
+ return d;
3405
+ }
3406
+ function resolvePackageDir(root, installDir, type, name) {
3407
+ return joinPosix(root, installDir, getInstallDirForType(type), name);
3400
3408
  }
3401
- function resolveInstallDir(root, type, name, version) {
3402
- return joinPosix(resolvePackageDir(root, type, name), version);
3409
+ function resolveInstallDir(root, installDir, type, name, version) {
3410
+ return joinPosix(resolvePackageDir(root, installDir, type, name), version);
3403
3411
  }
3404
3412
  async function addWorkspaceDependency(store, root, name, version) {
3405
3413
  if (!store.readFile) return;
@@ -3441,6 +3449,7 @@ async function installPackage(opts) {
3441
3449
  }
3442
3450
  async function installInternal(opts, visited) {
3443
3451
  const { ref, root, store, download, global, tools, deployTool } = opts;
3452
+ const installDir = checkInstallDir(opts.installDir);
3444
3453
  const parsed = parsePackageReference(ref);
3445
3454
  const bytes = await download(parsed.name, parsed.version);
3446
3455
  if (bytes.length > MAX_PACKAGE_SIZE) {
@@ -3467,11 +3476,11 @@ async function installInternal(opts, visited) {
3467
3476
  if (!store.writeBytes) {
3468
3477
  throw new Error("Installing a node-template requires a PackageStore with writeBytes (binary). This host does not support it.");
3469
3478
  }
3470
- const dir = joinPosix(root, ".prompd", getInstallDirForType("node-template"));
3479
+ const dir = joinPosix(root, installDir, getInstallDirForType("node-template"));
3471
3480
  installedPath = joinPosix(dir, `${slugify(name)}-${version}.pdpkg`);
3472
3481
  await store.writeBytes(installedPath, bytes);
3473
3482
  } else {
3474
- installedPath = resolveInstallDir(root, type, name, version);
3483
+ installedPath = resolveInstallDir(root, installDir, type, name, version);
3475
3484
  const base = normalizePosix(installedPath);
3476
3485
  await store.removeDir?.(installedPath);
3477
3486
  for (const [rel, content] of files) {
@@ -3494,13 +3503,14 @@ async function installInternal(opts, visited) {
3494
3503
  }
3495
3504
  async function uninstallPackage(opts) {
3496
3505
  const { root, store, global } = opts;
3506
+ const installDir = checkInstallDir(opts.installDir);
3497
3507
  if (!store.removeDir) throw new Error("Uninstall requires a PackageStore with removeDir.");
3498
3508
  const parsed = parsePackageReference(opts.ref);
3499
3509
  const name = parsed.name;
3500
3510
  const removed = [];
3501
3511
  for (const type of ["package", "workflow", "skill", "node-template"]) {
3502
3512
  if (type === "node-template") {
3503
- const dir = joinPosix(root, ".prompd", getInstallDirForType("node-template"));
3513
+ const dir = joinPosix(root, installDir, getInstallDirForType("node-template"));
3504
3514
  if (!store.readdir || !store.removeFile || !store.readBytes) continue;
3505
3515
  try {
3506
3516
  for (const entry of await store.readdir(dir)) {
@@ -3518,7 +3528,7 @@ async function uninstallPackage(opts) {
3518
3528
  } catch {
3519
3529
  }
3520
3530
  } else {
3521
- const dir = resolvePackageDir(root, type, name);
3531
+ const dir = resolvePackageDir(root, installDir, type, name);
3522
3532
  await store.removeDir(dir);
3523
3533
  removed.push(dir);
3524
3534
  }