@mastra/deployer-vercel 0.0.1-alpha.34 → 0.0.1-alpha.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,254 +1,5 @@
1
1
  # @mastra/deployer-vercel
2
2
 
3
- ## 0.0.1-alpha.34
4
-
5
- ### Patch Changes
6
-
7
- - 38b7f66: Update deployer logic
8
- - Updated dependencies [2f17a5f]
9
- - Updated dependencies [0696eeb]
10
- - Updated dependencies [cb290ee]
11
- - Updated dependencies [b4d7416]
12
- - Updated dependencies [38b7f66]
13
- - @mastra/core@0.2.0-alpha.84
14
- - @mastra/deployer@0.0.1-alpha.29
15
-
16
- ## 0.0.1-alpha.33
17
-
18
- ### Patch Changes
19
-
20
- - 9625602: Use mastra core splitted bundles in other packages
21
- - Updated dependencies [2ab57d6]
22
- - Updated dependencies [30322ce]
23
- - Updated dependencies [78eec7c]
24
- - Updated dependencies [9625602]
25
- - Updated dependencies [8769a62]
26
- - @mastra/deployer@0.0.1-alpha.28
27
- - @mastra/core@0.2.0-alpha.83
28
-
29
- ## 0.0.1-alpha.32
30
-
31
- ### Patch Changes
32
-
33
- - Updated dependencies [73d112c]
34
- - Updated dependencies [ac8c61a]
35
- - @mastra/deployer@0.0.1-alpha.27
36
- - @mastra/core@0.1.27-alpha.82
37
-
38
- ## 0.0.1-alpha.31
39
-
40
- ### Patch Changes
41
-
42
- - Updated dependencies [9fb3039]
43
- - @mastra/core@0.1.27-alpha.81
44
- - @mastra/deployer@0.0.1-alpha.26
45
-
46
- ## 0.0.1-alpha.30
47
-
48
- ### Patch Changes
49
-
50
- - 327ece7: Updates for ts versions
51
- - Updated dependencies [327ece7]
52
- - @mastra/core@0.1.27-alpha.80
53
- - @mastra/deployer@0.0.1-alpha.25
54
-
55
- ## 0.0.1-alpha.29
56
-
57
- ### Patch Changes
58
-
59
- - Updated dependencies [21fe536]
60
- - @mastra/core@0.1.27-alpha.79
61
- - @mastra/deployer@0.0.1-alpha.24
62
-
63
- ## 0.0.1-alpha.28
64
-
65
- ### Patch Changes
66
-
67
- - Updated dependencies [88f18d7]
68
- - @mastra/deployer@0.0.1-alpha.23
69
-
70
- ## 0.0.1-alpha.27
71
-
72
- ### Patch Changes
73
-
74
- - 44c7c26: Rebuild
75
-
76
- ## 0.0.1-alpha.26
77
-
78
- ### Patch Changes
79
-
80
- - Updated dependencies [685108a]
81
- - Updated dependencies [685108a]
82
- - @mastra/deployer@0.0.1-alpha.22
83
- - @mastra/core@0.1.27-alpha.78
84
-
85
- ## 0.0.1-alpha.25
86
-
87
- ### Patch Changes
88
-
89
- - 2b75edf: mastra deployers tsup bundling
90
- - Updated dependencies [8105fae]
91
- - Updated dependencies [cfb966f]
92
- - @mastra/core@0.1.27-alpha.77
93
- - @mastra/deployer@0.0.1-alpha.21
94
-
95
- ## 0.0.1-alpha.24
96
-
97
- ### Patch Changes
98
-
99
- - Updated dependencies [ae7bf94]
100
- - Updated dependencies [ae7bf94]
101
- - @mastra/deployer@0.0.1-alpha.20
102
- - @mastra/core@0.1.27-alpha.76
103
-
104
- ## 0.0.1-alpha.23
105
-
106
- ### Patch Changes
107
-
108
- - Updated dependencies [23dcb23]
109
- - Updated dependencies [7064554]
110
- - @mastra/core@0.1.27-alpha.75
111
- - @mastra/deployer@0.0.1-alpha.19
112
-
113
- ## 0.0.1-alpha.22
114
-
115
- ### Patch Changes
116
-
117
- - Updated dependencies [7b87567]
118
- - @mastra/core@0.1.27-alpha.74
119
- - @mastra/deployer@0.0.1-alpha.18
120
-
121
- ## 0.0.1-alpha.21
122
-
123
- ### Patch Changes
124
-
125
- - Updated dependencies [3427b95]
126
- - @mastra/core@0.1.27-alpha.73
127
- - @mastra/deployer@0.0.1-alpha.17
128
-
129
- ## 0.0.1-alpha.20
130
-
131
- ### Patch Changes
132
-
133
- - Updated dependencies [e4d4ede]
134
- - Updated dependencies [06b2c0a]
135
- - @mastra/core@0.1.27-alpha.72
136
- - @mastra/deployer@0.0.1-alpha.16
137
-
138
- ## 0.0.1-alpha.19
139
-
140
- ### Patch Changes
141
-
142
- - Updated dependencies [d9c8dd0]
143
- - @mastra/deployer@0.0.1-alpha.15
144
- - @mastra/core@0.1.27-alpha.71
145
-
146
- ## 0.0.1-alpha.18
147
-
148
- ### Patch Changes
149
-
150
- - Updated dependencies [ad2cd74]
151
- - @mastra/deployer@0.0.1-alpha.14
152
-
153
- ## 0.0.1-alpha.17
154
-
155
- ### Patch Changes
156
-
157
- - Updated dependencies [a1774e7]
158
- - @mastra/deployer@0.0.1-alpha.13
159
-
160
- ## 0.0.1-alpha.16
161
-
162
- ### Patch Changes
163
-
164
- - Updated dependencies [28dceab]
165
- - @mastra/deployer@0.0.1-alpha.12
166
-
167
- ## 0.0.1-alpha.15
168
-
169
- ### Patch Changes
170
-
171
- - bdaf834: publish packages
172
- - Updated dependencies [bdaf834]
173
- - @mastra/deployer@0.0.1-alpha.11
174
-
175
- ## 0.0.1-alpha.14
176
-
177
- ### Patch Changes
178
-
179
- - Updated dependencies [dd6d87f]
180
- - Updated dependencies [04434b6]
181
- - @mastra/core@0.1.27-alpha.70
182
- - @mastra/deployer@0.0.1-alpha.10
183
-
184
- ## 0.0.1-alpha.13
185
-
186
- ### Patch Changes
187
-
188
- - Updated dependencies [9066f95]
189
- - @mastra/deployer@0.0.1-alpha.9
190
-
191
- ## 0.0.1-alpha.12
192
-
193
- ### Patch Changes
194
-
195
- - 0d5a03d: Vector store modules
196
-
197
- ## 0.0.1-alpha.11
198
-
199
- ### Patch Changes
200
-
201
- - Updated dependencies [b425845]
202
- - @mastra/deployer@0.0.1-alpha.8
203
-
204
- ## 0.0.1-alpha.10
205
-
206
- ### Patch Changes
207
-
208
- - Updated dependencies [1944807]
209
- - Updated dependencies [9ade36e]
210
- - @mastra/deployer@0.0.1-alpha.7
211
- - @mastra/core@0.1.27-alpha.69
212
-
213
- ## 0.0.1-alpha.9
214
-
215
- ### Patch Changes
216
-
217
- - Updated dependencies [291fe57]
218
- - Updated dependencies [1a41fbf]
219
- - @mastra/deployer@0.0.1-alpha.6
220
-
221
- ## 0.0.1-alpha.8
222
-
223
- ### Patch Changes
224
-
225
- - Updated dependencies [0be7181]
226
- - Updated dependencies [0be7181]
227
- - @mastra/core@0.1.27-alpha.68
228
- - @mastra/deployer@0.0.1-alpha.5
229
-
230
- ## 0.0.1-alpha.7
231
-
232
- ### Patch Changes
233
-
234
- - Updated dependencies [7babd5c]
235
- - @mastra/deployer@0.0.1-alpha.4
236
-
237
- ## 0.0.1-alpha.6
238
-
239
- ### Patch Changes
240
-
241
- - Updated dependencies [c8ff2f5]
242
- - Updated dependencies [a291824]
243
- - @mastra/core@0.1.27-alpha.67
244
- - @mastra/deployer@0.0.1-alpha.3
245
-
246
- ## 0.0.1-alpha.5
247
-
248
- ### Patch Changes
249
-
250
- - 88600bc: Deployer fixes
251
-
252
3
  ## 0.0.1-alpha.4
