init-xmcp 0.5.6 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/__tests__/update-tsconfig.test.d.ts +1 -0
- package/dist/__tests__/update-tsconfig.test.js +44 -0
- package/dist/helpers/create-tool.js +1 -5
- package/dist/helpers/generate-config.js +6 -0
- package/dist/helpers/update-tsconfig.js +28 -19
- package/package.json +1 -1
- package/src/__tests__/update-tsconfig.test.ts +60 -0
- package/src/helpers/create-tool.ts +1 -5
- package/src/helpers/generate-config.ts +7 -0
- package/src/helpers/update-tsconfig.ts +39 -21
package/.turbo/turbo-build.log
CHANGED
|
@@ -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
|
-
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
content: [{ type: "text", text: result }],
|
|
51
|
-
};
|
|
47
|
+
return \`Hello, \${name}!\`;
|
|
52
48
|
}
|
|
53
49
|
`;
|
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
@@ -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
|
-
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
content: [{ type: "text", text: result }],
|
|
55
|
-
};
|
|
51
|
+
return \`Hello, \${name}!\`;
|
|
56
52
|
}
|
|
57
53
|
`;
|
|
@@ -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:
|
|
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(
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
const compilerOptions =
|
|
40
|
+
tsconfig.compilerOptions && typeof tsconfig.compilerOptions === "object"
|
|
41
|
+
? tsconfig.compilerOptions
|
|
42
|
+
: {};
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
const paths =
|
|
45
|
+
compilerOptions.paths && typeof compilerOptions.paths === "object"
|
|
46
|
+
? compilerOptions.paths
|
|
47
|
+
: {};
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const updatedTsconfig: TsConfig = {
|
|
50
|
+
...tsconfig,
|
|
51
|
+
compilerOptions: {
|
|
52
|
+
...compilerOptions,
|
|
53
|
+
paths: {
|
|
54
|
+
...paths,
|
|
55
|
+
"@xmcp/*": ["./.xmcp/*"],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
44
59
|
|
|
45
|
-
|
|
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 (!
|
|
50
|
-
|
|
51
|
-
|
|
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,
|
|
72
|
+
fs.writeJsonSync(tsconfigPath, updatedTsconfig, { spaces: 2 });
|
|
55
73
|
}
|