https://github.com/nrwl/typescript-template
Template repository containing an Nx Workspace with a TypeScript Library. It uses tsc for building and Vitest for unit testing.
https://github.com/nrwl/typescript-template
Last synced: 3 months ago
JSON representation
Template repository containing an Nx Workspace with a TypeScript Library. It uses tsc for building and Vitest for unit testing.
- Host: GitHub
- URL: https://github.com/nrwl/typescript-template
- Owner: nrwl
- Created: 2025-09-08T09:50:47.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-09-19T12:49:08.000Z (4 months ago)
- Last Synced: 2025-09-19T14:55:46.272Z (4 months ago)
- Language: TypeScript
- Size: 237 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nx TypeScript Repository
โจ A repository showcasing key [Nx](https://nx.dev) features for TypeScript monorepos โจ
## ๐ฆ Project Overview
This repository demonstrates a production-ready TypeScript monorepo with:
- **3 Publishable Packages** - Ready for NPM publishing
- `@org/strings` - String manipulation utilities
- `@org/async` - Async utility functions with retry logic
- `@org/colors` - Color conversion and manipulation utilities
- **1 Internal Library**
- `@org/utils` - Shared utilities (private, not published)
## ๐ Quick Start
```bash
# Clone the repository
git clone
cd typescript-template
# Install dependencies
npm install
# Build all packages
npx nx run-many -t build
# Run tests
npx nx run-many -t test
# Lint all projects
npx nx run-many -t lint
# Run everything in parallel
npx nx run-many -t lint test build --parallel=3
# Visualize the project graph
npx nx graph
```
## โญ Featured Nx Capabilities
This repository showcases several powerful Nx features:
### 1. ๐ Module Boundaries
Enforces architectural constraints using tags. Each package has specific dependencies it can use:
- `scope:shared` (utils) - Can be used by all packages
- `scope:strings` - Can only depend on shared utilities
- `scope:async` - Can only depend on shared utilities
- `scope:colors` - Can only depend on shared utilities
**Try it out:**
```bash
# See the current project graph and boundaries
npx nx graph
# View a specific project's details
npx nx show project strings --web
```
[Learn more about module boundaries โ](https://nx.dev/features/enforce-module-boundaries)
### 2. ๐ ๏ธ Custom Run Commands
Packages can define custom commands beyond standard build/test/lint:
```bash
# Run the custom build-base command for strings package
npx nx run strings:build-base
# See all available targets for a project
npx nx show project strings
```
[Learn more about custom run commands โ](https://nx.dev/concepts/executors-and-configurations)
### 3. ๐ง Self-Healing CI
The CI pipeline includes `nx fix-ci` which automatically identifies and suggests fixes for common issues. To test it, you can make a change to `async-retry.spec.ts` so that it fails, and create a PR.
```bash
# Run tests and see the failure
npx nx test async
# In CI, this command provides automated fixes
npx nx fix-ci
```
[Learn more about self-healing CI โ](https://nx.dev/ci/features/self-healing-ci)
### 4. ๐ฆ Package Publishing
Manage releases and publishing with Nx Release:
```bash
# Dry run to see what would be published
npx nx release --dry-run
# Version and release packages
npx nx release
# Publish only specific packages
npx nx release publish --projects=strings,colors
```
[Learn more about Nx Release โ](https://nx.dev/features/manage-releases)
## ๐ Project Structure
```
โโโ packages/
โ โโโ strings/ [scope:strings] - String utilities (publishable)
โ โโโ async/ [scope:async] - Async utilities (publishable)
โ โโโ colors/ [scope:colors] - Color utilities (publishable)
โ โโโ utils/ [scope:shared] - Shared utilities (private)
โโโ nx.json - Nx configuration
โโโ tsconfig.json - TypeScript configuration
โโโ eslint.config.mjs - ESLint with module boundary rules
```
## ๐ท๏ธ Understanding Tags
This repository uses tags to enforce module boundaries:
| Package | Tag | Can Import From |
| -------------- | --------------- | ---------------------- |
| `@org/utils` | `scope:shared` | Nothing (base library) |
| `@org/strings` | `scope:strings` | `scope:shared` |
| `@org/async` | `scope:async` | `scope:shared` |
| `@org/colors` | `scope:colors` | `scope:shared` |
The ESLint configuration enforces these boundaries, preventing circular dependencies and maintaining clean architecture.
## ๐งช Testing Module Boundaries
To see module boundary enforcement in action:
1. Try importing `@org/colors` into `@org/strings`
2. Run `npx nx lint strings`
3. You'll see an error about violating module boundaries
## ๐ Useful Commands
```bash
# Project exploration
npx nx graph # Interactive dependency graph
npx nx list # List installed plugins
npx nx show project strings --web # View project details
# Development
npx nx build strings # Build a specific package
npx nx test async # Test a specific package
npx nx lint colors # Lint a specific package
# Running multiple tasks
npx nx run-many -t build # Build all projects
npx nx run-many -t test --parallel=3 # Test in parallel
npx nx run-many -t lint test build # Run multiple targets
# Affected commands (great for CI)
npx nx affected -t build # Build only affected projects
npx nx affected -t test # Test only affected projects
# Release management
npx nx release --dry-run # Preview release changes
npx nx release # Create a new release
```
## Nx Cloud
Nx Cloud ensures a [fast and scalable CI](https://nx.dev/ci/intro/why-nx-cloud?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) pipeline. It includes features such as:
- [Remote caching](https://nx.dev/ci/features/remote-cache?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task distribution across multiple machines](https://nx.dev/ci/features/distribute-task-execution?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Automated e2e test splitting](https://nx.dev/ci/features/split-e2e-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task flakiness detection and rerunning](https://nx.dev/ci/features/flaky-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
## ๐ Learn More
- [Nx Documentation](https://nx.dev)
- [Module Boundaries](https://nx.dev/features/enforce-module-boundaries)
- [Custom Commands](https://nx.dev/concepts/executors-and-configurations)
- [Self-Healing CI](https://nx.dev/ci/features/self-healing-ci)
- [Releasing Packages](https://nx.dev/features/manage-releases)
- [Nx Cloud](https://nx.dev/ci/intro/why-nx-cloud)
## ๐ฌ Community
Join the Nx community:
- [Discord](https://go.nx.dev/community)
- [X (Twitter)](https://twitter.com/nxdevtools)
- [LinkedIn](https://www.linkedin.com/company/nrwl)
- [YouTube](https://www.youtube.com/@nxdevtools)
- [Blog](https://nx.dev/blog)