MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / isLocalNodeModulesScript

Function isLocalNodeModulesScript

src/config/ConfigParser.ts:30–57  ·  view source on GitHub ↗
(scriptPath: string, cwd: string)

Source from the content-addressed store, hash-verified

28import {ServerConfig} from './ServerConfig.js';
29
30function 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
59function isPlainObject(value: unknown): value is Record<string, unknown> {
60 return typeof value === 'object' && value !== null && !Array.isArray(value);

Callers 1

#resolveScriptNameMethod · 0.85

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected