@datadog/vite-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.
@@ -96,6 +96,7 @@ type GlobalContext = {
96
96
  build: BuildReport;
97
97
  cwd: string;
98
98
  git?: RepositoryData;
99
+ pluginNames: string[];
99
100
  start: number;
100
101
  version: string;
101
102
  };
package/dist/src/index.js CHANGED
@@ -12066,7 +12066,7 @@ const getBuildReportPlugin = (opts, context) => {
12066
12066
  };
12067
12067
  };
12068
12068
 
12069
- const PLUGIN_NAME$2 = "datadog-context-plugin";
12069
+ const PLUGIN_NAME$2 = "datadog-bundler-report-plugin";
12070
12070
  const rollupPlugin = (context) => ({
12071
12071
  options(options) {
12072
12072
  context.bundler.rawConfig = options;
@@ -19076,17 +19076,15 @@ const getInjectionPlugins = (opts, context, toInject) => {
19076
19076
  const log = getLogger(opts.logLevel, PLUGIN_NAME$4);
19077
19077
  const contentToInject = [];
19078
19078
  const getContentToInject = () => {
19079
- contentToInject.unshift(
19080
- // Needs at least one element otherwise ESBuild will throw 'Do not know how to load path'.
19081
- // Most likely because it tries to generate an empty file.
19082
- `
19079
+ const before = `
19083
19080
  /********************************************/
19084
- /* BEGIN INJECTION BY DATADOG BUILD PLUGINS */`
19085
- );
19086
- contentToInject.push(`
19081
+ /* BEGIN INJECTION BY DATADOG BUILD PLUGINS */`;
19082
+ const after = `
19087
19083
  /* END INJECTION BY DATADOG BUILD PLUGINS */
19088
- /********************************************/`);
19089
- return contentToInject.join("\n\n");
19084
+ /********************************************/`;
19085
+ return `${before}
19086
+ ${contentToInject.join("\n\n")}
19087
+ ${after}`;
19090
19088
  };
19091
19089
  const rollupInjectionPlugin = {
19092
19090
  banner(chunk) {
@@ -19097,11 +19095,11 @@ const getInjectionPlugins = (opts, context, toInject) => {
19097
19095
  }
19098
19096
  };
19099
19097
  return [
19100
- // Resolve the injected file.
19098
+ // Resolve the injected file for all bundlers.
19101
19099
  {
19102
19100
  name: RESOLUTION_PLUGIN_NAME,
19103
19101
  enforce: "pre",
19104
- resolveId(id) {
19102
+ async resolveId(id) {
19105
19103
  if (isInjection(id)) {
19106
19104
  return { id, moduleSideEffects: true };
19107
19105
  }
@@ -19117,7 +19115,7 @@ const getInjectionPlugins = (opts, context, toInject) => {
19117
19115
  }
19118
19116
  }
19119
19117
  },
19120
- // Prepare and fetch the content to inject.
19118
+ // Prepare and fetch the content to inject for all bundlers.
19121
19119
  {
19122
19120
  name: PREPARATION_PLUGIN_NAME,
19123
19121
  enforce: "pre",
@@ -19128,13 +19126,53 @@ const getInjectionPlugins = (opts, context, toInject) => {
19128
19126
  }
19129
19127
  },
19130
19128
  // Inject the virtual file that will be home of all injected content.
19129
+ // Each bundler has its own way to inject a file.
19131
19130
  {
19132
19131
  name: PLUGIN_NAME$4,
19133
19132
  esbuild: {
19134
19133
  setup(build) {
19135
19134
  const { initialOptions } = build;
19136
- initialOptions.inject = initialOptions.inject || [];
19137
- initialOptions.inject.push(INJECTED_FILE);
19135
+ build.onResolve({ filter: /.*/ }, async (args) => {
19136
+ if (args.kind !== "entry-point") {
19137
+ return null;
19138
+ }
19139
+ if (initialOptions.inject?.includes(args.path)) {
19140
+ return null;
19141
+ }
19142
+ return {
19143
+ pluginName: PLUGIN_NAME$4,
19144
+ path: require$$1.isAbsolute(args.path) ? args.path : require$$1.join(args.resolveDir, args.path),
19145
+ pluginData: {
19146
+ isInjectionResolver: true,
19147
+ originalPath: args.path,
19148
+ originalResolveDir: args.resolveDir
19149
+ },
19150
+ // Adding a suffix prevents esbuild from marking the entrypoint as resolved,
19151
+ // avoiding a dependency loop with the proxy module.
19152
+ // This ensures esbuild continues to traverse the module tree
19153
+ // and re-resolves the entrypoint when imported from the proxy module.
19154
+ suffix: "?datadogInjected=true"
19155
+ };
19156
+ });
19157
+ build.onLoad({ filter: /.*/ }, async (args) => {
19158
+ if (!args.pluginData?.isInjectionResolver) {
19159
+ return null;
19160
+ }
19161
+ const originalPath = args.pluginData.originalPath;
19162
+ const originalResolveDir = args.pluginData.originalResolveDir;
19163
+ const contents = `
19164
+ import ${JSON.stringify(INJECTED_FILE)};
19165
+ import * as OriginalModule from ${JSON.stringify(originalPath)};
19166
+ export default OriginalModule['default'.toString()];
19167
+ export * from ${JSON.stringify(originalPath)};
19168
+ `;
19169
+ return {
19170
+ loader: "js",
19171
+ pluginName: PLUGIN_NAME$4,
19172
+ contents,
19173
+ resolveDir: originalResolveDir
19174
+ };
19175
+ });
19138
19176
  }
19139
19177
  },
19140
19178
  webpack: (compiler) => {
@@ -19190,6 +19228,7 @@ const getInternalPlugins = (options, meta) => {
19190
19228
  const toInject = [];
19191
19229
  const globalContext = {
19192
19230
  auth: options.auth,
19231
+ pluginNames: [],
19193
19232
  bundler: {
19194
19233
  name: meta.framework,
19195
19234
  fullName: `${meta.framework}${variant}`,
@@ -36440,18 +36479,20 @@ const validateOptions = (options = {}) => {
36440
36479
  ...options
36441
36480
  };
36442
36481
  };
36482
+ const HOST_NAME = "datadog-build-plugins";
36443
36483
  const buildPluginFactory = ({
36444
36484
  version
36445
36485
  }) => {
36446
36486
  return createUnplugin((opts, unpluginMetaContext) => {
36447
36487
  const options = validateOptions(opts);
36448
- if ("esbuildHostName" in unpluginMetaContext) {
36449
- unpluginMetaContext.esbuildHostName = "datadog-plugins";
36488
+ if (unpluginMetaContext.framework === "esbuild") {
36489
+ unpluginMetaContext.esbuildHostName = HOST_NAME;
36450
36490
  }
36451
36491
  const { globalContext, internalPlugins } = getInternalPlugins(options, {
36452
36492
  version,
36453
36493
  ...unpluginMetaContext
36454
36494
  });
36495
+ globalContext.pluginNames.push(HOST_NAME);
36455
36496
  const plugins = [...internalPlugins];
36456
36497
  if (options.customPlugins) {
36457
36498
  const customPlugins = options.customPlugins(options, globalContext);
@@ -36463,13 +36504,14 @@ const buildPluginFactory = ({
36463
36504
  if (options[CONFIG_KEY] && options[CONFIG_KEY].disabled !== true) {
36464
36505
  plugins.push(...getPlugins(options, globalContext));
36465
36506
  }
36507
+ globalContext.pluginNames.push(...plugins.map((plugin) => plugin.name));
36466
36508
  return plugins;
36467
36509
  });
36468
36510
  };
36469
36511
 
36470
36512
  var name = "@datadog/vite-plugin";
36471
36513
  var packageManager = "yarn@4.0.2";
36472
- var version$1 = "2.3.1-dev-7";
36514
+ var version$1 = "2.3.1-dev-9";
36473
36515
  var license = "MIT";
36474
36516
  var author = "Datadog";
36475
36517
  var description = "Datadog Vite Plugin";