@adunne09/waldo 0.0.0-dev-202603160033 → 0.0.0-dev-202603161554

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.
Files changed (2) hide show
  1. package/bin/waldo +87 -11
  2. package/package.json +6 -6
package/bin/waldo CHANGED
@@ -6,8 +6,41 @@ import os from "node:os";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
 
9
+ function findNodeModulesRoot(target) {
10
+ let current = path.dirname(target);
11
+
12
+ for (;;) {
13
+ if (path.basename(current) === "node_modules") {
14
+ return current;
15
+ }
16
+
17
+ const parent = path.dirname(current);
18
+ if (parent === current) {
19
+ return undefined;
20
+ }
21
+
22
+ current = parent;
23
+ }
24
+ }
25
+
26
+ function createRuntimeEnv(target) {
27
+ const nodeModulesRoot = findNodeModulesRoot(target);
28
+ if (!nodeModulesRoot) {
29
+ return process.env;
30
+ }
31
+
32
+ const existingNodePath = process.env.NODE_PATH;
33
+ return {
34
+ ...process.env,
35
+ NODE_PATH: existingNodePath
36
+ ? `${nodeModulesRoot}${path.delimiter}${existingNodePath}`
37
+ : nodeModulesRoot,
38
+ };
39
+ }
40
+
9
41
  function run(target) {
10
42
  const result = childProcess.spawnSync(target, process.argv.slice(2), {
43
+ env: createRuntimeEnv(target),
11
44
  stdio: "inherit",
12
45
  });
13
46
 
@@ -19,10 +52,10 @@ function run(target) {
19
52
  process.exit(typeof result.status === "number" ? result.status : 0);
20
53
  }
21
54
 
22
- const envPath = process.env.WALDO_BIN_PATH;
23
- if (envPath) {
24
- run(envPath);
25
- }
55
+ const internalAutoUpdateFlag = "WALDO_INTERNAL_AUTOUPDATE";
56
+ const internalAutoUpdateCurrentVersionKey = "WALDO_INTERNAL_AUTOUPDATE_CURRENT_VERSION";
57
+ const internalAutoUpdateMethodKey = "WALDO_INTERNAL_AUTOUPDATE_METHOD";
58
+ const internalAutoUpdateReleaseTagKey = "WALDO_INTERNAL_AUTOUPDATE_RELEASE_TAG";
26
59
 
27
60
  const scriptPath = fs.realpathSync(fileURLToPath(import.meta.url));
28
61
  const scriptDir = path.dirname(scriptPath);
@@ -34,6 +67,11 @@ const defaultNpmRegistry = "https://registry.npmjs.org";
34
67
  const publicPackageName = "@adunne09/waldo";
35
68
  const defaultReleaseTag = "latest";
36
69
 
70
+ const envPath = process.env.WALDO_BIN_PATH;
71
+ if (envPath && process.env[internalAutoUpdateFlag] !== "1") {
72
+ run(envPath);
73
+ }
74
+
37
75
  let cachedPackageMetadata;
38
76
 
39
77
  function readPackageMetadata() {
@@ -303,6 +341,45 @@ function formatAutoUpdateSuccessMessage(current, latest) {
303
341
  return `Updated Waldo from ${current} to ${latest}. Restart to apply changes.`;
304
342
  }
305
343
 
344
+ function startAutoUpdateInBackground(method, current, releaseTag) {
345
+ const child = childProcess.spawn(process.execPath, [scriptPath], {
346
+ cwd: os.homedir(),
347
+ detached: true,
348
+ env: {
349
+ ...process.env,
350
+ [internalAutoUpdateFlag]: "1",
351
+ [internalAutoUpdateCurrentVersionKey]: current,
352
+ [internalAutoUpdateMethodKey]: method,
353
+ [internalAutoUpdateReleaseTagKey]: releaseTag,
354
+ },
355
+ stdio: ["ignore", "inherit", "inherit"],
356
+ });
357
+
358
+ child.unref();
359
+ }
360
+
361
+ async function runAutoUpdateInBackgroundProcess() {
362
+ const current = process.env[internalAutoUpdateCurrentVersionKey] || resolveCurrentVersion();
363
+ const method = process.env[internalAutoUpdateMethodKey] || resolveInstallMethod();
364
+ const releaseTag = process.env[internalAutoUpdateReleaseTagKey] || resolveReleaseTag();
365
+
366
+ if (method === "unknown") {
367
+ return;
368
+ }
369
+
370
+ try {
371
+ const latest = await resolveLatestVersion(releaseTag);
372
+ if (current === latest) {
373
+ return;
374
+ }
375
+
376
+ runGlobalUpgrade(method, latest);
377
+ console.log(formatAutoUpdateSuccessMessage(current, latest));
378
+ } catch {
379
+ console.error(`Waldo update failed; continuing with ${current}.`);
380
+ }
381
+ }
382
+
306
383
  const platformMap = {
307
384
  darwin: "darwin",
308
385
  linux: "linux",
@@ -362,19 +439,18 @@ async function maybeAutoUpdate() {
362
439
  try {
363
440
  const current = resolveCurrentVersion();
364
441
  const releaseTag = resolveReleaseTag();
365
- const latest = await resolveLatestVersion(releaseTag);
366
- if (current === latest) {
367
- return;
368
- }
369
-
370
- runGlobalUpgrade(method, latest);
371
- console.error(formatAutoUpdateSuccessMessage(current, latest));
442
+ startAutoUpdateInBackground(method, current, releaseTag);
372
443
  } catch {
373
444
  const current = resolveCurrentVersion();
374
445
  console.error(`Waldo update failed; continuing with ${current}.`);
375
446
  }
376
447
  }
377
448
 
449
+ if (process.env[internalAutoUpdateFlag] === "1") {
450
+ await runAutoUpdateInBackgroundProcess();
451
+ process.exit(0);
452
+ }
453
+
378
454
  await maybeAutoUpdate();
379
455
 
380
456
  const resolved = resolveBinary();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adunne09/waldo",
3
- "version": "0.0.0-dev-202603160033",
3
+ "version": "0.0.0-dev-202603161554",
4
4
  "waldoReleaseTag": "dev",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,10 +13,10 @@
13
13
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
14
14
  },
15
15
  "optionalDependencies": {
16
- "@adunne09/waldo-darwin-arm64": "0.0.0-dev-202603160033",
17
- "@adunne09/waldo-darwin-x64": "0.0.0-dev-202603160033",
18
- "@adunne09/waldo-linux-arm64": "0.0.0-dev-202603160033",
19
- "@adunne09/waldo-linux-x64": "0.0.0-dev-202603160033",
20
- "@adunne09/waldo-windows-x64": "0.0.0-dev-202603160033"
16
+ "@adunne09/waldo-darwin-arm64": "0.0.0-dev-202603161554",
17
+ "@adunne09/waldo-darwin-x64": "0.0.0-dev-202603161554",
18
+ "@adunne09/waldo-linux-arm64": "0.0.0-dev-202603161554",
19
+ "@adunne09/waldo-linux-x64": "0.0.0-dev-202603161554",
20
+ "@adunne09/waldo-windows-x64": "0.0.0-dev-202603161554"
21
21
  }
22
22
  }