init-xmcp 0.1.12 → 0.1.14-canary.0

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.1.12 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
2
+ > init-xmcp@0.1.14-canary.0 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
3
3
  > tsc
4
4
 
@@ -1,6 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import fs from "fs-extra";
3
3
  import path from "path";
4
+ import { readTsConfigFile } from "../utils/read-config-file.js";
4
5
  export function detectFramework(projectRoot) {
5
6
  // check if project has been initialized with nextjs or default to express
6
7
  const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
@@ -20,11 +21,12 @@ export function detectTypeScript(projectRoot) {
20
21
  // if typescript is in the dependencies, check for tsconfig.json and validate it
21
22
  if (fs.existsSync(path.join(projectRoot, "tsconfig.json"))) {
22
23
  try {
23
- const tsconfigContent = fs.readJsonSync(path.join(projectRoot, "tsconfig.json"));
24
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
25
+ const tsconfigContent = readTsConfigFile(tsconfigPath);
24
26
  return typeof tsconfigContent === "object" && tsconfigContent !== null;
25
27
  }
26
- catch {
27
- console.log(chalk.yellow("Please initialize xmcp within a TypeScript project. Invalid tsconfig.json file"));
28
+ catch (error) {
29
+ console.log(chalk.yellow(`Please initialize xmcp within a TypeScript project. ${error instanceof Error ? error.message : "Invalid tsconfig.json file"}`));
28
30
  return false;
29
31
  }
30
32
  }
@@ -1,6 +1,7 @@
1
1
  import path from "path";
2
2
  import fs from "fs-extra";
3
3
  import chalk from "chalk";
4
+ import { readTsConfigFile } from "../utils/read-config-file.js";
4
5
  /**
5
6
  * updates the tsconfig.json file to include the @xmcp/* alias for accessing the handler
6
7
  * @param projectRoot - The root directory of the project
@@ -8,7 +9,14 @@ import chalk from "chalk";
8
9
  */
9
10
  export function updateTsConfig(projectRoot) {
10
11
  const tsconfigPath = path.join(projectRoot, "tsconfig.json");
11
- const tsconfig = fs.readJsonSync(tsconfigPath);
12
+ let tsconfig;
13
+ try {
14
+ tsconfig = readTsConfigFile(tsconfigPath);
15
+ }
16
+ catch (error) {
17
+ console.log(chalk.yellow(`Failed to parse tsconfig.json: ${error instanceof Error ? error.message : "Unknown error"}`));
18
+ return;
19
+ }
12
20
  if (!tsconfig) {
13
21
  console.log(chalk.yellow("No tsconfig.json file found - skipping alias configuration"));
14
22
  return;
@@ -0,0 +1 @@
1
+ export declare function readTsConfigFile<T = any>(filePath: string): T;
@@ -0,0 +1,8 @@
1
+ import ts from "typescript";
2
+ export function readTsConfigFile(filePath) {
3
+ const { config, error } = ts.readConfigFile(filePath, ts.sys.readFile);
4
+ if (error) {
5
+ throw new Error(`Invalid tsconfig.json → ${ts.flattenDiagnosticMessageText(error.messageText, "\n")}`);
6
+ }
7
+ return config;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "init-xmcp",
3
- "version": "0.1.12",
3
+ "version": "0.1.14-canary.0",
4
4
  "author": {
5
5
  "name": "Basement Studio",
6
6
  "email": "hello@basement.studio",
@@ -48,6 +48,9 @@
48
48
  "inquirer": "^9.2.12",
49
49
  "ora": "^7.0.1"
50
50
  },
51
+ "peerDependencies": {
52
+ "typescript": "^5.0.0"
53
+ },
51
54
  "devDependencies": {
52
55
  "@types/fs-extra": "^11.0.4",
53
56
  "@types/inquirer": "^9.0.7",
@@ -1,6 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import fs from "fs-extra";
3
3
  import path from "path";
4
+ import { readTsConfigFile } from "../utils/read-config-file.js";
4
5
 
5
6
  export type Framework = "nextjs" | "express";
6
7
 
@@ -38,14 +39,13 @@ export function detectTypeScript(projectRoot: string): boolean {
38
39
  // if typescript is in the dependencies, check for tsconfig.json and validate it
39
40
  if (fs.existsSync(path.join(projectRoot, "tsconfig.json"))) {
40
41
  try {
41
- const tsconfigContent = fs.readJsonSync(
42
- path.join(projectRoot, "tsconfig.json")
43
- );
42
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
43
+ const tsconfigContent = readTsConfigFile(tsconfigPath);
44
44
  return typeof tsconfigContent === "object" && tsconfigContent !== null;
45
- } catch {
45
+ } catch (error) {
46
46
  console.log(
47
47
  chalk.yellow(
48
- "Please initialize xmcp within a TypeScript project. Invalid tsconfig.json file"
48
+ `Please initialize xmcp within a TypeScript project. ${error instanceof Error ? error.message : "Invalid tsconfig.json file"}`
49
49
  )
50
50
  );
51
51
  return false;
@@ -1,6 +1,7 @@
1
1
  import path from "path";
2
2
  import fs from "fs-extra";
3
3
  import chalk from "chalk";
4
+ import { readTsConfigFile } from "../utils/read-config-file.js";
4
5
 
5
6
  /**
6
7
  * updates the tsconfig.json file to include the @xmcp/* alias for accessing the handler
@@ -9,7 +10,16 @@ import chalk from "chalk";
9
10
  */
10
11
  export function updateTsConfig(projectRoot: string) {
11
12
  const tsconfigPath = path.join(projectRoot, "tsconfig.json");
12
- const tsconfig = fs.readJsonSync(tsconfigPath);
13
+
14
+ let tsconfig: any;
15
+ try {
16
+ tsconfig = readTsConfigFile(tsconfigPath);
17
+ } catch (error) {
18
+ console.log(
19
+ chalk.yellow(`Failed to parse tsconfig.json: ${error instanceof Error ? error.message : "Unknown error"}`)
20
+ );
21
+ return;
22
+ }
13
23
 
14
24
  if (!tsconfig) {
15
25
  console.log(
@@ -0,0 +1,11 @@
1
+ import ts from "typescript";
2
+
3
+ export function readTsConfigFile<T = any>(filePath: string): T {
4
+ const { config, error } = ts.readConfigFile(filePath, ts.sys.readFile);
5
+ if (error) {
6
+ throw new Error(
7
+ `Invalid tsconfig.json → ${ts.flattenDiagnosticMessageText(error.messageText, "\n")}`
8
+ );
9
+ }
10
+ return config as T;
11
+ }