Generating New Packages
Relevant source files
The following files were used as context for generating this wiki page:
Generating new packages in the web-projects monorepo is a standardized process managed by Turborepo Generators. This system ensures consistency across the codebase by using predefined templates and automated scaffolding scripts, allowing developers to quickly initialize new modules that adhere to the project's architectural standards.
The repository utilizes a workspace-based structure where all internal packages are located within the packages/ directory and managed via bun workspaces. The generation process is triggered via a CLI command that prompts the user for configuration details and then populates the target directory with the necessary boilerplate.
Sources: README.md:37-39, CLAUDE.md:10-10, package.json:42-46
Generation Workflow
The generation process follows a structured sequence where a user interacts with the turbo gen tool. The tool uses a configuration file to define prompts and subsequent file-system actions.
This diagram illustrates the logical flow from the initial command to the final creation of package files.
Sources: turbo/generators/config.ts:18-50
CLI Commands and Initialization
To start the generation of a new package, the user executes the following command from the repository root:
turbo gen package
This command invokes the Turborepo generator defined in the project. The configuration for this generator is located in turbo/generators/config.ts. The system uses @turbo/gen and PlopTypes to manage the interaction and file transformations.
Sources: README.md:37-39, turbo/generators/config.ts:1-2, package.json:28
Configuration and Logic
The generator is configured to prompt the user for two specific pieces of information: the package type and the package name.
Prompts and Validation
The generator uses a list prompt for the package type and an input prompt for the name. A validation function, validateNonEmptyString, ensures that the package name is not empty or composed solely of whitespace.
| Prompt Name | Type | Description | Validation |
|---|---|---|---|
type | list | Selection of the package template (e.g., ts-package) | Required selection |
name | input | The name of the new package to be created | Must be a non-empty string |
Sources: turbo/generators/config.ts:18-36
Execution Actions
Once the inputs are collected, the generator executes an addMany action. This action:
- Determines the base path of the repository.
- Locates the template directory under
templates/{{type}}. - Copies all files within that template directory to the final destination in the
packages/folder.
// turbo/generators/config.ts:40-48
actions: (answers) => {
const { type, name } = answers as PackageResponse;
const basePath = plop.getDestBasePath();
const templatePath = path.join(basePath, 'templates', type);
return [
{
type: 'addMany',
templateFiles: path.join(templatePath, '**/*'),
base: templatePath,
destination: `{{ turbo.paths.root }}/packages/${name}`,
},
];
}
Sources: turbo/generators/config.ts:37-50
Project Architecture Integration
New packages generated through this system are automatically integrated into the monorepo's architecture. The repository uses bun workspaces, which are configured to look for packages in apps/*, packages/*, and playgrounds/*.
This structure shows where new packages reside in relation to the global workspace configuration.
Sources: package.json:42-46, CLAUDE.md:21-41, templates/README.md:1-5
Workspace Patterns
When a package is generated, it is expected to follow the established workspace patterns:
- Internal References: Internal packages should refer to each other using the
workspace:*protocol in theirpackage.jsonfiles. - Build Output: Outputs are typically directed to
dist/or specific runtime directories. - Testing: New packages should include co-located test files (e.g.,
foo.test.ts) to be picked up by theturbo run testcommand.
Sources: CLAUDE.md:55-57, CLAUDE.md:66-71, turbo.json:1-25
Conclusion
The package generation system provides a robust and repeatable method for extending the web-projects repository. By leveraging turbo gen and centralized templates, the project maintains high standards of code quality and architectural consistency, ensuring that every new package is correctly configured for testing, building, and linting within the monorepo environment.