- 
                Notifications
    You must be signed in to change notification settings 
- Fork 320
feat: support --turbo build for Next.js #2422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: canary
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,12 +8,12 @@ function getNextJsVersion(): string | null { | |
| }); | ||
| const nextPackageJson = require(projectNextPath); | ||
| return nextPackageJson.version || null; | ||
| } catch (error) { | ||
| } catch { | ||
| try { | ||
| // Fallback to checking in the plugin's dependencies | ||
| const nextPackageJson = require('next/package.json'); | ||
| return nextPackageJson.version || null; | ||
| } catch (error) { | ||
| } catch { | ||
| console.warn( | ||
| 'Warning: Could not determine Next.js version, defaulting to latest config', | ||
| ); | ||
|  | @@ -43,7 +43,7 @@ export interface BamlNextConfig { | |
| webpack?: ((config: Configuration, context: any) => Configuration) | null; | ||
| } | ||
|  | ||
| export function withBaml(bamlConfig: BamlNextConfig = {}) { | ||
| export function withBaml(_bamlConfig: BamlNextConfig = {}) { | ||
| return function withBamlConfig<T extends GenericNextConfig>( | ||
| nextConfig: T = {} as T, | ||
| ): T { | ||
|  | @@ -55,65 +55,46 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) { | |
| const useNewConfig = majorVersion >= 14; | ||
| const isTurbo = Boolean(process.env.TURBOPACK === '1'); | ||
|  | ||
| if (isTurbo) { | ||
| console.warn( | ||
| '\x1b[33m%s\x1b[0m', | ||
| ` | ||
| ⚠️ Warning: @boundaryml/baml-nextjs-plugin does not yet support Turbopack | ||
| Please remove the --turbo flag from your "next dev" command. | ||
| Example: "next dev" instead of "next dev --turbo" | ||
| `, | ||
| ); | ||
| } | ||
|  | ||
| const turboConfig = isTurbo | ||
| ? { | ||
| ...(nextConfig.experimental?.turbo || {}), | ||
| rules: { | ||
| ...(nextConfig.experimental?.turbo?.rules || {}), | ||
| '*.node': { loaders: ['nextjs-node-loader'], as: '*.js' }, | ||
| }, | ||
| } | ||
| : undefined; | ||
|  | ||
| return { | ||
| ...nextConfig, | ||
| ...(useNewConfig | ||
| ? { | ||
| experimental: { | ||
| ...(nextConfig.experimental || {}), | ||
| ...(isTurbo ? { turbo: turboConfig } : {}), | ||
| }, | ||
| // In Turbo mode, we don't add it to serverExternalPackages to avoid the conflict | ||
| ...(isTurbo | ||
| ? {} | ||
| : { | ||
| serverExternalPackages: [ | ||
| ...(nextConfig?.serverExternalPackages || []), | ||
| '@boundaryml/baml', | ||
| ], | ||
| }), | ||
| // Always add BAML to serverExternalPackages for both webpack and Turbopack | ||
| serverExternalPackages: [ | ||
| ...(nextConfig?.serverExternalPackages || []), | ||
| '@boundaryml/baml', | ||
| '@boundaryml/baml-darwin-arm64', | ||
| '@boundaryml/baml-darwin-x64', | ||
| '@boundaryml/baml-linux-arm64-gnu', | ||
| '@boundaryml/baml-linux-arm64-musl', | ||
| '@boundaryml/baml-linux-x64-gnu', | ||
| '@boundaryml/baml-linux-x64-musl', | ||
| '@boundaryml/baml-win32-arm64-msvc', | ||
| '@boundaryml/baml-win32-x64-msvc', | ||
| ], | ||
| } | ||
| : { | ||
| experimental: { | ||
| ...(nextConfig.experimental || {}), | ||
| serverComponentsExternalPackages: [ | ||
| ...((nextConfig.experimental as any) | ||
| ?.serverComponentsExternalPackages || []), | ||
| ...(nextConfig.experimental?.serverComponentsExternalPackages || | ||
| []), | ||
| '@boundaryml/baml', | ||
| ], | ||
| ...(isTurbo ? { turbo: turboConfig } : {}), | ||
| }, | ||
| }), | ||
| webpack: (config: Configuration, context: any) => { | ||
| let webpackConfig = config; | ||
| if (typeof nextConfig.webpack === 'function') { | ||
| config = nextConfig.webpack(config, context); | ||
| webpackConfig = nextConfig.webpack(config, context); | ||
| } | ||
|  | ||
| if (context.isServer) { | ||
| // Externalize the native module | ||
| config.externals = [ | ||
| ...(Array.isArray(config.externals) ? config.externals : []), | ||
| webpackConfig.externals = [ | ||
| ...(Array.isArray(webpackConfig.externals) | ||
| ? webpackConfig.externals | ||
| : []), | ||
| '@boundaryml/baml', | ||
| '@boundaryml/baml-darwin-arm64', | ||
| '@boundaryml/baml-darwin-x64', | ||
|  | @@ -128,27 +109,22 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) { | |
|  | ||
| // Only add webpack rules if not using Turbo | ||
| if (!isTurbo) { | ||
| config.module = config.module || {}; | ||
| config.module.rules = config.module.rules || []; | ||
| config.module.rules.push({ | ||
| webpackConfig.module = webpackConfig.module || {}; | ||
| webpackConfig.module.rules = webpackConfig.module.rules || []; | ||
| webpackConfig.module.rules.push({ | ||
| test: /\.node$/, | ||
| use: [ | ||
| { | ||
| loader: 'nextjs-node-loader', | ||
| options: { | ||
| outputPath: config.output?.path, | ||
| outputPath: webpackConfig.output?.path, | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|  | ||
| // Ensure module and rules are defined | ||
| config.module = config.module || {}; | ||
| config.module.rules = config.module.rules || []; | ||
| // Add WebAssembly loading configuration (properly indented) | ||
|  | ||
| return config; | ||
| return webpackConfig; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correctness:  🤖 AI Agent Prompt for Cursor/Windsurf
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seawatts is this a real bug? | ||
| }, | ||
| } as T; | ||
| }; | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _bamlConfig parameter is currently unused. Consider removing it or using it for configurable behavior to avoid confusion.