@mastra/deployer 1.0.0-beta.14 → 1.0.0-beta.15

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 (63) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  3. package/dist/build/analyze.cjs +2 -2
  4. package/dist/build/analyze.js +1 -1
  5. package/dist/build/babel/remove-deployer.d.ts.map +1 -1
  6. package/dist/build/bundler.cjs +3 -3
  7. package/dist/build/bundler.d.ts.map +1 -1
  8. package/dist/build/bundler.js +1 -1
  9. package/dist/build/bundlerOptions.d.ts.map +1 -1
  10. package/dist/build/deployer.d.ts.map +1 -1
  11. package/dist/build/index.cjs +10 -10
  12. package/dist/build/index.js +3 -3
  13. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  14. package/dist/build/plugins/remove-all-except.d.ts +10 -0
  15. package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
  16. package/dist/build/serverOptions.d.ts.map +1 -1
  17. package/dist/build/shared/extract-mastra-option.d.ts +4 -8
  18. package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
  19. package/dist/bundler/index.cjs +3 -3
  20. package/dist/bundler/index.d.ts.map +1 -1
  21. package/dist/bundler/index.js +1 -1
  22. package/dist/{chunk-IVKDKRCR.cjs → chunk-7F6JKGX4.cjs} +20 -12
  23. package/dist/chunk-7F6JKGX4.cjs.map +1 -0
  24. package/dist/{chunk-HNSVE6YO.js → chunk-BDA7RMRF.js} +191 -171
  25. package/dist/chunk-BDA7RMRF.js.map +1 -0
  26. package/dist/{chunk-UJXH5MNH.cjs → chunk-CRIOGWZD.cjs} +190 -171
  27. package/dist/chunk-CRIOGWZD.cjs.map +1 -0
  28. package/dist/{chunk-ZXT4NSIV.js → chunk-ESR6AK5N.js} +14 -6
  29. package/dist/chunk-ESR6AK5N.js.map +1 -0
  30. package/dist/{chunk-V5W7WIXT.cjs → chunk-HRCR6OKC.cjs} +11 -22
  31. package/dist/chunk-HRCR6OKC.cjs.map +1 -0
  32. package/dist/{chunk-C6UFSG3V.js → chunk-ONWHS3PA.js} +34 -79
  33. package/dist/chunk-ONWHS3PA.js.map +1 -0
  34. package/dist/{chunk-PB5O2NTZ.cjs → chunk-OVVUJ46G.cjs} +39 -85
  35. package/dist/chunk-OVVUJ46G.cjs.map +1 -0
  36. package/dist/{chunk-BFA354MH.js → chunk-WFIG7I5C.js} +5 -16
  37. package/dist/chunk-WFIG7I5C.js.map +1 -0
  38. package/dist/index.cjs +4 -15
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.js +3 -14
  41. package/dist/index.js.map +1 -1
  42. package/dist/server/index.cjs +262 -14
  43. package/dist/server/index.cjs.map +1 -1
  44. package/dist/server/index.d.ts.map +1 -1
  45. package/dist/server/index.js +260 -12
  46. package/dist/server/index.js.map +1 -1
  47. package/package.json +6 -6
  48. package/dist/build/babel/get-deployer.d.ts +0 -3
  49. package/dist/build/babel/get-deployer.d.ts.map +0 -1
  50. package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
  51. package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
  52. package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
  53. package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
  54. package/dist/build/babel/remove-all-options-server.d.ts +0 -5
  55. package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
  56. package/dist/chunk-BFA354MH.js.map +0 -1
  57. package/dist/chunk-C6UFSG3V.js.map +0 -1
  58. package/dist/chunk-HNSVE6YO.js.map +0 -1
  59. package/dist/chunk-IVKDKRCR.cjs.map +0 -1
  60. package/dist/chunk-PB5O2NTZ.cjs.map +0 -1
  61. package/dist/chunk-UJXH5MNH.cjs.map +0 -1
  62. package/dist/chunk-V5W7WIXT.cjs.map +0 -1
  63. package/dist/chunk-ZXT4NSIV.js.map +0 -1
@@ -109,87 +109,6 @@ globalThis.__dirname = dirname(__filename);
109
109
  }
110
110
  );
111
111
  }
