Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/rspack-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## [1.0.0] - 2025-01-01

### Added

- Initial release of @codecov/rspack-plugin
- Bundle analysis support for Rspack projects
- Support for uploading bundle analysis to Codecov
- Support for dry run mode
- Support for GitHub OIDC authentication
- Support for tokenless uploads for public repositories
21 changes: 21 additions & 0 deletions packages/rspack-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Codecov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
150 changes: 150 additions & 0 deletions packages/rspack-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<p align="center">
<a href="https://about.codecov.io" target="_blank">
<img src="https://about.codecov.io/wp-content/themes/codecov/assets/brand/sentry-cobranding/logos/codecov-by-sentry-logo.svg" alt="Codecov by Sentry logo" width="280" height="84">
</a>
</p>

# Codecov Rspack Plugin

A Rspack plugin that provides bundle analysis support for Codecov.

> [!NOTE]
> The plugin does not support code coverage, see our [docs](https://docs.codecov.com/docs/quick-start) to set up coverage today!

## Installation

Using npm:

```bash
npm install @codecov/rspack-plugin --save-dev
```

Using yarn:

```bash
yarn add @codecov/rspack-plugin --dev
```

Using pnpm:

```bash
pnpm add @codecov/rspack-plugin --save-dev
```

## Public Repo Example - GitHub Actions

This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example).

```js
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");

module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
}),
],
};
```

## Public Repo Example - Non-GitHub Actions

This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`.

```js
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");

module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
uploadOverrides: {
branch: "<branch value>",
},
}),
],
};
```

## Private Repo Example

This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov.

```js
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");

module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
}),
],
};
```

## GitHub OIDC

For GitHub Actions users, you can use OIDC instead of a upload token. This is the recommended approach for GitHub Actions.

```js
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");

module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
oidc: {
useGitHubOIDC: true,
},
}),
],
};
```

See the [full documentation](https://docs.codecov.com/docs/bundle-analysis) for more details.
44 changes: 44 additions & 0 deletions packages/rspack-plugin/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineBuildConfig } from "unbuild";
import { codecovRollupPlugin } from "codecovProdRollupPlugin";
import packageJson from "./package.json";

export default defineBuildConfig({
entries: ["./src/index"],
outDir: "dist",
declaration: "compatible",
sourcemap: true,
rollup: {
dts: {
compilerOptions: {
removeComments: false,
},
},
emitCJS: true,
replace: {
preventAssignment: true,
values: {
__PACKAGE_VERSION__: JSON.stringify(packageJson.version),
__PACKAGE_NAME__: JSON.stringify(packageJson.name),
},
},
},
hooks: {
"rollup:options": (_ctx, opts) => {
if (process.env.PLUGIN_CODECOV_TOKEN && Array.isArray(opts.plugins)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-floating-promises
opts.plugins = [
// @ts-expect-error - using rollup plugin
...opts.plugins,
// @ts-expect-error - using rollup plugin
codecovRollupPlugin({
enableBundleAnalysis:
typeof process.env.PLUGIN_CODECOV_TOKEN === "string",
bundleName: packageJson.name,
uploadToken: process.env.PLUGIN_CODECOV_TOKEN,
apiUrl: process.env.PLUGIN_CODECOV_API_URL,
}),
];
}
},
},
});
76 changes: 76 additions & 0 deletions packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@codecov/rspack-plugin",
"version": "1.0.0",
"description": "Official Codecov Rspack plugin",
"author": "Codecov",
"license": "MIT",
"keywords": [
"Codecov",
"Rspack",
"bundler",
"plugin"
],
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"type-check": "tsc --noEmit",
"build": "unbuild",
"dev": "unbuild --stub && node --watch-path=src dist/index.mjs",
"clean": "rm -rf dist node_modules",
"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "pnpm lint --fix",
"format": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --write",
"format:check": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
"test:unit": "vitest run",
"test:unit:watch": "vitest watch",
"test:unit:ci": "vitest --coverage --reporter=junit --outputFile=./rspack-plugin.junit.xml run",
"test:unit:update": "vitest -u run",
"generate:typedoc": "typedoc --options ./typedoc.json"
},
"dependencies": {
"@codecov/bundler-plugin-core": "workspace:^"
},
"devDependencies": {
"@rspack/core": "^1.0.0",
"@rollup/plugin-replace": "^5.0.5",
"@types/node": "^20.10.0",
"@vitest/coverage-v8": "^2.1.9",
"codecovProdRollupPlugin": "npm:@codecov/[email protected]",
"ts-node": "^10.9.2",
"typedoc": "^0.27.5",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vitest": "^2.1.9"
},
"peerDependencies": {
"@rspack/core": "^0.5.0 || ^1.0.0"
},
"peerDependenciesMeta": {
"@rspack/core": {
"optional": true
}
},
"volta": {
"extends": "../../package.json"
},
"engines": {
"node": ">=18.0.0"
}
}
Loading