neon 3.1.1 → 3.2.1

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
@@ -352,6 +352,19 @@ How today's `set-context` uses map onto `link`:
352
352
 
353
353
  The key difference: `link` resolves and **verifies** before writing (so you never get a half-written or stale `.neon`), whereas `set-context` writes whatever you give it verbatim. The closest like-for-like replacement for the old raw write is `link --no-checks`.
354
354
 
355
+ ### open
356
+
357
+ `open` launches the linked project's page in the Neon Console. It reads the closest `.neon` file without authenticating or calling the Neon API, so it works from any sub-directory of a linked project.
358
+
359
+ ```bash
360
+ neon open
361
+
362
+ # Open a project without changing the linked context
363
+ neon open --project-id polished-snowflake-12345678
364
+ ```
365
+
366
+ A branch pinned in `.neon` does not change the destination. `.neon` stores the branch as a name, while the Console route requires its ID; resolving it would turn this local command into an authenticated API call.
367
+
355
368
  ### checkout
356
369
 
357
370
  `checkout [id|name]` pins a branch in the local context so subsequent commands target it — it's the focused companion to `link` for the common "switch the branch I'm working on" case (`link` resolves org + project; `checkout` pins the branch). It resolves the branch (by name or id) against the project, then **heals** the `.neon` file: it always (re)writes `projectId`, `branch`, and `orgId` (when the project has one), so a `.neon` that was missing fields or drifted ends up complete and consistent. The branch is stored as its **name** when known (matching `link`). When `orgId` isn't already known (from `--org-id` or the existing `.neon`), it's looked up from the project itself.
@@ -1044,6 +1057,7 @@ API keys in org-7
1044
1057
  | checkout | | Pin a branch in `.neon` |
1045
1058
  | diff | | Git-style schema diff vs a branch |
