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

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
@@ -11827,7 +11827,7 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11827
11827
  const isModuleSupported = (moduleIdentifier) => {
11828
11828
  return (
11829
11829
  // Ignore unidentified modules and runtimes.
11830
- !!moduleIdentifier && !moduleIdentifier.startsWith("webpack/runtime") && !moduleIdentifier.includes("/webpack4/buildin/")
11830
+ !!moduleIdentifier && !moduleIdentifier.startsWith("webpack/runtime") && !moduleIdentifier.includes("/webpack4/buildin/") && !moduleIdentifier.startsWith("multi ")
11831
11831
  );
11832
11832
  };
11833
11833
  const warn = (warning) => {
@@ -11854,6 +11854,9 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11854
11854
  return getModuleFromDep(dep)?.identifier();
11855
11855
  }).filter(Boolean)
11856
11856
  );
11857
+ if (!isModuleSupported(moduleIdentifier)) {
11858
+ continue;
11859
+ }
11857
11860
  for (const depIdentifier of dependencies) {
11858
11861
  const depDeps = tempDeps.get(depIdentifier) || {
11859
11862
  dependencies: /* @__PURE__ */ new Set(),
@@ -11862,9 +11865,6 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11862
11865
  depDeps.dependents.add(moduleIdentifier);
11863
11866
  tempDeps.set(depIdentifier, depDeps);
11864
11867
  }
11865
- if (!isModuleSupported(moduleIdentifier)) {
11866
- continue;
11867
- }
11868
11868
  const moduleDeps = tempDeps.get(moduleIdentifier) || {
11869
11869
  dependents: /* @__PURE__ */ new Set(),
11870
11870
  dependencies: /* @__PURE__ */ new Set()
@@ -11917,9 +11917,10 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11917
11917
  (f) => getAbsolutePath(context.bundler.outDir, f)
11918
11918
  );
11919
11919
  };
11920
+ const chunkGraph = result.chunkGraph;
11920
11921
  for (const chunk of chunks) {
11921
11922
  const files = getChunkFiles(chunk);
11922
- const chunkModules = chunk.getModules().flatMap((m) => {
11923
+ const chunkModules = (chunkGraph ? chunkGraph?.getChunkModules(chunk) : chunk.getModules()).flatMap((m) => {
11923
11924
  return "modules" in m && Array.isArray(m.modules) ? m.modules.map((m2) => m2.identifier()) : m.identifier();
11924
11925
  }).filter(isModuleSupported);
11925
11926
  for (const file of files) {
@@ -11973,7 +11974,12 @@ const getWebpackPlugin$2 = (context, PLUGIN_NAME, log) => (compiler) => {
11973
11974
  const entryInputs = [];
11974
11975
  let size = 0;
11975
11976
  const entryFiles = entrypoint.chunks.flatMap(getChunkFiles);
11976
- const entryFilename = entrypoint.chunks.filter((c) => c.entryModule).flatMap((c) => Array.from(c.files))[0];
11977
+ const entryFilename = entrypoint.chunks.filter(
11978
+ (c) => (
11979
+ // Webpack5 forces you to use the chunkGraph to get the modules.
11980
+ chunkGraph ? chunkGraph.getNumberOfEntryModules(c) > 0 : c.hasEntryModule()
11981
+ )
11982
+ ).flatMap((c) => Array.from(c.files))[0];
11977
11983
  for (const file2 of entryFiles) {
11978
11984
  const outputFound = reportOutputsIndexed.get(file2);
11979
11985
  if (!file2 || !outputFound) {
@@ -19103,22 +19109,36 @@ ${after}`;
19103
19109
  },
19104
19110
  webpack: (compiler) => {
19105
19111
  const BannerPlugin = compiler?.webpack?.BannerPlugin || bundler?.BannerPlugin || bundler?.default?.BannerPlugin;
19112
+ compiler?.webpack?.ChunkGraph || bundler?.ChunkGraph || bundler?.default?.ChunkGraph;
19106
19113
  if (!BannerPlugin) {
19107
19114
  log("Missing BannerPlugin", "error");
19108
19115
  }
19116
+ let chunkGraph;
19117
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME$4, (compilation) => {
19118
+ compilation.hooks.afterChunks.tap(PLUGIN_NAME$4, () => {
19119
+ chunkGraph = compilation.chunkGraph;
19120
+ });
19121
+ });
19109
19122
  compiler.options.plugins = compiler.options.plugins || [];
19110
19123
  compiler.options.plugins.push(
19111
19124
  new BannerPlugin({
19112
19125
  // Not wrapped in comments.
19113
19126
  raw: true,
19114
- // Not sure this is actually working, but it's supposed to only add
19127
+ // Doesn't seem to work, but it's supposed to only add
19115
19128
  // the banner to entry modules.
19116
19129
  entryOnly: true,
19117
- banner({ chunk }) {
19118
- if (!chunk?.entryModule) {
19119
- return "";
19130
+ banner(data) {
19131
+ if (context.bundler.variant === "5") {
19132
+ if (!chunkGraph || chunkGraph.getNumberOfEntryModules(data.chunk) === 0) {
19133
+ return "";
19134
+ }
19135
+ return getContentToInject();
19136
+ } else {
19137
+ if (!data.chunk?.hasEntryModule()) {
19138
+ return "";
19139
+ }
19140
+ return getContentToInject();
19120
19141
  }
19121
- return getContentToInject();
19122
19142
  }
19123
19143
  })
19124
19144
  );
@@ -36422,7 +36442,7 @@ const buildPluginFactory = ({
36422
36442
 
36423
36443
  var name = "@datadog/esbuild-plugin";
36424
36444
  var packageManager = "yarn@4.0.2";
36425
- var version$1 = "2.3.1-dev-10";
36445
+ var version$1 = "2.3.1-dev-12";
36426
36446
  var license = "MIT";
36427
36447
  var author = "Datadog";
36428
36448
  var description = "Datadog ESBuild Plugin";