@mastra/deployer 0.1.0-alpha.37 → 0.1.0-alpha.38

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/deployer
2
2
 
3
+ ## 0.1.0-alpha.38
4
+
5
+ ### Minor Changes
6
+
7
+ - 4d4f6b6: Update deployer
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [4d4f6b6]
12
+ - @mastra/core@0.2.0-alpha.92
13
+
3
14
  ## 0.1.0-alpha.37
4
15
 
5
16
  ### Patch Changes
@@ -0,0 +1,17 @@
1
+ import { Logger } from '@mastra/core';
2
+
3
+ /**
4
+ * Main bundle analysis function that orchestrates the three-step process:
5
+ * 1. Analyze dependencies
6
+ * 2. Bundle dependencies modules
7
+ * 3. Validate generated bundles
8
+ *
9
+ * This helps identify which dependencies need to be externalized vs bundled.
10
+ */
11
+ declare function analyzeBundle(entry: string, mastraEntry: string, outputDir: string, platform: 'node' | 'browser', logger: Logger): Promise<{
12
+ invalidChunks: Set<string>;
13
+ dependencies: Map<string, string>;
14
+ externalDependencies: Set<string>;
15
+ }>;
16
+
17
+ export { analyzeBundle };
@@ -0,0 +1,2 @@
1
+ export { analyzeBundle } from '../chunk-VBX3JP44.js';
2
+ import '../chunk-YNXJO2XU.js';
@@ -0,0 +1,14 @@
1
+ import * as rollup from 'rollup';
2
+ import { InputOptions, OutputOptions } from 'rollup';
3
+ import { analyzeBundle } from './analyze.js';
4
+ import '@mastra/core';
5
+
6
+ declare function getInputOptions(entryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, platform: 'node' | 'browser'): Promise<InputOptions>;
7
+ declare function createBundler(inputOptions: InputOptions, outputOptions: Partial<OutputOptions> & {
8
+ dir: string;
9
+ }): Promise<{
10
+ write: () => Promise<rollup.RollupOutput>;
11
+ close: () => Promise<void>;
12
+ }>;
13
+
14
+ export { createBundler, getInputOptions };
@@ -0,0 +1,2 @@
1
+ export { createBundler, getInputOptions } from '../chunk-ODEOQDHZ.js';
2
+ import '../chunk-YNXJO2XU.js';
@@ -1,57 +1,12 @@
1
+ export { D as Deps, F as FileService, g as getBundler, a as getWatcher } from '../fs-D6g-UVqp.js';
2
+ export { createBundler, getInputOptions as getBundlerInputOptions } from './bundler.js';
1
3
  import * as rollup from 'rollup';
2
- import { InputOptions, Plugin, InputOption } from 'rollup';
3
- import { MastraBase } from '@mastra/core/base';
4
+ import { InputOptions, OutputOptions } from 'rollup';
5
+ export { analyzeBundle } from './analyze.js';
6
+ import '@mastra/core/base';
7
+ import '@mastra/core';
4
8
 
5
- declare class Deps extends MastraBase {
6
- private packageManager;
7
- constructor();
8
- private findLockFile;
9
- private getPackageManager;
10
- install({ dir, packages }: {
11
- dir?: string;
12
- packages?: string[];
13
- }): Promise<unknown>;
14
- installPackages(packages: string[]): Promise<unknown>;
15
- checkDependencies(dependencies: string[]): Promise<string>;
16
- getProjectName(): Promise<any>;
17
- getPackageVersion(): Promise<string | undefined>;
18
- addScriptsToPackageJson(scripts: Record<string, string>): Promise<void>;
19
- }
9
+ declare function getInputOptions(entryFile: string, platform: 'node' | 'browser'): Promise<InputOptions>;
10
+ declare function createWatcher(inputOptions: InputOptions, outputOptions: OutputOptions): Promise<rollup.RollupWatcher>;
20
11
 
