How comandeer/rollup-lib-bundler works
Main Components
• Source Code Input: Represent the “src” folder that holds the library’s source files. Note the special subdirectories like “src/__bin__” for executables.
• Package Metadata Parser: A component (found in files like packageParser.ts and its submodules) that reads and parses package.json, extracting metadata such as name, version, exports, and bin configurations.
• Bundler Core: The central component (evidenced by files like bundler.ts and the “bundler” directory) that configures and runs Rollup bundling operations. This includes handling the determination of input entry points (e.g. src/index.js or src/index.ts, or even additional chunks via subpath exports).
• Babel Transpilation: Indicate that before or during bundling, the code is piped through Babel for transpilation. (Also note that transpilation targets can be derived from the “engines.node” field in package.json.)
• Terser Minification: Represent the minification step using terser that ensures smaller bundle sizes.
• Rollup Plugins: Within the bundler, there are custom plugins (such as those under “src/bundler/rollupPlugins”) that modify or preserve dynamic imports and resolve linked bundles.
• Output & Dist Handling: Show the process where bundled output is written into the “dist” (or alternative) directories. Highlight that the dist directory is purged before bundling takes place.
• CLI & Executable Handling: A flow for processing the CLI command (the “rlb” mentioned in the usage) that triggers the bundling process, including special handling for executables defined in the “bin” field.
• Testing Framework: Although not part of the production pipeline, note the “tests” directory used for validating functionality and bundling correctness.
Depicting Relationships & Data Flow
• From there, the source files (from “src/”) are processed by the Bundler Core where Rollup is configured. Within this core, illustrate interactions with:
• The Babel Transpiler: for converting code based on target node version.
• Custom Rollup Plugins: to manage dynamic import preservation and linked bundle resolution.
• Bundler’s output path determination (using the “exports” field from package.json) and the subsequent writing of bundled files to the correct output directories.
• For binary bundling, indicate a specialized flow: the bundler looks into “src/__bin__” based on the “bin” configuration in package.json, processes the file preserving the shebang, and outputs it as an ESM bundle.
• Optionally, include the Testing suite as a side component that executes tests on various fixture directories simulating different package configurations.
Architectural Patterns & Design Principles
• Pipeline/Flow Processing: Clearly represent the sequential steps – from reading package.json, gathering source code, processing through bundling/transpiling, to finally writing bundled files (with purging of output directories at the start).
• Convention over Configuration: Emphasize the opinionated nature – e.g., specific directory names (src, __bin__) and file naming conventions (index.js/ts mapping to “.” export).
Technology and Framework Labels
• Babel as the code transpiler.
• Terser for minification.
• Node.js runtime details (and note that “engines.node” can affect the Babel target).
• Optionally, note that tests use typical tools (as hinted at by test files, probably invoking CLI tests and other helpers).