@datadog/esbuild-plugin 0.0.13-4 → 0.0.13-6

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/dist/src/index.js CHANGED
@@ -17,20 +17,20 @@ var process2 = require('process');
17
17
 
18
18
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
19
19
  function _interopNamespaceDefault(e) {
20
- var n = Object.create(null);
21
- if (e) {
22
- Object.keys(e).forEach(function (k) {
23
- if (k !== 'default') {
24
- var d = Object.getOwnPropertyDescriptor(e, k);
25
- Object.defineProperty(n, k, d.get ? d : {
26
- enumerable: true,
27
- get: function () { return e[k]; }
28
- });
29
- }
30
- });
31
- }
32
- n.default = e;
33
- return Object.freeze(n);
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ if (k !== 'default') {
24
+ var d = Object.getOwnPropertyDescriptor(e, k);
25
+ Object.defineProperty(n, k, d.get ? d : {
26
+ enumerable: true,
27
+ get: function () { return e[k]; }
28
+ });
29
+ }
30
+ });
31
+ }
32
+ n.default = e;
33
+ return Object.freeze(n);
34
34
  }
35
35
 
36
36
  var querystring__namespace = /*#__PURE__*/_interopNamespaceDefault(querystring);
@@ -38,6 +38,66 @@ var querystring__namespace = /*#__PURE__*/_interopNamespaceDefault(querystring);
38
38
  const CONFIG_KEY = "telemetry";
39
39
  const PLUGIN_NAME = `${CONFIG_KEY}-plugin`;
40
40
 
41
+ const filterTreeMetrics = (metric) => (
42
+ // Remove tree metrics because way too verbose
43
+ !/modules\.tree\.(count|size)$/.test(metric.metric) ? metric : null
44
+ );
45
+ const filterSourcemapsAndNodeModules = (metric) => metric.tags.some(
46
+ (tag) => (
47
+ // Remove sourcemaps.
48
+ /^assetName:.*\.map$/.test(tag) || // Remove third parties.
49
+ /^moduleName:\/node_modules/.test(tag)
50
+ )
51
+ ) ? null : metric;
52
+ const filterMetricsOnThreshold = (metric) => {
53
+ const thresholds = {
54
+ size: 1e5,
55
+ count: 10,
56
+ duration: 1e3
57
+ };
58
+ if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
59
+ thresholds.count = 0;
60
+ }
61
+ if (/(modules\.(dependencies|dependents)$)/.test(metric.metric)) {
62
+ thresholds.count = 30;
63
+ }
64
+ if (/modules\.tree\.count$/.test(metric.metric)) {
65
+ thresholds.count = 150;
66
+ }
67
+ if (/modules\.tree\.size$/.test(metric.metric)) {
68
+ thresholds.size = 15e5;
69
+ }
70
+ if (/entries\.size$/.test(metric.metric)) {
71
+ thresholds.size = 0;
72
+ }
73
+ if (/entries\.modules\.count$/.test(metric.metric)) {
74
+ thresholds.count = 0;
75
+ }
76
+ return metric.value > thresholds[metric.type] ? metric : null;
77
+ };
78
+ const defaultFilters = [
79
+ filterTreeMetrics,
80
+ filterSourcemapsAndNodeModules,
81
+ filterMetricsOnThreshold
82
+ ];
83
+ const getMetric = (metric, opts) => ({
84
+ type: "gauge",
85
+ tags: [...metric.tags, ...opts.tags],
86
+ metric: `${opts.prefix ? `${opts.prefix}.` : ""}${metric.metric}`,
87
+ points: [[opts.timestamp, metric.value]]
88
+ });
89
+ const flattened = (arr) => [].concat(...arr);
90
+ const getType = (name) => name.includes(".") ? name.split(".").pop() : "unknown";
91
+ const getOptionsDD = (opt) => {
92
+ const options = opt[CONFIG_KEY];
93
+ return {
94
+ timestamp: Math.floor((options.timestamp || Date.now()) / 1e3),
95
+ tags: options.tags || [],
96
+ prefix: options.prefix || "",
97
+ filters: options.filters || defaultFilters
98
+ };
99
+ };
100
+
41
101
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
42
102
 
