@datadog/webpack-plugin 0.0.13-0 → 0.0.13-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/dist/src/index.d.ts +33 -15
- package/dist/src/index.js +305 -240
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +291 -224
- package/dist/src/index.mjs.map +1 -1
- package/package.json +20 -8
package/dist/src/index.mjs
CHANGED
|
@@ -14,7 +14,67 @@ import * as querystring from 'querystring';
|
|
|
14
14
|
import process2 from 'process';
|
|
15
15
|
|
|
16
16
|
const CONFIG_KEY = "telemetry";
|
|
17
|
-
const PLUGIN_NAME =
|
|
17
|
+
const PLUGIN_NAME = `datadog-${CONFIG_KEY}-plugin`;
|
|
18
|
+
|
|
19
|
+
const filterTreeMetrics = (metric) => (
|
|
20
|
+
// Remove tree metrics because way too verbose
|
|
21
|
+
!/modules\.tree\.(count|size)$/.test(metric.metric) ? metric : null
|
|
22
|
+
);
|
|
23
|
+
const filterSourcemapsAndNodeModules = (metric) => metric.tags.some(
|
|
24
|
+
(tag) => (
|
|
25
|
+
// Remove sourcemaps.
|
|
26
|
+
/^assetName:.*\.map$/.test(tag) || // Remove third parties.
|
|
27
|
+
/^moduleName:\/node_modules/.test(tag)
|
|
28
|
+
)
|
|
29
|
+
) ? null : metric;
|
|
30
|
+
const filterMetricsOnThreshold = (metric) => {
|
|
31
|
+
const thresholds = {
|
|
32
|
+
size: 1e5,
|
|
33
|
+
count: 10,
|
|
34
|
+
duration: 1e3
|
|
35
|
+
};
|
|
36
|
+
if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
|
|
37
|
+
thresholds.count = 0;
|
|
38
|
+
}
|
|
39
|
+
if (/(modules\.(dependencies|dependents)$)/.test(metric.metric)) {
|
|
40
|
+
thresholds.count = 30;
|
|
41
|
+
}
|
|
42
|
+
if (/modules\.tree\.count$/.test(metric.metric)) {
|
|
43
|
+
thresholds.count = 150;
|
|
44
|
+
}
|
|
45
|
+
if (/modules\.tree\.size$/.test(metric.metric)) {
|
|
46
|
+
thresholds.size = 15e5;
|
|
47
|
+
}
|
|
48
|
+
if (/entries\.size$/.test(metric.metric)) {
|
|
49
|
+
thresholds.size = 0;
|
|
50
|
+
}
|
|
51
|
+
if (/entries\.modules\.count$/.test(metric.metric)) {
|
|
52
|
+
thresholds.count = 0;
|
|
53
|
+
}
|
|
54
|
+
return metric.value > thresholds[metric.type] ? metric : null;
|
|
55
|
+
};
|
|
56
|
+
const defaultFilters = [
|
|
57
|
+
filterTreeMetrics,
|
|
58
|
+
filterSourcemapsAndNodeModules,
|
|
59
|
+
filterMetricsOnThreshold
|
|
60
|
+
];
|
|
61
|
+
const getMetric = (metric, opts) => ({
|
|
62
|
+
type: "gauge",
|
|
63
|
+
tags: [...metric.tags, ...opts.tags],
|
|
64
|
+
metric: `${opts.prefix ? `${opts.prefix}.` : ""}${metric.metric}`,
|
|
65
|
+
points: [[opts.timestamp, metric.value]]
|
|
66
|
+
});
|
|
67
|
+
const flattened = (arr) => [].concat(...arr);
|
|
68
|
+
const getType = (name) => name.includes(".") ? name.split(".").pop() : "unknown";
|
|
69
|
+
const getOptionsDD = (opt) => {
|
|
70
|
+
const options = opt[CONFIG_KEY];
|
|
71
|
+
return {
|
|
72
|
+
timestamp: Math.floor((options.timestamp || Date.now()) / 1e3),
|
|
73
|
+
tags: options.tags || [],
|
|
74
|
+
prefix: options.prefix || "",
|
|
75
|
+
filters: options.filters || defaultFilters
|
|
76
|
+
};
|
|
77
|
+
};
|
|
18
78
|
|
|
19
79
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
20
80
|
|
|
@@ -3035,87 +3095,6 @@ const getContext = (args) => {
|
|
|
3035
3095
|
}));
|
|
3036
3096
|
};
|
|
3037
3097
|
|
|
3038
|
-
const outputFiles = async (context, options) => {
|
|
3039
|
-
const { report, metrics, bundler } = context;
|
|
3040
|
-
const opts = options[CONFIG_KEY].output;
|
|
3041
|
-
if (typeof opts !== "string" && typeof opts !== "object") {
|
|
3042
|
-
return;
|
|
3043
|
-
}
|
|
3044
|
-
const startWriting = Date.now();
|
|
3045
|
-
let destination;
|
|
3046
|
-
const files = {
|
|
3047
|
-
timings: true,
|
|
3048
|
-
dependencies: true,
|
|
3049
|
-
bundler: true,
|
|
3050
|
-
metrics: true,
|
|
3051
|
-
result: true
|
|
3052
|
-
};
|
|
3053
|
-
if (typeof opts === "object") {
|
|
3054
|
-
destination = opts.destination;
|
|
3055
|
-
files.timings = opts.timings || false;
|
|
3056
|
-
files.dependencies = opts.dependencies || false;
|
|
3057
|
-
files.bundler = opts.bundler || false;
|
|
3058
|
-
files.metrics = opts.metrics || false;
|
|
3059
|
-
} else {
|
|
3060
|
-
destination = opts;
|
|
3061
|
-
}
|
|
3062
|
-
const outputPath = require$$1.resolve(options.cwd, destination);
|
|
3063
|
-
try {
|
|
3064
|
-
const errors = {};
|
|
3065
|
-
const filesToWrite = {};
|
|
3066
|
-
if (files.timings && report?.timings) {
|
|
3067
|
-
filesToWrite.timings = {
|
|
3068
|
-
content: {
|
|
3069
|
-
tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
|
|
3070
|
-
loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
|
|
3071
|
-
modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
|
|
3072
|
-
}
|
|
3073
|
-
};
|
|
3074
|
-
}
|
|
3075
|
-
if (files.dependencies && report?.dependencies) {
|
|
3076
|
-
filesToWrite.dependencies = { content: report.dependencies };
|
|
3077
|
-
}
|
|
3078
|
-
if (files.bundler) {
|
|
3079
|
-
if (bundler.webpack) {
|
|
3080
|
-
filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
|
|
3081
|
-
}
|
|
3082
|
-
if (bundler.esbuild) {
|
|
3083
|
-
filesToWrite.bundler = { content: bundler.esbuild };
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
if (metrics && files.metrics) {
|
|
3087
|
-
filesToWrite.metrics = { content: metrics };
|
|
3088
|
-
}
|
|
3089
|
-
const proms = Object.keys(filesToWrite).map((file) => {
|
|
3090
|
-
const start = Date.now();
|
|
3091
|
-
console.log(`Start writing ${file}.json.`);
|
|
3092
|
-
return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
|
|
3093
|
-
console.log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
|
|
3094
|
-
}).catch((e) => {
|
|
3095
|
-
console.log(
|
|
3096
|
-
`Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
|
|
3097
|
-
"error"
|
|
3098
|
-
);
|
|
3099
|
-
errors[file] = e;
|
|
3100
|
-
});
|
|
3101
|
-
});
|
|
3102
|
-
await Promise.all(proms);
|
|
3103
|
-
console.log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
|
|
3104
|
-
const fileErrored = Object.keys(errors);
|
|
3105
|
-
if (fileErrored.length) {
|
|
3106
|
-
console.log(
|
|
3107
|
-
`Couldn't write files.
|
|
3108
|
-
${fileErrored.map(
|
|
3109
|
-
(file) => ` - ${file}: ${errors[file].toString()}`
|
|
3110
|
-
)}`,
|
|
3111
|
-
"error"
|
|
3112
|
-
);
|
|
3113
|
-
}
|
|
3114
|
-
} catch (e) {
|
|
3115
|
-
console.log(`Couldn't write files. ${e}`, "error");
|
|
3116
|
-
}
|
|
3117
|
-
};
|
|
3118
|
-
|
|
3119
3098
|
var chalk$1 = {exports: {}};
|
|
3120
3099
|
|
|
3121
3100
|
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
|
@@ -5002,66 +4981,103 @@ var templates = (chalk, tmp) => {
|
|
|
5002
4981
|
var chalkExports = chalk$1.exports;
|
|
5003
4982
|
var chalk = /*@__PURE__*/getDefaultExportFromCjs(chalkExports);
|
|
5004
4983
|
|
|
5005
|
-
const
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
)
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
)
|
|
5015
|
-
) ? null : metric;
|
|
5016
|
-
const filterMetricsOnThreshold = (metric) => {
|
|
5017
|
-
const thresholds = {
|
|
5018
|
-
size: 1e5,
|
|
5019
|
-
count: 10,
|
|
5020
|
-
duration: 1e3
|
|
5021
|
-
};
|
|
5022
|
-
if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
|
|
5023
|
-
thresholds.count = 0;
|
|
4984
|
+
const log = (text, level, type = "debug", name) => {
|
|
4985
|
+
let color = chalk;
|
|
4986
|
+
let logFn = console.log;
|
|
4987
|
+
if (type === "error") {
|
|
4988
|
+
color = chalk.red;
|
|
4989
|
+
logFn = console.error;
|
|
4990
|
+
} else if (type === "warn") {
|
|
4991
|
+
color = chalk.yellow;
|
|
4992
|
+
logFn = console.warn;
|
|
5024
4993
|
}
|
|
5025
|
-
|
|
5026
|
-
|
|
4994
|
+
const prefix = name ? `[${chalk.bold(name)}] ` : "";
|
|
4995
|
+
if (level === "debug" || level === "warn" && ["error", "warn"].includes(type) || level === "error" && type === "error") {
|
|
4996
|
+
logFn(`${prefix}${color(text)}`);
|
|
5027
4997
|
}
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
4998
|
+
};
|
|
4999
|
+
const getLogFn = (level = "warn", name) => (text, type = "debug") => log(text, level, type, name);
|
|
5000
|
+
|
|
5001
|
+
const outputFiles = async (context, options) => {
|
|
5002
|
+
const { report, metrics, bundler } = context;
|
|
5003
|
+
const opts = options[CONFIG_KEY].output;
|
|
5004
|
+
if (typeof opts !== "string" && typeof opts !== "object") {
|
|
5005
|
+
return;
|
|
5033
5006
|
}
|
|
5034
|
-
|
|
5035
|
-
|
|
5007
|
+
const startWriting = Date.now();
|
|
5008
|
+
let destination;
|
|
5009
|
+
const files = {
|
|
5010
|
+
timings: true,
|
|
5011
|
+
dependencies: true,
|
|
5012
|
+
bundler: true,
|
|
5013
|
+
metrics: true,
|
|
5014
|
+
result: true
|
|
5015
|
+
};
|
|
5016
|
+
if (typeof opts === "object") {
|
|
5017
|
+
destination = opts.destination;
|
|
5018
|
+
files.timings = opts.timings || false;
|
|
5019
|
+
files.dependencies = opts.dependencies || false;
|
|
5020
|
+
files.bundler = opts.bundler || false;
|
|
5021
|
+
files.metrics = opts.metrics || false;
|
|
5022
|
+
} else {
|
|
5023
|
+
destination = opts;
|
|
5036
5024
|
}
|
|
5037
|
-
|
|
5038
|
-
|
|
5025
|
+
const outputPath = require$$1.resolve(options.cwd, destination);
|
|
5026
|
+
const log = getLogFn(options.logLevel, PLUGIN_NAME);
|
|
5027
|
+
try {
|
|
5028
|
+
const errors = {};
|
|
5029
|
+
const filesToWrite = {};
|
|
5030
|
+
if (files.timings && report?.timings) {
|
|
5031
|
+
filesToWrite.timings = {
|
|
5032
|
+
content: {
|
|
5033
|
+
tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
|
|
5034
|
+
loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
|
|
5035
|
+
modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
|
|
5036
|
+
}
|
|
5037
|
+
};
|
|
5038
|
+
}
|
|
5039
|
+
if (files.dependencies && report?.dependencies) {
|
|
5040
|
+
filesToWrite.dependencies = { content: report.dependencies };
|
|
5041
|
+
}
|
|
5042
|
+
if (files.bundler) {
|
|
5043
|
+
if (bundler.webpack) {
|
|
5044
|
+
filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
|
|
5045
|
+
}
|
|
5046
|
+
if (bundler.esbuild) {
|
|
5047
|
+
filesToWrite.bundler = { content: bundler.esbuild };
|
|
5048
|
+
}
|
|
5049
|
+
}
|
|
5050
|
+
if (metrics && files.metrics) {
|
|
5051
|
+
filesToWrite.metrics = { content: metrics };
|
|
5052
|
+
}
|
|
5053
|
+
const proms = Object.keys(filesToWrite).map((file) => {
|
|
5054
|
+
const start = Date.now();
|
|
5055
|
+
log(`Start writing ${file}.json.`);
|
|
5056
|
+
return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
|
|
5057
|
+
log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
|
|
5058
|
+
}).catch((e) => {
|
|
5059
|
+
log(
|
|
5060
|
+
`Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
|
|
5061
|
+
"error"
|
|
5062
|
+
);
|
|
5063
|
+
errors[file] = e;
|
|
5064
|
+
});
|
|
5065
|
+
});
|
|
5066
|
+
await Promise.all(proms);
|
|
5067
|
+
log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
|
|
5068
|
+
const fileErrored = Object.keys(errors);
|
|
5069
|
+
if (fileErrored.length) {
|
|
5070
|
+
log(
|
|
5071
|
+
`Couldn't write files.
|
|
5072
|
+
${fileErrored.map(
|
|
5073
|
+
(file) => ` - ${file}: ${errors[file].toString()}`
|
|
5074
|
+
)}`,
|
|
5075
|
+
"error"
|
|
5076
|
+
);
|
|
5077
|
+
}
|
|
5078
|
+
} catch (e) {
|
|
5079
|
+
log(`Couldn't write files. ${e}`, "error");
|
|
5039
5080
|
}
|
|
5040
|
-
return metric.value > thresholds[metric.type] ? metric : null;
|
|
5041
|
-
};
|
|
5042
|
-
const defaultFilters = [
|
|
5043
|
-
filterTreeMetrics,
|
|
5044
|
-
filterSourcemapsAndNodeModules,
|
|
5045
|
-
filterMetricsOnThreshold
|
|
5046
|
-
];
|
|
5047
|
-
const getMetric = (metric, opts) => ({
|
|
5048
|
-
type: "gauge",
|
|
5049
|
-
tags: [...metric.tags, ...opts.tags],
|
|
5050
|
-
metric: `${opts.prefix ? `${opts.prefix}.` : ""}${metric.metric}`,
|
|
5051
|
-
points: [[opts.timestamp, metric.value]]
|
|
5052
|
-
});
|
|
5053
|
-
const flattened = (arr) => [].concat(...arr);
|
|
5054
|
-
const getType = (name) => name.includes(".") ? name.split(".").pop() : "unknown";
|
|
5055
|
-
const getOptionsDD = (opt) => {
|
|
5056
|
-
const options = opt[CONFIG_KEY];
|
|
5057
|
-
return {
|
|
5058
|
-
timestamp: Math.floor((options.datadog?.timestamp || Date.now()) / 1e3),
|
|
5059
|
-
apiKey: opt.auth.apiKey || "",
|
|
5060
|
-
tags: options.datadog?.tags || [],
|
|
5061
|
-
endPoint: options.datadog?.endPoint || "app.datadoghq.com",
|
|
5062
|
-
prefix: options.datadog?.prefix || "",
|
|
5063
|
-
filters: options.datadog?.filters || defaultFilters
|
|
5064
|
-
};
|
|
5065
5081
|
};
|
|
5066
5082
|
|
|
5067
5083
|
const getGeneralReport = (report, bundler) => {
|
|
@@ -5615,19 +5631,24 @@ const getMetrics = (opts, report, bundler) => {
|
|
|
5615
5631
|
};
|
|
5616
5632
|
|
|
5617
5633
|
const sendMetrics = (metrics, opts) => {
|
|
5634
|
+
const log = getLogFn(opts.logLevel, PLUGIN_NAME);
|
|
5635
|
+
if (!opts.auth?.apiKey) {
|
|
5636
|
+
log(`Won't send metrics to Datadog: missing API Key.`, "warn");
|
|
5637
|
+
return;
|
|
5638
|
+
}
|
|
5618
5639
|
if (!metrics || !metrics.length) {
|
|
5619
5640
|
throw new Error("No metrics to send.");
|
|
5620
5641
|
}
|
|
5621
5642
|
const metricsNames = [...new Set(metrics.map((m) => m.metric))].sort().map((name) => `${name} - ${metrics.filter((m) => m.metric === name).length}`);
|
|
5622
|
-
|
|
5643
|
+
log(`
|
|
5623
5644
|
Sending ${metrics.length} metrics.
|
|
5624
5645
|
Metrics:
|
|
5625
5646
|
- ${metricsNames.join("\n - ")}`);
|
|
5626
5647
|
return new Promise((resolve, reject) => {
|
|
5627
5648
|
const req = request({
|
|
5628
5649
|
method: "POST",
|
|
5629
|
-
hostname: opts.endPoint,
|
|
5630
|
-
path: `/api/v1/series?api_key=${opts.apiKey}`
|
|
5650
|
+
hostname: opts.auth?.endPoint || "app.datadoghq.com",
|
|
5651
|
+
path: `/api/v1/series?api_key=${opts.auth?.apiKey}`
|
|
5631
5652
|
});
|
|
5632
5653
|
req.write(
|
|
5633
5654
|
JSON.stringify({
|
|
@@ -5652,18 +5673,20 @@ Status Code: ${res.statusCode}`);
|
|
|
5652
5673
|
|
|
5653
5674
|
const addMetrics = (context, options) => {
|
|
5654
5675
|
const { report, bundler } = context;
|
|
5676
|
+
const log = getLogFn(options.logLevel, PLUGIN_NAME);
|
|
5655
5677
|
context.metrics = context.metrics || [];
|
|
5656
5678
|
try {
|
|
5657
5679
|
context.metrics = getMetrics(options, report, bundler);
|
|
5658
5680
|
} catch (e) {
|
|
5659
5681
|
const stack = e instanceof Error ? e.stack : e;
|
|
5660
|
-
|
|
5682
|
+
log(`Couldn't aggregate metrics: ${stack}`, "error");
|
|
5661
5683
|
}
|
|
5662
5684
|
};
|
|
5663
5685
|
const processMetrics = async (context, options) => {
|
|
5664
5686
|
const { start } = context;
|
|
5665
5687
|
const duration = Date.now() - start;
|
|
5666
5688
|
const optionsDD = getOptionsDD(options);
|
|
5689
|
+
const log = getLogFn(options.logLevel, PLUGIN_NAME);
|
|
5667
5690
|
context.metrics = context.metrics || [];
|
|
5668
5691
|
context.metrics.push(
|
|
5669
5692
|
getMetric(
|
|
@@ -5676,20 +5699,17 @@ const processMetrics = async (context, options) => {
|
|
|
5676
5699
|
optionsDD
|
|
5677
5700
|
)
|
|
5678
5701
|
);
|
|
5679
|
-
|
|
5680
|
-
if (!
|
|
5681
|
-
|
|
5702
|
+
log(`Took ${formatDuration(duration)}.`);
|
|
5703
|
+
if (!options.auth?.apiKey) {
|
|
5704
|
+
log(`Won't send metrics to ${chalk.bold("Datadog")}: missing API Key.`, "warn");
|
|
5682
5705
|
return;
|
|
5683
5706
|
}
|
|
5684
5707
|
try {
|
|
5685
5708
|
const startSending = Date.now();
|
|
5686
|
-
await sendMetrics(context.metrics,
|
|
5687
|
-
|
|
5688
|
-
endPoint: optionsDD.endPoint
|
|
5689
|
-
});
|
|
5690
|
-
console.log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
|
|
5709
|
+
await sendMetrics(context.metrics, options);
|
|
5710
|
+
log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
|
|
5691
5711
|
} catch (e) {
|
|
5692
|
-
|
|
5712
|
+
log(`Error sending metrics ${e}`, "error");
|
|
5693
5713
|
}
|
|
5694
5714
|
};
|
|
5695
5715
|
|
|
@@ -5833,31 +5853,38 @@ const sortDesc = (attr) => (a, b) => {
|
|
|
5833
5853
|
return 0;
|
|
5834
5854
|
}
|
|
5835
5855
|
};
|
|
5836
|
-
const
|
|
5856
|
+
const getOutput = (values, renderValue) => {
|
|
5857
|
+
let output = "";
|
|
5837
5858
|
for (const val of values.slice(0, TOP)) {
|
|
5838
|
-
|
|
5859
|
+
output += `[${numColor(renderValue(val))}] ${nameColor(val.name)}
|
|
5860
|
+
`;
|
|
5839
5861
|
}
|
|
5862
|
+
return output;
|
|
5840
5863
|
};
|
|
5841
5864
|
const outputTapables = (timings) => {
|
|
5865
|
+
let output = "";
|
|
5842
5866
|
if (!timings) {
|
|
5843
|
-
return;
|
|
5867
|
+
return output;
|
|
5844
5868
|
}
|
|
5845
5869
|
const times = Array.from(timings.values());
|
|
5846
5870
|
if (!times.length) {
|
|
5847
|
-
return;
|
|
5871
|
+
return output;
|
|
5848
5872
|
}
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
=== Top ${TOP} duration
|
|
5873
|
+
output += "\n===== Tapables =====\n";
|
|
5874
|
+
output += `
|
|
5875
|
+
=== Top ${TOP} duration ===
|
|
5876
|
+
`;
|
|
5852
5877
|
times.sort(sortDesc("duration"));
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
=== Top ${TOP} hits
|
|
5878
|
+
output += getOutput(times, (time) => formatDuration(time.duration));
|
|
5879
|
+
output += `
|
|
5880
|
+
=== Top ${TOP} hits ===
|
|
5881
|
+
`;
|
|
5856
5882
|
times.sort(sortDesc("increment"));
|
|
5857
|
-
|
|
5883
|
+
output += getOutput(times, (plugin) => plugin.increment);
|
|
5884
|
+
return output;
|
|
5858
5885
|
};
|
|
5859
5886
|
const outputWebpack = (stats) => {
|
|
5860
|
-
|
|
5887
|
+
let output = "\n===== General =====\n";
|
|
5861
5888
|
const duration = stats.endTime - stats.startTime;
|
|
5862
5889
|
const nbDeps = stats.compilation.fileDependencies.size;
|
|
5863
5890
|
const nbFiles = stats.compilation.assets ? Object.keys(stats.compilation.assets).length : stats.compilation.emittedAssets.size;
|
|
@@ -5865,105 +5892,135 @@ const outputWebpack = (stats) => {
|
|
|
5865
5892
|
const nbModules = "size" in stats.compilation.modules ? stats.compilation.modules.size : stats.compilation.modules.length;
|
|
5866
5893
|
const nbChunks = "size" in stats.compilation.chunks ? stats.compilation.chunks.size : stats.compilation.chunks.length;
|
|
5867
5894
|
const nbEntries = "size" in stats.compilation.entries ? stats.compilation.entries.size : stats.compilation.entries.length;
|
|
5868
|
-
|
|
5895
|
+
output += `duration: ${chalk.bold(formatDuration(duration))}
|
|
5869
5896
|
nbDeps: ${chalk.bold(nbDeps.toString())}
|
|
5870
5897
|
nbFiles: ${chalk.bold(nbFiles.toString())}
|
|
5871
5898
|
nbWarnings: ${chalk.bold(nbWarnings.toString())}
|
|
5872
5899
|
nbModules: ${chalk.bold(nbModules.toString())}
|
|
5873
5900
|
nbChunks: ${chalk.bold(nbChunks.toString())}
|
|
5874
5901
|
nbEntries: ${chalk.bold(nbEntries.toString())}
|
|
5875
|
-
|
|
5902
|
+
`;
|
|
5903
|
+
return output;
|
|
5876
5904
|
};
|
|
5877
5905
|
const outputEsbuild = (stats) => {
|
|
5878
|
-
|
|
5906
|
+
let output = "\n===== General =====\n";
|
|
5879
5907
|
const nbDeps = stats.inputs ? Object.keys(stats.inputs).length : 0;
|
|
5880
5908
|
const nbFiles = stats.outputs ? Object.keys(stats.outputs).length : 0;
|
|
5881
5909
|
const nbWarnings = stats.warnings.length;
|
|
5882
5910
|
const nbErrors = stats.errors.length;
|
|
5883
5911
|
const nbEntries = stats.entrypoints ? Object.keys(stats.entrypoints).length : 0;
|
|
5884
|
-
|
|
5912
|
+
output += `
|
|
5885
5913
|
nbDeps: ${chalk.bold(nbDeps.toString())}
|
|
5886
5914
|
nbFiles: ${chalk.bold(nbFiles.toString())}
|
|
5887
5915
|
nbWarnings: ${chalk.bold(nbWarnings.toString())}
|
|
5888
5916
|
nbErrors: ${chalk.bold(nbErrors.toString())}
|
|
5889
5917
|
nbEntries: ${chalk.bold(nbEntries.toString())}
|
|
5890
|
-
|
|
5918
|
+
`;
|
|
5919
|
+
return output;
|
|
5891
5920
|
};
|
|
5892
5921
|
const outputLoaders = (timings) => {
|
|
5922
|
+
let output = "";
|
|
5893
5923
|
if (!timings) {
|
|
5894
|
-
return;
|
|
5924
|
+
return output;
|
|
5895
5925
|
}
|
|
5896
5926
|
const times = Array.from(timings.values());
|
|
5897
5927
|
if (!times.length) {
|
|
5898
|
-
return;
|
|
5928
|
+
return output;
|
|
5929
|
+
}
|
|
5930
|
+
output += "\n===== Loaders =====\n";
|
|
5931
|
+
output += `
|
|
5932
|
+
=== Top ${TOP} duration ===
|
|
5933
|
+
`;
|
|
5934
|
+
times.sort(sortDesc("duration"));
|
|
5935
|
+
output += getOutput(times, (loader) => formatDuration(loader.duration));
|
|
5936
|
+
output += `
|
|
5937
|
+
=== Top ${TOP} hits ===
|
|
5938
|
+
`;
|
|
5939
|
+
times.sort(sortDesc("increment"));
|
|
5940
|
+
output += getOutput(times, (loader) => loader.increment);
|
|
5941
|
+
return output;
|
|
5942
|
+
};
|
|
5943
|
+
const outputModulesDependencies = (deps) => {
|
|
5944
|
+
let output = "";
|
|
5945
|
+
if (!deps) {
|
|
5946
|
+
return output;
|
|
5947
|
+
}
|
|
5948
|
+
const dependencies = Object.values(deps);
|
|
5949
|
+
if (!dependencies.length) {
|
|
5950
|
+
return output;
|
|
5951
|
+
}
|
|
5952
|
+
output += "\n===== Modules =====\n";
|
|
5953
|
+
dependencies.sort(sortDesc((mod) => mod.dependents.length));
|
|
5954
|
+
output += `
|
|
5955
|
+
=== Top ${TOP} dependents ===
|
|
5956
|
+
`;
|
|
5957
|
+
output += getOutput(dependencies, (module) => module.dependents.length);
|
|
5958
|
+
dependencies.sort(sortDesc((mod) => mod.dependencies.length));
|
|
5959
|
+
output += `
|
|
5960
|
+
=== Top ${TOP} dependencies ===
|
|
5961
|
+
`;
|
|
5962
|
+
output += getOutput(dependencies, (module) => module.dependencies.length);
|
|
5963
|
+
dependencies.sort(sortDesc("size"));
|
|
5964
|
+
output += `
|
|
5965
|
+
=== Top ${TOP} size ===
|
|
5966
|
+
`;
|
|
5967
|
+
output += getOutput(dependencies, (module) => prettyBytes$1(module.size));
|
|
5968
|
+
return output;
|
|
5969
|
+
};
|
|
5970
|
+
const outputModulesTimings = (timings) => {
|
|
5971
|
+
let output = "";
|
|
5972
|
+
if (!timings) {
|
|
5973
|
+
return output;
|
|
5974
|
+
}
|
|
5975
|
+
const times = Array.from(timings.values());
|
|
5976
|
+
if (!times.length) {
|
|
5977
|
+
return output;
|
|
5899
5978
|
}
|
|
5900
|
-
|
|
5901
|
-
console.log(`
|
|
5902
|
-
=== Top ${TOP} duration ===`);
|
|
5979
|
+
output += "\n===== Modules =====\n";
|
|
5903
5980
|
times.sort(sortDesc("duration"));
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5981
|
+
output += `
|
|
5982
|
+
=== Top ${TOP} duration ===
|
|
5983
|
+
`;
|
|
5984
|
+
output += getOutput(times, (module) => formatDuration(module.duration));
|
|
5907
5985
|
times.sort(sortDesc("increment"));
|
|
5908
|
-
|
|
5986
|
+
output += `
|
|
5987
|
+
=== Top ${TOP} hits ===
|
|
5988
|
+
`;
|
|
5989
|
+
output += getOutput(times, (module) => module.increment);
|
|
5990
|
+
return output;
|
|
5909
5991
|
};
|
|
5910
|
-
const
|
|
5911
|
-
if (
|
|
5912
|
-
return;
|
|
5992
|
+
const shouldShowOutput = (output) => {
|
|
5993
|
+
if (typeof output === "boolean") {
|
|
5994
|
+
return output;
|
|
5913
5995
|
}
|
|
5914
|
-
if (
|
|
5915
|
-
|
|
5916
|
-
if (!dependencies.length) {
|
|
5917
|
-
return;
|
|
5918
|
-
}
|
|
5919
|
-
console.log("\n===== Modules =====");
|
|
5920
|
-
dependencies.sort(sortDesc((mod) => mod.dependents.length));
|
|
5921
|
-
console.log(`
|
|
5922
|
-
=== Top ${TOP} dependents ===`);
|
|
5923
|
-
render(dependencies, (module) => module.dependents.length);
|
|
5924
|
-
dependencies.sort(sortDesc((mod) => mod.dependencies.length));
|
|
5925
|
-
console.log(`
|
|
5926
|
-
=== Top ${TOP} dependencies ===`);
|
|
5927
|
-
render(dependencies, (module) => module.dependencies.length);
|
|
5928
|
-
dependencies.sort(sortDesc("size"));
|
|
5929
|
-
console.log(`
|
|
5930
|
-
=== Top ${TOP} size ===`);
|
|
5931
|
-
render(dependencies, (module) => prettyBytes$1(module.size));
|
|
5996
|
+
if (typeof output === "string") {
|
|
5997
|
+
return true;
|
|
5932
5998
|
}
|
|
5933
|
-
if (
|
|
5934
|
-
|
|
5935
|
-
if (!times.length) {
|
|
5936
|
-
return;
|
|
5937
|
-
}
|
|
5938
|
-
console.log("\n===== Modules =====");
|
|
5939
|
-
times.sort(sortDesc("duration"));
|
|
5940
|
-
console.log(`
|
|
5941
|
-
=== Top ${TOP} duration ===`);
|
|
5942
|
-
render(times, (module) => formatDuration(module.duration));
|
|
5943
|
-
times.sort(sortDesc("increment"));
|
|
5944
|
-
console.log(`
|
|
5945
|
-
=== Top ${TOP} hits ===`);
|
|
5946
|
-
render(times, (module) => module.increment);
|
|
5999
|
+
if (!output) {
|
|
6000
|
+
return true;
|
|
5947
6001
|
}
|
|
6002
|
+
return output.logs !== false;
|
|
5948
6003
|
};
|
|
5949
6004
|
const outputTexts = (context, options) => {
|
|
5950
6005
|
const { output } = options[CONFIG_KEY];
|
|
5951
6006
|
const { report, bundler } = context;
|
|
5952
|
-
if (output
|
|
6007
|
+
if (!shouldShowOutput(output)) {
|
|
5953
6008
|
return;
|
|
5954
6009
|
}
|
|
6010
|
+
let outputString = "";
|
|
5955
6011
|
if (report) {
|
|
5956
|
-
outputTapables(report.timings.tapables);
|
|
5957
|
-
outputLoaders(report.timings.loaders);
|
|
5958
|
-
|
|
6012
|
+
outputString += outputTapables(report.timings.tapables);
|
|
6013
|
+
outputString += outputLoaders(report.timings.loaders);
|
|
6014
|
+
outputString += outputModulesDependencies(report.dependencies);
|
|
6015
|
+
outputString += outputModulesTimings(report.timings.modules);
|
|
5959
6016
|
}
|
|
5960
6017
|
if (bundler.webpack) {
|
|
5961
|
-
outputWebpack(bundler.webpack);
|
|
6018
|
+
outputString += outputWebpack(bundler.webpack);
|
|
5962
6019
|
}
|
|
5963
6020
|
if (bundler.esbuild) {
|
|
5964
|
-
outputEsbuild(bundler.esbuild);
|
|
6021
|
+
outputString += outputEsbuild(bundler.esbuild);
|
|
5965
6022
|
}
|
|
5966
|
-
console.log();
|
|
6023
|
+
console.log(outputString);
|
|
5967
6024
|
};
|
|
5968
6025
|
|
|
5969
6026
|
const output = async (context, options) => {
|
|
@@ -6034,10 +6091,13 @@ const wrapPlugins = (build, context) => {
|
|
|
6034
6091
|
};
|
|
6035
6092
|
});
|
|
6036
6093
|
for (const plugin of plugins) {
|
|
6037
|
-
|
|
6094
|
+
if (plugin.name === PLUGIN_NAME) {
|
|
6095
|
+
continue;
|
|
6096
|
+
}
|
|
6038
6097
|
const oldSetup = plugin.setup;
|
|
6039
|
-
plugin.setup = () => {
|
|
6040
|
-
|
|
6098
|
+
plugin.setup = async (esbuild) => {
|
|
6099
|
+
const newBuildObject = getNewBuildObject(esbuild, plugin.name, context);
|
|
6100
|
+
await oldSetup({
|
|
6041
6101
|
...newBuildObject,
|
|
6042
6102
|
// Use non-modified plugins for other plugins
|
|
6043
6103
|
initialOptions: { ...newBuildObject.initialOptions, plugins: initialPlugins }
|
|
@@ -6496,11 +6556,13 @@ const getWebpackPlugin$1 = (opt) => {
|
|
|
6496
6556
|
};
|
|
6497
6557
|
};
|
|
6498
6558
|
|
|
6559
|
+
const helpers$1 = {
|
|
6560
|
+
filters: defaultFilters
|
|
6561
|
+
};
|
|
6499
6562
|
const getPlugins = (opt) => {
|
|
6500
6563
|
return [
|
|
6501
6564
|
{
|
|
6502
6565
|
name: PLUGIN_NAME,
|
|
6503
|
-
enforce: "post",
|
|
6504
6566
|
esbuild: getEsbuildPlugin$1(opt),
|
|
6505
6567
|
webpack: getWebpackPlugin$1(opt)
|
|
6506
6568
|
}
|
|
@@ -18121,6 +18183,12 @@ function createUnplugin(factory) {
|
|
|
18121
18183
|
};
|
|
18122
18184
|
}
|
|
18123
18185
|
|
|
18186
|
+
const helpers = {
|
|
18187
|
+
// Each product should have a unique entry.
|
|
18188
|
+
// #helpers-injection-marker
|
|
18189
|
+
[CONFIG_KEY]: helpers$1
|
|
18190
|
+
// #helpers-injection-marker
|
|
18191
|
+
};
|
|
18124
18192
|
const buildPluginFactory = () => {
|
|
18125
18193
|
return createUnplugin((userOptions, unpluginMetaContext) => {
|
|
18126
18194
|
const options = {
|
|
@@ -18136,7 +18204,6 @@ const buildPluginFactory = () => {
|
|
|
18136
18204
|
};
|
|
18137
18205
|
|
|
18138
18206
|
const datadogWebpackPlugin = buildPluginFactory().webpack;
|
|
18139
|
-
module.exports = datadogWebpackPlugin;
|
|
18140
18207
|
|
|
18141
|
-
export { datadogWebpackPlugin,
|
|
18208
|
+
export { datadogWebpackPlugin, helpers };
|
|
18142
18209
|
//# sourceMappingURL=index.mjs.map
|