1046
1059
  | [link](https://neon.com/docs/reference/cli-link) | | Link a directory to a project |
1060
+ | open | | Open the linked project in Console |
1047
1061
  | config | `init`, `status`, `plan`, `apply` | Drive a branch from `neon.ts` |
1048
1062
  | deploy | | Alias for `config apply` |
1049
1063
  | bootstrap | | Scaffold a project from a template |
@@ -174,6 +174,7 @@ const ensureAuth = async (props) => {
174
174
  if (isCurrentBranchProbe(props)) return;
175
175
  if (isConfigInit(props)) return;
176
176
  if (isProfileCommand(props)) return;
177
+ if (props._[0] === "open") return;
177
178
  const isLocalDev = props._[0] === "dev";
178
179
  const isBootstrap = props._[0] === "bootstrap";
179
180
  const isInit = props._[0] === "init";
@@ -21,6 +21,7 @@ import { t as inspect_exports } from "./inspect.js";
21
21
  import { t as ip_allow_exports } from "./ip_allow.js";
22
22
  import { t as logs_exports } from "./logs.js";
23
23
  import { t as neon_auth_exports } from "./neon_auth.js";
24
+ import { t as open_exports } from "./open.js";
24
25
  import { t as operations_exports } from "./operations.js";
25
26
  import { t as orgs_exports } from "./orgs.js";
26
27
  import { t as profile_exports } from "./profile.js";
@@ -55,6 +56,7 @@ var commands_default = [
55
56
  set_context_exports,
56
57
  checkout_exports,
57
58
  link_exports,
59
+ open_exports,
58
60
  init_exports,
59
61
  data_api_exports,
60
62
  functions_exports,
@@ -0,0 +1,33 @@
1
+ import { t as __exportAll } from "../_chunks/rolldown-runtime-D7D4PA-g.js";
2
+ import { log } from "../log.js";
3
+ import { getCliName } from "../utils/cli_name.js";
4
+ import open from "open";
5
+ //#region src/commands/open.ts
6
+ var open_exports = /* @__PURE__ */ __exportAll({
7
+ builder: () => builder,
8
+ command: () => command,
9
+ describe: () => describe,
10
+ handler: () => handler,
11
+ projectConsoleUrl: () => projectConsoleUrl
12
+ });
13
+ const command = "open";
14
+ const describe = "Open the linked project in the Neon Console";
15
+ const builder = (argv) => argv.usage("$0 open [options]").option("project-id", {
16
+ describe: "Project ID (defaults to the project linked in .neon)",
17
+ type: "string"
18
+ }).example("$0 open", describe);
19
+ const projectConsoleUrl = (projectId) => `https://console.neon.tech/app/projects/${encodeURIComponent(projectId)}`;
20
+ const handler = async (props) => {
21
+ if (!props.projectId) throw new Error(`No Neon project linked. Run \`${getCliName()} link\` to link this directory to a project.`);
22
+ const url = projectConsoleUrl(props.projectId);
23
+ log.info("Opening %s in your browser.", url);
24
+ const subprocess = await open(url);
25
+ await new Promise((resolve, reject) => {
26
+ subprocess.once("spawn", resolve);
27
+ subprocess.once("error", (error) => {
28
+ reject(/* @__PURE__ */ new Error(`Failed to open the Neon Console in your browser. Open ${url} manually. ${error.message}`));
29
+ });
30
+ });
31
+ };
32
+ //#endregion
33
+ export { builder, command, describe, handler, projectConsoleUrl, open_exports as t };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ const NO_SUBCOMMANDS_VERBS = [
27
27
  "set-context",
28
28
  "checkout",
29
29
  "link",
30
+ "open",
30
31
  "init",
31
32
  "dev",
32
33
  "deploy",
package/dist/init/auth.js CHANGED
@@ -5,7 +5,7 @@ import { log } from "@clack/prompts";
5
5
  import { execa } from "execa";
6
6
  //#region src/init/auth.ts
7
7
  /**
8
- * Ensures neonctl is authenticated by running a command that triggers auth if needed
8
+ * Ensures the Neon CLI is authenticated by running a command that triggers auth if needed
9
9
  * This will automatically start the OAuth flow if the user isn't already authenticated
10
10
  */
11
11
  async function ensureNeonctlAuth(options) {
@@ -14,7 +14,7 @@ async function ensureNeonctlAuth(options) {
14
14
  try {
15
15
  await execa("npx", [
16
16
  "-y",
17
- "neonctl",
17
+ "neon",
18
18
  "me"
19
19
  ], {
20
20
  stdio: "inherit",
@@ -32,7 +32,7 @@ async function ensureNeonctlAuth(options) {
32
32
  }
33
33
  }
34
34
  /**
35
- * Checks whether neonctl has stored OAuth credentials.
35
+ * Checks whether the Neon CLI has stored OAuth credentials.
36
36
  */
37
37
  async function isAuthenticated() {
38
38
  return await getNeonctlAccessToken() !== null;
@@ -3,12 +3,14 @@ import { lstatSync } from "node:fs";
3
3
  import { execa } from "execa";
4
4
  //#region src/init/neonctl.ts
5
5
  /**
6
- * Returns the Neon CLI command prefix: "CI= npx -y neon".
6
+ * Returns the Neon CLI command prefix emitted to users and agents:
7
+ * `CI= npx -y neon`.
7
8
  *
8
9
  * The CLI reads NEON_API_HOST and NEON_OAUTH_HOST from the environment
9
- * directly, so no extra flags are needed. The `neon` package ships both the
10
- * `neon` and `neonctl` binaries; we surface the cleaner `neon` command in the
11
- * examples emitted to users and agents.
10
+ * directly, so no extra flags are needed. The published package is `neon`
11
+ * (its binary is `neon`; the older `neonctl` alias is no longer shipped). `npx`
12
+ * runs it with zero global-install assumptions, and the leading `CI=` keeps the
13
+ * CLI non-interactive.
12
14
  *
13
15
  * Usage: `${neonctlCmd()} orgs list --output json`
14
16
  */
@@ -16,12 +18,19 @@ function neonctlCmd() {
16
18
  return "CI= npx -y neon";
17
19
  }
18
20
  /**
19
- * Gets the currently available neonctl version.
20
- * Tries the global binary first, then falls back to npx.
21
+ * The global binaries that indicate the Neon CLI is installed. The current
22
+ * package ships `neon`; `neonctl` is the legacy alias, kept in the probe so an
23
+ * older global install still counts as "installed" (and isn't reinstalled).
21
24
  */
22
- async function getNeonctlVersion() {
23
- try {
24
- const match = (await execa("neonctl", ["--version"], {
25
+ const NEON_CLI_BINARIES = ["neon", "neonctl"];
26
+ /**
27
+ * Gets the currently installed Neon CLI version, probing the `neon` binary
28
+ * first and falling back to the legacy `neonctl` alias. Returns null when the
29
+ * CLI isn't on PATH.
30
+ */
31
+ async function getNeonCliVersion() {
32
+ for (const bin of NEON_CLI_BINARIES) try {
33
+ const match = (await execa(bin, ["--version"], {
25
34
  stdio: "pipe",
26
35
  timeout: 5e3
27
36
  })).stdout.trim().match(/(\d+\.\d+\.\d+)/);
@@ -30,10 +39,10 @@ async function getNeonctlVersion() {
30
39
  return null;
31
40
  }
32
41
  /**
33
- * Checks whether the neonctl CLI is globally installed and whether it's up to date.
42
+ * Checks whether the Neon CLI is globally installed and whether it's up to date.
34
43
  */
35
44
  async function checkNeonctl() {
36
- const currentVersion = await getNeonctlVersion();
45
+ const currentVersion = await getNeonCliVersion();
37
46
  if (!currentVersion) return {
38
47
  installed: false,
39
48
  currentVersion: null,
@@ -44,7 +53,7 @@ async function checkNeonctl() {
44
53
  try {
45
54
  latestVersion = (await execa("npm", [
46
55
  "view",
47
- "neonctl",
56
+ "neon",
48
57
  "version"
49
58
  ], {
50
59
  stdio: "pipe",
@@ -82,9 +91,9 @@ function isOlderVersion(current, latest) {
82
91
  function isLocalDevSymlink() {
83
92
  try {
84
93
  const home = process.env.HOME || process.env.USERPROFILE || "";
85
- const candidates = [`${process.env.NVM_DIR || `${home}/.nvm`}/versions/node/${process.version}/lib/node_modules/neonctl`, `${home}/.nvm/versions/node/${process.version}/lib/node_modules/neonctl`];
86
- for (const candidate of candidates) try {
87
- if (lstatSync(candidate).isSymbolicLink()) return true;
94
+ const roots = [`${process.env.NVM_DIR || `${home}/.nvm`}/versions/node/${process.version}/lib/node_modules`, `${home}/.nvm/versions/node/${process.version}/lib/node_modules`];
95
+ for (const root of roots) for (const pkg of NEON_CLI_BINARIES) try {
96
+ if (lstatSync(`${root}/${pkg}`).isSymbolicLink()) return true;
88
97
  } catch {}
89
98
  return false;
90
99
  } catch {
@@ -98,7 +107,7 @@ function isLocalDevSymlink() {
98
107
  async function ensureNeonctl() {
99
108
  if (isLocalDevSymlink()) return {
100
109
  status: "already_current",
101
- version: await getNeonctlVersion() ?? "dev"
110
+ version: await getNeonCliVersion() ?? "dev"
102
111
  };
103
112
  const check = await checkNeonctl();
104
113
  if (check.installed && !check.needsUpdate) return {
@@ -106,7 +115,7 @@ async function ensureNeonctl() {
106
115
  version: check.currentVersion ?? void 0
107
116
  };
108
117
  const pm = resolveInvokingPackageManager();
109
- const install = globalInstallCommand(pm, "neonctl");
118
+ const install = globalInstallCommand(pm, "neon");
110
119
  if (!install) return {
111
120
  status: "failed",
112
121
  error: "Could not install the Neon CLI: this machine has no package manager that can perform a global install. npm, pnpm and bun are not on PATH (yarn Berry has no global install). Install npm, pnpm or bun, then run this again."
@@ -117,7 +126,7 @@ async function ensureNeonctl() {
117
126
  stdio: "pipe",
118
127
  timeout: 6e4
119
128
  });
120
- const version = await getNeonctlVersion();
129
+ const version = await getNeonCliVersion();
121
130
  return {
122
131
  status: check.installed ? "updated" : "installed",
123
132
  version: version ?? void 0
@@ -30,7 +30,7 @@ function extractNeonHost(cwd) {
30
30
  *
31
31
  * Strategy:
32
32
  * 1. Extract endpoint hostname from .env
33
- * 2. List orgs via neonctl
33
+ * 2. List orgs via the Neon CLI
34
34
  * 3. For each org, list projects
35
35
  * 4. For each project, get connection string and compare hostnames
36
36
  * 5. Return the matching org/project
@@ -42,7 +42,7 @@ async function resolveNeonContext(cwd) {
42
42
  try {
43
43
  const result = await execa("npx", [
44
44
  "-y",
45
- "neonctl",
45
+ "neon",
46
46
  "orgs",
47
47
  "list",
48
48
  "--output",
@@ -65,7 +65,7 @@ async function resolveNeonContext(cwd) {
65
65
  try {
66
66
  const result = await execa("npx", [
67
67
  "-y",
68
- "neonctl",
68
+ "neon",
69
69
  "projects",
70
70
  "list",
71
71
  "--org-id",
@@ -87,7 +87,7 @@ async function resolveNeonContext(cwd) {
87
87
  for (const project of projects) try {
88
88
  if ((await execa("npx", [
89
89
  "-y",
90
- "neonctl",
90
+ "neon",
91
91
  "connection-string",
92
92
  "--project-id",
93
93
  project.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -63,9 +63,9 @@
63
63
  "yaml": "^2.9.0",
64
64
  "yargs": "17.7.2",
65
65
  "yoctocolors": "^2.1.2",
66
- "@neon/sdk": "2.0.0",
67
66
  "@neon/config": "1.0.0",
68
- "@neon/config-runtime": "1.0.0"
67
+ "@neon/config-runtime": "1.0.0",
68
+ "@neon/sdk": "2.0.0"
69
69
  },
70
70
  "optionalDependencies": {
71
71
  "esbuild": "0.28.1"