@datadog/esbuild-plugin 0.0.13-1 → 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/dist/src/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var fs$j = require('fs');
6
4
  var require$$0 = require('constants');
7
5
  var require$$0$1 = require('stream');
@@ -19,26 +17,86 @@ var process2 = require('process');
19
17
 
20
18
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
21
19
  function _interopNamespaceDefault(e) {
22
- var n = Object.create(null);
23
- if (e) {
24
- Object.keys(e).forEach(function (k) {
25
- if (k !== 'default') {
26
- var d = Object.getOwnPropertyDescriptor(e, k);
27
- Object.defineProperty(n, k, d.get ? d : {
28
- enumerable: true,
29
- get: function () { return e[k]; }
30
- });
31
- }
32
- });
33
- }
34
- n.default = e;
35
- 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);
36
34
  }
37
35
 
38
36
  var querystring__namespace = /*#__PURE__*/_interopNamespaceDefault(querystring);
39
37
 
40
38
  const CONFIG_KEY = "telemetry";
41
- const PLUGIN_NAME = `${CONFIG_KEY}-plugin`;
39
+ const PLUGIN_NAME = `datadog-${CONFIG_KEY}-plugin`;
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
+ };
42
100
 
43
101
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
44
102
 
@@ -3058,129 +3116,6 @@ const getContext = (args) => {
3058
3116
  value: typeof arg === "string" ? arg : void 0
3059
3117
  }));
3060
3118
  };
3061
- const filterTreeMetrics = (metric) => (
3062
- // Remove tree metrics because way too verbose
3063
- !/modules\.tree\.(count|size)$/.test(metric.metric) ? metric : null
3064
- );
3065
- const filterSourcemapsAndNodeModules = (metric) => metric.tags.some(
3066
- (tag) => (
3067
- // Remove sourcemaps.
3068
- /^assetName:.*\.map$/.test(tag) || // Remove third parties.
3069
- /^moduleName:\/node_modules/.test(tag)
3070
- )
3071
- ) ? null : metric;
3072
- const filterMetricsOnThreshold = (metric) => {
3073
- const thresholds = {
3074
- size: 1e5,
3075
- count: 10,
3076
- duration: 1e3
3077
- };
3078
- if (/(entries|loaders|warnings|errors)\.count$/.test(metric.metric)) {
3079
- thresholds.count = 0;
3080
- }
3081
- if (/(modules\.(dependencies|dependents)$)/.test(metric.metric)) {
3082
- thresholds.count = 30;
3083
- }
3084
- if (/modules\.tree\.count$/.test(metric.metric)) {
3085
- thresholds.count = 150;
3086
- }
3087
- if (/modules\.tree\.size$/.test(metric.metric)) {
3088
- thresholds.size = 15e5;
3089
- }
3090
- if (/entries\.size$/.test(metric.metric)) {
3091
- thresholds.size = 0;
3092
- }
3093
- if (/entries\.modules\.count$/.test(metric.metric)) {
3094
- thresholds.count = 0;
3095
- }
3096
- return metric.value > thresholds[metric.type] ? metric : null;
3097
- };
3098
- const defaultTelemetryFilters = [
3099
- filterTreeMetrics,
3100
- filterSourcemapsAndNodeModules,
3101
- filterMetricsOnThreshold
3102
- ];
3103
-
3104
- const outputFiles = async (context, options) => {
3105
- const { report, metrics, bundler } = context;
3106
- const opts = options[CONFIG_KEY].output;
3107
- if (typeof opts !== "string" && typeof opts !== "object") {
3108
- return;
3109
- }
3110
- const startWriting = Date.now();
3111
- let destination;
3112
- const files = {
3113
- timings: true,
3114
- dependencies: true,
3115
- bundler: true,
3116
- metrics: true,
3117
- result: true
3118
- };
3119
- if (typeof opts === "object") {
3120
- destination = opts.destination;
3121
- files.timings = opts.timings || false;
3122
- files.dependencies = opts.dependencies || false;
3123
- files.bundler = opts.bundler || false;
3124
- files.metrics = opts.metrics || false;
3125
- } else {
3126
- destination = opts;
3127
- }
3128
- const outputPath = require$$1.resolve(options.cwd, destination);
3129
- try {
3130
- const errors = {};
3131
- const filesToWrite = {};
3132
- if (files.timings && report?.timings) {
3133
- filesToWrite.timings = {
3134
- content: {
3135
- tapables: report.timings.tapables ? Array.from(report.timings.tapables.values()) : null,
3136
- loaders: report.timings.loaders ? Array.from(report.timings.loaders.values()) : null,
3137
- modules: report.timings.modules ? Array.from(report.timings.modules.values()) : null
3138
- }
3139
- };
3140
- }
3141
- if (files.dependencies && report?.dependencies) {
3142
- filesToWrite.dependencies = { content: report.dependencies };
3143
- }
3144
- if (files.bundler) {
3145
- if (bundler.webpack) {
3146
- filesToWrite.bundler = { content: bundler.webpack.toJson({ children: false }) };
3147
- }
3148
- if (bundler.esbuild) {
3149
- filesToWrite.bundler = { content: bundler.esbuild };
3150
- }
3151
- }
3152
- if (metrics && files.metrics) {
3153
- filesToWrite.metrics = { content: metrics };
3154
- }
3155
- const proms = Object.keys(filesToWrite).map((file) => {
3156
- const start = Date.now();
3157
- console.log(`Start writing ${file}.json.`);
3158
- return writeFile(require$$1.join(outputPath, `${file}.json`), filesToWrite[file].content).then(() => {
3159
- console.log(`Wrote ${file}.json in ${formatDuration(Date.now() - start)}`);
3160
- }).catch((e) => {
3161
- console.log(
3162
- `Failed to write ${file}.json in ${formatDuration(Date.now() - start)}`,
3163
- "error"
3164
- );
3165
- errors[file] = e;
3166
- });
3167
- });
3168
- await Promise.all(proms);
3169
- console.log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
3170
- const fileErrored = Object.keys(errors);
3171
- if (fileErrored.length) {
3172
- console.log(
3173
- `Couldn't write files.
3174
- ${fileErrored.map(
3175
- (file) => ` - ${file}: ${errors[file].toString()}`
3176
- )}`,
3177
- "error"
3178
- );
3179
- }
3180
- } catch (e) {
3181
- console.log(`Couldn't write files. ${e}`, "error");
3182
- }
3183
- };
3184
3119
 
