neon 7.0.1 → 7.0.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/README.md CHANGED
@@ -47,10 +47,17 @@ brew upgrade neonctl
47
47
  To upgrade a binary version, download the latest binary file, as described above, and replace your old binary with the new one.
48
48
 
49
49
  Global npm, pnpm, Bun, and Homebrew installs check for updates once per day.
50
- When an update is available, terminal commands periodically print the matching
51
- upgrade command. Set `NO_UPDATE_NOTIFIER=1` to disable these checks. The notifier
50
+ When an update is available, terminal commands print the matching upgrade command
51
+ every three days. Set `NO_UPDATE_NOTIFIER=1` to disable these checks. The notifier
52
52
  does not run in CI, for machine-readable output, or from standalone binaries.
53
53
 
54
+ On macOS and Linux, the same terminal commands warn once a day when more than one
55
+ global `neon` install is on PATH, listing each one in PATH order. A project's
56
+ `node_modules/.bin`, which `npx` and package scripts add, doesn't count. When one
57
+ of them is Homebrew, the warning recommends `brew uninstall neonctl`, which
58
+ leaves `neon` running the other install, such as npm. While duplicates remain, the update notice is held back;
59
+ `NO_UPDATE_NOTIFIER=1` silences both.
60
+
54
61
  ## Connect
55
62
 
56
63
  Run the following command to authenticate a connection to Neon:
@@ -0,0 +1,47 @@
1
+ import { log } from "./log.js";
2
+ import { writeJsonFile } from "./utils/json_file.js";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ //#region src/notices.ts
6
+ /**
7
+ * When each terminal notice was last shown, so a notice repeats on its own interval rather
8
+ * than on every command. Kept apart from the update cache: that cache is tied to one install
9
+ * source and rewritten by a background worker, while a notice can come from any copy.
10
+ *
11
+ * Throttling is best effort. Two commands started together can both show a due notice.
12
+ */
13
+ const NOTICES_FILE = "notices.json";
14
+ /**
15
+ * Keeps ids this version doesn't know, so an older and a newer CLI sharing one config
16
+ * directory don't erase each other's timestamps.
17
+ */
18
+ const parseNoticeLog = (raw) => {
19
+ let value;
20
+ try {
21
+ value = JSON.parse(raw);
22
+ } catch {
23
+ return {};
24
+ }
25
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
26
+ return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "number" && Number.isFinite(entry[1])));
27
+ };
28
+ const isNoticeDue = (shownAt, now, intervalMs) => shownAt === void 0 || now - shownAt >= intervalMs;
29
+ const readNoticeLog = (path) => {
30
+ try {
31
+ return parseNoticeLog(readFileSync(path, "utf8"));
32
+ } catch {
33
+ return {};
34
+ }
35
+ };
36
+ const showNotice = ({ configDir, id, intervalMs, message, now = Date.now() }) => {
37
+ const path = join(configDir, NOTICES_FILE);
38
+ const shown = readNoticeLog(path);
39
+ if (!isNoticeDue(shown[id], now, intervalMs)) return;
40
+ log.warning("%s", message);
41
+ writeJsonFile(path, {
42
+ ...shown,
43
+ [id]: now
44
+ }, "CLI notice log");
45
+ };
46
+ //#endregion
47
+ export { isNoticeDue, parseNoticeLog, showNotice };
@@ -1,25 +1,29 @@
1
1
  import { isCi } from "./env.js";
2
2
  import { log } from "./log.js";
3
- import { recommendedCliUpgradeCommand } from "./utils/package_manager.js";
4
- import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
5
- import { join } from "node:path";
3
+ import { detectCliInstallMethod, recommendedCliUpgradeCommand } from "./utils/package_manager.js";
4
+ import { writeJsonFile } from "./utils/json_file.js";
5
+ import { showNotice } from "./notices.js";
6
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
7
+ import { basename, dirname, join } from "node:path";
6
8
  import { fileURLToPath } from "node:url";
7
9
  import { spawn } from "node:child_process";
10
+ import which from "which";
8
11
  import semver from "semver";
