@datadog/esbuild-plugin 2.3.1-dev-3 → 2.3.1-dev-5

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
@@ -20,7 +20,6 @@ var require$$0$2 = require('stream');
20
20
  var zlib = require('zlib');
21
21
  var require$$0$3 = require('constants');
22
22
  var require$$5 = require('assert');
23
- var https = require('https');
24
23
  var perf_hooks = require('perf_hooks');
25
24
  var querystring = require('querystring');
26
25
  var process2 = require('process');
@@ -2293,6 +2292,12 @@ var lib$3 = retry$1;
2293
2292
 
2294
2293
  var retry$2 = /*@__PURE__*/getDefaultExportFromCjs(lib$3);
2295
2294
 
2295
+ const PREPARATION_PLUGIN_NAME = "datadog-injection-preparation-plugin";
2296
+ const PLUGIN_NAME$4 = "datadog-injection-plugin";
2297
+ const RESOLUTION_PLUGIN_NAME = "datadog-injection-resolution-plugin";
2298
+ const INJECTED_FILE = "__DATADOG_INJECTION_STUB";
2299
+ const DISTANT_FILE_RX = /^https?:\/\//;
2300
+
2296
2301
  const formatDuration = (duration) => {
2297
2302
  const days = Math.floor(duration / 1e3 / 60 / 60 / 24);
2298
2303
  const usedDuration = duration - days * 24 * 60 * 60 * 1e3;
@@ -2371,6 +2376,7 @@ const truncateString = (str, maxLength = 60, placeholder = "[...]") => {
2371
2376
  const rightStop = stringLength - leftStop;
2372
2377
  return `${str.slice(0, leftStop)}${placeholder}${str.slice(-rightStop)}`;
2373
2378
  };
2379
+ const isInjection = (filename) => filename.includes(INJECTED_FILE);
2374
2380
 
2375
2381
  var balancedMatch = balanced$1;
2376
2382
  function balanced$1(a, b, str) {
@@ -11259,12 +11265,6 @@ const glob = Object.assign(glob_, {
11259
11265
  });
11260
11266
  glob.glob = glob;
11261
11267
 
11262
- const PREPARATION_PLUGIN_NAME = "datadog-injection-preparation-plugin";
11263
- const PLUGIN_NAME$4 = "datadog-injection-plugin";
11264
- const RESOLUTION_PLUGIN_NAME = "datadog-injection-resolution-plugin";
11265
- const INJECTED_FILE = "__DATADOG_INJECTION_STUB";
11266
- const DISTANT_FILE_RX = /^https?:\/\//;
11267
-
11268
11268
  const EXTENSION_RX = /\.(?!.*(?:\.|\/|\\))(\w{1,})/g;
11269
11269
  const QUERY_RX = /(\?|%3F|\|)+/gi;
11270
11270
  const getExtension = (filepath) => {
@@ -11325,7 +11325,6 @@ const serializeBuildReport = (report) => {
11325
11325
  }
11326
11326
  return jsonReport;
11327
11327
  };
11328
- const isInjection = (filename) => filename.includes(INJECTED_FILE);
11329
11328
  const BUNDLER_SPECIFICS = ["unknown", "commonjsHelpers.js", "vite/preload-helper.js"];
11330
11329
  const cleanReport = (report, filepath, filter) => {
11331
11330
  const cleanedReport = /* @__PURE__ */ new Set();
@@ -19097,10 +19096,27 @@ const getInjectionPlugins = (opts, context, toInject) => {
19097
19096
  return "";
19098
19097
  }
19099
19098
  };
19100
- const isInjectedFile = (id) => {
19101
- return id.includes(INJECTED_FILE);
19102
- };
19103
19099
  return [
19100
+ // Resolve the injected file.
19101
+ {
19102
+ name: RESOLUTION_PLUGIN_NAME,
19103
+ enforce: "pre",
19104
+ resolveId(id) {
19105
+ if (isInjection(id)) {
19106
+ return { id, moduleSideEffects: true };
19107
+ }
19108
+ },
19109
+ loadInclude(id) {
19110
+ if (isInjection(id)) {
19111
+ return true;
19112
+ }
19113
+ },
19114
+ load(id) {
19115
+ if (isInjection(id)) {
19116
+ return getContentToInject();
19117
+ }
19118
+ }
19119
+ },
19104
19120
  // Prepare and fetch the content to inject.
19105
19121
  {
19106
19122
  name: PREPARATION_PLUGIN_NAME,
@@ -19164,26 +19180,6 @@ const getInjectionPlugins = (opts, context, toInject) => {
19164
19180
  },
19165
19181
  rollup: rollupInjectionPlugin,
19166
19182
  vite: rollupInjectionPlugin
19167
- },
19168
- // Resolve the injected file.
19169
- {
19170
- name: RESOLUTION_PLUGIN_NAME,
19171
- enforce: "post",
19172
- resolveId(id) {
19173
- if (isInjectedFile(id)) {
19174
- return { id, moduleSideEffects: true };
19175
- }
19176
- },
19177
- loadInclude(id) {
19178
- if (isInjectedFile(id)) {
19179
- return true;
19180
- }
19181
- },
19182
- load(id) {
19183
- if (isInjectedFile(id)) {
19184
- return getContentToInject();
19185
- }
19186
- }
19187
19183
  }
19188
19184
  ];
19189
19185
  };
@@ -24363,30 +24359,10 @@ const sendMetrics = (metrics, auth, log) => {
24363
24359
  Sending ${metrics.length} metrics.
24364
24360
  Metrics:
24365
24361
  - ${metricsNames.join("\n - ")}`);
24366
- return new Promise((resolve, reject) => {
24367
- const req = https.request({
24368
- method: "POST",
24369
- hostname: auth.endPoint,
24370
- path: `/api/v1/series?api_key=${auth.apiKey}`
24371
- });
24372
- req.write(
24373
- JSON.stringify({
24374
- series: metrics
24375
- })
24376
- );
24377
- req.on("response", (res) => {
24378
- if (!(res.statusCode >= 200 && res.statusCode < 300)) {
24379
- res.resume();
24380
- reject(`Request Failed.
24381
- Status Code: ${res.statusCode}`);
24382
- return;
24383
- }
24384
- res.on("data", () => {
24385
- });
24386
- res.on("end", resolve);
24387
- });
24388
- req.on("error", reject);
24389
- req.end();
24362
+ return doRequest({
24363
+ method: "POST",
24364
+ url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
24365
+ getData: () => ({ data: JSON.stringify({ series: metrics }) })
24390
24366
  }).then(() => {
24391
24367
  log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
24392
24368
  }).catch((e) => {
@@ -36492,7 +36468,7 @@ const buildPluginFactory = ({
36492
36468
 
36493
36469
  var name = "@datadog/esbuild-plugin";
36494
36470
  var packageManager = "yarn@4.0.2";
36495
- var version$1 = "2.3.1-dev-3";
36471
+ var version$1 = "2.3.1-dev-5";
36496
36472
  var license = "MIT";
36497
36473
  var author = "Datadog";
36498
36474
  var description = "Datadog ESBuild Plugin";