3185
3120
  var chalk$1 = {exports: {}};
3186
3121
 
@@ -5068,24 +5003,103 @@ var templates = (chalk, tmp) => {
5068
5003
  var chalkExports = chalk$1.exports;
5069
5004
  var chalk = /*@__PURE__*/getDefaultExportFromCjs(chalkExports);
5070
5005
 
5071
- const getMetric = (metric, opts) => ({
5072
- type: "gauge",
5073
- tags: [...metric.tags, ...opts.tags],
5074
- metric: `${opts.prefix ? `${opts.prefix}.` : ""}${metric.metric}`,
5075
- points: [[opts.timestamp, metric.value]]
5076
- });
5077
- const flattened = (arr) => [].concat(...arr);
5078
- const getType = (name) => name.includes(".") ? name.split(".").pop() : "unknown";
5079
- const getOptionsDD = (opt) => {
5080
- const options = opt[CONFIG_KEY];
5081
- return {
5082
- timestamp: Math.floor((options.datadog?.timestamp || Date.now()) / 1e3),
5083
- apiKey: opt.auth.apiKey || "",
5084
- tags: options.datadog?.tags || [],
5085
- endPoint: options.datadog?.endPoint || "app.datadoghq.com",
5086
- prefix: options.datadog?.prefix || "",
5087
- 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
5088
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
+ }
5089
5103
  };
5090
5104
 
5091
5105
  const getGeneralReport = (report, bundler) => {
@@ -5639,19 +5653,24 @@ const getMetrics = (opts, report, bundler) => {
5639
5653
  };
5640
5654
 
5641
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
+ }
5642
5661
  if (!metrics || !metrics.length) {
5643
5662
  throw new Error("No metrics to send.");
5644
5663
  }
5645
5664
  const metricsNames = [...new Set(metrics.map((m) => m.metric))].sort().map((name) => `${name} - ${metrics.filter((m) => m.metric === name).length}`);
5646
- console.log(`
5665
+ log(`
5647
5666
  Sending ${metrics.length} metrics.
5648
5667
  Metrics:
5649
5668
  - ${metricsNames.join("\n - ")}`);
5650
5669
  return new Promise((resolve, reject) => {
5651
5670
  const req = https.request({
5652
5671
  method: "POST",
5653
- hostname: opts.endPoint,
5654
- 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}`
5655
5674
  });
