@mastra/deployer-netlify 0.0.1-alpha.21 → 0.0.1-alpha.24

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,30 @@
1
1
  # @mastra/deployer-netlify
2
2
 
3
+ ## 0.0.1-alpha.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 44c7c26: Rebuild
8
+
9
+ ## 0.0.1-alpha.23
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [685108a]
14
+ - Updated dependencies [685108a]
15
+ - @mastra/deployer@0.0.1-alpha.22
16
+ - @mastra/core@0.1.27-alpha.78
17
+
18
+ ## 0.0.1-alpha.22
19
+
20
+ ### Patch Changes
21
+
22
+ - 2b75edf: mastra deployers tsup bundling
23
+ - Updated dependencies [8105fae]
24
+ - Updated dependencies [cfb966f]
25
+ - @mastra/core@0.1.27-alpha.77
26
+ - @mastra/deployer@0.0.1-alpha.21
27
+
3
28
  ## 0.0.1-alpha.21
4
29
 
5
30
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { MastraDeployer } from '@mastra/core';
2
- export declare class NetlifyDeployer extends MastraDeployer {
2
+
3
+ declare class NetlifyDeployer extends MastraDeployer {
3
4
  constructor({ scope, env, projectName }: {
4
5
  projectName: string;
5
6
  env?: Record<string, any>;
@@ -16,4 +17,5 @@ export declare class NetlifyDeployer extends MastraDeployer {
16
17
  dir: string;
17
18
  }): void;
18
19
  }
19
- //# sourceMappingURL=index.d.ts.map
20
+
21
+ export { NetlifyDeployer };
package/dist/index.js CHANGED
@@ -1,8 +1,119 @@
1
+ import { MastraDeployer } from '@mastra/core';
2
+ import { execa } from 'execa';
3
+ import { existsSync, mkdirSync, writeFileSync, renameSync } from 'fs';
4
+ import { join } from 'path';
1
5
 
2
- 'use strict'
6
+ // src/index.ts
3
7
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./deployer-netlify.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./deployer-netlify.cjs.development.js')
8
+ // src/helpers.ts
9
+ async function createNetlifySite({ token, name, scope }) {
10
+ console.log(token, name, scope);
11
+ const response = await fetch("https://api.netlify.com/api/v1/sites", {
12
+ method: "POST",
13
+ headers: {
14
+ Authorization: `Bearer ${token}`,
15
+ "Content-Type": "application/json"
16
+ },
17
+ body: JSON.stringify({
18
+ name,
19
+ account_slug: scope,
20
+ // Optional - if not provided, creates in user's default account
21
+ force_ssl: true
22
+ // Enable HTTPS
23
+ })
24
+ });
25
+ const data = await response.json();
26
+ if (!response.ok) {
27
+ console.error(JSON.stringify(data));
28
+ throw new Error(`Failed to create site: ${data.message || "Unknown error"}`);
29
+ }
30
+ return {
31
+ id: data.id,
32
+ name: data.name,
33
+ url: data.ssl_url || data.url,
34
+ adminUrl: data.admin_url
35
+ };
8
36
  }
37
+ async function findNetlifySite({ token, name, scope }) {
38
+ const response = await fetch(`https://api.netlify.com/api/v1/${scope}/sites?filter=all&name=${name}`, {
39
+ headers: {
40
+ Authorization: `Bearer ${token}`,
41
+ "Content-Type": "application/json"
42
+ }
43
+ });
44
+ const data = await response.json();
45
+ if (!response.ok) {
46
+ throw new Error(`Failed to search sites: ${data.message || "Unknown error"}`);
47
+ }
48
+ return data.find((site) => site.name === name);
49
+ }
50
+ async function getOrCreateSite({ token, name, scope }) {
51
+ let existingSite;
52
+ try {
53
+ existingSite = await findNetlifySite({ token, name, scope });
54
+ } catch (e) {
55
+ }
56
+ if (existingSite) {
57
+ return existingSite;
58
+ }
59
+ return createNetlifySite({ token, name, scope });
60
+ }
61
+
62
+ // src/index.ts
63
+ var NetlifyDeployer = class extends MastraDeployer {
64
+ constructor({ scope, env, projectName }) {
65
+ super({ scope, env, projectName });
66
+ }
67
+ writeFiles({ dir }) {
68
+ if (!existsSync(join(dir, "netlify/functions/api"))) {
69
+ mkdirSync(join(dir, "netlify/functions/api"), { recursive: true });
70
+ }
71
+ writeFileSync(
72
+ join(dir, "netlify.toml"),
73
+ `
74
+ [functions]
75
+ node_bundler = "esbuild"
76
+ directory = "/netlify/functions"
77
+
78
+ [[redirects]]
79
+ force = true
80
+ from = "/*"
81
+ status = 200
82
+ to = "/.netlify/functions/api/:splat"
83
+ `
84
+ );
85
+ this.writeIndex({ dir });
86
+ }
87
+ async deploy({ dir, token }) {
88
+ const site = await getOrCreateSite({ token, name: this.projectName || `mastra`, scope: this.scope });
89
+ const p2 = execa(
90
+ "netlify",
91
+ ["deploy", "--site", site.id, "--auth", token, "--dir", ".", "--functions", "./netlify/functions"],
92
+ {
93
+ cwd: dir
94
+ }
95
+ );
96
+ p2.stdout.pipe(process.stdout);
97
+ await p2;
98
+ }
99
+ writeIndex({ dir }) {
100
+ ["mastra.mjs", "hono.mjs", "server.mjs"].forEach((file) => {
101
+ renameSync(join(dir, file), join(dir, `netlify/functions/api/${file}`));
102
+ });
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
+ );
116
+ }
117
+ };
118
+
119
+ export { NetlifyDeployer };
package/package.json CHANGED
@@ -1,21 +1,14 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.0.1-alpha.21",
3
+ "version": "0.0.1-alpha.24",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
- "module": "dist/deployer-netlify.esm.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/deployer-netlify.esm.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
18
- }
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
19
12
  },
20
13
  "./package.json": "./package.json"
21
14
  },
@@ -28,21 +21,20 @@
28
21
  "execa": "^9.3.1",
29
22
  "netlify-cli": "^18.0.1",
30
23
  "zod": "^3.24.1",
31
- "@mastra/core": "0.1.27-alpha.76",
32
- "@mastra/deployer": "0.0.1-alpha.20"
24
+ "@mastra/deployer": "0.0.1-alpha.22",
25
+ "@mastra/core": "0.1.27-alpha.78"
33
26
  },
34
27
  "devDependencies": {
35
28
  "@babel/preset-env": "^7.26.0",
36
29
  "@babel/preset-typescript": "^7.26.0",
37
30
  "@tsconfig/recommended": "^1.0.7",
38
- "@types/jsdom": "^21.1.7",
39
31
  "@types/node": "^22.9.0",
40
- "dts-cli": "^2.0.5",
41
- "vitest": "^2.1.8"
32
+ "tsup": "^8.0.1",
33
+ "vitest": "^3.0.4"
42
34
  },
43
35
  "scripts": {
44
- "build": "dts build",
45
- "build:dev": "dts watch",
36
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
37
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
46
38
  "test": "vitest run"
47
39
  }
48
40
  }
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
  });