diff --git a/README.md b/README.md index 047880b41..77f81e6b9 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Datadog Build Plugins A set of bundler plugins for: - - Webpack Webpack - - Vite Vite - - ESBuild esbuild - - Rollup Rollup - - Rspack Rspack + +- [ESBuild esbuild `@datadog/esbuild-plugin`](/packages/published/esbuild-plugin#readme) +- [Rollup Rollup `@datadog/rollup-plugin`](/packages/published/rollup-plugin#readme) +- [Rspack Rspack `@datadog/rspack-plugin`](/packages/published/rspack-plugin#readme) +- [Vite Vite `@datadog/vite-plugin`](/packages/published/vite-plugin#readme) +- [Webpack Webpack `@datadog/webpack-plugin`](/packages/published/webpack-plugin#readme) + To interact with Datadog directly from your builds. @@ -17,208 +19,43 @@ To interact with Datadog directly from your builds. -- [Bundler Plugins](#bundler-plugins) - - [ESBuild](#-esbuild) - - [Rollup](#-rollup) - - [Rspack](#-rspack) - - [Vite](#-vite) - - [Webpack](#-webpack) -- [Features](#features) - - [Error Tracking](#error-tracking-----) - - [Telemetry](#telemetry-----) +- [Installation](#installation) +- [Usage](#usage) - [Configuration](#configuration) - [`auth.apiKey`](#authapikey) - [`logLevel`](#loglevel) - [`customPlugins`](#customplugins) +- [Features](#features) + - [Error Tracking](#error-tracking-----) + - [Telemetry](#telemetry-----) - [Contributing](#contributing) - [License](#license) -## Bundler Plugins - - -### ESBuild ESBuild - -`@datadog/esbuild-plugin` - -#### Installation -- Yarn - -```bash -yarn add -D @datadog/esbuild-plugin -``` - -- NPM - -```bash -npm install --save-dev @datadog/esbuild-plugin -``` - - -#### Usage -```js -const { datadogEsbuildPlugin } = require('@datadog/esbuild-plugin'); - -require('esbuild').build({ - plugins: [ - datadogEsbuildPlugin({ - // Configuration - }), - ], -}); -``` - -> [!TIP] -> It is important to have the plugin in the first position in order to report every other plugins. - - -[📝 More details ➡️](/packages/published/esbuild-plugin#readme) - -### Rollup Rollup - -`@datadog/rollup-plugin` - -#### Installation -- Yarn - -```bash -yarn add -D @datadog/rollup-plugin -``` - -- NPM - -```bash -npm install --save-dev @datadog/rollup-plugin -``` - - -#### Usage -Inside your `rollup.config.js`. - -```js -import { datadogRollupPlugin } from '@datadog/rollup-plugin'; - -export default { - plugins: [ - datadogRollupPlugin({ - // Configuration - }), - ], -}; -``` - -> [!TIP] -> It is important to have the plugin in the first position in order to report every other plugins. - - -[📝 More details ➡️](/packages/published/rollup-plugin#readme) - -### Rspack Rspack - -`@datadog/rspack-plugin` - -#### Installation -- Yarn - -```bash -yarn add -D @datadog/rspack-plugin -``` - -- NPM - -```bash -npm install --save-dev @datadog/rspack-plugin -``` - - -#### Usage -Inside your `rspack.config.js`. - -```js -const { datadogRspackPlugin } = require('@datadog/rspack-plugin'); - -module.exports = { - plugins: [ - datadogRspackPlugin({ - // Configuration - }), - ], -}; -``` - -> [!TIP] -> It is important to have the plugin in the first position in order to report every other plugins. - - -[📝 More details ➡️](/packages/published/rspack-plugin#readme) - -### Vite Vite - -`@datadog/vite-plugin` - -#### Installation -- Yarn - -```bash -yarn add -D @datadog/vite-plugin -``` - -- NPM - -```bash -npm install --save-dev @datadog/vite-plugin -``` - - -#### Usage -Inside your `vite.config.js`. - -```js -import { datadogVitePlugin } from '@datadog/vite-plugin'; -import { defineConfig } from 'vite' - -export default defineConfig({ - plugins: [ - datadogVitePlugin({ - // Configuration - }), - ], -}; -``` - -> [!TIP] -> It is important to have the plugin in the first position in order to report every other plugins. - - -[📝 More details ➡️](/packages/published/vite-plugin#readme) - -### Webpack Webpack - -`@datadog/webpack-plugin` +## Installation -#### Installation - Yarn ```bash -yarn add -D @datadog/webpack-plugin +yarn add -D @datadog/{{bundler}}-plugin ``` - NPM ```bash -npm install --save-dev @datadog/webpack-plugin +npm install --save-dev @datadog/{{bundler}}-plugin ``` +## Usage -#### Usage -Inside your `webpack.config.js`. +In your bundler's configuration file: ```js -const { datadogWebpackPlugin } = require('@datadog/webpack-plugin'); +const { datadog{{Bundler}}Plugin } = require('@datadog/{{bundler}}-plugin'); -module.exports = { +export const config = { plugins: [ - datadogWebpackPlugin({ + datadog{{Bundler}}Plugin({ // Configuration }), ], @@ -226,67 +63,22 @@ module.exports = { ``` > [!TIP] -> It is important to have the plugin in the first position in order to report every other plugins. +> It is best to have the plugin in the first position in order to report every other plugins. - -[📝 More details ➡️](/packages/published/webpack-plugin#readme) +Follow the specific documentation for each bundler: + +- [ESBuild esbuild `@datadog/esbuild-plugin`](/packages/published/esbuild-plugin#readme) +- [Rollup Rollup `@datadog/rollup-plugin`](/packages/published/rollup-plugin#readme) +- [Rspack Rspack `@datadog/rspack-plugin`](/packages/published/rspack-plugin#readme) +- [Vite Vite `@datadog/vite-plugin`](/packages/published/vite-plugin#readme) +- [Webpack Webpack `@datadog/webpack-plugin`](/packages/published/webpack-plugin#readme) -## Features - - -### Error Tracking ESBuild Rollup Rspack Vite Webpack - -> Interact with Error Tracking directly from your build system. - -```typescript -datadogWebpackPlugin({ - errorTracking?: { - disabled?: boolean, - sourcemaps?: { - bailOnError?: boolean, - dryRun?: boolean, - intakeUrl?: string, - maxConcurrency?: number, - minifiedPathPrefix: string, - releaseVersion: string, - service: string, - }, - } -}); -``` - -[📝 Full documentation ➡️](/packages/plugins/error-tracking#readme) - -### Telemetry ESBuild Rollup Rspack Vite Webpack - -> Display and send telemetry data as metrics to Datadog. - -```typescript -datadogWebpackPlugin({ - telemetry?: { - disabled?: boolean, - enableTracing?: boolean, - endPoint?: string, - output?: boolean - | string - | { - destination: string, - timings?: boolean, - metrics?: boolean, - }, - prefix?: string, - tags?: string[], - timestamp?: number, - filters?: ((metric: Metric) => Metric | null)[], - } -}); -``` +## Configuration -[📝 Full documentation ➡️](/packages/plugins/telemetry#readme) - +
-## Configuration +Full configuration object ```typescript @@ -328,6 +120,8 @@ datadogWebpackPlugin({ ``` +
+ ### `auth.apiKey` > default `null` @@ -367,7 +161,11 @@ Your function will receive three arguments: - `context`: The global context shared accross our plugin. - `log`: A [logger](/packages/factory/README.md#logger) to display messages. -The `context` is a shared object that is mutated during the build process. It contains the following properties: +The `context` is a shared object that is mutated during the build process. + +
+ +Full context object ```typescript @@ -433,16 +231,77 @@ type GlobalContext = { version: string; } ``` + -> [!NOTE] -> Some parts of the context are only available after certain hooks: -> - `context.bundler.rawConfig` is added in the `buildStart` hook. -> - `context.build.*` is populated in the `writeBundle` hook. -> - `context.git.*` is populated in the `buildStart` hook. +
- +#### [📝 Full documentation ➡️](/packages/factory#global-context) + +## Features + + +### Error Tracking ESBuild Rollup Rspack Vite Webpack + +> Interact with Error Tracking directly from your build system. + +#### [📝 Full documentation ➡️](/packages/plugins/error-tracking#readme) + +
+ +Configuration + +```typescript +datadogWebpackPlugin({ + errorTracking?: { + disabled?: boolean, + sourcemaps?: { + bailOnError?: boolean, + dryRun?: boolean, + intakeUrl?: string, + maxConcurrency?: number, + minifiedPathPrefix: string, + releaseVersion: string, + service: string, + }, + } +}); +``` + +
-Your function will need to return an array of [Unplugin Plugins definitions](https://unplugin.unjs.io/guide/#supported-hooks). +### Telemetry ESBuild Rollup Rspack Vite Webpack + +> Display and send telemetry data as metrics to Datadog. + +#### [📝 Full documentation ➡️](/packages/plugins/telemetry#readme) + +
+ +Configuration + +```typescript +datadogWebpackPlugin({ + telemetry?: { + disabled?: boolean, + enableTracing?: boolean, + endPoint?: string, + output?: boolean + | string + | { + destination: string, + timings?: boolean, + metrics?: boolean, + }, + prefix?: string, + tags?: string[], + timestamp?: number, + filters?: ((metric: Metric) => Metric | null)[], + } +}); +``` + +
+ ## Contributing @@ -452,4 +311,4 @@ Check out [CONTRIBUTING.md](/CONTRIBUTING.md) for more information about how to [MIT](/LICENSE) -[Back to top :arrow_up:](#top) +### [Back to top :arrow_up:](#top) diff --git a/packages/factory/README.md b/packages/factory/README.md index 2dbbef1f1..ee2c5dae1 100644 --- a/packages/factory/README.md +++ b/packages/factory/README.md @@ -27,20 +27,23 @@ Most of the time they will interact via the global context. > This will populate `context.build` with a bunch of data coming from the build. -[📝 Full documentation ➡️](/packages/plugins/build-report#readme) +#### [📝 Full documentation ➡️](/packages/plugins/build-report#readme) + ### Bundler Report > A very basic report on the currently used bundler.
> It is useful to unify some configurations. -[📝 Full documentation ➡️](/packages/plugins/bundler-report#readme) +#### [📝 Full documentation ➡️](/packages/plugins/bundler-report#readme) + ### Git > Adds repository data to the global context from the `buildStart` hook. -[📝 Full documentation ➡️](/packages/plugins/git#readme) +#### [📝 Full documentation ➡️](/packages/plugins/git#readme) + ### Injection @@ -51,7 +54,8 @@ Most of the time they will interact via the global context. > - to initialise some global dependencies. > - ... -[📝 Full documentation ➡️](/packages/plugins/injection#readme) +#### [📝 Full documentation ➡️](/packages/plugins/injection#readme) + ## Logger @@ -170,3 +174,5 @@ type GlobalContext = { > - `context.bundler.rawConfig` is added in the `buildStart` hook. > - `context.build.*` is populated in the `writeBundle` hook. > - `context.git.*` is populated in the `buildStart` hook. + +Your function will need to return an array of [Unplugin Plugins definitions](https://unplugin.unjs.io/guide/#supported-hooks). diff --git a/packages/published/esbuild-plugin/README.md b/packages/published/esbuild-plugin/README.md index d90e66944..fca41be44 100644 --- a/packages/published/esbuild-plugin/README.md +++ b/packages/published/esbuild-plugin/README.md @@ -1,6 +1,6 @@ -# Datadog ESBuild Plugin +# Datadog esbuild Plugin -A ESBuild plugin to interact with Datadog from your ESBuild builds. +A esbuild plugin to interact with Datadog from your ESBuild builds. ## Installation diff --git a/packages/tools/src/commands/integrity/readme.ts b/packages/tools/src/commands/integrity/readme.ts index 36a7a9280..6641e99e0 100644 --- a/packages/tools/src/commands/integrity/readme.ts +++ b/packages/tools/src/commands/integrity/readme.ts @@ -139,12 +139,17 @@ const getPluginTemplate = (plugin: Workspace, pluginMeta: PluginMetadata) => { const configContent = pluginMeta.config ? outdent` +
+ + Configuration + \`\`\`typescript datadogWebpackPlugin({ ${pluginMeta.config.replace(/;/g, ',')} }); \`\`\` +
` : ''; @@ -152,8 +157,9 @@ const getPluginTemplate = (plugin: Workspace, pluginMeta: PluginMetadata) => { ${titleContent}${bundlerContent ? ` ${bundlerContent}` : ''} > ${intro.split('\n').join('\n> ')} + + #### [📝 Full documentation ➡️](/${plugin.location}#readme) ${configContent} - [📝 Full documentation ➡️](/${plugin.location}#readme) `; }; @@ -168,26 +174,14 @@ const getBundlerMeta = (bundler: Workspace): BundlerMetadata => { // Catch installation and usage. // Everything between "## (Installation|Usage)" and the next "##". const installation = readme.match(/## Installation\s*((!?[\s\S](?!##))*)/)?.[1] || ''; - const usage = readme.match(/## Usage\s*((!?[\s\S](?!##))*)/)?.[1] || ''; + const usage = readme.match(/## Usage\s*((!?[\s\S](?!```\n))+\n```)/)?.[1] || ''; return { title, name: title.toLowerCase(), usage, installation }; }; const getBundlerTemplate = (bundler: Workspace, bundlerMeta: BundlerMetadata) => { - const { title, name, installation, usage } = bundlerMeta; - return outdent` - ### ${getBundlerPicture(name)} ${title} - - \`${bundler.name}\` - - #### Installation - ${installation} - - #### Usage - ${usage} - - [📝 More details ➡️](/${bundler.location}#readme) - `; + const { title, name } = bundlerMeta; + return outdent`- [${getBundlerPicture(name)} ${title} \`${bundler.name}\`](/${bundler.location}#readme)`; }; const handleBundler = (bundler: Workspace, index: number) => { @@ -300,7 +294,7 @@ const handlePlugin = async (plugin: Workspace) => { const getGlobalContextType = () => { // Will capture the first code block after '## Global Context' up to the next title '## '. const RX = - /## Global Context(!?[\s\S](?!```typescript))+[\s\S](?```typescript([\s\S](?!## ))+)/gm; + /## Global Context(!?[\s\S](?!```typescript))+[\s\S](?```typescript([\s\S](?!```\n))+\n```)/gm; const coreReadmeContent = fs.readFileSync( path.resolve(ROOT, './packages/factory/README.md'), 'utf-8', @@ -364,7 +358,7 @@ export const updateReadmes = async (plugins: Workspace[], bundlers: Workspace[]) rootReadmeContent = replaceInBetween( rootReadmeContent, MD_BUNDLERS_KEY, - bundlersContents.join('\n\n'), + bundlersContents.join('\n'), ); rootReadmeContent = replaceInBetween( rootReadmeContent, diff --git a/packages/tools/src/helpers.ts b/packages/tools/src/helpers.ts index 3b1ff2cba..ad44339e2 100644 --- a/packages/tools/src/helpers.ts +++ b/packages/tools/src/helpers.ts @@ -47,7 +47,10 @@ export const slugify = (string: string) => { export const replaceInBetween = (content: string, mark: string, injection: string) => { const escapedMark = mark.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const escapedInjection = injection.replace(/\$/g, '$$$$'); - const rx = new RegExp(`${escapedMark}[\\S\\s]*${escapedMark}`, 'gm'); + const rx = new RegExp( + `${escapedMark}([\\S\\s](?!${escapedMark}))*(\\s|\\S)?${escapedMark}`, + 'gm', + ); return content.replace(rx, `${mark}\n${escapedInjection}\n${mark}`); };