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

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 +66 -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 +269 -15
  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 +267 -13
  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
@@ -143,87 +143,6 @@ globalThis.__dirname = dirname(__filename);
143
143
  }
144
144
  );
145
145
  }
146
- function removeAllOptionsFromMastraExcept(result, option, logger) {
147
- const t = babel__namespace.default.types;
148
- return {
149
- name: "remove-all-except-" + option + "-config",
150
- visitor: {
151
- ExportNamedDeclaration: {
152
- // remove all exports
153
- exit(path3) {
154
- path3.remove();
155
- }
156
- },
157
- NewExpression(path3, state) {
158
- const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
159
- if (!varDeclaratorPath) {
160
- return;
161
- }
162
- const parentNode = path3.parentPath.node;
163
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
164
- return;
165
- }
166
- let mastraArgs = t.objectExpression([]);
167
- if (t.isObjectExpression(path3.node.arguments[0])) {
168
- mastraArgs = path3.node.arguments[0];
169
- }
170
- let configProperty = mastraArgs.properties.find(
171
- // @ts-ignore
172
- (prop) => prop.key.name === option
173
- );
174
- let configValue = t.objectExpression([]);
175
- const programPath = path3.scope.getProgramParent().path;
176
- if (!programPath) {
177
- return;
178
- }
179
- if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
180
- result.hasCustomConfig = true;
181
- configValue = configProperty.value;
182
- if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
183
- const configBinding = state.file.scope.getBinding(option);
184
- if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
185
- const id = path3.scope.generateUidIdentifier(option);
186
- configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
187
- configValue = id;
188
- }
189
- }
190
- }
191
- const exportDeclaration = t.exportNamedDeclaration(
192
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
193
- []
194
- );
195
- programPath.node.body.push(exportDeclaration);
196
- },
197
- Program: {
198
- exit(path3) {
199
- const hasExport = path3.node.body.some(
200
- (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
201
- );
202
- if (!hasExport) {
203
- if (logger) {
204
- logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
205
- export const mastra = new Mastra({
206
- ${option}: <value>
207
- })
208
-
209
- `);
210
- }
211
- const fallbackExportDeclaration = t.exportNamedDeclaration(
212
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
213
- []
214
- );
215
- path3.node.body.push(fallbackExportDeclaration);
216
- }
217
- }
218
- }
219
- }
220
- };
221
- }
222
-
223
- // src/build/babel/remove-all-options-bundler.ts
224
- function removeAllOptionsExceptBundler(result, logger) {
225
- return removeAllOptionsFromMastraExcept(result, "bundler", logger);
226
- }
227
146
  function esbuild(options = {}) {
228
147
  return originalEsbuild__default.default({
229
148
  target: "node20",
@@ -441,7 +360,117 @@ function recursiveRemoveNonReferencedNodes(code) {
441
360
  );
442
361
  });
443
362
  }
444
- function extractMastraOptionBundler(name, entryFile, transformer, result, logger) {
363
+ function removeAllOptionsFromMastraExcept(result, option, logger) {
364
+ const t = babel__namespace.default.types;
365
+ return {
366
+ name: "remove-all-except-" + option + "-config",
367
+ visitor: {
368
+ ExportNamedDeclaration: {
369
+ // remove all exports
370
+ exit(path3) {
371
+ path3.remove();
372
+ }
373
+ },
374
+ NewExpression(path3, state) {
375
+ const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
376
+ if (!varDeclaratorPath) {
377
+ return;
378
+ }
379
+ const parentNode = path3.parentPath.node;
380
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
381
+ return;
382
+ }
383
+ let mastraArgs = t.objectExpression([]);
384
+ if (t.isObjectExpression(path3.node.arguments[0])) {
385
+ mastraArgs = path3.node.arguments[0];
386
+ }
387
+ let configProperty = mastraArgs.properties.find(
388
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
389
+ );
390
+ let configValue = t.objectExpression([]);
391
+ const programPath = path3.scope.getProgramParent().path;
392
+ if (!programPath) {
393
+ return;
394
+ }
395
+ if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
396
+ result.hasCustomConfig = true;
397
+ configValue = configProperty.value;
398
+ if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
399
+ const configBinding = state.file.scope.getBinding(option);
400
+ if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
401
+ const id = path3.scope.generateUidIdentifier(option);
402
+ configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
403
+ configValue = id;
404
+ }
405
+ }
406
+ }
407
+ const exportDeclaration = t.exportNamedDeclaration(
408
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
409
+ []
410
+ );
411
+ programPath.node.body.push(exportDeclaration);
412
+ },
413
+ Program: {
414
+ exit(path3) {
415
+ const hasExport = path3.node.body.some(
416
+ (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
417
+ );
418
+ if (!hasExport) {
419
+ if (logger) {
420
+ logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
421
+ export const mastra = new Mastra({
422
+ ${option}: <value>
423
+ })
424
+
425
+ `);
426
+ }
427
+ const fallbackExportDeclaration = t.exportNamedDeclaration(
428
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
429
+ []
430
+ );
431
+ path3.node.body.push(fallbackExportDeclaration);
432
+ }
433
+ }
434
+ }
435
+ }
436
+ };
437
+ }
438
+
439
+ // src/build/plugins/remove-all-except.ts
440
+ function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
441
+ return {
442
+ name: `remove-${name}`,
443
+ transform(code, id) {
444
+ if (id !== mastraEntry) {
445
+ return;
446
+ }
447
+ return new Promise((resolve2, reject) => {
448
+ babel__namespace.transform(
449
+ code,
450
+ {
451
+ babelrc: false,
452
+ configFile: false,
453
+ filename: id,
454
+ plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
455
+ sourceMaps: options?.sourcemap
456
+ },
457
+ (err, result2) => {
458
+ if (err) {
459
+ return reject(err);
460
+ }
461
+ resolve2({
462
+ code: result2.code,
463
+ map: result2.map
464
+ });
465
+ }
466
+ );
467
+ });
468
+ }
469
+ };
470
+ }
471
+
472
+ // src/build/shared/extract-mastra-option.ts
473
+ function extractMastraOptionBundler(name, entryFile, result, logger) {
445
474
  return rollup.rollup({
446
475
  logLevel: "silent",
447
476
  input: {
@@ -462,34 +491,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
462
491
  ignoreTryCatch: false
463
492
  }),
464
493
  json__default.default(),
465
- {
466
- name: `extract-${name}-config`,
467
- transform(code, id) {
468
- if (id !== entryFile) {
469
- return;
470
- }
471
- return new Promise((resolve2, reject) => {
472
- babel__namespace.transform(
473
- code,
474
- {
475
- babelrc: false,
476
- configFile: false,
477
- filename: id,
478
- plugins: [transformer(result, logger)]
479
- },
480
- (err, result2) => {
481
- if (err) {
482
- return reject(err);
483
- }
484
- resolve2({
485
- code: result2.code,
486
- map: result2.map
487
- });
488
- }
489
- );
490
- });
491
- }
492
- },
494
+ removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
493
495
  // let esbuild remove all unused imports
494
496
  esbuild(),
495
497
  {
@@ -506,11 +508,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
506
508
  ]
507
509
  });
