@mastra/deployer-netlify 1.2.11-alpha.0 → 1.2.11
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 +8 -0
- package/dist/index.cjs +146 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +121 -131
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mastra/deployer-netlify
|
|
2
2
|
|
|
3
|
+
## 1.2.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`ce93a3c`](https://github.com/mastra-ai/mastra/commit/ce93a3c114ea1cbfbd576f3db41d7c26c9844f5b), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`a211d09`](https://github.com/mastra-ai/mastra/commit/a211d09185dc65a746534914cf38b67f21ee9bac), [`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa), [`6218217`](https://github.com/mastra-ai/mastra/commit/62182171b6cfca0b099f1c6a77a2e65e7639ab86), [`5807d3a`](https://github.com/mastra-ai/mastra/commit/5807d3ae1d259b8b7d6df7e5bf2b485c694af9c8), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`05db566`](https://github.com/mastra-ai/mastra/commit/05db566fcbdcbf33d0bffca0c72ec30129e2e3ca), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`d1b7e3a`](https://github.com/mastra-ai/mastra/commit/d1b7e3a978a309a5653eeaa490d2d6c7c53bd093), [`29c584a`](https://github.com/mastra-ai/mastra/commit/29c584a13a88831e5ed1fdeb0ff8e82eae180433), [`c093146`](https://github.com/mastra-ai/mastra/commit/c0931466404d3c521308ea119cb165bb7e695155), [`8124754`](https://github.com/mastra-ai/mastra/commit/8124754ae89fbc69f8136d1df4a91904d0f84c4e), [`d12b2e4`](https://github.com/mastra-ai/mastra/commit/d12b2e4023fd9e3d3e93a9169f5088bcee2a849c)]:
|
|
8
|
+
- @mastra/core@1.54.0
|
|
9
|
+
- @mastra/deployer@1.54.0
|
|
10
|
+
|
|
3
11
|
## 1.2.11-alpha.0
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,131 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let module$1 = require("module");
|
|
25
|
+
let path = require("path");
|
|
26
|
+
let process = require("process");
|
|
27
|
+
process = __toESM(process, 1);
|
|
28
|
+
let _mastra_deployer = require("@mastra/deployer");
|
|
29
|
+
let _mastra_deployer_services = require("@mastra/deployer/services");
|
|
30
|
+
let fs_extra_esm = require("fs-extra/esm");
|
|
31
|
+
//#region src/index.ts
|
|
32
|
+
/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */
|
|
33
|
+
const builtins = new Set(module$1.builtinModules.filter((m) => !m.startsWith("_")));
|
|
34
|
+
/**
|
|
35
|
+
* Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.
|
|
36
|
+
* Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.
|
|
37
|
+
*/
|
|
16
38
|
function nodeBuiltinPrefix() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
return {
|
|
40
|
+
name: "node-builtin-prefix",
|
|
41
|
+
resolveId(source) {
|
|
42
|
+
const base = source.split("/")[0];
|
|
43
|
+
if (builtins.has(base) && !source.startsWith("node:")) return {
|
|
44
|
+
id: `node:${source}`,
|
|
45
|
+
external: true
|
|
46
|
+
};
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
27
50
|
}
|
|
28
|
-
|
|
51
|
+
/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */
|
|
52
|
+
const EDGE_INCOMPATIBLE_MODULES = [
|
|
53
|
+
"bufferutil",
|
|
54
|
+
"utf-8-validate",
|
|
55
|
+
"typescript"
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Rollup plugin that replaces edge-incompatible modules with an empty stub so
|
|
59
|
+
* they do not appear as external imports in the bundle.
|
|
60
|
+
*/
|
|
29
61
|
function stubEdgeIncompatibleModules() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
};
|
|
62
|
+
const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);
|
|
63
|
+
const STUB_ID = "\0mastra-netlify-edge-stub";
|
|
64
|
+
return {
|
|
65
|
+
name: "stub-edge-incompatible-modules",
|
|
66
|
+
resolveId(source) {
|
|
67
|
+
return stubs.has(source) ? STUB_ID : null;
|
|
68
|
+
},
|
|
69
|
+
load(id) {
|
|
70
|
+
if (id === STUB_ID) return "export default undefined;";
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
44
74
|
}
|
|
45
|
-
var NetlifyDeployer = class extends
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
included_files: [".netlify/v1/functions/**"]
|
|
111
|
-
},
|
|
112
|
-
redirects: [
|
|
113
|
-
{
|
|
114
|
-
force: true,
|
|
115
|
-
from: "/*",
|
|
116
|
-
to: "/.netlify/functions/api/:splat",
|
|
117
|
-
status: 200
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
await esm.move(path.join(outputDirectory, ".netlify", "v1"), path.join(process__default.default.cwd(), ".netlify", "v1"), {
|
|
123
|
-
overwrite: true
|
|
124
|
-
});
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
getEntry() {
|
|
128
|
-
return `
|
|
75
|
+
var NetlifyDeployer = class extends _mastra_deployer.Deployer {
|
|
76
|
+
target;
|
|
77
|
+
constructor(options = {}) {
|
|
78
|
+
super({ name: "NETLIFY" });
|
|
79
|
+
this.target = options.target ?? "serverless";
|
|
80
|
+
this.outputDir = this.target === "edge" ? (0, path.join)(".netlify", "v1", "edge-functions") : (0, path.join)(".netlify", "v1", "functions", "api");
|
|
81
|
+
}
|
|
82
|
+
async installDependencies(outputDirectory, rootDir = process.default.cwd()) {
|
|
83
|
+
const deps = new _mastra_deployer_services.DepsService(rootDir);
|
|
84
|
+
deps.__setLogger(this.logger);
|
|
85
|
+
if (this.target === "edge") await deps.install({ dir: (0, path.join)(outputDirectory, this.outputDir) });
|
|
86
|
+
else await deps.install({
|
|
87
|
+
dir: (0, path.join)(outputDirectory, this.outputDir),
|
|
88
|
+
architecture: {
|
|
89
|
+
os: ["linux"],
|
|
90
|
+
cpu: ["x64"],
|
|
91
|
+
libc: ["gnu"]
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async deploy() {
|
|
96
|
+
this.logger?.info("Deploying to Netlify failed. Please use the Netlify dashboard to deploy.");
|
|
97
|
+
}
|
|
98
|
+
async prepare(outputDirectory) {
|
|
99
|
+
await super.prepare(outputDirectory);
|
|
100
|
+
}
|
|
101
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, bundlerOptions) {
|
|
102
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
|
|
103
|
+
...bundlerOptions,
|
|
104
|
+
enableEsmShim: this.target !== "edge"
|
|
105
|
+
});
|
|
106
|
+
if (this.target === "edge" && Array.isArray(inputOptions.plugins)) {
|
|
107
|
+
inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());
|
|
108
|
+
if (Array.isArray(inputOptions.external)) inputOptions.external = inputOptions.external.filter((id) => !EDGE_INCOMPATIBLE_MODULES.includes(id));
|
|
109
|
+
}
|
|
110
|
+
return inputOptions;
|
|
111
|
+
}
|
|
112
|
+
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
113
|
+
const result = await this._bundle(this.getEntry(), entryFile, {
|
|
114
|
+
outputDirectory,
|
|
115
|
+
projectRoot,
|
|
116
|
+
enableEsmShim: this.target !== "edge"
|
|
117
|
+
}, toolsPaths, (0, path.join)(outputDirectory, this.outputDir));
|
|
118
|
+
if (this.target === "edge") await (0, fs_extra_esm.writeJson)((0, path.join)(outputDirectory, ".netlify", "v1", "config.json"), { edge_functions: [{
|
|
119
|
+
function: "index",
|
|
120
|
+
path: "/*"
|
|
121
|
+
}] });
|
|
122
|
+
else await (0, fs_extra_esm.writeJson)((0, path.join)(outputDirectory, ".netlify", "v1", "config.json"), {
|
|
123
|
+
functions: {
|
|
124
|
+
directory: ".netlify/v1/functions",
|
|
125
|
+
node_bundler: "none",
|
|
126
|
+
included_files: [".netlify/v1/functions/**"]
|
|
127
|
+
},
|
|
128
|
+
redirects: [{
|
|
129
|
+
force: true,
|
|
130
|
+
from: "/*",
|
|
131
|
+
to: "/.netlify/functions/api/:splat",
|
|
132
|
+
status: 200
|
|
133
|
+
}]
|
|
134
|
+
});
|
|
135
|
+
await (0, fs_extra_esm.move)((0, path.join)(outputDirectory, ".netlify", "v1"), (0, path.join)(process.default.cwd(), ".netlify", "v1"), { overwrite: true });
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
getEntry() {
|
|
139
|
+
return `
|
|
129
140
|
import { handle } from 'hono/netlify'
|
|
130
141
|
import { mastra } from '#mastra';
|
|
131
142
|
import { createHonoServer, getToolExports } from '#server';
|
|
@@ -140,20 +151,17 @@ var NetlifyDeployer = class extends deployer.Deployer {
|
|
|
140
151
|
|
|
141
152
|
export default handle(app)
|
|
142
153
|
`;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
process__default.default.exit(1);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
154
|
+
}
|
|
155
|
+
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
156
|
+
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
157
|
+
if (await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`) {
|
|
158
|
+
this.logger?.error(`Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.
|
|
159
|
+
LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`);
|
|
160
|
+
process.default.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
155
163
|
};
|
|
156
|
-
|
|
164
|
+
//#endregion
|
|
157
165
|
exports.NetlifyDeployer = NetlifyDeployer;
|
|
158
|
-
|
|
166
|
+
|
|
159
167
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["builtinModules","Deployer","join","process","DepsService","writeJson","move"],"mappings":";;;;;;;;;;;;;;AAUA,IAAM,QAAA,GAAW,IAAI,GAAA,CAAIA,uBAAA,CAAe,MAAA,CAAO,CAAA,CAAA,KAAK,CAAC,CAAA,CAAE,UAAA,CAAW,GAAG,CAAC,CAAC,CAAA;AAMvE,SAAS,iBAAA,GAAoB;AAC3B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,qBAAA;AAAA,IACN,UAAU,MAAA,EAAgB;AACxB,MAAA,MAAM,IAAA,GAAO,MAAA,CAAO,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAChC,MAAA,IAAI,QAAA,CAAS,IAAI,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,UAAA,CAAW,OAAO,CAAA,EAAG;AACrD,QAAA,OAAO,EAAE,EAAA,EAAI,CAAA,KAAA,EAAQ,MAAM,CAAA,CAAA,EAAI,UAAU,IAAA,EAAK;AAAA,MAChD;AACA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF;AAGA,IAAM,yBAAA,GAA4B,CAAC,YAAA,EAAc,gBAAA,EAAkB,YAAY,CAAA;AAM/E,SAAS,2BAAA,GAA8B;AACrC,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,yBAAyB,CAAA;AAC/C,EAAA,MAAM,OAAA,GAAU,4BAAA;AAChB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gCAAA;AAAA,IACN,UAAU,MAAA,EAAgB;AACxB,MAAA,OAAO,KAAA,CAAM,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mB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAGvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,EAAQ,KAAA;AAAA,QACX,CAAA;AAAA,gKAAA;AAAA,OAEF;AACA,MAAAA,wBAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { builtinModules } from 'node:module';\nimport { join } from 'node:path';\nimport process from 'node:process';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport { DepsService } from '@mastra/deployer/services';\nimport { move, writeJson } from 'fs-extra/esm';\n\n/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */\nconst builtins = new Set(builtinModules.filter(m => !m.startsWith('_')));\n\n/**\n * Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.\n * Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.\n */\nfunction nodeBuiltinPrefix() {\n return {\n name: 'node-builtin-prefix',\n resolveId(source: string) {\n const base = source.split('/')[0]!;\n if (builtins.has(base) && !source.startsWith('node:')) {\n return { id: `node:${source}`, external: true };\n }\n return null;\n },\n };\n}\n\n/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */\nconst EDGE_INCOMPATIBLE_MODULES = ['bufferutil', 'utf-8-validate', 'typescript'];\n\n/**\n * Rollup plugin that replaces edge-incompatible modules with an empty stub so\n * they do not appear as external imports in the bundle.\n */\nfunction stubEdgeIncompatibleModules() {\n const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);\n const STUB_ID = '\\0mastra-netlify-edge-stub';\n return {\n name: 'stub-edge-incompatible-modules',\n resolveId(source: string) {\n return stubs.has(source) ? STUB_ID : null;\n },\n load(id: string) {\n if (id === STUB_ID) {\n return 'export default undefined;';\n }\n return null;\n },\n };\n}\n\nexport interface NetlifyDeployerOptions {\n /**\n * Deploy target for Netlify.\n *\n * - `'serverless'` — Standard Netlify Functions (Node.js runtime, 60s default timeout).\n * - `'edge'` — Netlify Edge Functions (Deno-based runtime, no hard timeout, runs at the edge).\n *\n * @default 'serverless'\n */\n target?: 'serverless' | 'edge';\n}\n\nexport class NetlifyDeployer extends Deployer {\n readonly target: 'serverless' | 'edge';\n\n constructor(options: NetlifyDeployerOptions = {}) {\n super({ name: 'NETLIFY' });\n\n this.target = options.target ?? 'serverless';\n\n this.outputDir =\n this.target === 'edge' ? join('.netlify', 'v1', 'edge-functions') : join('.netlify', 'v1', 'functions', 'api');\n }\n\n protected async installDependencies(outputDirectory: string, rootDir = process.cwd()) {\n const deps = new DepsService(rootDir);\n deps.__setLogger(this.logger);\n\n if (this.target === 'edge') {\n // Edge functions run on Deno — no platform-specific architecture constraints\n await deps.install({ dir: join(outputDirectory, this.outputDir) });\n } else {\n await deps.install({\n dir: join(outputDirectory, this.outputDir),\n architecture: {\n os: ['linux'],\n cpu: ['x64'],\n libc: ['gnu'],\n },\n });\n }\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Netlify failed. Please use the Netlify dashboard to deploy.');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: this.target !== 'edge',\n });\n\n if (this.target === 'edge' && Array.isArray(inputOptions.plugins)) {\n // Run before subpathExternalsResolver so the resolveId hooks win.\n inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());\n\n // Drop edge-incompatible modules from Rollup's external list so the stub plugin can redirect them.\n if (Array.isArray(inputOptions.external)) {\n inputOptions.external = inputOptions.external.filter(id => !EDGE_INCOMPATIBLE_MODULES.includes(id as string));\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot, enableEsmShim: this.target !== 'edge' },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n // Use Netlify Frameworks API config.json\n // https://docs.netlify.com/build/frameworks/frameworks-api/\n if (this.target === 'edge') {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n edge_functions: [\n {\n function: 'index',\n path: '/*',\n },\n ],\n });\n } else {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n functions: {\n directory: '.netlify/v1/functions',\n node_bundler: 'none', // Mastra pre-bundles, don't re-bundle\n included_files: ['.netlify/v1/functions/**'],\n },\n redirects: [\n {\n force: true,\n from: '/*',\n to: '/.netlify/functions/api/:splat',\n status: 200,\n },\n ],\n });\n }\n\n await move(join(outputDirectory, '.netlify', 'v1'), join(process.cwd(), '.netlify', 'v1'), {\n overwrite: true,\n });\n\n return result;\n }\n\n private getEntry(): string {\n return `\n import { handle } from 'hono/netlify'\n import { mastra } from '#mastra';\n import { createHonoServer, getToolExports } from '#server';\n import { tools } from '#tools';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n if (mastra.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\n export default handle(app)\n`;\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n // LibSQL uses native Node.js bindings — incompatible with both serverless and edge environments\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger?.error(\n `Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.\n LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`,\n );\n process.exit(1);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["builtinModules","Deployer","DepsService"],"sources":["../src/index.ts"],"sourcesContent":["import { builtinModules } from 'node:module';\nimport { join } from 'node:path';\nimport process from 'node:process';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport { DepsService } from '@mastra/deployer/services';\nimport { move, writeJson } from 'fs-extra/esm';\n\n/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */\nconst builtins = new Set(builtinModules.filter(m => !m.startsWith('_')));\n\n/**\n * Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.\n * Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.\n */\nfunction nodeBuiltinPrefix() {\n return {\n name: 'node-builtin-prefix',\n resolveId(source: string) {\n const base = source.split('/')[0]!;\n if (builtins.has(base) && !source.startsWith('node:')) {\n return { id: `node:${source}`, external: true };\n }\n return null;\n },\n };\n}\n\n/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */\nconst EDGE_INCOMPATIBLE_MODULES = ['bufferutil', 'utf-8-validate', 'typescript'];\n\n/**\n * Rollup plugin that replaces edge-incompatible modules with an empty stub so\n * they do not appear as external imports in the bundle.\n */\nfunction stubEdgeIncompatibleModules() {\n const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);\n const STUB_ID = '\\0mastra-netlify-edge-stub';\n return {\n name: 'stub-edge-incompatible-modules',\n resolveId(source: string) {\n return stubs.has(source) ? STUB_ID : null;\n },\n load(id: string) {\n if (id === STUB_ID) {\n return 'export default undefined;';\n }\n return null;\n },\n };\n}\n\nexport interface NetlifyDeployerOptions {\n /**\n * Deploy target for Netlify.\n *\n * - `'serverless'` — Standard Netlify Functions (Node.js runtime, 60s default timeout).\n * - `'edge'` — Netlify Edge Functions (Deno-based runtime, no hard timeout, runs at the edge).\n *\n * @default 'serverless'\n */\n target?: 'serverless' | 'edge';\n}\n\nexport class NetlifyDeployer extends Deployer {\n readonly target: 'serverless' | 'edge';\n\n constructor(options: NetlifyDeployerOptions = {}) {\n super({ name: 'NETLIFY' });\n\n this.target = options.target ?? 'serverless';\n\n this.outputDir =\n this.target === 'edge' ? join('.netlify', 'v1', 'edge-functions') : join('.netlify', 'v1', 'functions', 'api');\n }\n\n protected async installDependencies(outputDirectory: string, rootDir = process.cwd()) {\n const deps = new DepsService(rootDir);\n deps.__setLogger(this.logger);\n\n if (this.target === 'edge') {\n // Edge functions run on Deno — no platform-specific architecture constraints\n await deps.install({ dir: join(outputDirectory, this.outputDir) });\n } else {\n await deps.install({\n dir: join(outputDirectory, this.outputDir),\n architecture: {\n os: ['linux'],\n cpu: ['x64'],\n libc: ['gnu'],\n },\n });\n }\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Netlify failed. Please use the Netlify dashboard to deploy.');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: this.target !== 'edge',\n });\n\n if (this.target === 'edge' && Array.isArray(inputOptions.plugins)) {\n // Run before subpathExternalsResolver so the resolveId hooks win.\n inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());\n\n // Drop edge-incompatible modules from Rollup's external list so the stub plugin can redirect them.\n if (Array.isArray(inputOptions.external)) {\n inputOptions.external = inputOptions.external.filter(id => !EDGE_INCOMPATIBLE_MODULES.includes(id as string));\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot, enableEsmShim: this.target !== 'edge' },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n // Use Netlify Frameworks API config.json\n // https://docs.netlify.com/build/frameworks/frameworks-api/\n if (this.target === 'edge') {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n edge_functions: [\n {\n function: 'index',\n path: '/*',\n },\n ],\n });\n } else {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n functions: {\n directory: '.netlify/v1/functions',\n node_bundler: 'none', // Mastra pre-bundles, don't re-bundle\n included_files: ['.netlify/v1/functions/**'],\n },\n redirects: [\n {\n force: true,\n from: '/*',\n to: '/.netlify/functions/api/:splat',\n status: 200,\n },\n ],\n });\n }\n\n await move(join(outputDirectory, '.netlify', 'v1'), join(process.cwd(), '.netlify', 'v1'), {\n overwrite: true,\n });\n\n return result;\n }\n\n private getEntry(): string {\n return `\n import { handle } from 'hono/netlify'\n import { mastra } from '#mastra';\n import { createHonoServer, getToolExports } from '#server';\n import { tools } from '#tools';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n if (mastra.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\n export default handle(app)\n`;\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n // LibSQL uses native Node.js bindings — incompatible with both serverless and edge environments\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger?.error(\n `Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.\n LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`,\n );\n process.exit(1);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,WAAW,IAAI,IAAIA,SAAAA,eAAe,QAAO,MAAK,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC;;;;;AAMvE,SAAS,oBAAoB;CAC3B,OAAO;EACL,MAAM;EACN,UAAU,QAAgB;GACxB,MAAM,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;GAC/B,IAAI,SAAS,IAAI,IAAI,KAAK,CAAC,OAAO,WAAW,OAAO,GAClD,OAAO;IAAE,IAAI,QAAQ;IAAU,UAAU;GAAK;GAEhD,OAAO;EACT;CACF;AACF;;AAGA,MAAM,4BAA4B;CAAC;CAAc;CAAkB;AAAY;;;;;AAM/E,SAAS,8BAA8B;CACrC,MAAM,QAAQ,IAAI,IAAI,yBAAyB;CAC/C,MAAM,UAAU;CAChB,OAAO;EACL,MAAM;EACN,UAAU,QAAgB;GACxB,OAAO,MAAM,IAAI,MAAM,IAAI,UAAU;EACvC;EACA,KAAK,IAAY;GACf,IAAI,OAAO,SACT,OAAO;GAET,OAAO;EACT;CACF;AACF;AAcA,IAAa,kBAAb,cAAqCC,iBAAAA,SAAS;CAC5C;CAEA,YAAY,UAAkC,CAAC,GAAG;EAChD,MAAM,EAAE,MAAM,UAAU,CAAC;EAEzB,KAAK,SAAS,QAAQ,UAAU;EAEhC,KAAK,YACH,KAAK,WAAW,UAAA,GAA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,GACtE,aAAA,GAAA,KAAA,KAAA,CACK,iBAAiB,KAAK,SAAS,CACtC;EAIA,IAAI,KAAK,WAAW,QAClB,OAAA,GAAA,aAAA,UAAA,EAAA,GAAA,KAAA,KAAA,CAAqB,iBAAiB,YAAY,MAAM,aAAa,GAAG,EACtE,gBAAgB,CACd;GACE,UAAU;GACV,MAAM;EACR,CACF,EACF,CAAC;OAED,OAAA,GAAA,aAAA,UAAA,EAAA,GAAA,KAAA,KAAA,CAAqB,iBAAiB,YAAY,MAAM,aAAa,GAAG;GACtE,WAAW;IACT,WAAW;IACX,cAAc;IACd,gBAAgB,CAAC,0BAA0B;GAC7C;GACA,WAAW,CACT;IACE,OAAO;IACP,MAAM;IACN,IAAI;IACJ,QAAQ;GACV,CACF;EACF,CAAC;EAGH,OAAA,GAAA,aAAA,KAAA,EAAA,GAAA,KAAA,KAAA,CAAgB,iBAAiB,YAAY,IAAI,IAAA,GAAA,KAAA,KAAA,CAAQ,QAAA,QAAQ,IAAI,GAAG,YAAY,IAAI,GAAG,EACzF,WAAW,KACb,CAAC;EAED,OAAO;CACT;CAEA,WAA2B;EACzB,OAAO;;;;;;;;;;;;;;;CAeT;CAEA,MAAM,KAAK,WAAmB,iBAAyB,YAAkD;EACvG,MAAM,MAAM,KAAK,WAAW,iBAAiB,UAAU;EAKvD,IAFmB,MAAM,KAAK,KAAK,kBAAkB,CAAC,gBAAgB,CAAC,MAAO,MAE/D;GACb,KAAK,QAAQ,MACX;iKAEF;GACA,QAAA,QAAQ,KAAK,CAAC;EAChB;CACF;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,125 +1,118 @@
|
|
|
1
|
-
import { builtinModules } from
|
|
2
|
-
import { join } from
|
|
3
|
-
import process from
|
|
4
|
-
import { Deployer } from
|
|
5
|
-
import { DepsService } from
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { builtinModules } from "module";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import process from "process";
|
|
4
|
+
import { Deployer } from "@mastra/deployer";
|
|
5
|
+
import { DepsService } from "@mastra/deployer/services";
|
|
6
|
+
import { move, writeJson } from "fs-extra/esm";
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */
|
|
9
|
+
const builtins = new Set(builtinModules.filter((m) => !m.startsWith("_")));
|
|
10
|
+
/**
|
|
11
|
+
* Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.
|
|
12
|
+
* Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.
|
|
13
|
+
*/
|
|
10
14
|
function nodeBuiltinPrefix() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
return {
|
|
16
|
+
name: "node-builtin-prefix",
|
|
17
|
+
resolveId(source) {
|
|
18
|
+
const base = source.split("/")[0];
|
|
19
|
+
if (builtins.has(base) && !source.startsWith("node:")) return {
|
|
20
|
+
id: `node:${source}`,
|
|
21
|
+
external: true
|
|
22
|
+
};
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */
|
|
28
|
+
const EDGE_INCOMPATIBLE_MODULES = [
|
|
29
|
+
"bufferutil",
|
|
30
|
+
"utf-8-validate",
|
|
31
|
+
"typescript"
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Rollup plugin that replaces edge-incompatible modules with an empty stub so
|
|
35
|
+
* they do not appear as external imports in the bundle.
|
|
36
|
+
*/
|
|
23
37
|
function stubEdgeIncompatibleModules() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
+
const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);
|
|
39
|
+
const STUB_ID = "\0mastra-netlify-edge-stub";
|
|
40
|
+
return {
|
|
41
|
+
name: "stub-edge-incompatible-modules",
|
|
42
|
+
resolveId(source) {
|
|
43
|
+
return stubs.has(source) ? STUB_ID : null;
|
|
44
|
+
},
|
|
45
|
+
load(id) {
|
|
46
|
+
if (id === STUB_ID) return "export default undefined;";
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
38
50
|
}
|
|
39
51
|
var NetlifyDeployer = class extends Deployer {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
included_files: [".netlify/v1/functions/**"]
|
|
105
|
-
},
|
|
106
|
-
redirects: [
|
|
107
|
-
{
|
|
108
|
-
force: true,
|
|
109
|
-
from: "/*",
|
|
110
|
-
to: "/.netlify/functions/api/:splat",
|
|
111
|
-
status: 200
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
await move(join(outputDirectory, ".netlify", "v1"), join(process.cwd(), ".netlify", "v1"), {
|
|
117
|
-
overwrite: true
|
|
118
|
-
});
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
getEntry() {
|
|
122
|
-
return `
|
|
52
|
+
target;
|
|
53
|
+
constructor(options = {}) {
|
|
54
|
+
super({ name: "NETLIFY" });
|
|
55
|
+
this.target = options.target ?? "serverless";
|
|
56
|
+
this.outputDir = this.target === "edge" ? join(".netlify", "v1", "edge-functions") : join(".netlify", "v1", "functions", "api");
|
|
57
|
+
}
|
|
58
|
+
async installDependencies(outputDirectory, rootDir = process.cwd()) {
|
|
59
|
+
const deps = new DepsService(rootDir);
|
|
60
|
+
deps.__setLogger(this.logger);
|
|
61
|
+
if (this.target === "edge") await deps.install({ dir: join(outputDirectory, this.outputDir) });
|
|
62
|
+
else await deps.install({
|
|
63
|
+
dir: join(outputDirectory, this.outputDir),
|
|
64
|
+
architecture: {
|
|
65
|
+
os: ["linux"],
|
|
66
|
+
cpu: ["x64"],
|
|
67
|
+
libc: ["gnu"]
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async deploy() {
|
|
72
|
+
this.logger?.info("Deploying to Netlify failed. Please use the Netlify dashboard to deploy.");
|
|
73
|
+
}
|
|
74
|
+
async prepare(outputDirectory) {
|
|
75
|
+
await super.prepare(outputDirectory);
|
|
76
|
+
}
|
|
77
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, bundlerOptions) {
|
|
78
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
|
|
79
|
+
...bundlerOptions,
|
|
80
|
+
enableEsmShim: this.target !== "edge"
|
|
81
|
+
});
|
|
82
|
+
if (this.target === "edge" && Array.isArray(inputOptions.plugins)) {
|
|
83
|
+
inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());
|
|
84
|
+
if (Array.isArray(inputOptions.external)) inputOptions.external = inputOptions.external.filter((id) => !EDGE_INCOMPATIBLE_MODULES.includes(id));
|
|
85
|
+
}
|
|
86
|
+
return inputOptions;
|
|
87
|
+
}
|
|
88
|
+
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
89
|
+
const result = await this._bundle(this.getEntry(), entryFile, {
|
|
90
|
+
outputDirectory,
|
|
91
|
+
projectRoot,
|
|
92
|
+
enableEsmShim: this.target !== "edge"
|
|
93
|
+
}, toolsPaths, join(outputDirectory, this.outputDir));
|
|
94
|
+
if (this.target === "edge") await writeJson(join(outputDirectory, ".netlify", "v1", "config.json"), { edge_functions: [{
|
|
95
|
+
function: "index",
|
|
96
|
+
path: "/*"
|
|
97
|
+
}] });
|
|
98
|
+
else await writeJson(join(outputDirectory, ".netlify", "v1", "config.json"), {
|
|
99
|
+
functions: {
|
|
100
|
+
directory: ".netlify/v1/functions",
|
|
101
|
+
node_bundler: "none",
|
|
102
|
+
included_files: [".netlify/v1/functions/**"]
|
|
103
|
+
},
|
|
104
|
+
redirects: [{
|
|
105
|
+
force: true,
|
|
106
|
+
from: "/*",
|
|
107
|
+
to: "/.netlify/functions/api/:splat",
|
|
108
|
+
status: 200
|
|
109
|
+
}]
|
|
110
|
+
});
|
|
111
|
+
await move(join(outputDirectory, ".netlify", "v1"), join(process.cwd(), ".netlify", "v1"), { overwrite: true });
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
getEntry() {
|
|
115
|
+
return `
|
|
123
116
|
import { handle } from 'hono/netlify'
|
|
124
117
|
import { mastra } from '#mastra';
|
|
125
118
|
import { createHonoServer, getToolExports } from '#server';
|
|
@@ -134,20 +127,17 @@ var NetlifyDeployer = class extends Deployer {
|
|
|
134
127
|
|
|
135
128
|
export default handle(app)
|
|
136
129
|
`;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
130
|
+
}
|
|
131
|
+
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
132
|
+
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
133
|
+
if (await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`) {
|
|
134
|
+
this.logger?.error(`Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.
|
|
135
|
+
LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
149
139
|
};
|
|
150
|
-
|
|
140
|
+
//#endregion
|
|
151
141
|
export { NetlifyDeployer };
|
|
152
|
-
|
|
142
|
+
|
|
153
143
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAUA,IAAM,QAAA,GAAW,IAAI,GAAA,CAAI,cAAA,CAAe,MAAA,CAAO,CAAA,CAAA,KAAK,CAAC,CAAA,CAAE,UAAA,CAAW,GAAG,CAAC,CAAC,CAAA;AAMvE,SAAS,iBAAA,GAAoB;AAC3B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,qBAAA;AAAA,IACN,UAAU,MAAA,EAAgB;AACxB,MAAA,MAAM,IAAA,GAAO,MAAA,CAAO,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA;AAChC,MAAA,IAAI,QAAA,CA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P,IAAA,EAAM,IAAA;AAAA,YACN,EAAA,EAAI,gCAAA;AAAA,YACJ,MAAA,EAAQ;AAAA;AACV;AACF,OACD,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,IAAA,CAAK,IAAA,CAAK,eAAA,EAAiB,UAAA,EAAY,IAAI,CAAA,EAAG,IAAA,CAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,UAAA,EAAY,IAAI,CAAA,EAAG;AAAA,MACzF,SAAA,EAAW;AAAA,KACZ,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEQ,QAAA,GAAmB;AACzB,IAAA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA,CAAA;AAAA,EAeT;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAGvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,EAAQ,KAAA;AAAA,QACX,CAAA;AAAA,gKAAA;AAAA,OAEF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import { builtinModules } from 'node:module';\nimport { join } from 'node:path';\nimport process from 'node:process';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport { DepsService } from '@mastra/deployer/services';\nimport { move, writeJson } from 'fs-extra/esm';\n\n/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */\nconst builtins = new Set(builtinModules.filter(m => !m.startsWith('_')));\n\n/**\n * Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.\n * Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.\n */\nfunction nodeBuiltinPrefix() {\n return {\n name: 'node-builtin-prefix',\n resolveId(source: string) {\n const base = source.split('/')[0]!;\n if (builtins.has(base) && !source.startsWith('node:')) {\n return { id: `node:${source}`, external: true };\n }\n return null;\n },\n };\n}\n\n/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */\nconst EDGE_INCOMPATIBLE_MODULES = ['bufferutil', 'utf-8-validate', 'typescript'];\n\n/**\n * Rollup plugin that replaces edge-incompatible modules with an empty stub so\n * they do not appear as external imports in the bundle.\n */\nfunction stubEdgeIncompatibleModules() {\n const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);\n const STUB_ID = '\\0mastra-netlify-edge-stub';\n return {\n name: 'stub-edge-incompatible-modules',\n resolveId(source: string) {\n return stubs.has(source) ? STUB_ID : null;\n },\n load(id: string) {\n if (id === STUB_ID) {\n return 'export default undefined;';\n }\n return null;\n },\n };\n}\n\nexport interface NetlifyDeployerOptions {\n /**\n * Deploy target for Netlify.\n *\n * - `'serverless'` — Standard Netlify Functions (Node.js runtime, 60s default timeout).\n * - `'edge'` — Netlify Edge Functions (Deno-based runtime, no hard timeout, runs at the edge).\n *\n * @default 'serverless'\n */\n target?: 'serverless' | 'edge';\n}\n\nexport class NetlifyDeployer extends Deployer {\n readonly target: 'serverless' | 'edge';\n\n constructor(options: NetlifyDeployerOptions = {}) {\n super({ name: 'NETLIFY' });\n\n this.target = options.target ?? 'serverless';\n\n this.outputDir =\n this.target === 'edge' ? join('.netlify', 'v1', 'edge-functions') : join('.netlify', 'v1', 'functions', 'api');\n }\n\n protected async installDependencies(outputDirectory: string, rootDir = process.cwd()) {\n const deps = new DepsService(rootDir);\n deps.__setLogger(this.logger);\n\n if (this.target === 'edge') {\n // Edge functions run on Deno — no platform-specific architecture constraints\n await deps.install({ dir: join(outputDirectory, this.outputDir) });\n } else {\n await deps.install({\n dir: join(outputDirectory, this.outputDir),\n architecture: {\n os: ['linux'],\n cpu: ['x64'],\n libc: ['gnu'],\n },\n });\n }\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Netlify failed. Please use the Netlify dashboard to deploy.');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: this.target !== 'edge',\n });\n\n if (this.target === 'edge' && Array.isArray(inputOptions.plugins)) {\n // Run before subpathExternalsResolver so the resolveId hooks win.\n inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());\n\n // Drop edge-incompatible modules from Rollup's external list so the stub plugin can redirect them.\n if (Array.isArray(inputOptions.external)) {\n inputOptions.external = inputOptions.external.filter(id => !EDGE_INCOMPATIBLE_MODULES.includes(id as string));\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot, enableEsmShim: this.target !== 'edge' },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n // Use Netlify Frameworks API config.json\n // https://docs.netlify.com/build/frameworks/frameworks-api/\n if (this.target === 'edge') {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n edge_functions: [\n {\n function: 'index',\n path: '/*',\n },\n ],\n });\n } else {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n functions: {\n directory: '.netlify/v1/functions',\n node_bundler: 'none', // Mastra pre-bundles, don't re-bundle\n included_files: ['.netlify/v1/functions/**'],\n },\n redirects: [\n {\n force: true,\n from: '/*',\n to: '/.netlify/functions/api/:splat',\n status: 200,\n },\n ],\n });\n }\n\n await move(join(outputDirectory, '.netlify', 'v1'), join(process.cwd(), '.netlify', 'v1'), {\n overwrite: true,\n });\n\n return result;\n }\n\n private getEntry(): string {\n return `\n import { handle } from 'hono/netlify'\n import { mastra } from '#mastra';\n import { createHonoServer, getToolExports } from '#server';\n import { tools } from '#tools';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n if (mastra.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\n export default handle(app)\n`;\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n // LibSQL uses native Node.js bindings — incompatible with both serverless and edge environments\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger?.error(\n `Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.\n LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`,\n );\n process.exit(1);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { builtinModules } from 'node:module';\nimport { join } from 'node:path';\nimport process from 'node:process';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport { DepsService } from '@mastra/deployer/services';\nimport { move, writeJson } from 'fs-extra/esm';\n\n/** Bare Node.js built-in module names (excludes internal `_`-prefixed ones). */\nconst builtins = new Set(builtinModules.filter(m => !m.startsWith('_')));\n\n/**\n * Rollup plugin that adds the `node:` prefix to bare Node.js built-in imports.\n * Deno requires `node:events` instead of `events`, `node:fs` instead of `fs`, etc.\n */\nfunction nodeBuiltinPrefix() {\n return {\n name: 'node-builtin-prefix',\n resolveId(source: string) {\n const base = source.split('/')[0]!;\n if (builtins.has(base) && !source.startsWith('node:')) {\n return { id: `node:${source}`, external: true };\n }\n return null;\n },\n };\n}\n\n/** Modules that Netlify's Edge bundler cannot resolve: native Node addons (`bufferutil`, `utf-8-validate`) and `typescript`. */\nconst EDGE_INCOMPATIBLE_MODULES = ['bufferutil', 'utf-8-validate', 'typescript'];\n\n/**\n * Rollup plugin that replaces edge-incompatible modules with an empty stub so\n * they do not appear as external imports in the bundle.\n */\nfunction stubEdgeIncompatibleModules() {\n const stubs = new Set(EDGE_INCOMPATIBLE_MODULES);\n const STUB_ID = '\\0mastra-netlify-edge-stub';\n return {\n name: 'stub-edge-incompatible-modules',\n resolveId(source: string) {\n return stubs.has(source) ? STUB_ID : null;\n },\n load(id: string) {\n if (id === STUB_ID) {\n return 'export default undefined;';\n }\n return null;\n },\n };\n}\n\nexport interface NetlifyDeployerOptions {\n /**\n * Deploy target for Netlify.\n *\n * - `'serverless'` — Standard Netlify Functions (Node.js runtime, 60s default timeout).\n * - `'edge'` — Netlify Edge Functions (Deno-based runtime, no hard timeout, runs at the edge).\n *\n * @default 'serverless'\n */\n target?: 'serverless' | 'edge';\n}\n\nexport class NetlifyDeployer extends Deployer {\n readonly target: 'serverless' | 'edge';\n\n constructor(options: NetlifyDeployerOptions = {}) {\n super({ name: 'NETLIFY' });\n\n this.target = options.target ?? 'serverless';\n\n this.outputDir =\n this.target === 'edge' ? join('.netlify', 'v1', 'edge-functions') : join('.netlify', 'v1', 'functions', 'api');\n }\n\n protected async installDependencies(outputDirectory: string, rootDir = process.cwd()) {\n const deps = new DepsService(rootDir);\n deps.__setLogger(this.logger);\n\n if (this.target === 'edge') {\n // Edge functions run on Deno — no platform-specific architecture constraints\n await deps.install({ dir: join(outputDirectory, this.outputDir) });\n } else {\n await deps.install({\n dir: join(outputDirectory, this.outputDir),\n architecture: {\n os: ['linux'],\n cpu: ['x64'],\n libc: ['gnu'],\n },\n });\n }\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Netlify failed. Please use the Netlify dashboard to deploy.');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: this.target !== 'edge',\n });\n\n if (this.target === 'edge' && Array.isArray(inputOptions.plugins)) {\n // Run before subpathExternalsResolver so the resolveId hooks win.\n inputOptions.plugins.unshift(nodeBuiltinPrefix(), stubEdgeIncompatibleModules());\n\n // Drop edge-incompatible modules from Rollup's external list so the stub plugin can redirect them.\n if (Array.isArray(inputOptions.external)) {\n inputOptions.external = inputOptions.external.filter(id => !EDGE_INCOMPATIBLE_MODULES.includes(id as string));\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot, enableEsmShim: this.target !== 'edge' },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n // Use Netlify Frameworks API config.json\n // https://docs.netlify.com/build/frameworks/frameworks-api/\n if (this.target === 'edge') {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n edge_functions: [\n {\n function: 'index',\n path: '/*',\n },\n ],\n });\n } else {\n await writeJson(join(outputDirectory, '.netlify', 'v1', 'config.json'), {\n functions: {\n directory: '.netlify/v1/functions',\n node_bundler: 'none', // Mastra pre-bundles, don't re-bundle\n included_files: ['.netlify/v1/functions/**'],\n },\n redirects: [\n {\n force: true,\n from: '/*',\n to: '/.netlify/functions/api/:splat',\n status: 200,\n },\n ],\n });\n }\n\n await move(join(outputDirectory, '.netlify', 'v1'), join(process.cwd(), '.netlify', 'v1'), {\n overwrite: true,\n });\n\n return result;\n }\n\n private getEntry(): string {\n return `\n import { handle } from 'hono/netlify'\n import { mastra } from '#mastra';\n import { createHonoServer, getToolExports } from '#server';\n import { tools } from '#tools';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n if (mastra.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\n export default handle(app)\n`;\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n // LibSQL uses native Node.js bindings — incompatible with both serverless and edge environments\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger?.error(\n `Netlify Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency.\n LibSQL with file URLs uses native Node.js bindings that cannot run in Netlify serverless or edge environments. Use other Mastra Storage options instead.`,\n );\n process.exit(1);\n }\n }\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,WAAW,IAAI,IAAI,eAAe,QAAO,MAAK,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC;;;;;AAMvE,SAAS,oBAAoB;CAC3B,OAAO;EACL,MAAM;EACN,UAAU,QAAgB;GACxB,MAAM,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;GAC/B,IAAI,SAAS,IAAI,IAAI,KAAK,CAAC,OAAO,WAAW,OAAO,GAClD,OAAO;IAAE,IAAI,QAAQ;IAAU,UAAU;GAAK;GAEhD,OAAO;EACT;CACF;AACF;;AAGA,MAAM,4BAA4B;CA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name": "@mastra/deployer-netlify",
|
|
3
|
-
"version": "1.2.11
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"fs-extra": "^11.3.5",
|
|
30
30
|
"rollup": "^4.61.1",
|
|
31
|
-
"@mastra/deployer": "^1.54.0
|
|
31
|
+
"@mastra/deployer": "^1.54.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"@vitest/coverage-v8": "4.1.10",
|
|
37
37
|
"@vitest/ui": "4.1.10",
|
|
38
38
|
"eslint": "^10.7.0",
|
|
39
|
-
"
|
|
39
|
+
"tsdown": "0.22.9",
|
|
40
40
|
"typescript": "^6.0.3",
|
|
41
41
|
"vitest": "4.1.10",
|
|
42
|
-
"@internal/lint": "0.0.
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
42
|
+
"@internal/lint": "0.0.118",
|
|
43
|
+
"@mastra/core": "1.54.0",
|
|
44
|
+
"@internal/types-builder": "0.0.93"
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://mastra.ai",
|
|
47
47
|
"repository": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"node": ">=22.13.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"build:watch": "
|
|
63
|
+
"build": "tsdown --silent --config tsdown.config.ts",
|
|
64
|
+
"build:watch": "tsdown --watch --silent --config tsdown.config.ts",
|
|
65
65
|
"test": "vitest run",
|
|
66
66
|
"lint": "oxlint . && eslint .",
|
|
67
67
|
"lint:fix": "oxlint --fix . && eslint --fix ."
|