112
- function removeAllOptionsFromMastraExcept(result, option, logger) {
113
- const t = babel__default.types;
114
- return {
115
- name: "remove-all-except-" + option + "-config",
116
- visitor: {
117
- ExportNamedDeclaration: {
118
- // remove all exports
119
- exit(path3) {
120
- path3.remove();
121
- }
122
- },
123
- NewExpression(path3, state) {
124
- const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
125
- if (!varDeclaratorPath) {
126
- return;
127
- }
128
- const parentNode = path3.parentPath.node;
129
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
130
- return;
131
- }
132
- let mastraArgs = t.objectExpression([]);
133
- if (t.isObjectExpression(path3.node.arguments[0])) {
134
- mastraArgs = path3.node.arguments[0];
135
- }
136
- let configProperty = mastraArgs.properties.find(
137
- // @ts-ignore
138
- (prop) => prop.key.name === option
139
- );
140
- let configValue = t.objectExpression([]);
141
- const programPath = path3.scope.getProgramParent().path;
142
- if (!programPath) {
143
- return;
144
- }
145
- if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
146
- result.hasCustomConfig = true;
147
- configValue = configProperty.value;
148
- if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
149
- const configBinding = state.file.scope.getBinding(option);
150
- if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
151
- const id = path3.scope.generateUidIdentifier(option);
152
- configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
153
- configValue = id;
154
- }
155
- }
156
- }
157
- const exportDeclaration = t.exportNamedDeclaration(
158
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
159
- []
160
- );
161
- programPath.node.body.push(exportDeclaration);
162
- },
163
- Program: {
164
- exit(path3) {
165
- const hasExport = path3.node.body.some(
166
- (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
167
- );
168
- if (!hasExport) {
169
- if (logger) {
170
- logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
171
- export const mastra = new Mastra({
172
- ${option}: <value>
173
- })
174
-
175
- `);
176
- }
177
- const fallbackExportDeclaration = t.exportNamedDeclaration(
178
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
179
- []
180
- );
181
- path3.node.body.push(fallbackExportDeclaration);
182
- }
183
- }
184
- }
185
- }
186
- };
187
- }
188
-
189
- // src/build/babel/remove-all-options-bundler.ts
190
- function removeAllOptionsExceptBundler(result, logger) {
191
- return removeAllOptionsFromMastraExcept(result, "bundler", logger);
192
- }
193
112
  function esbuild(options = {}) {
194
113
  return originalEsbuild({
195
114
  target: "node20",
@@ -407,7 +326,117 @@ function recursiveRemoveNonReferencedNodes(code) {
407
326
  );
408
327
  });
409
328
  }
410
- function extractMastraOptionBundler(name, entryFile, transformer, result, logger) {
329
+ function removeAllOptionsFromMastraExcept(result, option, logger) {
330
+ const t = babel__default.types;
331
+ return {
332
+ name: "remove-all-except-" + option + "-config",
333
+ visitor: {
334
+ ExportNamedDeclaration: {
335
+ // remove all exports
336
+ exit(path3) {
337
+ path3.remove();
338
+ }
339
+ },
340
+ NewExpression(path3, state) {
341
+ const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
342
+ if (!varDeclaratorPath) {
343
+ return;
344
+ }
345
+ const parentNode = path3.parentPath.node;
346
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
347
+ return;
348
+ }
349
+ let mastraArgs = t.objectExpression([]);
350
+ if (t.isObjectExpression(path3.node.arguments[0])) {
351
+ mastraArgs = path3.node.arguments[0];
352
+ }
353
+ let configProperty = mastraArgs.properties.find(
354
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
355
+ );
356
+ let configValue = t.objectExpression([]);
357
+ const programPath = path3.scope.getProgramParent().path;
358
+ if (!programPath) {
359
+ return;
360
+ }
361
+ if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
362
+ result.hasCustomConfig = true;
363
+ configValue = configProperty.value;
364
+ if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
365
+ const configBinding = state.file.scope.getBinding(option);
366
+ if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
367
+ const id = path3.scope.generateUidIdentifier(option);
368
+ configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
369
+ configValue = id;
370
+ }
371
+ }
372
+ }
373
+ const exportDeclaration = t.exportNamedDeclaration(
374
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
375
+ []
376
+ );
377
+ programPath.node.body.push(exportDeclaration);
378
+ },
379
+ Program: {
380
+ exit(path3) {
381
+ const hasExport = path3.node.body.some(
382
+ (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
383
+ );
384
+ if (!hasExport) {
385
+ if (logger) {
386
+ logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
387
+ export const mastra = new Mastra({
388
+ ${option}: <value>
389
+ })
390
+
391
+ `);
392
+ }
393
+ const fallbackExportDeclaration = t.exportNamedDeclaration(
394
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
395
+ []
396
+ );
397
+ path3.node.body.push(fallbackExportDeclaration);
398
+ }
399
+ }
400
+ }
401
+ }
402
+ };
403
+ }
404
+
405
+ // src/build/plugins/remove-all-except.ts
406
+ function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
407
+ return {
408
+ name: `remove-${name}`,
409
+ transform(code, id) {
410
+ if (id !== mastraEntry) {
411
+ return;
412
+ }
413
+ return new Promise((resolve2, reject) => {
414
+ babel.transform(
415
+ code,
416
+ {
417
+ babelrc: false,
418
+ configFile: false,
419
+ filename: id,
420
+ plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
421
+ sourceMaps: options?.sourcemap
422
+ },
423
+ (err, result2) => {
424
+ if (err) {
425
+ return reject(err);
426
+ }
427
+ resolve2({
428
+ code: result2.code,
429
+ map: result2.map
430
+ });
431
+ }
432
+ );
433
+ });
434
+ }
435
+ };
436
+ }
437
+
438
+ // src/build/shared/extract-mastra-option.ts
439
+ function extractMastraOptionBundler(name, entryFile, result, logger) {
411
440
  return rollup({
412
441
  logLevel: "silent",
413
442
  input: {
@@ -428,34 +457,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
428
457
  ignoreTryCatch: false
429
458
  }),
430
459
  json(),
431
- {
432
- name: `extract-${name}-config`,
433
- transform(code, id) {
434
- if (id !== entryFile) {
435
- return;
436
- }
437
- return new Promise((resolve2, reject) => {
438
- babel.transform(
439
- code,
440
- {
441
- babelrc: false,
442
- configFile: false,
443
- filename: id,
444
- plugins: [transformer(result, logger)]
445
- },
446
- (err, result2) => {
447
- if (err) {
448
- return reject(err);
449
- }
450
- resolve2({
451
- code: result2.code,
452
- map: result2.map
453
- });
454
- }
455
- );
456
- });
457
- }
458
- },
460
+ removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
459
461
  // let esbuild remove all unused imports
460
462
  esbuild(),
461
463
  {
@@ -472,11 +474,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
472
474
  ]
473
475
  });
