@mastra/deployer 1.55.0 → 1.56.0-alpha.1
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 +20 -0
- package/dist/{analyze-DhDZW9TS.cjs → analyze-Bd7sweH1.cjs} +102 -6
- package/dist/{analyze-DhDZW9TS.cjs.map → analyze-Bd7sweH1.cjs.map} +1 -1
- package/dist/{analyze-C2q7jxbN.js → analyze-NsGxmfVD.js} +90 -7
- package/dist/analyze-NsGxmfVD.js.map +1 -0
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze.cjs +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +5 -5
- package/dist/build/index.js +5 -5
- package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
- package/dist/{build-KCOeHd4N.js → build-BXESKc2J.js} +5 -5
- package/dist/{build-KCOeHd4N.js.map → build-BXESKc2J.js.map} +1 -1
- package/dist/{build-De4AZhfJ.cjs → build-CwZ98Yf2.cjs} +5 -5
- package/dist/{build-De4AZhfJ.cjs.map → build-CwZ98Yf2.cjs.map} +1 -1
- package/dist/bundler/index.cjs +36 -11
- package/dist/bundler/index.cjs.map +1 -1
- package/dist/bundler/index.d.ts +1 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +37 -12
- package/dist/bundler/index.js.map +1 -1
- package/dist/bundler/workspaceDependencies.d.ts +3 -5
- package/dist/bundler/workspaceDependencies.d.ts.map +1 -1
- package/dist/{bundler-D86rFu2J.js → bundler-U9F2---r.js} +2 -3
- package/dist/bundler-U9F2---r.js.map +1 -0
- package/dist/{bundler-BqrDXofn.cjs → bundler-u9WOUtpl.cjs} +2 -3
- package/dist/bundler-u9WOUtpl.cjs.map +1 -0
- package/dist/{bundlerOptions-aFsEi86t.js → bundlerOptions-9DigsVhY.js} +2 -2
- package/dist/{bundlerOptions-aFsEi86t.js.map → bundlerOptions-9DigsVhY.js.map} +1 -1
- package/dist/{bundlerOptions-rBmtSyGe.cjs → bundlerOptions-CYRir4LE.cjs} +2 -2
- package/dist/{bundlerOptions-rBmtSyGe.cjs.map → bundlerOptions-CYRir4LE.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/server/handlers/restart-active-runs.d.ts.map +1 -1
- package/dist/server/index.cjs +6 -2
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +6 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/deps.d.ts +6 -2
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/services/index.cjs +1 -1
- package/dist/services/index.js +1 -1
- package/dist/{services-CLi56qqe.js → services-CHz7RuZ1.js} +7 -3
- package/dist/services-CHz7RuZ1.js.map +1 -0
- package/dist/{services-BxYMLS9-.cjs → services-Cw3Ho44Z.cjs} +7 -3
- package/dist/services-Cw3Ho44Z.cjs.map +1 -0
- package/package.json +6 -6
- package/dist/analyze-C2q7jxbN.js.map +0 -1
- package/dist/bundler-BqrDXofn.cjs.map +0 -1
- package/dist/bundler-D86rFu2J.js.map +0 -1
- package/dist/services-BxYMLS9-.cjs.map +0 -1
- package/dist/services-CLi56qqe.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundlerOptions-aFsEi86t.js","names":["t","t"],"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,MAAE,qBAAqB,KAAK,IAAI,CAC7D,GACnB;IAGF,MAAM,aAAa,KAAK,WAAW;IAEnC,IAAI,CAACA,MAAE,qBAAqB,UAAU,KAAK,CAACA,MAAE,aAAa,WAAW,EAAE,KAAK,WAAW,GAAG,SAAS,UAClG;IAGF,IAAI,aAAaA,MAAE,iBAAiB,CAAC,CAAC;IACtC,IAAIA,MAAE,mBAAmB,KAAK,KAAK,UAAU,EAAE,GAC7C,aAAa,KAAK,KAAK,UAAU;IAInC,IAAI,iBAAiB,WAAW,WAAW,MACzC,SAAQA,MAAE,iBAAiB,IAAI,KAAKA,MAAE,aAAa,KAAK,GAAG,KAAK,KAAK,IAAI,SAAS,MACpF;IACA,IAAI,cAAgCA,MAAE,iBAAiB,CAAC,CAAC;IAEzD,MAAM,cAAc,KAAK,MAAM,iBAAiB,CAAC,CAAC;IAClD,IAAI,CAAC,aACH;IAGF,IAAI,kBAAkBA,MAAE,iBAAiB,cAAc,KAAKA,MAAE,aAAa,eAAe,KAAK,GAAG;KAChG,OAAO,kBAAkB;KACzB,cAAc,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-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,MAAE,qBAAqB,KAAK,IAAI,CAC7D,GACnB;IAGF,MAAM,aAAa,KAAK,WAAW;IAEnC,IAAI,CAACA,MAAE,qBAAqB,UAAU,KAAK,CAACA,MAAE,aAAa,WAAW,EAAE,KAAK,WAAW,GAAG,SAAS,UAClG;IAGF,IAAI,aAAaA,MAAE,iBAAiB,CAAC,CAAC;IACtC,IAAIA,MAAE,mBAAmB,KAAK,KAAK,UAAU,EAAE,GAC7C,aAAa,KAAK,KAAK,UAAU;IAInC,IAAI,iBAAiB,WAAW,WAAW,MACzC,SAAQA,MAAE,iBAAiB,IAAI,KAAKA,MAAE,aAAa,KAAK,G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B;EAC9F;CACF;CAEA,OAAO;AACT;;;AC9EA,eAAsB,kBACpB,WACA,WACA,QACmC;CACnC,MAAM,SAAS,MAAM,oBAAoB,WAAW,WAAW,WAAW,MAAM;CAEhF,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,UAAU;AAC1B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
|
|
2
|
-
const require_bundler = require("./bundler-
|
|
2
|
+
const require_bundler = require("./bundler-u9WOUtpl.cjs");
|
|
3
3
|
let _babel_core = require("@babel/core");
|
|
4
4
|
let url = require("url");
|
|
5
5
|
let _rollup_plugin_commonjs = require("@rollup/plugin-commonjs");
|
|
@@ -191,4 +191,4 @@ Object.defineProperty(exports, "getBundlerOptions", {
|
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
//# sourceMappingURL=bundlerOptions-
|
|
194
|
+
//# sourceMappingURL=bundlerOptions-CYRir4LE.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundlerOptions-rBmtSyGe.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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CAEhF,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,UAAU;AAC1B"}
|
|
1
|
+
{"version":3,"file":"bundlerOptions-CYRir4LE.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,YAAAA,MAAE,qBAAqB,KAAK,IAAI,CAC7D,GACnB;IAGF,MAAM,aAAa,KAAK,WAAW;IAEnC,IAAI,CAACA,YAAAA,MAAE,qBAAqB,UAAU,KAAK,CAACA,YAAAA,MAAE,aAAa,WAAW,EAAE,KAAK,WAAW,GAAG,SAAS,UAClG;IAGF,IAAI,aAAaA,YAAAA,MAAE,iBAA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AI;KAClB,IAAI,OAAO,WACT;KAGF,OAAO,kCAAkC,IAAI;IAC/C;GACF;GAEAA,gBAAAA,QAAQ;EACV;CACF,CAAC;AACH;AAEA,eAAsB,oBACpB,MACA,WACA,WACA,QAIQ;CACR,MAAM,SAAS,EACb,iBAAiB,MACnB;CAIA,MAAM,SAAS,OAAM,MAFC,2BAA2B,MAAM,WAAW,QAAQ,MAAM,EAAA,CAEnD,MAAM;EACjC,KAAK;EACL,QAAQ;EACR,gBAAgB;CAClB,CAAC;CAED,IAAI,OAAO,iBAAiB;EAC1B,MAAM,aAAa,GAAG,UAAU,GAAG,KAAK;EAExC,OAAO;GACL,cAAc;GACd,iBAAiB,QAAA,GAAA,IAAA,cAAA,CAAqB,UAAU,CAAC,CAAC,KAAK,CAAC,MAAK,MAAK,EAAE,KAAwB;EAC9F;CACF;CAEA,OAAO;AACT;;;AC9EA,eAAsB,kBACpB,WACA,WACA,QACmC;CACnC,MAAM,SAAS,MAAM,oBAAoB,WAAW,WAAW,WAAW,MAAM;CAEhF,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,UAAU;AAC1B"}
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_services = require("./services-
|
|
3
|
-
const require_bundlerOptions = require("./bundlerOptions-
|
|
2
|
+
const require_services = require("./services-Cw3Ho44Z.cjs");
|
|
3
|
+
const require_bundlerOptions = require("./bundlerOptions-CYRir4LE.cjs");
|
|
4
4
|
const require_bundler_index = require("./bundler/index.cjs");
|
|
5
|
-
require("./build-
|
|
5
|
+
require("./build-CwZ98Yf2.cjs");
|
|
6
6
|
//#region src/deploy/base.ts
|
|
7
7
|
var Deployer = class extends require_bundler_index.Bundler {
|
|
8
8
|
deps = new require_services.DepsService();
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as createChildProcessLogger, i as DepsService, o as createPinoStream, r as Deps, t as FileService } from "./services-
|
|
2
|
-
import { n as extractMastraOption } from "./bundlerOptions-
|
|
1
|
+
import { a as createChildProcessLogger, i as DepsService, o as createPinoStream, r as Deps, t as FileService } from "./services-CHz7RuZ1.js";
|
|
2
|
+
import { n as extractMastraOption } from "./bundlerOptions-9DigsVhY.js";
|
|
3
3
|
import { Bundler } from "./bundler/index.js";
|
|
4
|
-
import "./build-
|
|
4
|
+
import "./build-BXESKc2J.js";
|
|
5
5
|
//#region src/deploy/base.ts
|
|
6
6
|
var Deployer = class extends Bundler {
|
|
7
7
|
deps = new DepsService();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart-active-runs.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/restart-active-runs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIpC,wBAAsB,mCAAmC,CAAC,CAAC,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"restart-active-runs.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/restart-active-runs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIpC,wBAAsB,mCAAmC,CAAC,CAAC,EAAE,OAAO,qBAoBnE"}
|
package/dist/server/index.cjs
CHANGED
|
@@ -3009,8 +3009,12 @@ async function healthHandler(c) {
|
|
|
3009
3009
|
async function restartAllActiveWorkflowRunsHandler(c) {
|
|
3010
3010
|
try {
|
|
3011
3011
|
const mastra = c.get("mastra");
|
|
3012
|
-
mastra.restartAllActiveWorkflowRuns()
|
|
3013
|
-
|
|
3012
|
+
mastra.restartAllActiveWorkflowRuns().catch((error) => {
|
|
3013
|
+
mastra.getLogger().error("Failed to restart active workflow runs during server startup", { error });
|
|
3014
|
+
});
|
|
3015
|
+
if (mastra.recoveryConfig?.durableAgents === "auto") mastra.recoverAllDurableAgents().catch((error) => {
|
|
3016
|
+
mastra.getLogger().error("Failed to recover durable agent runs during server startup", { error });
|
|
3017
|
+
});
|
|
3014
3018
|
return c.json({ message: "Restarting all active workflow runs..." });
|
|
3015
3019
|
} catch (error) {
|
|
3016
3020
|
return handleError(error, "Error restarting active workflow runs");
|