kryptheon 0.1.18 → 0.1.19

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/bin/kryptheon.js CHANGED
@@ -1365,15 +1365,20 @@ function writeOwnPackageJson(dir) {
1365
1365
  }
1366
1366
  }
1367
1367
 
1368
- function installKryptheonIn(dir) {
1369
- console.log(' Installing kryptheon here - this usually takes under a minute.');
1370
- const args = ['install', '--save-dev', 'kryptheon', '--no-audit', '--no-fund', '--loglevel=error'];
1371
- // npm is npm.cmd on Windows, and Node will not start a .cmd directly
1372
- // (spawnSync EINVAL), so there it goes through cmd.exe. Every argument is a
1373
- // fixed string; nothing anybody typed reaches this command line.
1374
- const result = process.platform === 'win32'
1368
+ // `npm install --save-dev <spec>` in a folder. npm is npm.cmd on Windows, and
1369
+ // Node will not start a .cmd directly (spawnSync EINVAL), so there it goes
1370
+ // through cmd.exe. The spec is always "kryptheon" or "kryptheon@" and a
1371
+ // version made of digits and dots; nothing anybody typed reaches this line.
1372
+ function npmInstallDev(dir, spec) {
1373
+ const args = ['install', '--save-dev', spec, '--no-audit', '--no-fund', '--loglevel=error'];
1374
+ return process.platform === 'win32'
1375
1375
  ? spawnSync(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npm'].concat(args), { cwd: dir, encoding: 'utf8' })
1376
1376
  : spawnSync('npm', args, { cwd: dir, encoding: 'utf8' });
1377
+ }
1378
+
1379
+ function installKryptheonIn(dir) {
1380
+ console.log(' Installing kryptheon here - this usually takes under a minute.');
1381
+ const result = npmInstallDev(dir, 'kryptheon');
1377
1382
  // Judged by what is on disk afterwards, not by npm's exit code alone.
1378
1383
  const ok = !result.error && result.status === 0 && project.kryptheonInstalledIn(dir);
1379
1384
  if (ok) {
@@ -2085,6 +2090,37 @@ function handToFolderCopy() {
2085
2090
  /* said as unknown */
2086
2091
  }
2087
2092
  const mine = packageVersion();
2093
+
2094
+ // An older copy is brought up to this one first. Found the day 0.1.18
2095
+ // shipped: the fix was on the registry, `npx kryptheon@latest check` and
2096
+ // every AI tool asked for it, and the folder's 0.1.17 ran anyway - the
2097
+ // person would have had to type an npm command to get what they had
2098
+ // already asked for. Never downwards: a folder that is ahead of a cached
2099
+ // npx copy keeps what it has.
2100
+ if (project.olderVersion(theirVersion, mine)) {
2101
+ const root = path.dirname(path.dirname(theirs)); // <root>/node_modules/kryptheon
2102
+ if (project.hasPackageJson(root)) {
2103
+ console.log('');
2104
+ console.log(' This folder has kryptheon ' + theirVersion + ' and this is ' + mine + '. Updating the folder\'s');
2105
+ console.log(' copy, because your recordings load that one - usually under a minute.');
2106
+ const result = npmInstallDev(root, 'kryptheon@' + mine);
2107
+ let now = null;
2108
+ try {
2109
+ now = JSON.parse(fs.readFileSync(path.join(theirs, 'package.json'), 'utf8')).version;
2110
+ } catch (err) {
2111
+ now = null;
2112
+ }
2113
+ // Believed only when the folder now holds exactly this version.
2114
+ if (!result.error && result.status === 0 && now === mine && project.kryptheonCopyFor(USER_DIR) === theirs) {
2115
+ console.log(' Updated.');
2116
+ theirVersion = now;
2117
+ } else {
2118
+ console.log(' Could not update it just now (no internet?), so the ' + (now || theirVersion) + ' that is here runs.');
2119
+ if (now) theirVersion = now;
2120
+ }
2121
+ }
2122
+ }
2123
+
2088
2124
  if (theirVersion !== mine) {
2089
2125
  // Not an error: the folder's copy is the one its recordings are written
2090
2126
  // against. Said, so an older one is never mistaken for this one.
@@ -526,8 +526,29 @@ function installFailedLines() {
526
526
  ];
527
527
  }
528
528
 
529
+ /**
530
+ * Whether version `a` is older than `b`, by their numbers. Anything that is
531
+ * not plain x.y.z is never called older: updating on a guess would change
532
+ * somebody's package.json for nothing, and only digits and dots ever reach
533
+ * the npm command line built from the answer.
534
+ */
535
+ function olderVersion(a, b) {
536
+ const parse = (v) => {
537
+ const m = String(v == null ? '' : v).match(/^(\d+)\.(\d+)\.(\d+)$/);
538
+ return m ? m.slice(1).map(Number) : null;
539
+ };
540
+ const x = parse(a);
541
+ const y = parse(b);
542
+ if (!x || !y) return false;
543
+ for (let i = 0; i < 3; i++) {
544
+ if (x[i] !== y[i]) return x[i] < y[i];
545
+ }
546
+ return false;
547
+ }
548
+
529
549
  module.exports = {
530
550
  ESCAPE_HATCH: ESCAPE_HATCH,
551
+ olderVersion: olderVersion,
531
552
  HOME_RECORDINGS: HOME_RECORDINGS,
532
553
  kryptheonReachableFrom: kryptheonReachableFrom,
533
554
  kryptheonCopyFor: kryptheonCopyFor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kryptheon",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Record what you do in your app and get plain-language reports when it breaks.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",