xmcp 0.6.13 → 0.7.1
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.
- package/dist/cli.js +8 -8
- package/dist/index.js +2 -2
- package/dist/runtime/adapter-express.js +2 -2
- package/dist/runtime/adapter-fastify.js +2 -2
- package/dist/runtime/adapter-nestjs.js +7 -7
- package/dist/runtime/adapter-nextjs.js +11 -11
- package/dist/runtime/http.js +3 -3
- package/dist/runtime/stdio.js +8 -8
- package/package.json +10 -11
- package/src/auth/api-key.ts +0 -120
- package/src/auth/jwt.ts +0 -52
- package/src/cli/commands/create/__tests__/create.test.ts +0 -99
- package/src/cli/commands/create/index.ts +0 -74
- package/src/cli/commands/create/templates/index.ts +0 -4
- package/src/cli/commands/create/templates/prompt.ts +0 -30
- package/src/cli/commands/create/templates/resource.ts +0 -20
- package/src/cli/commands/create/templates/tool.ts +0 -34
- package/src/cli/commands/create/templates/widget.ts +0 -33
- package/src/cli/utils/naming.ts +0 -39
- package/src/cli.ts +0 -125
- package/src/client/headers.ts +0 -61
- package/src/client/index.ts +0 -180
- package/src/client/types.ts +0 -122
- package/src/client/utils.ts +0 -133
- package/src/cloudflare.ts +0 -6
- package/src/compiler/build-telemetry.ts +0 -88
- package/src/compiler/client/component-compiler.ts +0 -250
- package/src/compiler/client/transpile.ts +0 -21
- package/src/compiler/compiler-context.ts +0 -61
- package/src/compiler/config/__tests__/config.test.ts +0 -459
- package/src/compiler/config/index.ts +0 -62
- package/src/compiler/config/injection.ts +0 -210
- package/src/compiler/config/schemas/bundler.ts +0 -12
- package/src/compiler/config/schemas/experimental/index.ts +0 -22
- package/src/compiler/config/schemas/index.ts +0 -20
- package/src/compiler/config/schemas/paths.ts +0 -35
- package/src/compiler/config/schemas/template.ts +0 -80
- package/src/compiler/config/schemas/transport/http.ts +0 -116
- package/src/compiler/config/schemas/transport/stdio.ts +0 -31
- package/src/compiler/config/schemas/typescript.ts +0 -26
- package/src/compiler/config/utils.ts +0 -168
- package/src/compiler/generate-env-code.ts +0 -5
- package/src/compiler/generate-import-code.ts +0 -187
- package/src/compiler/generate-tools-code.ts +0 -174
- package/src/compiler/get-bundler-config/get-entries.ts +0 -44
- package/src/compiler/get-bundler-config/get-externals.ts +0 -114
- package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
- package/src/compiler/get-bundler-config/index.ts +0 -288
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
- package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
- package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
- package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
- package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
- package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
- package/src/compiler/index.ts +0 -484
- package/src/compiler/on-first-build.ts +0 -54
- package/src/compiler/parse-xmcp-config.ts +0 -200
- package/src/compiler/start-http-server.ts +0 -42
- package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
- package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
- package/src/compiler/utils/config-detection.ts +0 -34
- package/src/compiler/utils/path-utils.ts +0 -22
- package/src/compiler/watcher-recovery.ts +0 -72
- package/src/host-bridge.ts +0 -36
- package/src/index.ts +0 -94
- package/src/platforms/build-cloudflare-output.ts +0 -116
- package/src/platforms/build-vercel-output.ts +0 -131
- package/src/plugins/index.ts +0 -1
- package/src/plugins/x402/index.ts +0 -24
- package/src/runtime/adapters/express/index.ts +0 -75
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
- package/src/runtime/adapters/fastify/index.ts +0 -78
- package/src/runtime/adapters/nestjs/index.ts +0 -16
- package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
- package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
- package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
- package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
- package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
- package/src/runtime/adapters/nextjs/auth.ts +0 -265
- package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
- package/src/runtime/adapters/nextjs/index.ts +0 -82
- package/src/runtime/contexts/client-info-context.ts +0 -16
- package/src/runtime/contexts/http-request-context.ts +0 -21
- package/src/runtime/contexts/http-transport-context.ts +0 -18
- package/src/runtime/headers.ts +0 -42
- package/src/runtime/middlewares/utils.ts +0 -72
- package/src/runtime/platforms/cloudflare/cors.ts +0 -44
- package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
- package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
- package/src/runtime/platforms/cloudflare/types.ts +0 -23
- package/src/runtime/platforms/cloudflare/worker.ts +0 -270
- package/src/runtime/templates/home.ts +0 -746
- package/src/runtime/transports/http/base-streamable-http.ts +0 -46
- package/src/runtime/transports/http/cors/headers.ts +0 -58
- package/src/runtime/transports/http/cors/index.ts +0 -34
- package/src/runtime/transports/http/index.ts +0 -78
- package/src/runtime/transports/http/stateless-streamable-http.ts +0 -311
- package/src/runtime/transports/http/web-stateless-http.ts +0 -288
- package/src/runtime/transports/stdio/index.ts +0 -109
- package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
- package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
- package/src/runtime/utils/client-info.ts +0 -114
- package/src/runtime/utils/elicitation.ts +0 -396
- package/src/runtime/utils/ext-apps-registry.ts +0 -151
- package/src/runtime/utils/mcp-app-protocol.ts +0 -16
- package/src/runtime/utils/mcp-app-types.ts +0 -113
- package/src/runtime/utils/mcp-host-bridge.ts +0 -473
- package/src/runtime/utils/path-to-tool-name.ts +0 -69
- package/src/runtime/utils/prompt-loader.ts +0 -151
- package/src/runtime/utils/prompts.ts +0 -69
- package/src/runtime/utils/react/generate-html.ts +0 -69
- package/src/runtime/utils/react/index.ts +0 -6
- package/src/runtime/utils/request-tool-names.ts +0 -48
- package/src/runtime/utils/resource-loader.ts +0 -151
- package/src/runtime/utils/resources.ts +0 -331
- package/src/runtime/utils/server.ts +0 -107
- package/src/runtime/utils/tool-loader.ts +0 -149
- package/src/runtime/utils/tools.ts +0 -183
- package/src/runtime/utils/transformers/prompt.ts +0 -120
- package/src/runtime/utils/transformers/resource.ts +0 -196
- package/src/runtime/utils/transformers/tool.ts +0 -400
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
- package/src/runtime/utils/ui/flatten-meta.ts +0 -44
- package/src/runtime/utils/ui/split-meta.ts +0 -78
- package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
- package/src/runtime/utils/validators/index.ts +0 -138
- package/src/telemetry/ci-info.ts +0 -6
- package/src/telemetry/debug.ts +0 -8
- package/src/telemetry/events/definitions.ts +0 -52
- package/src/telemetry/events/detached-flush.ts +0 -83
- package/src/telemetry/events/post-payload.ts +0 -141
- package/src/telemetry/events/tracker.ts +0 -281
- package/src/telemetry/index.ts +0 -7
- package/src/telemetry/metadata.ts +0 -49
- package/src/telemetry/project-id.ts +0 -35
- package/src/telemetry/storage.ts +0 -218
- package/src/types/adapter.d.ts +0 -5
- package/src/types/client-info.ts +0 -20
- package/src/types/declarations.ts +0 -37
- package/src/types/injected.d.ts +0 -62
- package/src/types/middleware.ts +0 -19
- package/src/types/prompt.ts +0 -6
- package/src/types/resource.ts +0 -15
- package/src/types/tool.ts +0 -192
- package/src/types/ui-meta.ts +0 -42
- package/src/utils/cli-icons.ts +0 -5
- package/src/utils/constants.ts +0 -31
- package/src/utils/context.ts +0 -105
- package/src/utils/detect-package-manager.ts +0 -46
- package/src/utils/file-watcher.ts +0 -66
- package/src/utils/fs-utils.ts +0 -16
- package/src/utils/path-validation.ts +0 -66
- package/src/utils/port-utils.ts +0 -43
- package/src/utils/spawn-process.ts +0 -49
- package/src/utils/subscribable.ts +0 -62
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { createFsFromVolume, Volume } from "memfs";
|
|
4
|
-
import { compilerContext } from "./compiler-context";
|
|
5
|
-
import { rspack, RspackOptions } from "@rspack/core";
|
|
6
|
-
import { configSchema, type XmcpConfigOutputSchema } from "./config";
|
|
7
|
-
|
|
8
|
-
function validateConfig(config: unknown): XmcpConfigOutputSchema {
|
|
9
|
-
return configSchema.parse(config);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// read if exists
|
|
13
|
-
function readConfigFile(pathToConfig: string): string | null {
|
|
14
|
-
const configPath = path.resolve(process.cwd(), pathToConfig);
|
|
15
|
-
if (!fs.existsSync(configPath)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return fs.readFileSync(configPath, "utf8");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const configPaths = {
|
|
22
|
-
ts: "xmcp.config.ts",
|
|
23
|
-
json: "xmcp.config.json",
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Parse and validate xmcp config file
|
|
28
|
-
*/
|
|
29
|
-
export async function getConfig(): Promise<XmcpConfigOutputSchema> {
|
|
30
|
-
const config = await readConfig();
|
|
31
|
-
const { platforms } = compilerContext.getContext();
|
|
32
|
-
if (platforms.vercel) {
|
|
33
|
-
// Remove stdio to deploy on vercel
|
|
34
|
-
delete config.stdio;
|
|
35
|
-
}
|
|
36
|
-
if (platforms.cloudflare) {
|
|
37
|
-
// Remove stdio for Cloudflare Workers
|
|
38
|
-
delete config.stdio;
|
|
39
|
-
// Ensure HTTP is enabled for Workers builds
|
|
40
|
-
if (!config.http) {
|
|
41
|
-
config.http = true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return config;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Read config from file or return default
|
|
49
|
-
*/
|
|
50
|
-
export async function readConfig(): Promise<XmcpConfigOutputSchema> {
|
|
51
|
-
// Simple json config
|
|
52
|
-
const jsonFile = readConfigFile(configPaths.json);
|
|
53
|
-
if (jsonFile) {
|
|
54
|
-
return validateConfig(JSON.parse(jsonFile));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// TypeScript config, compile it
|
|
58
|
-
const tsFile = readConfigFile(configPaths.ts);
|
|
59
|
-
if (tsFile) {
|
|
60
|
-
try {
|
|
61
|
-
return await compileConfig();
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw new Error(`Failed to compile xmcp.config.ts:\n${error}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return configSchema.parse({
|
|
68
|
-
stdio: true,
|
|
69
|
-
http: true,
|
|
70
|
-
paths: {},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* If the user is using a typescript config file,
|
|
76
|
-
* we need to bundle it, run it and return its copiled code
|
|
77
|
-
* */
|
|
78
|
-
async function compileConfig(): Promise<XmcpConfigOutputSchema> {
|
|
79
|
-
const configPath = path.resolve(process.cwd(), configPaths.ts);
|
|
80
|
-
|
|
81
|
-
// Create memory filesystem
|
|
82
|
-
const memoryFs = createFsFromVolume(new Volume());
|
|
83
|
-
|
|
84
|
-
// rspack configuration
|
|
85
|
-
const rspackConfig: RspackOptions = {
|
|
86
|
-
mode: "production",
|
|
87
|
-
entry: configPath,
|
|
88
|
-
target: "node",
|
|
89
|
-
output: {
|
|
90
|
-
path: "/",
|
|
91
|
-
filename: "config.js",
|
|
92
|
-
library: {
|
|
93
|
-
type: "commonjs2",
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
resolve: {
|
|
97
|
-
extensions: [".ts", ".js"],
|
|
98
|
-
},
|
|
99
|
-
resolveLoader: {
|
|
100
|
-
modules: [
|
|
101
|
-
"node_modules",
|
|
102
|
-
path.resolve(__dirname, "../node_modules"), // for monorepo/npm
|
|
103
|
-
path.resolve(__dirname, "../.."), // for pnpm
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
module: {
|
|
107
|
-
rules: [
|
|
108
|
-
{
|
|
109
|
-
test: /\.ts$/,
|
|
110
|
-
use: {
|
|
111
|
-
loader: "builtin:swc-loader",
|
|
112
|
-
options: {
|
|
113
|
-
jsc: {
|
|
114
|
-
parser: {
|
|
115
|
-
syntax: "typescript",
|
|
116
|
-
},
|
|
117
|
-
target: "es2020",
|
|
118
|
-
},
|
|
119
|
-
module: {
|
|
120
|
-
type: "commonjs",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
exclude: /node_modules/,
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
},
|
|
128
|
-
externals: {
|
|
129
|
-
rspack: "commonjs2 rspack",
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
return new Promise((resolve, reject) => {
|
|
134
|
-
const compiler = rspack(rspackConfig);
|
|
135
|
-
|
|
136
|
-
if (!compiler) {
|
|
137
|
-
reject(new Error("Failed to create rspack compiler"));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Use memory filesystem for output
|
|
142
|
-
compiler.outputFileSystem = memoryFs as any;
|
|
143
|
-
|
|
144
|
-
compiler.run((err, stats) => {
|
|
145
|
-
if (err) {
|
|
146
|
-
reject(err);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (stats?.hasErrors()) {
|
|
151
|
-
reject(new Error(stats.toString({ colors: false, errors: true })));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
// Read the bundled code from memory
|
|
157
|
-
const bundledCode = memoryFs.readFileSync(
|
|
158
|
-
"/config.js",
|
|
159
|
-
"utf8"
|
|
160
|
-
) as string;
|
|
161
|
-
|
|
162
|
-
// Create a temporary module to evaluate the bundled code
|
|
163
|
-
const module = { exports: {} };
|
|
164
|
-
const require = (id: string) => {
|
|
165
|
-
// Handle rspack require
|
|
166
|
-
if (id === "rspack") {
|
|
167
|
-
return rspack;
|
|
168
|
-
}
|
|
169
|
-
throw new Error(`Cannot resolve module: ${id}`);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// Evaluate the bundled code
|
|
173
|
-
const func = new Function(
|
|
174
|
-
"module",
|
|
175
|
-
"exports",
|
|
176
|
-
"require",
|
|
177
|
-
"__filename",
|
|
178
|
-
"__dirname",
|
|
179
|
-
bundledCode
|
|
180
|
-
);
|
|
181
|
-
func(
|
|
182
|
-
module,
|
|
183
|
-
module.exports,
|
|
184
|
-
require,
|
|
185
|
-
configPath,
|
|
186
|
-
path.dirname(configPath)
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
// Extract the config - it could be default export or direct export
|
|
190
|
-
const configExport = (module.exports as any).default || module.exports;
|
|
191
|
-
const config =
|
|
192
|
-
typeof configExport === "function" ? configExport() : configExport;
|
|
193
|
-
|
|
194
|
-
resolve(validateConfig(config));
|
|
195
|
-
} catch (evalError) {
|
|
196
|
-
reject(evalError);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { yellowArrow } from "@/utils/cli-icons";
|
|
2
|
-
import { watchdog } from "@/utils/spawn-process";
|
|
3
|
-
import { ChildProcess, spawn } from "child_process";
|
|
4
|
-
|
|
5
|
-
let httpServerProcess: ChildProcess | null = null;
|
|
6
|
-
|
|
7
|
-
function spawnHttpServer() {
|
|
8
|
-
const process = spawn("node", ["dist/http.js"], {
|
|
9
|
-
stdio: "inherit",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
watchdog(process);
|
|
13
|
-
|
|
14
|
-
return process;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function killProcess(proc: ChildProcess) {
|
|
18
|
-
await new Promise<void>((resolve) => {
|
|
19
|
-
if (proc.exitCode !== null || proc.signalCode !== null) {
|
|
20
|
-
return resolve();
|
|
21
|
-
}
|
|
22
|
-
proc.on("exit", () => resolve());
|
|
23
|
-
try {
|
|
24
|
-
proc.kill("SIGKILL");
|
|
25
|
-
} catch {
|
|
26
|
-
resolve();
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function startHttpServer() {
|
|
32
|
-
if (!httpServerProcess) {
|
|
33
|
-
console.log(`${yellowArrow} Starting http server`);
|
|
34
|
-
// first time starting the server
|
|
35
|
-
httpServerProcess = spawnHttpServer();
|
|
36
|
-
} else {
|
|
37
|
-
console.log(`${yellowArrow} Restarting http server`);
|
|
38
|
-
// restart the server
|
|
39
|
-
await killProcess(httpServerProcess);
|
|
40
|
-
httpServerProcess = spawnHttpServer();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import {
|
|
4
|
-
mkdtempSync,
|
|
5
|
-
writeFileSync,
|
|
6
|
-
rmSync,
|
|
7
|
-
mkdirSync,
|
|
8
|
-
realpathSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { hasPostCSSConfig, findGlobalsCss } from "../config-detection";
|
|
13
|
-
|
|
14
|
-
test("hasPostCSSConfig - returns false when no config files exist", () => {
|
|
15
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
16
|
-
const originalCwd = process.cwd();
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
process.chdir(testDir);
|
|
20
|
-
const result = hasPostCSSConfig();
|
|
21
|
-
assert.strictEqual(result, false);
|
|
22
|
-
} finally {
|
|
23
|
-
process.chdir(originalCwd);
|
|
24
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("hasPostCSSConfig - returns true when postcss.config.js exists", () => {
|
|
29
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
30
|
-
const originalCwd = process.cwd();
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
process.chdir(testDir);
|
|
34
|
-
writeFileSync(join(testDir, "postcss.config.js"), "module.exports = {}");
|
|
35
|
-
const result = hasPostCSSConfig();
|
|
36
|
-
assert.strictEqual(result, true);
|
|
37
|
-
} finally {
|
|
38
|
-
process.chdir(originalCwd);
|
|
39
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("hasPostCSSConfig - returns true when postcss.config.mjs exists", () => {
|
|
44
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
45
|
-
const originalCwd = process.cwd();
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
process.chdir(testDir);
|
|
49
|
-
writeFileSync(join(testDir, "postcss.config.mjs"), "export default {}");
|
|
50
|
-
const result = hasPostCSSConfig();
|
|
51
|
-
assert.strictEqual(result, true);
|
|
52
|
-
} finally {
|
|
53
|
-
process.chdir(originalCwd);
|
|
54
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("hasPostCSSConfig - returns true when postcss.config.cjs exists", () => {
|
|
59
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
60
|
-
const originalCwd = process.cwd();
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
process.chdir(testDir);
|
|
64
|
-
writeFileSync(join(testDir, "postcss.config.cjs"), "module.exports = {}");
|
|
65
|
-
const result = hasPostCSSConfig();
|
|
66
|
-
assert.strictEqual(result, true);
|
|
67
|
-
} finally {
|
|
68
|
-
process.chdir(originalCwd);
|
|
69
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("hasPostCSSConfig - returns true when .postcssrc exists", () => {
|
|
74
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
75
|
-
const originalCwd = process.cwd();
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
process.chdir(testDir);
|
|
79
|
-
writeFileSync(join(testDir, ".postcssrc"), "{}");
|
|
80
|
-
const result = hasPostCSSConfig();
|
|
81
|
-
assert.strictEqual(result, true);
|
|
82
|
-
} finally {
|
|
83
|
-
process.chdir(originalCwd);
|
|
84
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("hasPostCSSConfig - returns true when .postcssrc.json exists", () => {
|
|
89
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
90
|
-
const originalCwd = process.cwd();
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
process.chdir(testDir);
|
|
94
|
-
writeFileSync(join(testDir, ".postcssrc.json"), "{}");
|
|
95
|
-
const result = hasPostCSSConfig();
|
|
96
|
-
assert.strictEqual(result, true);
|
|
97
|
-
} finally {
|
|
98
|
-
process.chdir(originalCwd);
|
|
99
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("hasPostCSSConfig - returns true when .postcssrc.js exists", () => {
|
|
104
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
105
|
-
const originalCwd = process.cwd();
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
process.chdir(testDir);
|
|
109
|
-
writeFileSync(join(testDir, ".postcssrc.js"), "module.exports = {}");
|
|
110
|
-
const result = hasPostCSSConfig();
|
|
111
|
-
assert.strictEqual(result, true);
|
|
112
|
-
} finally {
|
|
113
|
-
process.chdir(originalCwd);
|
|
114
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("hasPostCSSConfig - returns true when multiple config files exist", () => {
|
|
119
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
120
|
-
const originalCwd = process.cwd();
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
process.chdir(testDir);
|
|
124
|
-
writeFileSync(join(testDir, "postcss.config.js"), "module.exports = {}");
|
|
125
|
-
writeFileSync(join(testDir, ".postcssrc.json"), "{}");
|
|
126
|
-
const result = hasPostCSSConfig();
|
|
127
|
-
assert.strictEqual(result, true);
|
|
128
|
-
} finally {
|
|
129
|
-
process.chdir(originalCwd);
|
|
130
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("hasPostCSSConfig - returns false with non-postcss config files", () => {
|
|
135
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
136
|
-
const originalCwd = process.cwd();
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
process.chdir(testDir);
|
|
140
|
-
writeFileSync(join(testDir, "package.json"), "{}");
|
|
141
|
-
writeFileSync(join(testDir, "tsconfig.json"), "{}");
|
|
142
|
-
writeFileSync(join(testDir, "tailwind.config.js"), "{}");
|
|
143
|
-
const result = hasPostCSSConfig();
|
|
144
|
-
assert.strictEqual(result, false);
|
|
145
|
-
} finally {
|
|
146
|
-
process.chdir(originalCwd);
|
|
147
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("hasPostCSSConfig - returns false with similar but incorrect filenames", () => {
|
|
152
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
153
|
-
const originalCwd = process.cwd();
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
process.chdir(testDir);
|
|
157
|
-
writeFileSync(join(testDir, "postcss.js"), "{}");
|
|
158
|
-
writeFileSync(join(testDir, "postcss-config.js"), "{}");
|
|
159
|
-
writeFileSync(join(testDir, ".postcss"), "{}");
|
|
160
|
-
const result = hasPostCSSConfig();
|
|
161
|
-
assert.strictEqual(result, false);
|
|
162
|
-
} finally {
|
|
163
|
-
process.chdir(originalCwd);
|
|
164
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test("findGlobalsCss - returns null when no globals.css exists", () => {
|
|
169
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
170
|
-
const originalCwd = process.cwd();
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
process.chdir(testDir);
|
|
174
|
-
const result = findGlobalsCss();
|
|
175
|
-
assert.strictEqual(result, null);
|
|
176
|
-
} finally {
|
|
177
|
-
process.chdir(originalCwd);
|
|
178
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("findGlobalsCss - finds globals.css in root directory", () => {
|
|
183
|
-
const testDir = realpathSync(mkdtempSync(join(tmpdir(), "xmcp-test-")));
|
|
184
|
-
const originalCwd = process.cwd();
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
process.chdir(testDir);
|
|
188
|
-
const globalsPath = join(testDir, "globals.css");
|
|
189
|
-
writeFileSync(globalsPath, "body { margin: 0; }");
|
|
190
|
-
const result = findGlobalsCss();
|
|
191
|
-
assert.strictEqual(result, globalsPath);
|
|
192
|
-
} finally {
|
|
193
|
-
process.chdir(originalCwd);
|
|
194
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("findGlobalsCss - finds globals.css in src directory", () => {
|
|
199
|
-
const testDir = realpathSync(mkdtempSync(join(tmpdir(), "xmcp-test-")));
|
|
200
|
-
const originalCwd = process.cwd();
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
process.chdir(testDir);
|
|
204
|
-
const srcDir = join(testDir, "src");
|
|
205
|
-
mkdirSync(srcDir);
|
|
206
|
-
const globalsPath = join(srcDir, "globals.css");
|
|
207
|
-
writeFileSync(globalsPath, "body { margin: 0; }");
|
|
208
|
-
const result = findGlobalsCss();
|
|
209
|
-
assert.strictEqual(result, globalsPath);
|
|
210
|
-
} finally {
|
|
211
|
-
process.chdir(originalCwd);
|
|
212
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("findGlobalsCss - finds globals.css in src/tools directory", () => {
|
|
217
|
-
const testDir = realpathSync(mkdtempSync(join(tmpdir(), "xmcp-test-")));
|
|
218
|
-
const originalCwd = process.cwd();
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
process.chdir(testDir);
|
|
222
|
-
const toolsDir = join(testDir, "src", "tools");
|
|
223
|
-
mkdirSync(toolsDir, { recursive: true });
|
|
224
|
-
const globalsPath = join(toolsDir, "globals.css");
|
|
225
|
-
writeFileSync(globalsPath, "body { margin: 0; }");
|
|
226
|
-
const result = findGlobalsCss();
|
|
227
|
-
assert.strictEqual(result, globalsPath);
|
|
228
|
-
} finally {
|
|
229
|
-
process.chdir(originalCwd);
|
|
230
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test("findGlobalsCss - prioritizes root over src directory", () => {
|
|
235
|
-
const testDir = realpathSync(mkdtempSync(join(tmpdir(), "xmcp-test-")));
|
|
236
|
-
const originalCwd = process.cwd();
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
process.chdir(testDir);
|
|
240
|
-
const srcDir = join(testDir, "src");
|
|
241
|
-
mkdirSync(srcDir);
|
|
242
|
-
const rootGlobals = join(testDir, "globals.css");
|
|
243
|
-
const srcGlobals = join(srcDir, "globals.css");
|
|
244
|
-
writeFileSync(rootGlobals, "/* root */");
|
|
245
|
-
writeFileSync(srcGlobals, "/* src */");
|
|
246
|
-
const result = findGlobalsCss();
|
|
247
|
-
assert.strictEqual(result, rootGlobals);
|
|
248
|
-
} finally {
|
|
249
|
-
process.chdir(originalCwd);
|
|
250
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test("findGlobalsCss - prioritizes src over src/tools directory", () => {
|
|
255
|
-
const testDir = realpathSync(mkdtempSync(join(tmpdir(), "xmcp-test-")));
|
|
256
|
-
const originalCwd = process.cwd();
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
process.chdir(testDir);
|
|
260
|
-
const toolsDir = join(testDir, "src", "tools");
|
|
261
|
-
mkdirSync(toolsDir, { recursive: true });
|
|
262
|
-
const srcGlobals = join(testDir, "src", "globals.css");
|
|
263
|
-
const toolsGlobals = join(toolsDir, "globals.css");
|
|
264
|
-
writeFileSync(srcGlobals, "/* src */");
|
|
265
|
-
writeFileSync(toolsGlobals, "/* tools */");
|
|
266
|
-
const result = findGlobalsCss();
|
|
267
|
-
assert.strictEqual(result, srcGlobals);
|
|
268
|
-
} finally {
|
|
269
|
-
process.chdir(originalCwd);
|
|
270
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test("findGlobalsCss - returns null with similar but incorrect filenames", () => {
|
|
275
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
276
|
-
const originalCwd = process.cwd();
|
|
277
|
-
|
|
278
|
-
try {
|
|
279
|
-
process.chdir(testDir);
|
|
280
|
-
writeFileSync(join(testDir, "global.css"), "");
|
|
281
|
-
writeFileSync(join(testDir, "globals.scss"), "");
|
|
282
|
-
writeFileSync(join(testDir, "globals-css.css"), "");
|
|
283
|
-
const result = findGlobalsCss();
|
|
284
|
-
assert.strictEqual(result, null);
|
|
285
|
-
} finally {
|
|
286
|
-
process.chdir(originalCwd);
|
|
287
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
test("findGlobalsCss - returns null when only other CSS files exist", () => {
|
|
292
|
-
const testDir = mkdtempSync(join(tmpdir(), "xmcp-test-"));
|
|
293
|
-
const originalCwd = process.cwd();
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
process.chdir(testDir);
|
|
297
|
-
const srcDir = join(testDir, "src");
|
|
298
|
-
mkdirSync(srcDir);
|
|
299
|
-
writeFileSync(join(testDir, "styles.css"), "");
|
|
300
|
-
writeFileSync(join(srcDir, "app.css"), "");
|
|
301
|
-
const result = findGlobalsCss();
|
|
302
|
-
assert.strictEqual(result, null);
|
|
303
|
-
} finally {
|
|
304
|
-
process.chdir(originalCwd);
|
|
305
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
306
|
-
}
|
|
307
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import { pathToToolName } from "../path-utils";
|
|
4
|
-
|
|
5
|
-
test("pathToToolName - simple tool in root", () => {
|
|
6
|
-
const result = pathToToolName("tools/calculator.tsx");
|
|
7
|
-
assert.match(result, /^tools_calculator_[a-f0-9]{6}$/);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("pathToToolName - simple tool with ts extension", () => {
|
|
11
|
-
const result = pathToToolName("tools/weather.ts");
|
|
12
|
-
assert.match(result, /^tools_weather_[a-f0-9]{6}$/);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("pathToToolName - tool in nested directory", () => {
|
|
16
|
-
const result = pathToToolName("tools/advanced/calculator.tsx");
|
|
17
|
-
assert.match(result, /^tools_advanced_calculator_[a-f0-9]{6}$/);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("pathToToolName - tool in deeply nested directory", () => {
|
|
21
|
-
const result = pathToToolName("tools/math/advanced/calculator.tsx");
|
|
22
|
-
assert.match(result, /^tools_math_advanced_calculator_[a-f0-9]{6}$/);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("pathToToolName - tool with multiple dots in name", () => {
|
|
26
|
-
const result = pathToToolName("tools/my.tool.name.tsx");
|
|
27
|
-
assert.match(result, /^tools_my\.tool\.name_[a-f0-9]{6}$/);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("pathToToolName - tool in triple nested directory", () => {
|
|
31
|
-
const result = pathToToolName("tools/category/subcategory/tool.tsx");
|
|
32
|
-
assert.match(result, /^tools_category_subcategory_tool_[a-f0-9]{6}$/);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("pathToToolName - different tools with same name in different dirs are unique", () => {
|
|
36
|
-
const tool1 = pathToToolName("tools/basic/converter.tsx");
|
|
37
|
-
const tool2 = pathToToolName("tools/advanced/converter.tsx");
|
|
38
|
-
assert.notStrictEqual(tool1, tool2);
|
|
39
|
-
assert.match(tool1, /^tools_basic_converter_[a-f0-9]{6}$/);
|
|
40
|
-
assert.match(tool2, /^tools_advanced_converter_[a-f0-9]{6}$/);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("pathToToolName - tool with jsx extension", () => {
|
|
44
|
-
const result = pathToToolName("tools/component.jsx");
|
|
45
|
-
assert.match(result, /^tools_component_[a-f0-9]{6}$/);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("pathToToolName - tool with js extension", () => {
|
|
49
|
-
const result = pathToToolName("tools/helper.js");
|
|
50
|
-
assert.match(result, /^tools_helper_[a-f0-9]{6}$/);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("pathToToolName - absolute path", () => {
|
|
54
|
-
const result = pathToToolName("/home/user/project/tools/calculator.tsx");
|
|
55
|
-
assert.match(result, /^_home_user_project_tools_calculator_[a-f0-9]{6}$/);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("pathToToolName - tool with hyphen in name", () => {
|
|
59
|
-
const result = pathToToolName("tools/my-tool.tsx");
|
|
60
|
-
assert.match(result, /^tools_my-tool_[a-f0-9]{6}$/);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("pathToToolName - tool with underscore in name", () => {
|
|
64
|
-
const result = pathToToolName("tools/my_tool.tsx");
|
|
65
|
-
assert.match(result, /^tools_my_tool_[a-f0-9]{6}$/);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("pathToToolName - nested with hyphenated names", () => {
|
|
69
|
-
const result = pathToToolName("tools/data-tools/json-parser.tsx");
|
|
70
|
-
assert.match(result, /^tools_data-tools_json-parser_[a-f0-9]{6}$/);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("pathToToolName - four levels deep", () => {
|
|
74
|
-
const result = pathToToolName("tools/a/b/c/tool.tsx");
|
|
75
|
-
assert.match(result, /^tools_a_b_c_tool_[a-f0-9]{6}$/);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("pathToToolName - tool with capital letters", () => {
|
|
79
|
-
const result = pathToToolName("tools/MyComponent.tsx");
|
|
80
|
-
assert.match(result, /^tools_MyComponent_[a-f0-9]{6}$/);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("pathToToolName - nested with mixed case", () => {
|
|
84
|
-
const result = pathToToolName("tools/Advanced/Calculator.tsx");
|
|
85
|
-
assert.match(result, /^tools_Advanced_Calculator_[a-f0-9]{6}$/);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("pathToToolName - tool with number in name", () => {
|
|
89
|
-
const result = pathToToolName("tools/tool-v2.tsx");
|
|
90
|
-
assert.match(result, /^tools_tool-v2_[a-f0-9]{6}$/);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("pathToToolName - nested with numbers", () => {
|
|
94
|
-
const result = pathToToolName("tools/v2/calculator-2.tsx");
|
|
95
|
-
assert.match(result, /^tools_v2_calculator-2_[a-f0-9]{6}$/);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("pathToToolName - real world scenario with collision prevention", () => {
|
|
99
|
-
const basicCalc = pathToToolName("tools/calculator.tsx");
|
|
100
|
-
const advancedCalc = pathToToolName("tools/advanced/calculator.tsx");
|
|
101
|
-
const scientificCalc = pathToToolName("tools/scientific/calculator.tsx");
|
|
102
|
-
|
|
103
|
-
assert.match(basicCalc, /^tools_calculator_[a-f0-9]{6}$/);
|
|
104
|
-
assert.match(advancedCalc, /^tools_advanced_calculator_[a-f0-9]{6}$/);
|
|
105
|
-
assert.match(scientificCalc, /^tools_scientific_calculator_[a-f0-9]{6}$/);
|
|
106
|
-
|
|
107
|
-
const allUnique = new Set([basicCalc, advancedCalc, scientificCalc]);
|
|
108
|
-
assert.strictEqual(allUnique.size, 3);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("pathToToolName - handles empty path segments", () => {
|
|
112
|
-
const result = pathToToolName("tools//calculator.tsx");
|
|
113
|
-
assert.match(result, /^tools_calculator_[a-f0-9]{6}$/);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("pathToToolName - same basename different paths produce different hashes", () => {
|
|
117
|
-
const result1 = pathToToolName("tools/my-tool.tsx");
|
|
118
|
-
const result2 = pathToToolName("tools/my/tool.tsx");
|
|
119
|
-
assert.notStrictEqual(result1, result2);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test("pathToToolName - deterministic hash same path produces same result", () => {
|
|
123
|
-
const path = "tools/my/nested/tool.tsx";
|
|
124
|
-
const result1 = pathToToolName(path);
|
|
125
|
-
const result2 = pathToToolName(path);
|
|
126
|
-
assert.strictEqual(result1, result2);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("pathToToolName - custom directory name", () => {
|
|
130
|
-
const result = pathToToolName("my-custom-tools/calculator.tsx");
|
|
131
|
-
assert.match(result, /^my-custom-tools_calculator_[a-f0-9]{6}$/);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("pathToToolName - custom nested directory", () => {
|
|
135
|
-
const result = pathToToolName("src/my-tools/advanced/converter.tsx");
|
|
136
|
-
assert.match(result, /^src_my-tools_advanced_converter_[a-f0-9]{6}$/);
|
|
137
|
-
});
|