@mastra/deployer 0.0.0-afterToolExecute-20250414225911
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/LICENSE.md +46 -0
- package/README.md +159 -0
- package/dist/_tsup-dts-rollup.d.cts +479 -0
- package/dist/_tsup-dts-rollup.d.ts +479 -0
- package/dist/build/analyze.cjs +10 -0
- package/dist/build/analyze.d.cts +1 -0
- package/dist/build/analyze.d.ts +1 -0
- package/dist/build/analyze.js +1 -0
- package/dist/build/bundler.cjs +14 -0
- package/dist/build/bundler.d.cts +2 -0
- package/dist/build/bundler.d.ts +2 -0
- package/dist/build/bundler.js +1 -0
- package/dist/build/index.cjs +47 -0
- package/dist/build/index.d.cts +9 -0
- package/dist/build/index.d.ts +9 -0
- package/dist/build/index.js +6 -0
- package/dist/bundler/index.cjs +10 -0
- package/dist/bundler/index.d.cts +1 -0
- package/dist/bundler/index.d.ts +1 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-2ZPQX6BX.cjs +254 -0
- package/dist/chunk-4AYFLP6G.js +227 -0
- package/dist/chunk-54KOF3NB.cjs +137 -0
- package/dist/chunk-AE4CVAPK.cjs +151 -0
- package/dist/chunk-BDTZS3JM.js +299 -0
- package/dist/chunk-DYQ225MJ.js +115 -0
- package/dist/chunk-I3UVE6EH.cjs +161 -0
- package/dist/chunk-IKPL4RGG.js +140 -0
- package/dist/chunk-JDY6E7BT.cjs +152 -0
- package/dist/chunk-MYE33AKL.cjs +195 -0
- package/dist/chunk-NCROGJGB.cjs +142 -0
- package/dist/chunk-P5SATU7G.cjs +310 -0
- package/dist/chunk-SQQUYWPS.js +144 -0
- package/dist/chunk-WB3T6NKI.js +133 -0
- package/dist/chunk-WVBUOQT6.js +111 -0
- package/dist/chunk-YQB677IB.js +183 -0
- package/dist/index.cjs +191 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +151 -0
- package/dist/server/index.cjs +3860 -0
- package/dist/server/index.d.cts +2 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +3853 -0
- package/dist/services/index.cjs +19 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +2 -0
- package/dist/templates/instrumentation-template.js +89 -0
- package/dist/validator/custom-resolver.cjs +52 -0
- package/dist/validator/custom-resolver.d.cts +1 -0
- package/dist/validator/custom-resolver.d.ts +1 -0
- package/dist/validator/custom-resolver.js +50 -0
- package/dist/validator/loader.cjs +7 -0
- package/dist/validator/loader.d.cts +1 -0
- package/dist/validator/loader.d.ts +1 -0
- package/dist/validator/loader.js +4 -0
- package/package.json +138 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept } from './chunk-4AYFLP6G.js';
|
|
2
|
+
import { aliasHono } from './chunk-BDTZS3JM.js';
|
|
3
|
+
import { getInputOptions } from './chunk-IKPL4RGG.js';
|
|
4
|
+
import { watch, rollup } from 'rollup';
|
|
5
|
+
import * as babel from '@babel/core';
|
|
6
|
+
import esbuild from 'rollup-plugin-esbuild';
|
|
7
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
8
|
+
|
|
9
|
+
async function getInputOptions2(entryFile, platform) {
|
|
10
|
+
const inputOptions = await getInputOptions(
|
|
11
|
+
entryFile,
|
|
12
|
+
{
|
|
13
|
+
dependencies: /* @__PURE__ */ new Map(),
|
|
14
|
+
externalDependencies: /* @__PURE__ */ new Set(),
|
|
15
|
+
invalidChunks: /* @__PURE__ */ new Set()
|
|
16
|
+
},
|
|
17
|
+
platform
|
|
18
|
+
);
|
|
19
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
20
|
+
inputOptions.plugins = inputOptions.plugins.filter(
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
(plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
|
|
23
|
+
);
|
|
24
|
+
inputOptions.plugins.push(aliasHono());
|
|
25
|
+
}
|
|
26
|
+
return inputOptions;
|
|
27
|
+
}
|
|
28
|
+
async function createWatcher(inputOptions, outputOptions) {
|
|
29
|
+
const watcher = await watch({
|
|
30
|
+
...inputOptions,
|
|
31
|
+
output: {
|
|
32
|
+
...outputOptions,
|
|
33
|
+
format: "esm",
|
|
34
|
+
entryFileNames: "[name].mjs",
|
|
35
|
+
chunkFileNames: "[name].mjs"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return watcher;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/build/babel/remove-all-options-server.ts
|
|
42
|
+
function removeAllOptionsExceptServer(result) {
|
|
43
|
+
return removeAllOptionsFromMastraExcept(result, "server");
|
|
44
|
+
}
|
|
45
|
+
function getServerOptionsBundler(entryFile, result) {
|
|
46
|
+
return rollup({
|
|
47
|
+
logLevel: "silent",
|
|
48
|
+
input: {
|
|
49
|
+
"server-config": entryFile
|
|
50
|
+
},
|
|
51
|
+
treeshake: "smallest",
|
|
52
|
+
plugins: [
|
|
53
|
+
// transpile typescript to something we understand
|
|
54
|
+
esbuild({
|
|
55
|
+
target: "node20",
|
|
56
|
+
platform: "node",
|
|
57
|
+
minify: false
|
|
58
|
+
}),
|
|
59
|
+
commonjs({
|
|
60
|
+
extensions: [".js", ".ts"],
|
|
61
|
+
strictRequires: "strict",
|
|
62
|
+
transformMixedEsModules: true,
|
|
63
|
+
ignoreTryCatch: false
|
|
64
|
+
}),
|
|
65
|
+
{
|
|
66
|
+
name: "get-server-config",
|
|
67
|
+
transform(code, id) {
|
|
68
|
+
if (id !== entryFile) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
babel.transform(
|
|
73
|
+
code,
|
|
74
|
+
{
|
|
75
|
+
babelrc: false,
|
|
76
|
+
configFile: false,
|
|
77
|
+
filename: id,
|
|
78
|
+
plugins: [removeAllOptionsExceptServer(result)]
|
|
79
|
+
},
|
|
80
|
+
(err, result2) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
return reject(err);
|
|
83
|
+
}
|
|
84
|
+
resolve({
|
|
85
|
+
code: result2.code,
|
|
86
|
+
map: result2.map
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
// let esbuild remove all unused imports
|
|
94
|
+
esbuild({
|
|
95
|
+
target: "node20",
|
|
96
|
+
platform: "node",
|
|
97
|
+
minify: false
|
|
98
|
+
}),
|
|
99
|
+
{
|
|
100
|
+
name: "cleanup",
|
|
101
|
+
transform(code, id) {
|
|
102
|
+
if (id !== entryFile) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
return recursiveRemoveNonReferencedNodes(code);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
// let esbuild remove all unused imports
|
|
109
|
+
esbuild({
|
|
110
|
+
target: "node20",
|
|
111
|
+
platform: "node",
|
|
112
|
+
minify: false
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async function getServerOptions(entryFile, outputDir) {
|
|
118
|
+
const result = {
|
|
119
|
+
hasCustomConfig: false
|
|
120
|
+
};
|
|
121
|
+
const bundle = await getServerOptionsBundler(entryFile, result);
|
|
122
|
+
await bundle.write({
|
|
123
|
+
dir: outputDir,
|
|
124
|
+
format: "es",
|
|
125
|
+
entryFileNames: "[name].mjs"
|
|
126
|
+
});
|
|
127
|
+
if (result.hasCustomConfig) {
|
|
128
|
+
return (await import(`file:${outputDir}/server-config.mjs`)).server;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { createWatcher, getInputOptions2 as getInputOptions, getServerOptions };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import babel__default from '@babel/core';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path, { normalize } from 'node:path';
|
|
5
|
+
import { createHandler } from 'typescript-paths';
|
|
6
|
+
|
|
7
|
+
// src/build/plugins/remove-deployer.ts
|
|
8
|
+
function removeDeployer() {
|
|
9
|
+
const t = babel__default.types;
|
|
10
|
+
return {
|
|
11
|
+
name: "remove-deployer",
|
|
12
|
+
visitor: {
|
|
13
|
+
NewExpression(path2, state) {
|
|
14
|
+
const varDeclaratorPath = path2.findParent((path3) => t.isVariableDeclarator(path3.node));
|
|
15
|
+
if (!varDeclaratorPath) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const parentNode = path2.parentPath.node;
|
|
19
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!state.hasReplaced) {
|
|
23
|
+
state.hasReplaced = true;
|
|
24
|
+
const newMastraObj = t.cloneNode(path2.node);
|
|
25
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
|
|
26
|
+
const deployer = newMastraObj.arguments[0].properties.find(
|
|
27
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
28
|
+
);
|
|
29
|
+
if (!deployer) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
|
|
33
|
+
(prop) => prop !== deployer
|
|
34
|
+
);
|
|
35
|
+
if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
|
|
36
|
+
const deployerBinding = state.file.scope.getBinding(deployer.value.name);
|
|
37
|
+
if (deployerBinding) {
|
|
38
|
+
deployerBinding?.path?.parentPath?.remove();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
path2.replaceWith(newMastraObj);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/build/plugins/remove-deployer.ts
|
|
50
|
+
function removeDeployer2(mastraEntry) {
|
|
51
|
+
return {
|
|
52
|
+
name: "remove-deployer",
|
|
53
|
+
transform(code, id) {
|
|
54
|
+
if (id !== mastraEntry) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
babel.transform(
|
|
59
|
+
code,
|
|
60
|
+
{
|
|
61
|
+
babelrc: false,
|
|
62
|
+
configFile: false,
|
|
63
|
+
filename: id,
|
|
64
|
+
plugins: [removeDeployer]
|
|
65
|
+
},
|
|
66
|
+
(err, result) => {
|
|
67
|
+
if (err) {
|
|
68
|
+
return reject(err);
|
|
69
|
+
}
|
|
70
|
+
resolve({
|
|
71
|
+
code: result.code,
|
|
72
|
+
map: result.map
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var PLUGIN_NAME = "tsconfig-paths";
|
|
81
|
+
function tsConfigPaths({ tsConfigPath, respectCoreModule } = {}) {
|
|
82
|
+
let handler;
|
|
83
|
+
return {
|
|
84
|
+
name: PLUGIN_NAME,
|
|
85
|
+
buildStart() {
|
|
86
|
+
handler = createHandler({
|
|
87
|
+
log: () => {
|
|
88
|
+
},
|
|
89
|
+
tsConfigPath,
|
|
90
|
+
respectCoreModule,
|
|
91
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
},
|
|
95
|
+
async resolveId(request, importer, options) {
|
|
96
|
+
if (!importer || request.startsWith("\0")) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const moduleName = handler?.(request, normalize(importer));
|
|
100
|
+
if (!moduleName) {
|
|
101
|
+
return this.resolve(request, importer, { skipSelf: true, ...options });
|
|
102
|
+
}
|
|
103
|
+
if (!path.extname(moduleName)) {
|
|
104
|
+
return this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
105
|
+
}
|
|
106
|
+
return moduleName;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { removeDeployer2 as removeDeployer, tsConfigPaths };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { Transform } from 'stream';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import fsPromises from 'fs/promises';
|
|
5
|
+
import path, { dirname } from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { MastraBase } from '@mastra/core/base';
|
|
8
|
+
import { ensureFile, readJSON, writeJSON } from 'fs-extra/esm';
|
|
9
|
+
|
|
10
|
+
// src/deploy/log.ts
|
|
11
|
+
var createPinoStream = (logger) => {
|
|
12
|
+
return new Transform({
|
|
13
|
+
transform(chunk, _encoding, callback) {
|
|
14
|
+
const line = chunk.toString().trim();
|
|
15
|
+
if (line) {
|
|
16
|
+
console.log(line);
|
|
17
|
+
logger.info(line);
|
|
18
|
+
}
|
|
19
|
+
callback(null, chunk);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
function createChildProcessLogger({ logger, root }) {
|
|
24
|
+
const pinoStream = createPinoStream(logger);
|
|
25
|
+
return async ({ cmd, args, env }) => {
|
|
26
|
+
try {
|
|
27
|
+
const subprocess = spawn(cmd, args, {
|
|
28
|
+
cwd: root,
|
|
29
|
+
shell: true,
|
|
30
|
+
env
|
|
31
|
+
});
|
|
32
|
+
subprocess.stdout?.pipe(pinoStream);
|
|
33
|
+
subprocess.stderr?.pipe(pinoStream);
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
subprocess.on("close", (code) => {
|
|
36
|
+
pinoStream.end();
|
|
37
|
+
if (code === 0) {
|
|
38
|
+
resolve({ success: true });
|
|
39
|
+
} else {
|
|
40
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
subprocess.on("error", (error) => {
|
|
44
|
+
pinoStream.end();
|
|
45
|
+
logger.error("Process failed", { error });
|
|
46
|
+
reject(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.log(error);
|
|
51
|
+
logger.error("Process failed", { error });
|
|
52
|
+
pinoStream.end();
|
|
53
|
+
return { success: false, error };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var Deps = class extends MastraBase {
|
|
58
|
+
packageManager;
|
|
59
|
+
rootDir;
|
|
60
|
+
constructor(rootDir = process.cwd()) {
|
|
61
|
+
super({ component: "DEPLOYER", name: "DEPS" });
|
|
62
|
+
this.rootDir = rootDir;
|
|
63
|
+
this.packageManager = this.getPackageManager();
|
|
64
|
+
}
|
|
65
|
+
findLockFile(dir) {
|
|
66
|
+
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
67
|
+
for (const file of lockFiles) {
|
|
68
|
+
if (fs.existsSync(path.join(dir, file))) {
|
|
69
|
+
return file;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const parentDir = path.resolve(dir, "..");
|
|
73
|
+
if (parentDir !== dir) {
|
|
74
|
+
return this.findLockFile(parentDir);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
getPackageManager() {
|
|
79
|
+
const lockFile = this.findLockFile(this.rootDir);
|
|
80
|
+
switch (lockFile) {
|
|
81
|
+
case "pnpm-lock.yaml":
|
|
82
|
+
return "pnpm";
|
|
83
|
+
case "package-lock.json":
|
|
84
|
+
return "npm";
|
|
85
|
+
case "yarn.lock":
|
|
86
|
+
return "yarn";
|
|
87
|
+
case "bun.lock":
|
|
88
|
+
return "bun";
|
|
89
|
+
default:
|
|
90
|
+
return "npm";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async install({ dir = this.rootDir }) {
|
|
94
|
+
let runCommand = this.packageManager;
|
|
95
|
+
switch (this.packageManager) {
|
|
96
|
+
case "pnpm":
|
|
97
|
+
runCommand = `${this.packageManager} --ignore-workspace install`;
|
|
98
|
+
break;
|
|
99
|
+
case "yarn":
|
|
100
|
+
await ensureFile(path.join(dir, "yarn.lock"));
|
|
101
|
+
default:
|
|
102
|
+
runCommand = `${this.packageManager} install`;
|
|
103
|
+
}
|
|
104
|
+
const cpLogger = createChildProcessLogger({
|
|
105
|
+
logger: this.logger,
|
|
106
|
+
root: dir
|
|
107
|
+
});
|
|
108
|
+
return cpLogger({
|
|
109
|
+
cmd: runCommand,
|
|
110
|
+
args: [],
|
|
111
|
+
env: {
|
|
112
|
+
PATH: process.env.PATH
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async installPackages(packages) {
|
|
117
|
+
let runCommand = this.packageManager;
|
|
118
|
+
if (this.packageManager === "npm") {
|
|
119
|
+
runCommand = `${this.packageManager} i`;
|
|
120
|
+
} else {
|
|
121
|
+
runCommand = `${this.packageManager} add`;
|
|
122
|
+
}
|
|
123
|
+
const cpLogger = createChildProcessLogger({
|
|
124
|
+
logger: this.logger,
|
|
125
|
+
root: ""
|
|
126
|
+
});
|
|
127
|
+
return cpLogger({
|
|
128
|
+
cmd: `${runCommand}`,
|
|
129
|
+
args: packages,
|
|
130
|
+
env: {
|
|
131
|
+
PATH: process.env.PATH
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async checkDependencies(dependencies) {
|
|
136
|
+
try {
|
|
137
|
+
const packageJsonPath = path.join(this.rootDir, "package.json");
|
|
138
|
+
try {
|
|
139
|
+
await fsPromises.access(packageJsonPath);
|
|
140
|
+
} catch {
|
|
141
|
+
return "No package.json file found in the current directory";
|
|
142
|
+
}
|
|
143
|
+
const packageJson = await readJSON(packageJsonPath);
|
|
144
|
+
for (const dependency of dependencies) {
|
|
145
|
+
if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
|
|
146
|
+
return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return "ok";
|
|
150
|
+
} catch (err) {
|
|
151
|
+
console.error(err);
|
|
152
|
+
return "Could not check dependencies";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async getProjectName() {
|
|
156
|
+
try {
|
|
157
|
+
const packageJsonPath = path.join(this.rootDir, "package.json");
|
|
158
|
+
const pkg = await readJSON(packageJsonPath);
|
|
159
|
+
return pkg.name;
|
|
160
|
+
} catch (err) {
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async getPackageVersion() {
|
|
165
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
166
|
+
const __dirname = dirname(__filename);
|
|
167
|
+
const pkgJsonPath = path.join(__dirname, "..", "..", "package.json");
|
|
168
|
+
const content = await readJSON(pkgJsonPath);
|
|
169
|
+
return content.version;
|
|
170
|
+
}
|
|
171
|
+
async addScriptsToPackageJson(scripts) {
|
|
172
|
+
const packageJson = await readJSON("package.json");
|
|
173
|
+
packageJson.scripts = {
|
|
174
|
+
...packageJson.scripts,
|
|
175
|
+
...scripts
|
|
176
|
+
};
|
|
177
|
+
await writeJSON("package.json", packageJson, { spaces: 2 });
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var DepsService = class extends Deps {
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export { Deps, DepsService, createChildProcessLogger, createPinoStream };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkJDY6E7BT_cjs = require('./chunk-JDY6E7BT.cjs');
|
|
4
|
+
var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
|
|
5
|
+
var chunkNCROGJGB_cjs = require('./chunk-NCROGJGB.cjs');
|
|
6
|
+
var chunkMYE33AKL_cjs = require('./chunk-MYE33AKL.cjs');
|
|
7
|
+
var babel = require('@babel/core');
|
|
8
|
+
var rollup = require('rollup');
|
|
9
|
+
var esbuild = require('rollup-plugin-esbuild');
|
|
10
|
+
var commonjs = require('@rollup/plugin-commonjs');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
|
|
33
|
+
var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
|
|
34
|
+
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
35
|
+
|
|
36
|
+
// src/deploy/base.ts
|
|
37
|
+
var Deployer = class extends chunkJDY6E7BT_cjs.Bundler {
|
|
38
|
+
deps = new chunkMYE33AKL_cjs.DepsService();
|
|
39
|
+
constructor(args) {
|
|
40
|
+
super(args.name, "DEPLOYER");
|
|
41
|
+
this.deps.__setLogger(this.logger);
|
|
42
|
+
}
|
|
43
|
+
getEnvFiles() {
|
|
44
|
+
const possibleFiles = [".env.production", ".env.local", ".env"];
|
|
45
|
+
try {
|
|
46
|
+
const fileService = new chunkNCROGJGB_cjs.FileService();
|
|
47
|
+
const envFile = fileService.getFirstExistingFile(possibleFiles);
|
|
48
|
+
return Promise.resolve([envFile]);
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve([]);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function removeAllExceptDeployer() {
|
|
55
|
+
const t = babel__namespace.default.types;
|
|
56
|
+
return {
|
|
57
|
+
name: "remove-all-except-deployer",
|
|
58
|
+
visitor: {
|
|
59
|
+
ExportNamedDeclaration: {
|
|
60
|
+
// remove all exports
|
|
61
|
+
exit(path) {
|
|
62
|
+
path.remove();
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
NewExpression(path) {
|
|
66
|
+
const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
|
|
67
|
+
if (!varDeclaratorPath) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const parentNode = path.parentPath.node;
|
|
71
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const deployer = path.node.arguments[0]?.properties?.find(
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
(prop) => prop.key.name === "deployer"
|
|
77
|
+
);
|
|
78
|
+
const programPath = path.scope.getProgramParent().path;
|
|
79
|
+
if (!deployer || !programPath) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const exportDeclaration = t.exportNamedDeclaration(
|
|
83
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("deployer"), deployer.value)]),
|
|
84
|
+
[]
|
|
85
|
+
);
|
|
86
|
+
programPath.node.body.push(exportDeclaration);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getDeployerBundler(entryFile) {
|
|
92
|
+
return rollup.rollup({
|
|
93
|
+
logLevel: "silent",
|
|
94
|
+
input: {
|
|
95
|
+
deployer: entryFile
|
|
96
|
+
},
|
|
97
|
+
treeshake: "smallest",
|
|
98
|
+
plugins: [
|
|
99
|
+
// transpile typescript to something we understand
|
|
100
|
+
esbuild__default.default({
|
|
101
|
+
target: "node20",
|
|
102
|
+
platform: "node",
|
|
103
|
+
minify: false
|
|
104
|
+
}),
|
|
105
|
+
commonjs__default.default({
|
|
106
|
+
extensions: [".js", ".ts"],
|
|
107
|
+
strictRequires: "strict",
|
|
108
|
+
transformMixedEsModules: true,
|
|
109
|
+
ignoreTryCatch: false
|
|
110
|
+
}),
|
|
111
|
+
{
|
|
112
|
+
name: "get-deployer",
|
|
113
|
+
transform(code, id) {
|
|
114
|
+
if (id !== entryFile) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
babel__namespace.transform(
|
|
119
|
+
code,
|
|
120
|
+
{
|
|
121
|
+
babelrc: false,
|
|
122
|
+
configFile: false,
|
|
123
|
+
filename: id,
|
|
124
|
+
plugins: [removeAllExceptDeployer]
|
|
125
|
+
},
|
|
126
|
+
(err, result) => {
|
|
127
|
+
if (err) {
|
|
128
|
+
return reject(err);
|
|
129
|
+
}
|
|
130
|
+
resolve({
|
|
131
|
+
code: result.code,
|
|
132
|
+
map: result.map
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
// let esbuild remove all unused imports
|
|
140
|
+
esbuild__default.default({
|
|
141
|
+
target: "node20",
|
|
142
|
+
platform: "node",
|
|
143
|
+
minify: false
|
|
144
|
+
}),
|
|
145
|
+
{
|
|
146
|
+
name: "cleanup-nodes",
|
|
147
|
+
transform(code, id) {
|
|
148
|
+
if (id !== entryFile) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
return chunk2ZPQX6BX_cjs.recursiveRemoveNonReferencedNodes(code);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
// let esbuild remove all unused imports
|
|
155
|
+
esbuild__default.default({
|
|
156
|
+
target: "node20",
|
|
157
|
+
platform: "node",
|
|
158
|
+
minify: false
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
async function getDeployer(entryFile, outputDir) {
|
|
164
|
+
console.log("entryFile", entryFile);
|
|
165
|
+
const bundle = await getDeployerBundler(entryFile);
|
|
166
|
+
await bundle.write({
|
|
167
|
+
dir: outputDir,
|
|
168
|
+
format: "es",
|
|
169
|
+
entryFileNames: "[name].mjs"
|
|
170
|
+
});
|
|
171
|
+
return (await import(`file:${outputDir}/deployer.mjs`)).deployer;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
Object.defineProperty(exports, "FileService", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () { return chunkNCROGJGB_cjs.FileService; }
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(exports, "Deps", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function () { return chunkMYE33AKL_cjs.Deps; }
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(exports, "createChildProcessLogger", {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
get: function () { return chunkMYE33AKL_cjs.createChildProcessLogger; }
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "createPinoStream", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () { return chunkMYE33AKL_cjs.createPinoStream; }
|
|
189
|
+
});
|
|
190
|
+
exports.Deployer = Deployer;
|
|
191
|
+
exports.getDeployer = getDeployer;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Deps } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { FileService } from './_tsup-dts-rollup.cjs';
|
|
3
|
+
export { getDeployer } from './_tsup-dts-rollup.cjs';
|
|
4
|
+
export { Deployer } from './_tsup-dts-rollup.cjs';
|
|
5
|
+
export { createChildProcessLogger } from './_tsup-dts-rollup.cjs';
|
|
6
|
+
export { createPinoStream } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Deps } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { FileService } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { getDeployer } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { Deployer } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { createChildProcessLogger } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { createPinoStream } from './_tsup-dts-rollup.js';
|