@mastra/deployer-netlify 0.1.6-alpha.1 → 0.1.6-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.
@@ -1,18 +1,23 @@
1
1
 
2
- > @mastra/deployer-netlify@0.1.6-alpha.1 build /home/runner/work/mastra/mastra/deployers/netlify
3
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
2
+ > @mastra/deployer-netlify@0.1.6-alpha.4 build /home/runner/work/mastra/mastra/deployers/netlify
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 7575ms
9
+ TSC ⚡️ Build success in 6746ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/deployers/netlify/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 5691ms
14
+ Analysis will use the bundled TypeScript version 5.7.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/deployers/netlify/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 8074ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
19
+ CJS Build start
17
20
  ESM dist/index.js 3.46 KB
18
- ESM ⚡️ Build success in 310ms
21
+ ESM ⚡️ Build success in 321ms
22
+ CJS dist/index.cjs 3.51 KB
23
+ CJS ⚡️ Build success in 322ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @mastra/deployer-netlify
2
2
 
3
+ ## 0.1.6-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [dabecf4]
8
+ - @mastra/core@0.4.3-alpha.4
9
+ - @mastra/deployer@0.1.6-alpha.4
10
+
11
+ ## 0.1.6-alpha.3
12
+
13
+ ### Patch Changes
14
+
15
+ - bb4f447: Add support for commonjs
16
+ - Updated dependencies [0fd78ac]
17
+ - Updated dependencies [0d25b75]
18
+ - Updated dependencies [fd14a3f]
19
+ - Updated dependencies [3f369a2]
20
+ - Updated dependencies [4d4e1e1]
21
+ - Updated dependencies [bb4f447]
22
+ - @mastra/deployer@0.1.6-alpha.3
23
+ - @mastra/core@0.4.3-alpha.3
24
+
25
+ ## 0.1.6-alpha.2
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [2512a93]
30
+ - Updated dependencies [e62de74]
31
+ - @mastra/core@0.4.3-alpha.2
32
+ - @mastra/deployer@0.1.6-alpha.2
33
+
3
34
  ## 0.1.6-alpha.1
4
35
 
5
36
  ### Patch Changes
