@mastra/deployer-netlify 0.0.1-alpha.30 → 0.0.1-alpha.32

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,26 @@
1
1
  # @mastra/deployer-netlify
2
2
 
3
+ ## 0.0.1-alpha.32
4
+
5
+ ### Patch Changes
6
+
7
+ - e27fe69: Add dir to deployer
8
+ - Updated dependencies [e27fe69]
9
+ - @mastra/deployer@0.0.1-alpha.30
10
+
11
+ ## 0.0.1-alpha.31
12
+
13
+ ### Patch Changes
14
+
15
+ - 38b7f66: Update deployer logic
16
+ - Updated dependencies [2f17a5f]
17
+ - Updated dependencies [0696eeb]
18
+ - Updated dependencies [cb290ee]
19
+ - Updated dependencies [b4d7416]
20
+ - Updated dependencies [38b7f66]
21
+ - @mastra/core@0.2.0-alpha.84
22
+ - @mastra/deployer@0.0.1-alpha.29
23
+
3
24
  ## 0.0.1-alpha.30
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { MastraDeployer } from '@mastra/core/deployer';
1
+ import { Deployer } from '@mastra/deployer';
2
2
 
3
- declare class NetlifyDeployer extends MastraDeployer {
4
- constructor({ scope, env, projectName }: {
5
- projectName: string;
6
- env?: Record<string, any>;
3
+ declare class NetlifyDeployer extends Deployer {
4
+ protected scope: string;
5
+ protected projectName: string;
6
+ protected token: string;
7
+ constructor({ scope, projectName, token }: {
7
8
  scope: string;
9
+ projectName: string;
10
+ token: string;
8
11
  });
9
12
  writeFiles({ dir }: {
10
13
  dir: string;
11
14
  }): void;
12
- deploy({ dir, token }: {
13
- dir: string;
14
- token: string;
15
- }): Promise<void>;
16
- writeIndex({ dir }: {
17
- dir: string;
18
- }): void;
15
+ deploy(outputDirectory: string): Promise<void>;
16
+ prepare(outputDirectory: string): Promise<void>;
17
+ bundle(mastraDir: string, outputDirectory: string): Promise<void>;
18
+ private getEntry;
19
19
  }
20
20
 
21
21
  export { NetlifyDeployer };
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { MastraDeployer } from '@mastra/core/deployer';
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, writeFileSync, renameSync } from 'fs';
5
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
4
6
  import { join } from 'path';
5
7
 
6
8
  // src/index.ts
@@ -60,9 +62,15 @@ async function getOrCreateSite({ token, name, scope }) {
60
62
  }
61
63
 
62
64
  // src/index.ts
63
- var NetlifyDeployer = class extends MastraDeployer {
64
- constructor({ scope, env, projectName }) {
65
- super({ scope, env, projectName });
65
+ var NetlifyDeployer = class extends Deployer {
66
+ scope;
67
+ projectName;
68
+ token;
69
+ constructor({ scope, projectName, token }) {
70
+ super({ name: "NETLIFY" });
71
+ this.scope = scope;
72
+ this.projectName = projectName;
73
+ this.token = token;
66
74
  }
67
75
  writeFiles({ dir }) {
68
76
  if (!existsSync(join(dir, "netlify/functions/api"))) {
@@ -70,49 +78,70 @@ var NetlifyDeployer = class extends MastraDeployer {
70
78
  }
71
79
  writeFileSync(
72
80
  join(dir, "netlify.toml"),
73
- `
74
- [functions]
75
- node_bundler = "esbuild"
76
- directory = "/netlify/functions"
81
+ `[functions]
82
+ node_bundler = "esbuild"
83
+ directory = "netlify/functions"
77
84
 
78
- [[redirects]]
79
- force = true
80
- from = "/*"
81
- status = 200
82
- to = "/.netlify/functions/api/:splat"
83
- `
85
+ [[redirects]]
86
+ force = true
87
+ from = "/*"
88
+ status = 200
89
+ to = "/.netlify/functions/api/:splat"
90
+ `
84
91
  );
85
- this.writeIndex({ dir });
86
92
  }
87
- async deploy({ dir, token }) {
88
- const site = await getOrCreateSite({ token, name: this.projectName || `mastra`, scope: this.scope });
93
+ async deploy(outputDirectory) {
94
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
89
95
  const p2 = execa(
90
- "netlify",
91
- ["deploy", "--site", site.id, "--auth", token, "--dir", ".", "--functions", "./netlify/functions"],
96
+ "npx",
97
+ [
98
+ "netlify-cli",
99
+ "deploy",
100
+ "--site",
101
+ site.id,
102
+ "--auth",
103
+ this.token,
104
+ "--dir",
105
+ ".",
106
+ "--functions",
107
+ "./netlify/functions"
108
+ ],
92
109
  {
93
- cwd: dir
110
+ cwd: outputDirectory
94
111
  }
95
112
  );
96
113
  p2.stdout.pipe(process.stdout);
97
114
  await p2;
98
115
  }
99
- writeIndex({ dir }) {
100
- ["mastra.mjs", "hono.mjs", "server.mjs"].forEach((file) => {
101
- renameSync(join(dir, file), join(dir, `netlify/functions/api/${file}`));
116
+ async prepare(outputDirectory) {
117
+ await super.prepare(outputDirectory);
118
+ if (!existsSync(join(outputDirectory, "netlify/functions/api"))) {
119
+ mkdirSync(join(outputDirectory, "netlify/functions/api"), { recursive: true });
120
+ }
121
+ this.writeFiles({ dir: outputDirectory });
122
+ }
123
+ async bundle(mastraDir, outputDirectory) {
124
+ const bundler = await getBundler({
125
+ input: "#entry",
126
+ external: [/^@opentelemetry\//],
127
+ plugins: [virtual({ "#entry": this.getEntry() })]
102
128
  });
103
- writeFileSync(
104
- join(dir, "netlify/functions/api/api.mts"),
105
- `
106
- export default async (req, context) => {
107
- const { app } = await import('./hono.mjs');
108
- // Pass the request directly to Hono
109
- return app.fetch(req, {
110
- // Optional context passing if needed
111
- env: { context }
112
- })
113
- }
114
- `
115
- );
129
+ await bundler.write({
130
+ inlineDynamicImports: true,
131
+ file: join(outputDirectory, "netlify", "functions", "api", "index.mjs"),
132
+ format: "es"
133
+ });
134
+ }
135
+ getEntry() {
136
+ return `
137
+ import { handle } from 'hono/netlify'
138
+ import { mastra } from '#mastra';
139
+ import { createHonoServer } from '#server';
140
+
141
+ const app = await createHonoServer(mastra);
142
+
143
+ export default handle(app)
144
+ `;
116
145
  }
117
146
  };
118
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.0.1-alpha.30",
3
+ "version": "0.0.1-alpha.32",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,13 +16,14 @@
16
16
  "author": "",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
+ "@rollup/plugin-virtual": "^3.0.2",
19
20
  "date-fns": "^4.1.0",
20
21
  "dotenv": "^16.3.1",
21
22
  "execa": "^9.3.1",
22
23
  "netlify-cli": "^18.0.1",
23
24
  "zod": "^3.24.1",
24
- "@mastra/core": "0.2.0-alpha.83",
25
- "@mastra/deployer": "0.0.1-alpha.28"
25
+ "@mastra/core": "0.2.0-alpha.84",
26
+ "@mastra/deployer": "0.0.1-alpha.30"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@babel/preset-env": "^7.26.0",
package/src/index.ts CHANGED
@@ -1,13 +1,23 @@
1
- import { MastraDeployer } from '@mastra/core/deployer';
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
+ await 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
  }