@alejandrochaves/devflow-cli 1.8.0 → 1.9.0

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/git.js CHANGED
@@ -1,7 +1,44 @@
1
- import { execSync } from "child_process";
1
+ import { execFileSync } from "child_process";
2
2
  const PROTECTED_BRANCHES = ["main", "master", "develop", "production"];
3
+ /** Refs read from git can still be named like options (a tag "--output=x"); never pass those as arguments. */
4
+ export function isOptionLike(ref) {
5
+ return ref.startsWith("-");
6
+ }
7
+ /**
8
+ * The commit a user- or config-provided revision (a PR base, a tag) names, as an object id, so it can
9
+ * be put in a range without git reading it as an option. undefined when it names no commit.
10
+ */
11
+ export function resolveCommit(rev) {
12
+ if (!rev || isOptionLike(rev))
13
+ return undefined;
14
+ try {
15
+ // No --end-of-options (older gits lack it for rev-parse): a leading "-" is refused above, and the
16
+ // ^{commit} suffix keeps the argument a revision.
17
+ return execFileSync("git", ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`], {
18
+ encoding: "utf-8",
19
+ stdio: ["ignore", "pipe", "ignore"],
20
+ }).trim() || undefined;
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ }
26
+ /** Throws unless `name` is a valid branch name that git cannot read as an option. */
27
+ export function assertBranchName(name) {
28
+ let valid = !isOptionLike(name);
29
+ if (valid) {
30
+ try {
31
+ execFileSync("git", ["check-ref-format", "--branch", name], { stdio: "ignore" });
32
+ }
33
+ catch {
34
+ valid = false;
35
+ }
36
+ }
37
+ if (!valid)
38
+ throw new Error(`Invalid branch name: ${JSON.stringify(name)}. Check the ticket, type and branchFormat.`);
39
+ }
3
40
  export function getBranch() {
4
- return execSync("git branch --show-current", { encoding: "utf-8" }).trim();
41
+ return execFileSync("git", ["branch", "--show-current"], { encoding: "utf-8" }).trim();
5
42
  }
6
43
  export function parseBranch(branch, format) {
7
44
  // Default format for backwards compatibility
@@ -51,7 +88,7 @@ export function inferTicket(format) {
51
88
  }
52
89
  export function inferScope() {
53
90
  try {
54
- const log = execSync("git log main..HEAD --format=%s", {
91
+ const log = execFileSync("git", ["log", "main..HEAD", "--format=%s"], {
55
92
  encoding: "utf-8",
56
93
  }).trim();
57
94
  if (!log)
@@ -69,8 +106,11 @@ export function inferScope() {
69
106
  return undefined;
70
107
  }
71
108
  export function getCommits(base) {
109
+ const baseId = resolveCommit(base);
110
+ if (!baseId)
111
+ return [];
72
112
  try {
73
- const log = execSync(`git log ${base}..HEAD --format=%s`, { encoding: "utf-8" }).trim();
113
+ const log = execFileSync("git", ["log", `${baseId}..HEAD`, "--format=%s"], { encoding: "utf-8" }).trim();
74
114
  return log ? log.split("\n") : [];
75
115
  }
76
116
  catch {
@@ -88,19 +128,19 @@ export function getScopesFromCommits(commits) {
88
128
  }
89
129
  export function getDefaultBase(currentBranch) {
90
130
  try {
91
- const remoteBranches = execSync("git branch -r", { encoding: "utf-8" })
131
+ const remoteBranches = execFileSync("git", ["branch", "-r"], { encoding: "utf-8" })
92
132
  .trim()
93
133
  .split("\n")
94
134
  .map((b) => b.trim())
95
- .filter((b) => b && !b.includes("HEAD") && !b.endsWith(`/${currentBranch}`));
135
+ .filter((b) => b && !b.includes("HEAD") && !b.endsWith(`/${currentBranch}`) && !isOptionLike(b.replace(/^origin\//, "")));
96
136
  let closest = "main";
97
137
  let minAhead = Infinity;
98
138
  for (const remote of remoteBranches) {
99
139
  try {
100
- const mergeBase = execSync(`git merge-base HEAD ${remote}`, {
140
+ const mergeBase = execFileSync("git", ["merge-base", "HEAD", remote], {
101
141
  encoding: "utf-8",
102
142
  }).trim();
103
- const ahead = execSync(`git rev-list --count ${mergeBase}..HEAD`, {
143
+ const ahead = execFileSync("git", ["rev-list", "--count", `${mergeBase}..HEAD`], {
104
144
  encoding: "utf-8",
105
145
  }).trim();
106
146
  const count = parseInt(ahead, 10);
@@ -121,16 +161,19 @@ export function getDefaultBase(currentBranch) {
121
161
  }
122
162
  export function getRepoDefaultBranch() {
123
163
  try {
124
- const ref = execSync("git symbolic-ref refs/remotes/origin/HEAD", {
164
+ const ref = execFileSync("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], {
125
165
  encoding: "utf-8",
126
166
  stdio: ["pipe", "pipe", "ignore"],
127
167
  }).trim();
128
- return ref.replace(/^refs\/remotes\/origin\//, "");
168
+ const name = ref.replace(/^refs\/remotes\/origin\//, "");
169
+ if (isOptionLike(name))
170
+ throw new Error("option-like default branch");
171
+ return name;
129
172
  }
130
173
  catch {
131
174
  for (const candidate of ["main", "master", "trunk", "develop"]) {
132
175
  try {
133
- execSync(`git rev-parse --verify ${candidate}`, { stdio: "ignore" });
176
+ execFileSync("git", ["rev-parse", "--verify", candidate], { stdio: "ignore" });
134
177
  return candidate;
135
178
  }
136
179
  catch {
@@ -142,7 +185,7 @@ export function getRepoDefaultBranch() {
142
185
  }
143
186
  export function isGhInstalled() {
144
187
  try {
145
- execSync("gh --version", { stdio: "ignore" });
188
+ execFileSync("gh", ["--version"], { stdio: "ignore" });
146
189
  return true;
147
190
  }
148
191
  catch {
@@ -151,7 +194,7 @@ export function isGhInstalled() {
151
194
  }
152
195
  export function checkGhInstalled() {
153
196
  try {
154
- execSync("gh --version", { stdio: "ignore" });
197
+ execFileSync("gh", ["--version"], { stdio: "ignore" });
155
198
  }
156
199
  catch {
157
200
  console.error("Error: GitHub CLI (gh) is not installed.");
package/dist/index.js CHANGED
@@ -262,8 +262,10 @@ program
262
262
  console.log(generateZshCompletions());
263
263
  }
264
264
  });
265
- // Load plugins before parsing
266
- await loadPlugins(program);
265
+ // Load plugins before parsing. Completions output is eval'd by shells: never prompt or load there.
266
+ if (args[0] !== "completions") {
267
+ await loadPlugins(program);
268
+ }
267
269
  program.parse();
268
270
  function generateBashCompletions() {
269
271
  return `# devflow bash completions
package/dist/plugins.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  import { Command } from "commander";
2
+ /** Records the user's decision for this checkout and what these plugins resolve to now, outside the repo. */
3
+ export declare function setPluginTrust(cwd: string, plugins: string[], trusted: boolean): void;
4
+ /**
5
+ * Loads plugins named by the repo's package.json and .devflow/config.json. Both files come from the
6
+ * checked-out repo, so nothing is imported until the user has trusted this checkout and exactly what
7
+ * the plugins resolve to. The decision is asked once, interactively; non-interactive runs never trust
8
+ * on their own. A plugin whose package or entry file leaves the repo's node_modules is never loaded.
9
+ */
2
10
  export declare function loadPlugins(program: Command, cwd?: string): Promise<void>;
package/dist/plugins.js CHANGED
@@ -1,7 +1,13 @@
1
- import { existsSync, readFileSync } from "fs";
2
- import { resolve } from "path";
1
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, writeFileSync } from "fs";
2
+ import { isAbsolute, join, relative, resolve } from "path";
3
+ import { execFileSync } from "child_process";
4
+ import { homedir } from "os";
5
+ import { createHash } from "crypto";
6
+ import { confirm } from "@inquirer/prompts";
3
7
  import { yellow } from "./colors.js";
4
8
  const PLUGIN_PREFIX = "devflow-plugin-";
9
+ // npm package names only: no paths, so a plugin always resolves inside <repo>/node_modules.
10
+ const PACKAGE_NAME = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
5
11
  function findPlugins(cwd) {
6
12
  const plugins = [];
7
13
  // Check package.json for devflow plugins in dependencies
@@ -42,27 +48,226 @@ function findPlugins(cwd) {
42
48
  }
43
49
  return plugins;
44
50
  }
51
+ function trustStorePath() {
52
+ return resolve(homedir(), ".devflow", "trusted-plugins.json");
53
+ }
54
+ function readTrustStore() {
55
+ try {
56
+ return JSON.parse(readFileSync(trustStorePath(), "utf-8"));
57
+ }
58
+ catch {
59
+ return {};
60
+ }
61
+ }
62
+ const sha256 = (data) => createHash("sha256").update(data).digest("hex");
63
+ class LinksOutside extends Error {
64
+ }
65
+ /**
66
+ * Every file of a package (path and content, symlinks by their target), in a stable order. Nested
67
+ * node_modules are not hashed, only checked for links; dependencies installed next to the plugin
68
+ * (hoisted) are not covered here. A symlink anywhere in the package, nested node_modules included, must
69
+ * resolve inside it: one into the workspace would let a checkout change the code it points at without
70
+ * changing the hash (throws LinksOutside).
71
+ * Throws when anything can't be read, so the plugin is treated as unreadable rather than half-hashed.
72
+ */
73
+ function hashPackageDir(dir) {
74
+ const hash = createHash("sha256");
75
+ const walk = (rel, hashed) => {
76
+ const names = readdirSync(join(dir, rel)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
77
+ for (const name of names) {
78
+ const path = rel ? `${rel}/${name}` : name;
79
+ const stat = lstatSync(join(dir, path));
80
+ if (stat.isSymbolicLink()) {
81
+ if (!isInside(realpathSync(join(dir, path)), dir))
82
+ throw new LinksOutside();
83
+ if (hashed)
84
+ hash.update(`link\0${path}\0${readlinkSync(join(dir, path))}\0`);
85
+ }
86
+ else if (stat.isDirectory()) {
87
+ walk(path, hashed && name !== "node_modules");
88
+ }
89
+ else if (!hashed) {
90
+ continue;
91
+ }
92
+ else if (stat.isFile()) {
93
+ const content = readFileSync(join(dir, path));
94
+ hash.update(`file\0${path}\0${content.length}\0`).update(content);
95
+ }
96
+ else {
97
+ hash.update(`other\0${path}\0`);
98
+ }
99
+ }
100
+ };
101
+ walk("", true);
102
+ return hash.digest("hex");
103
+ }
104
+ function isInside(child, parent) {
105
+ const rel = relative(parent, child);
106
+ return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
107
+ }
108
+ function resolvePlugin(cwd, name) {
109
+ const linkPath = resolve(cwd, "node_modules", name);
110
+ if (!existsSync(linkPath))
111
+ return { name, problem: "not installed" };
112
+ try {
113
+ const dir = realpathSync(linkPath);
114
+ if (!isInside(dir, realpathSync(resolve(cwd, "node_modules")))) {
115
+ return { name, dir, problem: "resolves outside node_modules" };
116
+ }
117
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
118
+ const exported = pkg.exports?.["."];
119
+ const main = typeof pkg.main === "string" ? pkg.main : typeof exported === "string" ? exported : "index.js";
120
+ const entry = realpathSync(resolve(dir, main));
121
+ if (!isInside(entry, dir))
122
+ return { name, dir, problem: "entry file is outside the package" };
123
+ return {
124
+ name,
125
+ dir,
126
+ packageName: pkg.name,
127
+ version: pkg.version,
128
+ entry,
129
+ // The entry may sit in the package's own node_modules, which the directory hash skips
130
+ entrySha256: sha256(readFileSync(entry)),
131
+ dirSha256: hashPackageDir(dir),
132
+ };
133
+ }
134
+ catch (err) {
135
+ return { name, problem: err instanceof LinksOutside ? "links outside the package" : "unreadable" };
136
+ }
137
+ }
138
+ function gitOutput(cwd, args) {
139
+ try {
140
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
141
+ }
142
+ catch {
143
+ return "";
144
+ }
145
+ }
146
+ /**
147
+ * What git tracks under any node_modules (or as a node_modules entry itself, such as a symlink): "" when
148
+ * nothing, undefined when it can't tell. `git checkout` overwrites ignored files with tracked ones, so a
149
+ * branch that tracks files there swaps installed plugin code (or its dependencies) without asking.
150
+ */
151
+ function trackedNodeModules(cwd) {
152
+ if (gitOutput(cwd, ["rev-parse", "--is-inside-work-tree"]) !== "true")
153
+ return "";
154
+ try {
155
+ return execFileSync("git", ["ls-files", "-s", "--", ":(top,glob,icase)**/node_modules/**", ":(top,glob,icase)**/node_modules"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
156
+ }
157
+ catch {
158
+ return undefined;
159
+ }
160
+ }
161
+ /** Repo-controlled text (package version, paths) is shown in the trust prompt only as printable text. */
162
+ const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
163
+ const printable = (value) => String(value).replace(/[\p{Cc}\p{Cf}\u2028\u2029]/gu, "?");
164
+ const displayVersion = (version) => typeof version === "string" && SEMVER.test(version) ? version : `(invalid version ${JSON.stringify(printable(version).slice(0, 40))})`;
165
+ /**
166
+ * Everything the user's decision is about: this checkout (path, first root commit, origin, what it tracks under
167
+ * node_modules) and, in order, what each plugin resolves to (directory, package name and version, entry file,
168
+ * and the hashes of the entry and of the whole package). Any change asks again.
169
+ */
170
+ function trustKey(cwd, plugins) {
171
+ const checkout = {
172
+ path: realpathSync(cwd),
173
+ rootCommit: gitOutput(cwd, ["rev-list", "--max-parents=0", "HEAD"]).split("\n")[0],
174
+ origin: gitOutput(cwd, ["config", "--get", "remote.origin.url"]),
175
+ trackedNodeModules: sha256(trackedNodeModules(cwd) ?? "unknown"),
176
+ };
177
+ return sha256(JSON.stringify({
178
+ checkout,
179
+ plugins: plugins.map(({ name, dir, packageName, version, entry, entrySha256, dirSha256, problem }) => ({
180
+ name, dir, packageName, version, entry, entrySha256, dirSha256, problem,
181
+ })),
182
+ }));
183
+ }
184
+ function recordTrust(cwd, key, trusted) {
185
+ const store = readTrustStore();
186
+ store[realpathSync(cwd)] = { key, trusted };
187
+ mkdirSync(resolve(homedir(), ".devflow"), { recursive: true });
188
+ writeFileSync(trustStorePath(), JSON.stringify(store, null, 2));
189
+ }
190
+ /** Records the user's decision for this checkout and what these plugins resolve to now, outside the repo. */
191
+ export function setPluginTrust(cwd, plugins, trusted) {
192
+ recordTrust(cwd, trustKey(cwd, plugins.map((name) => resolvePlugin(cwd, name))), trusted);
193
+ }
194
+ /** true/false when the user decided on exactly this checkout and these resolved plugins, undefined otherwise. */
195
+ function getPluginTrust(cwd, key) {
196
+ const entry = readTrustStore()[realpathSync(cwd)];
197
+ if (!entry || entry.key !== key)
198
+ return undefined;
199
+ return entry.trusted === true;
200
+ }
201
+ function isInteractive() {
202
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY) && !process.env.CI;
203
+ }
204
+ /**
205
+ * Loads plugins named by the repo's package.json and .devflow/config.json. Both files come from the
206
+ * checked-out repo, so nothing is imported until the user has trusted this checkout and exactly what
207
+ * the plugins resolve to. The decision is asked once, interactively; non-interactive runs never trust
208
+ * on their own. A plugin whose package or entry file leaves the repo's node_modules is never loaded.
209
+ */
45
210
  export async function loadPlugins(program, cwd = process.cwd()) {
46
- const plugins = findPlugins(cwd);
47
- for (const pluginName of plugins) {
211
+ const names = [];
212
+ for (const name of findPlugins(cwd)) {
213
+ if (typeof name === "string" && PACKAGE_NAME.test(name)) {
214
+ names.push(name);
215
+ }
216
+ else {
217
+ console.error(yellow(`⚠ Ignoring plugin ${JSON.stringify(name)}: plugins must be npm package names.`));
218
+ }
219
+ }
220
+ if (names.length === 0)
221
+ return;
222
+ const resolved = names.map((name) => resolvePlugin(cwd, name));
223
+ for (const p of resolved) {
224
+ if (p.problem && p.problem !== "not installed") {
225
+ console.error(yellow(`⚠ Not loading plugin ${p.name}: ${p.problem}${p.dir ? ` (${printable(p.dir)})` : ""}.`));
226
+ }
227
+ }
228
+ const loadable = resolved.filter((p) => !p.problem);
229
+ if (loadable.length === 0)
230
+ return;
231
+ const tracked = trackedNodeModules(cwd);
232
+ if (tracked !== "") {
233
+ console.error(yellow(`⚠ Plugins not loaded: ${tracked === undefined
234
+ ? "could not check what git tracks under node_modules"
235
+ : "git tracks files under node_modules in this repository, so a checkout can replace installed plugin code"}. Untrack them (git rm -r --cached <path>/node_modules) to use plugins: ${loadable.map((p) => p.name).join(", ")}.`));
236
+ return;
237
+ }
238
+ const key = trustKey(cwd, resolved);
239
+ let trusted = getPluginTrust(cwd, key);
240
+ if (trusted === undefined && isInteractive()) {
48
241
  try {
49
- // Try to resolve the plugin from node_modules
50
- const pluginPath = resolve(cwd, "node_modules", pluginName);
51
- if (!existsSync(pluginPath))
52
- continue;
53
- const pkgJson = resolve(pluginPath, "package.json");
54
- if (!existsSync(pkgJson))
55
- continue;
56
- const pkg = JSON.parse(readFileSync(pkgJson, "utf-8"));
57
- const mainFile = pkg.main || pkg.exports?.["."] || "index.js";
58
- const entryPoint = resolve(pluginPath, mainFile);
59
- const mod = await import(entryPoint);
242
+ trusted = await confirm({
243
+ message: `This repository asks devflow to load plugins, which run code on your machine:\n ${loadable
244
+ .map((p) => `${p.name}@${displayVersion(p.version)} (${printable(p.dir)})`)
245
+ .join("\n ")}\nTrust these plugins for ${printable(cwd)}?`,
246
+ default: false,
247
+ });
248
+ recordTrust(cwd, key, trusted);
249
+ }
250
+ catch {
251
+ trusted = false;
252
+ }
253
+ }
254
+ if (trusted === false)
255
+ return; // declined earlier for exactly this checkout and these plugins
256
+ if (trusted === undefined) {
257
+ console.error(yellow(`⚠ Plugins not loaded (not trusted for this repository): ${loadable.map((p) => p.name).join(", ")}.`) +
258
+ (isInteractive() ? "" : " Run devflow in a terminal to review them."));
259
+ return;
260
+ }
261
+ for (const plugin of loadable) {
262
+ try {
263
+ // The same file that was hashed into the trust key
264
+ const mod = await import(plugin.entry);
60
265
  if (typeof mod.register === "function") {
61
266
  mod.register(program);
62
267
  }
63
268
  }
64
- catch (err) {
65
- console.error(yellow(`⚠ Failed to load plugin: ${pluginName}`));
269
+ catch {
270
+ console.error(yellow(`⚠ Failed to load plugin: ${plugin.name}`));
66
271
  }
67
272
  }
68
273
  }
@@ -1,4 +1,4 @@
1
- import { execSync, execFileSync } from "child_process";
1
+ import { execFileSync } from "child_process";
2
2
  import { yellow } from "../colors.js";
3
3
  function executeGraphQL(query) {
4
4
  try {
@@ -14,7 +14,7 @@ function executeGraphQL(query) {
14
14
  }
15
15
  export function getRepoInfo() {
16
16
  try {
17
- const result = execSync("gh repo view --json owner,name,isInOrganization", {
17
+ const result = execFileSync("gh", ["repo", "view", "--json", "owner,name,isInOrganization"], {
18
18
  encoding: "utf-8",
19
19
  stdio: ["pipe", "pipe", "pipe"],
20
20
  }).trim();
@@ -31,7 +31,7 @@ export function getRepoInfo() {
31
31
  }
32
32
  export function getCurrentUser() {
33
33
  try {
34
- const result = execSync("gh api user --jq '.login'", {
34
+ const result = execFileSync("gh", ["api", "user", "--jq", ".login"], {
35
35
  encoding: "utf-8",
36
36
  stdio: ["pipe", "pipe", "pipe"],
37
37
  }).trim();
@@ -1,4 +1,4 @@
1
- import { execSync } from "child_process";
1
+ import { execFileSync } from "child_process";
2
2
  import { yellow } from "../colors.js";
3
3
  // Maps GitHub issue labels to branch types
4
4
  export const LABEL_TO_BRANCH_TYPE = {
@@ -30,9 +30,7 @@ export function inferBranchTypeFromLabels(labels) {
30
30
  export class GitHubTicketProvider {
31
31
  listOpen(options) {
32
32
  try {
33
- const assigneeArg = options?.assignee ? `--assignee ${options.assignee}` : "--assignee @me";
34
- const cmd = `gh issue list ${assigneeArg} --state open --json number,title,labels,url,body --limit 50`;
35
- const output = execSync(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
33
+ const output = execFileSync("gh", ["issue", "list", `--assignee=${options?.assignee ?? "@me"}`, "--state", "open", "--json", "number,title,labels,url,body", "--limit", "50"], { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36
34
  const issues = JSON.parse(output);
37
35
  return issues.map((issue) => ({
38
36
  id: String(issue.number),
@@ -50,8 +48,10 @@ export class GitHubTicketProvider {
50
48
  }
51
49
  getById(id) {
52
50
  try {
53
- const cmd = `gh issue view ${id} --json number,title,labels,url,body`;
54
- const output = execSync(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
51
+ const output = execFileSync("gh", ["issue", "view", "--json", "number,title,labels,url,body", "--", id], {
52
+ encoding: "utf-8",
53
+ stdio: ["pipe", "pipe", "pipe"],
54
+ });
55
55
  const issue = JSON.parse(output);
56
56
  return {
57
57
  id: String(issue.number),
@@ -42,7 +42,11 @@ function getCurrentVersion() {
42
42
  return "0.0.0";
43
43
  }
44
44
  }
45
+ // The version comes from `npm view`, whose registry a repo's .npmrc can change: accept plain semver only.
46
+ const SEMVER = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
45
47
  function isNewer(latest, current) {
48
+ if (!SEMVER.test(latest))
49
+ return false;
46
50
  const l = latest.split(".").map(Number);
47
51
  const c = current.split(".").map(Number);
48
52
  for (let i = 0; i < 3; i++) {
@@ -54,7 +58,8 @@ function isNewer(latest, current) {
54
58
  return false;
55
59
  }
56
60
  function fetchLatestVersionAsync(cachePath, existingVersion) {
57
- const child = spawn("npm", ["view", PACKAGE_NAME, "version"], {
61
+ const child = spawn("npm", ["view", PACKAGE_NAME, "version", "--registry=https://registry.npmjs.org/"], {
62
+ cwd: homedir(),
58
63
  detached: true,
59
64
  stdio: ["ignore", "pipe", "ignore"],
60
65
  });
@@ -65,6 +70,8 @@ function fetchLatestVersionAsync(cachePath, existingVersion) {
65
70
  child.on("close", (code) => {
66
71
  if (code === 0) {
67
72
  const version = output.trim();
73
+ if (!SEMVER.test(version))
74
+ return;
68
75
  const newCache = { lastCheck: Date.now(), latestVersion: version };
69
76
  try {
70
77
  writeFileSync(cachePath, JSON.stringify(newCache));
@@ -94,10 +101,11 @@ export function checkForUpdates() {
94
101
  }
95
102
  function showNotification(latest) {
96
103
  const current = getCurrentVersion();
97
- console.log(dim("─") + " " +
104
+ // stderr: stdout may be eval'd (completions) or parsed.
105
+ console.error(dim("─") + " " +
98
106
  yellow("Update available:") + " " +
99
107
  dim(current) + " → " + cyan(latest) + " " +
100
108
  dim(`(npm update ${PACKAGE_NAME})`) + " " +
101
109
  dim("─"));
102
- console.log("");
110
+ console.error("");
103
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alejandrochaves/devflow-cli",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Interactive CLI for branch creation, conventional commits, and PR management",
5
5
  "type": "module",
6
6
  "bin": {