@@ -0,0 +1,38 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare function getOrCreateSite({ token, name, scope }: {
4
+ token: string;
5
+ name: string;
6
+ scope: string;
7
+ }): Promise<{
8
+ id: string | undefined;
9
+ name: string | undefined;
10
+ url: string | undefined;
11
+ adminUrl: string | undefined;
12
+ } | {
13
+ id: string;
14
+ name: string;
15
+ ssl_url: string;
16
+ url: string;
17
+ admin_url: string;
18
+ }>;
19
+
20
+ export declare class NetlifyDeployer extends Deployer {
21
+ protected scope: string;
22
+ protected projectName: string;
23
+ protected token: string;
24
+ constructor({ scope, projectName, token }: {
25
+ scope: string;
26
+ projectName: string;
27
+ token: string;
28
+ });
29
+ writeFiles({ dir }: {
30
+ dir: string;
31
+ }): void;
32
+ deploy(outputDirectory: string): Promise<void>;
33
+ prepare(outputDirectory: string): Promise<void>;
34
+ bundle(entryFile: string, outputDirectory: string): Promise<void>;
35
+ private getEntry;
36
+ }
37
+
38
+ export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var deployer = require('@mastra/deployer');
6
+ var execa = require('execa');
7
+
8
+ // src/index.ts
9
+
10
+ // src/helpers.ts
11
+ async function createNetlifySite({ token, name, scope }) {
12
+ const response = await fetch("https://api.netlify.com/api/v1/sites", {
13
+ method: "POST",
14
+ headers: {
15
+ Authorization: `Bearer ${token}`,
16
+ "Content-Type": "application/json"
17
+ },
18
+ body: JSON.stringify({
19
+ name,
20
+ account_slug: scope,
21
+ // Optional - if not provided, creates in user's default account
22
+ force_ssl: true
23
+ // Enable HTTPS
24
+ })
25
+ });
26
+ const data = await response.json();
27
+ if (!response.ok) {
28
+ console.error(JSON.stringify(data));
29
+ throw new Error(`Failed to create site: ${data.message || "Unknown error"}`);
30
+ }
31
+ return {
32
+ id: data.id,
33
+ name: data.name,
34
+ url: data.ssl_url || data.url,
35
+ adminUrl: data.admin_url
36
+ };
37
+ }
38
+ async function findNetlifySite({ token, name, scope }) {
39
+ const response = await fetch(`https://api.netlify.com/api/v1/${scope}/sites?filter=all&name=${name}`, {
40
+ headers: {
41
+ Authorization: `Bearer ${token}`,
42
+ "Content-Type": "application/json"
43
+ }
44
+ });
45
+ const data = await response.json();
46
+ if (!response.ok || !Array.isArray(data)) {
47
+ throw new Error(`Failed to search sites: ${data.message || "Unknown error"}`);
48
+ }
49
+ return data.find((site) => site.name === name);
50
+ }
51
+ async function getOrCreateSite({ token, name, scope }) {
52
+ let existingSite;
53
+ try {
54
+ existingSite = await findNetlifySite({ token, name, scope });
55
+ } catch {
56
+ }
57
+ if (existingSite) {
58
+ return existingSite;
59
+ }
60
+ return createNetlifySite({ token, name, scope });
61
+ }
62
+
63
+ // src/index.ts
64
+ var NetlifyDeployer = class extends deployer.Deployer {
65
+ scope;
66
+ projectName;
67
+ token;
68
+ constructor({ scope, projectName, token }) {
69
+ super({ name: "NETLIFY" });
70
+ this.scope = scope;
71
+ this.projectName = projectName;
72
+ this.token = token;
73
+ }
74
+ writeFiles({ dir }) {
75
+ if (!fs.existsSync(path.join(dir, "netlify/functions/api"))) {
76
+ fs.mkdirSync(path.join(dir, "netlify/functions/api"), { recursive: true });
77
+ }
78
+ fs.writeFileSync(
79
+ path.join(dir, "netlify.toml"),
80
+ `[functions]
81
+ node_bundler = "esbuild"
82
+ directory = "netlify/functions"
83
+
84
+ [[redirects]]
85
+ force = true
86
+ from = "/*"
87
+ status = 200
88
+ to = "/.netlify/functions/api/:splat"
89
+ `
90
+ );
91
+ }
92
+ async deploy(outputDirectory) {
93
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
94
+ const p2 = execa.execa(
95
+ "npx",
96
+ [
97
+ "netlify-cli",
98
+ "deploy",
99
+ "--site",
100
+ site.id,
101
+ "--auth",
102
+ this.token,
103
+ "--dir",
104
+ ".",
105
+ "--functions",
106
+ "./netlify/functions"
107
+ ],
108
+ {
109
+ cwd: path.join(outputDirectory, this.outputDir)
110
+ }
111
+ );
112
+ p2.stdout.pipe(process.stdout);
113
+ await p2;
114
+ }
115
+ async prepare(outputDirectory) {
116
+ await super.prepare(outputDirectory);
117
+ this.writeFiles({ dir: path.join(outputDirectory, this.outputDir) });
118
+ }
119
+ async bundle(entryFile, outputDirectory) {
120
+ return this._bundle(
121
+ this.getEntry(),
122
+ entryFile,
123
+ outputDirectory,
124
+ path.join(outputDirectory, this.outputDir, "netlify", "functions", "api")
125
+ );
126
+ }
127
+ getEntry() {
128
+ return `
129
+ import { handle } from 'hono/netlify'
130
+ import { mastra } from '#mastra';
131
+ import { createHonoServer } from '#server';
132
+
133
+ const app = await createHonoServer(mastra);
134
+
135
+ export default handle(app)
136
+ `;
137
+ }
138
+ };
139
+
140
+ exports.NetlifyDeployer = NetlifyDeployer;
@@ -0,0 +1 @@
1
+ export { NetlifyDeployer } from './_tsup-dts-rollup.cjs';
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.1.6-alpha.1",
3
+ "version": "0.1.6-alpha.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
12
18
  },
13
19
  "./package.json": "./package.json"
14
20
  },
@@ -21,8 +27,8 @@
21
27
  "execa": "^9.3.1",
22
28
  "netlify-cli": "^18.0.1",
23
29
  "zod": "^3.24.1",
24
- "@mastra/core": "^0.4.3-alpha.1",
25
- "@mastra/deployer": "^0.1.6-alpha.1"
30
+ "@mastra/core": "^0.4.3-alpha.4",
31
+ "@mastra/deployer": "^0.1.6-alpha.4"
26
32
  },
27
33
  "devDependencies": {
28
34
  "eslint": "^9.20.1",
@@ -34,7 +40,7 @@
34
40
  "@internal/lint": "0.0.0"
35
41
  },
36
42
  "scripts": {
37
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
43
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
38
44
  "build:watch": "pnpm build --watch",
39
45
  "test": "vitest run",
40
46
  "lint": "eslint ."