@datadog/esbuild-plugin 2.3.1-dev-10 → 2.3.1-dev-13

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.
@@ -2273,7 +2273,6 @@ var retry$2 = /*@__PURE__*/getDefaultExportFromCjs(lib$3);
2273
2273
  const PREPARATION_PLUGIN_NAME = "datadog-injection-preparation-plugin";
2274
2274
  const PLUGIN_NAME$4 = "datadog-injection-plugin";
2275
2275
  const INJECTED_FILE = "__datadog-helper-file";
2276
- const INJECTED_FILE_PATH = `${INJECTED_FILE}.js`;
2277
2276
  const DISTANT_FILE_RX = /^https?:\/\//;
2278
2277
 
2279
2278
  const formatDuration = (duration) => {
@@ -11804,7 +11803,7 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11804
11803
  const isModuleSupported = (moduleIdentifier) => {
11805
11804
  return (
11806
11805
  // Ignore unidentified modules and runtimes.
11807
- !!moduleIdentifier && !moduleIdentifier.startsWith("webpack/runtime") && !moduleIdentifier.includes("/webpack4/buildin/")
11806
+ !!moduleIdentifier && !moduleIdentifier.startsWith("webpack/runtime") && !moduleIdentifier.includes("/webpack4/buildin/") && !moduleIdentifier.startsWith("multi ")
11808
11807
  );
11809
11808
  };
11810
11809
  const warn = (warning) => {
@@ -11831,6 +11830,9 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11831
11830
  return getModuleFromDep(dep)?.identifier();
11832
11831
  }).filter(Boolean)
11833
11832
  );
11833
+ if (!isModuleSupported(moduleIdentifier)) {
11834
+ continue;
11835
+ }
11834
11836
  for (const depIdentifier of dependencies) {
11835
11837
  const depDeps = tempDeps.get(depIdentifier) || {
11836
11838
  dependencies: /* @__PURE__ */ new Set(),
@@ -11839,9 +11841,6 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11839
11841
  depDeps.dependents.add(moduleIdentifier);
11840
11842
  tempDeps.set(depIdentifier, depDeps);
11841
11843
  }
11842
- if (!isModuleSupported(moduleIdentifier)) {
11843
- continue;
11844
- }
11845
11844
  const moduleDeps = tempDeps.get(moduleIdentifier) || {
11846
11845
  dependents: /* @__PURE__ */ new Set(),
11847
11846
  dependencies: /* @__PURE__ */ new Set()
@@ -11894,9 +11893,10 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11894
11893
  (f) => getAbsolutePath(context.bundler.outDir, f)
11895
11894
  );
11896
11895
  };
11896
+ const chunkGraph = result.chunkGraph;
11897
11897
  for (const chunk of chunks) {
11898
11898
  const files = getChunkFiles(chunk);
11899
- const chunkModules = chunk.getModules().flatMap((m) => {
11899
+ const chunkModules = (chunkGraph ? chunkGraph?.getChunkModules(chunk) : chunk.getModules()).flatMap((m) => {
11900
11900
  return "modules" in m && Array.isArray(m.modules) ? m.modules.map((m2) => m2.identifier()) : m.identifier();
11901
11901
  }).filter(isModuleSupported);
11902
11902
  for (const file of files) {
@@ -11950,7 +11950,12 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11950
11950
  const entryInputs = [];
11951
11951
  let size = 0;
11952
11952
  const entryFiles = entrypoint.chunks.flatMap(getChunkFiles);
11953
- const entryFilename = entrypoint.chunks.filter((c) => c.entryModule).flatMap((c) => Array.from(c.files))[0];
11953
+ const entryFilename = entrypoint.chunks.filter(
11954
+ (c) => (
11955
+ // Webpack5 forces you to use the chunkGraph to get the modules.
11956
+ chunkGraph ? chunkGraph.getNumberOfEntryModules(c) > 0 : c.hasEntryModule()
11957
+ )
11958
+ ).flatMap((c) => Array.from(c.files))[0];
11954
11959
  for (const file2 of entryFiles) {
11955
11960
  const outputFound = reportOutputsIndexed.get(file2);
11956
11961
  if (!file2 || !outputFound) {
@@ -19023,6 +19028,7 @@ ${after}`;
19023
19028
  return "";
19024
19029
  }
19025
19030
  };
19031
+ const INJECTED_FILE_PATH = `${Math.random().toString().replace("0.", "")}_${INJECTED_FILE}.js`;
19026
19032
  const plugins = [
19027
19033
  // Prepare and fetch the content to inject for all bundlers.
19028
19034
  {
@@ -19080,22 +19086,36 @@ ${after}`;
19080
19086
  },
19081
19087
  webpack: (compiler) => {
19082
19088
  const BannerPlugin = compiler?.webpack?.BannerPlugin || bundler?.BannerPlugin || bundler?.default?.BannerPlugin;
19089
+ compiler?.webpack?.ChunkGraph || bundler?.ChunkGraph || bundler?.default?.ChunkGraph;
19083
19090
  if (!BannerPlugin) {
19084
19091
  log("Missing BannerPlugin", "error");
19085
19092
  }
19093
+ let chunkGraph;
19094
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME$4, (compilation) => {
19095
+ compilation.hooks.afterChunks.tap(PLUGIN_NAME$4, () => {
19096
+ chunkGraph = compilation.chunkGraph;
19097
+ });
19098
+ });
19086
19099
  compiler.options.plugins = compiler.options.plugins || [];
19087
19100
  compiler.options.plugins.push(
19088
19101
  new BannerPlugin({
19089
19102
  // Not wrapped in comments.
19090
19103
  raw: true,
19091
- // Not sure this is actually working, but it's supposed to only add
19104
+ // Doesn't seem to work, but it's supposed to only add
19092
19105
  // the banner to entry modules.
19093
19106
  entryOnly: true,
19094
- banner({ chunk }) {
19095
- if (!chunk?.entryModule) {
19096
- return "";
19107
+ banner(data) {
19108
+ if (context.bundler.variant === "5") {
19109
+ if (!chunkGraph || chunkGraph.getNumberOfEntryModules(data.chunk) === 0) {
19110
+ return "";
19111
+ }
19112
+ return getContentToInject();
19113
+ } else {
19114
+ if (!data.chunk?.hasEntryModule()) {
19115
+ return "";
19116
+ }
19117
+ return getContentToInject();
19097
19118
  }
19098
- return getContentToInject();
19099
19119
  }
19100
19120
  })
19101
19121
  );
@@ -36399,7 +36419,7 @@ const buildPluginFactory = ({
36399
36419
 
36400
36420
  var name = "@datadog/esbuild-plugin";
36401
36421
  var packageManager = "yarn@4.0.2";
36402
- var version$1 = "2.3.1-dev-10";
36422
+ var version$1 = "2.3.1-dev-13";
36403
36423
  var license = "MIT";
36404
36424
  var author = "Datadog";
36405
36425
  var description = "Datadog ESBuild Plugin";