(scriptPath: string, cwd: string)
| 28 | import {ServerConfig} from './ServerConfig.js'; |
| 29 | |
| 30 | function isLocalNodeModulesScript(scriptPath: string, cwd: string): boolean { |
| 31 | const isWindows = process.platform === 'win32'; |
| 32 | const pathApi = isWindows ? path.win32 : path.posix; |
| 33 | const resolvedCwd = pathApi.resolve(cwd); |
| 34 | const resolvedScript = pathApi.resolve(resolvedCwd, scriptPath); |
| 35 | const targetScript = isWindows |
| 36 | ? resolvedScript.toLowerCase() |
| 37 | : resolvedScript; |
| 38 | const binPrefix = `.bin${pathApi.sep}`; |
| 39 | const pkgPrefix = `chrome-devtools-mcp${pathApi.sep}`; |
| 40 | |
| 41 | let dir = resolvedCwd; |
| 42 | let parent = ''; |
| 43 | while (dir !== parent) { |
| 44 | const nodeModulesDir = pathApi.join(dir, 'node_modules'); |
| 45 | const base = isWindows ? nodeModulesDir.toLowerCase() : nodeModulesDir; |
| 46 | const rel = pathApi.relative(base, targetScript); |
| 47 | if ( |
| 48 | !pathApi.isAbsolute(rel) && |
| 49 | (rel.startsWith(binPrefix) || rel.startsWith(pkgPrefix)) |
| 50 | ) { |
| 51 | return true; |
| 52 | } |
| 53 | parent = dir; |
| 54 | dir = pathApi.dirname(dir); |
| 55 | } |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | function isPlainObject(value: unknown): value is Record<string, unknown> { |
| 60 | return typeof value === 'object' && value !== null && !Array.isArray(value); |
no test coverage detected