474
476
  }
475
- async function extractMastraOption(name, entryFile, transformer, outputDir, logger) {
477
+ async function extractMastraOption(name, entryFile, outputDir, logger) {
476
478
  const result = {
477
479
  hasCustomConfig: false
478
480
  };
479
- const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);
481
+ const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
480
482
  const output = await bundler.write({
481
483
  dir: outputDir,
482
484
  format: "es",
@@ -494,13 +496,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
494
496
 
495
497
  // src/build/bundlerOptions.ts
496
498
  async function getBundlerOptions(entryFile, outputDir, logger) {
497
- const result = await extractMastraOption(
498
- "bundler",
499
- entryFile,
500
- removeAllOptionsExceptBundler,
501
- outputDir,
502
- logger
503
- );
499
+ const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
504
500
  if (!result) {
505
501
  return null;
506
502
  }
@@ -569,8 +565,57 @@ function isNodeBuiltin(dep) {
569
565
  const [pkg2] = dep.split("/");
570
566
  return dep.startsWith("node:") || builtinModules.includes(dep) || builtinModules.includes(pkg2);
571
567
  }
568
+ async function getPackageRootPath(packageName, parentPath) {
569
+ let rootPath;
570
+ try {
571
+ let options = void 0;
572
+ if (parentPath) {
573
+ if (!parentPath.startsWith("file://")) {
574
+ parentPath = pathToFileURL(parentPath).href;
575
+ }
576
+ options = {
577
+ paths: [parentPath]
578
+ };
579
+ }
580
+ const pkg2 = await getPackageInfo(packageName, options);
581
+ rootPath = pkg2?.rootPath ?? null;
582
+ } catch (e) {
583
+ rootPath = null;
584
+ }
585
+ return rootPath;
586
+ }
587
+
588
+ // src/build/analyze/constants.ts
589
+ var DEPS_TO_IGNORE = ["#tools"];
590
+ var GLOBAL_EXTERNALS = [
591
+ "pino",
592
+ "pino-pretty",
593
+ "@libsql/client",
594
+ "pg",
595
+ "libsql",
596
+ "#tools",
597
+ "typescript",
598
+ "undici",
599
+ "readable-stream"
600
+ ];
601
+ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
572
602
  function removeDeployer() {
573
603
  const t = babel__default.types;
604
+ function removeDeployerFromObject(objectExpr, scope) {
605
+ const deployerProp = objectExpr.properties.find(
606
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
607
+ );
608
+ if (deployerProp) {
609
+ objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
610
+ if (t.isIdentifier(deployerProp.value)) {
611
+ const deployerBinding = scope.getBinding(deployerProp.value.name);
612
+ if (deployerBinding) {
613
+ deployerBinding.path?.parentPath?.remove();
614
+ }
615
+ }
616
+ }
617
+ return deployerProp;
618
+ }
574
619
  return {
575
620
  name: "remove-deployer",
576
621
  visitor: {
@@ -586,23 +631,30 @@ function removeDeployer() {
586
631
  if (!state.hasReplaced) {
587
632
  state.hasReplaced = true;
588
633
  const newMastraObj = t.cloneNode(path3.node);
589
- if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
590
- const deployer = newMastraObj.arguments[0].properties.find(
591
- (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
592
- );
593
- if (!deployer) {
594
- return;
634
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
635
+ const objectArg = newMastraObj.arguments[0];
636
+ let foundDeployer = false;
637
+ const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
638
+ if (directDeployer) {
639
+ foundDeployer = true;
595
640
  }
596
- newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
597
- (prop) => prop !== deployer
598
- );
599
- if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
600
- const deployerBinding = state.file.scope.getBinding(deployer.value.name);
601
- if (deployerBinding) {
602
- deployerBinding?.path?.parentPath?.remove();
641
+ for (const prop of objectArg.properties) {
642
+ if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
643
+ const spreadBinding = state.file.scope.getBinding(prop.argument.name);
644
+ if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
645
+ const init = spreadBinding.path.node.init;
646
+ if (t.isObjectExpression(init)) {
647
+ const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
648
+ if (spreadDeployer) {
649
+ foundDeployer = true;
650
+ }
651
+ }
652
+ }
603
653
  }
604
654
  }
605
- path3.replaceWith(newMastraObj);
655
+ if (foundDeployer) {
656
+ path3.replaceWith(newMastraObj);
657
+ }
606
658
  }
607
659
  }
608
660
  }
@@ -642,40 +694,6 @@ function removeDeployer2(mastraEntry, options) {
642
694
  }
643
695
  };
644
696
  }
645
- async function getPackageRootPath(packageName, parentPath) {
646
- let rootPath;
647
- try {
648
- let options = void 0;
649
- if (parentPath) {
650
- if (!parentPath.startsWith("file://")) {
651
- parentPath = pathToFileURL(parentPath).href;
652
- }
653
- options = {
654
- paths: [parentPath]
655
- };
656
- }
657
- const pkg2 = await getPackageInfo(packageName, options);
658
- rootPath = pkg2?.rootPath ?? null;
659
- } catch (e) {
660
- rootPath = null;
661
- }
662
- return rootPath;
663
- }
664
-
665
- // src/build/analyze/constants.ts
666
- var DEPS_TO_IGNORE = ["#tools"];
667
- var GLOBAL_EXTERNALS = [
668
- "pino",
669
- "pino-pretty",
670
- "@libsql/client",
671
- "pg",
672
- "libsql",
673
- "#tools",
674
- "typescript",
675
- "undici",
676
- "readable-stream"
677
- ];
678
- var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
679
697
 
680
698
  // src/build/analyze/analyzeEntry.ts
681
699
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
@@ -716,7 +734,9 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
716
734
  transformMixedEsModules: true,
717
735
  extensions: [".js", ".ts"]
718
736
  }),
719
- removeDeployer2(mastraEntry, { sourcemap: sourcemapEnabled }),
737
+ removeDeployer2(mastraEntry, {
738
+ sourcemap: sourcemapEnabled
739
+ }),
720
740
  esbuild()
721
741
  ]
722
742
  );
@@ -1749,6 +1769,6 @@ If you think your configuration is valid, please open an issue.`);
1749
1769
  };
1750
1770
  }
1751
1771
 
1752
- export { aliasHono, analyzeBundle, esbuild, esmShim, extractMastraOption, getBundlerOptions, getPackageRootPath, getWorkspaceInformation, removeAllOptionsFromMastraExcept, removeDeployer2 as removeDeployer, subpathExternalsResolver, tsConfigPaths };
1753
- //# sourceMappingURL=chunk-HNSVE6YO.js.map
1754
- //# sourceMappingURL=chunk-HNSVE6YO.js.map
1772
+ export { aliasHono, analyzeBundle, esbuild, esmShim, extractMastraOption, getBundlerOptions, getPackageRootPath, getWorkspaceInformation, removeDeployer2 as removeDeployer, subpathExternalsResolver, tsConfigPaths };
1773
+ //# sourceMappingURL=chunk-BDA7RMRF.js.map
1774
+ //# sourceMappingURL=chunk-BDA7RMRF.js.map