9
12
  //#region src/update_notifier.ts
10
- const CHECK_INTERVAL_MS = 864e5;
11
- const NOTIFY_INTERVAL_MS = 3 * CHECK_INTERVAL_MS;
13
+ const DAY_MS = 864e5;
14
+ const CHECK_INTERVAL_MS = DAY_MS;
15
+ const UPDATE_NOTICE_INTERVAL_MS = 3 * DAY_MS;
16
+ const DUPLICATE_NOTICE_INTERVAL_MS = DAY_MS;
12
17
  const CACHE_FILE = "update-check.json";
13
18
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
14
19
  const parseUpdateCheckCache = (raw) => {
15
20
  try {
16
21
  const value = JSON.parse(raw);
17
- if (!isRecord(value) || typeof value.checkedAt !== "number" || !Number.isFinite(value.checkedAt) || value.source !== "homebrew" && value.source !== "npm" || value.latestVersion !== void 0 && typeof value.latestVersion !== "string" || value.notifiedAt !== void 0 && (typeof value.notifiedAt !== "number" || !Number.isFinite(value.notifiedAt))) return;
22
+ if (!isRecord(value) || typeof value.checkedAt !== "number" || !Number.isFinite(value.checkedAt) || value.source !== "homebrew" && value.source !== "npm" || value.latestVersion !== void 0 && typeof value.latestVersion !== "string") return;
18
23
  return {
19
24
  checkedAt: value.checkedAt,
20
25
  source: value.source,
21
- ...value.latestVersion === void 0 ? {} : { latestVersion: value.latestVersion },
22
- ...value.notifiedAt === void 0 ? {} : { notifiedAt: value.notifiedAt }
26
+ ...value.latestVersion === void 0 ? {} : { latestVersion: value.latestVersion }
23
27
  };
24
28
  } catch {
25
29
  return;
@@ -32,20 +36,7 @@ const readUpdateCheckCache = (cachePath) => {
32
36
  return;
33
37
  }
34
38
  };
35
- const writeUpdateCheckCache = (cachePath, cache) => {
36
- const temporaryPath = `${cachePath}.${process.pid}.tmp`;
37
- try {
38
- writeFileSync(temporaryPath, `${JSON.stringify(cache)}\n`, { mode: 384 });
39
- renameSync(temporaryPath, cachePath);
40
- return true;
41
- } catch (error) {
42
- try {
43
- rmSync(temporaryPath, { force: true });
44
- } catch {}
45
- log.debug("Could not write the CLI update cache: %s", error instanceof Error ? error.message : String(error));
46
- return false;
47
- }
48
- };
39
+ const writeUpdateCheckCache = (cachePath, cache) => writeJsonFile(cachePath, cache, "CLI update cache");
49
40
  const formatUpdateNotice = ({ currentVersion, latestVersion, upgradeCommand }) => {
50
41
  if (semver.valid(currentVersion) === null || semver.valid(latestVersion) === null || !semver.gt(latestVersion, currentVersion)) return;
51
42
  return `Neon CLI update available: ${currentVersion} → ${latestVersion}\n${upgradeCommand}`;
@@ -84,6 +75,71 @@ const spawnUpdateWorker = (cachePath, source) => {
84
75
  log.debug("Could not start the CLI update check: %s", error instanceof Error ? error.message : String(error));
85
76
  }
86
77
  };
78
+ const INSTALL_LABELS = {
79
+ homebrew: "Homebrew",
80
+ bun: "Bun",
81
+ pnpm: "pnpm",
82
+ npm: "npm"
83
+ };
84
+ /**
85
+ * `npm exec`, `npx`, package scripts, and `dlx` prepend a project's or a cache's
86
+ * `node_modules/.bin`, which is gone from PATH once the command ends.
87
+ */
88
+ const isPackageBin = (executable) => {
89
+ const bin = dirname(executable);
90
+ return basename(bin) === ".bin" && basename(dirname(bin)) === "node_modules";
91
+ };
92
+ /**
93
+ * Every distinct `command` executable on `path`, in PATH order, leaving out
94
+ * package-local `node_modules/.bin` entries. Entries that resolve to the same
95
+ * file (a repeated PATH directory, Homebrew's `bin` and `opt` links) count once.
96
+ */
97
+ const findCliInstalls = (command, path) => {
98
+ const seen = /* @__PURE__ */ new Set();
99
+ const installs = [];
100
+ for (const executable of which.sync(command, {
101
+ all: true,
102
+ nothrow: true,
103
+ path
104
+ }) ?? []) {
105
+ if (isPackageBin(executable)) continue;
106
+ const target = realpathSync(executable);
107
+ if (seen.has(target)) continue;
108
+ seen.add(target);
109
+ installs.push({
110
+ method: detectCliInstallMethod(target),
111
+ path: executable
112
+ });
113
+ }
114
+ return installs;
115
+ };
116
+ const formatDuplicateInstallNotice = ({ installs, otherNeonctl }) => {
117
+ if (installs.length < 2) return void 0;
118
+ const lines = ["Multiple Neon CLI installs found on PATH:", ...installs.map(({ method, path }, index) => {
119
+ const labels = [...method === void 0 ? [] : [INSTALL_LABELS[method]], ...index === 0 ? ["first on PATH"] : []];
120
+ return labels.length === 0 ? ` ${path}` : ` ${path} (${labels.join(", ")})`;
121
+ })];
122
+ if (!installs.some(({ method }) => method === "homebrew")) {
123
+ lines.push("Keep one and uninstall the others.");
124
+ return lines.join("\n");
125
+ }
126
+ lines.push(installs.some(({ method }) => method === "npm") ? "Remove the Homebrew install to use npm:" : "Remove the Homebrew install:", " brew uninstall neonctl");
127
+ if (!otherNeonctl) lines.push("This also removes the `neonctl` command; run `neon` instead.");
128
+ lines.push("Then open a new shell.");
129
+ return lines.join("\n");
130
+ };
131
+ const duplicateInstallNotice = () => {
132
+ try {
133
+ const installs = findCliInstalls("neon", process.env.PATH);
134
+ return formatDuplicateInstallNotice({
135
+ installs,
136
+ otherNeonctl: findCliInstalls("neonctl", process.env.PATH).some(({ method }) => method !== "homebrew")
137
+ });
138
+ } catch (error) {
139
+ log.debug("Could not check PATH for other Neon CLI installs: %s", error instanceof Error ? error.message : String(error));
140
+ return;
141
+ }
142
+ };
87
143
  const isPackagedExecutable = () => "pkg" in process;
88
144
  const shouldRunUpdateNotifier = ({ commandPath, currentBranch, disabled, isCi: runningInCi, isPackaged, output, stderrIsTty, stdoutIsTty }) => !runningInCi && !disabled && !isPackaged && output === "table" && stdoutIsTty && stderrIsTty && commandPath.length > 0 && commandPath[0] !== "completion" && !isCurrentBranchProbe({
89
145
  commandPath,
@@ -100,37 +156,43 @@ const notifyIfUpdateAvailable = ({ commandPath, configDir, currentBranch, curren
100
156
  stderrIsTty: process.stderr.isTTY === true,
101
157
  stdoutIsTty: process.stdout.isTTY === true
102
158
  })) return;
159
+ const now = Date.now();
160
+ if (process.platform !== "win32") {
161
+ const duplicateNotice = duplicateInstallNotice();
162
+ if (duplicateNotice !== void 0) {
163
+ showNotice({
164
+ configDir,
165
+ id: "duplicate-installs",
166
+ intervalMs: DUPLICATE_NOTICE_INTERVAL_MS,
167
+ message: duplicateNotice,
168
+ now
169
+ });
170
+ return;
171
+ }
172
+ }
103
173
  const command = recommendedCliUpgradeCommand(fileURLToPath(import.meta.url));
104
174
  if (command === void 0) return;
105
175
  const cachePath = join(configDir, CACHE_FILE);
106
- const now = Date.now();
107
176
  const source = updateSource(command);
108
177
  const cache = cacheForUpdateSource(readUpdateCheckCache(cachePath), source);
109
- let nextCache = cache;
110
- if (cache?.latestVersion !== void 0 && (cache.notifiedAt === void 0 || now - cache.notifiedAt >= NOTIFY_INTERVAL_MS)) {
111
- const notice = formatUpdateNotice({
112
- currentVersion,
113
- latestVersion: cache.latestVersion,
114
- upgradeCommand: command
115
- });
116
- if (notice !== void 0) {
117
- log.warning("%s", notice);
118
- nextCache = {
119
- ...cache,
120
- notifiedAt: now
121
- };
122
- }
123
- }
124
- if (!shouldRefreshUpdateCheck(cache, now)) {
125
- if (nextCache !== cache && nextCache !== void 0) writeUpdateCheckCache(cachePath, nextCache);
126
- return;
127
- }
128
- nextCache = {
129
- ...nextCache,
178
+ const notice = cache?.latestVersion === void 0 ? void 0 : formatUpdateNotice({
179
+ currentVersion,
180
+ latestVersion: cache.latestVersion,
181
+ upgradeCommand: command
182
+ });
183
+ if (notice !== void 0) showNotice({
184
+ configDir,
185
+ id: "update",
186
+ intervalMs: UPDATE_NOTICE_INTERVAL_MS,
187
+ message: notice,
188
+ now
189
+ });
190
+ if (!shouldRefreshUpdateCheck(cache, now)) return;
191
+ if (writeUpdateCheckCache(cachePath, {
192
+ ...cache,
130
193
  checkedAt: now,
131
194
  source
132
- };
133
- if (writeUpdateCheckCache(cachePath, nextCache)) spawnUpdateWorker(cachePath, source);
195
+ })) spawnUpdateWorker(cachePath, source);
134
196
  };
135
197
  const recordLatestVersion = (cachePath, source, latestVersion) => {
136
198
  if (semver.valid(latestVersion) === null) return;
@@ -142,4 +204,4 @@ const recordLatestVersion = (cachePath, source, latestVersion) => {
142
204
  });
143
205
  };
