@mastra/deployer-vercel 0.0.1-alpha.35 → 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,261 +1,5 @@
1
1
  # @mastra/deployer-vercel
2
2
 
3
- ## 0.0.1-alpha.35
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [e27fe69]
8
- - @mastra/deployer@0.0.1-alpha.30
9
-
10
- ## 0.0.1-alpha.34
11
-
12
- ### Patch Changes
13
-
14
- - 38b7f66: Update deployer logic
15
- - Updated dependencies [2f17a5f]
16
- - Updated dependencies [0696eeb]
17
- - Updated dependencies [cb290ee]
18
- - Updated dependencies [b4d7416]
19
- - Updated dependencies [38b7f66]
20
- - @mastra/core@0.2.0-alpha.84
21
- - @mastra/deployer@0.0.1-alpha.29
22
-
23
- ## 0.0.1-alpha.33
24
-
25
- ### Patch Changes
26
-
27
- - 9625602: Use mastra core splitted bundles in other packages
28
- - Updated dependencies [2ab57d6]
29
- - Updated dependencies [30322ce]
30
- - Updated dependencies [78eec7c]
31
- - Updated dependencies [9625602]
32
- - Updated dependencies [8769a62]
33
- - @mastra/deployer@0.0.1-alpha.28
34
- - @mastra/core@0.2.0-alpha.83
35
-
36
- ## 0.0.1-alpha.32
37
-
38
- ### Patch Changes
39
-
40
- - Updated dependencies [73d112c]
41
- - Updated dependencies [ac8c61a]
42
- - @mastra/deployer@0.0.1-alpha.27
43
- - @mastra/core@0.1.27-alpha.82
44
-
45
- ## 0.0.1-alpha.31
46
-
47
- ### Patch Changes
48
-
49
- - Updated dependencies [9fb3039]
50
- - @mastra/core@0.1.27-alpha.81
51
- - @mastra/deployer@0.0.1-alpha.26
52
-
53
- ## 0.0.1-alpha.30
54
-
55
- ### Patch Changes
56
-
57
- - 327ece7: Updates for ts versions
58
- - Updated dependencies [327ece7]
59
- - @mastra/core@0.1.27-alpha.80
60
- - @mastra/deployer@0.0.1-alpha.25
61
-
62
- ## 0.0.1-alpha.29
63
-
64
- ### Patch Changes
65
-
66
- - Updated dependencies [21fe536]
67
- - @mastra/core@0.1.27-alpha.79
68
- - @mastra/deployer@0.0.1-alpha.24
69
-
70
- ## 0.0.1-alpha.28
71
-
72
- ### Patch Changes
73
-
74
- - Updated dependencies [88f18d7]
75
- - @mastra/deployer@0.0.1-alpha.23
76
-
77
- ## 0.0.1-alpha.27
78
-
79
- ### Patch Changes
80
-
81
- - 44c7c26: Rebuild
82
-
83
- ## 0.0.1-alpha.26
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [685108a]
88
- - Updated dependencies [685108a]
89
- - @mastra/deployer@0.0.1-alpha.22
90
- - @mastra/core@0.1.27-alpha.78
91
-
92
- ## 0.0.1-alpha.25
93
-
94
- ### Patch Changes
95
-
96
- - 2b75edf: mastra deployers tsup bundling
97
- - Updated dependencies [8105fae]
98
- - Updated dependencies [cfb966f]
99
- - @mastra/core@0.1.27-alpha.77
100
- - @mastra/deployer@0.0.1-alpha.21
101
-
102
- ## 0.0.1-alpha.24
103
-
104
- ### Patch Changes
105
-
106
- - Updated dependencies [ae7bf94]
107
- - Updated dependencies [ae7bf94]
108
- - @mastra/deployer@0.0.1-alpha.20
109
- - @mastra/core@0.1.27-alpha.76
110
-
111
- ## 0.0.1-alpha.23
112
-
113
- ### Patch Changes
114
-
115
- - Updated dependencies [23dcb23]
116
- - Updated dependencies [7064554]
117
- - @mastra/core@0.1.27-alpha.75
118
- - @mastra/deployer@0.0.1-alpha.19
119
-
120
- ## 0.0.1-alpha.22
121
-
122
- ### Patch Changes
123
-
124
- - Updated dependencies [7b87567]
125
- - @mastra/core@0.1.27-alpha.74
126
- - @mastra/deployer@0.0.1-alpha.18
127
-
128
- ## 0.0.1-alpha.21
129
-
130
- ### Patch Changes
131
-
132
- - Updated dependencies [3427b95]
133
- - @mastra/core@0.1.27-alpha.73
134
- - @mastra/deployer@0.0.1-alpha.17
135
-
136
- ## 0.0.1-alpha.20
137
-
138
- ### Patch Changes
139
-
140
- - Updated dependencies [e4d4ede]
141
- - Updated dependencies [06b2c0a]
142
- - @mastra/core@0.1.27-alpha.72
143
- - @mastra/deployer@0.0.1-alpha.16
144
-
145
- ## 0.0.1-alpha.19
146
-
147
- ### Patch Changes
148
-
149
- - Updated dependencies [d9c8dd0]
150
- - @mastra/deployer@0.0.1-alpha.15
151
- - @mastra/core@0.1.27-alpha.71
152
-
153
- ## 0.0.1-alpha.18
154
-
155
- ### Patch Changes
156
-
157
- - Updated dependencies [ad2cd74]
158
- - @mastra/deployer@0.0.1-alpha.14
159
-
160
- ## 0.0.1-alpha.17
161
-
162
- ### Patch Changes
163
-
164
- - Updated dependencies [a1774e7]
165
- - @mastra/deployer@0.0.1-alpha.13
166
-
167
- ## 0.0.1-alpha.16
168
-
169
- ### Patch Changes
170
-
171
- - Updated dependencies [28dceab]
172
- - @mastra/deployer@0.0.1-alpha.12
173
-
174
- ## 0.0.1-alpha.15
175
-
176
- ### Patch Changes
177
-
178
- - bdaf834: publish packages
179
- - Updated dependencies [bdaf834]
180
- - @mastra/deployer@0.0.1-alpha.11
181
-
182
- ## 0.0.1-alpha.14
183
-
184
- ### Patch Changes
185
-
186
- - Updated dependencies [dd6d87f]
187
- - Updated dependencies [04434b6]
188
- - @mastra/core@0.1.27-alpha.70
189
- - @mastra/deployer@0.0.1-alpha.10
190
-
191
- ## 0.0.1-alpha.13
192
-
193
- ### Patch Changes
194
-
195
- - Updated dependencies [9066f95]
196
- - @mastra/deployer@0.0.1-alpha.9
197
-
198
- ## 0.0.1-alpha.12
199
-
200
- ### Patch Changes
201
-
202
- - 0d5a03d: Vector store modules
203
-
204
- ## 0.0.1-alpha.11
205
-
206
- ### Patch Changes
207
-
208
- - Updated dependencies [b425845]
209
- - @mastra/deployer@0.0.1-alpha.8
210
-
211
- ## 0.0.1-alpha.10
212
-
213
- ### Patch Changes
214
-
215
- - Updated dependencies [1944807]
216
- - Updated dependencies [9ade36e]
217
- - @mastra/deployer@0.0.1-alpha.7
218
- - @mastra/core@0.1.27-alpha.69
219
-
220
- ## 0.0.1-alpha.9
221
-
222
- ### Patch Changes
223
-
224
- - Updated dependencies [291fe57]
225
- - Updated dependencies [1a41fbf]
226
- - @mastra/deployer@0.0.1-alpha.6
227
-
228
- ## 0.0.1-alpha.8
229
-
230
- ### Patch Changes
231
-
232
- - Updated dependencies [0be7181]
233
- - Updated dependencies [0be7181]
234
- - @mastra/core@0.1.27-alpha.68
235
- - @mastra/deployer@0.0.1-alpha.5
236
-
237
- ## 0.0.1-alpha.7
238
-
239
- ### Patch Changes
240
-
241
- - Updated dependencies [7babd5c]
242
- - @mastra/deployer@0.0.1-alpha.4
243
-
244
- ## 0.0.1-alpha.6
245
-
246
- ### Patch Changes
247
-
248
- - Updated dependencies [c8ff2f5]
249
- - Updated dependencies [a291824]
250
- - @mastra/core@0.1.27-alpha.67
251
- - @mastra/deployer@0.0.1-alpha.3
252
-
253
- ## 0.0.1-alpha.5
254
-
255
- ### Patch Changes
256
-
257
- - 88600bc: Deployer fixes
258
-
259
3
  ## 0.0.1-alpha.4
260
4
 
261
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.35",
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.30"
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 };