253
4
 
254
5
  ### Patch Changes
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@mastra/deployer-vercel",
3
- "version": "0.0.1-alpha.34",
3
+ "version": "0.0.1-alpha.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
+ "module": "dist/deployer-vercel.esm.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/deployer-vercel.esm.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
12
19
  },
13
20
  "./package.json": "./package.json"
14
21
  },
@@ -16,24 +23,23 @@
16
23
  "author": "",
17
24
  "license": "ISC",
18
25
  "dependencies": {
19
- "@rollup/plugin-virtual": "^3.0.2",
20
- "fs-extra": "^11.2.0",
21
- "@mastra/core": "0.2.0-alpha.84",
22
- "@mastra/deployer": "0.0.1-alpha.29"
26
+ "@mastra/deployer": "0.0.1-alpha.2",
27
+ "@mastra/core": "0.1.27-alpha.66"
23
28
  },
24
29
  "devDependencies": {
25
30
  "@babel/preset-env": "^7.26.0",
26
31
  "@babel/preset-typescript": "^7.26.0",
27
32
  "@tsconfig/recommended": "^1.0.7",
33
+ "@types/jsdom": "^21.1.7",
28
34
  "@types/node": "^22.9.0",
29
- "tsup": "^8.0.1",
30
- "typescript": "^5.3.3",
31
- "vercel": "^39.3.0",
32
- "vitest": "^3.0.4"
35
+ "@types/pg": "^8.11.10",
36
+ "dts-cli": "^2.0.5",
37
+ "vitest": "^2.1.8",
38
+ "vercel": "^39.3.0"
33
39
  },
