Skip to content

Commit 50e1c2d

Browse files
authored
Merge pull request #39 from K9i-0/fix/xcode-build-npx-issues
fix: Xcodeビルドとnpx実行の問題を修正
2 parents 2d8eb29 + 103cfa1 commit 50e1c2d

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

Sources/ClaudeUsageMonitor/ServerManager.swift

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,51 @@ class ServerManager: ObservableObject {
5151
print("[ServerManager] Bundle.main.bundlePath: \(Bundle.main.bundlePath)")
5252
print("[ServerManager] Bundle.main.resourcePath: \(Bundle.main.resourcePath ?? "nil")")
5353

54-
if let bundledServerPath = Bundle.main.path(forResource: "server", ofType: nil) {
55-
serverPath = bundledServerPath
56-
print("[ServerManager] Using bundled server at: \(bundledServerPath)")
57-
58-
// Verify server.js exists
59-
let serverJsPath = (bundledServerPath as NSString).appendingPathComponent("server.js")
60-
if FileManager.default.fileExists(atPath: serverJsPath) {
61-
print("[ServerManager] server.js found at: \(serverJsPath)")
62-
} else {
63-
print("[ServerManager] ERROR: server.js not found at: \(serverJsPath)")
54+
// Check for server directory in Resources
55+
if let resourcePath = Bundle.main.resourcePath {
56+
let bundledServerPath = (resourcePath as NSString).appendingPathComponent("server")
57+
if FileManager.default.fileExists(atPath: bundledServerPath) {
58+
serverPath = bundledServerPath
59+
print("[ServerManager] Using bundled server at: \(bundledServerPath)")
60+
61+
// Verify server.js exists
62+
let serverJsPath = (bundledServerPath as NSString).appendingPathComponent("server.js")
63+
if FileManager.default.fileExists(atPath: serverJsPath) {
64+
print("[ServerManager] server.js found at: \(serverJsPath)")
65+
} else {
66+
print("[ServerManager] ERROR: server.js not found at: \(serverJsPath)")
67+
}
6468
}
65-
} else {
66-
// Fallback to development location
67-
let appPath = Bundle.main.bundlePath
68-
let devServerPath = (appPath as NSString).deletingLastPathComponent
69-
.appending("/server")
70-
if FileManager.default.fileExists(atPath: devServerPath) {
71-
serverPath = devServerPath
72-
print("[ServerManager] Using development server at: \(devServerPath)")
69+
}
70+
71+
// Fallback to development location if not found in bundle
72+
if serverPath == nil {
73+
// Try multiple possible locations
74+
let possiblePaths = [
75+
// Development location (when running from Xcode)
76+
(Bundle.main.bundlePath as NSString).deletingLastPathComponent.appending("/server"),
77+
// Project root location
78+
"/Users/kotahayashi/Workspace/ClaudeCodeMonitor/server",
79+
// Alternative development location
80+
((Bundle.main.bundlePath as NSString).deletingLastPathComponent as NSString)
81+
.deletingLastPathComponent
82+
.replacingOccurrences(of: "/Build/Products/Debug", with: "")
83+
.appending("/server")
84+
]
85+
86+
for path in possiblePaths {
87+
if FileManager.default.fileExists(atPath: path) {
88+
serverPath = path
89+
print("[ServerManager] Using development server at: \(path)")
90+
break
91+
}
7392
}
7493
}
7594

7695
// Check if server directory exists
7796
guard let validServerPath = serverPath else {
78-
print("[ServerManager] Server directory not found")
97+
print("[ServerManager] Server directory not found - server will not start")
98+
print("[ServerManager] This is expected in development mode. npx will be used directly.")
7999
NSLog("[ServerManager] Server directory not found")
80100
return false
81101
}
@@ -87,6 +107,7 @@ class ServerManager: ObservableObject {
87107
var nodePath: String?
88108
let systemNodePaths = [
89109
"/Users/\(NSUserName())/.local/share/mise/shims/node",
110+
"/Users/\(NSUserName())/.local/share/mise/installs/node/22.16.0/bin/node",
90111
"/opt/homebrew/bin/node",
91112
"/usr/local/bin/node",
92113
"/usr/bin/node"

Sources/ClaudeUsageMonitor/UsageMonitor.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,17 @@ class UsageMonitor: ObservableObject, UsageMonitoring {
353353
// Add npm/node to PATH
354354
var environment = ProcessInfo.processInfo.environment
355355
let existingPath = environment["PATH"] ?? ""
356-
environment["PATH"] = "/usr/local/bin:/opt/homebrew/bin:\(existingPath)"
356+
// Add common Node.js installation paths
357+
let nodePaths = [
358+
"/usr/local/bin",
359+
"/opt/homebrew/bin",
360+
"/Users/\(NSUserName())/.local/share/mise/shims",
361+
"/Users/\(NSUserName())/.local/share/mise/installs/node/22.16.0/bin",
362+
"/Users/\(NSUserName())/.nvm/versions/node/v20.11.0/bin",
363+
"/Users/\(NSUserName())/.nvm/versions/node/v20.18.2/bin",
364+
"/usr/bin"
365+
].joined(separator: ":")
366+
environment["PATH"] = "\(nodePaths):\(existingPath)"
357367
task.environment = environment
358368

359369
let pipe = Pipe()

0 commit comments

Comments
 (0)