5656
5675
  req.write(
5657
5676
  JSON.stringify({
@@ -5676,18 +5695,20 @@ Status Code: ${res.statusCode}`);
5676
5695
 
5677
5696
  const addMetrics = (context, options) => {
5678
5697
  const { report, bundler } = context;
5698
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5679
5699
  context.metrics = context.metrics || [];
5680
5700
  try {
5681
5701
  context.metrics = getMetrics(options, report, bundler);
5682
5702
  } catch (e) {
5683
5703
  const stack = e instanceof Error ? e.stack : e;
5684
- console.log(`Couldn't aggregate metrics: ${stack}`, "error");
5704
+ log(`Couldn't aggregate metrics: ${stack}`, "error");
5685
5705
  }
5686
5706
  };
5687
5707
  const processMetrics = async (context, options) => {
5688
5708
  const { start } = context;
5689
5709
  const duration = Date.now() - start;
5690
5710
  const optionsDD = getOptionsDD(options);
5711
+ const log = getLogFn(options.logLevel, PLUGIN_NAME);
5691
5712
  context.metrics = context.metrics || [];
5692
5713
  context.metrics.push(
5693
5714
  getMetric(
@@ -5700,20 +5721,17 @@ const processMetrics = async (context, options) => {
5700
5721
  optionsDD
5701
5722
  )
5702
5723
  );
5703
- console.log(`Took ${formatDuration(duration)}.`);
5704
- if (!optionsDD.apiKey) {
5705
- 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");
5706
5727
  return;
5707
5728
  }
5708
5729
  try {
5709
5730
  const startSending = Date.now();
5710
- await sendMetrics(context.metrics, {
5711
- apiKey: optionsDD.apiKey,
5712
- endPoint: optionsDD.endPoint
5713
- });
5714
- console.log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
5731
+ await sendMetrics(context.metrics, options);
5732
+ log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
5715
5733
  } catch (e) {
5716
- console.log(`Error sending metrics ${e}`, "error");
5734
+ log(`Error sending metrics ${e}`, "error");
5717
5735
  }
5718
5736
  };
5719
5737
 
@@ -5857,31 +5875,38 @@ const sortDesc = (attr) => (a, b) => {
5857
5875
  return 0;
5858
5876
  }
5859
5877
  };
5860
- const render = (values, renderValue) => {
5878
+ const getOutput = (values, renderValue) => {
5879
+ let output = "";
5861
5880
  for (const val of values.slice(0, TOP)) {
5862
- console.log(`[${numColor(renderValue(val))}] ${nameColor(val.name)}`);
5881
+ output += `[${numColor(renderValue(val))}] ${nameColor(val.name)}
5882
+ `;
5863
5883
  }
5884
+ return output;
5864
5885
  };
5865
5886
  const outputTapables = (timings) => {
5887
+ let output = "";
5866
5888
  if (!timings) {
5867
- return;
5889
+ return output;
5868
5890
  }
5869
5891
  const times = Array.from(timings.values());
5870
5892
  if (!times.length) {
5871
- return;
5893
+ return output;
5872
5894
  }
5873
- console.log("\n===== Tapables =====");
5874
- console.log(`
5875
- === Top ${TOP} duration ===`);
5895
+ output += "\n===== Tapables =====\n";
5896
+ output += `
5897
+ === Top ${TOP} duration ===
5898
+ `;
5876
5899
  times.sort(sortDesc("duration"));
5877
- render(times, (time) => formatDuration(time.duration));
5878
- console.log(`
5879
- === Top ${TOP} hits ===`);
5900
+ output += getOutput(times, (time) => formatDuration(time.duration));
5901
+ output += `
5902
+ === Top ${TOP} hits ===
5903
+ `;
5880
5904
  times.sort(sortDesc("increment"));
5881
- render(times, (plugin) => plugin.increment);
5905
+ output += getOutput(times, (plugin) => plugin.increment);
5906
+ return output;
5882
5907
  };
5883
5908
  const outputWebpack = (stats) => {
5884
- console.log("\n===== General =====");
5909
+ let output = "\n===== General =====\n";
5885
5910
  const duration = stats.endTime - stats.startTime;
5886
5911
  const nbDeps = stats.compilation.fileDependencies.size;
5887
5912
  const nbFiles = stats.compilation.assets ? Object.keys(stats.compilation.assets).length : stats.compilation.emittedAssets.size;
@@ -5889,105 +5914,135 @@ const outputWebpack = (stats) => {
5889
5914
  const nbModules = "size" in stats.compilation.modules ? stats.compilation.modules.size : stats.compilation.modules.length;
5890
5915
  const nbChunks = "size" in stats.compilation.chunks ? stats.compilation.chunks.size : stats.compilation.chunks.length;
5891
5916
  const nbEntries = "size" in stats.compilation.entries ? stats.compilation.entries.size : stats.compilation.entries.length;
5892
- console.log(`duration: ${chalk.bold(formatDuration(duration))}
5917
+ output += `duration: ${chalk.bold(formatDuration(duration))}
5893
5918
  nbDeps: ${chalk.bold(nbDeps.toString())}
5894
5919
  nbFiles: ${chalk.bold(nbFiles.toString())}
5895
5920
  nbWarnings: ${chalk.bold(nbWarnings.toString())}
5896
5921
  nbModules: ${chalk.bold(nbModules.toString())}
5897
5922
  nbChunks: ${chalk.bold(nbChunks.toString())}
5898
5923
  nbEntries: ${chalk.bold(nbEntries.toString())}
5899
- `);
5924
+ `;
5925
+ return output;
5900
5926
  };
5901
5927
  const outputEsbuild = (stats) => {
5902
- console.log("\n===== General =====");
5928
+ let output = "\n===== General =====\n";
5903
5929
  const nbDeps = stats.inputs ? Object.keys(stats.inputs).length : 0;
5904
5930
  const nbFiles = stats.outputs ? Object.keys(stats.outputs).length : 0;
5905
5931
  const nbWarnings = stats.warnings.length;
5906
5932
  const nbErrors = stats.errors.length;
5907
5933
  const nbEntries = stats.entrypoints ? Object.keys(stats.entrypoints).length : 0;
5908
- console.log(`
5934
+ output += `
5909
5935
  nbDeps: ${chalk.bold(nbDeps.toString())}
5910
5936
  nbFiles: ${chalk.bold(nbFiles.toString())}
5911
5937
  nbWarnings: ${chalk.bold(nbWarnings.toString())}
5912
5938
  nbErrors: ${chalk.bold(nbErrors.toString())}
5913
5939
  nbEntries: ${chalk.bold(nbEntries.toString())}
5914
- `);
5940
+ `;
5941
+ return output;
5915
5942
  };
5916
5943
  const outputLoaders = (timings) => {
5944
+ let output = "";
5917
5945
  if (!timings) {
5918
- return;
5946
+ return output;
5919
5947
  }
5920
5948
  const times = Array.from(timings.values());
5921
5949
  if (!times.length) {
5922
- return;
5950
+ return output;
5951
+ }
5952
+ output += "\n===== Loaders =====\n";
5953
+ output += `
5954
+ === Top ${TOP} duration ===
5955
+ `;
5956
+ times.sort(sortDesc("duration"));
5957
+ output += getOutput(times, (loader) => formatDuration(loader.duration));
5958
+ output += `
5959
+ === Top ${TOP} hits ===
5960
+ `;
5961
+ times.sort(sortDesc("increment"));
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;
5923
5996
  }
5924
- console.log("\n===== Loaders =====");
5925
- console.log(`
5926
- === Top ${TOP} duration ===`);
5997
+ const times = Array.from(timings.values());
5998
+ if (!times.length) {
5999
+ return output;
6000
+ }
6001
+ output += "\n===== Modules =====\n";
5927
6002
  times.sort(sortDesc("duration"));
5928
- render(times, (loader) => formatDuration(loader.duration));
5929
- console.log(`
5930
- === Top ${TOP} hits ===`);
6003
+ output += `
6004
+ === Top ${TOP} duration ===
6005
+ `;
6006
+ output += getOutput(times, (module) => formatDuration(module.duration));
5931
6007
  times.sort(sortDesc("increment"));
5932
- render(times, (loader) => loader.increment);
6008
+ output += `
6009
+ === Top ${TOP} hits ===
6010
+ `;
6011
+ output += getOutput(times, (module) => module.increment);
6012
+ return output;
5933
6013
  };
5934
- const outputModules = (deps, timings) => {
5935
- if (!deps && !timings) {
5936
- return;
6014
+ const shouldShowOutput = (output) => {
6015
+ if (typeof output === "boolean") {
6016
+ return output;
5937
6017
  }
5938
- if (deps) {
5939
- const dependencies = Object.values(deps);
5940
- if (!dependencies.length) {
5941
- return;
5942
- }
5943
- console.log("\n===== Modules =====");
5944
- dependencies.sort(sortDesc((mod) => mod.dependents.length));
5945
- console.log(`
5946
- === Top ${TOP} dependents ===`);
5947
- render(dependencies, (module) => module.dependents.length);
5948
- dependencies.sort(sortDesc((mod) => mod.dependencies.length));
5949
- console.log(`
5950
- === Top ${TOP} dependencies ===`);
5951
- render(dependencies, (module) => module.dependencies.length);
5952
- dependencies.sort(sortDesc("size"));
5953
- console.log(`
5954
- === Top ${TOP} size ===`);
5955
- render(dependencies, (module) => prettyBytes$1(module.size));
6018
+ if (typeof output === "string") {
6019
+ return true;
5956
6020
  }
5957
- if (timings) {
5958
- const times = Array.from(timings.values());
5959
- if (!times.length) {
5960
- return;
5961
- }
5962
- console.log("\n===== Modules =====");
5963
- times.sort(sortDesc("duration"));
5964
- console.log(`
5965
- === Top ${TOP} duration ===`);
5966
- render(times, (module) => formatDuration(module.duration));
5967
- times.sort(sortDesc("increment"));
5968
- console.log(`
5969
- === Top ${TOP} hits ===`);
5970
- render(times, (module) => module.increment);
6021
+ if (!output) {
6022
+ return true;
5971
6023
  }
6024
+ return output.logs !== false;
5972
6025
  };
5973
6026
  const outputTexts = (context, options) => {
5974
6027
  const { output } = options[CONFIG_KEY];
5975
6028
  const { report, bundler } = context;
5976
- if (output === false) {
6029
+ if (!shouldShowOutput(output)) {
5977
6030
  return;
5978
6031
  }
6032
+ let outputString = "";
5979
6033
  if (report) {
5980
- outputTapables(report.timings.tapables);
5981
- outputLoaders(report.timings.loaders);
5982
- outputModules(report.dependencies, report.timings.modules);
6034
+ outputString += outputTapables(report.timings.tapables);
6035
+ outputString += outputLoaders(report.timings.loaders);
6036
+ outputString += outputModulesDependencies(report.dependencies);
6037
+ outputString += outputModulesTimings(report.timings.modules);
5983
6038
  }
5984
6039
  if (bundler.webpack) {
5985
- outputWebpack(bundler.webpack);
6040
+ outputString += outputWebpack(bundler.webpack);
5986
6041
  }
5987
6042
  if (bundler.esbuild) {
5988
- outputEsbuild(bundler.esbuild);
6043
+ outputString += outputEsbuild(bundler.esbuild);
5989
6044
  }
5990
- console.log();
6045
+ console.log(outputString);
5991
6046
  };
5992
6047
 
5993
6048
  const output = async (context, options) => {
@@ -6058,10 +6113,13 @@ const wrapPlugins = (build, context) => {
6058
6113
  };
6059
6114
  });
6060
6115
  for (const plugin of plugins) {
6061
- const newBuildObject = getNewBuildObject(build, plugin.name, context);
6116
+ if (plugin.name === PLUGIN_NAME) {
6117
+ continue;
6118
+ }
6062
6119
  const oldSetup = plugin.setup;
6063
- plugin.setup = () => {
6064
- oldSetup({
6120
+ plugin.setup = async (esbuild) => {
6121
+ const newBuildObject = getNewBuildObject(esbuild, plugin.name, context);
6122
+ await oldSetup({
6065
6123
  ...newBuildObject,
6066
6124
  // Use non-modified plugins for other plugins
6067
6125
  initialOptions: { ...newBuildObject.initialOptions, plugins: initialPlugins }
@@ -6520,11 +6578,13 @@ const getWebpackPlugin$1 = (opt) => {
6520
6578
  };
6521
6579
  };
6522
6580
 
6581
+ const helpers$1 = {
6582
+ filters: defaultFilters
6583
+ };
6523
6584
  const getPlugins = (opt) => {
6524
6585
  return [
6525
6586
  {
6526
6587
  name: PLUGIN_NAME,
6527
- enforce: "post",
6528
6588
  esbuild: getEsbuildPlugin$1(opt),
6529
6589
  webpack: getWebpackPlugin$1(opt)
6530
6590
  }
@@ -18145,6 +18205,12 @@ function createUnplugin(factory) {
18145
18205
  };
18146
18206
  }
18147
18207
 
18208
+ const helpers = {
18209
+ // Each product should have a unique entry.
18210
+ // #helpers-injection-marker
18211
+ [CONFIG_KEY]: helpers$1
18212
+ // #helpers-injection-marker
18213
+ };
18148
18214
  const buildPluginFactory = () => {
18149
18215
  return createUnplugin((userOptions, unpluginMetaContext) => {
18150
18216
  const options = {
@@ -18160,8 +18226,7 @@ const buildPluginFactory = () => {
18160
18226
  };
18161
18227
 
18162
18228
  const datadogEsbuildPlugin = buildPluginFactory().esbuild;
18163
- module.exports = datadogEsbuildPlugin;
18164
18229
 
18165
18230
  exports.datadogEsbuildPlugin = datadogEsbuildPlugin;
18166
- exports.default = datadogEsbuildPlugin;
18231
+ exports.helpers = helpers;
18167
18232
  //# sourceMappingURL=index.js.map