Common utilities and types for Codefox projects.
Since this is a workspace package, you can add it to your project's dependencies:
{
"dependencies": {
"codefox-common": "workspace:*"
}
}
Then run:
pnpm install
The package will automatically build during installation due to the prepare script.
If you need to rebuild the package manually:
# Install dependencies
pnpm install
# Build package
pnpm run build
This will create:
- CommonJS build in
dist/cjs
- ES Modules build in
dist/esm
- TypeScript declarations in
dist/types
You can import types and utilities using either ESM or CommonJS syntax:
// ESM
import { BaseEntity, Result } from 'codefox-common';
// CommonJS
const { BaseEntity } = require('codefox-common');
// Base entity with common fields
interface BaseEntity {
id: string;
createdAt: Date;
updatedAt: Date;
}
// Error response structure
interface ErrorResponse {
code: string;
message: string;
details?: Record<string, unknown>;
}
// Generic result type
type Result<T> =
| {
success: true;
data: T;
}
| {
success: false;
error: ErrorResponse;
};
- Make changes in
src/
directory - The package will automatically rebuild when you run
pnpm install
- For manual rebuilds, run
pnpm run build
- Import and use in other workspace packages
codefox-common/
├── src/
│ ├── index.ts # Main entry point
│ └── types.ts # Type definitions
├── dist/ # Build output (generated)
├── tsconfig.json # Base TypeScript config
├── tsconfig.cjs.json # CommonJS build config
├── tsconfig.esm.json # ES Modules build config
└── tsconfig.types.json # Type declarations config
The package uses npm's prepare
script to automatically build during installation. This means:
- When you run
pnpm install
in the root workspace - When you add/update this package as a dependency
- When you clone the repository and run initial setup
The package will automatically build itself, ensuring the compiled files are always available.