@sentry/bundler-plugin-core 0.1.0 → 0.2.0

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/esm/index.js CHANGED
@@ -818,7 +818,7 @@ function normalizeUserOptions(userOptions) {
818
818
  // Optional options
819
819
  setCommits: userOptions.setCommits,
820
820
  deploy: userOptions.deploy,
821
- entries: normalizeEntries(userOptions.entries),
821
+ releaseInjectionTargets: normalizeReleaseInjectionTargets(userOptions.releaseInjectionTargets),
822
822
  dist: userOptions.dist,
823
823
  errorHandler: userOptions.errorHandler,
824
824
  configFile: userOptions.configFile
@@ -831,16 +831,17 @@ function normalizeUserOptions(userOptions) {
831
831
  return options;
832
832
  }
833
833
  /**
834
- * Converts the user-facing `entries` option to the internal `entries` option
834
+ * Converts the user-facing `releaseInjectionTargets` option to the internal
835
+ * `releaseInjectionTargets` option
835
836
  */
836
837
 
837
- function normalizeEntries(userEntries) {
838
- if (userEntries === undefined) {
838
+ function normalizeReleaseInjectionTargets(userReleaseInjectionTargets) {
839
+ if (userReleaseInjectionTargets === undefined) {
839
840
  return undefined;
840
- } else if (typeof userEntries === "function") {
841
- return userEntries;
841
+ } else if (typeof userReleaseInjectionTargets === "function") {
842
+ return userReleaseInjectionTargets;
842
843
  } else {
843
- return arrayify(userEntries);
844
+ return arrayify(userReleaseInjectionTargets);
844
845
  }
845
846
  }
846
847
  /**
@@ -945,7 +946,7 @@ function makeSentryClient(dsn, telemetryEnabled) {
945
946
  enabled: telemetryEnabled,
946
947
  tracesSampleRate: telemetryEnabled ? 1.0 : 0.0,
947
948
  sampleRate: telemetryEnabled ? 1.0 : 0.0,
948
- release: "0.1.0",
949
+ release: "0.2.0",
949
950
  integrations: [new Integrations.Http({
950
951
  tracing: true
951
952
  })],
@@ -1475,6 +1476,7 @@ function getDryRunCLI(cli, logger) {
1475
1476
  // This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
1476
1477
  // This probably doesn't work for all bundlers but for rollup it does.
1477
1478
  var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
1479
+ var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs"];
1478
1480
  /**
1479
1481
  * The sentry bundler plugin concerns itself with two things:
1480
1482
  * - Release injection
@@ -1482,45 +1484,11 @@ var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
1482
1484
  *
1483
1485
  * Release injection:
1484
1486
  *
1485
- * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` variable into the entrypoint of all bundles.
1486
- * On a technical level this is done by appending an import (`import "sentry-release-injector;"`) to all entrypoint files
1487
- * of the user code (see `transformInclude` and `transform` hooks). This import is then resolved by the sentry plugin
1488
- * to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
1489
- *
1490
- * The resulting output approximately looks like this:
1491
- *
1492
- * ```text
1493
- * entrypoint1.js (user file)
1494
- * ┌─────────────────────────┐ ┌─────────────────────────────────────────────────┐
1495
- * │ │ │ import { myFunction } from "./my-library.js"; │
1496
- * │ sentry-bundler-plugin │ │ │
1497
- * │ │ │ const myResult = myFunction(); │
1498
- * └---------│--------------- │ export { myResult }; │
1499
- * │ │ │
1500
- * │ injects │ // injected by sentry plugin │
1501
- * ├───────────────────► import "sentry-release-injector"; ─────────────────────┐
1502
- * │ └─────────────────────────────────────────────────┘ │
1503
- * │ │
1504
- * │ │
1505
- * │ entrypoint2.js (user file) │
1506
- * │ ┌─────────────────────────────────────────────────┐ │
1507
- * │ │ export function myFunction() { │ │
1508
- * │ │ return "Hello world!"; │ │
1509
- * │ │ } │ │
1510
- * │ │ │ │
1511
- * │ injects │ // injected by sentry plugin │ │
1512
- * └───────────────────► import "sentry-release-injector"; ─────────────────────┤
1513
- * └─────────────────────────────────────────────────┘ │
1514
- * │
1515
- * │
1516
- * sentry-release-injector │
1517
- * ┌──────────────────────────────────┐ │
1518
- * │ │ is resolved │
1519
- * │ global.SENTRY_RELEASE = { ... } │ by plugin │
1520
- * │ // + a little more logic │<─────────────────────┘
1521
- * │ │ (only once)
1522
- * └──────────────────────────────────┘
1523
- * ```
1487
+ * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
1488
+ * that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
1489
+ * to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
1490
+ * by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
1491
+ * If a user wants to inject the release into a particular set of modules they can use the `releaseInjectionTargets` option.
1524
1492
  *
1525
1493
  * Source maps upload:
1526
1494
  *
@@ -1569,12 +1537,7 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1569
1537
  });
1570
1538
  sentryHub.setUser({
1571
1539
  id: internalOptions.org
1572
- }); // This is `nonEntrypointSet` instead of `entrypointSet` because this set is filled in the `resolveId` hook and there
1573
- // we don't have guaranteed access to *absolute* paths of files if they're entrypoints. For non-entrypoints we're
1574
- // guaranteed to have absolute paths - we're then using the paths in later hooks to make decisions about whether a
1575
- // file is an entrypoint or a non-entrypoint.
1576
-
1577
- var nonEntrypointSet = new Set();
1540
+ });
1578
1541
  var transaction;
1579
1542
  var releaseInjectionSpan;
1580
1543
  return {
@@ -1651,10 +1614,6 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1651
1614
  level: "info"
1652
1615
  });
1653
1616
 
1654
- if (!isEntry) {
1655
- nonEntrypointSet.add(id);
1656
- }
1657
-
1658
1617
  if (id === RELEASE_INJECTOR_ID) {
1659
1618
  return RELEASE_INJECTOR_ID;
1660
1619
  } else {
@@ -1695,7 +1654,7 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1695
1654
 
1696
1655
  /**
1697
1656
  * This hook determines whether we want to transform a module. In the sentry bundler plugin we want to transform every entrypoint
1698
- * unless configured otherwise with the `entries` option.
1657
+ * unless configured otherwise with the `releaseInjectionTargets` option.
1699
1658
  *
1700
1659
  * @param id Always the absolute (fully resolved) path to the module.
1701
1660
  * @returns `true` or `false` depending on whether we want to transform the module. For the sentry bundler plugin we only
@@ -1705,30 +1664,37 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1705
1664
  sentryHub.addBreadcrumb({
1706
1665
  category: "transformInclude",
1707
1666
  level: "info"
1708
- });
1667
+ }); // We don't want to transform our injected code.
1709
1668
 
1710
- if (internalOptions.entries) {
1711
- // If there's an `entries` option transform (ie. inject the release varible) when the file path matches the option.
1712
- if (typeof internalOptions.entries === "function") {
1713
- return internalOptions.entries(id);
1669
+ if (id === RELEASE_INJECTOR_ID) {
1670
+ return false;
1671
+ }
1672
+
1673
+ if (internalOptions.releaseInjectionTargets) {
1674
+ // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
1675
+ if (typeof internalOptions.releaseInjectionTargets === "function") {
1676
+ return internalOptions.releaseInjectionTargets(id);
1714
1677
  }
1715
1678
 
1716
- return internalOptions.entries.some(function (entry) {
1679
+ return internalOptions.releaseInjectionTargets.some(function (entry) {
1717
1680
  if (entry instanceof RegExp) {
1718
1681
  return entry.test(id);
1719
1682
  } else {
1720
1683
  return id === entry;
1721
1684
  }
1722
1685
  });
1723
- } // We want to transform (release injection) every module except for "sentry-release-injector".
1724
-
1725
-
1726
- return id !== RELEASE_INJECTOR_ID && !nonEntrypointSet.has(id);
1686
+ } else {
1687
+ var pathIsOrdinary = !id.includes("?") && !id.includes("#");
1688
+ var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
1689
+ return id.endsWith(allowedFileEnding);
1690
+ });
1691
+ return pathIsOrdinary && pathHasAllowedFileEnding;
1692
+ }
1727
1693
  },
1728
1694
 
1729
1695
  /**
1730
1696
  * This hook is responsible for injecting the "sentry release injector" imoprt statement into each entrypoint unless
1731
- * configured otherwise with the `entries` option (logic for that is in the `transformInclude` hook).
1697
+ * configured otherwise with the `releaseInjectionTargets` option (logic for that is in the `transformInclude` hook).
1732
1698
  *
1733
1699
  * @param code Code of the file to transform.
1734
1700
  * @param id Always the absolute (fully resolved) path to the module.
@@ -1740,11 +1706,10 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1740
1706
  level: "info"
1741
1707
  }); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
1742
1708
 
1743
- var ms = new MagicString(code); // Very stupid author's note: For some absurd reason, when we add a JSDoc to this hook, the TS language server starts complaining about `ms` and adding a type annotation helped so that's why it's here. (┛ಠ_ಠ)┛彡┻━┻
1744
- // appending instead of prepending has less probability of mucking with user'sadly
1745
- // source maps and import statements get to the top anyways
1709
+ var ms = new MagicString(code); // Appending instead of prepending has less probability of mucking with user's source maps.
1710
+ // Luckily import statements get hoisted to the top anyways.
1746
1711
 
1747
- ms.append("import \"".concat(RELEASE_INJECTOR_ID, "\";"));
1712
+ ms.append(";\nimport \"".concat(RELEASE_INJECTOR_ID, "\";"));
1748
1713
 
1749
1714
  if (unpluginMetaContext.framework === "esbuild") {
1750
1715
  // esbuild + unplugin is buggy at the moment when we return an object with a `map` (sourcemap) property.