> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_swc//swc:repositories.bzl

> Bazel rules_swc repository rules for fetching the SWC toolchain, including swc_register_toolchains and swc_version_from for syncing JavaScript SWC versions.

<Callout icon="book">
  Documentation for [@aspect\_rules\_swc@v2.6.1](https://registry.bazel.build/modules/aspect_rules_swc/2.6.1) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_swc/blob/v2.6.1/swc/repositories.bzl)
</Callout>

Repository rules for fetching the swc toolchain.

For typical usage, see the snippets provided in the rules\_swc release notes.

### Version matching

To keep the swc version in sync with non-Bazel tooling, use `swc_version_from`.

Currently this only works when a single, pinned version appears, see:
[https://github.com/aspect-build/rules\_ts/issues/308](https://github.com/aspect-build/rules_ts/issues/308)

For example, `package.json`:

```json theme={null}
{
  "devDependencies": {
    "@swc/core": "1.3.37"
  }
}
```

Allows this in `WORKSPACE`:

```python theme={null}
swc_register_toolchains(
    name = "swc",
    swc_version_from = "//:package.json",
)
```

## Function: `swc_register_toolchains`

Convenience macro for users which does typical setup.

* create a repository for each built-in platform like "swc\_linux\_amd64"
* create a repository exposing toolchains for each platform like "swc\_platforms"
* register a toolchain pointing at each platform
  Users can avoid this macro and do these steps themselves, if they want more control.

### Parameters

<ParamField body="name" type="unknown" required>
  base name for all created repos; we recommend `swc`
</ParamField>

<ParamField body="swc_version" type="unknown" default={`None`}>
  version of the swc project, from [https://github.com/swc-project/swc/releases](https://github.com/swc-project/swc/releases)
  Exactly one of `swc_version` or `swc_version_from` must be set.
</ParamField>

<ParamField body="swc_version_from" type="unknown" default={`None`}>
  label of a json file which declares an `@swc/core` version.

  This may be a `package.json` file, with "@swc/core" in the dependencies or
  devDependencies property, and the version exactly specified.

  With rules\_js v1.32.0 or greater, it may also be a `resolved.json` file
  produced by `npm_translate_lock`, such as
  `@npm//path/to/linked:@swc/core/resolved.json`

  Exactly one of `swc_version` or `swc_version_from` must be set.
</ParamField>

<ParamField body="platforms" type="unknown" default={`["darwin-arm64", "darwin-x64", "linux-arm64-gnu", "linux-arm64-musl", "linux-x64-gnu", "linux-x64-musl", "win32-arm64-msvc", "win32-ia32-msvc", "win32-x64-msvc"]`}>
  list of platforms (must be a key in PLATFORMS) to register toolchains for.
  Defaults to all platforms.
</ParamField>

<ParamField body="register" type="unknown" default={`True`}>
  whether to call through to native.register\_toolchains.
  Should be True for WORKSPACE users, but false when used under bzlmod extension
</ParamField>

<ParamField body="kwargs" type="unknown">
  passed to each swc\_repositories call
</ParamField>

## Repository rule: `swc_repositories`

Fetch external dependencies needed to run the SWC cli

### Attributes

<ParamField body="name" type="name" required>
  A unique name for this repository.
</ParamField>

<ParamField body="repo_mapping" type="dictionary: String → String">
  In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

  For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).

  This attribute is *not* supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function).
</ParamField>

<ParamField body="swc_version" type="string" default={`""`}>
  Explicit version. If provided, the package.json is not read.
</ParamField>

<ParamField body="swc_version_from" type="label" default={`None`}>
  Location of package.json which has a version for @swc/core.
</ParamField>

<ParamField body="platform" type="string" required />

<ParamField body="integrity_hashes" type="dictionary: String → String" default={`{}`}>
  A mapping from platform to integrity hash.
</ParamField>
