Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ packages/plugins/analytics @yoannmoin

# Custom Hooks
packages/plugins/custom-hooks @yoannmoinet

# True End
packages/plugins/true-end @yoannmoinet

# Ci Visibility
packages/plugins/ci-visibility @yoannmoinet
93 changes: 71 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ To interact with Datadog directly from your builds.
- [Configuration](#configuration)
- [`auth.apiKey`](#authapikey)
- [`auth.appKey`](#authappkey)
- [`customPlugins`](#customplugins)
- [`disableGit`](#disablegit)
- [`logLevel`](#loglevel)
- [`customPlugins`](#customplugins)
- [`metadata.name`](#metadataname)
- [Features](#features)
- [Ci Visibility](#ci-visibility-----)
- [Error Tracking](#error-tracking-----)
- [Telemetry](#telemetry-----)
- [Contributing](#contributing)
Expand Down Expand Up @@ -90,6 +92,9 @@ Follow the specific documentation for each bundler:
};
customPlugins?: (arg: GetPluginsArg) => UnpluginPlugin[];
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
ciVisibility?: {
disabled?: boolean;
};
errorTracking?: {
disabled?: boolean;
sourcemaps?: {
Expand Down Expand Up @@ -137,19 +142,6 @@ In order to interact with Datadog, you have to use [your own API Key](https://ap

In order to interact with Datadog, you have to use [your own Application Key](https://app.datadoghq.com/organization-settings/application-keys).

### `disableGit`

> default: `false`

Disable the [Git plugin](/packages/plugins/git#readme) if you don't want to use it.<br/>
For instance if you see a `Error: No git remotes available` error.

### `logLevel`

> default: `'warn'`

Which level of log do you want to show.

### `customPlugins`

> default: `[]`
Expand Down Expand Up @@ -184,27 +176,44 @@ Your function will receive three arguments:

The `context` is a shared object that is mutated during the build process.

Your function has to return an array of [Unplugin Plugins definitions](https://unplugin.unjs.io/guide/#supported-hooks).<br/>
You can also use our own [custom hooks](/packages/plugins/custom-hooks#existing-hooks).

<details>

<summary>Full context object</summary>

<!-- #global-context-type -->
<pre>
type GlobalContext = {
// Trigger an asynchronous <a href="/packages/plugins/custom-hooks#readme" title="CustomHooks">custom hook</a>.
asyncHook: async (name: string, ...args: any[]) => Promise<void>;
// Mirror of the user's config.
auth?: {
apiKey?: string;
appKey?: string;
};
// More details on the currently running bundler.
bundler: <a href="/packages/plugins/bundler-report#readme" title="BundlerReport">BundlerReport</a>
// Added in `writeBundle`.
build: <a href="/packages/plugins/build-report#readme" title="BuildReport">BuildReport</a>
// Available in the `buildReport` hook.
build: <a href="/packages/plugins/build-report#readme" title="BuildReport">BuildReport</a>;
// Available in the `bundlerReport` hook.
bundler: <a href="/packages/plugins/bundler-report#readme" title="BundlerReport">BundlerReport</a>;
cwd: string;
getLogger: (name: string) => <a href="#logger" title="Logger">Logger</a>
// Added in `buildStart`.
git?: <a href="/packages/plugins/git#readme" title="Git">Git</a>
inject: <a href="/packages/plugins/injection#readme" title="Injection">Injection</a>
env: string;
getLogger: (name: string) => <a href="#logger" title="Logger">Logger</a>;
// Available in the `git` hook.
git?: <a href="/packages/plugins/git#readme" title="Git">Git</a>;
// Trigger a synchronous <a href="/packages/plugins/custom-hooks#readme" title="CustomHooks">custom hook</a>.
hook: (name: string, ...args: any[]) => void;
inject: <a href="/packages/plugins/injection#readme" title="Injection">Injection</a>;
// The list of all the plugin names that are currently running in the ecosystem.
pluginNames: string[];
// The list of all the plugin instances that are currently running in the ecosystem.
plugins: Plugin[];
// Send a log to Datadog.
sendLog: (message: string, context?: Record<string, string>) => Promise<void>;
// The start time of the build.
start: number;
// The version of the plugin.
version: string;
}
</pre>
Expand All @@ -214,9 +223,49 @@ type GlobalContext = {

#### [📝 Full documentation ➡️](/packages/factory#global-context)


### `disableGit`

> default: `false`

Disable the [Git plugin](/packages/plugins/git#readme) if you don't want to use it.<br/>
For instance if you see a `Error: No git remotes available` error.

### `logLevel`

> default: `'warn'`

Which level of log do you want to show.

### `metadata.name`
> default: `null`

The name of the build.<br/>
This is used to identify the build in logs, metrics and spans.

## Features

<!-- #list-of-packages -->
### Ci Visibility <img src="packages/assets/src/esbuild.svg" alt="ESBuild" width="17" /> <img src="packages/assets/src/rollup.svg" alt="Rollup" width="17" /> <img src="packages/assets/src/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />

> Interact with CI Visibility directly from your build system.

#### [📝 Full documentation ➡️](/packages/plugins/ci-visibility#readme)

<details>

<summary>Configuration</summary>

```typescript
datadogWebpackPlugin({
ciVisibility?: {
disabled?: boolean,
}
});
```

</details>

### Error Tracking <img src="packages/assets/src/esbuild.svg" alt="ESBuild" width="17" /> <img src="packages/assets/src/rollup.svg" alt="Rollup" width="17" /> <img src="packages/assets/src/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />

> Interact with Error Tracking directly from your build system.
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/helpers/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const serializeBuildReport = (report: BuildReport): SerializedBuildReport
const jsonReport: SerializedBuildReport = {
bundler: report.bundler,
errors: report.errors,
metadata: report.metadata,
warnings: report.warnings,
logs: report.logs,
timings: report.timings,
Expand Down Expand Up @@ -93,6 +94,7 @@ export const unserializeBuildReport = (report: SerializedBuildReport): BuildRepo
const buildReport: BuildReport = {
bundler: report.bundler,
errors: report.errors,
metadata: report.metadata,
warnings: report.warnings,
logs: report.logs,
timings: report.timings,
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/helpers/strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,20 @@ describe('Strings Helpers', () => {
expect(filterSensitiveInfoFromRepositoryUrl(input)).toBe(expected);
});
});

describe('capitalize', () => {
test.each([
['hello world', 'Hello World'],
['hello', 'Hello'],
['HELLO', 'Hello'],
['hELLO', 'Hello'],
['hELLO wORLD', 'Hello World'],
['hELLO wORLD!', 'Hello World!'],
['hELLO wORLD! 123', 'Hello World! 123'],
['', ''],
])('Should capitalize "%s" => "%s"', async (str, expected) => {
const { capitalize } = await import('@dd/core/helpers/strings');
expect(capitalize(str)).toBe(expected);
});
});
});
7 changes: 7 additions & 0 deletions packages/core/src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,12 @@ export const filterSensitiveInfoFromRepositoryUrl = (repositoryUrl: string = '')
}
};

// Capitalize the first letter of each word in a string.
export const capitalize = (str: string) =>
str
.split(' ')
.map((st) => st.charAt(0).toUpperCase() + st.slice(1).toLowerCase())
.join(' ');

let index = 0;
export const getUniqueId = () => `${Date.now()}.${performance.now()}.${++index}`;
35 changes: 24 additions & 11 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import type { TrackedFilesMatcher } from '@dd/internal-git-plugin/trackedFilesMatcher';
/* eslint-disable arca/import-ordering */
// #imports-injection-marker
import type { CiVisibilityOptions } from '@dd/ci-visibility-plugin/types';
import type * as ciVisibility from '@dd/ci-visibility-plugin';
import type { ErrorTrackingOptions } from '@dd/error-tracking-plugin/types';
import type * as errorTracking from '@dd/error-tracking-plugin';
import type { RumOptions } from '@dd/rum-plugin/types';
Expand Down Expand Up @@ -56,14 +58,20 @@ export type SerializedEntry = Assign<Entry, { inputs: string[]; outputs: string[
export type SerializedInput = Assign<Input, { dependencies: string[]; dependents: string[] }>;
export type SerializedOutput = Assign<Output, { inputs: string[] }>;

export type LogTags = string[];
export type Timer = {
label: string;
pluginName: string;
spans: { start: number; end?: number; tags?: string[] }[];
tags: string[];
spans: { start: number; end?: number; tags: LogTags }[];
tags: LogTags;
total: number;
logLevel: LogLevel;
};

export type BuildMetadata = {
name?: string;
};

export type BuildReport = {
bundler: Omit<BundlerReport, 'outDir' | 'rawConfig'>;
errors: string[];
Expand All @@ -75,6 +83,7 @@ export type BuildReport = {
message: string;
time: number;
}[];
metadata: BuildMetadata;
timings: Timer[];
entries?: Entry[];
inputs?: Input[];
Expand Down Expand Up @@ -121,16 +130,16 @@ export type ToInjectItem = {

export type TimeLogger = {
timer: Timer;
resume: () => void;
end: () => void;
pause: () => void;
tag: (tags: string[], opts?: { span?: boolean }) => void;
resume: (startTime?: number) => void;
end: (endTime?: number) => void;
pause: (pauseTime?: number) => void;
tag: (tags: LogTags, opts?: { span?: boolean }) => void;
};

// The rest parameter is a LogLevel or a boolean to auto start the timer.
export type TimeLog = (
label: string,
opts?: { level?: LogLevel; start?: boolean; log?: boolean; tags?: string[] },
opts?: { level?: LogLevel; start?: boolean | number; log?: boolean; tags?: LogTags },
) => TimeLogger;
export type GetLogger = (name: string) => Logger;
export type Logger = {
Expand All @@ -147,18 +156,18 @@ export type TriggerHook<R> = <K extends keyof CustomHooks>(
...args: Parameters<NonNullable<CustomHooks[K]>>
) => R;
export type GlobalContext = {
asyncHook: TriggerHook<Promise<void[]>>;
auth?: AuthOptions;
inject: (item: ToInjectItem) => void;
bundler: BundlerReport;
build: BuildReport;
bundler: BundlerReport;
cwd: string;
env: Env;
getLogger: GetLogger;
git?: RepositoryData;
asyncHook: TriggerHook<Promise<void[]>>;
hook: TriggerHook<void>;
plugins: (PluginOptions | CustomPluginOptions)[];
inject: (item: ToInjectItem) => void;
pluginNames: string[];
plugins: (PluginOptions | CustomPluginOptions)[];
sendLog: (message: string, ctx?: any) => Promise<void>;
start: number;
version: string;
Expand All @@ -172,11 +181,13 @@ export type FactoryMeta = {
export type HookFn<T extends Array<any>> = (...args: T) => void;
export type AsyncHookFn<T extends Array<any>> = (...args: T) => Promise<void> | void;
export type CustomHooks = {
asyncTrueEnd?: () => Promise<void> | void;
cwd?: HookFn<[string]>;
init?: HookFn<[GlobalContext]>;
buildReport?: HookFn<[BuildReport]>;
bundlerReport?: HookFn<[BundlerReport]>;
git?: AsyncHookFn<[RepositoryData]>;
syncTrueEnd?: () => void;
};

export type PluginOptions = Assign<
Expand Down Expand Up @@ -212,13 +223,15 @@ export type AuthOptions = {

export interface BaseOptions {
auth?: AuthOptions;
metadata?: BuildMetadata;
disableGit?: boolean;
logLevel?: LogLevel;
}

export interface Options extends BaseOptions {
// Each product should have a unique entry.
// #types-injection-marker
[ciVisibility.CONFIG_KEY]?: CiVisibilityOptions;
[errorTracking.CONFIG_KEY]?: ErrorTrackingOptions;
[rum.CONFIG_KEY]?: RumOptions;
[telemetry.CONFIG_KEY]?: TelemetryOptions;
Expand Down
Loading