@datadog/esbuild-plugin 2.3.0-dev → 2.3.0-dev-1

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.
@@ -10823,7 +10823,7 @@ const glob = Object.assign(glob_, {
10823
10823
  glob.glob = glob;
10824
10824
 
10825
10825
  const EXTENSION_RX = /\.(?!.*(?:\.|\/|\\))(\w{1,})/g;
10826
- const QUERY_RX = /(\?|!|%3F)+/gi;
10826
+ const QUERY_RX = /(\?|%3F|\|)+/gi;
10827
10827
  const getExtension = (filepath) => {
10828
10828
  EXTENSION_RX.lastIndex = 0;
10829
10829
  return EXTENSION_RX.exec(filepath)?.[1];
@@ -10837,14 +10837,83 @@ const getType = (name) => {
10837
10837
  }
10838
10838
  return getExtension(cleanPath(name)) || "unknown";
10839
10839
  };
10840
+ const serializeBuildReport = (report) => {
10841
+ const jsonReport = {
10842
+ errors: report.errors,
10843
+ warnings: report.warnings,
10844
+ start: report.start,
10845
+ end: report.end,
10846
+ duration: report.duration,
10847
+ writeDuration: report.writeDuration,
10848
+ entries: [],
10849
+ inputs: [],
10850
+ outputs: []
10851
+ };
10852
+ for (const entry of report.entries || []) {
10853
+ const newEntry = { ...entry, inputs: [], outputs: [] };
10854
+ if (entry.inputs) {
10855
+ newEntry.inputs = entry.inputs.map((file) => file.filepath);
10856
+ }
10857
+ if (entry.outputs) {
10858
+ newEntry.outputs = entry.outputs.map((file) => file.filepath);
10859
+ }
10860
+ jsonReport.entries.push(newEntry);
10861
+ }
10862
+ for (const input of report.inputs || []) {
10863
+ const newInput = { ...input, dependencies: [], dependents: [] };
10864
+ if (input.dependencies) {
10865
+ for (const dependency of input.dependencies) {
10866
+ newInput.dependencies.push(dependency.filepath);
10867
+ }
10868
+ }
10869
+ if (input.dependents) {
10870
+ for (const dependent of input.dependents) {
10871
+ newInput.dependents.push(dependent.filepath);
10872
+ }
10873
+ }
10874
+ jsonReport.inputs.push(newInput);
10875
+ }
10876
+ for (const output of report.outputs || []) {
10877
+ const newOutput = { ...output, inputs: [] };
10878
+ if (output.inputs) {
10879
+ newOutput.inputs = output.inputs.map((file) => file.filepath);
10880
+ }
10881
+ jsonReport.outputs.push(newOutput);
10882
+ }
10883
+ return jsonReport;
10884
+ };
10840
10885
  const BUNDLER_SPECIFICS = ["unknown", "commonjsHelpers.js", "vite/preload-helper.js"];
10841
- const cleanReport = (report, filepath) => {
10842
- return Array.from(new Set(report.map(cleanPath))).filter(
10843
- (reportFilepath) => reportFilepath !== filepath && !BUNDLER_SPECIFICS.includes(reportFilepath)
10844
- );
10886
+ const cleanReport = (report, filepath, filter) => {
10887
+ const cleanedReport = /* @__PURE__ */ new Set();
10888
+ for (const reportFilepath of report) {
10889
+ const cleanedPath = cleanPath(reportFilepath);
10890
+ if (
10891
+ // Don't add itself into it.
10892
+ cleanedPath === filepath || // Remove common specific files injected by bundlers.
10893
+ BUNDLER_SPECIFICS.includes(cleanedPath)
10894
+ ) {
10895
+ continue;
10896
+ }
10897
+ if (filter) {
10898
+ const filteredValue = filter(cleanedPath);
10899
+ if (filteredValue) {
10900
+ cleanedReport.add(filteredValue);
10901
+ }
10902
+ } else {
10903
+ cleanedReport.add(cleanedPath);
10904
+ }
10905
+ }
10906
+ return cleanedReport;
10845
10907
  };
10846
10908
  const cleanPath = (filepath) => {
10847
- return filepath.split(QUERY_RX).shift().replace(/^[^\w\s.,!@#$%^&*()=+~`\-/]+/, "");
10909
+ return filepath.split("!").pop().split(QUERY_RX).shift().replace(/^[^\w\s.,!@#$%^&*()=+~`\-/]+/, "");
10910
+ };
10911
+ const getResolvedPath = (filepath) => {
10912
+ try {
10913
+ return require.resolve(filepath);
10914
+ } catch (e) {
10915
+ return filepath;
10916
+ }
10848
10917
  };
10849
10918
  const cleanName = (context, filepath) => {
10850
10919
  if (filepath === "unknown") {
@@ -10853,12 +10922,7 @@ const cleanName = (context, filepath) => {
10853
10922
  if (filepath.includes("webpack/runtime")) {
10854
10923
  return filepath.replace("webpack/runtime/", "").replace(/ +/g, "-");
10855
10924
  }
10856
- let resolvedPath = filepath;
10857
- try {
10858
- resolvedPath = require.resolve(filepath);
10859
- } catch (e) {
10860
- }
10861
- return resolvedPath.replace(context.bundler.outDir, "").replace(context.cwd, "").split("node_modules").pop().split("?").shift().replace(/^\/+/, "");
10925
+ return filepath.split("!").pop().replace(context.bundler.outDir, "").replace(context.cwd, "").split("node_modules").pop().split(QUERY_RX).shift().replace(/^\/+/, "");
10862
10926
  };
10863
10927
 
10864
10928
  const reIndexMeta = (obj, cwd) => Object.fromEntries(
@@ -10881,7 +10945,7 @@ const getEntryNames = (entrypoints, context) => {
10881
10945
  const fullPath = entry && typeof entry === "object" ? entry.in : entry;
10882
10946
  const allFiles = getAllEntryFiles(fullPath, context.cwd);
10883
10947
  for (const file of allFiles) {
10884
- const cleanedName = cleanName(context, file);
10948
+ const cleanedName = cleanName(context, getResolvedPath(file));
10885
10949
  entryNames.set(cleanedName, cleanedName);
10886
10950
  }
10887
10951
  }
@@ -10890,7 +10954,7 @@ const getEntryNames = (entrypoints, context) => {
10890
10954
  for (const [entryName, entryPath] of entryList) {
10891
10955
  const allFiles = getAllEntryFiles(entryPath, context.cwd);
10892
10956
  for (const file of allFiles) {
10893
- const cleanedName = cleanName(context, file);
10957
+ const cleanedName = cleanName(context, getResolvedPath(file));
10894
10958
  entryNames.set(cleanedName, entryName);
10895
10959
  }
10896
10960
  }
@@ -10928,8 +10992,8 @@ const getEsbuildPlugin$2 = (context, log) => {
10928
10992
  const file = {
10929
10993
  name: cleanName(context, filename),
10930
10994
  filepath,
10931
- dependents: [],
10932
- dependencies: [],
10995
+ dependents: /* @__PURE__ */ new Set(),
10996
+ dependencies: /* @__PURE__ */ new Set(),
10933
10997
  size: input.bytes,
10934
10998
  type: getType(filename)
10935
10999
  };
@@ -11004,7 +11068,17 @@ const getEsbuildPlugin$2 = (context, log) => {
11004
11068
  meta: metaOutputsIndexed
11005
11069
  }
11006
11070
  };
11071
+ const FILE_EXCEPTIONS_RX = /(<runtime>|https:|file:|data:|#)/g;
11072
+ const isFileSupported = (filePath) => {
11073
+ if (filePath.match(FILE_EXCEPTIONS_RX)) {
11074
+ return false;
11075
+ }
11076
+ return true;
11077
+ };
11007
11078
  const getAllImports = (filePath, ref, allImports = {}) => {
11079
+ if (!isFileSupported(filePath)) {
11080
+ return allImports;
11081
+ }
11008
11082
  const file = ref.report[filePath];
11009
11083
  if (!file) {
11010
11084
  warn(`Could not find report's ${filePath}`);
@@ -11056,14 +11130,17 @@ const getEsbuildPlugin$2 = (context, log) => {
11056
11130
  continue;
11057
11131
  }
11058
11132
  for (const dependency of metaFile.imports) {
11133
+ if (!isFileSupported(dependency.path)) {
11134
+ continue;
11135
+ }
11059
11136
  const dependencyPath = path$i.join(cwd, dependency.path);
11060
11137
  const dependencyFile = references.inputs.report[dependencyPath];
11061
11138
  if (!dependencyFile) {
11062
11139
  warn(`Could not find input file of ${dependency.path}`);
11063
11140
  continue;
11064
11141
  }
11065
- input.dependencies.push(dependencyFile);
11066
- dependencyFile.dependents.push(input);
11142
+ input.dependencies.add(dependencyFile);
11143
+ dependencyFile.dependents.add(input);
11067
11144
  }
11068
11145
  }
11069
11146
  context.build.outputs = outputs;
@@ -11090,19 +11167,23 @@ const getRollupPlugin$1 = (context, log) => {
11090
11167
  moduleParsed(info) {
11091
11168
  const cleanId = cleanPath(info.id);
11092
11169
  const report = importsReport[cleanId] || {
11093
- dependencies: [],
11094
- dependents: []
11170
+ dependencies: /* @__PURE__ */ new Set(),
11171
+ dependents: /* @__PURE__ */ new Set()
11095
11172
  };
11096
11173
  const newDependencies = cleanReport(
11097
- [...info.dynamicallyImportedIds, ...info.importedIds],
11174
+ /* @__PURE__ */ new Set([...info.dynamicallyImportedIds, ...info.importedIds]),
11098
11175
  cleanId
11099
- ).filter((dependency) => !report.dependencies.includes(dependency));
11176
+ );
11100
11177
  const newDependents = cleanReport(
11101
- [...info.dynamicImporters, ...info.importers],
11178
+ /* @__PURE__ */ new Set([...info.dynamicImporters, ...info.importers]),
11102
11179
  cleanId
11103
- ).filter((dependent) => !report.dependents.includes(dependent));
11104
- report.dependencies.push(...newDependencies);
11105
- report.dependents.push(...newDependents);
11180
+ );
11181
+ for (const dependent of newDependents) {
11182
+ report.dependents.add(dependent);
11183
+ }
11184
+ for (const dependency of newDependencies) {
11185
+ report.dependencies.add(dependency);
11186
+ }
11106
11187
  importsReport[cleanId] = report;
11107
11188
  },
11108
11189
  writeBundle(options, bundle) {
@@ -11121,22 +11202,28 @@ const getRollupPlugin$1 = (context, log) => {
11121
11202
  for (const dependency of dependencies) {
11122
11203
  const cleanedDependency = cleanPath(dependency);
11123
11204
  if (!importsReport[cleanedDependency]) {
11124
- importsReport[cleanedDependency] = { dependencies: [], dependents: [] };
11205
+ importsReport[cleanedDependency] = {
11206
+ dependencies: /* @__PURE__ */ new Set(),
11207
+ dependents: /* @__PURE__ */ new Set()
11208
+ };
11125
11209
  }
11126
- if (importsReport[cleanedDependency].dependents.includes(filepath)) {
11210
+ if (importsReport[cleanedDependency].dependents.has(filepath)) {
11127
11211
  continue;
11128
11212
  }
11129
- importsReport[cleanedDependency].dependents.push(filepath);
11213
+ importsReport[cleanedDependency].dependents.add(filepath);
11130
11214
  }
11131
11215
  for (const dependent of dependents) {
11132
11216
  const cleanedDependent = cleanPath(dependent);
11133
11217
  if (!importsReport[cleanedDependent]) {
11134
- importsReport[cleanedDependent] = { dependencies: [], dependents: [] };
11218
+ importsReport[cleanedDependent] = {
11219
+ dependencies: /* @__PURE__ */ new Set(),
11220
+ dependents: /* @__PURE__ */ new Set()
11221
+ };
11135
11222
  }
11136
- if (importsReport[cleanedDependent].dependencies.includes(filepath)) {
11223
+ if (importsReport[cleanedDependent].dependencies.has(filepath)) {
11137
11224
  continue;
11138
11225
  }
11139
- importsReport[cleanedDependent].dependencies.push(filepath);
11226
+ importsReport[cleanedDependent].dependencies.add(filepath);
11140
11227
  }
11141
11228
  }
11142
11229
  for (const [filename, asset] of Object.entries(bundle)) {
@@ -11159,8 +11246,8 @@ const getRollupPlugin$1 = (context, log) => {
11159
11246
  }
11160
11247
  const moduleFile = {
11161
11248
  name: cleanName(context, modulepath),
11162
- dependencies: [],
11163
- dependents: [],
11249
+ dependencies: /* @__PURE__ */ new Set(),
11250
+ dependents: /* @__PURE__ */ new Set(),
11164
11251
  filepath: modulepath,
11165
11252
  // Since we store as input, we use the originalLength.
11166
11253
  size: module.originalLength,
@@ -11191,7 +11278,7 @@ const getRollupPlugin$1 = (context, log) => {
11191
11278
  );
11192
11279
  continue;
11193
11280
  }
11194
- input.dependencies.push(foundInput);
11281
+ input.dependencies.add(foundInput);
11195
11282
  }
11196
11283
  for (const dependent of importReport.dependents) {
11197
11284
  const foundInput = reportInputsIndexed[dependent];
@@ -11201,7 +11288,7 @@ const getRollupPlugin$1 = (context, log) => {
11201
11288
  );
11202
11289
  continue;
11203
11290
  }
11204
- input.dependents.push(foundInput);
11291
+ input.dependents.add(foundInput);
11205
11292
  }
11206
11293
  }
11207
11294
  if (tempSourcemaps.length) {
@@ -11279,34 +11366,58 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11279
11366
  chunkGroupChildren: true,
11280
11367
  chunkGroups: true,
11281
11368
  chunkModules: true,
11369
+ chunkRelations: true,
11282
11370
  entrypoints: true,
11283
11371
  errors: true,
11284
11372
  ids: true,
11285
11373
  modules: true,
11374
+ nestedModules: true,
11286
11375
  reasons: true,
11287
11376
  relatedAssets: true,
11288
- runtime: true,
11289
- runtimeModules: true,
11290
11377
  warnings: true
11291
11378
  });
11292
11379
  const chunks = stats.chunks || [];
11293
- const assets = stats.assets ? [...stats.assets] : [];
11294
- const modules = stats.modules || [];
11380
+ const assets = compilation.getAssets();
11381
+ const modules = [];
11295
11382
  const entrypoints = stats.entrypoints || [];
11296
11383
  const tempSourcemaps = [];
11297
11384
  const tempDeps = {};
11298
11385
  const reportInputsIndexed = {};
11299
11386
  const reportOutputsIndexed = {};
11300
- if (context.bundler.variant === "5" && stats.assets) {
11301
- for (const asset of stats.assets) {
11302
- if (asset.related) {
11303
- assets.push(...asset.related);
11387
+ const modulePerId = /* @__PURE__ */ new Map();
11388
+ const modulePerIdentifier = /* @__PURE__ */ new Map();
11389
+ const concatModulesPerId = /* @__PURE__ */ new Map();
11390
+ const concatModulesPerIdentifier = /* @__PURE__ */ new Map();
11391
+ for (const module of stats.modules || []) {
11392
+ if (module.modules) {
11393
+ if (module.id) {
11394
+ concatModulesPerId.set(module.id, module.modules);
11395
+ }
11396
+ if (module.identifier) {
11397
+ concatModulesPerIdentifier.set(module.identifier, module.modules);
11398
+ }
11399
+ for (const subModule of module.modules) {
11400
+ modules.push(subModule);
11401
+ if (subModule.id) {
11402
+ modulePerId.set(subModule.id, subModule);
11403
+ }
11404
+ if (subModule.identifier) {
11405
+ modulePerIdentifier.set(subModule.identifier, subModule);
11406
+ }
11407
+ }
11408
+ } else {
11409
+ modules.push(module);
11410
+ if (module.id) {
11411
+ modulePerId.set(module.id, module);
11412
+ }
11413
+ if (module.identifier) {
11414
+ modulePerIdentifier.set(module.identifier, module);
11304
11415
  }
11305
11416
  }
11306
11417
  }
11307
11418
  for (const asset of assets) {
11308
11419
  const file = {
11309
- size: asset.size,
11420
+ size: asset.info.size || 0,
11310
11421
  name: asset.name,
11311
11422
  inputs: [],
11312
11423
  filepath: path$i.join(context.bundler.outDir, asset.name),
@@ -11321,38 +11432,77 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11321
11432
  for (const sourcemap of tempSourcemaps) {
11322
11433
  const outputFound = reportOutputsIndexed[sourcemap.filepath.replace(/\.map$/, "")];
11323
11434
  if (!outputFound) {
11324
- warn(`Output not found for ${sourcemap.name}`);
11435
+ warn(`Output not found for sourcemap ${sourcemap.name}`);
11325
11436
  continue;
11326
11437
  }
11327
11438
  sourcemap.inputs.push(outputFound);
11328
11439
  }
11440
+ const getModulePath = (module) => {
11441
+ return module.nameForCondition ? module.nameForCondition : module.name ? path$i.join(context.cwd, module.name) : module.identifier ? module.identifier : "unknown";
11442
+ };
11443
+ const getModules = (reason) => {
11444
+ const { moduleIdentifier, moduleId } = reason;
11445
+ if (!moduleIdentifier && !moduleId) {
11446
+ return [];
11447
+ }
11448
+ const modulesFound = [];
11449
+ if (moduleId) {
11450
+ const module = modulePerId.get(moduleId);
11451
+ if (module) {
11452
+ modulesFound.push(module);
11453
+ }
11454
+ const concatModules = concatModulesPerId.get(moduleId);
11455
+ if (concatModules) {
11456
+ modulesFound.push(...concatModules);
11457
+ }
11458
+ }
11459
+ if (moduleIdentifier) {
11460
+ const module = modulePerIdentifier.get(moduleIdentifier);
11461
+ if (module) {
11462
+ modulesFound.push(module);
11463
+ }
11464
+ const concatModules = concatModulesPerIdentifier.get(moduleIdentifier);
11465
+ if (concatModules) {
11466
+ modulesFound.push(...concatModules);
11467
+ }
11468
+ }
11469
+ return Array.from(new Set(modulesFound.map(getModulePath)));
11470
+ };
11471
+ const modulesDone = /* @__PURE__ */ new Set();
11329
11472
  for (const module of modules) {
11330
- if (module.moduleType === "runtime" || module.name?.startsWith("(webpack)")) {
11473
+ if (module.moduleType === "runtime" || module.name?.startsWith("(webpack)") || module.type === "orphan modules") {
11474
+ continue;
11475
+ }
11476
+ const modulePath = getModulePath(module);
11477
+ if (modulesDone.has(modulePath)) {
11331
11478
  continue;
11332
11479
  }
11333
- const modulePath = module.identifier ? module.identifier : module.name ? path$i.join(context.cwd, module.name) : "unknown";
11480
+ modulesDone.add(modulePath);
11334
11481
  if (modulePath === "unknown") {
11335
11482
  warn(`Unknown module: ${JSON.stringify(module)}`);
11336
11483
  }
11337
11484
  if (module.reasons) {
11338
- const moduleDeps = tempDeps[modulePath] || { dependencies: [], dependents: [] };
11339
- const reasons = module.reasons.map((reason) => {
11340
- const reasonName = reason.resolvedModuleIdentifier ? reason.resolvedModuleIdentifier : reason.moduleIdentifier ? reason.moduleIdentifier : reason.resolvedModule ? path$i.join(context.cwd, reason.resolvedModule) : "unknown";
11341
- return reasonName;
11342
- }).filter((reason) => reason !== "unknown");
11343
- for (const reason of reasons) {
11344
- const reasonDeps = tempDeps[reason] || { dependencies: [], dependents: [] };
11345
- reasonDeps.dependencies.push(modulePath);
11346
- tempDeps[reason] = reasonDeps;
11347
- }
11348
- moduleDeps.dependents.push(...reasons);
11485
+ const moduleDeps = tempDeps[modulePath] || {
11486
+ dependencies: /* @__PURE__ */ new Set(),
11487
+ dependents: /* @__PURE__ */ new Set()
11488
+ };
11489
+ const dependents = module.reasons.flatMap(getModules);
11490
+ for (const dependent of dependents) {
11491
+ const reasonDeps = tempDeps[dependent] || {
11492
+ dependencies: /* @__PURE__ */ new Set(),
11493
+ dependents: /* @__PURE__ */ new Set()
11494
+ };
11495
+ reasonDeps.dependencies.add(modulePath);
11496
+ tempDeps[dependent] = reasonDeps;
11497
+ moduleDeps.dependents.add(dependent);
11498
+ }
11349
11499
  tempDeps[modulePath] = moduleDeps;
11350
11500
  }
11351
11501
  const file = {
11352
11502
  size: module.size || 0,
11353
11503
  name: cleanName(context, modulePath),
11354
- dependencies: [],
11355
- dependents: [],
11504
+ dependencies: /* @__PURE__ */ new Set(),
11505
+ dependents: /* @__PURE__ */ new Set(),
11356
11506
  filepath: modulePath,
11357
11507
  type: getType(modulePath)
11358
11508
  };
@@ -11370,7 +11520,9 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11370
11520
  warn(`Output not found for ${file.name}`);
11371
11521
  continue;
11372
11522
  }
11373
- outputFound.inputs.push(file);
11523
+ if (!outputFound.inputs.includes(file)) {
11524
+ outputFound.inputs.push(file);
11525
+ }
11374
11526
  }
11375
11527
  reportInputsIndexed[modulePath] = file;
11376
11528
  inputs.push(file);
@@ -11388,10 +11540,8 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11388
11540
  warn(`Could not find dependency report for ${input.name}`);
11389
11541
  continue;
11390
11542
  }
11391
- input.dependencies = cleanReport(depsReport.dependencies, input.filepath).map(
11392
- getInput
11393
- );
11394
- input.dependents = cleanReport(depsReport.dependents, input.filepath).map(getInput);
11543
+ input.dependencies = cleanReport(depsReport.dependencies, input.filepath, getInput);
11544
+ input.dependents = cleanReport(depsReport.dependents, input.filepath, getInput);
11395
11545
  }
11396
11546
  for (const [name, entry] of Object.entries(entrypoints)) {
11397
11547
  const entryOutputs = [];
@@ -11414,21 +11564,21 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11414
11564
  }
11415
11565
  const outputFound = reportOutputsIndexed[assetPath];
11416
11566
  if (outputFound) {
11417
- if (outputFound.type !== "map") {
11567
+ if (outputFound.type !== "map" && !entryOutputs.includes(outputFound)) {
11418
11568
  entryOutputs.push(outputFound);
11419
11569
  entryInputs.push(...outputFound.inputs);
11420
11570
  size += outputFound.size;
11421
11571
  }
11422
11572
  }
11423
11573
  }
11424
- const assetFound = assets.find((asset) => asset.chunkNames?.includes(name));
11574
+ const entryFilename = stats.assetsByChunkName?.[name]?.[0];
11425
11575
  const file = {
11426
11576
  name,
11427
- filepath: assetFound ? path$i.join(context.bundler.outDir, assetFound.name) : "unknown",
11577
+ filepath: entryFilename ? path$i.join(context.bundler.outDir, entryFilename) : "unknown",
11428
11578
  size,
11429
- inputs: entryInputs,
11579
+ inputs: Array.from(new Set(entryInputs)),
11430
11580
  outputs: entryOutputs,
11431
- type: assetFound ? getType(assetFound.name) : "unknown"
11581
+ type: entryFilename ? getType(entryFilename) : "unknown"
11432
11582
  };
11433
11583
  entries.push(file);
11434
11584
  }
@@ -11438,7 +11588,7 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11438
11588
  });
11439
11589
  };
11440
11590
 
11441
- const PLUGIN_NAME$3 = "build-report";
11591
+ const PLUGIN_NAME$3 = "datadog-build-report-plugin";
11442
11592
  const getBuildReportPlugin = (opts, context) => {
11443
11593
  const log = getLogger(opts.logLevel, PLUGIN_NAME$3);
11444
11594
  return {
@@ -18343,7 +18493,7 @@ const getRepositoryData = async (git, repositoryURL) => {
18343
18493
 
18344
18494
  const getGitPlugin = (options, context) => {
18345
18495
  return {
18346
- name: "git-plugin",
18496
+ name: "datadog-git-plugin",
18347
18497
  enforce: "pre",
18348
18498
  async buildStart() {
18349
18499
  const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;
@@ -18356,7 +18506,7 @@ const getGitPlugin = (options, context) => {
18356
18506
  };
18357
18507
  };
18358
18508
 
18359
- const PLUGIN_NAME$2 = "context-plugin";
18509
+ const PLUGIN_NAME$2 = "datadog-context-plugin";
18360
18510
  const rollupPlugin = (context) => ({
18361
18511
  options(options) {
18362
18512
  context.bundler.rawConfig = options;
@@ -18376,9 +18526,6 @@ const getGlobalContextPlugin = (opts, meta) => {
18376
18526
  const variant = meta.framework === "webpack" ? meta.webpack.compiler["webpack"] ? "5" : "4" : "";
18377
18527
  const globalContext = {
18378
18528
  auth: opts.auth,
18379
- start: Date.now(),
18380
- cwd,
18381
- version: meta.version,
18382
18529
  bundler: {
18383
18530
  name: meta.framework,
18384
18531
  fullName: `${meta.framework}${variant}`,
@@ -18388,7 +18535,10 @@ const getGlobalContextPlugin = (opts, meta) => {
18388
18535
  build: {
18389
18536
  errors: [],
18390
18537
  warnings: []
18391
- }
18538
+ },
18539
+ cwd,
18540
+ start: Date.now(),
18541
+ version: meta.version
18392
18542
  };
18393
18543
  const globalContextPlugin = {
18394
18544
  name: PLUGIN_NAME$2,
@@ -23299,31 +23449,6 @@ const getLoaders = (loaders) => {
23299
23449
  return metrics;
23300
23450
  };
23301
23451
 
23302
- const getModuleEntryTags = (file, entries) => {
23303
- const entryNames = entries.filter((entry) => {
23304
- const foundModules = entry.inputs.filter((input) => {
23305
- return input.name === file.name;
23306
- });
23307
- return foundModules.length;
23308
- }).map((entry) => entry.name);
23309
- return Array.from(new Set(entryNames)).map((entryName) => `entryName:${entryName}`);
23310
- };
23311
- const getAssetEntryTags = (file, entries) => {
23312
- const cleanAssetName = file.name.replace(/\.map$/, "");
23313
- const entryNames = entries.filter((entry) => {
23314
- const foundModules = entry.outputs.filter((output) => {
23315
- return output.name === cleanAssetName;
23316
- });
23317
- return foundModules.length;
23318
- }).map((entry) => entry.name);
23319
- return Array.from(new Set(entryNames)).map((entryName) => `entryName:${entryName}`);
23320
- };
23321
- const getModuleAssetTags = (file, outputs) => {
23322
- const assetNames = outputs.filter((output) => {
23323
- return output.inputs.find((input) => input.filepath === file.filepath);
23324
- }).map((output) => output.name);
23325
- return Array.from(new Set(assetNames)).map((assetName) => `assetName:${assetName}`);
23326
- };
23327
23452
  const getUniversalMetrics = (globalContext) => {
23328
23453
  const metrics = [];
23329
23454
  const inputs = globalContext.build.inputs || [];
@@ -23332,6 +23457,32 @@ const getUniversalMetrics = (globalContext) => {
23332
23457
  const nbWarnings = globalContext.build.warnings.length;
23333
23458
  const nbErrors = globalContext.build.errors.length;
23334
23459
  const duration = globalContext.build.duration;
23460
+ const entriesPerInput = /* @__PURE__ */ new Map();
23461
+ const assetsPerInput = /* @__PURE__ */ new Map();
23462
+ const entriesPerAsset = /* @__PURE__ */ new Map();
23463
+ for (const entry of entries) {
23464
+ for (const input of entry.inputs) {
23465
+ if (!entriesPerInput.has(input.filepath)) {
23466
+ entriesPerInput.set(input.filepath, []);
23467
+ }
23468
+ entriesPerInput.get(input.filepath).push(entry.name);
23469
+ }
23470
+ for (const output of entry.outputs) {
23471
+ const cleanAssetName = output.filepath.replace(/\.map$/, "");
23472
+ if (!entriesPerAsset.has(cleanAssetName)) {
23473
+ entriesPerAsset.set(cleanAssetName, []);
23474
+ }
23475
+ entriesPerAsset.get(cleanAssetName).push(entry.name);
23476
+ }
23477
+ }
23478
+ for (const output of outputs) {
23479
+ for (const input of output.inputs) {
23480
+ if (!assetsPerInput.has(input.filepath)) {
23481
+ assetsPerInput.set(input.filepath, []);
23482
+ }
23483
+ assetsPerInput.get(input.filepath).push(output.name);
23484
+ }
23485
+ }
23335
23486
  metrics.push(
23336
23487
  {
23337
23488
  metric: "assets.count",
@@ -23373,12 +23524,17 @@ const getUniversalMetrics = (globalContext) => {
23373
23524
  });
23374
23525
  }
23375
23526
  for (const input of inputs) {
23376
- const tags = [
23377
- `moduleName:${input.name}`,
23378
- `moduleType:${input.type}`,
23379
- ...getModuleEntryTags(input, entries),
23380
- ...getModuleAssetTags(input, outputs)
23381
- ];
23527
+ const tags = [`moduleName:${input.name}`, `moduleType:${input.type}`];
23528
+ if (entriesPerInput.has(input.filepath)) {
23529
+ tags.push(
23530
+ ...entriesPerInput.get(input.filepath).map((entryName) => `entryName:${entryName}`)
23531
+ );
23532
+ }
23533
+ if (assetsPerInput.has(input.filepath)) {
23534
+ tags.push(
23535
+ ...assetsPerInput.get(input.filepath).map((assetName) => `assetName:${assetName}`)
23536
+ );
23537
+ }
23382
23538
  metrics.push(
23383
23539
  {
23384
23540
  metric: "modules.size",
@@ -23389,38 +23545,37 @@ const getUniversalMetrics = (globalContext) => {
23389
23545
  {
23390
23546
  metric: "modules.dependencies",
23391
23547
  type: "count",
23392
- value: input.dependencies.length,
23548
+ value: input.dependencies.size,
23393
23549
  tags
23394
23550
  },
23395
23551
  {
23396
23552
  metric: "modules.dependents",
23397
23553
  type: "count",
23398
- value: input.dependents.length,
23554
+ value: input.dependents.size,
23399
23555
  tags
23400
23556
  }
23401
23557
  );
23402
23558
  }
23403
23559
  for (const output of outputs) {
23560
+ const tags = [`assetName:${output.name}`, `assetType:${output.type}`];
23561
+ const cleanAssetName = output.filepath.replace(/\.map$/, "");
23562
+ if (entriesPerAsset.has(cleanAssetName)) {
23563
+ tags.push(
23564
+ ...entriesPerAsset.get(cleanAssetName).map((entryName) => `entryName:${entryName}`)
23565
+ );
23566
+ }
23404
23567
  metrics.push(
23405
23568
  {
23406
23569
  metric: "assets.size",
23407
23570
  type: "size",
23408
23571
  value: output.size,
23409
- tags: [
23410
- `assetName:${output.name}`,
23411
- `assetType:${output.type}`,
23412
- ...getAssetEntryTags(output, entries)
23413
- ]
23572
+ tags
23414
23573
  },
23415
23574
  {
23416
23575
  metric: "assets.modules.count",
23417
23576
  type: "count",
23418
23577
  value: output.inputs.length,
23419
- tags: [
23420
- `assetName:${output.name}`,
23421
- `assetType:${output.type}`,
23422
- ...getAssetEntryTags(output, entries)
23423
- ]
23578
+ tags
23424
23579
  }
23425
23580
  );
23426
23581
  }
@@ -23661,6 +23816,7 @@ var prettyBytes = (number, options) => {
23661
23816
  var prettyBytes$1 = /*@__PURE__*/getDefaultExportFromCjs(prettyBytes);
23662
23817
 
23663
23818
  const TOP = 5;
23819
+ const MAX_VALUE_LENGTH = 60;
23664
23820
  const numColor = chalk.bold.red;
23665
23821
  const nameColor = chalk.bold.cyan;
23666
23822
  const sortDesc = (attr) => (a, b) => {
@@ -23737,7 +23893,7 @@ const getGeneralValues = (context) => {
23737
23893
  const getAssetsValues = (context) => {
23738
23894
  const assetSizesToPrint = {
23739
23895
  name: "Asset size",
23740
- values: (context.build.outputs || []).sort(sortDesc((output) => output.size)).map((output) => ({
23896
+ values: (context.build.outputs || []).filter((output) => output.type !== "map").sort(sortDesc((output) => output.size)).map((output) => ({
23741
23897
  name: output.name,
23742
23898
  value: prettyBytes$1(output.size)
23743
23899
  })),
@@ -23761,17 +23917,6 @@ const getAssetsValues = (context) => {
23761
23917
  };
23762
23918
  return [assetSizesToPrint, entrySizesToPrint, entryModulesToPrint];
23763
23919
  };
23764
- const getAll = (attribute, collection, filepath, accumulator = []) => {
23765
- const reported = collection[filepath]?.[attribute] || [];
23766
- for (const reportedFilename of reported) {
23767
- if (accumulator.includes(reportedFilename) || reportedFilename === filepath) {
23768
- continue;
23769
- }
23770
- accumulator.push(reportedFilename);
23771
- getAll(attribute, collection, reportedFilename, accumulator);
23772
- }
23773
- return accumulator;
23774
- };
23775
23920
  const getModulesValues = (context) => {
23776
23921
  const dependentsToPrint = {
23777
23922
  name: `Module total dependents`,
@@ -23793,55 +23938,86 @@ const getModulesValues = (context) => {
23793
23938
  values: [],
23794
23939
  top: true
23795
23940
  };
23796
- const dependencies = [];
23797
- const inputs = Object.fromEntries(
23798
- (context.build.inputs || []).map((input) => [
23799
- input.filepath,
23800
- {
23801
- name: input.name,
23802
- size: input.size,
23803
- dependencies: input.dependencies.map((dep) => dep.filepath),
23804
- dependents: input.dependents.map((dep) => dep.filepath)
23805
- }
23806
- ])
23807
- );
23808
- for (const filepath in inputs) {
23809
- if (!Object.hasOwn(inputs, filepath)) {
23941
+ const dependencies = /* @__PURE__ */ new Set();
23942
+ const serializedReport = serializeBuildReport(context.build);
23943
+ const inputs = /* @__PURE__ */ new Map();
23944
+ const fileDependencies = /* @__PURE__ */ new Map();
23945
+ const fileDependents = /* @__PURE__ */ new Map();
23946
+ for (const input of serializedReport.inputs || []) {
23947
+ if (input.type === "map") {
23810
23948
  continue;
23811
23949
  }
23812
- const fileDependencies = getAll("dependencies", inputs, filepath);
23813
- const aggregatedSize = fileDependencies.reduce(
23814
- (acc, dep) => acc + inputs[dep].size,
23815
- inputs[filepath].size
23816
- );
23817
- dependencies.push({
23818
- name: inputs[filepath].name,
23819
- size: inputs[filepath].size,
23950
+ const dependenciesSet = new Set(input.dependencies);
23951
+ const dependentsSet = new Set(input.dependents);
23952
+ for (const dep of dependenciesSet) {
23953
+ if (!fileDependents.has(dep)) {
23954
+ fileDependents.set(dep, /* @__PURE__ */ new Set());
23955
+ }
23956
+ fileDependents.get(dep).add(input.filepath);
23957
+ }
23958
+ for (const dep of dependentsSet) {
23959
+ if (!fileDependencies.has(dep)) {
23960
+ fileDependencies.set(dep, /* @__PURE__ */ new Set());
23961
+ }
23962
+ fileDependencies.get(dep).add(input.filepath);
23963
+ }
23964
+ if (fileDependencies.has(input.filepath)) {
23965
+ const existingDependencies = fileDependencies.get(input.filepath);
23966
+ for (const dep of existingDependencies) {
23967
+ dependenciesSet.add(dep);
23968
+ }
23969
+ }
23970
+ if (fileDependents.has(input.filepath)) {
23971
+ const existingDependents = fileDependents.get(input.filepath);
23972
+ for (const dep of existingDependents) {
23973
+ dependentsSet.add(dep);
23974
+ }
23975
+ }
23976
+ fileDependencies.set(input.filepath, dependenciesSet);
23977
+ fileDependents.set(input.filepath, dependentsSet);
23978
+ inputs.set(input.filepath, {
23979
+ name: input.name,
23980
+ size: input.size,
23981
+ dependencies: dependenciesSet,
23982
+ dependents: dependentsSet
23983
+ });
23984
+ }
23985
+ for (const [filepath, input] of inputs) {
23986
+ const inputDependencies = fileDependencies.get(filepath) || /* @__PURE__ */ new Set();
23987
+ const inputDependents = fileDependents.get(filepath) || /* @__PURE__ */ new Set();
23988
+ let aggregatedSize = input.size;
23989
+ for (const dep of inputDependencies) {
23990
+ aggregatedSize += inputs.get(dep)?.size || 0;
23991
+ }
23992
+ dependencies.add({
23993
+ name: input.name,
23994
+ size: input.size,
23820
23995
  aggregatedSize,
23821
- dependents: getAll("dependents", inputs, filepath),
23822
- dependencies: fileDependencies
23996
+ dependents: inputDependents,
23997
+ dependencies: inputDependencies
23823
23998
  });
23824
23999
  }
23825
- if (!dependencies.length) {
24000
+ if (!dependencies.size) {
23826
24001
  return [dependentsToPrint, dependenciesToPrint, sizesToPrint];
23827
24002
  }
23828
- dependencies.sort(sortDesc((file) => file.dependents.length));
23829
- dependentsToPrint.values = dependencies.map((file) => ({
24003
+ const dependenciesArray = Array.from(dependencies);
24004
+ dependenciesArray.sort(sortDesc((file) => file.dependents.size));
24005
+ dependentsToPrint.values = dependenciesArray.map((file) => ({
23830
24006
  name: file.name,
23831
- value: file.dependents.length.toString()
24007
+ value: file.dependents.size.toString()
23832
24008
  }));
23833
- dependencies.sort(sortDesc((file) => file.dependencies.length));
23834
- dependenciesToPrint.values = dependencies.map((file) => ({
24009
+ dependenciesArray.sort(sortDesc((file) => file.dependencies.size));
24010
+ dependenciesToPrint.values = dependenciesArray.map((file) => ({
23835
24011
  name: file.name,
23836
- value: file.dependencies.length.toString()
24012
+ value: file.dependencies.size.toString()
23837
24013
  }));
23838
- dependencies.sort(sortDesc("size"));
23839
- sizesToPrint.values = dependencies.map((file) => ({
24014
+ dependenciesArray.sort(sortDesc("size"));
24015
+ sizesToPrint.values = dependenciesArray.map((file) => ({
23840
24016
  name: file.name,
23841
24017
  value: prettyBytes$1(file.size)
23842
24018
  }));
23843
- dependencies.sort(sortDesc("aggregatedSize"));
23844
- aggregatedSizesToPrint.values = dependencies.map((file) => ({
24019
+ dependenciesArray.sort(sortDesc("aggregatedSize"));
24020
+ aggregatedSizesToPrint.values = dependenciesArray.map((file) => ({
23845
24021
  name: file.name,
23846
24022
  value: prettyBytes$1(file.aggregatedSize || file.size)
23847
24023
  }));
@@ -23876,6 +24052,17 @@ const renderValues = (values) => {
23876
24052
  let outputString = "";
23877
24053
  const titlePadding = 4;
23878
24054
  const valuePadding = 4;
24055
+ for (const group of values) {
24056
+ if (group.top && group.values.length >= TOP) {
24057
+ group.values = group.values.slice(0, TOP);
24058
+ group.name = `Top ${TOP} ${group.name}`;
24059
+ }
24060
+ for (const value of group.values) {
24061
+ if (value.name.length > MAX_VALUE_LENGTH) {
24062
+ value.name = `${value.name.slice(0, 10)}[...]${value.name.slice(-(MAX_VALUE_LENGTH - 15))}`;
24063
+ }
24064
+ }
24065
+ }
23879
24066
  const maxTitleWidth = Math.max(...values.map((val) => val.name.length));
23880
24067
  const maxNameWidth = Math.max(...values.flatMap((val) => val.values.map((v) => v.name.length)));
23881
24068
  const maxValueWidth = Math.max(
@@ -23889,13 +24076,11 @@ const renderValues = (values) => {
23889
24076
  if (group.values.length === 0) {
23890
24077
  continue;
23891
24078
  }
23892
- const title = group.top && group.values.length >= TOP ? `Top ${TOP} ${group.name}` : group.name;
23893
- const titlePad = totalWidth - (title.length + titlePadding);
24079
+ const titlePad = totalWidth - (group.name.length + titlePadding);
23894
24080
  outputString += `
23895
- == ${title} ${"=".repeat(titlePad)}=
24081
+ == ${group.name} ${"=".repeat(titlePad)}=
23896
24082
  `;
23897
- const valuesToPrint = group.top ? group.values.slice(0, TOP) : group.values;
23898
- for (const value of valuesToPrint) {
24083
+ for (const value of group.values) {
23899
24084
  const valuePad = maxValueWidth - value.value.length;
23900
24085
  outputString += ` [${numColor(value.value)}] ${" ".repeat(valuePad)}${nameColor(value.name)}
23901
24086
  `;
@@ -24143,6 +24328,10 @@ class Tapables {
24143
24328
  this.tapables = [];
24144
24329
  this.hooks = {};
24145
24330
  this.timings = /* @__PURE__ */ new Map();
24331
+ this.ignoredHooks = [
24332
+ // This one triggers a DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK warning.
24333
+ "normalModuleLoader"
24334
+ ];
24146
24335
  this.cwd = cwd;
24147
24336
  }
24148
24337
  saveResult(type, pluginName, hookName, context, start, end) {
@@ -24189,7 +24378,7 @@ class Tapables {
24189
24378
  }
24190
24379
  getPromiseTapPatch(type, fn, pluginName, hookName) {
24191
24380
  return (...args) => {
24192
- this.checkHooks();
24381
+ this.checkNewHooks();
24193
24382
  const startTime = performance$1.now();
24194
24383
  const returnValue = fn.apply(this, args);
24195
24384
  const cb = () => {
@@ -24208,7 +24397,7 @@ class Tapables {
24208
24397
  }
24209
24398
  getAsyncTapPatch(type, fn, pluginName, hookName) {
24210
24399
  return (...args) => {
24211
- this.checkHooks();
24400
+ this.checkNewHooks();
24212
24401
  const startTime = performance$1.now();
24213
24402
  const originalCB = args.pop();
24214
24403
  const newCB = (...a) => {
@@ -24227,7 +24416,7 @@ class Tapables {
24227
24416
  }
24228
24417
  getDefaultTapPatch(type, fn, pluginName, hookName) {
24229
24418
  return (...args) => {
24230
- this.checkHooks();
24419
+ this.checkNewHooks();
24231
24420
  const startTime = performance$1.now();
24232
24421
  const returnValue = fn.apply(this, args);
24233
24422
  this.saveResult(
@@ -24286,23 +24475,32 @@ class Tapables {
24286
24475
  this.hooks[tapableName].push(hookName);
24287
24476
  this.replaceTaps(hookName, hook);
24288
24477
  }
24289
- checkHooks() {
24290
- for (const tapable of this.tapables) {
24291
- const name = tapable.constructor.name;
24292
- for (const hookName of Object.keys(tapable.hooks)) {
24293
- this.patchHook(name, hookName, tapable.hooks[hookName]);
24478
+ patchHooks(tapable) {
24479
+ const name = tapable.constructor.name;
24480
+ const hooksToPatch = Object.keys(tapable.hooks).filter((hookName) => {
24481
+ if (this.ignoredHooks.includes(hookName)) {
24482
+ return false;
24483
+ }
24484
+ if (this.hooks[name]?.includes(hookName)) {
24485
+ return false;
24294
24486
  }
24487
+ return true;
24488
+ });
24489
+ for (const hookName of hooksToPatch) {
24490
+ this.patchHook(name, hookName, tapable.hooks[hookName]);
24491
+ }
24492
+ }
24493
+ checkNewHooks() {
24494
+ for (const tapable of this.tapables) {
24495
+ this.patchHooks(tapable);
24295
24496
  }
24296
24497
  }
24297
24498
  // Let's navigate through all the hooks we can find.
24298
24499
  throughHooks(tapable) {
24299
- const name = tapable.constructor.name;
24300
24500
  if (!this.tapables.includes(tapable)) {
24301
24501
  this.tapables.push(tapable);
24302
24502
  }
24303
- for (const hookName of Object.keys(tapable.hooks)) {
24304
- this.patchHook(name, hookName, tapable.hooks[hookName]);
24305
- }
24503
+ this.patchHooks(tapable);
24306
24504
  }
24307
24505
  }
24308
24506
 
@@ -36032,6 +36230,10 @@ const buildPluginFactory = ({
36032
36230
  ...unpluginMetaContext
36033
36231
  });
36034
36232
  const plugins = [...internalPlugins];
36233
+ if (options.customPlugins) {
36234
+ const customPlugins = options.customPlugins(options, globalContext);
36235
+ plugins.push(...customPlugins);
36236
+ }
36035
36237
  if (options[CONFIG_KEY$1] && options[CONFIG_KEY$1].disabled !== true) {
36036
36238
  plugins.push(...getPlugins$2(options, globalContext));
36037
36239
  }
@@ -36044,7 +36246,7 @@ const buildPluginFactory = ({
36044
36246
 
36045
36247
  var name = "@datadog/esbuild-plugin";
36046
36248
  var packageManager = "yarn@4.0.2";
36047
- var version$1 = "2.3.0-dev";
36249
+ var version$1 = "2.3.0-dev-1";
36048
36250
  var license = "MIT";
36049
36251
  var author = "Datadog";
36050
36252
  var description = "Datadog ESBuild Plugin";