@mastra/deployer-cloudflare 0.0.1-alpha.31 → 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 +13 -0
- package/dist/index.d.ts +14 -15
- package/dist/index.js +84 -33
- package/global.d.ts +1 -0
- package/package.json +6 -3
- package/src/index.ts +94 -36
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/deployer-cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 38b7f66: Update deployer logic
|
|
8
|
+
- Updated dependencies [2f17a5f]
|
|
9
|
+
- Updated dependencies [0696eeb]
|
|
10
|
+
- Updated dependencies [cb290ee]
|
|
11
|
+
- Updated dependencies [b4d7416]
|
|
12
|
+
- Updated dependencies [38b7f66]
|
|
13
|
+
- @mastra/core@0.2.0-alpha.84
|
|
14
|
+
- @mastra/deployer@0.0.1-alpha.29
|
|
15
|
+
|
|
3
16
|
## 0.0.1-alpha.31
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
2
|
|
|
3
3
|
interface CFRoute {
|
|
4
4
|
pattern: string;
|
|
5
5
|
zone_name: string;
|
|
6
6
|
custom_domain?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare class CloudflareDeployer extends
|
|
8
|
+
declare class CloudflareDeployer extends Deployer {
|
|
9
9
|
private cloudflare;
|
|
10
10
|
routes?: CFRoute[];
|
|
11
11
|
workerNamespace?: string;
|
|
12
|
+
scope: string;
|
|
13
|
+
env?: Record<string, any>;
|
|
14
|
+
projectName?: string;
|
|
12
15
|
constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
|
|
13
16
|
env?: Record<string, any>;
|
|
14
17
|
scope: string;
|
|
15
|
-
projectName
|
|
18
|
+
projectName?: string;
|
|
16
19
|
routes?: CFRoute[];
|
|
17
20
|
workerNamespace?: string;
|
|
18
|
-
auth
|
|
21
|
+
auth: {
|
|
19
22
|
apiToken: string;
|
|
20
|
-
apiEmail
|
|
23
|
+
apiEmail?: string;
|
|
21
24
|
};
|
|
22
25
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
deploy({ dir, token }: {
|
|
30
|
-
dir: string;
|
|
31
|
-
token: string;
|
|
32
|
-
}): Promise<void>;
|
|
26
|
+
writePackageJson(outputDirectory: string): Promise<void>;
|
|
27
|
+
writeFiles(outputDirectory: string): Promise<void>;
|
|
28
|
+
private getEntry;
|
|
29
|
+
bundle(mastraDir: string, outputDirectory: string): Promise<void>;
|
|
30
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
31
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
33
32
|
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
34
33
|
scope: string;
|
|
35
34
|
workerName: string;
|
package/dist/index.js
CHANGED
|
@@ -1,80 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Deployer, createChildProcessLogger } from '@mastra/deployer';
|
|
2
|
+
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
+
import virtual from '@rollup/plugin-virtual';
|
|
3
4
|
import { Cloudflare } from 'cloudflare';
|
|
4
5
|
import { writeFileSync } from 'fs';
|
|
5
6
|
import { join } from 'path';
|
|
6
7
|
|
|
7
8
|
// src/index.ts
|
|
8
|
-
var CloudflareDeployer = class extends
|
|
9
|
+
var CloudflareDeployer = class extends Deployer {
|
|
9
10
|
cloudflare;
|
|
10
11
|
routes = [];
|
|
11
12
|
workerNamespace;
|
|
13
|
+
scope;
|
|
14
|
+
env;
|
|
15
|
+
projectName;
|
|
12
16
|
constructor({
|
|
13
17
|
scope,
|
|
14
18
|
env,
|
|
15
|
-
projectName,
|
|
19
|
+
projectName = "mastra",
|
|
16
20
|
routes,
|
|
17
21
|
workerNamespace,
|
|
18
22
|
auth
|
|
19
23
|
}) {
|
|
20
|
-
super({
|
|
24
|
+
super({ name: "CLOUDFLARE" });
|
|
25
|
+
this.scope = scope;
|
|
26
|
+
this.projectName = projectName;
|
|
21
27
|
this.routes = routes;
|
|
22
28
|
this.workerNamespace = workerNamespace;
|
|
23
|
-
if (
|
|
24
|
-
this.
|
|
29
|
+
if (env) {
|
|
30
|
+
this.env = env;
|
|
25
31
|
}
|
|
32
|
+
this.cloudflare = new Cloudflare(auth);
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
async writePackageJson(outputDirectory) {
|
|
35
|
+
this.logger.debug(`Writing package.json`);
|
|
36
|
+
const pkgPath = join(outputDirectory, "package.json");
|
|
37
|
+
writeFileSync(
|
|
38
|
+
pkgPath,
|
|
39
|
+
JSON.stringify(
|
|
40
|
+
{
|
|
41
|
+
name: "server",
|
|
42
|
+
version: "1.0.0",
|
|
43
|
+
description: "",
|
|
44
|
+
type: "module",
|
|
45
|
+
main: "index.mjs",
|
|
46
|
+
scripts: {
|
|
47
|
+
start: "node ./index.mjs",
|
|
48
|
+
build: 'echo "Already built"'
|
|
49
|
+
},
|
|
50
|
+
author: "Mastra",
|
|
51
|
+
license: "ISC",
|
|
52
|
+
dependencies: {
|
|
53
|
+
"@mastra/core": "latest"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
null,
|
|
57
|
+
2
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
async writeFiles(outputDirectory) {
|
|
62
|
+
const env = await this.loadEnvVars();
|
|
63
|
+
const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
|
|
64
|
+
const cfWorkerName = this.projectName;
|
|
31
65
|
const wranglerConfig = {
|
|
32
66
|
name: cfWorkerName,
|
|
33
67
|
main: "index.mjs",
|
|
34
68
|
compatibility_date: "2024-12-02",
|
|
35
69
|
compatibility_flags: ["nodejs_compat"],
|
|
36
|
-
build: {
|
|
37
|
-
command: "npm install"
|
|
38
|
-
},
|
|
39
70
|
observability: {
|
|
40
71
|
logs: {
|
|
41
72
|
enabled: true
|
|
42
73
|
}
|
|
43
74
|
},
|
|
44
|
-
vars:
|
|
75
|
+
vars: envsAsObject
|
|
45
76
|
};
|
|
46
77
|
if (!this.workerNamespace && this.routes) {
|
|
47
78
|
wranglerConfig.routes = this.routes;
|
|
48
79
|
}
|
|
49
|
-
writeFileSync(join(
|
|
80
|
+
writeFileSync(join(outputDirectory, "wrangler.json"), JSON.stringify(wranglerConfig));
|
|
50
81
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
getEntry() {
|
|
83
|
+
return `
|
|
84
|
+
export default {
|
|
85
|
+
fetch: async (request, env, context) => {
|
|
86
|
+
Object.keys(env).forEach(key => {
|
|
87
|
+
process.env[key] = env[key]
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const { mastra } = await import('#mastra')
|
|
91
|
+
const { createHonoServer } = await import('#server')
|
|
92
|
+
const app = await createHonoServer(mastra)
|
|
93
|
+
return app.fetch(request, env, context);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
async bundle(mastraDir, outputDirectory) {
|
|
99
|
+
const bundler = await getBundler(
|
|
100
|
+
{
|
|
101
|
+
input: "#entry",
|
|
102
|
+
plugins: [virtual({ "#entry": this.getEntry() })],
|
|
103
|
+
external: [/^@opentelemetry\//],
|
|
104
|
+
treeshake: "smallest"
|
|
105
|
+
},
|
|
106
|
+
"browser"
|
|
65
107
|
);
|
|
108
|
+
bundler.write({
|
|
109
|
+
inlineDynamicImports: true,
|
|
110
|
+
file: join(outputDirectory, "index.mjs"),
|
|
111
|
+
format: "es"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async prepare(outputDirectory) {
|
|
115
|
+
await super.prepare(outputDirectory);
|
|
116
|
+
await this.writeFiles(outputDirectory);
|
|
66
117
|
}
|
|
67
|
-
async deploy(
|
|
118
|
+
async deploy(outputDirectory) {
|
|
68
119
|
const cmd = this.workerNamespace ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler deploy";
|
|
69
120
|
const cpLogger = createChildProcessLogger({
|
|
70
121
|
logger: this.logger,
|
|
71
|
-
root:
|
|
122
|
+
root: outputDirectory
|
|
72
123
|
});
|
|
73
124
|
await cpLogger({
|
|
74
125
|
cmd,
|
|
75
126
|
args: [],
|
|
76
127
|
env: {
|
|
77
|
-
CLOUDFLARE_API_TOKEN:
|
|
128
|
+
CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
|
|
78
129
|
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
79
130
|
...this.env,
|
|
80
131
|
PATH: process.env.PATH
|
package/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'rollup-plugin-shim';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,14 +20,17 @@
|
|
|
20
20
|
"author": "",
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@rollup/plugin-virtual": "^3.0.2",
|
|
23
24
|
"cloudflare": "^4.0.0",
|
|
24
25
|
"date-fns": "^4.1.0",
|
|
25
26
|
"dotenv": "^16.3.1",
|
|
26
27
|
"execa": "^9.3.1",
|
|
28
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
29
|
+
"rollup-plugin-shim": "^1.0.0",
|
|
27
30
|
"wrangler": "^3.103.2",
|
|
28
31
|
"zod": "^3.24.1",
|
|
29
|
-
"@mastra/core": "0.2.0-alpha.
|
|
30
|
-
"@mastra/deployer": "0.0.1-alpha.
|
|
32
|
+
"@mastra/core": "0.2.0-alpha.84",
|
|
33
|
+
"@mastra/deployer": "0.0.1-alpha.29"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"@babel/preset-env": "^7.26.0",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Deployer, createChildProcessLogger } from '@mastra/deployer';
|
|
2
|
+
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
+
import virtual from '@rollup/plugin-virtual';
|
|
3
4
|
import { Cloudflare } from 'cloudflare';
|
|
4
5
|
import { writeFileSync } from 'fs';
|
|
5
6
|
import { join } from 'path';
|
|
@@ -10,100 +11,157 @@ interface CFRoute {
|
|
|
10
11
|
custom_domain?: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export class CloudflareDeployer extends
|
|
14
|
+
export class CloudflareDeployer extends Deployer {
|
|
14
15
|
private cloudflare: Cloudflare | undefined;
|
|
15
16
|
routes?: CFRoute[] = [];
|
|
16
17
|
workerNamespace?: string;
|
|
18
|
+
scope: string;
|
|
19
|
+
env?: Record<string, any>;
|
|
20
|
+
projectName?: string;
|
|
21
|
+
|
|
17
22
|
constructor({
|
|
18
23
|
scope,
|
|
19
24
|
env,
|
|
20
|
-
projectName,
|
|
25
|
+
projectName = 'mastra',
|
|
21
26
|
routes,
|
|
22
27
|
workerNamespace,
|
|
23
28
|
auth,
|
|
24
29
|
}: {
|
|
25
30
|
env?: Record<string, any>;
|
|
26
31
|
scope: string;
|
|
27
|
-
projectName
|
|
32
|
+
projectName?: string;
|
|
28
33
|
routes?: CFRoute[];
|
|
29
34
|
workerNamespace?: string;
|
|
30
|
-
auth
|
|
35
|
+
auth: {
|
|
31
36
|
apiToken: string;
|
|
32
|
-
apiEmail
|
|
37
|
+
apiEmail?: string;
|
|
33
38
|
};
|
|
34
39
|
}) {
|
|
35
|
-
super({
|
|
40
|
+
super({ name: 'CLOUDFLARE' });
|
|
36
41
|
|
|
42
|
+
this.scope = scope;
|
|
43
|
+
this.projectName = projectName;
|
|
37
44
|
this.routes = routes;
|
|
38
45
|
this.workerNamespace = workerNamespace;
|
|
39
46
|
|
|
40
|
-
if (
|
|
41
|
-
this.
|
|
47
|
+
if (env) {
|
|
48
|
+
this.env = env;
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
this.cloudflare = new Cloudflare(auth);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async writePackageJson(outputDirectory: string) {
|
|
55
|
+
this.logger.debug(`Writing package.json`);
|
|
56
|
+
const pkgPath = join(outputDirectory, 'package.json');
|
|
57
|
+
|
|
58
|
+
writeFileSync(
|
|
59
|
+
pkgPath,
|
|
60
|
+
JSON.stringify(
|
|
61
|
+
{
|
|
62
|
+
name: 'server',
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
description: '',
|
|
65
|
+
type: 'module',
|
|
66
|
+
main: 'index.mjs',
|
|
67
|
+
scripts: {
|
|
68
|
+
start: 'node ./index.mjs',
|
|
69
|
+
build: 'echo "Already built"',
|
|
70
|
+
},
|
|
71
|
+
author: 'Mastra',
|
|
72
|
+
license: 'ISC',
|
|
73
|
+
dependencies: {
|
|
74
|
+
'@mastra/core': 'latest'
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
null,
|
|
78
|
+
2,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
43
81
|
}
|
|
44
82
|
|
|
45
|
-
|
|
46
|
-
this.loadEnvVars();
|
|
83
|
+
async writeFiles(outputDirectory: string): Promise<void> {
|
|
84
|
+
const env = await this.loadEnvVars();
|
|
47
85
|
|
|
48
|
-
|
|
86
|
+
const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
|
|
49
87
|
|
|
50
|
-
const cfWorkerName = this.projectName
|
|
88
|
+
const cfWorkerName = this.projectName;
|
|
51
89
|
|
|
52
90
|
const wranglerConfig: Record<string, any> = {
|
|
53
91
|
name: cfWorkerName,
|
|
54
92
|
main: 'index.mjs',
|
|
55
93
|
compatibility_date: '2024-12-02',
|
|
56
94
|
compatibility_flags: ['nodejs_compat'],
|
|
57
|
-
build: {
|
|
58
|
-
command: 'npm install',
|
|
59
|
-
},
|
|
60
95
|
observability: {
|
|
61
96
|
logs: {
|
|
62
97
|
enabled: true,
|
|
63
98
|
},
|
|
64
99
|
},
|
|
65
|
-
vars:
|
|
100
|
+
vars: envsAsObject,
|
|
66
101
|
};
|
|
67
102
|
|
|
68
103
|
if (!this.workerNamespace && this.routes) {
|
|
69
104
|
wranglerConfig.routes = this.routes;
|
|
70
105
|
}
|
|
71
106
|
|
|
72
|
-
writeFileSync(join(
|
|
107
|
+
writeFileSync(join(outputDirectory, 'wrangler.json'), JSON.stringify(wranglerConfig));
|
|
73
108
|
}
|
|
74
109
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
private getEntry(): string {
|
|
111
|
+
return `
|
|
112
|
+
export default {
|
|
113
|
+
fetch: async (request, env, context) => {
|
|
114
|
+
Object.keys(env).forEach(key => {
|
|
115
|
+
process.env[key] = env[key]
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const { mastra } = await import('#mastra')
|
|
119
|
+
const { createHonoServer } = await import('#server')
|
|
120
|
+
const app = await createHonoServer(mastra)
|
|
121
|
+
return app.fetch(request, env, context);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async bundle(mastraDir: string, outputDirectory: string): Promise<void> {
|
|
128
|
+
const bundler = await getBundler(
|
|
129
|
+
{
|
|
130
|
+
input: '#entry',
|
|
131
|
+
plugins: [virtual({ '#entry': this.getEntry() })],
|
|
132
|
+
external: [/^@opentelemetry\//],
|
|
133
|
+
treeshake: 'smallest',
|
|
134
|
+
},
|
|
135
|
+
'browser',
|
|
89
136
|
);
|
|
137
|
+
|
|
138
|
+
bundler.write({
|
|
139
|
+
inlineDynamicImports: true,
|
|
140
|
+
file: join(outputDirectory, 'index.mjs'),
|
|
141
|
+
format: 'es',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async prepare(outputDirectory: string): Promise<void> {
|
|
146
|
+
await super.prepare(outputDirectory);
|
|
147
|
+
await this.writeFiles(outputDirectory);
|
|
90
148
|
}
|
|
91
149
|
|
|
92
|
-
|
|
150
|
+
async deploy(outputDirectory: string): Promise<void> {
|
|
93
151
|
const cmd = this.workerNamespace
|
|
94
152
|
? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}`
|
|
95
153
|
: 'npm exec -- wrangler deploy';
|
|
96
154
|
|
|
97
155
|
const cpLogger = createChildProcessLogger({
|
|
98
156
|
logger: this.logger,
|
|
99
|
-
root:
|
|
157
|
+
root: outputDirectory,
|
|
100
158
|
});
|
|
101
159
|
|
|
102
160
|
await cpLogger({
|
|
103
161
|
cmd,
|
|
104
162
|
args: [],
|
|
105
163
|
env: {
|
|
106
|
-
CLOUDFLARE_API_TOKEN:
|
|
164
|
+
CLOUDFLARE_API_TOKEN: this.cloudflare!.apiToken!,
|
|
107
165
|
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
108
166
|
...this.env,
|
|
109
167
|
PATH: process.env.PATH!,
|
package/tsconfig.json
CHANGED