144
206
  //#endregion
145
- export { cacheForUpdateSource, formatUpdateNotice, notifyIfUpdateAvailable, parseUpdateCheckCache, recordLatestVersion, shouldRefreshUpdateCheck, shouldRunUpdateNotifier, spawnUpdateWorkerProcess, writeUpdateCheckCache };
207
+ export { cacheForUpdateSource, findCliInstalls, formatDuplicateInstallNotice, formatUpdateNotice, notifyIfUpdateAvailable, parseUpdateCheckCache, recordLatestVersion, shouldRefreshUpdateCheck, shouldRunUpdateNotifier, spawnUpdateWorkerProcess, writeUpdateCheckCache };
@@ -0,0 +1,20 @@
1
+ import { log } from "../log.js";
2
+ import { renameSync, rmSync, writeFileSync } from "node:fs";
3
+ //#region src/utils/json_file.ts
4
+ /** Renames a temporary file into place so a concurrent reader never sees a partial write. */
5
+ const writeJsonFile = (path, value, description) => {
6
+ const temporaryPath = `${path}.${process.pid}.tmp`;
7
+ try {
8
+ writeFileSync(temporaryPath, `${JSON.stringify(value)}\n`, { mode: 384 });
9
+ renameSync(temporaryPath, path);
10
+ return true;
11
+ } catch (error) {
12
+ try {
13
+ rmSync(temporaryPath, { force: true });
14
+ } catch {}
15
+ log.debug("Could not write the %s: %s", description, error instanceof Error ? error.message : String(error));
16
+ return false;
17
+ }
18
+ };
19
+ //#endregion
20
+ export { writeJsonFile };
@@ -159,12 +159,23 @@ const resolvePackageManager = (cwd) => inferPackageManager(cwd) ?? installedPack
159
159
  * as {@link resolvePackageManager} minus the lockfile walk.