43
103
  function getDefaultExportFromCjs (x) {
@@ -3056,129 +3116,6 @@ const getContext = (args) => {
3056
3116
  value: typeof arg === "string" ? arg : void 0
3057
3117
  }));
3058
3118
  };
3059
- const filterTreeMetrics = (metric) => (
3060
- // Remove tree metrics because way too verbose
3061
- !/modules\.tree\.(count|size)$/.test(metric.metric) ? metric : null
3062
- );
3063
- const filterSourcemapsAndNodeModules = (metric) => metric.tags.some(
3064
- (tag) => (
3065
- // Remove sourcemaps.
3066
- /^assetName:.*\.map$/.test(tag) || // Remove third parties.
3067
- /^moduleName:\/node_modules/.test(tag)
3068
- )
3069
- ) ? null : metric;
3070
- const filterMetricsOnThreshold = (metric) => {
3071
- const thresholds = {
3072
- size: 1e5,
3073
- count: 10,
3074
- duration: 1e3
3075
- };
3076
- if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
3077
- thresholds.count = 0;
3078
- }
3079
- if (/(modules\.(dependencies|dependents)$)/.test(metric.metric)) {
3080
- thresholds.count = 30;
3081
- }
3082
- if (/modules\.tree\.count$/.test(metric.metric)) {
3083
- thresholds.count = 150;
3084
- }
3085
- if (/modules\.tree\.size$/.test(metric.metric)) {
3086
- thresholds.size = 15e5;
3087
- }
3088
- if (/entries\.size$/.test(metric.metric)) {
3089
- thresholds.size = 0;
3090
- }
3091
- if (/entries\.modules\.count$/.test(metric.metric)) {
3092
- thresholds.count = 0;
3093
- }
3094
- return metric.value > thresholds[metric.type] ? metric : null;
3095
- };
3096
- const defaultTelemetryFilters = [
3097
- filterTreeMetrics,
3098
- filterSourcemapsAndNodeModules,
3099
- filterMetricsOnThreshold
3100
- ];
3101
-
3102
- const outputFiles = async (context, options) => {
3103
- const { report, metrics, bundler } = context;
3104
- const opts = options[CONFIG_KEY].output;
3105
- if (typeof opts !== "string" && typeof opts !== "object") {
3106
- return;
3107
- }
3108
- const startWriting = Date.now();
3109
- let destination;
3110
- const files = {
3111
- timings: true,
3112
- dependencies: true,
3113
- bundler: true,
3114
- metrics: true,
3115
- result: true
3116
- };
3117
- if (typeof opts === "object") {
3118
- destination = opts.destination;
3119
- files.timings = opts.timings || false;
3120
- files.dependencies = opts.dependencies || false;
3121
- files.bundler = opts.bundler || false;
3122
- files.metrics = opts.metrics || false;
3123
- } else {
3124
- destination = opts;
3125
- }
3126
- const outputPath = require$$1.resolve(options.cwd, destination);
3127
- try {
3128
- const errors = {};
3129
- const filesToWrite = {};
3130
- if (files.timings && report?.timings) {
3131
- filesToWrite.timings = {
3132
- content: {
3133
- tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
3134
- loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
3135
- modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
3136
- }
3137
- };
3138
- }
3139
- if (files.dependencies && report?.dependencies) {
3140
- filesToWrite.dependencies = { content: report.dependencies };
3141
- }
3142
- if (files.bundler) {
3143
- if (bundler.webpack) {
3144
- filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
3145
- }
3146
- if (bundler.esbuild) {
3147
- filesToWrite.bundler = { content: bundler.esbuild };
3148
- }
3149
- }
3150
- if (metrics && files.metrics) {
3151
- filesToWrite.metrics = { content: metrics };
3152
- }
3153
- const proms = Object.keys(filesToWrite).map((file) => {
3154
- const start = Date.now();
3155
- console.log(`Start writing ${file}.json.`);
3156
- return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
3157
- console.log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
3158
- }).catch((e) => {
3159
- console.log(
3160
- `Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
3161
- "error"
3162
- );
3163
- errors[file] = e;
3164
- });
3165
- });
3166
- await Promise.all(proms);
3167
- console.log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
3168
- const fileErrored = Object.keys(errors);
3169
- if (fileErrored.length) {
3170
- console.log(
3171
- `Couldn't write files.
3172
- ${fileErrored.map(
3173
- (file) => ` - ${file}: ${errors[file].toString()}`
3174
- )}`,
3175
- "error"
3176
- );
3177
- }
3178
- } catch (e) {
3179
- console.log(`Couldn't write files. ${e}`, "error");
3180
- }
3181
- };
3182
3119
 
3183
3120
  var chalk$1 = {exports: {}};
3184
3121
 
@@ -5066,24 +5003,103 @@ var templates = (chalk, tmp) => {
5066
5003
  var chalkExports = chalk$1.exports;
5067
5004
  var chalk = /*@__PURE__*/getDefaultExportFromCjs(chalkExports);
5068
5005
 
5069
- const getMetric = (metric, opts) => ({
5070
- type: "gauge",
5071
- tags: [...metric.tags, ...opts.tags],
5072
- metric: `${opts.prefix ? `${opts.prefix}.` : ""}${metric.metric}`,
5073
- points: [[opts.timestamp, metric.value]]
5074
- });
5075
- const flattened = (arr) => [].concat(...arr);
5076
- const getType = (name) => name.includes(".") ? name.split(".").pop() : "unknown";
5077
- const getOptionsDD = (opt) => {
5078
- const options = opt[CONFIG_KEY];
5079
- return {
5080
- timestamp: Math.floor((options.datadog?.timestamp || Date.now()) / 1e3),
5081
- apiKey: opt.auth.apiKey || "",
5082
- tags: options.datadog?.tags || [],
5083
- endPoint: options.datadog?.endPoint || "app.datadoghq.com",
5084
- prefix: options.datadog?.prefix || "",
5085
- filters: options.datadog?.filters || defaultTelemetryFilters
5006
+ const log = (text, level, type = "debug", name) => {
5007
+ let color = chalk;
5008
+ let logFn = console.log;
5009
+ if (type === "error") {
5010
+ color = chalk.red;
5011
+ logFn = console.error;
5012
+ } else if (type === "warn") {
5013
+ color = chalk.yellow;
5014
+ logFn = console.warn;
5015
+ }
5016
+ const prefix = name ? `[${chalk.bold(name)}] ` : "";
5017
+ if (level === "debug" || level === "warn" && ["error", "warn"].includes(type) || level === "error" && type === "error") {
5018
+ logFn(`${prefix}${color(text)}`);
5019
+ }
5020
+ };
5021
+ const getLogFn = (level = "warn", name) => (text, type = "debug") => log(text, level, type, name);
5022
+
5023
+ const outputFiles = async (context, options) => {
5024
+ const { report, metrics, bundler } = context;
5025
+ const opts = options[CONFIG_KEY].output;
5026
+ if (typeof opts !== "string" && typeof opts !== "object") {
5027
+ return;
5028
+ }
5029
+ const startWriting = Date.now();
5030
+ let destination;
5031
+ const files = {
5032
+ timings: true,
5033
+ dependencies: true,
5034
+ bundler: true,
5035
+ metrics: true,
5036
+ result: true
5086
5037
  };
5038
+ if (typeof opts === "object") {
5039
+ destination = opts.destination;
5040
+ files.timings = opts.timings || false;
5041
+ files.dependencies = opts.dependencies || false;
5042
+ files.bundler = opts.bundler || false;
5043
+ files.metrics = opts.metrics || false;
5044
+ } else {
5045
+ destination = opts;
5046
+ }
5047
+ const outputPath = require$$1.resolve(options.cwd, destination);
5048
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5049
+ try {
5050
+ const errors = {};
5051
+ const filesToWrite = {};
5052
+ if (files.timings && report?.timings) {
5053
+ filesToWrite.timings = {
5054
+ content: {
5055
+ tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
5056
+ loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
5057
+ modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
5058
+ }
5059
+ };
5060
+ }
5061
+ if (files.dependencies && report?.dependencies) {
5062
+ filesToWrite.dependencies = { content: report.dependencies };
5063
+ }
5064
+ if (files.bundler) {
5065
+ if (bundler.webpack) {
5066
+ filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
5067
+ }
5068
+ if (bundler.esbuild) {
5069
+ filesToWrite.bundler = { content: bundler.esbuild };
5070
+ }
5071
+ }
5072
+ if (metrics && files.metrics) {
5073
+ filesToWrite.metrics = { content: metrics };
5074
+ }
5075
+ const proms = Object.keys(filesToWrite).map((file) => {
5076
+ const start = Date.now();
5077
+ log(`Start writing ${file}.json.`);
5078
+ return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
5079
+ log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
5080
+ }).catch((e) => {
5081
+ log(
5082
+ `Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
5083
+ "error"
5084
+ );
5085
+ errors[file] = e;
5086
+ });
5087
+ });
5088
+ await Promise.all(proms);
5089
+ log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
5090
+ const fileErrored = Object.keys(errors);
5091
+ if (fileErrored.length) {
5092
+ log(
5093
+ `Couldn't write files.
5094
+ ${fileErrored.map(
5095
+ (file) => ` - ${file}: ${errors[file].toString()}`
5096
+ )}`,
5097
+ "error"
5098
+ );
5099
+ }
5100
+ } catch (e) {
5101
+ log(`Couldn't write files. ${e}`, "error");
5102
+ }
5087
5103
  };
5088
5104
 
5089
5105
  const getGeneralReport = (report, bundler) => {
@@ -5637,19 +5653,24 @@ const getMetrics = (opts, report, bundler) => {
5637
5653
  };
5638
5654
 
5639
5655
  const sendMetrics = (metrics, opts) => {
5656
+ const log = getLogFn(opts.logLevel, PLUGIN_NAME);
5657
+ if (!opts.auth?.apiKey) {
5658
+ log(`Won't send metrics to Datadog: missing API Key.`, "warn");
5659
+ return;
5660
+ }
5640
5661
  if (!metrics || !metrics.length) {
5641
5662
  throw new Error("No metrics to send.");
5642
5663
  }
5643
5664
  const metricsNames = [...new Set(metrics.map((m) => m.metric))].sort().map((name) => `${name} - ${metrics.filter((m) => m.metric === name).length}`);
5644
- console.log(`
5665
+ log(`
5645
5666
  Sending ${metrics.length} metrics.
5646
5667
  Metrics:
5647
5668
  - ${metricsNames.join("\n - ")}`);
5648
5669
  return new Promise((resolve, reject) => {
5649
5670
  const req = https.request({
5650
5671
  method: "POST",
5651
- hostname: opts.endPoint,
5652
- path: `/api/v1/series?api_key=${opts.apiKey}`
5672
+ hostname: opts.auth?.endPoint || "app.datadoghq.com",
5673
+ path: `/api/v1/series?api_key=${opts.auth?.apiKey}`
5653
5674
  });
5654
5675
  req.write(
5655
5676
  JSON.stringify({
@@ -5674,18 +5695,20 @@ Status Code: ${res.statusCode}`);
5674
5695
 
5675
5696
  const addMetrics = (context, options) => {
5676
5697
  const { report, bundler } = context;
5698
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5677
5699
  context.metrics = context.metrics || [];
5678
5700
  try {
5679
5701
  context.metrics = getMetrics(options, report, bundler);
5680
5702
  } catch (e) {
5681
5703
  const stack = e instanceof Error ? e.stack : e;
5682
- console.log(`Couldn't aggregate metrics: ${stack}`, "error");
5704
+ log(`Couldn't aggregate metrics: ${stack}`, "error");
5683
5705
  }
5684
5706
  };
5685
5707
  const processMetrics = async (context, options) => {
5686
5708
  const { start } = context;
5687
5709
  const duration = Date.now() - start;
5688
5710
  const optionsDD = getOptionsDD(options);
5711
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5689
5712
  context.metrics = context.metrics || [];
5690
5713
  context.metrics.push(
5691
5714
  getMetric(
@@ -5698,20 +5721,17 @@ const processMetrics = async (context, options) => {
5698
5721
  optionsDD
5699
5722
  )
5700
5723
  );
5701
- console.log(`Took ${formatDuration(duration)}.`);
5702
- if (!optionsDD.apiKey) {
5703
- console.log(`Won't send metrics to ${chalk.bold("Datadog")}: missing API Key.`, "warn");
5724
+ log(`Took ${formatDuration(duration)}.`);
5725
+ if (!options.auth?.apiKey) {
5726
+ log(`Won't send metrics to ${chalk.bold("Datadog")}: missing API Key.`, "warn");
5704
5727
  return;
5705
5728
  }
5706
5729
  try {
5707
5730
  const startSending = Date.now();
5708
- await sendMetrics(context.metrics, {
5709
- apiKey: optionsDD.apiKey,
5710
- endPoint: optionsDD.endPoint
5711
- });
5712
- console.log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
5731
+ await sendMetrics(context.metrics, options);
5732
+ log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
5713
5733
  } catch (e) {
5714
- console.log(`Error sending metrics ${e}`, "error");
5734
+ log(`Error sending metrics ${e}`, "error");
5715
5735
  }
5716
5736
  };
5717
5737
 
@@ -5855,31 +5875,38 @@ const sortDesc = (attr) => (a, b) => {
5855
5875
  return 0;
5856
5876
  }
5857
5877
  };
5858
- const render = (values, renderValue) => {
5878
+ const getOutput = (values, renderValue) => {
5879
+ let output = "";
5859
5880
  for (const val of values.slice(0, TOP)) {
5860
- console.log(`[${numColor(renderValue(val))}] ${nameColor(val.name)}`);
5881
+ output += `[${numColor(renderValue(val))}] ${nameColor(val.name)}
5882
+ `;
5861
5883
  }
5884
+ return output;
5862
5885
  };
5863
5886
  const outputTapables = (timings) => {
5887
+ let output = "";
5864
5888
  if (!timings) {
5865
- return;
5889
+ return output;
5866
5890
  }
5867
5891
  const times = Array.from(timings.values());
5868
5892
  if (!times.length) {
5869
- return;
5893
+ return output;
5870
5894
  }
5871
- console.log("\n===== Tapables =====");
5872
- console.log(`
5873
- === Top ${TOP} duration ===`);
5895
+ output += "\n===== Tapables =====\n";
5896
+ output += `
5897
+ === Top ${TOP} duration ===
5898
+ `;
5874
5899
  times.sort(sortDesc("duration"));
5875
- render(times, (time) => formatDuration(time.duration));
5876
- console.log(`
5877
- === Top ${TOP} hits ===`);
5900
+ output += getOutput(times, (time) => formatDuration(time.duration));
5901
+ output += `
5902
+ === Top ${TOP} hits ===
5903
+ `;
5878
5904
  times.sort(sortDesc("increment"));
5879
- render(times, (plugin) => plugin.increment);
5905
+ output += getOutput(times, (plugin) => plugin.increment);
5906
+ return output;
5880
5907
  };
5881
5908
  const outputWebpack = (stats) => {
5882
- console.log("\n===== General =====");
5909
+ let output = "\n===== General =====\n";
5883
5910
  const duration = stats.endTime - stats.startTime;
5884
5911
  const nbDeps = stats.compilation.fileDependencies.size;
5885
5912
  const nbFiles = stats.compilation.assets ? Object.keys(stats.compilation.assets).length : stats.compilation.emittedAssets.size;
@@ -5887,105 +5914,124 @@ const outputWebpack = (stats) => {
5887
5914
  const nbModules = "size" in stats.compilation.modules ? stats.compilation.modules.size : stats.compilation.modules.length;
5888
5915
  const nbChunks = "size" in stats.compilation.chunks ? stats.compilation.chunks.size : stats.compilation.chunks.length;
5889
5916
  const nbEntries = "size" in stats.compilation.entries ? stats.compilation.entries.size : stats.compilation.entries.length;
5890
- console.log(`duration: ${chalk.bold(formatDuration(duration))}
5917
+ output += `duration: ${chalk.bold(formatDuration(duration))}
5891
5918
  nbDeps: ${chalk.bold(nbDeps.toString())}
5892
5919
  nbFiles: ${chalk.bold(nbFiles.toString())}
5893
5920
  nbWarnings: ${chalk.bold(nbWarnings.toString())}
5894
5921
  nbModules: ${chalk.bold(nbModules.toString())}
5895
5922
  nbChunks: ${chalk.bold(nbChunks.toString())}
5896
5923
  nbEntries: ${chalk.bold(nbEntries.toString())}
5897
- `);
5924
+ `;
5925
+ return output;
5898
5926
  };
5899
5927
  const outputEsbuild = (stats) => {
5900
- console.log("\n===== General =====");
5928
+ let output = "\n===== General =====\n";
5901
5929
  const nbDeps = stats.inputs ? Object.keys(stats.inputs).length : 0;
5902
5930
  const nbFiles = stats.outputs ? Object.keys(stats.outputs).length : 0;
5903
5931
  const nbWarnings = stats.warnings.length;
5904
5932
  const nbErrors = stats.errors.length;
5905
5933
  const nbEntries = stats.entrypoints ? Object.keys(stats.entrypoints).length : 0;
5906
- console.log(`
5934
+ output += `
5907
5935
  nbDeps: ${chalk.bold(nbDeps.toString())}
5908
5936
  nbFiles: ${chalk.bold(nbFiles.toString())}
5909
5937
  nbWarnings: ${chalk.bold(nbWarnings.toString())}
5910
5938
  nbErrors: ${chalk.bold(nbErrors.toString())}
5911
5939
  nbEntries: ${chalk.bold(nbEntries.toString())}
5912
- `);
5940
+ `;
5941
+ return output;
5913
5942
  };
5914
5943
  const outputLoaders = (timings) => {
5944
+ let output = "";
5915
5945
  if (!timings) {
5916
- return;
5946
+ return output;
5917
5947
  }
5918
5948
  const times = Array.from(timings.values());
5919
5949
  if (!times.length) {
5920
- return;
5950
+ return output;
5921
5951
  }
5922
- console.log("\n===== Loaders =====");
5923
- console.log(`
5924
- === Top ${TOP} duration ===`);
5952
+ output += "\n===== Loaders =====\n";
5953
+ output += `
5954
+ === Top ${TOP} duration ===
5955
+ `;
5925
5956
  times.sort(sortDesc("duration"));
5926
- render(times, (loader) => formatDuration(loader.duration));
5927
- console.log(`
5928
- === Top ${TOP} hits ===`);
5957
+ output += getOutput(times, (loader) => formatDuration(loader.duration));
5958
+ output += `
5959
+ === Top ${TOP} hits ===
5960
+ `;
5929
5961
  times.sort(sortDesc("increment"));
5930
- render(times, (loader) => loader.increment);
5931
- };
5932
- const outputModules = (deps, timings) => {
5933
- if (!deps && !timings) {
5934
- return;
5935
- }
5936
- if (deps) {
5937
- const dependencies = Object.values(deps);
5938
- if (!dependencies.length) {
5939
- return;
5940
- }
5941
- console.log("\n===== Modules =====");
5942
- dependencies.sort(sortDesc((mod) => mod.dependents.length));
5943
- console.log(`
5944
- === Top ${TOP} dependents ===`);
5945
- render(dependencies, (module) => module.dependents.length);
5946
- dependencies.sort(sortDesc((mod) => mod.dependencies.length));
5947
- console.log(`
5948
- === Top ${TOP} dependencies ===`);
5949
- render(dependencies, (module) => module.dependencies.length);
5950
- dependencies.sort(sortDesc("size"));
5951
- console.log(`
5952
- === Top ${TOP} size ===`);
5953
- render(dependencies, (module) => prettyBytes$1(module.size));
5962
+ output += getOutput(times, (loader) => loader.increment);
5963
+ return output;
5964
+ };
5965
+ const outputModulesDependencies = (deps) => {
5966
+ let output = "";
5967
+ if (!deps) {
5968
+ return output;
5969
+ }
5970
+ const dependencies = Object.values(deps);
5971
+ if (!dependencies.length) {
5972
+ return output;
5973
+ }
5974
+ output += "\n===== Modules =====\n";
5975
+ dependencies.sort(sortDesc((mod) => mod.dependents.length));
5976
+ output += `
5977
+ === Top ${TOP} dependents ===
5978
+ `;
5979
+ output += getOutput(dependencies, (module) => module.dependents.length);
5980
+ dependencies.sort(sortDesc((mod) => mod.dependencies.length));
5981
+ output += `
5982
+ === Top ${TOP} dependencies ===
5983
+ `;
5984
+ output += getOutput(dependencies, (module) => module.dependencies.length);
5985
+ dependencies.sort(sortDesc("size"));
5986
+ output += `
5987
+ === Top ${TOP} size ===
5988
+ `;
5989
+ output += getOutput(dependencies, (module) => prettyBytes$1(module.size));
5990
+ return output;
5991
+ };
5992
+ const outputModulesTimings = (timings) => {
5993
+ let output = "";
5994
+ if (!timings) {
5995
+ return output;
5954
5996
  }
5955
- if (timings) {
5956
- const times = Array.from(timings.values());
5957
- if (!times.length) {
5958
- return;
5959
- }
5960
- console.log("\n===== Modules =====");
5961
- times.sort(sortDesc("duration"));
5962
- console.log(`
5963
- === Top ${TOP} duration ===`);
5964
- render(times, (module) => formatDuration(module.duration));
5965
- times.sort(sortDesc("increment"));
5966
- console.log(`
5967
- === Top ${TOP} hits ===`);
5968
- render(times, (module) => module.increment);
5997
+ const times = Array.from(timings.values());
5998
+ if (!times.length) {
5999
+ return output;
5969
6000
  }
6001
+ output += "\n===== Modules =====\n";
6002
+ times.sort(sortDesc("duration"));
6003
+ output += `
6004
+ === Top ${TOP} duration ===
6005
+ `;
6006
+ output += getOutput(times, (module) => formatDuration(module.duration));
6007
+ times.sort(sortDesc("increment"));
6008
+ output += `
6009
+ === Top ${TOP} hits ===
6010
+ `;
6011
+ output += getOutput(times, (module) => module.increment);
6012
+ return output;
5970
6013
  };
5971
6014
  const outputTexts = (context, options) => {
5972
6015
  const { output } = options[CONFIG_KEY];
5973
6016
  const { report, bundler } = context;
6017
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5974
6018
  if (output === false) {
5975
6019
  return;
5976
6020
  }
6021
+ let outputString = "";
5977
6022
  if (report) {
5978
- outputTapables(report.timings.tapables);
5979
- outputLoaders(report.timings.loaders);
5980
- outputModules(report.dependencies, report.timings.modules);
6023
+ outputString += outputTapables(report.timings.tapables);
6024
+ outputString += outputLoaders(report.timings.loaders);
6025
+ outputString += outputModulesDependencies(report.dependencies);
6026
+ outputString += outputModulesTimings(report.timings.modules);
5981
6027
  }
5982
6028
  if (bundler.webpack) {
5983
- outputWebpack(bundler.webpack);
6029
+ outputString += outputWebpack(bundler.webpack);
5984
6030
  }
5985
6031
  if (bundler.esbuild) {
5986
- outputEsbuild(bundler.esbuild);
6032
+ outputString += outputEsbuild(bundler.esbuild);
5987
6033
  }
5988
- console.log();
6034
+ log(outputString);
5989
6035
  };
5990
6036
 
5991
6037
  const output = async (context, options) => {
@@ -6518,11 +6564,14 @@ const getWebpackPlugin$1 = (opt) => {
6518
6564
  };
6519
6565
  };
6520
6566
 
6567
+ const helpers$1 = {
6568
+ filters: defaultFilters
6569
+ };
6521
6570
  const getPlugins = (opt) => {
6522
6571
  return [
6523
6572
  {
6524
6573
  name: PLUGIN_NAME,
6525
- enforce: "post",
6574
+ enforce: "pre",
6526
6575
  esbuild: getEsbuildPlugin$1(opt),
6527
6576
  webpack: getWebpackPlugin$1(opt)
6528
6577
  }
@@ -18143,6 +18192,12 @@ function createUnplugin(factory) {
18143
18192
  };
18144
18193
  }
18145
18194
 
18195
+ const helpers = {
18196
+ // Each product should have a unique entry.
18197
+ // #helpers-injection-marker
18198
+ [CONFIG_KEY]: helpers$1
18199
+ // #helpers-injection-marker
18200
+ };
18146
18201
  const buildPluginFactory = () => {
18147
18202
  return createUnplugin((userOptions, unpluginMetaContext) => {
18148
18203
  const options = {
@@ -18160,4 +18215,5 @@ const buildPluginFactory = () => {
18160
18215
  const datadogEsbuildPlugin = buildPluginFactory().esbuild;
18161
18216
 
18162
18217
  exports.datadogEsbuildPlugin = datadogEsbuildPlugin;
18218
+ exports.helpers = helpers;
18163
18219
  //# sourceMappingURL=index.js.map