create-mastra 1.0.0-beta.2 → 1.0.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # create-mastra
2
2
 
3
+ ## 1.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Add timeTravel APIs and add timeTravel feature to studio ([#10361](https://github.com/mastra-ai/mastra/pull/10361))
8
+
9
+ ## 1.0.0-beta.3
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: detect bun runtime and cleanup on failure ([#10242](https://github.com/mastra-ai/mastra/pull/10242))
14
+
3
15
  ## 1.0.0-beta.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -7,12 +7,12 @@ import os from 'node:os';
7
7
  import path3, { dirname } from 'node:path';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { PostHog } from 'posthog-node';
10
+ import fs4 from 'node:fs/promises';
10
11
  import util, { stripVTControlCharacters } from 'node:util';
11
12
  import y$1, { stdout, stdin } from 'node:process';
12
13
  import * as g from 'node:readline';
13
14
  import g__default from 'node:readline';
14
15
  import { Writable } from 'node:stream';
15
- import fs4 from 'node:fs/promises';
16
16
  import child_process from 'node:child_process';
17
17
  import tty from 'node:tty';
18
18
  import fsExtra, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
@@ -1188,7 +1188,7 @@ var PinoLogger = class extends MastraLogger {
1188
1188
  };
1189
1189
 
1190
1190
  var package_default = {
1191
- version: "1.0.0-beta.2"};
1191
+ version: "1.0.0-beta.4"};
1192
1192
  function getPackageManagerAddCommand(pm) {
1193
1193
  switch (pm) {
1194
1194
  case "npm":
@@ -2128,6 +2128,9 @@ This means the Mastra docs MCP server will be available in all your Windsurf pro
2128
2128
  function getPackageManager() {
2129
2129
  const userAgent = process.env.npm_config_user_agent || "";
2130
2130
  const execPath = process.env.npm_execpath || "";
2131
+ if (userAgent.includes("bun")) {
2132
+ return "bun";
2133
+ }
2131
2134
  if (userAgent.includes("yarn")) {
2132
2135
  return "yarn";
2133
2136
  }
@@ -2137,6 +2140,9 @@ function getPackageManager() {
2137
2140
  if (userAgent.includes("npm")) {
2138
2141
  return "npm";
2139
2142
  }
2143
+ if (execPath.includes("bun")) {
2144
+ return "bun";
2145
+ }
2140
2146
  if (execPath.includes("yarn")) {
2141
2147
  return "yarn";
2142
2148
  }
@@ -2443,6 +2449,32 @@ var execWithTimeout = async (command, timeoutMs) => {
2443
2449
  throw error;
2444
2450
  }
2445
2451
  };
2452
+ async function getInitCommand(pm) {
2453
+ switch (pm) {
2454
+ case "npm":
2455
+ return "npm init -y";
2456
+ case "pnpm":
2457
+ return "pnpm init";
2458
+ case "yarn":
2459
+ return "yarn init -y";
2460
+ case "bun":
2461
+ return "bun init -y";
2462
+ default:
2463
+ return "npm init -y";
2464
+ }
2465
+ }
2466
+ async function initializePackageJson(pm) {
2467
+ const initCommand = await getInitCommand(pm);
2468
+ await exec3(initCommand);
2469
+ const packageJsonPath = path3.join(process.cwd(), "package.json");
2470
+ const packageJson = JSON.parse(await fs4.readFile(packageJsonPath, "utf-8"));
2471
+ packageJson.type = "module";
2472
+ packageJson.engines = {
2473
+ ...packageJson.engines,
2474
+ node: ">=22.13.0"
2475
+ };
2476
+ await fs4.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
2477
+ }
2446
2478
  async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
2447
2479
  let installCommand = getPackageManagerAddCommand(pm);
2448
2480
  if (isDev) {
@@ -2497,10 +2529,13 @@ var createMastraProject = async ({
2497
2529
  });
2498
2530
  }
2499
2531
  const s2 = Y();
2532
+ const originalCwd = process.cwd();
2533
+ let projectPath = null;
2500
2534
  try {
2501
2535
  s2.start("Creating project");
2502
2536
  try {
2503
2537
  await fs4.mkdir(projectName);
2538
+ projectPath = path3.resolve(originalCwd, projectName);
2504
2539
  } catch (error) {
2505
2540
  if (error instanceof Error && "code" in error && error.code === "EEXIST") {
2506
2541
  s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
@@ -2515,9 +2550,7 @@ var createMastraProject = async ({
2515
2550
  const installCommand = getPackageManagerAddCommand(pm);
2516
2551
  s2.message("Initializing project structure");
2517
2552
  try {
2518
- await exec3(`npm init -y`);
2519
- await exec3(`npm pkg set type="module"`);
2520
- await exec3(`npm pkg set engines.node=">=20.9.0"`);
2553
+ await initializePackageJson(pm);
2521
2554
  const depsService = new DepsService();
2522
2555
  await depsService.addScriptsToPackageJson({
2523
2556
  dev: "mastra dev",
@@ -2596,6 +2629,16 @@ var createMastraProject = async ({
2596
2629
  s2.stop();
2597
2630
  const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
2598
2631
  xe(`Project creation failed: ${errorMessage}`);
2632
+ if (projectPath && fs3__default__default.existsSync(projectPath)) {
2633
+ try {
2634
+ process.chdir(originalCwd);
2635
+ await fs4.rm(projectPath, { recursive: true, force: true });
2636
+ } catch (cleanupError) {
2637
+ console.error(
2638
+ `Warning: Failed to clean up project directory: ${cleanupError instanceof Error ? cleanupError.message : "Unknown error"}`
2639
+ );
2640
+ }
2641
+ }
2599
2642
  process.exit(1);
2600
2643
  }
2601
2644
  };
@@ -2794,6 +2837,7 @@ async function createFromTemplate(args) {
2794
2837
  }
2795
2838
  llmProvider = providerResponse;
2796
2839
  }
2840
+ let projectPath = null;
2797
2841
  try {
2798
2842
  const analytics = args.injectedAnalytics || getAnalytics();
2799
2843
  if (analytics) {
@@ -2811,7 +2855,7 @@ async function createFromTemplate(args) {
2811
2855
  const isBeta = version$1?.includes("beta") ?? false;
2812
2856
  const isMastraTemplate = selectedTemplate.githubUrl.includes("github.com/mastra-ai/");
2813
2857
  const branch = isBeta && isMastraTemplate ? "beta" : void 0;
2814
- const projectPath = await cloneTemplate({
2858
+ projectPath = await cloneTemplate({
2815
2859
  template: selectedTemplate,
2816
2860
  projectName,
2817
2861
  branch,
@@ -2826,6 +2870,17 @@ async function createFromTemplate(args) {
2826
2870
  `);
2827
2871
  postCreate({ projectName });
2828
2872
  } catch (error) {
2873
+ if (projectPath) {
2874
+ try {
2875
+ if (fs3__default__default.existsSync(projectPath)) {
2876
+ await fs4.rm(projectPath, { recursive: true, force: true });
2877
+ }
2878
+ } catch (cleanupError) {
2879
+ console.error(
2880
+ `Warning: Failed to clean up project directory: ${cleanupError instanceof Error ? cleanupError.message : "Unknown error"}`
2881
+ );
2882
+ }
2883
+ }
2829
2884
  M.error(`Failed to create project from template: ${error instanceof Error ? error.message : "Unknown error"}`);
2830
2885
  throw error;
2831
2886
  }