-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c8c419
commit 64d26cf
Showing
9 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# RUM Plugin <!-- #omit in toc --> | ||
|
||
Interact with our Real User Monitoring product (RUM) in Datadog directly from your build system. | ||
|
||
<!-- The title and the following line will both be added to the root README.md --> | ||
|
||
## Table of content <!-- #omit in toc --> | ||
|
||
<!-- This is auto generated with yarn cli integrity --> | ||
|
||
<!-- #toc --> | ||
- [Configuration](#configuration) | ||
<!-- #toc --> | ||
|
||
## Configuration | ||
|
||
```ts | ||
rum?: { | ||
disabled?: boolean; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@dd/rum-plugins", | ||
"packageManager": "yarn@4.0.2", | ||
"license": "MIT", | ||
"private": true, | ||
"author": "Datadog", | ||
"description": "Interact with our Real User Monitoring product (RUM) in Datadog directly from your build system.", | ||
"homepage": "https://github.com/DataDog/build-plugins/tree/main/packages/plugins/rum#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DataDog/build-plugins", | ||
"directory": "packages/plugins/rum" | ||
}, | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./*": "./src/*.ts" | ||
}, | ||
"scripts": { | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@dd/core": "workspace:*", | ||
"chalk": "2.3.1", | ||
"unplugin": "1.10.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2019-Present Datadog, Inc. | ||
|
||
import type { PluginName } from '@dd/core/types'; | ||
|
||
export const CONFIG_KEY = 'rum' as const; | ||
export const PLUGIN_NAME: PluginName = 'datadog-rum-plugin' as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2019-Present Datadog, Inc. | ||
|
||
import { getLogFn } from '@dd/core/log'; | ||
import type { Context } from '@dd/core/plugins'; | ||
import type { GetPlugins } from '@dd/core/types'; | ||
import chalk from 'chalk'; | ||
|
||
import { PLUGIN_NAME, CONFIG_KEY } from './constants'; | ||
import type { OptionsWithRumEnabled, RumOptions, RumOptionsEnabled } from './types'; | ||
|
||
export { CONFIG_KEY, PLUGIN_NAME } from './constants'; | ||
|
||
export const helpers = { | ||
// Add the helpers you'd like to expose here. | ||
}; | ||
|
||
export type types = { | ||
// Add the types you'd like to expose here. | ||
RumOptions: RumOptions; | ||
OptionsWithRumEnabled: OptionsWithRumEnabled; | ||
}; | ||
|
||
// Deal with validation and defaults here. | ||
export const validateOptions = (config: Partial<OptionsWithRumEnabled>): RumOptionsEnabled => { | ||
const red = chalk.bold.red; | ||
const errors = []; | ||
const validatedOptions: RumOptionsEnabled = config[CONFIG_KEY] || {}; | ||
|
||
if (validatedOptions.sourcemaps) { | ||
if (!validatedOptions.sourcemaps.basePath) { | ||
errors.push(`${red('sourcemaps.basePath')} is required.`); | ||
} | ||
if (!validatedOptions.sourcemaps.releaseVersion) { | ||
errors.push(`${red('sourcemaps.releaseVersion')} is required.`); | ||
} | ||
} | ||
|
||
if (errors.length) { | ||
throw new Error(`Invalid configuration for ${PLUGIN_NAME}:\n ${errors.join('\n ')}`); | ||
} | ||
|
||
return validatedOptions; | ||
}; | ||
|
||
export const getPlugins: GetPlugins<OptionsWithRumEnabled> = ( | ||
opts: OptionsWithRumEnabled, | ||
context: Context, | ||
) => { | ||
return [ | ||
{ | ||
name: PLUGIN_NAME, | ||
async writeBundle() { | ||
const rumOptions = opts[CONFIG_KEY]; | ||
if (rumOptions.disabled || !rumOptions.sourcemaps) { | ||
return; | ||
} | ||
const log = getLogFn(opts.logLevel, PLUGIN_NAME); | ||
log(`Uploading sourcemaps.`); | ||
|
||
// Verify configuration. | ||
// Gather the sourcemaps files using glob. | ||
// Build payloads (with git info from context plugin). | ||
// Upload the sourcemaps. | ||
}, | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2019-Present Datadog, Inc. | ||
|
||
import type { GetPluginsOptionsWithCWD } from '@dd/core/types'; | ||
|
||
import type { CONFIG_KEY } from './constants'; | ||
|
||
export type RumOptions = { | ||
disabled?: boolean; | ||
sourcemaps?: { | ||
basePath: string; | ||
dryRun?: boolean; | ||
maxConcurrency?: number; | ||
minifiedPathPrefix?: string; | ||
releaseVersion: string; | ||
}; | ||
}; | ||
|
||
export interface RumOptionsEnabled extends RumOptions { | ||
disabled?: false; | ||
} | ||
|
||
export interface OptionsWithRumEnabled extends GetPluginsOptionsWithCWD { | ||
[CONFIG_KEY]: RumOptionsEnabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"rootDir": "./", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["**/*"], | ||
"exclude": ["dist", "node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2019-Present Datadog, Inc. | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { runBundlers } from '../../helpers'; | ||
|
||
// Mock log function. | ||
const logFn = jest.fn((originalLogFn, ...args: any[]) => { | ||
const [text, ...rest] = args; | ||
originalLogFn(`[MOCKED] ${text}`, ...rest); | ||
}); | ||
|
||
jest.mock('@dd/core/log', () => { | ||
return { | ||
getLogFn: (...args: any[]) => { | ||
const { getLogFn: original } = jest.requireActual('@dd/core/log'); | ||
return (...argsLogs: any[]) => { | ||
logFn(original(...args), ...argsLogs); | ||
}; | ||
}, | ||
}; | ||
}); | ||
|
||
// Some paths. | ||
const entry = path.resolve(__dirname, './fixtures/index.js'); | ||
const destination = path.resolve(__dirname, './fixtures/dist'); | ||
|
||
describe('RUM Plugin', () => { | ||
afterAll(() => { | ||
// Clean files | ||
fs.rmSync(destination, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}); | ||
|
||
test('It should log at the end of the build', async () => { | ||
// Build everything. | ||
const results = await runBundlers({ entry, destination }, { rum: { sourcemaps: {} } }); | ||
|
||
// Assert logs. | ||
expect(logFn).toHaveBeenNthCalledWith( | ||
results.length, | ||
expect.any(Function), | ||
expect.any(String), | ||
); | ||
}); | ||
}); |