creating-modules
Creates new modules within existing packages following project conventions. Handles file structure, barrel exports, namespace files, package.json imports/exports, and internal import patterns.
When & Why to Use This Skill
This Claude skill automates the end-to-end creation of new modules within existing packages, ensuring strict adherence to project-specific conventions. It streamlines the development workflow by handling complex scaffolding tasks, including directory setup, implementation files, barrel exports, and namespace definitions, while automatically managing package.json configurations and internal import patterns.
Use Cases
- Rapid Feature Scaffolding: Instantly generate standardized directory structures and boilerplate files for new components or features in a TypeScript/Node.js environment.
- Automated Configuration Management: Eliminate manual errors by automatically updating package.json 'imports' and 'exports' fields to support modern subpath patterns.
- Consistency Enforcement: Ensure all team members follow uniform naming conventions (kebab-case for directories, PascalCase for namespaces) and export structures across a large codebase.
- Monorepo Optimization: Simplify the process of adding and linking sub-modules within complex package structures while maintaining clean internal reference patterns using '#' imports.
| name | creating-modules |
|---|---|
| description | Creates new modules within existing packages following project conventions. Handles file structure, barrel exports, namespace files, package.json imports/exports, and internal import patterns. |
Creating Modules
Steps
Create module directory:
packages/<pkg>/src/<module-name>/Create implementation files:
<module-name>.tsor split across multiple filesCreate barrel file
__.ts:export * from './implementation.js' export type * from './types.js'Create namespace file
_.ts:export * as ModuleName from './__.js'Add to package.json imports:
{ "imports": { "#module-name": "./build/module-name/_.js", "#module-name/*": "./build/module-name/*.js" } }Add to package.json exports:
{ "exports": { "./module-name": "./build/module-name/__.js" } }Sync tsconfig paths (run
syncing-tsconfig-pathsskill script)Add to main exports in
src/index.ts:export * from '#module-name'
Reference
Module Structure
src/module-name/
├── _.ts # Namespace file - exports the namespace
├── _.test.ts # Module tests
├── __.ts # Barrel file - exports all functions/types
└── *.ts # Implementation files
Import System
Use # imports for internal module references within a package:
// Correct - use # imports
import { Fn } from '#fn'
import { Obj } from '#obj'
// Incorrect - don't use relative or package imports internally
import { Fn } from '../fn/_.js'
import { Obj } from '@kitz/core/obj'
Naming
- Directory: kebab-case (
group-by/) - Namespace export: PascalCase (
GroupBy) - Functions: camelCase, no namespace prefix (
by, notgroupBy)
Notes
- Each package defines its own
#imports in package.json - Cross-package
#imports are not valid - use package name imports