@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.
Files changed (58) hide show
  1. package/LICENSE.md +46 -0
  2. package/README.md +159 -0
  3. package/dist/_tsup-dts-rollup.d.cts +479 -0
  4. package/dist/_tsup-dts-rollup.d.ts +479 -0
  5. package/dist/build/analyze.cjs +10 -0
  6. package/dist/build/analyze.d.cts +1 -0
  7. package/dist/build/analyze.d.ts +1 -0
  8. package/dist/build/analyze.js +1 -0
  9. package/dist/build/bundler.cjs +14 -0
  10. package/dist/build/bundler.d.cts +2 -0
  11. package/dist/build/bundler.d.ts +2 -0
  12. package/dist/build/bundler.js +1 -0
  13. package/dist/build/index.cjs +47 -0
  14. package/dist/build/index.d.cts +9 -0
  15. package/dist/build/index.d.ts +9 -0
  16. package/dist/build/index.js +6 -0
  17. package/dist/bundler/index.cjs +10 -0
  18. package/dist/bundler/index.d.cts +1 -0
  19. package/dist/bundler/index.d.ts +1 -0
  20. package/dist/bundler/index.js +1 -0
  21. package/dist/chunk-2ZPQX6BX.cjs +254 -0
  22. package/dist/chunk-4AYFLP6G.js +227 -0
  23. package/dist/chunk-54KOF3NB.cjs +137 -0
  24. package/dist/chunk-AE4CVAPK.cjs +151 -0
  25. package/dist/chunk-BDTZS3JM.js +299 -0
  26. package/dist/chunk-DYQ225MJ.js +115 -0
  27. package/dist/chunk-I3UVE6EH.cjs +161 -0
  28. package/dist/chunk-IKPL4RGG.js +140 -0
  29. package/dist/chunk-JDY6E7BT.cjs +152 -0
  30. package/dist/chunk-MYE33AKL.cjs +195 -0
  31. package/dist/chunk-NCROGJGB.cjs +142 -0
  32. package/dist/chunk-P5SATU7G.cjs +310 -0
  33. package/dist/chunk-SQQUYWPS.js +144 -0
  34. package/dist/chunk-WB3T6NKI.js +133 -0
  35. package/dist/chunk-WVBUOQT6.js +111 -0
  36. package/dist/chunk-YQB677IB.js +183 -0
  37. package/dist/index.cjs +191 -0
  38. package/dist/index.d.cts +6 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.js +151 -0
  41. package/dist/server/index.cjs +3860 -0
  42. package/dist/server/index.d.cts +2 -0
  43. package/dist/server/index.d.ts +2 -0
  44. package/dist/server/index.js +3853 -0
  45. package/dist/services/index.cjs +19 -0
  46. package/dist/services/index.d.cts +3 -0
  47. package/dist/services/index.d.ts +3 -0
  48. package/dist/services/index.js +2 -0
  49. package/dist/templates/instrumentation-template.js +89 -0
  50. package/dist/validator/custom-resolver.cjs +52 -0
  51. package/dist/validator/custom-resolver.d.cts +1 -0
  52. package/dist/validator/custom-resolver.d.ts +1 -0
  53. package/dist/validator/custom-resolver.js +50 -0
  54. package/dist/validator/loader.cjs +7 -0
  55. package/dist/validator/loader.d.cts +1 -0
  56. package/dist/validator/loader.d.ts +1 -0
  57. package/dist/validator/loader.js +4 -0
  58. package/package.json +138 -0
