- Clone the repo
- Install dependencies
- Architecture
- Create a new plugin
- Tests
- Integrity
- Formatting, Linting and Compiling
- Open Source compliance
- Documentation
- Publish a new public version
- Publish a new dev version
- Work with Datadog's Frontend monorepo
- Misc. Tooling
git clone [email protected]:DataDog/build-plugins.gitUse Volta (recommended)
brew install volta
volta setup
# From the repo's root.
volta install node yarnOr install Yarn yourself
brew install yarnNote
Do not worry about the version, it's dealt with by the repo.
Ensure dependencies are up to date in the repository.
# From the repo's root.
yarnWe have two types of workspaces:
| Name | Location | Description |
|---|---|---|
@datadog/esbuild-plugin |
./packages/published/esbuild-plugin |
The esbuild plugin. |
@datadog/rspack-plugin |
./packages/published/rspack-plugin |
The rspack plugin. |
@datadog/rollup-plugin |
./packages/published/rollup-plugin |
The rollup plugin. |
@datadog/vite-plugin |
./packages/published/vite-plugin |
The vite plugin. |
@datadog/webpack-plugin |
./packages/published/webpack-plugin |
The webpack plugin. |
| Name | Location | Description |
|---|---|---|
@dd/assets |
./packages/assets |
Only the static files used as assets. |
@dd/core |
./packages/core |
The core package that contains the shared code between the plugins. |
@dd/factory |
./packages/factory |
The factory package that contains the logic to aggregate all the plugins together. |
@dd/*-plugin |
./packages/plugins/* |
The actual features of our bundler plugins. |
@dd/tests |
./packages/tests |
The tests package that contains the e2e tests and the tooling for testing. |
@dd/tools |
./packages/tools |
The tools package that contains the CLI and some tooling we use locally for development. |
Here's a diagram to help you understand the structure:
---
title: Datadog Build Plugins Design
---
stateDiagram-v2
published: Published Packages
productPlugins: Product Plugins
errorTrackingPlugin: @dd/error-tracking-plugin
rumPlugin: @dd/rum-plugin
metricsPlugin: @dd/metrics-plugin
esbuildplugin: @datadog/esbuild-plugin
viteplugin: @datadog/vite-plugin
rspackplugin: @datadog/rspack-plugin
rollupplugin: @datadog/rollup-plugin
webpackplugin: @datadog/webpack-plugin
tools: @dd/tools
factory: @dd/factory
core: @dd/core
types: Shared Types
sharedHelpers: Shared Helpers
sharedConstants: Shared Constants
ahelpers: Aggregated Helpers
atypes: Aggregated Types
aplugins: Aggregated List of Plugins
globalContext: Creation of the Global Context
cli: Internal CLIs
helpers: Tooling helpers
internalPlugins: Internal Plugins
analyticsPlugin: @dd/internal-analytics-plugin
buildReportPlugin: @dd/internal-build-report-plugin
bundlerReportPlugin: @dd/internal-bundler-report-plugin
customHooksPlugin: @dd/internal-custom-hooks-plugin
gitPlugin: @dd/internal-git-plugin
injectionPlugin: @dd/internal-injection-plugin
state internalPlugins {
analyticsPlugin
buildReportPlugin
bundlerReportPlugin
customHooksPlugin
gitPlugin
injectionPlugin
}
state core {
sharedHelpers
sharedConstants
types
}
state published {
esbuildplugin
viteplugin
rspackplugin
rollupplugin
webpackplugin
}
state productPlugins {
errorTrackingPlugin
rumPlugin
metricsPlugin
}
state factory {
ahelpers
atypes
aplugins
globalContext
}
state tools {
cli
helpers
}
internalPlugins --> factory
productPlugins --> factory: CONFIG_KEY<br/>helpers<br/>types<br/>getPlugins()
core --> tools
core --> factory
core --> internalPlugins
core --> productPlugins
factory --> internalPlugins: Global Context
factory --> productPlugins: Global Context
factory --> published: Unplugin Factory
published --> npm: types<br/>helpers<br/>datadogBundlerPlugin
We have a small wizard that will help you create a new plugin. Bootstrapping all the files you'll need to start coding.
yarn cli create-pluginThen learn more about what you can use from the ecosystem.
Important
If you're modifying a behavior or adding a new feature, update/add the required tests to your PR.
We have a command to check the integrity of the files in the repository. To ensure everything is in order and follow our different compliance rules. This is also checked in the CI.
You can run this command and commit the changes if needed.
yarn cli integrityIt will:
- update all the
.mdfiles.- generate and update the Table of Contents delimited by
<!-- #toc -->. - update the root README with the list of plugins and their configuration.
- update the Custom Hooks' README with the list of hooks from the other plugins.
- verify that all internal links are valid.
- generate and update the Table of Contents delimited by
- update the necessary
.tsandpackage.jsonfiles.- with the aggregated types from the plugins.
- with the aggregated helpers from the plugins.
- with the aggregated configurations from the plugins.
- with the correct dependencies for our published packages.
- verify every plugins.
- have a README.
- have Codeowners.
- comply with our OSS rules (this can also be run with
yarn oss).- add a header to each file.
- update the
LICENSES-3rdparty.csv,LICENSE,NOTICEandREADME.mdwith the correct licenses.
- update the lock files.
- auto format the codebase.
- typecheck the codebase.
We're using eslint and prettier to lint and format the code.
It's automatically done at save time when you're using VSCode or you can run a command to do it manually:
# With autofix
yarn format
# Without autofix
yarn lintWe're also using TypeScript.
# Typecheck everything
yarn typecheck:all
# Typecheck a specific workspace
yarn workspace <workspace> typecheck
# Build everything
yarn build:all
# Build a specific workspace
yarn workspace <workspace> build
# Watch changes on everything
yarn watch:all
# Watch a specific workspace
yarn workspace <workspace> watchNote
Typechecking and linting are also done in the pre-commit hook, to avoid pushing CI breaking code.
We follow a few rules, so we made a simple command to keep it compliant.
# Make the code compliant with our Open Source rules.
yarn ossIt will:
- update headers of each files.
- update
LICENSES-3rdparty.csv,LICENSE,NOTICEandREADME.mdwith the correct licenses.
It is also run part of the yarn cli integrity CLI.
We try to keep the documentation as up to date as possible.
Important
If you're modifying a behavior or adding a new feature, update/add the required documentation to your PR.
- Run this action with the type of bump you need (
patch,minor,major) and keep themasterbranch as target.
- Review/accept the PR it created and merge it.
-
Create a new release
a. Select the tag created in the bump PR.
b. Name it v{version} with the version created in the bump PR.
c. Generate the release notes, and clean it if needed.
- Publish release.
Another action will takeover and publish the package on NPM.
Usually, after 4-5min, your version will be available from NPM.
You can also manually trigger the publish workflow from the master branch:
- Ensure you're on the
masterbranch - Update the version in package.json if needed (via the bump workflow or manually)
- Go to the publish workflow
- Click "Run workflow"
- Select the
masterbranch - Set
channeltolatest - Leave
versionempty (it will use the version from package.json) - Run the workflow
Important
When publishing to the latest channel from master, you cannot provide a custom version, the workflow will use the version from package.json to ensure version integrity.
You can publish a version in the dev channel so you can easily test your changes in a different repository's CI.
The easiest way to publish a dev version is using the GitHub Actions workflow:
- Go to the publish workflow
- Click "Run workflow"
- Select your feature branch (or
masterif publishing from there) - Set
channeltodev - Set
versionto your dev version (e.g.,3.0.9-dev.0)- The version must follow the format
X.Y.Z-dev.N - For example:
3.0.9-dev.0,3.0.9-dev.1, etc.
- The version must follow the format
- Run the workflow
Note
- Dev versions can be published from any branch
- You can provide a custom version when publishing to the
devchannel - The workflow will validate the version format and fail if it doesn't match
X.Y.Z-dev.N
Wait a few minutes, and you're good to go.
Unfold to learn more
It's pretty useful to work with our frontend monorepo locally when developing plugins.
There is a pretty straightforward way to do it.
- Have our monorepo and
build-pluginsin the$DATADOG_ROOTdirectory (default with the onboarding script). - That's it...
From the root of build-plugins, run:
yarn devThis will:
- update the
package.jsonof our published packages so they point to the built files. - watch and build the
build-pluginscodebase. - reset the
package.jsonback to the original state after you stop theyarn devcommand.
From the root of the monorepo, run:
yarn link-build-pluginsThis will link the local build-plugins packages to the monorepo and update its package.json accordingly (do not commit this change).
Now you can trigger builds in the monorepo, they will use your local build-plugins code.
Once done, you should run yarn unlink --all in the frontend monorepo and kill the yarn dev process in build-plugins.
If you need to update the monorepo's versions of the plugins, you can run:
yarn update-build-plugins <version>This will update the versions of all the plugins we use in the monorepo (webpack, rspack and esbuild).
If you want to test your build-plugins's changes in our monorepo's CI, you can publish a dev version of the plugins.
Follow the instructions in Publish a new dev version to publish your dev version (e.g., 2.5.1-dev.0).
Once published, in the monorepo:
yarn update-build-plugins 2.5.1-dev.0Commit and push the changes.
We have a CLI to help with some tasks.





