openspec-playwright 0.1.24 → 0.1.25

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openspec-playwright",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "OpenSpec + Playwright E2E verification setup tool for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
package/release-notes.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## What's Changed
2
2
 
3
- - fix: playwright.config.ts detects package.json in subdirectories
3
+ - fix: playwright.config.ts searches subdirs for package.json
4
4
 
5
- **Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.24
5
+ **Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.25
@@ -1,8 +1,8 @@
1
1
  import { defineConfig, devices } from '@playwright/test';
2
- import { readFileSync, existsSync } from 'fs';
2
+ import { readFileSync, existsSync, readdirSync } from 'fs';
3
3
  import { join } from 'path';
4
4
 
5
- // ─── Detect project root (find package.json walking up) ───
5
+ // ─── Detect project root (where openspec/ lives) ───
6
6
  function findProjectRoot(start: string): string {
7
7
  let dir = start;
8
8
  for (let i = 0; i < 10; i++) {
@@ -14,7 +14,35 @@ function findProjectRoot(start: string): string {
14
14
  return start;
15
15
  }
16
16
 
17
+ // ─── Find the npm project root (where package.json with scripts lives) ───
18
+ // Checks project root first, then immediate subdirectories
19
+ function findNpmRoot(projectRoot: string): string {
20
+ const pkgAtRoot = join(projectRoot, 'package.json');
21
+ if (existsSync(pkgAtRoot)) {
22
+ const pkg = JSON.parse(readFileSync(pkgAtRoot, 'utf-8'));
23
+ if (pkg.scripts?.dev || pkg.scripts?.start || pkg.scripts?.serve || pkg.scripts?.preview) {
24
+ return projectRoot;
25
+ }
26
+ }
27
+ // Check immediate subdirectories (e.g., openspec/ and imap/ are siblings)
28
+ try {
29
+ const entries = readdirSync(projectRoot, { withFileTypes: true });
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;
32
+ const subPkg = join(projectRoot, entry.name, 'package.json');
33
+ if (existsSync(subPkg)) {
34
+ const sub = JSON.parse(readFileSync(subPkg, 'utf-8'));
35
+ if (sub.scripts?.dev || sub.scripts?.start) {
36
+ return join(projectRoot, entry.name);
37
+ }
38
+ }
39
+ }
40
+ } catch {}
41
+ return projectRoot;
42
+ }
43
+
17
44
  const projectRoot = findProjectRoot(__dirname);
45
+ const npmRoot = findNpmRoot(projectRoot);
18
46
 
19
47
  // ─── BASE_URL: prefer env, then seed.spec.ts, then default ───
20
48
  const seedSpec = join(projectRoot, 'tests', 'playwright', 'seed.spec.ts');
@@ -25,13 +53,17 @@ if (existsSync(seedSpec)) {
25
53
  if (m) baseUrl = m[1];
26
54
  }
27
55
 
28
- // ─── Dev command: detect from package.json scripts ───
29
- const pkgPath = join(projectRoot, 'package.json');
56
+ // ─── Dev command: detect from the npm project ───
30
57
  let devCmd = 'npm run dev';
31
- if (existsSync(pkgPath)) {
32
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
58
+ const npmPkg = join(npmRoot, 'package.json');
59
+ if (existsSync(npmPkg)) {
60
+ const pkg = JSON.parse(readFileSync(npmPkg, 'utf-8'));
33
61
  const scripts = pkg.scripts ?? {};
34
62
  devCmd = scripts.dev ?? scripts.start ?? scripts.serve ?? scripts.preview ?? devCmd;
63
+ // Prefix with cd if npmRoot differs from projectRoot
64
+ if (npmRoot !== projectRoot) {
65
+ devCmd = `cd ${npmRoot} && ${devCmd}`;
66
+ }
35
67
  }
36
68
 
37
69
  export default defineConfig({
Binary file