@pmate/cli 0.48.4 → 0.49.0
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.js +35 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8933,6 +8933,7 @@ function packageRef(value) {
|
|
|
8933
8933
|
function validateInstallMetadata(value, id) {
|
|
8934
8934
|
const p = value;
|
|
8935
8935
|
if (!p || p.id !== id || p.id !== p.namespace + ":" + p.name || !semver.test(p.version) || !/^[-a-zA-Z0-9_.]+\/[-a-zA-Z0-9_.]+$/.test(p.repository) || !relative(p.directory) || !relative(p.manifest) || !Array.isArray(p.platforms) || !Array.isArray(p.prepare) || p.prepare.length > 20 || !p.bins || typeof p.bins !== "object" || !Object.keys(p.bins).length) throw Error("Invalid package registry metadata");
|
|
8936
|
+
if (p.replaces !== void 0 && (!Array.isArray(p.replaces) || p.replaces.length > 20 || p.replaces.some((id2) => typeof id2 !== "string" || packageRef(id2).id !== id2 || packageRef(id2).namespace !== p.namespace || id2 === p.id))) throw Error("Invalid replaced package identities");
|
|
8936
8937
|
for (const [name, file] of Object.entries(p.bins)) if (!segment.test(name) || !relative(file)) throw Error("Invalid package bin");
|
|
8937
8938
|
for (const step of [...p.prepare, ...Object.values(p.lifecycle ?? {})]) if (!step || typeof step.command !== "string" || !step.command || step.command.includes("\0") || !Array.isArray(step.args) || step.args.some((a) => typeof a !== "string" || a.includes("\0")) || step.cwd !== void 0 && !relative(step.cwd)) throw Error("Invalid package command");
|
|
8938
8939
|
if (p.lifecycle && !["health,start,status,stop", "drain,health,start,status,stop"].includes(Object.keys(p.lifecycle).sort().join(","))) throw Error("Incomplete package lifecycle");
|
|
@@ -8972,6 +8973,28 @@ var PackageInstaller = class {
|
|
|
8972
8973
|
const cwd = step.cwd ? this.local(root, step.cwd) : root;
|
|
8973
8974
|
return this.execute(step.command, step.args, cwd);
|
|
8974
8975
|
}
|
|
8976
|
+
validateReplacements(metadata, records) {
|
|
8977
|
+
for (const id of metadata.replaces ?? []) {
|
|
8978
|
+
const old = records[id];
|
|
8979
|
+
if (!old) continue;
|
|
8980
|
+
if (old.definition.lifecycle || Object.keys(old.bins).some((bin) => !metadata.bins[bin])) throw Error("Replacement must include every old command and cannot replace managed services");
|
|
8981
|
+
for (const bin of Object.keys(old.bins)) this.commandOwner({ ...metadata, id: "replacement-validation" }, { [id]: old }, bin);
|
|
8982
|
+
}
|
|
8983
|
+
}
|
|
8984
|
+
commandOwner(metadata, records, name) {
|
|
8985
|
+
const candidates = [records[metadata.id], ...(metadata.replaces ?? []).map((id) => records[id])].filter((p) => !!p);
|
|
8986
|
+
const owner = candidates.find((p) => p.bins[name]);
|
|
8987
|
+
if (owner && owner.id !== metadata.id) {
|
|
8988
|
+
if (owner.definition.lifecycle) throw Error("Cannot replace a package with managed services");
|
|
8989
|
+
if (Object.keys(owner.bins).some((bin) => !metadata.bins[bin])) throw Error("Replacement must include every old command");
|
|
8990
|
+
const roots = [import_node_path2.default.join(this.directory, "repos", ...owner.definition.repository.split("/")), import_node_path2.default.join(this.directory, "releases", ...owner.definition.repository.split("/"), owner.definition.name + "-" + owner.version)];
|
|
8991
|
+
if (!roots.includes(owner.root) || !(0, import_node_fs2.realpathSync)(owner.bins[name]).startsWith((0, import_node_fs2.realpathSync)(owner.root) + import_node_path2.default.sep)) throw Error("Replaced command is outside its managed installation");
|
|
8992
|
+
}
|
|
8993
|
+
return owner;
|
|
8994
|
+
}
|
|
8995
|
+
retireReplaced(metadata, records) {
|
|
8996
|
+
for (const id of metadata.replaces ?? []) if (records[id]) delete records[id];
|
|
8997
|
+
}
|
|
8975
8998
|
async healthy(root, step) {
|
|
8976
8999
|
for (let attempt = 0; attempt < 15; attempt++) {
|
|
8977
9000
|
try {
|
|
@@ -9011,12 +9034,14 @@ var PackageInstaller = class {
|
|
|
9011
9034
|
}
|
|
9012
9035
|
/** Prepare a separate source tree, then switch command links. Never touch running processes. */
|
|
9013
9036
|
async installStaged(metadata) {
|
|
9014
|
-
const records = this.records()
|
|
9037
|
+
const records = this.records();
|
|
9038
|
+
this.validateReplacements(metadata, records);
|
|
9039
|
+
const old = records[metadata.id];
|
|
9015
9040
|
const root = import_node_path2.default.join(this.directory, "releases", ...metadata.repository.split("/"), metadata.name + "-" + metadata.version);
|
|
9016
9041
|
(0, import_node_fs2.mkdirSync)(this.binDirectory, { recursive: true });
|
|
9017
9042
|
for (const name of Object.keys(metadata.bins)) {
|
|
9018
|
-
const link = import_node_path2.default.join(this.binDirectory, name), stat = (0, import_node_fs2.lstatSync)(link, { throwIfNoEntry: false });
|
|
9019
|
-
if (stat && (!
|
|
9043
|
+
const owner = this.commandOwner(metadata, records, name), link = import_node_path2.default.join(this.binDirectory, name), stat = (0, import_node_fs2.lstatSync)(link, { throwIfNoEntry: false });
|
|
9044
|
+
if (stat && (!owner?.bins[name] || !stat.isSymbolicLink() || (0, import_node_fs2.realpathSync)(link) !== (0, import_node_fs2.realpathSync)(owner.bins[name]))) throw Error("Refusing to replace unmanaged command: " + name);
|
|
9020
9045
|
}
|
|
9021
9046
|
if (old?.version === metadata.version) {
|
|
9022
9047
|
const manifest2 = JSON.parse((0, import_node_fs2.readFileSync)(this.local(old.root, import_node_path2.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
@@ -9046,13 +9071,16 @@ var PackageInstaller = class {
|
|
|
9046
9071
|
(0, import_node_fs2.renameSync)(temporary, link);
|
|
9047
9072
|
}
|
|
9048
9073
|
const record = { id: metadata.id, version: metadata.version, root, directory: metadata.directory, manifest: metadata.manifest, bins, metadataRevision: metadata.revision, commit, installedAt: (/* @__PURE__ */ new Date()).toISOString(), definition: metadata };
|
|
9074
|
+
this.retireReplaced(metadata, records);
|
|
9049
9075
|
records[metadata.id] = record;
|
|
9050
9076
|
this.save(records);
|
|
9051
9077
|
this.say("Installed " + metadata.id + " " + metadata.version + "; restart selected processes separately");
|
|
9052
9078
|
return { ...record, changed: true };
|
|
9053
9079
|
}
|
|
9054
9080
|
async installLocked(metadata) {
|
|
9055
|
-
const records = this.records()
|
|
9081
|
+
const records = this.records();
|
|
9082
|
+
this.validateReplacements(metadata, records);
|
|
9083
|
+
const old = records[metadata.id], root = import_node_path2.default.join(this.directory, "repos", ...metadata.repository.split("/"));
|
|
9056
9084
|
(0, import_node_fs2.mkdirSync)(import_node_path2.default.dirname(root), { recursive: true, mode: 448 });
|
|
9057
9085
|
if (old && old.root !== root) throw Error("Installed repository location differs; migration required");
|
|
9058
9086
|
if ((0, import_node_fs2.existsSync)(root)) {
|
|
@@ -9063,8 +9091,8 @@ var PackageInstaller = class {
|
|
|
9063
9091
|
}
|
|
9064
9092
|
(0, import_node_fs2.mkdirSync)(this.binDirectory, { recursive: true });
|
|
9065
9093
|
for (const name of Object.keys(metadata.bins)) {
|
|
9066
|
-
const file = import_node_path2.default.join(this.binDirectory, name), stat = (0, import_node_fs2.lstatSync)(file, { throwIfNoEntry: false });
|
|
9067
|
-
if (stat && (!
|
|
9094
|
+
const owner = this.commandOwner(metadata, records, name), file = import_node_path2.default.join(this.binDirectory, name), stat = (0, import_node_fs2.lstatSync)(file, { throwIfNoEntry: false });
|
|
9095
|
+
if (stat && (!owner?.bins[name] || !stat.isSymbolicLink() || (0, import_node_fs2.realpathSync)(file) !== (0, import_node_fs2.realpathSync)(owner.bins[name]))) throw Error("Refusing to replace unmanaged command: " + name);
|
|
9068
9096
|
}
|
|
9069
9097
|
if (old?.version === metadata.version && (0, import_node_fs2.existsSync)(root)) {
|
|
9070
9098
|
const manifest = JSON.parse((0, import_node_fs2.readFileSync)(this.local(root, import_node_path2.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
@@ -9138,6 +9166,7 @@ var PackageInstaller = class {
|
|
|
9138
9166
|
(0, import_node_fs2.renameSync)(temporary, link);
|
|
9139
9167
|
}
|
|
9140
9168
|
const record = { id: metadata.id, version: metadata.version, root, directory: metadata.directory, manifest: metadata.manifest, bins, metadataRevision: metadata.revision, commit, installedAt: (/* @__PURE__ */ new Date()).toISOString(), definition: metadata };
|
|
9169
|
+
this.retireReplaced(metadata, records);
|
|
9141
9170
|
records[metadata.id] = record;
|
|
9142
9171
|
this.save(records);
|
|
9143
9172
|
this.say("Installed " + metadata.id + " " + metadata.version);
|