@prompd/core 0.5.0-beta.11 → 0.5.0-beta.13

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
@@ -3366,6 +3366,62 @@ var HybridFileSystem = class {
3366
3366
  }
3367
3367
  };
3368
3368
 
3369
+ // src/lib/compiler/install.ts
3370
+ var MAX_PACKAGE_SIZE = 50 * 1024 * 1024;
3371
+ function joinPosix3(...parts) {
3372
+ const joined = parts.filter((p) => p && p !== ".").join("/").replace(/\/{2,}/g, "/");
3373
+ return joined.replace(/\/+$/, "") || "/";
3374
+ }
3375
+ function normalizeSegments(p) {
3376
+ const out = [];
3377
+ for (const seg of p.split("/")) {
3378
+ if (!seg || seg === ".") continue;
3379
+ if (seg === "..") {
3380
+ out.pop();
3381
+ continue;
3382
+ }
3383
+ out.push(seg);
3384
+ }
3385
+ return out.join("/");
3386
+ }
3387
+ async function installPackage(opts) {
3388
+ const { ref, type, root, store, download } = opts;
3389
+ const parsed = parsePackageReference(ref);
3390
+ const bytes = await download(parsed.name, parsed.version);
3391
+ if (bytes.length > MAX_PACKAGE_SIZE) {
3392
+ throw new Error(`Package too large: ${bytes.length} bytes (max ${MAX_PACKAGE_SIZE})`);
3393
+ }
3394
+ const files = await extractPdpkg(bytes);
3395
+ if (files.size === 0) {
3396
+ throw new Error(`Package "${parsed.name}" contains no installable files.`);
3397
+ }
3398
+ let name = parsed.name;
3399
+ let version = parsed.version;
3400
+ const manifest = files.get("manifest.json") ?? files.get("prompd.json");
3401
+ if (manifest) {
3402
+ try {
3403
+ const m = JSON.parse(manifest);
3404
+ if (typeof m.name === "string" && m.name) name = m.name;
3405
+ if (typeof m.version === "string" && m.version) version = m.version;
3406
+ } catch {
3407
+ }
3408
+ }
3409
+ const installedPath = joinPosix3(root, ".prompd", getInstallDirForType(type), name);
3410
+ const baseSegments = normalizeSegments(installedPath);
3411
+ await store.removeDir?.(installedPath);
3412
+ const written = [];
3413
+ for (const [rel, content] of files) {
3414
+ const dest = joinPosix3(installedPath, rel);
3415
+ const destSegments = normalizeSegments(dest);
3416
+ if (destSegments !== baseSegments && !destSegments.startsWith(baseSegments + "/")) {
3417
+ throw new Error(`Security violation: extracted path escapes install directory: ${rel}`);
3418
+ }
3419
+ await store.writeFile(dest, content);
3420
+ written.push(rel);
3421
+ }
3422
+ return { name, version, scope: parsed.scope, installedPath, files: written };
3423
+ }
3424
+
3369
3425
  // src/lib/compiler/index.ts
3370
3426
  function createCoreStages() {
3371
3427
  return [
@@ -4809,6 +4865,7 @@ exports.getExecutionOrder = getExecutionOrder;
4809
4865
  exports.getInstallDirForType = getInstallDirForType;
4810
4866
  exports.getLanguageAliasesForExtension = getLanguageAliasesForExtension;
4811
4867
  exports.getLanguageForExtension = getLanguageForExtension;
4868
+ exports.installPackage = installPackage;
4812
4869
  exports.isAbsolutePosix = isAbsolutePosix;
4813
4870
  exports.isPrompdFile = isPrompdFile;
4814
4871
  exports.isValidPackageReference = isValidPackageReference;