34
40
  "scripts": {
35
- "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
36
- "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
41
+ "build": "dts build",
42
+ "build:dev": "dts watch",
37
43
  "test": "vitest run"
38
44
  }
39
45
  }
package/src/index.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { Deployer } from '@mastra/deployer';
2
- import { getBundler } from '@mastra/deployer/build';
3
- import virtual from '@rollup/plugin-virtual';
1
+ import { MastraDeployer } from '@mastra/core';
4
2
  import * as child_process from 'child_process';
5
3
  import { readFileSync, writeFileSync } from 'fs';
6
4
  import { join } from 'path';
7
- import process from 'process';
8
5
 
9
6
  interface EnvVar {
10
7
  key: string;
@@ -18,22 +15,15 @@ interface VercelError {
18
15
  code: string;
19
16
  }
20
17
 
21
- export class VercelDeployer extends Deployer {
22
- private teamId: string;
23
- private projectName: string;
24
- private token: string;
25
-
26
- constructor({ teamId, projectName, token }: { teamId: string; projectName: string; token: string }) {
27
- super({ name: 'VERCEL' });
28
-
29
- this.teamId = teamId;
30
- this.projectName = projectName;
31
- this.token = token;
18
+ export class VercelDeployer extends MastraDeployer {
19
+ constructor({ scope, env, projectName }: { env?: Record<string, any>; scope: string; projectName: string }) {
20
+ super({ scope, env, projectName });
32
21
  }
22
+ writeFiles({ dir }: { dir: string }): void {
23
+ this.writeIndex({ dir });
33
24
 
34
- writeFiles(outputDirectory: string): void {
35
25
  writeFileSync(
36
- join(outputDirectory, 'vercel.json'),
26
+ join(dir, 'vercel.json'),
37
27
  JSON.stringify(
38
28
  {
39
29
  version: 2,
@@ -68,15 +58,23 @@ export class VercelDeployer extends Deployer {
68
58
  }
69
59
  }
70
60
 
71
- private async syncEnv(envVars: Map<string, string>) {
61
+ async syncEnv({ scope, dir, token }: { token: string; dir: string; scope: string }) {
62
+ const envFiles = this.getEnvFiles();
63
+ const envVars: string[] = [];
64
+
65
+ for (const file of envFiles) {
66
+ const vars = this.parseEnvFile(file);
67
+ envVars.push(...vars);
68
+ }
69
+
72
70
  console.log('Syncing environment variables...');
73
71
 
74
72
  // Transform env vars into the format expected by Vercel API
75
- const vercelEnvVars: EnvVar[] = Array.from(envVars.entries()).map(([key, value]) => {
73
+ const vercelEnvVars: EnvVar[] = envVars.map(envVar => {
74
+ const [key, value] = envVar.split('=');
76
75
  if (!key || !value) {
77
- throw new Error(`Invalid environment variable format: ${key || value}`);
76
+ throw new Error(`Invalid environment variable format: ${envVar}`);
78
77
  }
79
-
80
78
  return {
81
79
  key,
82
80
  value,
@@ -86,19 +84,16 @@ export class VercelDeployer extends Deployer {
86
84
  });
87
85
 
88
86
  try {
89
- const projectId = this.getProjectId({ dir: process.cwd() });
87
+ const projectId = this.getProjectId({ dir });
90
88
 
91
- const response = await fetch(
92
- `https://api.vercel.com/v10/projects/${projectId}/env?teamId=${this.teamId}&upsert=true`,
93
- {
94
- method: 'POST',
95
- headers: {
96
- Authorization: `Bearer ${this.token}`,
97
- 'Content-Type': 'application/json',
98
- },
99
- body: JSON.stringify(vercelEnvVars),
89
+ const response = await fetch(`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${scope}&upsert=true`, {
90
+ method: 'POST',
91
+ headers: {
92
+ Authorization: `Bearer ${token}`,
93
+ 'Content-Type': 'application/json',
100
94
  },
101
- );
95
+ body: JSON.stringify(vercelEnvVars),
96
+ });
102
97
 
103
98
  if (!response.ok) {
104
99
  const error = (await response.json()) as VercelError;
@@ -116,70 +111,63 @@ export class VercelDeployer extends Deployer {
116
111
  }
117
112
  }
118
113
 
119
- async prepare(outputDirectory: string): Promise<void> {
120
- await super.prepare(outputDirectory);
121
- await this.writeFiles(outputDirectory);
122
- }
123
-
124
- private getEntry(): string {
125
- return `
126
- import { handle } from 'hono/vercel'
127
- import { mastra } from '#mastra';
128
- import { createHonoServer } from '#server';
129
-
130
- const app = await createHonoServer(mastra);
131
-
132
- export const GET = handle(app);
133
- export const POST = handle(app);
134
- `;
135
- }
136
-
137
- async bundle(mastraDir: string, outputDirectory: string): Promise<void> {
138
- const bundler = await getBundler({
139
- input: '#entry',
140
- plugins: [virtual({ '#entry': this.getEntry() })],
141
- });
142
-
143
- await bundler.write({
144
- inlineDynamicImports: true,
145
- file: `${outputDirectory}/index.mjs`,
146
- format: 'es',
147
- });
148
- }
114
+ async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
115
+ // Get env vars for initial deployment
116
+ const envFiles = this.getEnvFiles();
117
+ const envVars: string[] = [];
149
118
 
150
- async deploy(outputDirectory: string): Promise<void> {
151
- const envVars = await this.loadEnvVars();
119
+ for (const file of envFiles) {
120
+ const vars = this.parseEnvFile(file);
121
+ envVars.push(...vars);
122
+ }
152
123
 
153
124
  // Create the command array with base arguments
154
125
  const commandArgs = [
155
126
  '--scope',
156
- this.teamId as string,
127
+ this.scope as string,
157
128
  '--cwd',
158
- outputDirectory,
159
- '--token',
160
- this.token,
129
+ dir,
161
130
  'deploy',
131
+ '--token',
132
+ token,
162
133
  '--yes',
163
134
  ...(this.projectName ? ['--name', this.projectName] : []),
164
135
  ];
165
136
 
137
+ // Add env vars to initial deployment
138
+ for (const envVar of envVars) {
139
+ commandArgs.push('--env', envVar);
140
+ }
141
+
166
142
  // Run the Vercel deploy command
167
- child_process.execSync(`npx vercel ${commandArgs.join(' ')}`, {
168
- cwd: outputDirectory,
143
+ child_process.execSync(`vercel ${commandArgs.join(' ')}`, {
144
+ cwd: dir,
169
145
  env: {
170
- // ...this.env,
146
+ ...this.env,
171
147
  PATH: process.env.PATH,
172
148
  },
173
149
  stdio: 'inherit',
174
150
  });
175
151
 
176
- this.logger.info('Deployment started on Vercel. You can wait for it to finish or exit this command.');
152
+ console.log('Deployment started on Vercel. You can wait for it to finish or exit this command.');
177
153
 
178
- if (envVars.size > 0) {
154
+ if (envVars.length > 0) {
179
155
  // Sync environment variables for future deployments
180
- await this.syncEnv(envVars);
156
+ await this.syncEnv({ scope: this.scope, dir, token });
181
157
  } else {
182
- this.logger.info('\nAdd your ENV vars to .env or your vercel dashboard.\n');
158
+ console.log('\nAdd your ENV vars to .env or your vercel dashboard.\n');
183
159
  }
184
160
  }
161
+
162
+ writeIndex({ dir }: { dir: string }): void {
163
+ writeFileSync(
164
+ join(dir, 'index.mjs'),
165
+ `
166
+ import { handle } from 'hono/vercel'
167
+ import { app } from './hono.mjs';
168
+ export const GET = handle(app);
169
+ export const POST = handle(app);
170
+ `,
171
+ );
172
+ }
185
173
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,10 @@
1
1
  {
2
- "extends": "../../tsconfig.node.json",
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "moduleResolution": "bundler",
5
+ "outDir": "./dist",
6
+ "rootDir": "./src"
7
+ },
3
8
  "include": ["src/**/*"],
4
9
  "exclude": ["node_modules", "**/*.test.ts"]
5
10
  }
package/vitest.config.ts CHANGED
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- environment: 'node',
5
+ globals: true,
6
6
  include: ['src/**/*.test.ts'],
7
7
  },
8
8
  });
package/README.md DELETED
@@ -1,95 +0,0 @@
1
- # @mastra/deployer-vercel
2
-
3
- A Vercel deployer for Mastra applications.
4
-
5
- ## Features
6
-
7
- - Deploy Mastra applications to Vercel
8
- - Zero-configuration serverless deployments
9
- - Automatic environment variable synchronization
10
- - Support for production, preview, and development environments
11
- - Instant global deployments with Edge Functions
12
-
13
- ## Installation
14
-
15
- ```bash
16
- pnpm add @mastra/deployer-vercel
17
- ```
18
-
19
- ## Usage
20
-
21
- The Vercel deployer is used as part of the Mastra framework:
22
-
23
- ```typescript
24
- import { Mastra } from '@mastra/core';
25
- import { VercelDeployer } from '@mastra/deployer-vercel';
26
-
27
- const deployer = new VercelDeployer({
28
- scope: 'your-team-id',
29
- projectName: 'your-project-name',
30
- });
31
-
32
- const mastra = new Mastra({
33
- deployer,
34
- // ... other Mastra configuration options
35
- });
36
- ```
37
-
38
- ## Configuration
39
-
40
- ### Constructor Options
41
-
42
- - `scope` (required): Your Vercel team ID or username
43
- - `projectName`: Name of your Vercel project (will be created if it doesn't exist)
44
-
45
- ## Project Structure
46
-
47
- The deployer creates:
48
-
49
- ```
50
- your-project/
51
- ├── vercel.json # Deployment configuration
52
- └── index.mjs # Application entry point
53
- ```
54
-
55
- ### vercel.json Configuration
56
-
57
- Default configuration:
58
-
59
- ```json
60
- {
61
- "version": 2,
62
- "installCommand": "npm install --omit=dev",
63
- "builds": [
64
- {
65
- "src": "index.mjs",
66
- "use": "@vercel/node",
67
- "config": {
68
- "includeFiles": ["**"]
69
- }
70
- }
71
- ],
72
- "routes": [
73
- {
74
- "src": "/(.*)",
75
- "dest": "index.mjs"
76
- }
77
- ]
78
- }
79
- ```
80
-
81
- ## Environment Variables
82
-
83
- Environment variables are handled automatically through:
84
-
85
- - `.env` files in your project
86
- - Environment variables passed through the Mastra configuration
87
- - Vercel's environment variable UI
88
-
89
- ## Deployment Process
90
-
91
- The deployer:
92
-
93
- 1. Configures your project with the necessary files
94
- 2. Deploys to Vercel using the CLI
95
- 3. Synchronizes environment variables for future deployments
package/dist/index.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { Deployer } from '@mastra/deployer';
2
-
3
- declare class VercelDeployer extends Deployer {
4
- private teamId;
5
- private projectName;
6
- private token;
7
- constructor({ teamId, projectName, token }: {
8
- teamId: string;
9
- projectName: string;
10
- token: string;
11
- });
12
- writeFiles(outputDirectory: string): void;
13
- private getProjectId;
14
- private syncEnv;
15
- prepare(outputDirectory: string): Promise<void>;
16
- private getEntry;
17
- bundle(mastraDir: string, outputDirectory: string): Promise<void>;
18
- deploy(outputDirectory: string): Promise<void>;
19
- }
20
-
21
- export { VercelDeployer };
package/dist/index.js DELETED
@@ -1,152 +0,0 @@
1
- import { Deployer } from '@mastra/deployer';
2
- import { getBundler } from '@mastra/deployer/build';
3
- import virtual from '@rollup/plugin-virtual';
4
- import * as child_process from 'child_process';
5
- import { writeFileSync, readFileSync } from 'fs';
6
- import { join } from 'path';
7
- import process from 'process';
8
-
9
- // src/index.ts
10
- var VercelDeployer = class extends Deployer {
11
- teamId;
12
- projectName;
13
- token;
14
- constructor({ teamId, projectName, token }) {
15
- super({ name: "VERCEL" });
16
- this.teamId = teamId;
17
- this.projectName = projectName;
18
- this.token = token;
19
- }
20
- writeFiles(outputDirectory) {
21
- writeFileSync(
22
- join(outputDirectory, "vercel.json"),
23
- JSON.stringify(
24
- {
25
- version: 2,
26
- installCommand: "npm install --omit=dev",
27
- builds: [
28
- {
29
- src: "index.mjs",
30
- use: "@vercel/node",
31
- config: { includeFiles: ["**"] }
32
- }
33
- ],
34
- routes: [
35
- {
36
- src: "/(.*)",
37
- dest: "index.mjs"
38
- }
39
- ]
40
- },
41
- null,
42
- 2
43
- )
44
- );
45
- }
46
- getProjectId({ dir }) {
47
- const projectJsonPath = join(dir, ".vercel", "project.json");
48
- try {
49
- const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
50
- return projectJson.projectId;
51
- } catch (error) {
52
- throw new Error("Could not find project ID. Make sure the project has been deployed first.");
53
- }
54
- }
55
- async syncEnv(envVars) {
56
- console.log("Syncing environment variables...");
57
- const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
58
- if (!key || !value) {
59
- throw new Error(`Invalid environment variable format: ${key || value}`);
60
- }
61
- return {
62
- key,
63
- value,
64
- target: ["production", "preview", "development"],
65
- type: "plain"
66
- };
67
- });
68
- try {
69
- const projectId = this.getProjectId({ dir: process.cwd() });
70
- const response = await fetch(
71
- `https://api.vercel.com/v10/projects/${projectId}/env?teamId=${this.teamId}&upsert=true`,
72
- {
73
- method: "POST",
74
- headers: {
75
- Authorization: `Bearer ${this.token}`,
76
- "Content-Type": "application/json"
77
- },
78
- body: JSON.stringify(vercelEnvVars)
79
- }
80
- );
81
- if (!response.ok) {
82
- const error = await response.json();
83
- throw new Error(`Failed to sync environment variables: ${error.message}`);
84
- }
85
- console.log("\u2713 Successfully synced environment variables");
86
- } catch (error) {
87
- if (error instanceof Error) {
88
- console.error("Failed to sync environment variables:", error.message);
89
- } else {
90
- console.error("Failed to sync environment variables:", error);
91
- }
92
- throw error;
93
- }
94
- }
95
- async prepare(outputDirectory) {
96
- await super.prepare(outputDirectory);
97
- await this.writeFiles(outputDirectory);
98
- }
99
- getEntry() {
100
- return `
101
- import { handle } from 'hono/vercel'
102
- import { mastra } from '#mastra';
103
- import { createHonoServer } from '#server';
104
-
105
- const app = await createHonoServer(mastra);
106
-
107
- export const GET = handle(app);
108
- export const POST = handle(app);
109
- `;
110
- }
111
- async bundle(mastraDir, outputDirectory) {
112
- const bundler = await getBundler({
113
- input: "#entry",
114
- plugins: [virtual({ "#entry": this.getEntry() })]
115
- });
116
- await bundler.write({
117
- inlineDynamicImports: true,
118
- file: `${outputDirectory}/index.mjs`,
119
- format: "es"
120
- });
121
- }
122
- async deploy(outputDirectory) {
123
- const envVars = await this.loadEnvVars();
124
- const commandArgs = [
125
- "--scope",
126
- this.teamId,
127
- "--cwd",
128
- outputDirectory,
129
- "--token",
130
- this.token,
131
- "deploy",
132
- "--yes",
133
- ...this.projectName ? ["--name", this.projectName] : []
134
- ];
135
- child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
136
- cwd: outputDirectory,
137
- env: {
138
- // ...this.env,
139
- PATH: process.env.PATH
140
- },
141
- stdio: "inherit"
142
- });
143
- this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
144
- if (envVars.size > 0) {
145
- await this.syncEnv(envVars);
146
- } else {
147
- this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
148
- }
149
- }
150
- };
151
-
152
- export { VercelDeployer };