@0perator/operator 0.1.360-next.1 → 0.1.360-next.2

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/update.js CHANGED
@@ -29,6 +29,22 @@ export function updateChannel(args, current) {
29
29
  }
30
30
  // A next build is a 0.1.N-next.K prerelease; a release is a plain 0.1.N.
31
31
  const channelOf = (version) => (/-next\.\d+$/.test(version) ? "next" : "latest");
32
+ /** Whether `target` is older than `current`. 0.1.N-next.K precedes 0.1.N. An unparsable version is never older. */
33
+ export function isOlder(target, current) {
34
+ const parse = (v) => {
35
+ const m = /^(\d+)\.(\d+)\.(\d+)(?:-next\.(\d+))?$/.exec(v);
36
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3]), m[4] === undefined ? Infinity : Number(m[4])] : undefined;
37
+ };
38
+ const t = parse(target), c = parse(current);
39
+ if (!t || !c)
40
+ return false;
41
+ const i = t.findIndex((n, k) => n !== c[k]);
42
+ return i >= 0 && t[i] < c[i];
43
+ }
44
+ // A plain `operator update` never goes back: a build older than the running one installs only when a flag names its
45
+ // channel.
46
+ const refusedAsOlder = (channel, target, current) => `operator update: the ${channel} channel is v${target}, older than this v${current} — nothing installed. ` +
47
+ `To go back on purpose: operator update --${channel}\n`;
32
48
  // Walk up from the running file looking for a .git dir (source checkout) before we hit a
33
49
  // node_modules boundary (global install). Returns the repo root, or null for a packaged install.
34
50
  function findRepoRoot() {
@@ -80,7 +96,7 @@ function versionAt(pkgJson) {
80
96
  * the other channel: a tag the registry doesn't have, or a registry it can't read, installs nothing and exits 1.
81
97
  * Before and after are read from THIS install's package.json (npm replaces it in place), not from `npm root -g`: npm
82
98
  * redacts UUID-shaped path segments in its output as `***`. */
83
- export function installChannel(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url))) {
99
+ export function installChannel(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), refuseOlder = false) {
84
100
  const current = versionAt(pkgJson) ?? "?";
85
101
  const read = distTags();
86
102
  if ("error" in read) {
@@ -94,6 +110,10 @@ export function installChannel(channel, pkgJson = fileURLToPath(new URL("../pack
94
110
  process.stderr.write(`operator update: ${PKG} has no ${channel} channel on the registry yet (it has ${has}) — nothing installed.\n`);
95
111
  return 1;
96
112
  }
113
+ if (refuseOlder && isOlder(target, current)) {
114
+ process.stderr.write(refusedAsOlder(channel, target, current));
115
+ return 0;
116
+ }
97
117
  process.stderr.write(`operator update: v${current} (${channelOf(current)}) → ${PKG}@${channel} (v${target})\n`);
98
118
  const code = run("npm", ["install", "-g", `${PKG}@${channel}`]);
99
119
  if (code !== 0) {
@@ -120,7 +140,7 @@ async function download(url, ms) {
120
140
  * old ones (kept for rollback) and its bin link moved; any other install is replaced in place by `npm install -g`.
121
141
  * Returns null, having installed nothing, when the URL can't be reached and the registry can stand in (not for an
122
142
  * install.sh install, which exits 1 instead). */
123
- export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), base = process.env.OPERATOR_DIST_BASE || DIST_BASE) {
143
+ export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), base = process.env.OPERATOR_DIST_BASE || DIST_BASE, refuseOlder = false) {
124
144
  const current = versionAt(pkgJson) ?? "?";
125
145
  const release = RELEASE_PKG.exec(pkgJson);
126
146
  let target, tarball, sums;
@@ -132,6 +152,10 @@ export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("
132
152
  process.stderr.write(`operator update: already on v${current} (${channel}).\n`);
133
153
  return 0;
134
154
  }
155
+ if (refuseOlder && isOlder(target, current)) {
156
+ process.stderr.write(refusedAsOlder(channel, target, current));
157
+ return 0;
158
+ }
135
159
  [tarball, sums] = await Promise.all([
136
160
  download(`${base}/operator-${target}.tgz`, 300_000),
137
161
  download(`${base}/SHA256SUMS`, 15_000).then((b) => b.toString("utf8")),
@@ -235,5 +259,6 @@ export async function runUpdate(args = [], pkgJson = fileURLToPath(new URL("../p
235
259
  }
236
260
  return code;
237
261
  }
238
- return (await installFromDist(pick.channel)) ?? installChannel(pick.channel);
262
+ const refuseOlder = !pick.explicit;
263
+ return (await installFromDist(pick.channel, undefined, undefined, refuseOlder)) ?? installChannel(pick.channel, undefined, refuseOlder);
239
264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.360-next.1",
3
+ "version": "0.1.360-next.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",