@mastra/deployer-netlify 0.0.1-alpha.3 → 0.0.1-alpha.31

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/src/index.ts CHANGED
@@ -1,13 +1,23 @@
1
- import { MastraDeployer } from '@mastra/core';
1
+ import { Deployer } from '@mastra/deployer';
2
+ import { getBundler } from '@mastra/deployer/build';
3
+ import virtual from '@rollup/plugin-virtual';
2
4
  import { execa } from 'execa';
3
- import { existsSync, mkdirSync, renameSync, writeFileSync } from 'fs';
5
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
4
6
  import { join } from 'path';
5
7
 
6
8
  import { getOrCreateSite } from './helpers.js';
7
9
 
8
- export class NetlifyDeployer extends MastraDeployer {
9
- constructor({ scope, env, projectName }: { projectName: string; env?: Record<string, any>; scope: string }) {
10
- super({ scope, env, projectName });
10
+ export class NetlifyDeployer extends Deployer {
11
+ protected scope: string;
12
+ protected projectName: string;
13
+ protected token: string;
14
+
15
+ constructor({ scope, projectName, token }: { scope: string; projectName: string; token: string }) {
16
+ super({ name: 'NETLIFY' });
17
+
18
+ this.scope = scope;
19
+ this.projectName = projectName;
20
+ this.token = token;
11
21
  }
12
22
 
13
23
  writeFiles({ dir }: { dir: string }): void {
@@ -18,30 +28,38 @@ export class NetlifyDeployer extends MastraDeployer {
18
28
  // TODO ENV KEYS
19
29
  writeFileSync(
20
30
  join(dir, 'netlify.toml'),
21
- `
22
- [functions]
23
- node_bundler = "esbuild"
24
- directory = "/netlify/functions"
25
-
26
- [[redirects]]
27
- force = true
28
- from = "/*"
29
- status = 200
30
- to = "/.netlify/functions/api/:splat"
31
- `,
32
- );
31
+ `[functions]
32
+ node_bundler = "esbuild"
33
+ directory = "netlify/functions"
33
34
 
34
- this.writeIndex({ dir });
35
+ [[redirects]]
36
+ force = true
37
+ from = "/*"
38
+ status = 200
39
+ to = "/.netlify/functions/api/:splat"
40
+ `,
41
+ );
35
42
  }
36
43
 
37
- async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
38
- const site = await getOrCreateSite({ token, name: this.projectName || `mastra`, scope: this.scope });
44
+ async deploy(outputDirectory: string): Promise<void> {
45
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
39
46
 
40
47
  const p2 = execa(
41
- 'netlify',
42
- ['deploy', '--site', site.id, '--auth', token, '--dir', '.', '--functions', './netlify/functions'],
48
+ 'npx',
49
+ [
50
+ 'netlify-cli',
51
+ 'deploy',
52
+ '--site',
53
+ site.id,
54
+ '--auth',
55
+ this.token,
56
+ '--dir',
57
+ '.',
58
+ '--functions',
59
+ './netlify/functions',
60
+ ],
43
61
  {
44
- cwd: dir,
62
+ cwd: outputDirectory,
45
63
  },
46
64
  );
47
65
 
@@ -49,23 +67,39 @@ export class NetlifyDeployer extends MastraDeployer {
49
67
  await p2;
50
68
  }
51
69
 
52
- writeIndex({ dir }: { dir: string }): void {
53
- ['mastra.mjs', 'hono.mjs', 'server.mjs'].forEach(file => {
54
- renameSync(join(dir, file), join(dir, `netlify/functions/api/${file}`));
70
+ async prepare(outputDirectory: string): Promise<void> {
71
+ await super.prepare(outputDirectory);
72
+
73
+ // Prepare the deployment directory
74
+ if (!existsSync(join(outputDirectory, 'netlify/functions/api'))) {
75
+ mkdirSync(join(outputDirectory, 'netlify/functions/api'), { recursive: true });
76
+ }
77
+ this.writeFiles({ dir: outputDirectory });
78
+ }
79
+
80
+ async bundle(mastraDir: string, outputDirectory: string): Promise<void> {
81
+ const bundler = await getBundler({
82
+ input: '#entry',
83
+ external: [/^@opentelemetry\//],
84
+ plugins: [virtual({ '#entry': this.getEntry() })],
55
85
  });
56
86
 
57
- writeFileSync(
58
- join(dir, 'netlify/functions/api/api.mts'),
59
- `
60
- export default async (req, context) => {
61
- const { app } = await import('./hono.mjs');
62
- // Pass the request directly to Hono
63
- return app.fetch(req, {
64
- // Optional context passing if needed
65
- env: { context }
66
- })
67
- }
68
- `,
69
- );
87
+ bundler.write({
88
+ inlineDynamicImports: true,
89
+ file: join(outputDirectory, 'netlify', 'functions', 'api', 'index.mjs'),
90
+ format: 'es',
91
+ });
92
+ }
93
+
94
+ private getEntry(): string {
95
+ return `
96
+ import { handle } from 'hono/netlify'
97
+ import { mastra } from '#mastra';
98
+ import { createHonoServer } from '#server';
99
+
100
+ const app = await createHonoServer(mastra);
101
+
102
+ export default handle(app)
103
+ `;
70
104
  }
71
105
  }
package/tsconfig.json CHANGED
@@ -1,10 +1,5 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "outDir": "./dist",
6
- "rootDir": "./src"
7
- },
2
+ "extends": "../../tsconfig.node.json",
8
3
  "include": ["src/**/*"],
9
4
  "exclude": ["node_modules", "**/*.test.ts"]
10
5
  }
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
- globals: true,
5
+ environment: 'node',
6
6
  include: ['src/**/*.test.ts'],
7
7
  },
8
8
  });