apigrip 0.2.1 → 0.2.3

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.
@@ -2,14 +2,13 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { parseSpec } from '../../core/spec-parser.js';
4
4
  import { createServer } from '../../server/index.js';
5
- import { findProjectForDir } from '../../core/projects-store.js';
6
-
7
- const ROOT_SPEC_FILES = ['openapi.yaml', 'openapi.yml', 'openapi.json', 'swagger.yaml', 'swagger.yml', 'swagger.json'];
5
+ import { findProjectForDir, loadProjects } from '../../core/projects-store.js';
6
+ import { discoverSpec } from '../../core/spec-discovery.js';
8
7
 
9
8
  /**
10
9
  * Quick project resolution for the serve command.
11
- * Unlike resolveProjectContext, this never does BFS discovery.
12
- * Only auto-opens cwd if it's a git repo with a root-level spec file.
10
+ * Uses full spec discovery for known project dirs (bookmarks, explicit flags, git repos)
11
+ * but never does BFS on arbitrary directories like home.
13
12
  */
14
13
  async function resolveServeProject(argv) {
15
14
  // 1. Explicit flags take priority
@@ -18,39 +17,39 @@ async function resolveServeProject(argv) {
18
17
  return { projectDir, specPath: argv.spec };
19
18
  }
20
19
  if (argv.project) {
21
- const specPath = findRootSpec(argv.project);
22
- return { projectDir: argv.project, specPath };
20
+ const discovered = await discoverSpec(argv.project);
21
+ return { projectDir: argv.project, specPath: discovered?.specPath || null };
23
22
  }
24
23
 
25
24
  // 2. Check if cwd is inside a bookmarked project
26
25
  const cwd = process.cwd();
27
26
  const bookmark = findProjectForDir(cwd);
28
27
  if (bookmark) {
29
- const specPath = bookmark.spec || findRootSpec(bookmark.path);
28
+ const discovered = bookmark.spec ? null : await discoverSpec(bookmark.path);
29
+ const specPath = bookmark.spec || discovered?.specPath || null;
30
30
  return { projectDir: bookmark.path, specPath };
31
31
  }
32
32
 
33
- // 3. Only auto-open cwd if it's a git repo with a root-level spec
33
+ // 3. Auto-open cwd if it's a git repo (bounded dir, safe to search)
34
34
  const isGitRepo = fs.existsSync(path.join(cwd, '.git'));
35
35
  if (isGitRepo) {
36
- const specPath = findRootSpec(cwd);
37
- if (specPath) {
38
- return { projectDir: cwd, specPath };
36
+ const discovered = await discoverSpec(cwd);
37
+ if (discovered?.specPath) {
38
+ return { projectDir: cwd, specPath: discovered.specPath };
39
39
  }
40
40
  }
41
41
 
42
- // 4. Start without a project user can open from history in the UI
43
- return { projectDir: null, specPath: null };
44
- }
45
-
46
- function findRootSpec(dir) {
47
- for (const name of ROOT_SPEC_FILES) {
48
- const p = path.join(dir, name);
49
- try {
50
- if (fs.statSync(p).isFile()) return p;
51
- } catch { /* not found */ }
42
+ // 4. Fall back to the first bookmarked project
43
+ const projects = loadProjects();
44
+ if (projects.length > 0) {
45
+ const proj = projects[0];
46
+ const discovered = proj.spec ? null : await discoverSpec(proj.path);
47
+ const specPath = proj.spec || discovered?.specPath || null;
48
+ return { projectDir: proj.path, specPath };
52
49
  }
53
- return null;
50
+
51
+ // 5. Start without a project — user can open from history in the UI
52
+ return { projectDir: null, specPath: null };
54
53
  }
55
54
 
56
55
  export async function serveCommand(argv) {