@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.
@@ -18,7 +18,6 @@ import require$$0$3, { Readable } from 'stream';
18
18
  import { createGzip } from 'zlib';
19
19
  import require$$0$2 from 'constants';
20
20
  import require$$5 from 'assert';
21
- import { request } from 'https';
22
21
  import { performance as performance$1 } from 'perf_hooks';
23
22
  import * as querystring from 'querystring';
24
23
  import process2 from 'process';
@@ -2270,6 +2269,12 @@ var lib$3 = retry$1;
2270
2269
 
2271
2270
  var retry$2 = /*@__PURE__*/getDefaultExportFromCjs(lib$3);
2272
2271
 
2272
+ const PREPARATION_PLUGIN_NAME = "datadog-injection-preparation-plugin";
2273
+ const PLUGIN_NAME$4 = "datadog-injection-plugin";
2274
+ const RESOLUTION_PLUGIN_NAME = "datadog-injection-resolution-plugin";
2275
+ const INJECTED_FILE = "__DATADOG_INJECTION_STUB";
2276
+ const DISTANT_FILE_RX = /^https?:\/\//;
2277
+
2273
2278
  const formatDuration = (duration) => {
2274
2279
  const days = Math.floor(duration / 1e3 / 60 / 60 / 24);
2275
2280
  const usedDuration = duration - days * 24 * 60 * 60 * 1e3;
@@ -2348,6 +2353,7 @@ const truncateString = (str, maxLength = 60, placeholder = "[...]") => {
2348
2353
  const rightStop = stringLength - leftStop;
2349
2354
  return `${str.slice(0, leftStop)}${placeholder}${str.slice(-rightStop)}`;
2350
2355
  };
2356
+ const isInjection = (filename) => filename.includes(INJECTED_FILE);
2351
2357
 
2352
2358
  var balancedMatch = balanced$1;
2353
2359
  function balanced$1(a, b, str) {
@@ -11236,12 +11242,6 @@ const glob = Object.assign(glob_, {
11236
11242
  });
11237
11243
  glob.glob = glob;
11238
11244
 
11239
- const PREPARATION_PLUGIN_NAME = "datadog-injection-preparation-plugin";
11240
- const PLUGIN_NAME$4 = "datadog-injection-plugin";
11241
- const RESOLUTION_PLUGIN_NAME = "datadog-injection-resolution-plugin";
11242
- const INJECTED_FILE = "__DATADOG_INJECTION_STUB";
11243
- const DISTANT_FILE_RX = /^https?:\/\//;
11244
-
11245
11245
  const EXTENSION_RX = /\.(?!.*(?:\.|\/|\\))(\w{1,})/g;
11246
11246
  const QUERY_RX = /(\?|%3F|\|)+/gi;
11247
11247
  const getExtension = (filepath) => {
@@ -11302,7 +11302,6 @@ const serializeBuildReport = (report) => {
11302
11302
  }
11303
11303
  return jsonReport;
11304
11304
  };
11305
- const isInjection = (filename) => filename.includes(INJECTED_FILE);
11306
11305
  const BUNDLER_SPECIFICS = ["unknown", "commonjsHelpers.js", "vite/preload-helper.js"];
11307
11306
  const cleanReport = (report, filepath, filter) => {
11308
11307
  const cleanedReport = /* @__PURE__ */ new Set();
@@ -19074,10 +19073,27 @@ const getInjectionPlugins = (opts, context, toInject) => {
19074
19073
  return "";
19075
19074
  }
19076
19075
  };
19077
- const isInjectedFile = (id) => {
19078
- return id.includes(INJECTED_FILE);
19079
- };
19080
19076
  return [
19077
+ // Resolve the injected file.
19078
+ {
19079
+ name: RESOLUTION_PLUGIN_NAME,
19080
+ enforce: "pre",
19081
+ resolveId(id) {
19082
+ if (isInjection(id)) {
19083
+ return { id, moduleSideEffects: true };
19084
+ }
19085
+ },
19086
+ loadInclude(id) {
19087
+ if (isInjection(id)) {
19088
+ return true;
19089
+ }
19090
+ },
19091
+ load(id) {
19092
+ if (isInjection(id)) {
19093
+ return getContentToInject();
19094
+ }
19095
+ }
19096
+ },
19081
19097
  // Prepare and fetch the content to inject.
19082
19098
  {
19083
19099
  name: PREPARATION_PLUGIN_NAME,
@@ -19141,26 +19157,6 @@ const getInjectionPlugins = (opts, context, toInject) => {
19141
19157
  },
19142
19158
  rollup: rollupInjectionPlugin,
19143
19159
  vite: rollupInjectionPlugin
19144
- },
19145
- // Resolve the injected file.
19146
- {
19147
- name: RESOLUTION_PLUGIN_NAME,
19148
- enforce: "post",
19149
- resolveId(id) {
19150
- if (isInjectedFile(id)) {
19151
- return { id, moduleSideEffects: true };
19152
- }
19153
- },
19154
- loadInclude(id) {
19155
- if (isInjectedFile(id)) {
19156
- return true;
19157
- }
19158
- },
19159
- load(id) {
19160
- if (isInjectedFile(id)) {
19161
- return getContentToInject();
19162
- }
19163
- }
19164
19160
  }
19165
19161
  ];
19166
19162
  };
@@ -24340,30 +24336,10 @@ const sendMetrics = (metrics, auth, log) => {
24340
24336
  Sending ${metrics.length} metrics.
24341
24337
  Metrics:
24342
24338
  - ${metricsNames.join("\n - ")}`);
24343
- return new Promise((resolve, reject) => {
24344
- const req = request({
24345
- method: "POST",
24346
- hostname: auth.endPoint,
24347
- path: `/api/v1/series?api_key=${auth.apiKey}`
24348
- });
24349
- req.write(
24350
- JSON.stringify({
24351
- series: metrics
24352
- })
24353
- );
24354
- req.on("response", (res) => {
24355
- if (!(res.statusCode >= 200 && res.statusCode < 300)) {
24356
- res.resume();
24357
- reject(`Request Failed.
24358
- Status Code: ${res.statusCode}`);
24359
- return;
24360
- }
24361
- res.on("data", () => {
24362
- });
24363
- res.on("end", resolve);
24364
- });
24365
- req.on("error", reject);
24366
- req.end();
24339
+ return doRequest({
24340
+ method: "POST",
24341
+ url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
24342
+ getData: () => ({ data: JSON.stringify({ series: metrics }) })
24367
24343
  }).then(() => {
24368
24344
  log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
24369
24345
  }).catch((e) => {
@@ -36469,7 +36445,7 @@ const buildPluginFactory = ({
36469
36445
 
36470
36446
  var name = "@datadog/esbuild-plugin";
36471
36447
  var packageManager = "yarn@4.0.2";
36472
- var version$1 = "2.3.1-dev-3";
36448
+ var version$1 = "2.3.1-dev-5";
36473
36449
  var license = "MIT";
36474
36450
  var author = "Datadog";
36475
36451
  var description = "Datadog ESBuild Plugin";