160
160
  */
161
161
  const resolveInvokingPackageManager = () => detectInvokingPackageManager() ?? installedPackageManagers()[0] ?? "npm";
162
+ /** How the CLI file at `path` was installed globally, or undefined when it can't be told. */
163
+ const detectCliInstallMethod = (path) => {
164
+ const normalized = path.replace(/\\/g, "/").toLowerCase();
165
+ if (normalized.includes("/cellar/neonctl/")) return "homebrew";
166
+ if (normalized.includes("/.bun/install/global/node_modules/neon/")) return "bun";
167
+ if (normalized.includes("/pnpm/global/") && normalized.includes("/.pnpm/neon@") && normalized.includes("/node_modules/neon/")) return "pnpm";
168
+ if (normalized.includes("/lib/node_modules/neon/") || normalized.includes("/npm/node_modules/neon/")) return "npm";
169
+ };
170
+ const CLI_UPGRADE_COMMANDS = {
171
+ homebrew: "brew upgrade neonctl",
172
+ bun: "bun i -g neon@latest",
173
+ pnpm: "pnpm i -g neon@latest",
174
+ npm: "npm i -g neon@latest"
175
+ };
162
176
  const recommendedCliUpgradeCommand = (modulePath) => {
163
- const path = modulePath.replace(/\\/g, "/").toLowerCase();
164
- if (path.includes("/cellar/neonctl/")) return "brew upgrade neonctl";
165
- if (path.includes("/.bun/install/global/node_modules/neon/")) return "bun i -g neon@latest";
166
- if (path.includes("/pnpm/global/") && path.includes("/.pnpm/neon@") && path.includes("/node_modules/neon/")) return "pnpm i -g neon@latest";
167
- if (path.includes("/lib/node_modules/neon/") || path.includes("/npm/node_modules/neon/")) return "npm i -g neon@latest";
177
+ const method = detectCliInstallMethod(modulePath);
178
+ return method === void 0 ? void 0 : CLI_UPGRADE_COMMANDS[method];
168
179
  };
