|
| 1 | +# Contributing Guidelines |
| 2 | + |
| 3 | +This is the main repository that provides the `deno` CLI. |
| 4 | + |
| 5 | +If you want to fix a bug or add a new feature to `deno` this is the repository |
| 6 | +to contribute to. |
| 7 | + |
| 8 | +Some systems, including a large part of the Node.js compatibility layer are |
| 9 | +implemented in JavaScript and TypeScript modules. These are a good place to |
| 10 | +start if you are looking to make your first contribution. |
| 11 | + |
| 12 | +[Here](https://node-test-viewer.deno.dev/results/latest) is a list of Node.js |
| 13 | +test cases, including both successful and failing ones. Reviewing these can |
| 14 | +provide valuable insight into how the compatibility layer works in practice, and |
| 15 | +where improvements might be needed. They can also serve as a useful guide for |
| 16 | +identifying areas where contributions are most impactful. |
| 17 | + |
| 18 | +While iterating on such modules it is recommended to include `--features hmr` in |
| 19 | +your `cargo` flags. This is a special development mode where the JS/TS sources |
| 20 | +are not included in the binary but read at runtime, meaning the binary will not |
| 21 | +have to be rebuilt if they are changed. |
| 22 | + |
| 23 | +To use the commands below, you need to first install the necessary tools on your |
| 24 | +system as described [here](#building-from-source). |
| 25 | + |
| 26 | +```sh |
| 27 | +# cargo build |
| 28 | +cargo build --features hmr |
| 29 | + |
| 30 | +# cargo run -- run hello.ts |
| 31 | +cargo run --features hmr -- run hello.ts |
| 32 | + |
| 33 | +# cargo test integration::node_unit_tests::os_test |
| 34 | +cargo test --features hmr integration::node_unit_tests::os_test |
| 35 | +``` |
| 36 | + |
| 37 | +Also remember to reference this feature flag in your editor settings. For VSCode |
| 38 | +users, combine the following into your workspace file: |
| 39 | + |
| 40 | +```jsonc |
| 41 | +{ |
| 42 | + "settings": { |
| 43 | + "rust-analyzer.cargo.features": ["hmr"], |
| 44 | + // Adds support for resolving internal `ext:*` modules |
| 45 | + "deno.importMap": "tools/core_import_map.json" |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +To use a development version of the LSP in VSCode: |
| 51 | + |
| 52 | +1. Install and enable the |
| 53 | + [Deno VSCode extension](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno) |
| 54 | +2. Update your VSCode settings and point `deno.path` to your development binary: |
| 55 | + |
| 56 | +```jsonc |
| 57 | +// .vscode/settings.json |
| 58 | +{ |
| 59 | + "deno.path": "/path/to/your/deno/target/debug/deno" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## Submitting a PR |
| 64 | + |
| 65 | +In addition to the above make sure that: |
| 66 | + |
| 67 | +> To use the commands below, you need to first install the necessary tools on |
| 68 | +> your system as described [here](building_from_source). |
| 69 | +
|
| 70 | +1. `cargo test` passes - this will run full test suite for `deno` including unit |
| 71 | + tests, integration tests and Web Platform Tests |
| 72 | + |
| 73 | +1. Run `./tools/format.js` - this will format all of the code to adhere to the |
| 74 | + consistent style in the repository |
| 75 | + |
| 76 | +1. Run `./tools/lint.js` - this will check Rust and JavaScript code for common |
| 77 | + mistakes and errors using `clippy` (for Rust) and `dlint` (for JavaScript) |
| 78 | + |
| 79 | +## Building from source |
| 80 | + |
| 81 | +Below are instructions on how to build Deno from source. If you just want to use |
| 82 | +Deno you can download a prebuilt executable (more information in the |
| 83 | +[`Getting Started`](/runtime/getting_started/installation/) chapter). |
| 84 | + |
| 85 | +### Cloning the Repository |
| 86 | + |
| 87 | +> Deno uses submodules, so you must remember to clone using |
| 88 | +> `--recurse-submodules`. |
| 89 | +
|
| 90 | +**Linux(Debian)**/**Mac**/**WSL**: |
| 91 | + |
| 92 | +```shell |
| 93 | +git clone --recurse-submodules https://github.com/denoland/deno.git |
| 94 | +``` |
| 95 | + |
| 96 | +**Windows**: |
| 97 | + |
| 98 | +1. [Enable "Developer Mode"](https://www.google.com/search?q=windows+enable+developer+mode) |
| 99 | + (otherwise symlinks would require administrator privileges). |
| 100 | +2. Make sure you are using git version 2.19.2.windows.1 or newer. |
| 101 | +3. Set `core.symlinks=true` before the checkout: |
| 102 | + |
| 103 | + ```shell |
| 104 | + git config --global core.symlinks true |
| 105 | + git clone --recurse-submodules https://github.com/denoland/deno.git |
| 106 | + ``` |
| 107 | + |
| 108 | +### Prerequisites |
| 109 | + |
| 110 | +#### Rust |
| 111 | + |
| 112 | +> Deno requires a specific release of Rust. Deno may not support building on |
| 113 | +> other versions, or on the Rust Nightly Releases. The version of Rust required |
| 114 | +> for a particular release is specified in the `rust-toolchain.toml` file. |
| 115 | +
|
| 116 | +[Update or Install Rust](https://www.rust-lang.org/tools/install). Check that |
| 117 | +Rust installed/updated correctly: |
| 118 | + |
| 119 | +```console |
| 120 | +rustc -V |
| 121 | +cargo -V |
| 122 | +``` |
| 123 | + |
| 124 | +#### Native Compilers and Linkers |
| 125 | + |
| 126 | +Many components of Deno require a native compiler to build optimized native |
| 127 | +functions. |
| 128 | + |
| 129 | +##### Linux(Debian)/WSL |
| 130 | + |
| 131 | +```shell |
| 132 | +wget https://apt.llvm.org/llvm.sh |
| 133 | +chmod +x llvm.sh |
| 134 | +./llvm.sh 17 |
| 135 | +apt install --install-recommends -y cmake libglib2.0-dev |
| 136 | +``` |
| 137 | + |
| 138 | +##### Mac |
| 139 | + |
| 140 | +Mac users must have the _XCode Command Line Tools_ installed. |
| 141 | +([XCode](https://developer.apple.com/xcode/) already includes the _XCode Command |
| 142 | +Line Tools_. Run `xcode-select --install` to install it without XCode.) |
| 143 | + |
| 144 | +[CMake](https://cmake.org/) is also required, but does not ship with the |
| 145 | +_Command Line Tools_. |
| 146 | + |
| 147 | +```console |
| 148 | +brew install cmake |
| 149 | +``` |
| 150 | + |
| 151 | +##### Mac M1/M2 |
| 152 | + |
| 153 | +For Apple aarch64 users `lld` must be installed. |
| 154 | + |
| 155 | +```console |
| 156 | +brew install llvm lld |
| 157 | +# Add /opt/homebrew/opt/llvm/bin/ to $PATH |
| 158 | +``` |
| 159 | + |
| 160 | +##### Windows |
| 161 | + |
| 162 | +1. Get [VS Community 2019](https://www.visualstudio.com/downloads/) with the |
| 163 | + "Desktop development with C++" toolkit and make sure to select the following |
| 164 | + required tools listed below along with all C++ tools. |
| 165 | + |
| 166 | + - Visual C++ tools for CMake |
| 167 | + - Windows 10 SDK (10.0.17763.0) |
| 168 | + - Testing tools core features - Build Tools |
| 169 | + - Visual C++ ATL for x86 and x64 |
| 170 | + - Visual C++ MFC for x86 and x64 |
| 171 | + - C++/CLI support |
| 172 | + - VC++ 2015.3 v14.00 (v140) toolset for desktop |
| 173 | + |
| 174 | +2. Enable "Debugging Tools for Windows". |
| 175 | + - Go to "Control Panel" → "Programs" → "Programs and Features" |
| 176 | + - Select "Windows Software Development Kit - Windows 10" |
| 177 | + - → "Change" → "Change" → Check "Debugging Tools For Windows" → "Change" |
| 178 | + →"Finish". |
| 179 | + - Or use: |
| 180 | + [Debugging Tools for Windows](https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/) |
| 181 | + (Notice: it will download the files, you should install |
| 182 | + `X64 Debuggers And Tools-x64_en-us.msi` file manually.) |
| 183 | + |
| 184 | +#### Protobuf Compiler |
| 185 | + |
| 186 | +Building Deno requires the |
| 187 | +[Protocol Buffers compiler](https://grpc.io/docs/protoc-installation/). |
| 188 | + |
| 189 | +##### Linux(Debian)/WSL |
| 190 | + |
| 191 | +```sh |
| 192 | +apt install -y protobuf-compiler |
| 193 | +protoc --version # Ensure compiler version is 3+ |
| 194 | +``` |
| 195 | + |
| 196 | +##### Mac |
| 197 | + |
| 198 | +```sh |
| 199 | +brew install protobuf |
| 200 | +protoc --version # Ensure compiler version is 3+ |
| 201 | +``` |
| 202 | + |
| 203 | +##### Windows |
| 204 | + |
| 205 | +Windows users can download the latest binary release from |
| 206 | +[GitHub](https://github.com/protocolbuffers/protobuf/releases/latest). |
| 207 | + |
| 208 | +### Python 3 |
| 209 | + |
| 210 | +> Deno requires [Python 3](https://www.python.org/downloads) for running WPT |
| 211 | +> tests. Ensure that a suffix-less `python`/`python.exe` exists in your `PATH` |
| 212 | +> and it refers to Python 3. |
| 213 | +
|
| 214 | +### Building Deno |
| 215 | + |
| 216 | +The easiest way to build Deno is by using a precompiled version of V8. |
| 217 | + |
| 218 | +_For WSL make sure you have sufficient memory allocated in `.wslconfig`. It is |
| 219 | +recommended that you allocate at least 16GB._ |
| 220 | + |
| 221 | +```console |
| 222 | +cargo build -vv |
| 223 | +``` |
| 224 | + |
| 225 | +However, you may also want to build Deno and V8 from source code if you are |
| 226 | +doing lower-level V8 development, or using a platform that does not have |
| 227 | +precompiled versions of V8: |
| 228 | + |
| 229 | +```console |
| 230 | +V8_FROM_SOURCE=1 cargo build -vv |
| 231 | +``` |
| 232 | + |
| 233 | +When building V8 from source, there may be more dependencies. See |
| 234 | +[rusty_v8's README](https://github.com/denoland/rusty_v8) for more details about |
| 235 | +the V8 build. |
| 236 | + |
| 237 | +### Building |
| 238 | + |
| 239 | +Build with Cargo: |
| 240 | + |
| 241 | +```shell |
| 242 | +# Build: |
| 243 | +cargo build -vv |
| 244 | + |
| 245 | +# Build errors? Ensure you have latest main and try building again, or if that doesn't work try: |
| 246 | +cargo clean && cargo build -vv |
| 247 | + |
| 248 | +# Run: |
| 249 | +./target/debug/deno run tests/testdata/run/002_hello.ts |
| 250 | +``` |
| 251 | + |
| 252 | +### Running the Tests |
| 253 | + |
| 254 | +Deno has a comprehensive test suite written in both Rust and TypeScript. The |
| 255 | +Rust tests can be run during the build process using: |
| 256 | + |
| 257 | +```shell |
| 258 | +cargo test -vv |
| 259 | +``` |
| 260 | + |
| 261 | +The TypeScript tests can be run using: |
| 262 | + |
| 263 | +```shell |
| 264 | +# Run all unit/tests: |
| 265 | +target/debug/deno test -A --unstable --lock=tools/deno.lock.json --config tests/config/deno.json tests/unit |
| 266 | + |
| 267 | +# Run a specific test: |
| 268 | +target/debug/deno test -A --unstable --lock=tools/deno.lock.json --config tests/config/deno.json tests/unit/os_test.ts |
| 269 | +``` |
| 270 | + |
| 271 | +### Working with Multiple Crates |
| 272 | + |
| 273 | +If a change-set spans multiple Deno crates, you may want to build multiple |
| 274 | +crates together. It's suggested that you checkout all the required crates next |
| 275 | +to one another. For example: |
| 276 | + |
| 277 | +```shell |
| 278 | +- denoland/ |
| 279 | + - deno/ |
| 280 | + - deno_core/ |
| 281 | + - deno_ast/ |
| 282 | + - ... |
| 283 | +``` |
| 284 | + |
| 285 | +Then you can use |
| 286 | +[Cargo's patch feature](https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html) |
| 287 | +to override the default dependency paths: |
| 288 | + |
| 289 | +```shell |
| 290 | +cargo build --config 'patch.crates-io.deno_ast.path="../deno_ast"' |
| 291 | +``` |
| 292 | + |
| 293 | +If you are working on a change-set for few days, you may prefer to add the patch |
| 294 | +to your `Cargo.toml` file (just make sure you remove this before staging your |
| 295 | +changes): |
| 296 | + |
| 297 | +```sh |
| 298 | +[patch.crates-io] |
| 299 | +deno_ast = { path = "../deno_ast" } |
| 300 | +``` |
| 301 | +
|
| 302 | +This will build the `deno_ast` crate from the local path and link against that |
| 303 | +version instead of fetching it from `crates.io`. |
| 304 | +
|
| 305 | +**Note**: It's important that the version of the dependencies in the |
| 306 | +`Cargo.toml` match the version of the dependencies you have on disk. |
| 307 | +
|
| 308 | +Use `cargo search <dependency_name>` to inspect the versions. |
0 commit comments