@mastra/deployer-vercel 0.0.1-alpha.26 → 0.0.1-alpha.27

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,11 @@
1
1
  # @mastra/deployer-vercel
2
2
 
3
+ ## 0.0.1-alpha.27
4
+
5
+ ### Patch Changes
6
+
7
+ - 44c7c26: Rebuild
8
+
3
9
  ## 0.0.1-alpha.26
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { MastraDeployer } from '@mastra/core';
2
- export declare class VercelDeployer extends MastraDeployer {
2
+
3
+ declare class VercelDeployer extends MastraDeployer {
3
4
  constructor({ scope, env, projectName }: {
4
5
  env?: Record<string, any>;
5
6
  scope: string;
@@ -22,4 +23,5 @@ export declare class VercelDeployer extends MastraDeployer {
22
23
  dir: string;
23
24
  }): void;
24
25
  }
25
- //# sourceMappingURL=index.d.ts.map
26
+
27
+ export { VercelDeployer };
package/dist/index.js CHANGED
@@ -1,8 +1,140 @@
1
+ import { MastraDeployer } from '@mastra/core';
2
+ import * as child_process from 'child_process';
3
+ import { writeFileSync, readFileSync } from 'fs';
4
+ import { join } from 'path';
1
5
 
2
- 'use strict'
6
+ // src/index.ts
7
+ var VercelDeployer = class extends MastraDeployer {
8
+ constructor({ scope, env, projectName }) {
9
+ super({ scope, env, projectName });
10
+ }
11
+ writeFiles({ dir }) {
12
+ this.writeIndex({ dir });
13
+ writeFileSync(
14
+ join(dir, "vercel.json"),
15
+ JSON.stringify(
16
+ {
17
+ version: 2,
18
+ installCommand: "npm install --omit=dev",
19
+ builds: [
20
+ {
21
+ src: "index.mjs",
22
+ use: "@vercel/node",
23
+ config: { includeFiles: ["**"] }
24
+ }
25
+ ],
26
+ routes: [
27
+ {
28
+ src: "/(.*)",
29
+ dest: "index.mjs"
30
+ }
31
+ ]
32
+ },
33
+ null,
34
+ 2
35
+ )
36
+ );
37
+ }
38
+ getProjectId({ dir }) {
39
+ const projectJsonPath = join(dir, ".vercel", "project.json");
40
+ try {
41
+ const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
42
+ return projectJson.projectId;
43
+ } catch (error) {
44
+ throw new Error("Could not find project ID. Make sure the project has been deployed first.");
45
+ }
46
+ }
47
+ async syncEnv({ scope, dir, token }) {
48
+ const envFiles = this.getEnvFiles();
49
+ const envVars = [];
50
+ for (const file of envFiles) {
51
+ const vars = this.parseEnvFile(file);
52
+ envVars.push(...vars);
53
+ }
54
+ console.log("Syncing environment variables...");
55
+ const vercelEnvVars = envVars.map((envVar) => {
56
+ const [key, value] = envVar.split("=");
57
+ if (!key || !value) {
58
+ throw new Error(`Invalid environment variable format: ${envVar}`);
59
+ }
60
+ return {
61
+ key,
62
+ value,
63
+ target: ["production", "preview", "development"],
64
+ type: "plain"
65
+ };
66
+ });
67
+ try {
68
+ const projectId = this.getProjectId({ dir });
69
+ const response = await fetch(`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${scope}&upsert=true`, {
70
+ method: "POST",
71
+ headers: {
72
+ Authorization: `Bearer ${token}`,
73
+ "Content-Type": "application/json"
74
+ },
75
+ body: JSON.stringify(vercelEnvVars)
76
+ });
77
+ if (!response.ok) {
78
+ const error = await response.json();
79
+ throw new Error(`Failed to sync environment variables: ${error.message}`);
80
+ }
81
+ console.log("\u2713 Successfully synced environment variables");
82
+ } catch (error) {
83
+ if (error instanceof Error) {
84
+ console.error("Failed to sync environment variables:", error.message);
85
+ } else {
86
+ console.error("Failed to sync environment variables:", error);
87
+ }
88
+ throw error;
89
+ }
90
+ }
91
+ async deploy({ dir, token }) {
92
+ const envFiles = this.getEnvFiles();
93
+ const envVars = [];
94
+ for (const file of envFiles) {
95
+ const vars = this.parseEnvFile(file);
96
+ envVars.push(...vars);
97
+ }
98
+ const commandArgs = [
99
+ "--scope",
100
+ this.scope,
101
+ "--cwd",
102
+ dir,
103
+ "deploy",
104
+ "--token",
105
+ token,
106
+ "--yes",
107
+ ...this.projectName ? ["--name", this.projectName] : []
108
+ ];
109
+ for (const envVar of envVars) {
110
+ commandArgs.push("--env", envVar);
111
+ }
112
+ child_process.execSync(`vercel ${commandArgs.join(" ")}`, {
113
+ cwd: dir,
114
+ env: {
115
+ ...this.env,
116
+ PATH: process.env.PATH
117
+ },
118
+ stdio: "inherit"
119
+ });
120
+ console.log("Deployment started on Vercel. You can wait for it to finish or exit this command.");
121
+ if (envVars.length > 0) {
122
+ await this.syncEnv({ scope: this.scope, dir, token });
123
+ } else {
124
+ console.log("\nAdd your ENV vars to .env or your vercel dashboard.\n");
125
+ }
126
+ }
127
+ writeIndex({ dir }) {
128
+ writeFileSync(
129
+ join(dir, "index.mjs"),
130
+ `
131
+ import { handle } from 'hono/vercel'
132
+ import { app } from './hono.mjs';
133
+ export const GET = handle(app);
134
+ export const POST = handle(app);
135
+ `
136
+ );
137
+ }
138
+ };
3
139
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./deployer-vercel.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./deployer-vercel.cjs.development.js')
8
- }
140
+ export { VercelDeployer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-vercel",
3
- "version": "0.0.1-alpha.26",
3
+ "version": "0.0.1-alpha.27",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,6 +25,7 @@
25
25
  "@tsconfig/recommended": "^1.0.7",
26
26
  "@types/node": "^22.9.0",
27
27
  "tsup": "^8.0.1",
28
+ "typescript": "^5.3.3",
28
29
  "vercel": "^39.3.0",
29
30
  "vitest": "^3.0.4"
30
31
  },
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ export class VercelDeployer extends MastraDeployer {
19
19
  constructor({ scope, env, projectName }: { env?: Record<string, any>; scope: string; projectName: string }) {
20
20
  super({ scope, env, projectName });
21
21
  }
22
+
22
23
  writeFiles({ dir }: { dir: string }): void {
23
24
  this.writeIndex({ dir });
24
25