{"version":3,"file":"bundlerOptions-I2E5y2Wp.cjs","names":["t","t","tsConfigPaths","esbuild"],"sources":["../src/build/babel/remove-all-options-except.ts","../src/build/plugins/remove-all-except.ts","../src/build/babel/remove-non-referenced-nodes.ts","../src/build/plugins/remove-unused-references.ts","../src/build/shared/extract-mastra-option.ts","../src/build/bundlerOptions.ts"],"sourcesContent":["import { types as t } from '@babel/core';\nimport type { NodePath, PluginObject, types } from '@babel/core';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\n\nexport function removeAllOptionsFromMastraExcept(\n  result: { hasCustomConfig: boolean },\n  option: keyof MastraConfig,\n  logger?: IMastraLogger,\n): PluginObject {\n  return {\n    name: 'remove-all-except-' + option + '-config',\n    visitor: {\n      ExportNamedDeclaration: {\n        // remove all exports, but keep the underlying declarations — the\n        // extracted option may reference them (e.g. `export const deployer = ...`\n        // used as `new Mastra({ deployer })`). Unreferenced declarations are\n        // dropped by the cleanup pass afterwards.\n        exit(path) {\n          if (path.node.declaration) {\n            const [declaration] = path.replaceWith(path.node.declaration);\n            // Already traversed — don't requeue, or the NewExpression visitor\n            // would append the extracted export a second time.\n            declaration.skip();\n          } else {\n            path.remove();\n          }\n        },\n      },\n\n      NewExpression(path, state) {\n        // is a variable declaration\n        const varDeclaratorPath = path.findParent(path => t.isVariableDeclarator(path.node));\n        if (!varDeclaratorPath) {\n          return;\n        }\n\n        const parentNode = path.parentPath.node;\n        // check if it's a const of mastra\n        if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== 'mastra') {\n          return;\n        }\n\n        let mastraArgs = t.objectExpression([]);\n        if (t.isObjectExpression(path.node.arguments[0])) {\n          mastraArgs = path.node.arguments[0];\n        }\n\n        // Find the config property, skipping SpreadElement nodes\n        let configProperty = mastraArgs.properties.find(\n          prop => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option,\n        );\n        let configValue: types.Expression = t.objectExpression([]);\n\n        const programPath = path.scope.getProgramParent().path as NodePath<types.Program> | undefined;\n        if (!programPath) {\n          return;\n        }\n\n        if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {\n          result.hasCustomConfig = true;\n          configValue = configProperty.value;\n\n          if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {\n            const configBinding = state.file.scope.getBinding(option)!;\n\n            if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {\n              const id = path.scope.generateUidIdentifier(option);\n\n              configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init!));\n              configValue = id;\n            }\n          }\n        }\n\n        // add the deployer export\n        const exportDeclaration = t.exportNamedDeclaration(\n          t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), configValue)]),\n          [],\n        );\n\n        programPath.node.body.push(exportDeclaration);\n      },\n\n      Program: {\n        exit(path) {\n          // Add a fallback export if no mastra configuration was found\n          const hasExport = path.node.body.some(\n            node => node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration',\n          );\n\n          if (!hasExport) {\n            if (logger) {\n              logger.warn('Mastra config could not be extracted', {\n                option,\n                details:\n                  'Please make sure your entry file looks like this:\\nexport const mastra = new Mastra({\\n  <option>: <value>\\n})',\n              });\n            }\n\n            const fallbackExportDeclaration = t.exportNamedDeclaration(\n              t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),\n              [],\n            );\n            path.node.body.push(fallbackExportDeclaration);\n          }\n        },\n      },\n    },\n  } satisfies PluginObject;\n}\n","import { transformAsync } from '@babel/core';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\nimport type { Plugin, SourceMapInput } from 'rollup';\nimport { removeAllOptionsFromMastraExcept } from '../babel/remove-all-options-except';\n\nexport function removeAllOptionsFromMastraExceptPlugin(\n  mastraEntry: string,\n  name: keyof MastraConfig,\n  result: { hasCustomConfig: boolean },\n  options?: { sourcemap?: boolean; logger?: IMastraLogger },\n): Plugin {\n  return {\n    name: `remove-${name}`,\n    transform(code, id) {\n      if (id !== mastraEntry) {\n        return;\n      }\n\n      return transformAsync(code, {\n        babelrc: false,\n        configFile: false,\n        filename: id,\n        plugins: [() => removeAllOptionsFromMastraExcept(result, name, options?.logger)],\n        sourceMaps: options?.sourcemap,\n      }).then(result => ({\n        code: result!.code!,\n        map: result!.map! as SourceMapInput,\n      }));\n    },\n  } satisfies Plugin;\n}\n","import { types as t } from '@babel/core';\nimport type { PluginObject } from '@babel/core';\n\nexport function removeNonReferencedNodes() {\n  return {\n    name: 'remove-non-referenced-nodes',\n    visitor: {\n      Program(path) {\n        // Get the scope information\n        const scope = path.scope;\n\n        // Filter body to keep only referenced nodes\n        const currentBody = path.get('body');\n        const filteredBody = currentBody.filter(childPath => {\n          if (childPath.isExportDeclaration()) {\n            return true;\n          }\n\n          // For variable declarations, check if any declared variables are referenced\n          if (childPath.isVariableDeclaration()) {\n            return childPath.node.declarations.some(decl => {\n              if (!t.isIdentifier(decl.id)) {\n                return false;\n              }\n\n              const name = decl.id.name;\n              const binding = scope.getBinding(name);\n              // Keep if it has references or is exported\n              return binding && (binding.referenced || binding.referencePaths.length > 0);\n            });\n          }\n\n          // For function/class declarations, check if they're referenced\n          if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {\n            if (!t.isIdentifier(childPath.node.id)) {\n              return false;\n            }\n\n            const name = childPath.node.id.name;\n            const binding = scope.getBinding(name);\n            return binding && (binding.referenced || binding.referencePaths.length > 0);\n          }\n\n          // For imports, check if any imported items are referenced\n          if (childPath.isImportDeclaration()) {\n            return childPath.node.specifiers.some(specifier => {\n              const importedName = specifier.local.name;\n              const binding = scope.getBinding(importedName);\n              return binding && (binding.referenced || binding.referencePaths.length > 0);\n            });\n          }\n\n          // Default to keeping other node types\n          return false;\n        });\n\n        // Replace the program body with filtered nodes\n        path.set(\n          'body',\n          filteredBody.map(p => p.node),\n        );\n      },\n    },\n  } as PluginObject;\n}\n","import { transformAsync } from '@babel/core';\nimport { removeNonReferencedNodes } from '../babel/remove-non-referenced-nodes';\n\nexport async function recursiveRemoveNonReferencedNodes(code: string): Promise<{ code: string; map: any }> {\n  const result = await transformAsync(code, {\n    babelrc: false,\n    configFile: false,\n    plugins: [removeNonReferencedNodes],\n  });\n\n  // keep looping until the code is not changed\n  if (result && result.code! !== code) {\n    return recursiveRemoveNonReferencedNodes(result!.code!);\n  }\n\n  return {\n    code: result!.code!,\n    map: result!.map!,\n  };\n}\n","import { pathToFileURL } from 'node:url';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\nimport { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';\nimport commonjs from '@rollup/plugin-commonjs';\nimport json from '@rollup/plugin-json';\nimport { rollup } from 'rollup';\nimport type { RollupOutput } from 'rollup';\nimport { esbuild } from '../plugins/esbuild';\nimport { removeAllOptionsFromMastraExceptPlugin } from '../plugins/remove-all-except';\nimport { recursiveRemoveNonReferencedNodes } from '../plugins/remove-unused-references';\nimport { tsConfigPaths } from '../plugins/tsconfig-paths';\n\nexport function extractMastraOptionBundler(\n  name: keyof MastraConfig,\n  entryFile: string,\n  result: {\n    hasCustomConfig: boolean;\n  },\n  logger?: IMastraLogger,\n) {\n  return rollup({\n    logLevel: 'silent',\n    input: {\n      [`${name}-config`]: entryFile,\n    },\n    treeshake: 'smallest',\n    plugins: [\n      tsConfigPaths(),\n      // transpile typescript to something we understand\n      esbuild(),\n      optimizeLodashImports({\n        include: '**/*.{js,ts,mjs,cjs}',\n      }),\n      commonjs({\n        extensions: ['.js', '.ts'],\n        strictRequires: 'strict',\n        transformMixedEsModules: true,\n        ignoreTryCatch: false,\n      }),\n      json(),\n      removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),\n      // let esbuild remove all unused imports\n      esbuild(),\n      {\n        name: 'cleanup',\n        transform(code, id) {\n          if (id !== entryFile) {\n            return;\n          }\n\n          return recursiveRemoveNonReferencedNodes(code);\n        },\n      },\n      // let esbuild remove it once more\n      esbuild(),\n    ],\n  });\n}\n\nexport async function extractMastraOption<T extends keyof MastraConfig>(\n  name: T,\n  entryFile: string,\n  outputDir: string,\n  logger?: IMastraLogger,\n): Promise<{\n  bundleOutput: RollupOutput;\n  getConfig: () => Promise<MastraConfig[T]>;\n} | null> {\n  const result = {\n    hasCustomConfig: false,\n  };\n\n  const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);\n\n  const output = await bundler.write({\n    dir: outputDir,\n    format: 'es',\n    entryFileNames: '[name].mjs',\n  });\n\n  if (result.hasCustomConfig) {\n    const configPath = `${outputDir}/${name}-config.mjs`;\n\n    return {\n      bundleOutput: output,\n      getConfig: () => import(pathToFileURL(configPath).href).then(m => m[name] as MastraConfig[T]),\n    };\n  }\n\n  return null;\n}\n","import type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config } from '@mastra/core/mastra';\nimport { extractMastraOption, extractMastraOptionBundler } from './shared/extract-mastra-option';\n\nexport function getBundlerOptionsBundler(\n  entryFile: string,\n  result: {\n    hasCustomConfig: false;\n  },\n) {\n  return extractMastraOptionBundler('bundler', entryFile, result);\n}\n\nexport async function getBundlerOptions(\n  entryFile: string,\n  outputDir: string,\n  logger?: IMastraLogger,\n): Promise<Config['bundler'] | null> {\n  const result = await extractMastraOption('bundler', entryFile, outputDir, logger);\n\n  if (!result) {\n    return null;\n  }\n\n  return result.getConfig();\n}\n"],"mappings":";;;;;;;;;;;AAKA,SAAgB,iCACd,QACA,QACA,QACc;CACd,OAAO;EACL,MAAM,uBAAuB,SAAS;EACtC,SAAS;GACP,wBAAwB,EAKtB,KAAK,MAAM;IACT,IAAI,KAAK,KAAK,aAAa;KACzB,MAAM,CAAC,eAAe,KAAK,YAAY,KAAK,KAAK,WAAW;KAG5D,YAAY,KAAK;IACnB,OACE,KAAK,OAAO;GAEhB,EACF;GAEA,cAAc,MAAM,OAAO;IAGzB,IAAI,CADsB,KAAK,YAAW,SAAQA,YA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