169
180
  /**
170
181
  * The argv for an install with `pm`: every dependency in the manifest when
@@ -333,4 +344,4 @@ const runCommand = (cmd, args, cwd, env) => new Promise((resolvePromise) => {
333
344
  });
334
345
  });
335
346
  //#endregion
336
- export { DO_NOT_SUBSTITUTE_HINT, MISSING_BINARY_HINT, commandEnv, detectInvokingPackageManager, detectProjectPackageManager, formatExecCommand, formatInstallCommand, globalInstallCommand, inferPackageManager, installArgs, installedPackageManagers, recommendedCliUpgradeCommand, resolveInvokingPackageManager, resolvePackageManager, runCommand };
347
+ export { DO_NOT_SUBSTITUTE_HINT, MISSING_BINARY_HINT, commandEnv, detectCliInstallMethod, detectInvokingPackageManager, detectProjectPackageManager, formatExecCommand, formatInstallCommand, globalInstallCommand, inferPackageManager, installArgs, installedPackageManagers, recommendedCliUpgradeCommand, resolveInvokingPackageManager, resolvePackageManager, runCommand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -65,8 +65,8 @@
65
65
  "yargs": "17.7.2",
66
66
  "yoctocolors": "^2.1.2",
67
67
  "@neon/config": "1.8.3",
68
- "@neon/config-runtime": "1.7.3",
69
- "@neon/sdk": "7.0.0"
68
+ "@neon/sdk": "7.0.0",
69
+ "@neon/config-runtime": "1.7.3"
70
70
  },
71
71
  "optionalDependencies": {
72
72
  "@napi-rs/keyring": "1.3.0",
@@ -99,9 +99,9 @@
99
99
  "tsx": "4.22.3",
100
100
  "typescript": "^5.9.0",
101
101
  "vitest": "^3.0.9",
102
+ "@neon-internals/cli-core": "0.0.0",
102
103
  "@neon-internals/env-core": "0.0.26",
103
104
  "@neon/e2e-harness": "0.0.0",
104
- "@neon-internals/cli-core": "0.0.0",
105
105
  "@neon/functions": "0.11.0"
106
106
  },
107
107
  "publishConfig": {