init-xmcp 0.5.6-canary.0 → 0.5.7

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > init-xmcp@0.5.6-canary.0 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
2
+ > init-xmcp@0.5.7 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
3
3
  > tsc
4
4
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { describe, it, beforeEach, afterEach } from "node:test";
2
+ import assert from "node:assert";
3
+ import path from "path";
4
+ import fs from "fs-extra";
5
+ import os from "os";
6
+ import { updateTsConfig } from "../helpers/update-tsconfig.js";
7
+ describe("updateTsConfig", () => {
8
+ let tempDir;
9
+ beforeEach(() => {
10
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "xmcp-tsconfig-"));
11
+ });
12
+ afterEach(() => {
13
+ fs.removeSync(tempDir);
14
+ });
15
+ it("merges alias without removing existing config", () => {
16
+ const tsconfigPath = path.join(tempDir, "tsconfig.json");
17
+ fs.writeJsonSync(tsconfigPath, {
18
+ compilerOptions: {
19
+ strict: true,
20
+ paths: {
21
+ "@app/*": ["./src/*"],
22
+ },
23
+ },
24
+ include: ["src"],
25
+ exclude: ["dist"],
26
+ }, { spaces: 2 });
27
+ updateTsConfig(tempDir);
28
+ const updated = fs.readJsonSync(tsconfigPath);
29
+ assert.strictEqual(updated.compilerOptions.strict, true);
30
+ assert.deepStrictEqual(updated.compilerOptions.paths["@app/*"], ["./src/*"]);
31
+ assert.deepStrictEqual(updated.compilerOptions.paths["@xmcp/*"], ["./.xmcp/*"]);
32
+ assert.deepStrictEqual(updated.exclude, ["dist"]);
33
+ assert.ok(updated.include.includes("src"));
34
+ assert.ok(updated.include.includes("xmcp-env.d.ts"));
35
+ });
36
+ it("creates compilerOptions and paths when missing", () => {
37
+ const tsconfigPath = path.join(tempDir, "tsconfig.json");
38
+ fs.writeJsonSync(tsconfigPath, { include: ["src"] }, { spaces: 2 });
39
+ updateTsConfig(tempDir);
40
+ const updated = fs.readJsonSync(tsconfigPath);
41
+ assert.deepStrictEqual(updated.compilerOptions.paths["@xmcp/*"], ["./.xmcp/*"]);
42
+ assert.ok(updated.include.includes("xmcp-env.d.ts"));
43
+ });
44
+ });
@@ -44,10 +44,6 @@ export const metadata = {
44
44
 
45
45
  // Tool implementation
46
46
  export default async function greet({ name }: InferSchema<typeof schema>) {
47
- const result = \`Hello, \${name}!\`;
48
-
49
- return {
50
- content: [{ type: "text", text: result }],
51
- };
47
+ return \`Hello, \${name}!\`;
52
48
  }
53
49
  `;
@@ -30,6 +30,12 @@ const config: XmcpConfig = {
30
30
  resources: "${resourcesPath}",`;
31
31
  }
32
32
  configContent += `
33
+ },`;
34
+ }
35
+ if (frameworkAdapter === "nextjs") {
36
+ configContent += `
37
+ typescript: {
38
+ skipTypeCheck: true,
33
39
  },`;
34
40
  }
35
41
  configContent += `
@@ -21,23 +21,32 @@ export function updateTsConfig(projectRoot) {
21
21
  console.log(chalk.yellow("No tsconfig.json file found - skipping alias configuration"));
22
22
  return;
23
23
  }
24
- // there's a file, but it's empty - we can add the compiler options and paths
25
- if (!tsconfig.compilerOptions) {
26
- tsconfig.compilerOptions = {};
27
- }
28
- if (!tsconfig.compilerOptions.paths) {
29
- tsconfig.compilerOptions.paths = {};
30
- }
31
- // alias for accessing the handler, otherwise should be pointing to .xmcp/adapter when importing it
32
- if (!tsconfig.compilerOptions.paths["@xmcp/*"]) {
33
- tsconfig.compilerOptions.paths["@xmcp/*"] = ["./.xmcp/*"];
34
- }
35
- if (!tsconfig.include) {
36
- tsconfig.include = [];
37
- }
38
- if (!tsconfig.include.includes("xmcp-env.d.ts")) {
39
- // include xmcp-env.d.ts in the build
40
- tsconfig.include.push("xmcp-env.d.ts");
41
- }
42
- fs.writeJsonSync(tsconfigPath, tsconfig, { spaces: 2 });
24
+ const compilerOptions = tsconfig.compilerOptions && typeof tsconfig.compilerOptions === "object"
25
+ ? tsconfig.compilerOptions
26
+ : {};
27
+ const paths = compilerOptions.paths && typeof compilerOptions.paths === "object"
28
+ ? compilerOptions.paths
29
+ : {};
30
+ const updatedTsconfig = {
31
+ ...tsconfig,
32
+ compilerOptions: {
33
+ ...compilerOptions,
34
+ paths: {
35
+ ...paths,
36
+ "@xmcp/*": ["./.xmcp/*"],
37
+ },
38
+ },
39
+ };
40
+ const includeEntries = Array.isArray(tsconfig.include)
41
+ ? tsconfig.include
42
+ : tsconfig.include
43
+ ? [tsconfig.include]
44
+ : [];
45
+ if (!includeEntries.includes("xmcp-env.d.ts")) {
46
+ updatedTsconfig.include = [...includeEntries, "xmcp-env.d.ts"];
47
+ }
48
+ else if (tsconfig.include) {
49
+ updatedTsconfig.include = tsconfig.include;
50
+ }
51
+ fs.writeJsonSync(tsconfigPath, updatedTsconfig, { spaces: 2 });
43
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "init-xmcp",
3
- "version": "0.5.6-canary.0",
3
+ "version": "0.5.7",
4
4
  "author": {
5
5
  "name": "xmcp",
6
6
  "email": "support@xmcp.dev",
@@ -0,0 +1,60 @@
1
+ import { describe, it, beforeEach, afterEach } from "node:test";
2
+ import assert from "node:assert";
3
+ import path from "path";
4
+ import fs from "fs-extra";
5
+ import os from "os";
6
+ import { updateTsConfig } from "../helpers/update-tsconfig.js";
7
+
8
+ describe("updateTsConfig", () => {
9
+ let tempDir: string;
10
+
11
+ beforeEach(() => {
12
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "xmcp-tsconfig-"));
13
+ });
14
+
15
+ afterEach(() => {
16
+ fs.removeSync(tempDir);
17
+ });
18
+
19
+ it("merges alias without removing existing config", () => {
20
+ const tsconfigPath = path.join(tempDir, "tsconfig.json");
21
+ fs.writeJsonSync(
22
+ tsconfigPath,
23
+ {
24
+ compilerOptions: {
25
+ strict: true,
26
+ paths: {
27
+ "@app/*": ["./src/*"],
28
+ },
29
+ },
30
+ include: ["src"],
31
+ exclude: ["dist"],
32
+ },
33
+ { spaces: 2 }
34
+ );
35
+
36
+ updateTsConfig(tempDir);
37
+
38
+ const updated = fs.readJsonSync(tsconfigPath);
39
+
40
+ assert.strictEqual(updated.compilerOptions.strict, true);
41
+ assert.deepStrictEqual(updated.compilerOptions.paths["@app/*"], ["./src/*"]);
42
+ assert.deepStrictEqual(updated.compilerOptions.paths["@xmcp/*"], ["./.xmcp/*"]);
43
+ assert.deepStrictEqual(updated.exclude, ["dist"]);
44
+ assert.ok(updated.include.includes("src"));
45
+ assert.ok(updated.include.includes("xmcp-env.d.ts"));
46
+ });
47
+
48
+ it("creates compilerOptions and paths when missing", () => {
49
+ const tsconfigPath = path.join(tempDir, "tsconfig.json");
50
+ fs.writeJsonSync(tsconfigPath, { include: ["src"] }, { spaces: 2 });
51
+
52
+ updateTsConfig(tempDir);
53
+
54
+ const updated = fs.readJsonSync(tsconfigPath);
55
+
56
+ assert.deepStrictEqual(updated.compilerOptions.paths["@xmcp/*"], ["./.xmcp/*"]);
57
+ assert.ok(updated.include.includes("xmcp-env.d.ts"));
58
+ });
59
+ });
60
+
@@ -48,10 +48,6 @@ export const metadata = {
48
48
 
49
49
  // Tool implementation
50
50
  export default async function greet({ name }: InferSchema<typeof schema>) {
51
- const result = \`Hello, \${name}!\`;
52
-
53
- return {
54
- content: [{ type: "text", text: result }],
55
- };
51
+ return \`Hello, \${name}!\`;
56
52
  }
57
53
  `;
@@ -44,6 +44,13 @@ const config: XmcpConfig = {
44
44
  },`;
45
45
  }
46
46
 
47
+ if (frameworkAdapter === "nextjs") {
48
+ configContent += `
49
+ typescript: {
50
+ skipTypeCheck: true,
51
+ },`;
52
+ }
53
+
47
54
  configContent += `
48
55
  };
49
56
 
@@ -3,6 +3,12 @@ import fs from "fs-extra";
3
3
  import chalk from "chalk";
4
4
  import { readTsConfigFile } from "../utils/read-config-file.js";
5
5
 
6
+ type TsConfig = {
7
+ compilerOptions?: Record<string, any>;
8
+ include?: string[] | string;
9
+ [key: string]: any;
10
+ };
11
+
6
12
  /**
7
13
  * updates the tsconfig.json file to include the @xmcp/* alias for accessing the handler
8
14
  * @param projectRoot - The root directory of the project
@@ -10,13 +16,15 @@ import { readTsConfigFile } from "../utils/read-config-file.js";
10
16
  */
11
17
  export function updateTsConfig(projectRoot: string) {
12
18
  const tsconfigPath = path.join(projectRoot, "tsconfig.json");
13
-
14
- let tsconfig: any;
19
+
20
+ let tsconfig: TsConfig | undefined;
15
21
  try {
16
22
  tsconfig = readTsConfigFile(tsconfigPath);
17
23
  } catch (error) {
18
24
  console.log(
19
- chalk.yellow(`Failed to parse tsconfig.json: ${error instanceof Error ? error.message : "Unknown error"}`)
25
+ chalk.yellow(
26
+ `Failed to parse tsconfig.json: ${error instanceof Error ? error.message : "Unknown error"}`
27
+ )
20
28
  );
21
29
  return;
22
30
  }
@@ -28,28 +36,38 @@ export function updateTsConfig(projectRoot: string) {
28
36
  return;
29
37
  }
30
38
 
31
- // there's a file, but it's empty - we can add the compiler options and paths
32
- if (!tsconfig.compilerOptions) {
33
- tsconfig.compilerOptions = {};
34
- }
39
+ const compilerOptions =
40
+ tsconfig.compilerOptions && typeof tsconfig.compilerOptions === "object"
41
+ ? tsconfig.compilerOptions
42
+ : {};
35
43
 
36
- if (!tsconfig.compilerOptions.paths) {
37
- tsconfig.compilerOptions.paths = {};
38
- }
44
+ const paths =
45
+ compilerOptions.paths && typeof compilerOptions.paths === "object"
46
+ ? compilerOptions.paths
47
+ : {};
39
48
 
40
- // alias for accessing the handler, otherwise should be pointing to .xmcp/adapter when importing it
41
- if (!tsconfig.compilerOptions.paths["@xmcp/*"]) {
42
- tsconfig.compilerOptions.paths["@xmcp/*"] = ["./.xmcp/*"];
43
- }
49
+ const updatedTsconfig: TsConfig = {
50
+ ...tsconfig,
51
+ compilerOptions: {
52
+ ...compilerOptions,
53
+ paths: {
54
+ ...paths,
55
+ "@xmcp/*": ["./.xmcp/*"],
56
+ },
57
+ },
58
+ };
44
59
 
45
- if (!tsconfig.include) {
46
- tsconfig.include = [];
47
- }
60
+ const includeEntries = Array.isArray(tsconfig.include)
61
+ ? tsconfig.include
62
+ : tsconfig.include
63
+ ? [tsconfig.include]
64
+ : [];
48
65
 
49
- if (!tsconfig.include.includes("xmcp-env.d.ts")) {
50
- // include xmcp-env.d.ts in the build
51
- tsconfig.include.push("xmcp-env.d.ts");
66
+ if (!includeEntries.includes("xmcp-env.d.ts")) {
67
+ updatedTsconfig.include = [...includeEntries, "xmcp-env.d.ts"];
68
+ } else if (tsconfig.include) {
69
+ updatedTsconfig.include = tsconfig.include;
52
70
  }
53
71
 
54
- fs.writeJsonSync(tsconfigPath, tsconfig, { spaces: 2 });
72
+ fs.writeJsonSync(tsconfigPath, updatedTsconfig, { spaces: 2 });
55
73
  }