508
510
  }
509
- async function extractMastraOption(name, entryFile, transformer, outputDir, logger) {
511
+ async function extractMastraOption(name, entryFile, outputDir, logger) {
510
512
  const result = {
511
513
  hasCustomConfig: false
512
514
  };
513
- const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);
515
+ const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
514
516
  const output = await bundler.write({
515
517
  dir: outputDir,
516
518
  format: "es",
@@ -528,13 +530,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
528
530
 
529
531
  // src/build/bundlerOptions.ts
530
532
  async function getBundlerOptions(entryFile, outputDir, logger) {
531
- const result = await extractMastraOption(
532
- "bundler",
533
- entryFile,
534
- removeAllOptionsExceptBundler,
535
- outputDir,
536
- logger
537
- );
533
+ const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
538
534
  if (!result) {
539
535
  return null;
540
536
  }
@@ -603,8 +599,57 @@ function isNodeBuiltin(dep) {
603
599
  const [pkg2] = dep.split("/");
604
600
  return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg2);
605
601
  }
602
+ async function getPackageRootPath(packageName, parentPath) {
603
+ let rootPath;
604
+ try {
605
+ let options = void 0;
606
+ if (parentPath) {
607
+ if (!parentPath.startsWith("file://")) {
608
+ parentPath = url.pathToFileURL(parentPath).href;
609
+ }
610
+ options = {
611
+ paths: [parentPath]
612
+ };
613
+ }
614
+ const pkg2 = await localPkg.getPackageInfo(packageName, options);
615
+ rootPath = pkg2?.rootPath ?? null;
616
+ } catch (e) {
617
+ rootPath = null;
618
+ }
619
+ return rootPath;
620
+ }
621
+
622
+ // src/build/analyze/constants.ts
623
+ var DEPS_TO_IGNORE = ["#tools"];
624
+ var GLOBAL_EXTERNALS = [
625
+ "pino",
626
+ "pino-pretty",
627
+ "@libsql/client",
628
+ "pg",
629
+ "libsql",
630
+ "#tools",
631
+ "typescript",
632
+ "undici",
633
+ "readable-stream"
634
+ ];
635
+ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
606
636
  function removeDeployer() {
607
637
  const t = babel__namespace.default.types;
638
+ function removeDeployerFromObject(objectExpr, scope) {
639
+ const deployerProp = objectExpr.properties.find(
640
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
641
+ );
642
+ if (deployerProp) {
643
+ objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
644
+ if (t.isIdentifier(deployerProp.value)) {
645
+ const deployerBinding = scope.getBinding(deployerProp.value.name);
646
+ if (deployerBinding) {
647
+ deployerBinding.path?.parentPath?.remove();
648
+ }
649
+ }
650
+ }
651
+ return deployerProp;
652
+ }
608
653
  return {
609
654
  name: "remove-deployer",
610
655
  visitor: {
@@ -620,23 +665,30 @@ function removeDeployer() {
620
665
  if (!state.hasReplaced) {
621
666
  state.hasReplaced = true;
622
667
  const newMastraObj = t.cloneNode(path3.node);
623
- if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
624
- const deployer = newMastraObj.arguments[0].properties.find(
625
- (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
626
- );
627
- if (!deployer) {
628
- return;
668
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
669
+ const objectArg = newMastraObj.arguments[0];
670
+ let foundDeployer = false;
671
+ const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
672
+ if (directDeployer) {
673
+ foundDeployer = true;
629
674
  }
630
- newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
631
- (prop) => prop !== deployer
632
- );
633
- if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
634
- const deployerBinding = state.file.scope.getBinding(deployer.value.name);
635
- if (deployerBinding) {
636
- deployerBinding?.path?.parentPath?.remove();
675
+ for (const prop of objectArg.properties) {
676
+ if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
677
+ const spreadBinding = state.file.scope.getBinding(prop.argument.name);
678
+ if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
679
+ const init = spreadBinding.path.node.init;
680
+ if (t.isObjectExpression(init)) {
681
+ const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
682
+ if (spreadDeployer) {
683
+ foundDeployer = true;
684
+ }
685
+ }
686
+ }
637
687
  }
638
688
  }
639
- path3.replaceWith(newMastraObj);
689
+ if (foundDeployer) {
690
+ path3.replaceWith(newMastraObj);
691
+ }
640
692
  }
641
693
  }
642
694
  }
@@ -676,40 +728,6 @@ function removeDeployer2(mastraEntry, options) {
676
728
  }
677
729
  };
678
730
  }
679
- async function getPackageRootPath(packageName, parentPath) {
680
- let rootPath;
681
- try {
682
- let options = void 0;
683
- if (parentPath) {
684
- if (!parentPath.startsWith("file://")) {
685
- parentPath = url.pathToFileURL(parentPath).href;
686
- }
687
- options = {
688
- paths: [parentPath]
689
- };
690
- }
691
- const pkg2 = await localPkg.getPackageInfo(packageName, options);
692
- rootPath = pkg2?.rootPath ?? null;
693
- } catch (e) {
694
- rootPath = null;
695
- }
696
- return rootPath;
697
- }
698
-
699
- // src/build/analyze/constants.ts
700
- var DEPS_TO_IGNORE = ["#tools"];
701
- var GLOBAL_EXTERNALS = [
702
- "pino",
703
- "pino-pretty",
704
- "@libsql/client",
705
- "pg",
706
- "libsql",
707
- "#tools",
708
- "typescript",
709
- "undici",
710
- "readable-stream"
711
- ];
712
- var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
713
731
 
714
732
  // src/build/analyze/analyzeEntry.ts
715
733
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
@@ -750,7 +768,9 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
750
768
  transformMixedEsModules: true,
751
769
  extensions: [".js", ".ts"]
752
770
  }),
753
- removeDeployer2(mastraEntry, { sourcemap: sourcemapEnabled }),
771
+ removeDeployer2(mastraEntry, {
772
+ sourcemap: sourcemapEnabled
773
+ }),
754
774
  esbuild()
755
775
  ]
756
776
  );
@@ -1791,9 +1811,8 @@ exports.extractMastraOption = extractMastraOption;
1791
1811
  exports.getBundlerOptions = getBundlerOptions;
1792
1812
  exports.getPackageRootPath = getPackageRootPath;
1793
1813
  exports.getWorkspaceInformation = getWorkspaceInformation;
1794
- exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
1795
1814
  exports.removeDeployer = removeDeployer2;
1796
1815
  exports.subpathExternalsResolver = subpathExternalsResolver;
1797
1816
  exports.tsConfigPaths = tsConfigPaths;
1798
- //# sourceMappingURL=chunk-UJXH5MNH.cjs.map
1799
- //# sourceMappingURL=chunk-UJXH5MNH.cjs.map
1817
+ //# sourceMappingURL=chunk-CRIOGWZD.cjs.map
1818
+ //# sourceMappingURL=chunk-CRIOGWZD.cjs.map