@@ -0,0 +1,161 @@
1
+ 'use strict';
2
+
3
+ var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
4
+ var chunkP5SATU7G_cjs = require('./chunk-P5SATU7G.cjs');
5
+ var chunkAE4CVAPK_cjs = require('./chunk-AE4CVAPK.cjs');
6
+ var rollup = require('rollup');
7
+ var babel = require('@babel/core');
8
+ var esbuild = require('rollup-plugin-esbuild');
9
+ var commonjs = require('@rollup/plugin-commonjs');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n.default = e;
28
+ return Object.freeze(n);
29
+ }
30
+
31
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
32
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
33
+ var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
34
+
35
+ async function getInputOptions2(entryFile, platform) {
36
+ const inputOptions = await chunkAE4CVAPK_cjs.getInputOptions(
37
+ entryFile,
38
+ {
39
+ dependencies: /* @__PURE__ */ new Map(),
40
+ externalDependencies: /* @__PURE__ */ new Set(),
41
+ invalidChunks: /* @__PURE__ */ new Set()
42
+ },
43
+ platform
44
+ );
45
+ if (Array.isArray(inputOptions.plugins)) {
46
+ inputOptions.plugins = inputOptions.plugins.filter(
47
+ // @ts-ignore
48
+ (plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
49
+ );
50
+ inputOptions.plugins.push(chunkP5SATU7G_cjs.aliasHono());
51
+ }
52
+ return inputOptions;
53
+ }
54
+ async function createWatcher(inputOptions, outputOptions) {
55
+ const watcher = await rollup.watch({
56
+ ...inputOptions,
57
+ output: {
58
+ ...outputOptions,
59
+ format: "esm",
60
+ entryFileNames: "[name].mjs",
61
+ chunkFileNames: "[name].mjs"
62
+ }
63
+ });
64
+ return watcher;
65
+ }
66
+
67
+ // src/build/babel/remove-all-options-server.ts
68
+ function removeAllOptionsExceptServer(result) {
69
+ return chunk2ZPQX6BX_cjs.removeAllOptionsFromMastraExcept(result, "server");
70
+ }
71
+ function getServerOptionsBundler(entryFile, result) {
72
+ return rollup.rollup({
73
+ logLevel: "silent",
74
+ input: {
75
+ "server-config": entryFile
76
+ },
77
+ treeshake: "smallest",
78
+ plugins: [
79
+ // transpile typescript to something we understand
80
+ esbuild__default.default({
81
+ target: "node20",
82
+ platform: "node",
83
+ minify: false
84
+ }),
85
+ commonjs__default.default({
86
+ extensions: [".js", ".ts"],
87
+ strictRequires: "strict",
88
+ transformMixedEsModules: true,
89
+ ignoreTryCatch: false
90
+ }),
91
+ {
92
+ name: "get-server-config",
93
+ transform(code, id) {
94
+ if (id !== entryFile) {
95
+ return;
96
+ }
97
+ return new Promise((resolve, reject) => {
98
+ babel__namespace.transform(
99
+ code,
100
+ {
101
+ babelrc: false,
102
+ configFile: false,
103
+ filename: id,
104
+ plugins: [removeAllOptionsExceptServer(result)]
105
+ },
106
+ (err, result2) => {
107
+ if (err) {
108
+ return reject(err);
109
+ }
110
+ resolve({
111
+ code: result2.code,
112
+ map: result2.map
113
+ });
114
+ }
115
+ );
116
+ });
117
+ }
118
+ },
119
+ // let esbuild remove all unused imports
120
+ esbuild__default.default({
121
+ target: "node20",
122
+ platform: "node",
123
+ minify: false
124
+ }),
125
+ {
126
+ name: "cleanup",
127
+ transform(code, id) {
128
+ if (id !== entryFile) {
129
+ return;
130
+ }
131
+ return chunk2ZPQX6BX_cjs.recursiveRemoveNonReferencedNodes(code);
132
+ }
133
+ },
134
+ // let esbuild remove all unused imports
135
+ esbuild__default.default({
136
+ target: "node20",
137
+ platform: "node",
138
+ minify: false
139
+ })
140
+ ]
141
+ });
142
+ }
143
+ async function getServerOptions(entryFile, outputDir) {
144
+ const result = {
145
+ hasCustomConfig: false
146
+ };
147
+ const bundle = await getServerOptionsBundler(entryFile, result);
148
+ await bundle.write({
149
+ dir: outputDir,
150
+ format: "es",
151
+ entryFileNames: "[name].mjs"
152
+ });
153
+ if (result.hasCustomConfig) {
154
+ return (await import(`file:${outputDir}/server-config.mjs`)).server;
155
+ }
156
+ return null;
157
+ }
158
+
159
+ exports.createWatcher = createWatcher;
160
+ exports.getInputOptions = getInputOptions2;
161
+ exports.getServerOptions = getServerOptions;
@@ -0,0 +1,140 @@
1
+ import { tsConfigPaths, removeDeployer } from './chunk-WVBUOQT6.js';
2
+ import alias from '@rollup/plugin-alias';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import json from '@rollup/plugin-json';
5
+ import nodeResolve from '@rollup/plugin-node-resolve';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { rollup } from 'rollup';
8
+ import esbuild from 'rollup-plugin-esbuild';
9
+
10
+ async function getInputOptions(entryFile, analyzedBundleInfo, platform) {
11
+ let nodeResolvePlugin = platform === "node" ? nodeResolve({
12
+ preferBuiltins: true,
13
+ exportConditions: ["node", "import", "require"],
14
+ mainFields: ["module", "main"]
15
+ }) : nodeResolve({
16
+ preferBuiltins: false,
17
+ exportConditions: ["browser", "import", "require"],
18
+ mainFields: ["module", "main"],
19
+ browser: true
20
+ });
21
+ const externalsCopy = /* @__PURE__ */ new Set();
22
+ for (const external of analyzedBundleInfo.externalDependencies) {
23
+ if (external.startsWith("@")) {
24
+ const [scope, name] = external.split("/", 3);
25
+ externalsCopy.add(`${scope}/${name}`);
26
+ externalsCopy.add(`${scope}/${name}/*`);
27
+ } else {
28
+ externalsCopy.add(external);
29
+ externalsCopy.add(`${external}/*`);
30
+ }
31
+ }
32
+ const externals = Array.from(externalsCopy);
33
+ const normalizedEntryFile = entryFile.replaceAll("\\", "/");
34
+ return {
35
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
36
+ treeshake: "smallest",
37
+ preserveSymlinks: true,
38
+ external: externals,
39
+ plugins: [
40
+ tsConfigPaths(),
41
+ {
42
+ name: "alias-optimized-deps",
43
+ // @ts-ignore
44
+ resolveId(id) {
45
+ if (!analyzedBundleInfo.dependencies.has(id)) {
46
+ return null;
47
+ }
48
+ const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
49
+ if (isInvalidChunk) {
50
+ return {
51
+ id,
52
+ external: true
53
+ };
54
+ }
55
+ return {
56
+ id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
57
+ external: false
58
+ };
59
+ }
60
+ },
61
+ alias({
62
+ entries: [
63
+ {
64
+ find: /^\#server$/,
65
+ replacement: fileURLToPath(import.meta.resolve("@mastra/deployer/server")).replaceAll("\\", "/")
66
+ },
67
+ {
68
+ find: /^\@mastra\/server\/(.*)/,
69
+ replacement: `@mastra/server/$1`,
70
+ customResolver: (id) => {
71
+ if (id.startsWith("@mastra/server")) {
72
+ return {
73
+ id: fileURLToPath(import.meta.resolve(id))
74
+ };
75
+ }
76
+ }
77
+ },
78
+ { find: /^\#mastra$/, replacement: normalizedEntryFile }
79
+ ]
80
+ }),
81
+ esbuild({
82
+ target: "node20",
83
+ platform,
84
+ minify: false,
85
+ define: {
86
+ "process.env.NODE_ENV": JSON.stringify("production")
87
+ }
88
+ }),
89
+ commonjs({
90
+ extensions: [".js", ".ts"],
91
+ transformMixedEsModules: true,
92
+ esmExternals(id) {
93
+ return externals.includes(id);
94
+ }
95
+ }),
96
+ nodeResolvePlugin,
97
+ // for debugging
98
+ // {
99
+ // name: 'logger',
100
+ // //@ts-ignore
101
+ // resolveId(id, ...args) {
102
+ // console.log({ id, args });
103
+ // },
104
+ // // @ts-ignore
105
+ // transform(code, id) {
106
+ // if (code.includes('class Duplexify ')) {
107
+ // console.log({ duplex: id });
108
+ // }
109
+ // },
110
+ // },
111
+ json(),
112
+ removeDeployer(entryFile),
113
+ // treeshake unused imports
114
+ esbuild({
115
+ include: entryFile,
116
+ target: "node20",
117
+ platform,
118
+ minify: false
119
+ })
120
+ ].filter(Boolean)
121
+ };
122
+ }
123
+ async function createBundler(inputOptions, outputOptions) {
124
+ const bundler = await rollup(inputOptions);
125
+ return {
126
+ write: () => {
127
+ return bundler.write({
128
+ ...outputOptions,
129
+ format: "esm",
130
+ entryFileNames: "[name].mjs",
131
+ chunkFileNames: "[name].mjs"
132
+ });
133
+ },
134
+ close: () => {
135
+ return bundler.close();
136
+ }
137
+ };
138
+ }
139
+
140
+ export { createBundler, getInputOptions };
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+
3
+ var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
4
+ var chunkP5SATU7G_cjs = require('./chunk-P5SATU7G.cjs');
5
+ var chunkAE4CVAPK_cjs = require('./chunk-AE4CVAPK.cjs');
6
+ var chunkMYE33AKL_cjs = require('./chunk-MYE33AKL.cjs');
7
+ var fs = require('fs');
8
+ var promises = require('fs/promises');
9
+ var path = require('path');
10
+ var url = require('url');
11
+ var bundler = require('@mastra/core/bundler');
12
+ var virtual = require('@rollup/plugin-virtual');
13
+ var esm = require('fs-extra/esm');
14
+ var resolveFrom = require('resolve-from');
15
+
16
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
+
19
+ var virtual__default = /*#__PURE__*/_interopDefault(virtual);
20
+ var resolveFrom__default = /*#__PURE__*/_interopDefault(resolveFrom);
21
+
22
+ var Bundler = class extends bundler.MastraBundler {
23
+ analyzeOutputDir = ".build";
24
+ outputDir = "output";
25
+ constructor(name, component = "BUNDLER") {
26
+ super({ name, component });
27
+ }
28
+ async prepare(outputDirectory) {
29
+ await esm.emptyDir(outputDirectory);
30
+ await esm.ensureDir(path.join(outputDirectory, this.analyzeOutputDir));
31
+ await esm.ensureDir(path.join(outputDirectory, this.outputDir));
32
+ }
33
+ async writeInstrumentationFile(outputDirectory) {
34
+ const instrumentationFile = path.join(outputDirectory, "instrumentation.mjs");
35
+ const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-JDY6E7BT.cjs', document.baseURI).href))));
36
+ await esm.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
37
+ }
38
+ async writePackageJson(outputDirectory, dependencies) {
39
+ this.logger.debug(`Writing project's package.json`);
40
+ await esm.ensureDir(outputDirectory);
41
+ const pkgPath = path.join(outputDirectory, "package.json");
42
+ const dependenciesMap = /* @__PURE__ */ new Map();
43
+ for (const [key, value] of dependencies.entries()) {
44
+ if (key.startsWith("@")) {
45
+ const pkgChunks = key.split("/");
46
+ dependenciesMap.set(`${pkgChunks[0]}/${pkgChunks[1]}`, value);
47
+ continue;
48
+ }
49
+ dependenciesMap.set(key, value);
50
+ }
51
+ dependenciesMap.set("@opentelemetry/instrumentation", "latest");
52
+ await promises.writeFile(
53
+ pkgPath,
54
+ JSON.stringify(
55
+ {
56
+ name: "server",
57
+ version: "1.0.0",
58
+ description: "",
59
+ type: "module",
60
+ main: "index.mjs",
61
+ scripts: {
62
+ start: "node ./index.mjs"
63
+ },
64
+ author: "Mastra",
65
+ license: "ISC",
66
+ dependencies: Object.fromEntries(dependenciesMap.entries())
67
+ },
68
+ null,
69
+ 2
70
+ )
71
+ );
72
+ }
73
+ createBundler(inputOptions, outputOptions) {
74
+ return chunkAE4CVAPK_cjs.createBundler(inputOptions, outputOptions);
75
+ }
76
+ async analyze(entry, mastraFile, outputDirectory) {
77
+ return await chunkP5SATU7G_cjs.analyzeBundle(entry, mastraFile, path.join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
78
+ }
79
+ async installDependencies(outputDirectory, rootDir = process.cwd()) {
80
+ const deps = new chunkMYE33AKL_cjs.DepsService(rootDir);
81
+ deps.__setLogger(this.logger);
82
+ await deps.install({ dir: path.join(outputDirectory, this.outputDir) });
83
+ }
84
+ async copyPublic(mastraDir, outputDirectory) {
85
+ const publicDir = path.join(mastraDir, "public");
86
+ try {
87
+ await promises.stat(publicDir);
88
+ } catch {
89
+ return;
90
+ }
91
+ await esm.copy(publicDir, path.join(outputDirectory, this.outputDir));
92
+ }
93
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
94
+ const inputOptions = await chunkAE4CVAPK_cjs.getInputOptions(mastraEntryFile, analyzedBundleInfo, "node");
95
+ const isVirtual = serverFile.includes("\n") || fs.existsSync(serverFile);
96
+ if (isVirtual) {
97
+ inputOptions.input = { index: "#entry" };
98
+ if (Array.isArray(inputOptions.plugins)) {
99
+ inputOptions.plugins.unshift(virtual__default.default({ "#entry": serverFile }));
100
+ } else {
101
+ inputOptions.plugins = [virtual__default.default({ "#entry": serverFile })];
102
+ }
103
+ } else {
104
+ inputOptions.input = { index: serverFile };
105
+ }
106
+ return inputOptions;
107
+ }
108
+ async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = path.join(outputDirectory, this.outputDir)) {
109
+ this.logger.info("Start bundling Mastra");
110
+ const analyzedBundleInfo = await chunkP5SATU7G_cjs.analyzeBundle(
111
+ serverFile,
112
+ mastraEntryFile,
113
+ path.join(outputDirectory, this.analyzeOutputDir),
114
+ "node",
115
+ this.logger
116
+ );
117
+ await chunk2ZPQX6BX_cjs.writeTelemetryConfig(mastraEntryFile, path.join(outputDirectory, this.outputDir));
118
+ const dependenciesToInstall = /* @__PURE__ */ new Map();
119
+ for (const dep of analyzedBundleInfo.externalDependencies) {
120
+ try {
121
+ const pkgPath = resolveFrom__default.default(mastraEntryFile, `${dep}/package.json`);
122
+ const pkg = await esm.readJSON(pkgPath);
123
+ dependenciesToInstall.set(dep, pkg.version);
124
+ } catch {
125
+ dependenciesToInstall.set(dep, "latest");
126
+ }
127
+ }
128
+ if (analyzedBundleInfo.externalDependencies.has("@mastra/memory") || analyzedBundleInfo.dependencies.has("@mastra/memory")) {
129
+ dependenciesToInstall.set("fastembed", "latest");
130
+ }
131
+ await this.writePackageJson(path.join(outputDirectory, this.outputDir), dependenciesToInstall);
132
+ await this.writeInstrumentationFile(path.join(outputDirectory, this.outputDir));
133
+ this.logger.info("Bundling Mastra application");
134
+ const inputOptions = await this.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
135
+ const bundler = await this.createBundler(inputOptions, {
136
+ dir: bundleLocation,
137
+ manualChunks: {
138
+ mastra: ["#mastra"]
139
+ }
140
+ });
141
+ await bundler.write();
142
+ this.logger.info("Bundling Mastra done");
143
+ this.logger.info("Copying public files");
144
+ await this.copyPublic(path.dirname(mastraEntryFile), outputDirectory);
145
+ this.logger.info("Done copying public files");
146
+ this.logger.info("Installing dependencies");
147
+ await this.installDependencies(outputDirectory);
148
+ this.logger.info("Done installing dependencies");
149
+ }
150
+ };
151
+
152
+ exports.Bundler = Bundler;
@@ -0,0 +1,195 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var stream = require('stream');
5
+ var fs = require('fs');
6
+ var fsPromises = require('fs/promises');
7
+ var path = require('path');
8
+ var url = require('url');
9
+ var base = require('@mastra/core/base');
10
+ var esm = require('fs-extra/esm');
11
+
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
16
+ var fsPromises__default = /*#__PURE__*/_interopDefault(fsPromises);
17
+ var path__default = /*#__PURE__*/_interopDefault(path);
18
+
19
+ // src/deploy/log.ts
20
+ var createPinoStream = (logger) => {
21
+ return new stream.Transform({
22
+ transform(chunk, _encoding, callback) {
23
+ const line = chunk.toString().trim();
24
+ if (line) {
25
+ console.log(line);
26
+ logger.info(line);
27
+ }
28
+ callback(null, chunk);
29
+ }
30
+ });
31
+ };
32
+ function createChildProcessLogger({ logger, root }) {
33
+ const pinoStream = createPinoStream(logger);
34
+ return async ({ cmd, args, env }) => {
35
+ try {
36
+ const subprocess = child_process.spawn(cmd, args, {
37
+ cwd: root,
38
+ shell: true,
39
+ env
40
+ });
41
+ subprocess.stdout?.pipe(pinoStream);
42
+ subprocess.stderr?.pipe(pinoStream);
43
+ return new Promise((resolve, reject) => {
44
+ subprocess.on("close", (code) => {
45
+ pinoStream.end();
46
+ if (code === 0) {
47
+ resolve({ success: true });
48
+ } else {
49
+ reject(new Error(`Process exited with code ${code}`));
50
+ }
51
+ });
52
+ subprocess.on("error", (error) => {
53
+ pinoStream.end();
54
+ logger.error("Process failed", { error });
55
+ reject(error);
56
+ });
57
+ });
58
+ } catch (error) {
59
+ console.log(error);
60
+ logger.error("Process failed", { error });
61
+ pinoStream.end();
62
+ return { success: false, error };
63
+ }
64
+ };
65
+ }
66
+ var Deps = class extends base.MastraBase {
67
+ packageManager;
68
+ rootDir;
69
+ constructor(rootDir = process.cwd()) {
70
+ super({ component: "DEPLOYER", name: "DEPS" });
71
+ this.rootDir = rootDir;
72
+ this.packageManager = this.getPackageManager();
73
+ }
74
+ findLockFile(dir) {
75
+ const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
76
+ for (const file of lockFiles) {
77
+ if (fs__default.default.existsSync(path__default.default.join(dir, file))) {
78
+ return file;
79
+ }
80
+ }
81
+ const parentDir = path__default.default.resolve(dir, "..");
82
+ if (parentDir !== dir) {
83
+ return this.findLockFile(parentDir);
84
+ }
85
+ return null;
86
+ }
87
+ getPackageManager() {
88
+ const lockFile = this.findLockFile(this.rootDir);
89
+ switch (lockFile) {
90
+ case "pnpm-lock.yaml":
91
+ return "pnpm";
92
+ case "package-lock.json":
93
+ return "npm";
94
+ case "yarn.lock":
95
+ return "yarn";
96
+ case "bun.lock":
97
+ return "bun";
98
+ default:
99
+ return "npm";
100
+ }
101
+ }
102
+ async install({ dir = this.rootDir }) {
103
+ let runCommand = this.packageManager;
104
+ switch (this.packageManager) {
105
+ case "pnpm":
106
+ runCommand = `${this.packageManager} --ignore-workspace install`;
107
+ break;
108
+ case "yarn":
109
+ await esm.ensureFile(path__default.default.join(dir, "yarn.lock"));
110
+ default:
111
+ runCommand = `${this.packageManager} install`;
112
+ }
113
+ const cpLogger = createChildProcessLogger({
114
+ logger: this.logger,
115
+ root: dir
116
+ });
117
+ return cpLogger({
118
+ cmd: runCommand,
119
+ args: [],
120
+ env: {
121
+ PATH: process.env.PATH
122
+ }
123
+ });
124
+ }
125
+ async installPackages(packages) {
126
+ let runCommand = this.packageManager;
127
+ if (this.packageManager === "npm") {
128
+ runCommand = `${this.packageManager} i`;
129
+ } else {
130
+ runCommand = `${this.packageManager} add`;
131
+ }
132
+ const cpLogger = createChildProcessLogger({
133
+ logger: this.logger,
134
+ root: ""
135
+ });
136
+ return cpLogger({
137
+ cmd: `${runCommand}`,
138
+ args: packages,
139
+ env: {
140
+ PATH: process.env.PATH
141
+ }
142
+ });
143
+ }
144
+ async checkDependencies(dependencies) {
145
+ try {
146
+ const packageJsonPath = path__default.default.join(this.rootDir, "package.json");
147
+ try {
148
+ await fsPromises__default.default.access(packageJsonPath);
149
+ } catch {
150
+ return "No package.json file found in the current directory";
151
+ }
152
+ const packageJson = await esm.readJSON(packageJsonPath);
153
+ for (const dependency of dependencies) {
154
+ if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
155
+ return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
156
+ }
157
+ }
158
+ return "ok";
159
+ } catch (err) {
160
+ console.error(err);
161
+ return "Could not check dependencies";
162
+ }
163
+ }
164
+ async getProjectName() {
165
+ try {
166
+ const packageJsonPath = path__default.default.join(this.rootDir, "package.json");
167
+ const pkg = await esm.readJSON(packageJsonPath);
168
+ return pkg.name;
169
+ } catch (err) {
170
+ throw err;
171
+ }
172
+ }
173
+ async getPackageVersion() {
174
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-MYE33AKL.cjs', document.baseURI).href)));
175
+ const __dirname = path.dirname(__filename);
176
+ const pkgJsonPath = path__default.default.join(__dirname, "..", "..", "package.json");
177
+ const content = await esm.readJSON(pkgJsonPath);
178
+ return content.version;
179
+ }
180
+ async addScriptsToPackageJson(scripts) {
181
+ const packageJson = await esm.readJSON("package.json");
182
+ packageJson.scripts = {
183
+ ...packageJson.scripts,
184
+ ...scripts
185
+ };
186
+ await esm.writeJSON("package.json", packageJson, { spaces: 2 });
187
+ }
188
+ };
189
+ var DepsService = class extends Deps {
190
+ };
191
+
192
+ exports.Deps = Deps;
193
+ exports.DepsService = DepsService;
194
+ exports.createChildProcessLogger = createChildProcessLogger;
195
+ exports.createPinoStream = createPinoStream;