-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (45 loc) · 1.79 KB
/
index.ts
File metadata and controls
53 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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 { GlobalContext, GetPlugins, Options } from '@dd/core/types';
import { PLUGIN_NAME } from './constants';
import { uploadSourcemaps } from './sourcemaps';
import type { ErrorTrackingOptions, ErrorTrackingOptionsWithSourcemaps } from './types';
import { validateOptions } from './validate';
export { CONFIG_KEY, PLUGIN_NAME } from './constants';
export type types = {
// Add the types you'd like to expose here.
ErrorTrackingOptions: ErrorTrackingOptions;
};
export const getPlugins: GetPlugins = (opts: Options, context: GlobalContext) => {
const log = context.getLogger(PLUGIN_NAME);
// Verify configuration.
const timeOptions = log.time('validate options');
const options = validateOptions(opts, log);
timeOptions.end();
// If the plugin is disabled, return an empty array.
if (options.disabled) {
return [];
}
return [
{
name: PLUGIN_NAME,
enforce: 'post',
async writeBundle() {
if (options.disabled) {
return;
}
if (options.sourcemaps) {
const totalTime = log.time('sourcemaps process');
// Need the "as" because Typescript doesn't understand that we've already checked for sourcemaps.
await uploadSourcemaps(
options as ErrorTrackingOptionsWithSourcemaps,
context,
log,
);
totalTime.end();
}
},
},
];
};