CLAUDE.md
CLAUDE.mdCLAUDE.mdroot
Quality
89/100
Scores the file, not the repository.Length
1,703 words
63 headings · 16 code blocksRepository
108k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Deno Development Guide23## Table of Contents45- [Git workflow](#git-workflow)6- [High Level Overview](#high-level-overview)7- [Quick Start](#quick-start)8- [Commands](#commands)9- [Testing](#testing)10- [Development Workflows](#development-workflows)11- [Debugging](#debugging)12- [Codebase Navigation](#codebase-navigation)13- [Troubleshooting](#troubleshooting)1415## Git workflow1617Deno uses a GH based standard git workflow. The main branch is `main`. All18development happens in feature branches, which are then merged into `main` via19pull requests.2021When the feature is finished and ready to for review, follow these steps:2223- Create a new git branch, if you haven't already, with a descriptive name24 (e.g., `feature/new-cli-command` or `fix/bug-in-worker-threads`).25- Commit your changes with clear and descriptive commit messages.26- Push your branch to the remote repository.27- Open a pull request (PR) against the `main` branch on GitHub.28- Before committing, make sure `tools/format.js` is run to format your code29- Before committing, if only non-Rust was changed, make sure to run30 `tools/lint.js --js` and fix any lint errors before committing31- If you changed Rust code, make sure to run `tools/lint.js` and fix any lint32 errors before committing33- In the PR description, provide a clear summary of the changes you made, why34 they were necessary, and any relevant context or links to related issues.35- When pushing updates to the PR, make sure to never force push. Create as many36 commits as you need, all of them get squashed when the PR is merged, so there37 is no need to rewrite history. This also allows reviewers to see the38 incremental changes you made in response to feedback.39- Keep your changes minimal, don't do drive-by changes in a PR. If you need to40 make a change that is not directly related to the PR, create a separate PR for41 it. This keeps the review process focused and efficient.4243## High Level Overview4445The user visible interface and high level integration is in the `deno` crate46(located in `./cli`).4748This includes flag parsing, subcommands, package management tooling, etc. Flag49parsing is in `cli/args/flags.rs`. Tools are in `cli/tools/<tool>`.5051The `deno_runtime` crate (`./runtime`) assembles the JavaScript runtime,52including all "extensions" (native functionality exposed to JavaScript). The53extensions themselves are in the `ext/` directory, and provide system access to54JavaScript – for instance filesystem operations and networking.5556### Key Directories5758- `cli/` - User-facing CLI implementation, subcommands, and tools59- `runtime/` - JavaScript runtime assembly and integration60- `ext/` - Extensions providing native functionality to JS (fs, net, etc.)61- `tests/specs/` - Integration tests (spec tests)62- `tests/unit/` - Unit tests63- `tests/testdata/` - Test fixtures and data files6465## Quick Start6667Before building, install the required prerequisites (Rust, native compilers,68cmake, protobuf, etc.) and clone with `--recurse-submodules` as described in69[`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md#building-from-source).7071### Building Deno7273To compile after making changes:7475```bash76cargo build77```7879For faster iteration during development (less optimization):8081```bash82cargo build --bin deno83```8485Execute your development build:8687```bash88./target/debug/deno eval 'console.log("Hello from dev build")'89```9091### Running with your changes9293```bash94# Run a local file95./target/debug/deno run path/to/file.ts9697# Run with permissions98./target/debug/deno run --allow-net --allow-read script.ts99100# Run the REPL101./target/debug/deno102```103104## Commands105106### Compilation and Checks107108```bash109# Check for compilation errors (fast, no binary output)110cargo check111112# Check specific package113cargo check -p deno_runtime114115# Build release version (slow, optimized)116cargo build --release117```118119### Code Quality120121```bash122# Lint the code123./tools/lint.js124125# Format the code126./tools/format.js127128# Both lint and format129./tools/format.js && ./tools/lint.js130```131132## Testing133134### Running Tests135136```bash137# Run all tests (this takes a while)138cargo test139140# Filter tests by name141cargo test <nameOfTest>142143# Run tests in a specific package144cargo test -p deno_core145146# Run just the CLI integration tests147cargo test --bin deno148149# Run spec tests only150cargo test specs151152# Run a specific spec test153cargo test spec::test_name154```155156### Unit Tests (`tests/unit/`)157158JavaScript/TypeScript unit tests live in `tests/unit/` as `*_test.ts` files. Run159them via `cargo test`:160161```bash162# Run all unit tests in a specific file163cargo test unit::webcrypto_test164165# Run all unit tests166cargo test unit::167168# Run Node.js compatibility unit tests (tests/unit_node/)169cargo test unit_node::crypto_test170171# Run all Node.js compat unit tests172cargo test unit_node::173```174175Do NOT run these directly with `./target/debug/deno test` — they depend on the176cargo test harness for correct setup.177178### Test Organization179180- **Spec tests** (`tests/specs/`) - Main integration tests, CLI command181 execution and output validation182- **Unit tests** (`tests/unit/`) - JavaScript/TypeScript unit tests for runtime183 APIs184- **Integration tests** (`tests/integration/`) - Additional integration tests185- **WPT** (`tests/wpt/`) - Web Platform Tests for web standards compliance186187## "spec" tests188189The main form of integration test in deno is the "spec" test. These tests can be190found in `tests/specs`. The idea is that you have a `__test__.jsonc` file that191lays out one or more tests, where a test is a CLI command to execute and the192output is captured and asserted against.193194The name of the test comes from the directory the `__test__.jsonc` appears in.195196### Creating a New Spec Test1971981. Create a directory in `tests/specs/` with a descriptive name1992. Add a `__test__.jsonc` file describing your test steps2003. Add any input files needed for the test2014. Add `.out` files for expected output (or inline in `__test__.jsonc`)202203Example:204205```206tests/specs/my_feature/207 __test__.jsonc208 main.ts209 expected.out210```211212### `__test__.jsonc` schema213214The schema for `__test__.jsonc` can be found in `tests/specs/schema.json`.215216Example test structure:217218```jsonc219{220 "tests": {221 "basic_case": {222 "args": "run main.ts",223 "output": "expected.out"224 },225 "with_flag": {226 "steps": [227 {228 "args": "run --allow-net main.ts",229 "output": "[WILDCARD]success[WILDCARD]"230 }231 ]232 }233 }234}235```236237### Output assertions238239The expected output can be inline in a `__test__.jsonc` file or in a file ending240with `.out`. For a given test step, the `output` field tells you either the241inline expectation or the name of the file containing the **expectation**. The242expectation uses a small matching language to support wildcards and things like243that. A literal character means you expect that exact character, so `Foo bar`244would expect the output to be "Foo bar". Then there are things with special245meanings:246247- `[WILDCARD]` : matches 0 or more of any character, like `.*` in regex. this248 can cross newlines249- `[WILDLINE]` : matches 0 or more of any character, ending at the end of a line250- `[WILDCHAR]` - match the next character251- `[WILDCHARS(5)]` - match any of the next 5 characters252- `[UNORDERED_START]` followed by many lines then `[UNORDERED_END]` will match253 the lines in any order (useful for non-deterministic output)254- `[# example]` - line comments start with `[#` and end with `]`255256Example `.out` file:257258```259Check file://[WILDCARD]/main.ts260[WILDCARD]261Successfully compiled [WILDLINE]262```263264## Development Workflows265266### Adding a New CLI Subcommand2672681. Define the command structure in `cli/args/flags.rs`2692. Add the command handler in `cli/tools/<command_name>.rs` or270 `cli/tools/<command_name>/mod.rs`2713. Wire it up in `cli/main.rs`2724. Add spec tests in `tests/specs/<command_name>/`273274Example files to reference:275276- Simple command: `cli/tools/fmt.rs`277- Complex command: `cli/tools/test/`278279### Modifying or Adding an Extension2802811. Navigate to `ext/<extension_name>/` (e.g., `ext/fs/`, `ext/net/`)2822. Rust code provides the ops (operations) exposed to JavaScript2833. JavaScript code in the extension provides the higher-level APIs2844. Update `runtime/worker.rs` to register the extension if new2855. Add tests in the extension's directory286287### Updating Dependencies288289```bash290# Update Cargo dependencies291cargo update292293# Update to latest compatible versions294cargo upgrade # Requires cargo-edit: cargo install cargo-edit295296# Check for outdated dependencies297cargo outdated # Requires cargo-outdated298```299300## Debugging301302### Debugging Rust Code303304Use `lldb` directly:305306```bash307lldb ./target/debug/deno308(lldb) run eval 'console.log("test")'309```310311### Debugging JavaScript Runtime Issues312313Use println debugging.314315### Verbose Logging316317```bash318# Set Rust log level319DENO_LOG=debug ./target/debug/deno run script.ts320321# Specific module logging322DENO_LOG=deno_core=debug ./target/debug/deno run script.ts323```324325### Debug Prints326327In Rust code:328329```rust330eprintln!("Debug: {:?}", some_variable);331dbg!(some_variable);332```333334In JavaScript/TypeScript code:335336```javascript337console.log("Debug:", value);338```339340## Codebase Navigation341342### Key Files to Understand First3433441. `cli/main.rs` - Entry point, command routing3452. `cli/args/flags.rs` - CLI flag parsing and structure3463. `runtime/worker.rs` - Worker/runtime initialization3474. `runtime/permissions.rs` - Permission system3485. `cli/module_loader.rs` - Module loading and resolution349350### Common Patterns351352- **Ops** - Rust functions exposed to JavaScript (in `ext/` directories)353- **Extensions** - Collections of ops and JS code providing functionality354- **Workers** - JavaScript execution contexts (main worker, web workers)355- **Resources** - Managed objects passed between Rust and JS (files, sockets,356 etc.)357358### Finding Examples359360- Need to add a CLI flag? Look at similar commands in `cli/args/flags.rs`361- Need to add an op? Look at ops in relevant `ext/` directory (e.g.,362 `ext/fs/lib.rs`)363- Need to add a tool? Reference existing tools in `cli/tools/`364365## Troubleshooting366367### Build Failures368369**Error: linking with `cc` failed**370371- Make sure you have the required system dependencies372- On macOS: `xcode-select --install`373- On Linux: Install `build-essential` or equivalent374375**Error: failed to download dependencies**376377- Check internet connection378- Try `cargo clean` then rebuild379- Check if behind a proxy, configure cargo accordingly380381For other build failures (missing `cmake`, `stdarg.h`, etc.), see the full382prerequisites in383[`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md#building-from-source).384385### Test Failures386387**Spec test failures**388389- Check the test output carefully for differences390- Update `.out` files if output format changed intentionally391- Use `[WILDCARD]` for non-deterministic parts of output392393**Flaky tests**394395- Add `[UNORDERED_START]`/`[UNORDERED_END]` for order-independent output396- Check for race conditions in test code397- May need to increase timeouts or add retries398399### Permission Issues400401**Tests failing with permission errors**402403- Ensure test files have correct permissions404- Check that test setup properly grants necessary permissions405406### Performance Issues407408**Slow compile times**409410- Use `cargo check` instead of `cargo build` when possible411- Use `--bin deno` to build only the main binary412- Use `sccache` or `mold` linker for faster builds413- Consider using `cargo-watch` for incremental builds414415### Runtime Debugging416417**Crashes or panics**418419- Run with `RUST_BACKTRACE=1` for full backtrace420- Use `RUST_BACKTRACE=full` for even more detail421- Check for unwrap() calls that might panic422423**Unexpected behavior**424425- Add debug prints liberally426- Check permission grants - many features require explicit permissions427428### Getting Help429430- Check existing issues on GitHub431- Look at recent PRs for similar changes432- Review the Discord community for discussions433- When in doubt, ask! The maintainers are helpful434
Also in denoland/deno
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| denoland/deno.github/copilot-instructions.md · 108k | Copilot instructions | buildtestlint-formatstyle+7 | 88/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| bagisto/bagistoCLAUDE.md · 28k | CLAUDE.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| livewire/livewireCLAUDE.md · 24k | CLAUDE.md | setupbuildteststyle+4 | 100/100 | 3 days ago | |
| microsoft/playwrightCLAUDE.md · 94k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| dotCMS/corecore-web/CLAUDE.md · 949 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| nimbalyst/nimbalystpackages/android/CLAUDE.md · 1.4k | CLAUDE.md | setupbuildstylearch+2 | 100/100 | 3 days ago | |
| filamentphp/filamentCLAUDE.md · 32k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| Adit-Jain-srm/NightmareNetCLAUDE.md · 45 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 3 days ago | |
| dotCMS/coreCLAUDE.md · 949 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | today |
