This document details the physical organization of the Svelte repository as a pnpm-based monorepo, including workspace configuration, package layout, dependency management, and development infrastructure. For information about the internal architecture of the core svelte package itself, see Core Package Architecture. For build and release workflows, see CI/CD and Release Process.
The Svelte repository is structured as a monorepo containing multiple packages, documentation sites, and development tooling managed through pnpm workspaces. The root package.json defines workspace-level scripts and shared development dependencies, while individual packages maintain their own dependencies and build configurations.
Sources: package.json1-56 pnpm-lock.yaml1-68
The monorepo is configured at package.json1-56 with the following key characteristics:
| Property | Value | Purpose |
|---|---|---|
name | "svelte-monorepo" | Root package identifier |
private | true | Prevents accidental publication |
type | "module" | ES modules by default |
packageManager | "[email protected]" | Enforces pnpm version |
engines.pnpm | ">=9.0.0" | Minimum pnpm version requirement |
The workspace uses pnpm's workspace protocol to manage internal package dependencies. This is evident in the lockfile structure at pnpm-lock.yaml7-68 which defines importers for the root, core packages, and playgrounds.
Diagram: Workspace Structure and Importers
Sources: package.json1-10 pnpm-lock.yaml1-68
The monorepo organizes code into distinct categories:
Diagram: Package and Infrastructure Layout
The primary package is packages/svelte/, which contains the Svelte compiler and runtime. The lockfile at pnpm-lock.yaml69-164 shows its dependencies including:
acorn, @sveltejs/acorn-typescript, magic-string, esrap, zimmerframe@jridgewell/sourcemap-codec, @types/estree, devalue, esm-env@types/trusted-types, @types/aria-queryThe svelte package is referenced from other workspace packages using the workspace protocol, as seen at pnpm-lock.yaml53-55:
The playgrounds/sandbox/ package at pnpm-lock.yaml166-191 provides a development environment with:
@sveltejs/vite-plugin-svelte for Vite integrationvite for the development serverpolka for simple HTTP servervite-plugin-inspect and vite-plugin-devtools-jsonSources: pnpm-lock.yaml69-164 pnpm-lock.yaml166-191
The monorepo uses a centralized development dependency strategy with shared tooling at the root level:
Diagram: Dependency Distribution Strategy
The root package.json at package.json28-47 defines shared development dependencies:
| Category | Dependencies | Purpose |
|---|---|---|
| Version Management | @changesets/cli, @svitejs/changesets-changelog-github-compact | Automated versioning and changelog |
| Code Quality | eslint, @eslint/js, eslint-plugin-lube, eslint-plugin-svelte, @sveltejs/eslint-config | Linting and style enforcement |
| Formatting | prettier, prettier-plugin-svelte | Code formatting |
| Testing | vitest, @vitest/coverage-v8, jsdom, playwright | Unit, integration, and E2E testing |
| Type Checking | typescript, typescript-eslint, @types/node, @types/picomatch | TypeScript support |
| Benchmarking | v8-natives | Performance measurement |
The workspace enforces specific peer dependency versions at package.json49-55:
This configuration ensures ESLint version 10 is used consistently across all packages.
Sources: package.json28-55 pnpm-lock.yaml10-67
The root package.json provides workspace-level scripts at package.json16-27:
Diagram: Development Workflow Scripts
Build Scripts:
build: Uses pnpm -r --filter=./packages/* to recursively build all packages under packages/ directorycheck: First builds the core svelte package, then runs all workspace checksQuality Scripts:
lint: Runs both ESLint and Prettier in check modeformat: Applies Prettier formatting to the entire codebaseChangeset Scripts:
changeset:version: Runs changeset version then executes pnpm -r generate:version and stages all changeschangeset:publish: Publishes versioned packages to npm registryBenchmarking Scripts:
bench: Runs benchmarks in production mode with Node native syntax accessbench:compare: Compares benchmark results between runsbench:debug: Runs benchmarks with Node inspector for debuggingSources: package.json16-27
The monorepo uses Changesets for version management and changelog generation. The configuration at pnpm-lock.yaml12-13 shows:
The changeset:version script at package.json22 includes a custom step that runs pnpm -r generate:version after version bumping, allowing packages to generate version-specific files.
The .gitignore at .gitignore1-27 defines excluded content:
| Pattern | Purpose |
|---|---|
node_modules/ | Dependencies |
coverage/, *.lcov | Test coverage reports |
.eslintcache | ESLint cache files |
.env, .env.test | Environment variables |
.vercel | Deployment artifacts |
tmp | Temporary files |
benchmarking/compare/.results | Benchmark results |
This configuration ensures build artifacts, dependencies, and local development files are not tracked in version control.
The repository enforces pnpm usage through multiple mechanisms:
"packageManager": "[email protected]""pnpm": ">=9.0.0"This prevents developers from accidentally using npm or yarn, which would generate different lockfiles and potentially cause dependency resolution issues.
Sources: package.json8-11 pnpm-lock.yaml1-6 .gitignore1-27
The following diagram shows how workspace packages reference each other:
Diagram: Workspace Package Dependencies
The workspace protocol ensures that:
playgrounds/sandbox always uses the local development version of svelte via workspace:* at pnpm-lock.yaml177-179svelte via workspace:^ at pnpm-lock.yaml53-55Sources: pnpm-lock.yaml53-55 pnpm-lock.yaml69-164 pnpm-lock.yaml177-179
Refresh this wiki