Ports the CLI, TUI, and launcher from v1.5 into v2 behind a single `mcp-inspector` entrypoint (launcher → web/cli/tui). Includes the `mcp-inspector --web --dev` launcher fix (Vite alias resolution + prod-server double-start), the root `postinstall` install cascade with simplified CI, and spec/AGENTS docs (no-workspaces rationale, Development setup). Closes #1246. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
100 lines
3.4 KiB
TypeScript
100 lines
3.4 KiB
TypeScript
/**
|
|
* Vitest/Vite resolve aliases shared between clients/web and node clients
|
|
* (cli, tui). Pass each client's directory so bare-module pins resolve against
|
|
* that client's node_modules.
|
|
*/
|
|
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
export function vitestSharedPaths(clientDir: string) {
|
|
const dirname = path.resolve(clientDir);
|
|
const repoRoot = path.resolve(dirname, '../..');
|
|
|
|
const sharedAliases = {
|
|
'@inspector/core': path.resolve(repoRoot, 'core'),
|
|
'@modelcontextprotocol/inspector-test-server': path.resolve(
|
|
repoRoot,
|
|
'test-servers/build/index.js',
|
|
),
|
|
};
|
|
|
|
const sharedDedupe = ['react', 'react-dom', '@modelcontextprotocol/sdk'];
|
|
|
|
const nodeModulesAliases = [
|
|
{ find: /^react$/, replacement: path.resolve(dirname, 'node_modules/react') },
|
|
{
|
|
find: /^react\/jsx-runtime$/,
|
|
replacement: path.resolve(dirname, 'node_modules/react/jsx-runtime.js'),
|
|
},
|
|
{
|
|
find: /^react\/jsx-dev-runtime$/,
|
|
replacement: path.resolve(dirname, 'node_modules/react/jsx-dev-runtime.js'),
|
|
},
|
|
{
|
|
find: /^react-dom$/,
|
|
replacement: path.resolve(dirname, 'node_modules/react-dom'),
|
|
},
|
|
{
|
|
find: /^react-dom\/client$/,
|
|
replacement: path.resolve(dirname, 'node_modules/react-dom/client.js'),
|
|
},
|
|
{ find: /^pino$/, replacement: path.resolve(dirname, 'node_modules/pino') },
|
|
{
|
|
find: /^pino\/browser\.js$/,
|
|
replacement: path.resolve(dirname, 'node_modules/pino/browser.js'),
|
|
},
|
|
{ find: /^zustand$/, replacement: path.resolve(dirname, 'node_modules/zustand') },
|
|
{
|
|
find: /^zustand\/middleware$/,
|
|
replacement: path.resolve(dirname, 'node_modules/zustand/middleware.js'),
|
|
},
|
|
{
|
|
find: /^zustand\/vanilla$/,
|
|
replacement: path.resolve(dirname, 'node_modules/zustand/vanilla.js'),
|
|
},
|
|
{
|
|
find: /^hono$/,
|
|
replacement: path.resolve(dirname, 'node_modules/hono/dist/index.js'),
|
|
},
|
|
{
|
|
find: /^hono\/streaming$/,
|
|
replacement: path.resolve(dirname, 'node_modules/hono/dist/helper/streaming/index.js'),
|
|
},
|
|
{
|
|
find: /^@hono\/node-server$/,
|
|
replacement: path.resolve(dirname, 'node_modules/@hono/node-server'),
|
|
},
|
|
{ find: /^atomically$/, replacement: path.resolve(dirname, 'node_modules/atomically') },
|
|
{ find: /^chokidar$/, replacement: path.resolve(dirname, 'node_modules/chokidar') },
|
|
{
|
|
find: /^@napi-rs\/keyring$/,
|
|
replacement: path.resolve(dirname, 'node_modules/@napi-rs/keyring'),
|
|
},
|
|
{ find: /^express$/, replacement: path.resolve(dirname, 'node_modules/express') },
|
|
{ find: /^yaml$/, replacement: path.resolve(dirname, 'node_modules/yaml') },
|
|
{
|
|
find: /^@modelcontextprotocol\/sdk\/client\/auth\.js$/,
|
|
replacement: path.resolve(
|
|
dirname,
|
|
'node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js',
|
|
),
|
|
},
|
|
];
|
|
|
|
const projectResolve = {
|
|
alias: [
|
|
...Object.entries(sharedAliases).map(([find, replacement]) => ({ find, replacement })),
|
|
...nodeModulesAliases,
|
|
],
|
|
dedupe: sharedDedupe,
|
|
};
|
|
|
|
return { repoRoot, sharedAliases, sharedDedupe, nodeModulesAliases, projectResolve };
|
|
}
|
|
|
|
/** Convenience for importers that only have import.meta.url. */
|
|
export function vitestSharedPathsFromMetaUrl(metaUrl: string) {
|
|
const clientDir = path.dirname(fileURLToPath(metaUrl));
|
|
return vitestSharedPaths(clientDir);
|
|
}
|