{"id":15868,"library":"tsbunch","title":"TSBunch: TypeScript Bundler (TS to TS)","description":"TSBunch is a specialized TypeScript bundler designed to concatenate multiple `.ts` modules into a single `.ts` file without transpiling them to JavaScript. It is currently at version 0.4.25. Its primary use case is for platforms like CodinGame that require a single-file submission for TypeScript projects but do not allow or need JavaScript transpilation. Unlike mainstream bundlers (e.g., Webpack, Rollup, esbuild), TSBunch avoids generating JavaScript, instead leveraging TypeScript's `namespace` feature for module aggregation. This makes it unique for specific build workflows where the output must remain TypeScript. It has known limitations regarding full ES module import/export syntax support and does not resolve circular dependencies, operating primarily via string matching rather than a full AST analysis.","status":"active","version":"0.4.25","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/Zweihander-Main/TSBunch","tags":["javascript","typescript","bundler","codingame"],"install":[{"cmd":"npm install tsbunch","lang":"bash","label":"npm"},{"cmd":"yarn add tsbunch","lang":"bash","label":"yarn"},{"cmd":"pnpm add tsbunch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary API is a default export, a function named `tsbunch`. The documentation exclusively uses CommonJS `require`, but an ESM import should also work if your environment supports it.","wrong":"const tsbunch = require('tsbunch'); // For CJS","symbol":"tsbunch","correct":"import tsbunch from 'tsbunch'; // For ESM"}],"quickstart":{"code":"import tsbunch from 'tsbunch';\nimport path from 'path';\n\n// Simulate an entry file\n// tsbunch expects actual files on disk\n// For a runnable example, create these files first:\n// \n// // src/moduleA.ts\n// export const dataA = 'Hello from Module A!';\n// \n// // src/entry.ts\n// import { dataA } from './moduleA';\n// namespace MyBundle {\n//   console.log(dataA);\n//   export const bundledMessage = `Bundled: ${dataA}`;\n// }\n// \n// // src/declarations.d.ts\n// declare namespace Global {\n//   const APP_VERSION: string;\n// }\n\nconst entryFile = path.resolve(__dirname, 'src/entry.ts');\nconst outputFile = path.resolve(__dirname, 'out/bundle.ts');\nconst declarationFile = path.resolve(__dirname, 'src/declarations.d.ts');\n\n// In a real scenario, you'd ensure 'src' and 'out' directories exist.\n// For demonstration, we'll just show the call.\n\ntry {\n  console.log('Attempting to bundle...');\n  tsbunch(entryFile, outputFile, declarationFile);\n  console.log(`Bundle created successfully at ${outputFile}`);\n  console.log('You would typically inspect ' + outputFile + ' now.');\n  console.log('Note: This code snippet assumes you have actual files for entry, output, and declarations.');\n} catch (error) {\n  console.error('Bundling failed:', error);\n  console.error('Make sure your entry, output, and declaration file paths are correct and the files exist.');\n}\n\n// To run this: \n// 1. Create the files: src/moduleA.ts, src/entry.ts, src/declarations.d.ts\n// 2. Install tsbunch: npm install --save-dev tsbunch\n// 3. Run: node your-quickstart-file.js","lang":"typescript","description":"Demonstrates how to use the `tsbunch` function to bundle a TypeScript entry file, specify an output path, and include an optional declaration file, illustrating its core command-line usage."},"warnings":[{"fix":"Review the 'Caveats' section in the TSBunch README for supported and unsupported import/export syntax. Adjust your module structure to conform to the supported patterns, typically favoring explicit named exports and avoiding dynamic imports or re-exports from other modules.","message":"TSBunch uses string matching instead of an Abstract Syntax Tree (AST) for parsing. This means its support for the full ES module import/export specification is limited and might not behave as expected for all valid TypeScript module patterns.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Instead of directly default exporting functions or classes, assign them to a `const` and then `export default` that constant. Example: `const MyFunc = () => {}; export default MyFunc;`","message":"Direct `export default function` or `export default class` declarations will have their names changed by TSBunch. This can lead to unexpected behavior if you rely on the original default export name.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Before bundling, ensure your TypeScript project's module graph is free of circular dependencies. Tools like `madge` or `depcheck` can help identify these cycles in your codebase.","message":"TSBunch does not resolve circular dependencies. If your project contains circular imports, the bundling process may take an unusually long time or fail, leading to an unresponsive build process.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Refactor your code to use only explicit named imports and exports for modules that will be bundled. Avoid advanced module patterns that rely on dynamic loading or re-exporting namespaces.","message":"Dynamic `import()` expressions, type-only exports (`export type {}`), or re-exports (`export * from 'module'`) are not supported by TSBunch and will not be correctly processed.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Verify that all imported modules use supported `import` syntax as outlined in the TSBunch 'Caveats' section. Ensure module paths are relative and correct within the project structure.","cause":"TSBunch failed to correctly resolve or include a module due to unsupported import syntax or a file path issue. This often happens with dynamic imports or complex re-exports.","error":"Error: Cannot find module 'module-name' in the bundled output"},{"fix":"Identify and refactor any circular dependencies in your project's module graph. Use `madge --circular --ts` or similar tools to help pinpoint these issues before running TSBunch.","cause":"This is a common symptom of circular dependencies within the TypeScript modules being bundled. TSBunch does not have mechanisms to detect or resolve these cycles, leading to infinite loops or deep recursion during string matching.","error":"Bundling process hangs or takes an extremely long time without completing."},{"fix":"Review the 'Caveats' section for partially supported or unsupported import/export syntax. Specifically, avoid direct `export default function/class` and use a `const` variable for the default export instead. Ensure all module exports are explicitly named and simple.","cause":"The output `.ts` file contains syntax errors because TSBunch's string-based parsing incorrectly altered or failed to process certain import/export statements, or due to unsupported patterns like `export { default } from '...'`.","error":"Unexpected token 'export' or 'import' in output file, or bundled code fails to compile TypeScript."}],"ecosystem":"npm"}