@datadog/esbuild-plugin 2.3.3-dev-2 → 2.3.3-dev-3

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
@@ -28,16 +28,16 @@ const logPriority = {
28
28
  const getLoggerFactory = (build, logLevel = "warn") => (name) => {
29
29
  const log = (text, type = "debug") => {
30
30
  let color = chalk.dim;
31
- let logFn2 = console.log;
31
+ let logFn = console.log;
32
32
  if (type === "error") {
33
33
  color = chalk.red;
34
- logFn2 = console.error;
34
+ logFn = console.error;
35
35
  } else if (type === "warn") {
36
36
  color = chalk.yellow;
37
- logFn2 = console.warn;
37
+ logFn = console.warn;
38
38
  } else if (type === "info") {
39
39
  color = chalk.cyan;
40
- logFn2 = console.log;
40
+ logFn = console.log;
41
41
  }
42
42
  const prefix = `[${type}|${name}]`;
43
43
  const content = typeof text === "string" ? text : JSON.stringify(text, null, 2);
@@ -49,17 +49,19 @@ const getLoggerFactory = (build, logLevel = "warn") => (name) => {
49
49
  build.warnings.push(content);
50
50
  }
51
51
  if (logPriority[type] >= logPriority[logLevel]) {
52
- logFn2(`${color(prefix)} ${content}`);
52
+ logFn(`${color(prefix)} ${content}`);
53
53
  }
54
54
  };
55
- const logFn = (text, type = "debug") => {
56
- log(text, type);
55
+ return {
56
+ getLogger: (subName) => {
57
+ const logger = getLoggerFactory(build, logLevel);
58
+ return logger(`${name}:${subName}`);
59
+ },
60
+ error: (text) => log(text, "error"),
61
+ warn: (text) => log(text, "warn"),
62
+ info: (text) => log(text, "info"),
63
+ debug: (text) => log(text, "debug")
57
64
  };
58
- logFn.error = (text) => log(text, "error");
59
- logFn.warn = (text) => log(text, "warn");
60
- logFn.info = (text) => log(text, "info");
61
- logFn.debug = (text) => log(text, "debug");
62
- return logFn;
63
65
  };
64
66
  const getContext = ({
65
67
  options,
@@ -90,7 +92,6 @@ const getContext = ({
90
92
  inject: (item) => {
91
93
  injections.push(item);
92
94
  },
93
- getLogger: getLoggerFactory(build, options.logLevel),
94
95
  start: Date.now(),
95
96
  version
96
97
  };
@@ -105,9 +106,6 @@ const validateOptions$2 = (options = {}) => {
105
106
  };
106
107
  };
107
108
 
108
- const CONFIG_KEY$1 = "rum";
109
- const PLUGIN_NAME$4 = "datadog-rum-plugin";
110
-
111
109
  const decomposePath = (options, context, sourcemapFilePath) => {
112
110
  if (path.extname(sourcemapFilePath) !== ".map") {
113
111
  throw new Error(`The file ${chalk.green.bold(sourcemapFilePath)} is not a sourcemap.`);
@@ -430,7 +428,7 @@ const upload = async (payloads, options, context, log) => {
430
428
  "."
431
429
  )
432
430
  };
433
- log(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
431
+ log.debug(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
434
432
  addPromises.push(
435
433
  queue.add(async () => {
436
434
  try {
@@ -444,10 +442,10 @@ const upload = async (payloads, options, context, log) => {
444
442
  ${error.message}
445
443
  Retrying ${attempt}/${NB_RETRIES}`;
446
444
  warnings.push(warningMessage);
447
- log(warningMessage, "warn");
445
+ log.warn(warningMessage);
448
446
  }
449
447
  });
450
- log(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
448
+ log.debug(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
451
449
  } catch (e) {
452
450
  errors.push({ metadata, error: e });
453
451
  if (options.bailOnError === true) {
@@ -479,13 +477,13 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
479
477
  const errors = payloads.map((payload) => payload.errors).flat();
480
478
  const warnings = payloads.map((payload) => payload.warnings).flat();
481
479
  if (warnings.length > 0) {
482
- log(`Warnings while preparing payloads:
483
- - ${warnings.join("\n - ")}`, "warn");
480
+ log.warn(`Warnings while preparing payloads:
481
+ - ${warnings.join("\n - ")}`);
484
482
  }
485
483
  if (errors.length > 0) {
486
484
  const errorMsg = `Failed to prepare payloads, aborting upload :
487
485
  - ${errors.join("\n - ")}`;
488
- log(errorMsg, "error");
486
+ log.error(errorMsg);
489
487
  if (options.bailOnError === true) {
490
488
  throw new Error(errorMsg);
491
489
  }
@@ -497,9 +495,8 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
497
495
  context,
498
496
  log
499
497
  );
500
- log(
501
- `Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}.`,
502
- "info"
498
+ log.info(
499
+ `Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}.`
503
500
  );
504
501
  if (uploadErrors.length > 0) {
505
502
  const listOfErrors = ` - ${uploadErrors.map(({ metadata: fileMetadata, error }) => {
@@ -510,14 +507,14 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
510
507
  }).join("\n - ")}`;
511
508
  const errorMsg = `Failed to upload some sourcemaps:
512
509
  ${listOfErrors}`;
513
- log(errorMsg, "error");
510
+ log.error(errorMsg);
514
511
  if (options.bailOnError === true) {
515
512
  throw new Error(errorMsg);
516
513
  }
517
514
  }
518
515
  if (uploadWarnings.length > 0) {
519
- log(`Warnings while uploading sourcemaps:
520
- - ${warnings.join("\n - ")}`, "warn");
516
+ log.warn(`Warnings while uploading sourcemaps:
517
+ - ${warnings.join("\n - ")}`);
521
518
  }
522
519
  };
523
520
 
@@ -529,19 +526,22 @@ const uploadSourcemaps = async (options, context, log) => {
529
526
  Uploading ${green(sourcemaps.length.toString())} sourcemaps with configuration:
530
527
  ${configurationString}
531
528
  `;
532
- log(summary, "info");
529
+ log.info(summary);
533
530
  await sendSourcemaps(sourcemaps, options.sourcemaps, context, log);
534
531
  };
535
532
 
533
+ const CONFIG_KEY$1 = "rum";
534
+ const PLUGIN_NAME$5 = "datadog-rum-plugin";
535
+
536
536
  const defaultIntakeUrl = `https://sourcemap-intake.${process.env.DATADOG_SITE || "datadoghq.com"}/api/v2/srcmap`;
537
537
  const validateOptions$1 = (config, log) => {
538
538
  const errors = [];
539
539
  const sourcemapsResults = validateSourcemapsOptions(config);
540
540
  errors.push(...sourcemapsResults.errors);
541
541
  if (errors.length) {
542
- log(`
543
- - ${errors.join("\n - ")}`, "error");
544
- throw new Error(`Invalid configuration for ${PLUGIN_NAME$4}.`);
542
+ log.error(`
543
+ - ${errors.join("\n - ")}`);
544
+ throw new Error(`Invalid configuration for ${PLUGIN_NAME$5}.`);
545
545
  }
546
546
  const toReturn = {
547
547
  ...config[CONFIG_KEY$1],
@@ -599,8 +599,7 @@ const validateSourcemapsOptions = (config) => {
599
599
  return toReturn;
600
600
  };
601
601
 
602
- const getPlugins$2 = (opts, context) => {
603
- const log = context.getLogger(PLUGIN_NAME$4);
602
+ const getPlugins$1 = (opts, context, log) => {
604
603
  const rumOptions = validateOptions$1(opts, log);
605
604
  return [
606
605
  {
@@ -619,7 +618,7 @@ const getPlugins$2 = (opts, context) => {
619
618
  };
620
619
 
621
620
  const CONFIG_KEY = "telemetry";
622
- const PLUGIN_NAME$3 = `datadog-telemetry-plugin`;
621
+ const PLUGIN_NAME$4 = `datadog-telemetry-plugin`;
623
622
 
624
623
  const filterTreeMetrics = (metric) => (
625
624
  // Remove tree metrics because way too verbose
@@ -735,9 +734,8 @@ const getValueContext = (args) => {
735
734
  }));
736
735
  };
737
736
 
738
- const getPlugins$1 = (plugins) => {
739
- const metrics = [];
740
- metrics.push({
737
+ const addPluginMetrics = (plugins, metrics) => {
738
+ metrics.add({
741
739
  metric: "plugins.count",
742
740
  type: "count",
743
741
  value: plugins.size,
@@ -754,67 +752,54 @@ const getPlugins$1 = (plugins) => {
754
752
  hookDuration += duration;
755
753
  pluginDuration += duration;
756
754
  }
757
- metrics.push(
758
- {
759
- metric: "plugins.hooks.duration",
760
- type: "duration",
761
- value: hookDuration,
762
- tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
763
- },
764
- {
765
- metric: "plugins.hooks.increment",
766
- type: "count",
767
- value: hook.values.length,
768
- tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
769
- }
770
- );
771
- }
772
- metrics.push(
773
- {
774
- metric: "plugins.duration",
755
+ metrics.add({
756
+ metric: "plugins.hooks.duration",
775
757
  type: "duration",
776
- value: pluginDuration,
777
- tags: [`pluginName:${plugin.name}`]
778
- },
779
- {
780
- metric: "plugins.increment",
758
+ value: hookDuration,
759
+ tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
760
+ }).add({
761
+ metric: "plugins.hooks.increment",
781
762
  type: "count",
782
- value: pluginCount,
783
- tags: [`pluginName:${plugin.name}`]
784
- }
785
- );
763
+ value: hook.values.length,
764
+ tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
765
+ });
766
+ }
767
+ metrics.add({
768
+ metric: "plugins.duration",
769
+ type: "duration",
770
+ value: pluginDuration,
771
+ tags: [`pluginName:${plugin.name}`]
772
+ }).add({
773
+ metric: "plugins.increment",
774
+ type: "count",
775
+ value: pluginCount,
776
+ tags: [`pluginName:${plugin.name}`]
777
+ });
786
778
  }
787
- return metrics;
788
779
  };
789
- const getLoaders = (loaders) => {
790
- const metrics = [];
791
- metrics.push({
780
+ const addLoaderMetrics = (loaders, metrics) => {
781
+ metrics.add({
792
782
  metric: "loaders.count",
793
783
  type: "count",
794
784
  value: loaders.size,
795
785
  tags: []
796
786
  });
797
787
  for (const loader of loaders.values()) {
798
- metrics.push(
799
- {
800
- metric: "loaders.duration",
801
- type: "duration",
802
- value: loader.duration,
803
- tags: [`loaderName:${loader.name}`]
804
- },
805
- {
806
- metric: "loaders.increment",
807
- type: "count",
808
- value: loader.increment,
809
- tags: [`loaderName:${loader.name}`]
810
- }
811
- );
788
+ metrics.add({
789
+ metric: "loaders.duration",
790
+ type: "duration",
791
+ value: loader.duration,
792
+ tags: [`loaderName:${loader.name}`]
793
+ }).add({
794
+ metric: "loaders.increment",
795
+ type: "count",
796
+ value: loader.increment,
797
+ tags: [`loaderName:${loader.name}`]
798
+ });
812
799
  }
813
- return metrics;
814
800
  };
815
801
 
816
- const getUniversalMetrics = (globalContext) => {
817
- const metrics = [];
802
+ const addUniversalMetrics = (globalContext, metrics) => {
818
803
  const inputs = globalContext.build.inputs || [];
819
804
  const outputs = globalContext.build.outputs || [];
820
805
  const entries = globalContext.build.entries || [];
@@ -847,40 +832,34 @@ const getUniversalMetrics = (globalContext) => {
847
832
  assetsPerInput.get(input.filepath).push(output.name);
848
833
  }
849
834
  }
850
- metrics.push(
851
- {
852
- metric: "assets.count",
853
- type: "count",
854
- value: outputs.length,
855
- tags: []
856
- },
857
- {
858
- metric: "entries.count",
859
- type: "count",
860
- value: entries.length,
861
- tags: []
862
- },
863
- {
864
- metric: "errors.count",
865
- type: "count",
866
- value: nbErrors,
867
- tags: []
868
- },
869
- {
870
- metric: "modules.count",
871
- type: "count",
872
- value: inputs.length,
873
- tags: []
874
- },
875
- {
876
- metric: "warnings.count",
877
- type: "count",
878
- value: nbWarnings,
879
- tags: []
880
- }
881
- );
835
+ metrics.add({
836
+ metric: "assets.count",
837
+ type: "count",
838
+ value: outputs.length,
839
+ tags: []
840
+ }).add({
841
+ metric: "entries.count",
842
+ type: "count",
843
+ value: entries.length,
844
+ tags: []
845
+ }).add({
846
+ metric: "errors.count",
847
+ type: "count",
848
+ value: nbErrors,
849
+ tags: []
850
+ }).add({
851
+ metric: "modules.count",
852
+ type: "count",
853
+ value: inputs.length,
854
+ tags: []
855
+ }).add({
856
+ metric: "warnings.count",
857
+ type: "count",
858
+ value: nbWarnings,
859
+ tags: []
860
+ });
882
861
  if (duration) {
883
- metrics.push({
862
+ metrics.add({
884
863
  metric: "compilation.duration",
885
864
  type: "duration",
886
865
  value: duration,
@@ -899,26 +878,22 @@ const getUniversalMetrics = (globalContext) => {
899
878
  ...assetsPerInput.get(input.filepath).map((assetName) => `assetName:${assetName}`)
900
879
  );
901
880
  }
902
- metrics.push(
903
- {
904
- metric: "modules.size",
905
- type: "size",
906
- value: input.size,
907
- tags
908
- },
909
- {
910
- metric: "modules.dependencies",
911
- type: "count",
912
- value: input.dependencies.size,
913
- tags
914
- },
915
- {
916
- metric: "modules.dependents",
917
- type: "count",
918
- value: input.dependents.size,
919
- tags
920
- }
921
- );
881
+ metrics.add({
882
+ metric: "modules.size",
883
+ type: "size",
884
+ value: input.size,
885
+ tags
886
+ }).add({
887
+ metric: "modules.dependencies",
888
+ type: "count",
889
+ value: input.dependencies.size,
890
+ tags
891
+ }).add({
892
+ metric: "modules.dependents",
893
+ type: "count",
894
+ value: input.dependents.size,
895
+ tags
896
+ });
922
897
  }
923
898
  for (const output of outputs) {
924
899
  const tags = [`assetName:${output.name}`, `assetType:${output.type}`];
@@ -928,72 +903,69 @@ const getUniversalMetrics = (globalContext) => {
928
903
  ...entriesPerAsset.get(cleanAssetName).map((entryName) => `entryName:${entryName}`)
929
904
  );
930
905
  }
931
- metrics.push(
932
- {
933
- metric: "assets.size",
934
- type: "size",
935
- value: output.size,
936
- tags
937
- },
938
- {
939
- metric: "assets.modules.count",
940
- type: "count",
941
- value: output.inputs.length,
942
- tags
943
- }
944
- );
906
+ metrics.add({
907
+ metric: "assets.size",
908
+ type: "size",
909
+ value: output.size,
910
+ tags
911
+ }).add({
912
+ metric: "assets.modules.count",
913
+ type: "count",
914
+ value: output.inputs.length,
915
+ tags
916
+ });
945
917
  }
946
918
  for (const entry of entries) {
947
919
  const tags = [`entryName:${entry.name}`];
948
- metrics.push(
949
- {
950
- metric: "entries.size",
951
- type: "size",
952
- value: entry.size,
953
- tags
954
- },
955
- {
956
- metric: "entries.modules.count",
957
- type: "count",
958
- value: entry.inputs.length,
959
- tags
960
- },
961
- {
962
- metric: "entries.assets.count",
963
- type: "count",
964
- value: entry.outputs.length,
965
- tags
966
- }
967
- );
920
+ metrics.add({
921
+ metric: "entries.size",
922
+ type: "size",
923
+ value: entry.size,
924
+ tags
925
+ }).add({
926
+ metric: "entries.modules.count",
927
+ type: "count",
928
+ value: entry.inputs.length,
929
+ tags
930
+ }).add({
931
+ metric: "entries.assets.count",
932
+ type: "count",
933
+ value: entry.outputs.length,
934
+ tags
935
+ });
968
936
  }
969
937
  return metrics;
970
938
  };
971
- const getMetrics = (globalContext, optionsDD, report) => {
972
- const metrics = [];
939
+ const addMetrics = (globalContext, optionsDD, metricsToSend, report) => {
940
+ const metrics = /* @__PURE__ */ new Set();
973
941
  if (report) {
974
942
  const { timings } = report;
975
943
  if (timings) {
976
944
  if (timings.tapables) {
977
- metrics.push(...getPlugins$1(timings.tapables));
945
+ addPluginMetrics(timings.tapables, metrics);
978
946
  }
979
947
  if (timings.loaders) {
980
- metrics.push(...getLoaders(timings.loaders));
948
+ addLoaderMetrics(timings.loaders, metrics);
981
949
  }
982
950
  }
983
951
  }
984
- metrics.push(...getUniversalMetrics(globalContext));
985
- const metricsToSend = metrics.map((m) => {
986
- let metric = m;
952
+ addUniversalMetrics(globalContext, metrics);
953
+ for (const metric of metrics) {
987
954
  if (optionsDD.filters?.length) {
955
+ let filteredMetric = metric;
988
956
  for (const filter of optionsDD.filters) {
989
- if (metric) {
990
- metric = filter(metric);
957
+ if (!filteredMetric) {
958
+ break;
991
959
  }
960
+ filteredMetric = filter(metric);
961
+ }
962
+ if (filteredMetric) {
963
+ metricsToSend.add(getMetric(filteredMetric, optionsDD));
992
964
  }
965
+ } else {
966
+ metricsToSend.add(getMetric(metric, optionsDD));
993
967
  }
994
- return metric ? getMetric(metric, optionsDD) : null;
995
- }).filter((m) => m !== null);
996
- return metricsToSend;
968
+ }
997
969
  };
998
970
 
999
971
  const outputFiles = async (data, outputOptions, log, cwd) => {
@@ -1027,37 +999,35 @@ const outputFiles = async (data, outputOptions, log, cwd) => {
1027
999
  }
1028
1000
  };
1029
1001
  }
1030
- if (metrics && files.metrics) {
1031
- filesToWrite.metrics = { content: metrics };
1002
+ if (files.metrics) {
1003
+ filesToWrite.metrics = { content: Array.from(metrics) };
1032
1004
  }
1033
1005
  const proms = Object.entries(filesToWrite).map(async ([filename, file]) => {
1034
1006
  const start = Date.now();
1035
- log(`Start writing ${filename}.json.`);
1007
+ log.debug(`Start writing ${filename}.json.`);
1036
1008
  try {
1037
1009
  await outputJson(path.join(outputPath, `${filename}.json`), file.content);
1038
- log(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
1010
+ log.debug(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
1039
1011
  } catch (e) {
1040
- log(
1041
- `Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}`,
1042
- "error"
1012
+ log.error(
1013
+ `Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}`
1043
1014
  );
1044
1015
  errors[filename] = e;
1045
1016
  }
1046
1017
  });
1047
1018
  await Promise.all(proms);
1048
- log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
1019
+ log.debug(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
1049
1020
  const fileErrored = Object.keys(errors);
1050
1021
  if (fileErrored.length) {
1051
- log(
1022
+ log.error(
1052
1023
  `Couldn't write files.
1053
1024
  ${fileErrored.map(
1054
1025
  (file) => ` - ${file}: ${errors[file].toString()}`
1055
- )}`,
1056
- "error"
1026
+ )}`
1057
1027
  );
1058
1028
  }
1059
1029
  } catch (e) {
1060
- log(`Couldn't write files. ${e}`, "error");
1030
+ log.error(`Couldn't write files. ${e}`);
1061
1031
  }
1062
1032
  };
1063
1033
 
@@ -1448,22 +1418,31 @@ const outputTexts = (globalContext, log, report) => {
1448
1418
  valuesToPrint.push(...getAssetsValues(globalContext));
1449
1419
  valuesToPrint.push(...getGeneralValues(globalContext));
1450
1420
  const outputString = renderValues(valuesToPrint);
1451
- log(outputString, "info");
1421
+ log.info(outputString);
1452
1422
  };
1453
1423
 
1454
1424
  const sendMetrics = (metrics, auth, log) => {
1455
1425
  const startSending = Date.now();
1456
1426
  if (!auth.apiKey) {
1457
- log(`Won't send metrics to Datadog: missing API Key.`, "warn");
1427
+ log.warn(`Won't send metrics to Datadog: missing API Key.`);
1458
1428
  return;
1459
1429
  }
1460
- if (!metrics || metrics.length === 0) {
1461
- log(`No metrics to send.`, "warn");
1430
+ if (!metrics.size) {
1431
+ log.warn(`No metrics to send.`);
1462
1432
  return;
1463
1433
  }
1464
- const metricsNames = [...new Set(metrics.map((m) => m.metric))].sort().map((name) => `${name} - ${metrics.filter((m) => m.metric === name).length}`);
1465
- log(`
1466
- Sending ${metrics.length} metrics.
1434
+ const metricIterations = /* @__PURE__ */ new Map();
1435
+ for (const metric of metrics) {
1436
+ if (!metricIterations.has(metric.metric)) {
1437
+ metricIterations.set(metric.metric, 0);
1438
+ }
1439
+ metricIterations.set(metric.metric, metricIterations.get(metric.metric) + 1);
1440
+ }
1441
+ const metricsNames = Array.from(metricIterations.entries()).map(
1442
+ ([name, count]) => `${name} - ${count}`
1443
+ );
1444
+ log.debug(`
1445
+ Sending ${metrics.size} metrics.
1467
1446
  Metrics:
1468
1447
  - ${metricsNames.join("\n - ")}`);
1469
1448
  return doRequest({
@@ -1471,9 +1450,9 @@ Metrics:
1471
1450
  url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
1472
1451
  getData: () => ({ data: JSON.stringify({ series: metrics }) })
1473
1452
  }).then(() => {
1474
- log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
1453
+ log.debug(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
1475
1454
  }).catch((e) => {
1476
- log(`Error sending metrics ${e}`, "error");
1455
+ log.error(`Error sending metrics ${e}`);
1477
1456
  });
1478
1457
  };
1479
1458
 
@@ -1489,7 +1468,7 @@ const wrapPlugins = (build, context) => {
1489
1468
  };
1490
1469
  });
1491
1470
  for (const plugin of plugins) {
1492
- if (plugin.name.includes(PLUGIN_NAME$3)) {
1471
+ if (plugin.name.includes(PLUGIN_NAME$4)) {
1493
1472
  continue;
1494
1473
  }
1495
1474
  const oldSetup = plugin.setup;
@@ -1567,7 +1546,7 @@ const getEsbuildPlugin$1 = (bundlerContext, globalContext, logger) => {
1567
1546
  wrapPlugins(build, globalContext.cwd);
1568
1547
  build.onEnd(async (result) => {
1569
1548
  if (!result.metafile) {
1570
- logger("Missing metafile, can't proceed with modules data.", "warn");
1549
+ logger.warn("Missing metafile, can't proceed with modules data.");
1571
1550
  return;
1572
1551
  }
1573
1552
  const { plugins, modules } = getResults();
@@ -1792,7 +1771,7 @@ class Tapables {
1792
1771
  if (hook._fakeHook) {
1793
1772
  return;
1794
1773
  }
1795
- if (tapableName.includes(PLUGIN_NAME$3)) {
1774
+ if (tapableName.includes(PLUGIN_NAME$4)) {
1796
1775
  return;
1797
1776
  }
1798
1777
  if (!this.hooks[tapableName]) {
@@ -1833,10 +1812,10 @@ class Tapables {
1833
1812
  }
1834
1813
  }
1835
1814
 
1836
- const getWebpackPlugin$1 = (bundlerContext, globalContext) => {
1815
+ const getWebpackPlugin = (bundlerContext, globalContext) => {
1837
1816
  return async (compiler) => {
1838
1817
  globalContext.build.start = Date.now();
1839
- const HOOK_OPTIONS = { name: PLUGIN_NAME$3 };
1818
+ const HOOK_OPTIONS = { name: PLUGIN_NAME$4 };
1840
1819
  const tapables = new Tapables(globalContext.cwd);
1841
1820
  const loaders = new Loaders(globalContext.cwd);
1842
1821
  tapables.throughHooks(compiler);
@@ -1866,19 +1845,19 @@ const getWebpackPlugin$1 = (bundlerContext, globalContext) => {
1866
1845
  const helpers$2 = {
1867
1846
  filters: defaultFilters
1868
1847
  };
1869
- const getPlugins = (options, context) => {
1848
+ const getPlugins = (options, context, logger) => {
1870
1849
  let realBuildEnd = 0;
1871
1850
  const bundlerContext = {
1872
1851
  start: Date.now()
1873
1852
  };
1874
1853
  const telemetryOptions = validateOptions(options);
1875
- const logger = context.getLogger(PLUGIN_NAME$3);
1876
1854
  const plugins = [];
1877
1855
  const legacyPlugin = {
1878
- name: PLUGIN_NAME$3,
1856
+ name: PLUGIN_NAME$4,
1879
1857
  enforce: "pre",
1880
1858
  esbuild: getEsbuildPlugin$1(bundlerContext, context, logger),
1881
- webpack: getWebpackPlugin$1(bundlerContext, context)
1859
+ webpack: getWebpackPlugin(bundlerContext, context),
1860
+ rspack: getWebpackPlugin(bundlerContext, context)
1882
1861
  };
1883
1862
  const universalPlugin = {
1884
1863
  name: "datadog-universal-telemetry-plugin",
@@ -1894,9 +1873,9 @@ const getPlugins = (options, context) => {
1894
1873
  context.build.end = Date.now();
1895
1874
  context.build.duration = context.build.end - context.build.start;
1896
1875
  context.build.writeDuration = context.build.end - realBuildEnd;
1897
- const metrics = [];
1876
+ const metrics = /* @__PURE__ */ new Set();
1898
1877
  const optionsDD = getOptionsDD(telemetryOptions);
1899
- metrics.push(...getMetrics(context, optionsDD, bundlerContext.report));
1878
+ addMetrics(context, optionsDD, metrics, bundlerContext.report);
1900
1879
  await outputFiles(
1901
1880
  { report: bundlerContext.report, metrics },
1902
1881
  telemetryOptions.output,
@@ -1961,11 +1940,15 @@ const getEsbuildPlugin = (context, log) => {
1961
1940
  const entrypoints = build.initialOptions.entryPoints;
1962
1941
  const entryNames = getEntryNames(entrypoints, context);
1963
1942
  build.onEnd((result) => {
1964
- context.build.errors.push(...result.errors.map((err) => err.text));
1965
- context.build.warnings.push(...result.warnings.map((err) => err.text));
1943
+ for (const error of result.errors) {
1944
+ context.build.errors.push(error.text);
1945
+ }
1946
+ for (const warning of result.warnings) {
1947
+ context.build.warnings.push(warning.text);
1948
+ }
1966
1949
  const warn = (warning) => {
1967
1950
  context.build.warnings.push(warning);
1968
- log(warning, "warn");
1951
+ log.warn(warning);
1969
1952
  };
1970
1953
  if (!result.metafile) {
1971
1954
  warn("Missing metafile from build result.");
@@ -2212,7 +2195,7 @@ const getRollupPlugin = (context, log) => {
2212
2195
  const reportOutputsIndexed = {};
2213
2196
  const warn = (warning) => {
2214
2197
  context.build.warnings.push(warning);
2215
- log(warning, "warn");
2198
+ log.warn(warning);
2216
2199
  };
2217
2200
  for (const [filepath, { dependencies, dependents }] of Object.entries(importsReport)) {
2218
2201
  for (const dependency of dependencies) {
@@ -2362,14 +2345,14 @@ const getRollupPlugin = (context, log) => {
2362
2345
  };
2363
2346
  };
2364
2347
 
2365
- const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2348
+ const getXpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2366
2349
  const inputs = [];
2367
2350
  const outputs = [];
2368
2351
  const entries = [];
2369
- const warnings = [];
2370
2352
  const reportInputsIndexed = /* @__PURE__ */ new Map();
2371
2353
  const reportOutputsIndexed = /* @__PURE__ */ new Map();
2372
2354
  const modulesPerFile = /* @__PURE__ */ new Map();
2355
+ const moduleIndex = /* @__PURE__ */ new Map();
2373
2356
  const tempSourcemaps = [];
2374
2357
  const tempDeps = /* @__PURE__ */ new Map();
2375
2358
  const isModuleSupported = (moduleIdentifier) => {
@@ -2379,83 +2362,148 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2379
2362
  );
2380
2363
  };
2381
2364
  const warn = (warning) => {
2382
- warnings.push(warning);
2383
- log(warning, "warn");
2365
+ context.build.warnings.push(warning);
2366
+ log.warn(warning);
2384
2367
  };
2385
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
2386
- compilation.hooks.finishModules.tap(PLUGIN_NAME, (finishedModules) => {
2387
- const getModuleFromDep = (dep) => {
2388
- return compilation.moduleGraph ? compilation.moduleGraph.getModule(dep) : dep.module;
2389
- };
2390
- for (const module of finishedModules) {
2391
- const moduleIdentifier = module.identifier();
2392
- const dependencies = new Set(
2393
- [...module.dependencies, ...module.blocks.flatMap((b) => b.dependencies)].filter(
2394
- (dep) => (
2395
- // Ignore side effects.
2396
- dep.type !== "harmony side effect evaluation" && // Ignore those we can't identify.
2397
- getModuleFromDep(dep)?.identifier() && // Only what we support.
2398
- isModuleSupported(getModuleFromDep(dep)?.identifier()) && // Don't add itself as a dependency.
2399
- getModuleFromDep(dep)?.identifier() !== moduleIdentifier
2400
- )
2401
- ).map((dep) => {
2402
- return getModuleFromDep(dep)?.identifier();
2403
- }).filter(Boolean)
2404
- );
2405
- if (!isModuleSupported(moduleIdentifier)) {
2406
- continue;
2407
- }
2408
- for (const depIdentifier of dependencies) {
2409
- const depDeps = tempDeps.get(depIdentifier) || {
2410
- dependencies: /* @__PURE__ */ new Set(),
2411
- dependents: /* @__PURE__ */ new Set()
2412
- };
2413
- depDeps.dependents.add(moduleIdentifier);
2414
- tempDeps.set(depIdentifier, depDeps);
2415
- }
2416
- const moduleDeps = tempDeps.get(moduleIdentifier) || {
2417
- dependents: /* @__PURE__ */ new Set(),
2418
- dependencies: /* @__PURE__ */ new Set()
2419
- };
2420
- for (const moduleDep of dependencies) {
2421
- moduleDeps.dependencies.add(moduleDep);
2368
+ const getKeysToIndex = (mod) => {
2369
+ const values = {
2370
+ identifier: mod.identifier()
2371
+ };
2372
+ if ("resource" in mod && typeof mod.resource === "string") {
2373
+ values.resource = mod.resource;
2374
+ }
2375
+ if ("request" in mod && typeof mod.request === "string") {
2376
+ values.request = mod.request;
2377
+ }
2378
+ if ("rawRequest" in mod && typeof mod.rawRequest === "string") {
2379
+ values.rawRequest = mod.rawRequest;
2380
+ }
2381
+ if ("userRequest" in mod && typeof mod.userRequest === "string") {
2382
+ values.userRequest = mod.userRequest;
2383
+ }
2384
+ const keysToIndex = /* @__PURE__ */ new Set();
2385
+ for (const [key, value] of Object.entries(values)) {
2386
+ if (!value) {
2387
+ continue;
2388
+ }
2389
+ if (moduleIndex.has(value)) {
2390
+ warn(`Module ${mod.identifier()} is already indexed by ${key}.`);
2391
+ if (moduleIndex.get(value) !== mod) {
2392
+ warn(`Module ${mod.identifier()} is indexed with a different value.`);
2422
2393
  }
2423
- tempDeps.set(moduleIdentifier, moduleDeps);
2424
- const file = {
2425
- size: module.size() || 0,
2426
- name: cleanName(context, moduleIdentifier),
2427
- dependencies: /* @__PURE__ */ new Set(),
2428
- dependents: /* @__PURE__ */ new Set(),
2429
- filepath: moduleIdentifier,
2430
- type: getType(moduleIdentifier)
2431
- };
2432
- inputs.push(file);
2433
- reportInputsIndexed.set(moduleIdentifier, file);
2394
+ } else {
2395
+ keysToIndex.add(value);
2434
2396
  }
2435
- for (const input of inputs) {
2436
- const depsReport = tempDeps.get(input.filepath);
2437
- if (!depsReport) {
2438
- warn(`Could not find dependency report for ${input.name}`);
2439
- continue;
2397
+ }
2398
+ return keysToIndex;
2399
+ };
2400
+ const getAllDependencies = (module, dependencies = []) => {
2401
+ if ("dependencies" in module) {
2402
+ for (const dependency of module.dependencies) {
2403
+ dependencies.push(dependency);
2404
+ getAllDependencies(dependency, dependencies);
2405
+ }
2406
+ }
2407
+ if ("blocks" in module) {
2408
+ for (const block of module.blocks) {
2409
+ getAllDependencies(block, dependencies);
2410
+ }
2411
+ }
2412
+ return dependencies;
2413
+ };
2414
+ const getModuleFromDep = (mod, dep) => {
2415
+ if ("request" in dep && dep.request) {
2416
+ if (moduleIndex.has(dep.request)) {
2417
+ return moduleIndex.get(dep.request);
2418
+ }
2419
+ if (mod.context && moduleIndex.has(getAbsolutePath(mod.context, dep.request))) {
2420
+ return moduleIndex.get(getAbsolutePath(mod.context, dep.request));
2421
+ }
2422
+ }
2423
+ };
2424
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
2425
+ compilation.hooks.finishModules.tap(
2426
+ PLUGIN_NAME,
2427
+ (finishedModules) => {
2428
+ for (const module of finishedModules) {
2429
+ const keysToIndex = getKeysToIndex(module);
2430
+ for (const key of keysToIndex) {
2431
+ moduleIndex.set(key, module);
2432
+ }
2440
2433
  }
2441
- for (const dependency of depsReport.dependencies) {
2442
- const depInput = reportInputsIndexed.get(dependency);
2443
- if (!depInput) {
2444
- warn(`Could not find input of dependency ${dependency}`);
2434
+ for (const module of finishedModules) {
2435
+ const moduleIdentifier = module.identifier();
2436
+ const dependencies = new Set(
2437
+ getAllDependencies(module).map((dep) => {
2438
+ const mod = getModuleFromDep(module, dep);
2439
+ if (!mod || !mod.identifier()) {
2440
+ return false;
2441
+ }
2442
+ const identifier = mod.identifier();
2443
+ if (!isModuleSupported(identifier)) {
2444
+ return false;
2445
+ }
2446
+ if (identifier === moduleIdentifier) {
2447
+ return false;
2448
+ }
2449
+ return identifier;
2450
+ }).filter(Boolean)
2451
+ );
2452
+ if (!isModuleSupported(moduleIdentifier)) {
2445
2453
  continue;
2446
2454
  }
2447
- input.dependencies.add(depInput);
2455
+ for (const depIdentifier of dependencies) {
2456
+ const depDeps = tempDeps.get(depIdentifier) || {
2457
+ dependencies: /* @__PURE__ */ new Set(),
2458
+ dependents: /* @__PURE__ */ new Set()
2459
+ };
2460
+ depDeps.dependents.add(moduleIdentifier);
2461
+ tempDeps.set(depIdentifier, depDeps);
2462
+ }
2463
+ const moduleDeps = tempDeps.get(moduleIdentifier) || {
2464
+ dependents: /* @__PURE__ */ new Set(),
2465
+ dependencies: /* @__PURE__ */ new Set()
2466
+ };
2467
+ for (const moduleDep of dependencies) {
2468
+ moduleDeps.dependencies.add(moduleDep);
2469
+ }
2470
+ tempDeps.set(moduleIdentifier, moduleDeps);
2471
+ const file = {
2472
+ size: module.size() || 0,
2473
+ name: cleanName(context, moduleIdentifier),
2474
+ dependencies: /* @__PURE__ */ new Set(),
2475
+ dependents: /* @__PURE__ */ new Set(),
2476
+ filepath: moduleIdentifier,
2477
+ type: getType(moduleIdentifier)
2478
+ };
2479
+ inputs.push(file);
2480
+ reportInputsIndexed.set(moduleIdentifier, file);
2448
2481
  }
2449
- for (const dependent of depsReport.dependents) {
2450
- const depInput = reportInputsIndexed.get(dependent);
2451
- if (!depInput) {
2452
- warn(`Could not find input of dependent ${dependent}`);
2482
+ for (const input of inputs) {
2483
+ const depsReport = tempDeps.get(input.filepath);
2484
+ if (!depsReport) {
2485
+ warn(`Could not find dependency report for ${input.name}`);
2453
2486
  continue;
2454
2487
  }
2455
- input.dependents.add(depInput);
2488
+ for (const dependency of depsReport.dependencies) {
2489
+ const depInput = reportInputsIndexed.get(dependency);
2490
+ if (!depInput) {
2491
+ warn(`Could not find input of dependency ${dependency}`);
2492
+ continue;
2493
+ }
2494
+ input.dependencies.add(depInput);
2495
+ }
2496
+ for (const dependent of depsReport.dependents) {
2497
+ const depInput = reportInputsIndexed.get(dependent);
2498
+ if (!depInput) {
2499
+ warn(`Could not find input of dependent ${dependent}`);
2500
+ continue;
2501
+ }
2502
+ input.dependents.add(depInput);
2503
+ }
2456
2504
  }
2457
2505
  }
2458
- });
2506
+ );
2459
2507
  });
2460
2508
  compiler.hooks.afterEmit.tap(PLUGIN_NAME, (result) => {
2461
2509
  const chunks = result.chunks;
@@ -2468,7 +2516,13 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2468
2516
  const chunkGraph = result.chunkGraph;
2469
2517
  for (const chunk of chunks) {
2470
2518
  const files = getChunkFiles(chunk);
2471
- const chunkModules = (chunkGraph ? chunkGraph?.getChunkModules(chunk) : chunk.getModules()).flatMap((m) => {
2519
+ const chunkModules = (chunkGraph ? (
2520
+ // @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
2521
+ chunkGraph?.getChunkModules(chunk)
2522
+ ) : (
2523
+ // This one is for webpack 4.
2524
+ "getModules" in chunk && typeof chunk.getModules === "function" ? chunk.getModules() : []
2525
+ )).flatMap((m) => {
2472
2526
  return "modules" in m && Array.isArray(m.modules) ? m.modules.map((m2) => m2.identifier()) : m.identifier();
2473
2527
  }).filter(isModuleSupported);
2474
2528
  for (const file of files) {
@@ -2523,11 +2577,16 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2523
2577
  let size = 0;
2524
2578
  const entryFiles = entrypoint.chunks.flatMap(getChunkFiles);
2525
2579
  const entryFilename = entrypoint.chunks.filter(
2526
- (c) => (
2527
- // Webpack5 forces you to use the chunkGraph to get the modules.
2528
- chunkGraph ? chunkGraph.getNumberOfEntryModules(c) > 0 : c.hasEntryModule()
2580
+ (chunk) => chunkGraph ? (
2581
+ // @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
2582
+ chunkGraph.getChunkEntryModulesIterable(chunk)
2583
+ ) : (
2584
+ // This one is for webpack 4.
2585
+ "hasEntryModule" in chunk && typeof chunk.hasEntryModule === "function" ? chunk.hasEntryModule() : false
2529
2586
  )
2530
- ).flatMap((c) => Array.from(c.files))[0];
2587
+ ).flatMap((c) => Array.from(c.files)).filter(
2588
+ (f) => f.includes(name) || entrypoint.name && f.includes(entrypoint.name)
2589
+ )[0];
2531
2590
  for (const file2 of entryFiles) {
2532
2591
  const outputFound = reportOutputsIndexed.get(file2);
2533
2592
  if (!file2 || !outputFound) {
@@ -2550,23 +2609,27 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2550
2609
  };
2551
2610
  entries.push(file);
2552
2611
  }
2553
- context.build.errors.push(...result.errors.map((err) => err.message));
2554
- context.build.warnings.push(...warnings, ...result.warnings.map((err) => err.message));
2612
+ for (const error of result.errors) {
2613
+ context.build.errors.push(error.message);
2614
+ }
2615
+ for (const warning of result.warnings) {
2616
+ context.build.warnings.push(warning.message);
2617
+ }
2555
2618
  context.build.inputs = inputs;
2556
2619
  context.build.outputs = outputs;
2557
2620
  context.build.entries = entries;
2558
2621
  });
2559
2622
  };
2560
2623
 
2561
- const PLUGIN_NAME$2 = "datadog-build-report-plugin";
2562
- const getBuildReportPlugins = (context) => {
2563
- const log = context.getLogger(PLUGIN_NAME$2);
2624
+ const PLUGIN_NAME$3 = "datadog-build-report-plugin";
2625
+ const getBuildReportPlugins = (context, log) => {
2564
2626
  return [
2565
2627
  {
2566
- name: PLUGIN_NAME$2,
2628
+ name: PLUGIN_NAME$3,
2567
2629
  enforce: "post",
2568
2630
  esbuild: getEsbuildPlugin(context, log),
2569
- webpack: getWebpackPlugin(context, PLUGIN_NAME$2, log),
2631
+ rspack: getXpackPlugin(context, PLUGIN_NAME$3, log),
2632
+ webpack: getXpackPlugin(context, PLUGIN_NAME$3, log),
2570
2633
  // Vite and Rollup have the same API.
2571
2634
  vite: getRollupPlugin(context, log),
2572
2635
  rollup: getRollupPlugin(context, log)
@@ -2574,7 +2637,7 @@ const getBuildReportPlugins = (context) => {
2574
2637
  ];
2575
2638
  };
2576
2639
 
2577
- const PLUGIN_NAME$1 = "datadog-bundler-report-plugin";
2640
+ const PLUGIN_NAME$2 = "datadog-bundler-report-plugin";
2578
2641
  const rollupPlugin = (context) => ({
2579
2642
  options(options) {
2580
2643
  context.bundler.rawConfig = options;
@@ -2589,9 +2652,15 @@ const rollupPlugin = (context) => ({
2589
2652
  }
2590
2653
  }
2591
2654
  });
2655
+ const xpackPlugin = (context) => (compiler) => {
2656
+ context.bundler.rawConfig = compiler.options;
2657
+ if (compiler.options.output?.path) {
2658
+ context.bundler.outDir = compiler.options.output.path;
2659
+ }
2660
+ };
2592
2661
  const getBundlerReportPlugins = (globalContext) => {
2593
2662
  const bundlerReportPlugin = {
2594
- name: PLUGIN_NAME$1,
2663
+ name: PLUGIN_NAME$2,
2595
2664
  enforce: "pre",
2596
2665
  esbuild: {
2597
2666
  setup(build) {
@@ -2605,12 +2674,8 @@ const getBundlerReportPlugins = (globalContext) => {
2605
2674
  build.initialOptions.metafile = true;
2606
2675
  }
2607
2676
  },
2608
- webpack(compiler) {
2609
- globalContext.bundler.rawConfig = compiler.options;
2610
- if (compiler.options.output?.path) {
2611
- globalContext.bundler.outDir = compiler.options.output.path;
2612
- }
2613
- },
2677
+ webpack: xpackPlugin(globalContext),
2678
+ rspack: xpackPlugin(globalContext),
2614
2679
  // Vite and Rollup have the same API.
2615
2680
  vite: rollupPlugin(globalContext),
2616
2681
  rollup: rollupPlugin(globalContext)
@@ -2778,10 +2843,11 @@ const getRepositoryData = async (git, repositoryURL) => {
2778
2843
  return data;
2779
2844
  };
2780
2845
 
2846
+ const PLUGIN_NAME$1 = "datadog-git-plugin";
2781
2847
  const getGitPlugins = (options, context) => {
2782
2848
  return [
2783
2849
  {
2784
- name: "datadog-git-plugin",
2850
+ name: PLUGIN_NAME$1,
2785
2851
  enforce: "pre",
2786
2852
  async buildStart() {
2787
2853
  const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;
@@ -2839,10 +2905,10 @@ const processItem = async (item, log) => {
2839
2905
  } catch (error) {
2840
2906
  const itemId = `${item.type} - ${truncateString(item.value)}`;
2841
2907
  if (item.fallback) {
2842
- log(`Fallback for "${itemId}": ${error.toString()}`, "warn");
2908
+ log.warn(`Fallback for "${itemId}": ${error.toString()}`);
2843
2909
  result = await processItem(item.fallback, log);
2844
2910
  } else {
2845
- log(`Failed "${itemId}": ${error.toString()}`, "warn");
2911
+ log.warn(`Failed "${itemId}": ${error.toString()}`);
2846
2912
  result = "";
2847
2913
  }
2848
2914
  }
@@ -2857,8 +2923,7 @@ const processInjections = async (toInject, log) => {
2857
2923
  return results.filter(Boolean);
2858
2924
  };
2859
2925
 
2860
- const getInjectionPlugins = (bundler, context, toInject) => {
2861
- const log = context.getLogger(PLUGIN_NAME);
2926
+ const getInjectionPlugins = (bundler, context, toInject, log) => {
2862
2927
  const contentToInject = [];
2863
2928
  const getContentToInject = () => {
2864
2929
  const before = `
@@ -2898,11 +2963,11 @@ ${after}`;
2898
2963
  );
2899
2964
  try {
2900
2965
  if (fs.existsSync(absolutePathInjectFile)) {
2901
- log(`Temporary file "${INJECTED_FILE_PATH}" already exists.`, "warn");
2966
+ log.warn(`Temporary file "${INJECTED_FILE_PATH}" already exists.`);
2902
2967
  }
2903
2968
  await outputFile(absolutePathInjectFile, getContentToInject());
2904
2969
  } catch (e) {
2905
- log(`Could not create the file: ${e.message}`, "error");
2970
+ log.error(`Could not create the file: ${e.message}`);
2906
2971
  }
2907
2972
  },
2908
2973
  async buildEnd() {
@@ -2913,6 +2978,7 @@ ${after}`;
2913
2978
  context.bundler.outDir,
2914
2979
  INJECTED_FILE_PATH
2915
2980
  );
2981
+ log.debug(`Removing temporary file "${INJECTED_FILE_PATH}".`);
2916
2982
  await rm(absolutePathInjectFile);
2917
2983
  }
2918
2984
  },
@@ -2935,7 +3001,7 @@ ${after}`;
2935
3001
  const BannerPlugin = compiler?.webpack?.BannerPlugin || bundler?.BannerPlugin || bundler?.default?.BannerPlugin;
2936
3002
  compiler?.webpack?.ChunkGraph || bundler?.ChunkGraph || bundler?.default?.ChunkGraph;
2937
3003
  if (!BannerPlugin) {
2938
- log("Missing BannerPlugin", "error");
3004
+ log.error("Missing BannerPlugin");
2939
3005
  }
2940
3006
  let chunkGraph;
2941
3007
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
@@ -2967,6 +3033,20 @@ ${after}`;
2967
3033
  })
2968
3034
  );
2969
3035
  },
3036
+ rspack: (compiler) => {
3037
+ compiler.options.plugins = compiler.options.plugins || [];
3038
+ compiler.options.plugins.push(
3039
+ new compiler.rspack.BannerPlugin({
3040
+ // Not wrapped in comments.
3041
+ raw: true,
3042
+ // Only entry modules.
3043
+ entryOnly: true,
3044
+ banner() {
3045
+ return getContentToInject();
3046
+ }
3047
+ })
3048
+ );
3049
+ },
2970
3050
  rollup: rollupInjectionPlugin,
2971
3051
  vite: rollupInjectionPlugin
2972
3052
  }
@@ -2998,25 +3078,43 @@ const buildPluginFactory = ({
2998
3078
  injections,
2999
3079
  version
3000
3080
  });
3081
+ const getLogger = getLoggerFactory(context.build, options.logLevel);
3001
3082
  context.pluginNames.push(HOST_NAME);
3002
3083
  const plugins = [
3003
3084
  // Prefill with our internal plugins.
3004
3085
  // #internal-plugins-injection-marker
3005
- ...getBuildReportPlugins(context),
3086
+ ...getBuildReportPlugins(context, getLogger("datadog-build-report-plugin")),
3006
3087
  ...getBundlerReportPlugins(context),
3007
3088
  ...getGitPlugins(options, context),
3008
- ...getInjectionPlugins(bundler, context, injections)
3089
+ ...getInjectionPlugins(
3090
+ bundler,
3091
+ context,
3092
+ injections,
3093
+ getLogger("datadog-injection-plugin")
3094
+ )
3009
3095
  // #internal-plugins-injection-marker
3010
3096
  ];
3011
3097
  if (options.customPlugins) {
3012
- const customPlugins = options.customPlugins(options, context);
3098
+ const customPlugins = options.customPlugins(
3099
+ options,
3100
+ context,
3101
+ getLogger("datadog-custom-plugins")
3102
+ );
3013
3103
  plugins.push(...customPlugins);
3014
3104
  }
3015
3105
  if (options[CONFIG_KEY$1] && options[CONFIG_KEY$1].disabled !== true) {
3016
- plugins.push(...getPlugins$2(options, context));
3106
+ plugins.push(
3107
+ ...getPlugins$1(options, context, getLogger(PLUGIN_NAME$5))
3108
+ );
3017
3109
  }
3018
3110
  if (options[CONFIG_KEY] && options[CONFIG_KEY].disabled !== true) {
3019
- plugins.push(...getPlugins(options, context));
3111
+ plugins.push(
3112
+ ...getPlugins(
3113
+ options,
3114
+ context,
3115
+ getLogger(PLUGIN_NAME$4)
3116
+ )
3117
+ );
3020
3118
  }
3021
3119
  context.pluginNames.push(...plugins.map((plugin) => plugin.name));
3022
3120
  return plugins;
@@ -3025,7 +3123,7 @@ const buildPluginFactory = ({
3025
3123
 
3026
3124
  var name = "@datadog/esbuild-plugin";
3027
3125
  var packageManager = "yarn@4.0.2";
3028
- var version$1 = "2.3.3-dev-2";
3126
+ var version$1 = "2.3.3-dev-3";
3029
3127
  var license = "MIT";
3030
3128
  var author = "Datadog";
3031
3129
  var description = "Datadog ESBuild Plugin";