@datadog/esbuild-plugin 2.3.1-dev-7 → 2.3.1-dev-9

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.
@@ -12043,7 +12043,7 @@ const getBuildReportPlugin = (opts, context) => {
12043
12043
  };
12044
12044
  };
12045
12045
 
12046
- const PLUGIN_NAME$2 = "datadog-context-plugin";
12046
+ const PLUGIN_NAME$2 = "datadog-bundler-report-plugin";
12047
12047
  const rollupPlugin = (context) => ({
12048
12048
  options(options) {
12049
12049
  context.bundler.rawConfig = options;
@@ -19053,17 +19053,15 @@ const getInjectionPlugins = (opts, context, toInject) => {
19053
19053
  const log = getLogger(opts.logLevel, PLUGIN_NAME$4);
19054
19054
  const contentToInject = [];
19055
19055
  const getContentToInject = () => {
19056
- contentToInject.unshift(
19057
- // Needs at least one element otherwise ESBuild will throw 'Do not know how to load path'.
19058
- // Most likely because it tries to generate an empty file.
19059
- `
19056
+ const before = `
19060
19057
  /********************************************/
19061
- /* BEGIN INJECTION BY DATADOG BUILD PLUGINS */`
19062
- );
19063
- contentToInject.push(`
19058
+ /* BEGIN INJECTION BY DATADOG BUILD PLUGINS */`;
19059
+ const after = `
19064
19060
  /* END INJECTION BY DATADOG BUILD PLUGINS */
19065
- /********************************************/`);
19066
- return contentToInject.join("\n\n");
19061
+ /********************************************/`;
19062
+ return `${before}
19063
+ ${contentToInject.join("\n\n")}
19064
+ ${after}`;
19067
19065
  };
19068
19066
  const rollupInjectionPlugin = {
19069
19067
  banner(chunk) {
@@ -19074,11 +19072,11 @@ const getInjectionPlugins = (opts, context, toInject) => {
19074
19072
  }
19075
19073
  };
19076
19074
  return [
19077
- // Resolve the injected file.
19075
+ // Resolve the injected file for all bundlers.
19078
19076
  {
19079
19077
  name: RESOLUTION_PLUGIN_NAME,
19080
19078
  enforce: "pre",
19081
- resolveId(id) {
19079
+ async resolveId(id) {
19082
19080
  if (isInjection(id)) {
19083
19081
  return { id, moduleSideEffects: true };
19084
19082
  }
@@ -19094,7 +19092,7 @@ const getInjectionPlugins = (opts, context, toInject) => {
19094
19092
  }
19095
19093
  }
19096
19094
  },
19097
- // Prepare and fetch the content to inject.
19095
+ // Prepare and fetch the content to inject for all bundlers.
19098
19096
  {
19099
19097
  name: PREPARATION_PLUGIN_NAME,
19100
19098
  enforce: "pre",
@@ -19105,13 +19103,53 @@ const getInjectionPlugins = (opts, context, toInject) => {
19105
19103
  }
19106
19104
  },
19107
19105
  // Inject the virtual file that will be home of all injected content.
19106
+ // Each bundler has its own way to inject a file.
19108
19107
  {
19109
19108
  name: PLUGIN_NAME$4,
19110
19109
  esbuild: {
19111
19110
  setup(build) {
19112
19111
  const { initialOptions } = build;
19113
- initialOptions.inject = initialOptions.inject || [];
19114
- initialOptions.inject.push(INJECTED_FILE);
19112
+ build.onResolve({ filter: /.*/ }, async (args) => {
19113
+ if (args.kind !== "entry-point") {
19114
+ return null;
19115
+ }
19116
+ if (initialOptions.inject?.includes(args.path)) {
19117
+ return null;
19118
+ }
19119
+ return {
19120
+ pluginName: PLUGIN_NAME$4,
19121
+ path: require$$1.isAbsolute(args.path) ? args.path : require$$1.join(args.resolveDir, args.path),
19122
+ pluginData: {
19123
+ isInjectionResolver: true,
19124
+ originalPath: args.path,
19125
+ originalResolveDir: args.resolveDir
19126
+ },
19127
+ // Adding a suffix prevents esbuild from marking the entrypoint as resolved,
19128
+ // avoiding a dependency loop with the proxy module.
19129
+ // This ensures esbuild continues to traverse the module tree
19130
+ // and re-resolves the entrypoint when imported from the proxy module.
19131
+ suffix: "?datadogInjected=true"
19132
+ };
19133
+ });
19134
+ build.onLoad({ filter: /.*/ }, async (args) => {
19135
+ if (!args.pluginData?.isInjectionResolver) {
19136
+ return null;
19137
+ }
19138
+ const originalPath = args.pluginData.originalPath;
19139
+ const originalResolveDir = args.pluginData.originalResolveDir;
19140
+ const contents = `
19141
+ import ${JSON.stringify(INJECTED_FILE)};
19142
+ import * as OriginalModule from ${JSON.stringify(originalPath)};
19143
+ export default OriginalModule['default'.toString()];
19144
+ export * from ${JSON.stringify(originalPath)};
19145
+ `;
19146
+ return {
19147
+ loader: "js",
19148
+ pluginName: PLUGIN_NAME$4,
19149
+ contents,
19150
+ resolveDir: originalResolveDir
19151
+ };
19152
+ });
19115
19153
  }
19116
19154
  },
19117
19155
  webpack: (compiler) => {
@@ -19167,6 +19205,7 @@ const getInternalPlugins = (options, meta) => {
19167
19205
  const toInject = [];
19168
19206
  const globalContext = {
19169
19207
  auth: options.auth,
19208
+ pluginNames: [],
19170
19209
  bundler: {
19171
19210
  name: meta.framework,
19172
19211
  fullName: `${meta.framework}${variant}`,
@@ -36417,18 +36456,20 @@ const validateOptions = (options = {}) => {
36417
36456
  ...options
36418
36457
  };
36419
36458
  };
36459
+ const HOST_NAME = "datadog-build-plugins";
36420
36460
  const buildPluginFactory = ({
36421
36461
  version
36422
36462
  }) => {
36423
36463
  return createUnplugin((opts, unpluginMetaContext) => {
36424
36464
  const options = validateOptions(opts);
36425
- if ("esbuildHostName" in unpluginMetaContext) {
36426
- unpluginMetaContext.esbuildHostName = "datadog-plugins";
36465
+ if (unpluginMetaContext.framework === "esbuild") {
36466
+ unpluginMetaContext.esbuildHostName = HOST_NAME;
36427
36467
  }
36428
36468
  const { globalContext, internalPlugins } = getInternalPlugins(options, {
36429
36469
  version,
36430
36470
  ...unpluginMetaContext
36431
36471
  });
36472
+ globalContext.pluginNames.push(HOST_NAME);
36432
36473
  const plugins = [...internalPlugins];
36433
36474
  if (options.customPlugins) {
36434
36475
  const customPlugins = options.customPlugins(options, globalContext);
@@ -36440,13 +36481,14 @@ const buildPluginFactory = ({
36440
36481
  if (options[CONFIG_KEY] && options[CONFIG_KEY].disabled !== true) {
36441
36482
  plugins.push(...getPlugins(options, globalContext));
36442
36483
  }
36484
+ globalContext.pluginNames.push(...plugins.map((plugin) => plugin.name));
36443
36485
  return plugins;
36444
36486
  });
36445
36487
  };
36446
36488
 
36447
36489
  var name = "@datadog/esbuild-plugin";
36448
36490
  var packageManager = "yarn@4.0.2";
36449
- var version$1 = "2.3.1-dev-7";
36491
+ var version$1 = "2.3.1-dev-9";
36450
36492
  var license = "MIT";
36451
36493
  var author = "Datadog";
36452
36494
  var description = "Datadog ESBuild Plugin";