@datadog/webpack-plugin 0.0.13-4 → 0.0.13-5

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.
@@ -16,6 +16,66 @@ import process2 from 'process';
16
16
  const CONFIG_KEY = "telemetry";
17
17
  const PLUGIN_NAME = `${CONFIG_KEY}-plugin`;
18
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
+ };
78
+
19
79
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
20
80
 
21
81
  function getDefaultExportFromCjs (x) {
@@ -3034,129 +3094,6 @@ const getContext = (args) => {
3034
3094
  value: typeof arg === "string" ? arg : void 0
3035
3095
  }));
3036
3096
  };
3037
- const filterTreeMetrics = (metric) => (
3038
- // Remove tree metrics because way too verbose
3039
- !/modules\.tree\.(count|size)$/.test(metric.metric) ? metric : null
3040
- );
3041
- const filterSourcemapsAndNodeModules = (metric) => metric.tags.some(
3042
- (tag) => (
3043
- // Remove sourcemaps.
3044
- /^assetName:.*\.map$/.test(tag) || // Remove third parties.
3045
- /^moduleName:\/node_modules/.test(tag)
3046
- )
3047
- ) ? null : metric;
3048
- const filterMetricsOnThreshold = (metric) => {
3049
- const thresholds = {
3050
- size: 1e5,
3051
- count: 10,
3052
- duration: 1e3
3053
- };
3054
- if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
3055
- thresholds.count = 0;
3056
- }
3057
- if (/(modules\.(dependencies|dependents)$)/.test(metric.metric)) {
3058
- thresholds.count = 30;
3059
- }
3060
- if (/modules\.tree\.count$/.test(metric.metric)) {
3061
- thresholds.count = 150;
3062
- }
3063
- if (/modules\.tree\.size$/.test(metric.metric)) {
3064
- thresholds.size = 15e5;
3065
- }
3066
- if (/entries\.size$/.test(metric.metric)) {
3067
- thresholds.size = 0;
3068
- }
3069
- if (/entries\.modules\.count$/.test(metric.metric)) {
3070
- thresholds.count = 0;
3071
- }
3072
- return metric.value > thresholds[metric.type] ? metric : null;
3073
- };
3074
- const defaultTelemetryFilters = [
3075
- filterTreeMetrics,
3076
- filterSourcemapsAndNodeModules,
3077
- filterMetricsOnThreshold
3078
- ];
3079
-
3080
- const outputFiles = async (context, options) => {
3081
- const { report, metrics, bundler } = context;
3082
- const opts = options[CONFIG_KEY].output;
3083
- if (typeof opts !== "string" && typeof opts !== "object") {
3084
- return;
3085
- }
3086
- const startWriting = Date.now();
3087
- let destination;
3088
- const files = {
3089
- timings: true,
3090
- dependencies: true,
3091
- bundler: true,
3092
- metrics: true,
3093
- result: true
3094
- };
3095
- if (typeof opts === "object") {
3096
- destination = opts.destination;
3097
- files.timings = opts.timings || false;
3098
- files.dependencies = opts.dependencies || false;
3099
- files.bundler = opts.bundler || false;
3100
- files.metrics = opts.metrics || false;
3101
- } else {
3102
- destination = opts;
3103
- }
3104
- const outputPath = require$$1.resolve(options.cwd, destination);
3105
- try {
3106
- const errors = {};
3107
- const filesToWrite = {};
3108
- if (files.timings && report?.timings) {
3109
- filesToWrite.timings = {
3110
- content: {
3111
- tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
3112
- loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
3113
- modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
3114
- }
3115
- };
3116
- }
3117
- if (files.dependencies && report?.dependencies) {
3118
- filesToWrite.dependencies = { content: report.dependencies };
3119
- }
3120
- if (files.bundler) {
3121
- if (bundler.webpack) {
3122
- filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
3123
- }
3124
- if (bundler.esbuild) {
3125
- filesToWrite.bundler = { content: bundler.esbuild };
3126
- }
3127
- }
3128
- if (metrics && files.metrics) {
3129
- filesToWrite.metrics = { content: metrics };
3130
- }
3131
- const proms = Object.keys(filesToWrite).map((file) => {
3132
- const start = Date.now();
3133
- console.log(`Start writing ${file}.json.`);
3134
- return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
3135
- console.log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
3136
- }).catch((e) => {
3137
- console.log(
3138
- `Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
3139
- "error"
3140
- );
3141
- errors[file] = e;
3142
- });
3143
- });
3144
- await Promise.all(proms);
3145
- console.log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
3146
- const fileErrored = Object.keys(errors);
3147
- if (fileErrored.length) {
3148
- console.log(
3149
- `Couldn't write files.
3150
- ${fileErrored.map(
3151
- (file) => ` - ${file}: ${errors[file].toString()}`
3152
- )}`,
3153
- "error"
3154
- );
3155
- }
3156
- } catch (e) {
3157
- console.log(`Couldn't write files. ${e}`, "error");
3158
- }
3159
- };
3160
3097
 
3161
3098
  var chalk$1 = {exports: {}};
3162
3099
 
@@ -5044,24 +4981,103 @@ var templates = (chalk, tmp) => {
5044
4981
  var chalkExports = chalk$1.exports;
5045
4982
  var chalk = /*@__PURE__*/getDefaultExportFromCjs(chalkExports);
5046
4983
 
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 || defaultTelemetryFilters
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;
4993
+ }
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)}`);
4997
+ }
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;
5006
+ }
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
5064
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;
5024
+ }
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");
5080
+ }
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
- console.log(`
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
- console.log(`Couldn't aggregate metrics: ${stack}`, "error");
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
- console.log(`Took ${formatDuration(duration)}.`);
5680
- if (!optionsDD.apiKey) {
5681
- console.log(`Won't send metrics to ${chalk.bold("Datadog")}: missing API Key.`, "warn");
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
- apiKey: optionsDD.apiKey,
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
- console.log(`Error sending metrics ${e}`, "error");
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 render = (values, renderValue) => {
5856
+ const getOutput = (values, renderValue) => {
5857
+ let st = "";
5837
5858
  for (const val of values.slice(0, TOP)) {
5838
- console.log(`[${numColor(renderValue(val))}] ${nameColor(val.name)}`);
5859
+ st += `[${numColor(renderValue(val))}] ${nameColor(val.name)}
5860
+ `;
5839
5861
  }
5862
+ return st;
5840
5863
  };
5841
5864
  const outputTapables = (timings) => {
5865
+ let st = "";
5842
5866
  if (!timings) {
5843
- return;
5867
+ return st;
5844
5868
  }
5845
5869
  const times = Array.from(timings.values());
5846
5870
  if (!times.length) {
5847
- return;
5871
+ return st;
5848
5872
  }
5849
- console.log("\n===== Tapables =====");
5850
- console.log(`
5851
- === Top ${TOP} duration ===`);
5873
+ st += "\n===== Tapables =====\n";
5874
+ st += `
5875
+ === Top ${TOP} duration ===
5876
+ `;
5852
5877
  times.sort(sortDesc("duration"));
5853
- render(times, (time) => formatDuration(time.duration));
5854
- console.log(`
5855
- === Top ${TOP} hits ===`);
5878
+ st += getOutput(times, (time) => formatDuration(time.duration));
5879
+ st += `
5880
+ === Top ${TOP} hits ===
5881
+ `;
5856
5882
  times.sort(sortDesc("increment"));
5857
- render(times, (plugin) => plugin.increment);
5883
+ st += getOutput(times, (plugin) => plugin.increment);
5884
+ return st;
5858
5885
  };
5859
5886
  const outputWebpack = (stats) => {
5860
- console.log("\n===== General =====");
5887
+ let st = "\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,124 @@ 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
- console.log(`duration: ${chalk.bold(formatDuration(duration))}
5895
+ st += `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 st;
5876
5904
  };
5877
5905
  const outputEsbuild = (stats) => {
5878
- console.log("\n===== General =====");
5906
+ let st = "\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
- console.log(`
5912
+ st += `
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 st;
5891
5920
  };
5892
5921
  const outputLoaders = (timings) => {
5922
+ let st = "";
5893
5923
  if (!timings) {
5894
- return;
5924
+ return st;
5895
5925
  }
5896
5926
  const times = Array.from(timings.values());
5897
5927
  if (!times.length) {
5898
- return;
5928
+ return st;
5899
5929
  }
5900
- console.log("\n===== Loaders =====");
5901
- console.log(`
5902
- === Top ${TOP} duration ===`);
5930
+ st += "\n===== Loaders =====\n";
5931
+ st += `
5932
+ === Top ${TOP} duration ===
5933
+ `;
5903
5934
  times.sort(sortDesc("duration"));
5904
- render(times, (loader) => formatDuration(loader.duration));
5905
- console.log(`
5906
- === Top ${TOP} hits ===`);
5935
+ st += getOutput(times, (loader) => formatDuration(loader.duration));
5936
+ st += `
5937
+ === Top ${TOP} hits ===
5938
+ `;
5907
5939
  times.sort(sortDesc("increment"));
5908
- render(times, (loader) => loader.increment);
5909
- };
5910
- const outputModules = (deps, timings) => {
5911
- if (!deps && !timings) {
5912
- return;
5913
- }
5914
- if (deps) {
5915
- const dependencies = Object.values(deps);
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));
5940
+ st += getOutput(times, (loader) => loader.increment);
5941
+ return st;
5942
+ };
5943
+ const outputModulesDependencies = (deps) => {
5944
+ let st = "";
5945
+ if (!deps) {
5946
+ return st;
5947
+ }
5948
+ const dependencies = Object.values(deps);
5949
+ if (!dependencies.length) {
5950
+ return st;
5951
+ }
5952
+ st += "\n===== Modules =====\n";
5953
+ dependencies.sort(sortDesc((mod) => mod.dependents.length));
5954
+ st += `
5955
+ === Top ${TOP} dependents ===
5956
+ `;
5957
+ st += getOutput(dependencies, (module) => module.dependents.length);
5958
+ dependencies.sort(sortDesc((mod) => mod.dependencies.length));
5959
+ st += `
5960
+ === Top ${TOP} dependencies ===
5961
+ `;
5962
+ st += getOutput(dependencies, (module) => module.dependencies.length);
5963
+ dependencies.sort(sortDesc("size"));
5964
+ st += `
5965
+ === Top ${TOP} size ===
5966
+ `;
5967
+ st += getOutput(dependencies, (module) => prettyBytes$1(module.size));
5968
+ return st;
5969
+ };
5970
+ const outputModulesTimings = (timings) => {
5971
+ let st = "";
5972
+ if (!timings) {
5973
+ return st;
5932
5974
  }
5933
- if (timings) {
5934
- const times = Array.from(timings.values());
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);
5975
+ const times = Array.from(timings.values());
5976
+ if (!times.length) {
5977
+ return st;
5947
5978
  }
5979
+ st += "\n===== Modules =====\n";
5980
+ times.sort(sortDesc("duration"));
5981
+ st += `
5982
+ === Top ${TOP} duration ===
5983
+ `;
5984
+ st += getOutput(times, (module) => formatDuration(module.duration));
5985
+ times.sort(sortDesc("increment"));
5986
+ st += `
5987
+ === Top ${TOP} hits ===
5988
+ `;
5989
+ st += getOutput(times, (module) => module.increment);
5990
+ return st;
5948
5991
  };
5949
5992
  const outputTexts = (context, options) => {
5950
5993
  const { output } = options[CONFIG_KEY];
5951
5994
  const { report, bundler } = context;
5995
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5952
5996
  if (output === false) {
5953
5997
  return;
5954
5998
  }
5999
+ let st = "";
5955
6000
  if (report) {
5956
- outputTapables(report.timings.tapables);
5957
- outputLoaders(report.timings.loaders);
5958
- outputModules(report.dependencies, report.timings.modules);
6001
+ st += outputTapables(report.timings.tapables);
6002
+ st += outputLoaders(report.timings.loaders);
6003
+ st += outputModulesDependencies(report.dependencies);
6004
+ st += outputModulesTimings(report.timings.modules);
5959
6005
  }
5960
6006
  if (bundler.webpack) {
5961
- outputWebpack(bundler.webpack);
6007
+ st += outputWebpack(bundler.webpack);
5962
6008
  }
5963
6009
  if (bundler.esbuild) {
5964
- outputEsbuild(bundler.esbuild);
6010
+ st += outputEsbuild(bundler.esbuild);
5965
6011
  }
5966
- console.log();
6012
+ log(st);
5967
6013
  };
5968
6014
 
5969
6015
  const output = async (context, options) => {
@@ -6496,11 +6542,14 @@ const getWebpackPlugin$1 = (opt) => {
6496
6542
  };
6497
6543
  };
6498
6544
 
6545
+ const helpers$1 = {
6546
+ filters: defaultFilters
6547
+ };
6499
6548
  const getPlugins = (opt) => {
6500
6549
  return [
6501
6550
  {
6502
6551
  name: PLUGIN_NAME,
6503
- enforce: "post",
6552
+ enforce: "pre",
6504
6553
  esbuild: getEsbuildPlugin$1(opt),
6505
6554
  webpack: getWebpackPlugin$1(opt)
6506
6555
  }
@@ -18121,6 +18170,12 @@ function createUnplugin(factory) {
18121
18170
  };
18122
18171
  }
18123
18172
 
18173
+ const helpers = {
18174
+ // Each product should have a unique entry.
18175
+ // #helpers-injection-marker
18176
+ [CONFIG_KEY]: helpers$1
18177
+ // #helpers-injection-marker
18178
+ };
18124
18179
  const buildPluginFactory = () => {
18125
18180
  return createUnplugin((userOptions, unpluginMetaContext) => {
18126
18181
  const options = {
@@ -18137,5 +18192,5 @@ const buildPluginFactory = () => {
18137
18192
 
18138
18193
  const datadogWebpackPlugin = buildPluginFactory().webpack;
18139
18194
 
18140
- export { datadogWebpackPlugin };
18195
+ export { datadogWebpackPlugin, helpers };
18141
18196
  //# sourceMappingURL=index.mjs.map