@prompd/core 0.5.0-beta.12 → 0.5.0-beta.14
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 +71 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -1
- package/dist/index.d.ts +74 -1
- package/dist/index.js +70 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3366,6 +3366,75 @@ 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
|
+
function resolveInstallDir(root, type, name) {
|
|
3388
|
+
return joinPosix3(root, ".prompd", getInstallDirForType(type), name);
|
|
3389
|
+
}
|
|
3390
|
+
async function installPackage(opts) {
|
|
3391
|
+
const { ref, type, root, store, download } = opts;
|
|
3392
|
+
const parsed = parsePackageReference(ref);
|
|
3393
|
+
const bytes = await download(parsed.name, parsed.version);
|
|
3394
|
+
if (bytes.length > MAX_PACKAGE_SIZE) {
|
|
3395
|
+
throw new Error(`Package too large: ${bytes.length} bytes (max ${MAX_PACKAGE_SIZE})`);
|
|
3396
|
+
}
|
|
3397
|
+
const files = await extractPdpkg(bytes);
|
|
3398
|
+
if (files.size === 0) {
|
|
3399
|
+
throw new Error(`Package "${parsed.name}" contains no installable files.`);
|
|
3400
|
+
}
|
|
3401
|
+
let name = parsed.name;
|
|
3402
|
+
let version = parsed.version;
|
|
3403
|
+
const manifest = files.get("manifest.json") ?? files.get("prompd.json");
|
|
3404
|
+
if (manifest) {
|
|
3405
|
+
try {
|
|
3406
|
+
const m = JSON.parse(manifest);
|
|
3407
|
+
if (typeof m.name === "string" && m.name) name = m.name;
|
|
3408
|
+
if (typeof m.version === "string" && m.version) version = m.version;
|
|
3409
|
+
} catch {
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
const installedPath = resolveInstallDir(root, type, name);
|
|
3413
|
+
const baseSegments = normalizeSegments(installedPath);
|
|
3414
|
+
await store.removeDir?.(installedPath);
|
|
3415
|
+
const written = [];
|
|
3416
|
+
for (const [rel, content] of files) {
|
|
3417
|
+
const dest = joinPosix3(installedPath, rel);
|
|
3418
|
+
const destSegments = normalizeSegments(dest);
|
|
3419
|
+
if (destSegments !== baseSegments && !destSegments.startsWith(baseSegments + "/")) {
|
|
3420
|
+
throw new Error(`Security violation: extracted path escapes install directory: ${rel}`);
|
|
3421
|
+
}
|
|
3422
|
+
await store.writeFile(dest, content);
|
|
3423
|
+
written.push(rel);
|
|
3424
|
+
}
|
|
3425
|
+
return { name, version, scope: parsed.scope, installedPath, files: written };
|
|
3426
|
+
}
|
|
3427
|
+
async function uninstallPackage(opts) {
|
|
3428
|
+
const { ref, type, root, store } = opts;
|
|
3429
|
+
if (!store.removeDir) {
|
|
3430
|
+
throw new Error("Uninstall requires a PackageStore with removeDir.");
|
|
3431
|
+
}
|
|
3432
|
+
const parsed = parsePackageReference(ref);
|
|
3433
|
+
const installedPath = resolveInstallDir(root, type, parsed.name);
|
|
3434
|
+
await store.removeDir(installedPath);
|
|
3435
|
+
return { name: parsed.name, scope: parsed.scope, installedPath };
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3369
3438
|
// src/lib/compiler/index.ts
|
|
3370
3439
|
function createCoreStages() {
|
|
3371
3440
|
return [
|
|
@@ -4809,6 +4878,7 @@ exports.getExecutionOrder = getExecutionOrder;
|
|
|
4809
4878
|
exports.getInstallDirForType = getInstallDirForType;
|
|
4810
4879
|
exports.getLanguageAliasesForExtension = getLanguageAliasesForExtension;
|
|
4811
4880
|
exports.getLanguageForExtension = getLanguageForExtension;
|
|
4881
|
+
exports.installPackage = installPackage;
|
|
4812
4882
|
exports.isAbsolutePosix = isAbsolutePosix;
|
|
4813
4883
|
exports.isPrompdFile = isPrompdFile;
|
|
4814
4884
|
exports.isValidPackageReference = isValidPackageReference;
|
|
@@ -4823,6 +4893,7 @@ exports.resolvePackageFile = resolvePackageFile;
|
|
|
4823
4893
|
exports.resolvePosix = resolvePosix;
|
|
4824
4894
|
exports.serializeWorkflow = serializeWorkflow;
|
|
4825
4895
|
exports.stripFilePath = stripFilePath;
|
|
4896
|
+
exports.uninstallPackage = uninstallPackage;
|
|
4826
4897
|
exports.validateWorkflow = validateWorkflow;
|
|
4827
4898
|
exports.validateWorkflowQuick = validateWorkflowQuick;
|
|
4828
4899
|
//# sourceMappingURL=index.cjs.map
|