21
- type NormalizedInputOptions = Omit<Partial<InputOptions>, 'plugins' | 'input' | 'external'> & {
22
- plugins?: Plugin[];
23
- input: InputOption;
24
- external?: (string | RegExp)[];
25
- };
26
- declare function getBundler(inputOptions: NormalizedInputOptions, args?: {
27
- platform?: 'node' | 'browser';
28
- dir?: string;
29
- }): Promise<rollup.RollupBuild>;
30
- declare function getWatcher(inputOptions: NormalizedInputOptions, args?: {
31
- platform?: 'node' | 'browser';
32
- dir?: string;
33
- }): Promise<rollup.RollupWatcher>;
34
-
35
- declare class FileService {
36
- /**
37
- *
38
- * @param inputFile the file in the starter files directory to copy
39
- * @param outputFilePath the destination path
40
- * @param replaceIfExists flag to replace if it exists
41
- * @returns
42
- */
43
- copyStarterFile(inputFile: string, outputFilePath: string, replaceIfExists?: boolean): Promise<boolean>;
44
- setupEnvFile({ dbUrl }: {
45
- dbUrl: string;
46
- }): Promise<void>;
47
- getFirstExistingFile(files: string[]): string;
48
- replaceValuesInFile({ filePath, replacements, }: {
49
- filePath: string;
50
- replacements: {
51
- search: string;
52
- replace: string;
53
- }[];
54
- }): void;
55
- }
56
-
57
- export { Deps, FileService, getBundler, getWatcher };
12
+ export { createWatcher, getInputOptions as getWatcherInputOptions };
@@ -1 +1,5 @@
1
- export { Deps, FileService, getBundler, getWatcher } from '../chunk-PGK75D2J.js';
1
+ export { FileService, createWatcher, getBundler, getWatcher, getInputOptions as getWatcherInputOptions } from '../chunk-NJ6UKWFH.js';
2
+ export { Deps } from '../chunk-Q3WKR6OZ.js';
3
+ export { analyzeBundle } from '../chunk-VBX3JP44.js';
4
+ export { createBundler, getInputOptions as getBundlerInputOptions } from '../chunk-ODEOQDHZ.js';
5
+ import '../chunk-YNXJO2XU.js';
@@ -0,0 +1,26 @@
1
+ import * as rollup from 'rollup';
2
+ import { InputOptions, OutputOptions } from 'rollup';
3
+ import { MastraBundler } from '@mastra/core/bundler';
4
+
5
+ declare abstract class Bundler extends MastraBundler {
6
+ protected analyzeOutputDir: string;
7
+ protected outputDir: string;
8
+ constructor(name: string, component?: 'BUNDLER' | 'DEPLOYER');
9
+ prepare(outputDirectory: string): Promise<void>;
10
+ writePackageJson(outputDirectory: string, dependencies: Map<string, string>): Promise<void>;
11
+ protected createBundler(inputOptions: InputOptions, outputOptions: Partial<OutputOptions> & {
12
+ dir: string;
13
+ }): Promise<{
14
+ write: () => Promise<rollup.RollupOutput>;
15
+ close: () => Promise<void>;
16
+ }>;
17
+ protected analyze(entry: string, mastraFile: string, outputDirectory: string): Promise<{
18
+ invalidChunks: Set<string>;
19
+ dependencies: Map<string, string>;
20
+ externalDependencies: Set<string>;
21
+ }>;
22
+ protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
23
+ protected _bundle(serverFile: string, mastraEntryFile: string, outputDirectory: string, bundleLocation?: string): Promise<void>;
24
+ }
25
+
26
+ export { Bundler };
@@ -0,0 +1,5 @@
1
+ export { Bundler } from '../chunk-YVQH4O5I.js';
2
+ import '../chunk-Q3WKR6OZ.js';
3
+ import '../chunk-VBX3JP44.js';
4
+ import '../chunk-ODEOQDHZ.js';
5
+ import '../chunk-YNXJO2XU.js';
@@ -0,0 +1,254 @@
1
+ import { aliasHono } from './chunk-VBX3JP44.js';
2
+ import { getInputOptions, telemetryFix, libSqlFix } from './chunk-ODEOQDHZ.js';
3
+ import { removeDeployer } from './chunk-YNXJO2XU.js';
4
+ import alias from '@rollup/plugin-alias';
5
+ import commonjs from '@rollup/plugin-commonjs';
6
+ import json from '@rollup/plugin-json';
7
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
8
+ import { builtinModules } from 'node:module';
9
+ import path, { join } from 'path';
10
+ import { rollup, watch } from 'rollup';
11
+ import esbuild from 'rollup-plugin-esbuild';
12
+ import { fileURLToPath } from 'url';
13
+ import * as fs2 from 'fs';
14
+ import fs2__default from 'fs';
15
+ import fsExtra from 'fs-extra/esm';
16
+
17
+ var EnvService = class {
18
+ };
19
+ var FileEnvService = class extends EnvService {
20
+ filePath;
21
+ constructor(filePath) {
22
+ super();
23
+ this.filePath = filePath;
24
+ }
25
+ readFile(filePath) {
26
+ return new Promise((resolve, reject) => {
27
+ fs2.readFile(filePath, "utf8", (err, data) => {
28
+ if (err) reject(err);
29
+ else resolve(data);
30
+ });
31
+ });
32
+ }
33
+ writeFile({ filePath, data }) {
34
+ return new Promise((resolve, reject) => {
35
+ fs2.writeFile(filePath, data, "utf8", (err) => {
36
+ if (err) reject(err);
37
+ else resolve();
38
+ });
39
+ });
40
+ }
41
+ async updateEnvData({
42
+ key,
43
+ value,
44
+ filePath = this.filePath,
45
+ data
46
+ }) {
47
+ const regex = new RegExp(`^${key}=.*$`, "m");
48
+ if (data.match(regex)) {
49
+ data = data.replace(regex, `${key}=${value}`);
50
+ } else {
51
+ data += `
52
+ ${key}=${value}`;
53
+ }
54
+ await this.writeFile({ filePath, data });
55
+ console.log(`${key} set to ${value} in ENV file.`);
56
+ return data;
57
+ }
58
+ async getEnvValue(key) {
59
+ try {
60
+ const data = await this.readFile(this.filePath);
61
+ const regex = new RegExp(`^${key}=(.*)$`, "m");
62
+ const match = data.match(regex);
63
+ return match?.[1] || null;
64
+ } catch (err) {
65
+ console.error(`Error reading ENV value: ${err}`);
66
+ return null;
67
+ }
68
+ }
69
+ async setEnvValue(key, value) {
70
+ try {
71
+ const data = await this.readFile(this.filePath);
72
+ await this.updateEnvData({ key, value, data });
73
+ } catch (err) {
74
+ console.error(`Error writing ENV value: ${err}`);
75
+ }
76
+ }
77
+ };
78
+
79
+ // src/build/fs.ts
80
+ var FileService = class {
81
+ /**
82
+ *
83
+ * @param inputFile the file in the starter files directory to copy
84
+ * @param outputFilePath the destination path
85
+ * @param replaceIfExists flag to replace if it exists
86
+ * @returns
87
+ */
88
+ async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
89
+ const __filename = fileURLToPath(import.meta.url);
90
+ const __dirname = path.dirname(__filename);
91
+ const filePath = path.resolve(__dirname, "..", "starter-files", inputFile);
92
+ const fileString = fs2__default.readFileSync(filePath, "utf8");
93
+ if (fs2__default.existsSync(outputFilePath) && !replaceIfExists) {
94
+ console.log(`${outputFilePath} already exists`);
95
+ return false;
96
+ }
97
+ await fsExtra.outputFile(outputFilePath, fileString);
98
+ return true;
99
+ }
100
+ async setupEnvFile({ dbUrl }) {
101
+ const envPath = path.join(process.cwd(), ".env.development");
102
+ await fsExtra.ensureFile(envPath);
103
+ const fileEnvService = new FileEnvService(envPath);
104
+ await fileEnvService.setEnvValue("DB_URL", dbUrl);
105
+ }
106
+ getFirstExistingFile(files) {
107
+ for (const f of files) {
108
+ if (fs2__default.existsSync(f)) {
109
+ return f;
110
+ }
111
+ }
112
+ throw new Error("Missing required file, checked the following paths: " + files.join(", "));
113
+ }
114
+ replaceValuesInFile({
115
+ filePath,
116
+ replacements
117
+ }) {
118
+ let fileContent = fs2__default.readFileSync(filePath, "utf8");
119
+ replacements.forEach(({ search, replace }) => {
120
+ fileContent = fileContent.replaceAll(search, replace);
121
+ });
122
+ fs2__default.writeFileSync(filePath, fileContent);
123
+ }
124
+ };
125
+
126
+ // src/build/bundle.ts
127
+ function getOptions(inputOptions, platform, root) {
128
+ const fileService = new FileService();
129
+ const entry = fileService.getFirstExistingFile([
130
+ join(root, "src/mastra/index.ts"),
131
+ join(root, "src/mastra/index.js")
132
+ ]);
133
+ const nodeBuiltins = platform === "node" ? builtinModules : [];
134
+ let nodeResolvePlugin = platform === "node" ? nodeResolve({
135
+ preferBuiltins: true,
136
+ exportConditions: ["node", "import", "require"],
137
+ mainFields: ["module", "main"]
138
+ }) : nodeResolve({
139
+ preferBuiltins: false,
140
+ exportConditions: ["browser", "import", "require"],
141
+ mainFields: ["module", "main"],
142
+ browser: true
143
+ });
144
+ return {
145
+ logLevel: "silent",
146
+ ...inputOptions,
147
+ treeshake: false,
148
+ preserveSymlinks: true,
149
+ external: [
150
+ ...nodeBuiltins,
151
+ ...nodeBuiltins.map((builtin) => "node:" + builtin),
152
+ ...inputOptions.external ?? []
153
+ ],
154
+ plugins: [
155
+ ...inputOptions.plugins ?? [],
156
+ telemetryFix(),
157
+ alias({
158
+ entries: [
159
+ {
160
+ find: /^\#server$/,
161
+ replacement: fileURLToPath(import.meta.resolve("@mastra/deployer/server")).replaceAll("\\", "/")
162
+ },
163
+ { find: /^\#mastra$/, replacement: entry.replaceAll("\\", "/") },
164
+ {
165
+ find: /^hono\//,
166
+ replacement: "hono/",
167
+ customResolver: (id, importer) => {
168
+ if (!importer?.startsWith("\0virtual")) {
169
+ return null;
170
+ }
171
+ const path2 = import.meta.resolve(id);
172
+ return fileURLToPath(path2);
173
+ }
174
+ }
175
+ ]
176
+ }),
177
+ commonjs({
178
+ strictRequires: "strict",
179
+ transformMixedEsModules: true
180
+ // dynamicRequireTargets: ['node_modules/**/@libsql+win32-*/*'],
181
+ }),
182
+ libSqlFix(),
183
+ // for debugging
184
+ // {
185
+ // name: 'logger',
186
+ // // @ts-ignore
187
+ // resolveId(id, ...args) {
188
+ // console.log({ id, args });
189
+ // },
190
+ // },
191
+ nodeResolvePlugin,
192
+ json(),
193
+ esbuild({
194
+ include: /\.tsx?$/,
195
+ target: "node20",
196
+ platform,
197
+ minify: false,
198
+ define: {
199
+ "process.env.NODE_ENV": JSON.stringify("production")
200
+ }
201
+ }),
202
+ removeDeployer(entry),
203
+ esbuild({
204
+ include: entry,
205
+ target: "node20",
206
+ platform,
207
+ minify: false
208
+ })
209
+ ].filter(Boolean)
210
+ };
211
+ }
212
+ async function getBundler(inputOptions, args = {}) {
213
+ const { platform = "node", dir = process.cwd() } = args;
214
+ const bundle = await rollup(getOptions(inputOptions, platform, dir));
215
+ return bundle;
216
+ }
217
+ async function getWatcher(inputOptions, args = {}) {
218
+ const { platform = "node", dir = process.cwd() } = args;
219
+ const watcher = watch(getOptions(inputOptions, platform, dir));
220
+ return watcher;
221
+ }
222
+ async function getInputOptions2(entryFile, platform) {
223
+ const inputOptions = await getInputOptions(
224
+ entryFile,
225
+ {
226
+ dependencies: /* @__PURE__ */ new Map(),
227
+ externalDependencies: /* @__PURE__ */ new Set(),
228
+ invalidChunks: /* @__PURE__ */ new Set()
229
+ },
230
+ platform
231
+ );
232
+ if (Array.isArray(inputOptions.plugins)) {
233
+ inputOptions.plugins = inputOptions.plugins.filter(
234
+ // @ts-ignore
235
+ (plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
236
+ );
237
+ inputOptions.plugins.push(aliasHono());
238
+ }
239
+ return inputOptions;
240
+ }
241
+ async function createWatcher(inputOptions, outputOptions) {
242
+ const watcher = await watch({
243
+ ...inputOptions,
244
+ output: {
245
+ ...outputOptions,
246
+ format: "esm",
247
+ entryFileNames: "[name].mjs",
248
+ chunkFileNames: "[name].mjs"
249
+ }
250
+ });
251
+ return watcher;
252
+ }
253
+
254
+ export { FileService, createWatcher, getBundler, getInputOptions2 as getInputOptions, getWatcher };
@@ -0,0 +1,251 @@
1
+ import { removeDeployer } from './chunk-YNXJO2XU.js';
2
+ import alias from '@rollup/plugin-alias';
3
+ import json from '@rollup/plugin-json';
4
+ import nodeResolve from '@rollup/plugin-node-resolve';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { rollup } from 'rollup';
7
+ import esbuild from 'rollup-plugin-esbuild';
8
+ import * as babel from '@babel/core';
9
+ import babel__default from '@babel/core';
10
+ import { currentTarget } from '@neon-rs/load';
11
+ import { familySync, GLIBC } from 'detect-libc';
12
+ import { dirname, join, resolve } from 'path';
13
+ import fsExtra from 'fs-extra/esm';
14
+ import { addNamed } from '@babel/helper-module-imports';
15
+ import { platform } from 'process';
16
+
17
+ function rewriteLibsqlImport() {
18
+ const t = babel__default.types;
19
+ let hasReplaced = false;
20
+ return {
21
+ name: "rewrite-libsql-import",
22
+ visitor: {
23
+ FunctionDeclaration(path) {
24
+ if (path.node.id?.name === "requireNative" && !hasReplaced) {
25
+ hasReplaced = true;
26
+ const createRequire = addNamed(path, "createRequire", "module");
27
+ const requireIdentifier = t.identifier("require");
28
+ path.replaceWith(
29
+ t.functionDeclaration(
30
+ t.identifier("requireNative"),
31
+ [],
32
+ t.blockStatement([
33
+ t.variableDeclaration("const", [
34
+ t.variableDeclarator(
35
+ requireIdentifier,
36
+ t.callExpression(createRequire, [
37
+ t.memberExpression(
38
+ t.metaProperty(t.identifier("import"), t.identifier("meta")),
39
+ t.identifier("url")
40
+ )
41
+ ])
42
+ )
43
+ ]),
44
+ t.returnStatement(t.callExpression(requireIdentifier, [t.stringLiteral("./libsql.node")]))
45
+ ])
46
+ )
47
+ );
48
+ }
49
+ }
50
+ }
51
+ };
52
+ }
53
+
54
+ // src/build/plugins/fix-libsql.ts
55
+ function libSqlFix() {
56
+ return {
57
+ name: "libSqlFix",
58
+ transform(code, id) {
59
+ if (!id.includes("\\libsql\\index.js") && !id.includes("/libsql/index.js")) {
60
+ return null;
61
+ }
62
+ return new Promise((resolve2, reject) => {
63
+ babel.transform(
64
+ code,
65
+ {
66
+ babelrc: false,
67
+ configFile: false,
68
+ filename: id,
69
+ plugins: [rewriteLibsqlImport]
70
+ },
71
+ (err, result) => {
72
+ if (err) {
73
+ return reject(err);
74
+ }
75
+ resolve2({
76
+ code: result.code,
77
+ map: result.map
78
+ });
79
+ }
80
+ );
81
+ });
82
+ },
83
+ async generateBundle({ file, dir }) {
84
+ if (!file && !dir) {
85
+ throw new Error("No output options were given.");
86
+ }
87
+ const outputDirectory = dir || dirname(file);
88
+ let target = currentTarget();
89
+ if (familySync() == GLIBC) {
90
+ switch (target) {
91
+ case "linux-x64-musl":
92
+ target = "linux-x64-gnu";
93
+ break;
94
+ case "linux-arm64-musl":
95
+ target = "linux-arm64-gnu";
96
+ break;
97
+ }
98
+ }
99
+ const fileToCopy = await this.resolve(`@libsql/${target}/index.node`);
100
+ if (fileToCopy) {
101
+ await fsExtra.copy(fileToCopy.id, join(outputDirectory, "libsql.node"));
102
+ }
103
+ }
104
+ };
105
+ }
106
+ function getTelemetryMachineFile() {
107
+ switch (platform) {
108
+ case "darwin":
109
+ return "getMachineId-darwin";
110
+ case "linux":
111
+ return "getMachineId-linux";
112
+ case "freebsd":
113
+ return "getMachineId-bsd";
114
+ case "win32":
115
+ return "getMachineId-win";
116
+ default:
117
+ return "getMachineId-unsupported";
118
+ }
119
+ }
120
+ function telemetryFix() {
121
+ return {
122
+ name: "telemetry-fix",
123
+ transform(code, id) {
124
+ if (id.includes("require-in-the-middle")) {
125
+ return code.replace(
126
+ `const path = require('path')`,
127
+ `const path = require('path');
128
+ const { createRequire } = require('module');
129
+ const realRequire = createRequire(import.meta.url)`
130
+ ).replaceAll(`require.resolve`, `realRequire.resolve`);
131
+ }
132
+ },
133
+ resolveId(id, importer) {
134
+ if (id === "./machine-id/getMachineId" && importer) {
135
+ return { id: resolve(dirname(importer), `./machine-id/${getTelemetryMachineFile()}.js`) };
136
+ }
137
+ if (id === "formdata-node") {
138
+ return { id: "formdata-node", external: false };
139
+ }
140
+ },
141
+ load(id) {
142
+ if (id.startsWith("formdata-node")) {
143
+ return "export default {};";
144
+ }
145
+ return null;
146
+ }
147
+ };
148
+ }
149
+
150
+ // src/build/bundler.ts
151
+ async function getInputOptions(entryFile, analyzedBundleInfo, platform2) {
152
+ let nodeResolvePlugin = platform2 === "node" ? nodeResolve({
153
+ preferBuiltins: true,
154
+ exportConditions: ["node", "import", "require"],
155
+ mainFields: ["module", "main"]
156
+ }) : nodeResolve({
157
+ preferBuiltins: false,
158
+ exportConditions: ["browser", "import", "require"],
159
+ mainFields: ["module", "main"],
160
+ browser: true
161
+ });
162
+ return {
163
+ logLevel: "silent",
164
+ treeshake: true,
165
+ preserveSymlinks: true,
166
+ external: Array.from(analyzedBundleInfo.externalDependencies),
167
+ plugins: [
168
+ telemetryFix(),
169
+ libSqlFix(),
170
+ {
171
+ name: "alias-optimized-deps",
172
+ // @ts-ignore
173
+ resolveId(id) {
174
+ if (!analyzedBundleInfo.dependencies.has(id)) {
175
+ return null;
176
+ }
177
+ const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
178
+ if (isInvalidChunk) {
179
+ return {
180
+ id,
181
+ external: true
182
+ };
183
+ }
184
+ return {
185
+ id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
186
+ external: false
187
+ };
188
+ }
189
+ },
190
+ alias({
191
+ entries: [
192
+ {
193
+ find: /^\#server$/,
194
+ replacement: fileURLToPath(import.meta.resolve("@mastra/deployer/server")).replaceAll("\\", "/")
195
+ },
196
+ { find: /^\#mastra$/, replacement: entryFile.replaceAll("\\", "/") }
197
+ ]
198
+ }),
199
+ nodeResolvePlugin,
200
+ // for debugging
201
+ // {
202
+ // name: 'logger',
203
+ // //@ts-ignore
204
+ // resolveId(id, ...args) {
205
+ // console.log({ id, args });
206
+ // },
207
+ // // @ts-ignore
208
+ // transform(code, id) {
209
+ // if (code.includes('class Duplexify ')) {
210
+ // console.log({ duplex: id });
211
+ // }
212
+ // },
213
+ // },
214
+ json(),
215
+ esbuild({
216
+ target: "node20",
217
+ platform: platform2,
218
+ minify: false,
219
+ define: {
220
+ "process.env.NODE_ENV": JSON.stringify("production")
221
+ }
222
+ }),
223
+ removeDeployer(entryFile),
224
+ // treeshake unused imports
225
+ esbuild({
226
+ include: entryFile,
227
+ target: "node20",
228
+ platform: platform2,
229
+ minify: false
230
+ })
231
+ ].filter(Boolean)
232
+ };
233
+ }
234
+ async function createBundler(inputOptions, outputOptions) {
235
+ const bundler = await rollup(inputOptions);
236
+ return {
237
+ write: () => {
238
+ return bundler.write({
239
+ ...outputOptions,
240
+ format: "esm",
241
+ entryFileNames: "[name].mjs",
242
+ chunkFileNames: "[name].mjs"
243
+ });
244
+ },
245
+ close: () => {
246
+ return bundler.close();
247
+ }
248
+ };
249
+ }
250
+
251
+ export { createBundler, getInputOptions, libSqlFix, telemetryFix };