@sentry/bundler-plugin-core 0.3.0 → 0.4.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/cjs/index.js CHANGED
@@ -775,7 +775,7 @@ function arrayify(maybeArray) {
775
775
 
776
776
  var SENTRY_SAAS_URL = "https://sentry.io";
777
777
  function normalizeUserOptions(userOptions) {
778
- var _userOptions$org, _userOptions$project, _ref, _userOptions$release, _ref2, _userOptions$url, _userOptions$finalize, _userOptions$cleanArt, _userOptions$dryRun, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$injectRe, _ref3, _userOptions$customHe;
778
+ var _userOptions$org, _userOptions$project, _ref, _userOptions$release, _ref2, _userOptions$url, _userOptions$finalize, _userOptions$cleanArt, _userOptions$dryRun, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$injectRe;
779
779
 
780
780
  var options = {
781
781
  // include is the only strictly required option
@@ -810,10 +810,6 @@ function normalizeUserOptions(userOptions) {
810
810
  // the passed options are undefined.
811
811
  authToken: userOptions.authToken,
812
812
  // env var: `SENTRY_AUTH_TOKEN`
813
- // CLI v1 (and the "old" webpack plugin) use `CUSTOM_HEADER`,
814
- // but CLI v2 uses `SENTRY_HEADER` (which is also better aligned with other naming)
815
- // In the spirit of maximum compatibility, we allow both here.
816
- customHeader: (_ref3 = (_userOptions$customHe = userOptions.customHeader) !== null && _userOptions$customHe !== void 0 ? _userOptions$customHe : process.env["SENTRY_HEADER"]) !== null && _ref3 !== void 0 ? _ref3 : process.env["CUSTOM_HEADER"],
817
813
  headers: userOptions.headers,
818
814
  vcsRemote: userOptions.vcsRemote,
819
815
  // env var: `SENTRY_VSC_REMOTE`
@@ -873,12 +869,12 @@ function normalizeInclude(userOptions) {
873
869
 
874
870
 
875
871
  function normalizeIncludeEntry(userOptions, includeEntry) {
876
- var _ref4, _includeEntry$ignore, _ref5, _includeEntry$ext, _includeEntry$ignoreF, _includeEntry$urlPref, _includeEntry$urlSuff, _includeEntry$stripPr, _ref6, _includeEntry$stripCo, _ref7, _includeEntry$sourceM, _ref8, _includeEntry$rewrite, _ref9, _includeEntry$validat;
872
+ var _ref3, _includeEntry$ignore, _ref4, _includeEntry$ext, _includeEntry$ignoreF, _includeEntry$urlPref, _includeEntry$urlSuff, _includeEntry$stripPr, _ref5, _includeEntry$stripCo, _ref6, _includeEntry$sourceM, _ref7, _includeEntry$rewrite, _ref8, _includeEntry$validat;
877
873
 
878
- var ignoreOption = (_ref4 = (_includeEntry$ignore = includeEntry.ignore) !== null && _includeEntry$ignore !== void 0 ? _includeEntry$ignore : userOptions.ignore) !== null && _ref4 !== void 0 ? _ref4 : ["node_modules"];
874
+ var ignoreOption = (_ref3 = (_includeEntry$ignore = includeEntry.ignore) !== null && _includeEntry$ignore !== void 0 ? _includeEntry$ignore : userOptions.ignore) !== null && _ref3 !== void 0 ? _ref3 : ["node_modules"];
879
875
  var ignore = Array.isArray(ignoreOption) ? ignoreOption : [ignoreOption]; // We're prefixing all entries in the `ext` option with a `.` (if it isn't already) to align with Node.js' `path.extname()`
880
876
 
881
- var ext = (_ref5 = (_includeEntry$ext = includeEntry.ext) !== null && _includeEntry$ext !== void 0 ? _includeEntry$ext : userOptions.ext) !== null && _ref5 !== void 0 ? _ref5 : ["js", "map", "jsbundle", "bundle"];
877
+ var ext = (_ref4 = (_includeEntry$ext = includeEntry.ext) !== null && _includeEntry$ext !== void 0 ? _includeEntry$ext : userOptions.ext) !== null && _ref4 !== void 0 ? _ref4 : ["js", "map", "jsbundle", "bundle"];
882
878
  var dotPrefixedExt = ext.map(function (extension) {
883
879
  return ".".concat(extension.replace(/^\./, ""));
884
880
  });
@@ -890,10 +886,10 @@ function normalizeIncludeEntry(userOptions, includeEntry) {
890
886
  urlPrefix: (_includeEntry$urlPref = includeEntry.urlPrefix) !== null && _includeEntry$urlPref !== void 0 ? _includeEntry$urlPref : userOptions.urlPrefix,
891
887
  urlSuffix: (_includeEntry$urlSuff = includeEntry.urlSuffix) !== null && _includeEntry$urlSuff !== void 0 ? _includeEntry$urlSuff : userOptions.urlSuffix,
892
888
  stripPrefix: (_includeEntry$stripPr = includeEntry.stripPrefix) !== null && _includeEntry$stripPr !== void 0 ? _includeEntry$stripPr : userOptions.stripPrefix,
893
- stripCommonPrefix: (_ref6 = (_includeEntry$stripCo = includeEntry.stripCommonPrefix) !== null && _includeEntry$stripCo !== void 0 ? _includeEntry$stripCo : userOptions.stripCommonPrefix) !== null && _ref6 !== void 0 ? _ref6 : false,
894
- sourceMapReference: (_ref7 = (_includeEntry$sourceM = includeEntry.sourceMapReference) !== null && _includeEntry$sourceM !== void 0 ? _includeEntry$sourceM : userOptions.sourceMapReference) !== null && _ref7 !== void 0 ? _ref7 : true,
895
- rewrite: (_ref8 = (_includeEntry$rewrite = includeEntry.rewrite) !== null && _includeEntry$rewrite !== void 0 ? _includeEntry$rewrite : userOptions.rewrite) !== null && _ref8 !== void 0 ? _ref8 : true,
896
- validate: (_ref9 = (_includeEntry$validat = includeEntry.validate) !== null && _includeEntry$validat !== void 0 ? _includeEntry$validat : userOptions.validate) !== null && _ref9 !== void 0 ? _ref9 : false
889
+ stripCommonPrefix: (_ref5 = (_includeEntry$stripCo = includeEntry.stripCommonPrefix) !== null && _includeEntry$stripCo !== void 0 ? _includeEntry$stripCo : userOptions.stripCommonPrefix) !== null && _ref5 !== void 0 ? _ref5 : false,
890
+ sourceMapReference: (_ref6 = (_includeEntry$sourceM = includeEntry.sourceMapReference) !== null && _includeEntry$sourceM !== void 0 ? _includeEntry$sourceM : userOptions.sourceMapReference) !== null && _ref6 !== void 0 ? _ref6 : true,
891
+ rewrite: (_ref7 = (_includeEntry$rewrite = includeEntry.rewrite) !== null && _includeEntry$rewrite !== void 0 ? _includeEntry$rewrite : userOptions.rewrite) !== null && _ref7 !== void 0 ? _ref7 : true,
892
+ validate: (_ref8 = (_includeEntry$validat = includeEntry.validate) !== null && _includeEntry$validat !== void 0 ? _includeEntry$validat : userOptions.validate) !== null && _ref8 !== void 0 ? _ref8 : false
897
893
  };
898
894
  }
899
895
  /**
@@ -947,7 +943,7 @@ function makeSentryClient(dsn, allowedToSendTelemetryPromise, userProject) {
947
943
  // a dashboard.
948
944
  // Yes, this is slightly abusing the purpose of this field.
949
945
  dist: userProject,
950
- release: "0.3.0",
946
+ release: "0.4.0",
951
947
  integrations: [],
952
948
  tracePropagationTargets: ["sentry.io/api"],
953
949
  stackParser: node.defaultStackParser,
@@ -1099,12 +1095,12 @@ function _shouldSendTelemetry() {
1099
1095
  _shouldSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
1100
1096
  var _cliInfo$split$, _cliInfo$split$$repla;
1101
1097
 
1102
- var silent, org, project, authToken, url, vcsRemote, customHeader, headers, telemetry, dryRun, cli, cliInfo, cliInfoUrl;
1098
+ var silent, org, project, authToken, url, vcsRemote, headers, telemetry, dryRun, cli, cliInfo, cliInfoUrl;
1103
1099
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1104
1100
  while (1) {
1105
1101
  switch (_context2.prev = _context2.next) {
1106
1102
  case 0:
1107
- silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, vcsRemote = options.vcsRemote, customHeader = options.customHeader, headers = options.headers, telemetry = options.telemetry, dryRun = options.dryRun; // `options.telemetry` defaults to true
1103
+ silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, vcsRemote = options.vcsRemote, headers = options.headers, telemetry = options.telemetry, dryRun = options.dryRun; // `options.telemetry` defaults to true
1108
1104
 
1109
1105
  if (!(telemetry === false)) {
1110
1106
  _context2.next = 3;
@@ -1137,7 +1133,6 @@ function _shouldSendTelemetry() {
1137
1133
  project: project,
1138
1134
  vcsRemote: vcsRemote,
1139
1135
  silent: silent,
1140
- customHeader: customHeader,
1141
1136
  headers: headers
1142
1137
  });
1143
1138
  _context2.prev = 8;
@@ -1595,7 +1590,6 @@ function getSentryCli(internalOptions, logger) {
1595
1590
  authToken = internalOptions.authToken,
1596
1591
  url = internalOptions.url,
1597
1592
  vcsRemote = internalOptions.vcsRemote,
1598
- customHeader = internalOptions.customHeader,
1599
1593
  headers = internalOptions.headers;
1600
1594
  var cli = new SentryCli__default["default"](internalOptions.configFile, {
1601
1595
  url: url,
@@ -1604,7 +1598,6 @@ function getSentryCli(internalOptions, logger) {
1604
1598
  project: project,
1605
1599
  vcsRemote: vcsRemote,
1606
1600
  silent: silent,
1607
- customHeader: customHeader,
1608
1601
  headers: headers
1609
1602
  });
1610
1603
 
@@ -1657,10 +1650,6 @@ function getDryRunCLI(cli, logger) {
1657
1650
  };
1658
1651
  }
1659
1652
 
1660
- // This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
1661
- // This probably doesn't work for all bundlers but for rollup it does.
1662
-
1663
- var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
1664
1653
  var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"];
1665
1654
  /**
1666
1655
  * The sentry bundler plugin concerns itself with two things:
@@ -1668,17 +1657,17 @@ var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"]
1668
1657
  * - Sourcemaps upload
1669
1658
  *
1670
1659
  * Release injection:
1671
- *
1672
- * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
1673
- * that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
1674
- * to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
1675
- * by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
1676
- * If a user wants to inject the release into a particular set of modules they can use the `releaseInjectionTargets` option.
1660
+ * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into
1661
+ * each JavaScript/TypeScript entrypoint. On a technical level this is done by identifying
1662
+ * entrypoints in the `resolveId` hook and prepending user code in the `transform` hook.
1663
+ * If a user wants to inject the release into a particular set of modules instead,
1664
+ * they can use the `releaseInjectionTargets` option.
1677
1665
  *
1678
1666
  * Source maps upload:
1679
1667
  *
1680
- * The sentry bundler plugin will also take care of uploading source maps to Sentry. This is all done in the
1681
- * `writeBundle` hook. In this hook the sentry plugin will execute the release creation pipeline:
1668
+ * The sentry bundler plugin will also take care of uploading source maps to Sentry. This
1669
+ * is all done in the `writeBundle` hook. In this hook the sentry plugin will execute the
1670
+ * release creation pipeline:
1682
1671
  *
1683
1672
  * 1. Create a new release
1684
1673
  * 2. Delete already uploaded artifacts for this release (if `cleanArtifacts` is enabled)
@@ -1725,6 +1714,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1725
1714
  });
1726
1715
  var transaction;
1727
1716
  var releaseInjectionSpan;
1717
+ var absolueEntrypointPaths = new Set();
1728
1718
  return {
1729
1719
  name: "sentry-plugin",
1730
1720
  enforce: "pre",
@@ -1811,68 +1801,11 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1811
1801
  isEntry: isEntry
1812
1802
  });
1813
1803
 
1814
- if (id === RELEASE_INJECTOR_ID) {
1815
- return RELEASE_INJECTOR_ID;
1816
- } else {
1817
- return undefined;
1804
+ if (isEntry) {
1805
+ absolueEntrypointPaths.add(path__default["default"].resolve(path__default["default"].normalize(id)));
1818
1806
  }
1819
- },
1820
- loadInclude: function loadInclude(id) {
1821
- logger.debug('Called "loadInclude":', {
1822
- id: id
1823
- });
1824
- return id === RELEASE_INJECTOR_ID;
1825
- },
1826
1807
 
1827
- /**
1828
- * Responsible for "virtually" loading the "sentry-release-injector" module. "Virtual" means that the module is not
1829
- * read from somewhere on disk but rather just returned via a string.
1830
- *
1831
- * @param id Always the absolute (fully resolved) path to the module.
1832
- * @returns The global injector code when we load the "sentry-release-injector" module. Otherwise returns `undefined`.
1833
- */
1834
- load: function load(id) {
1835
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1836
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1837
- while (1) {
1838
- switch (_context2.prev = _context2.next) {
1839
- case 0:
1840
- logger.debug('Called "load":', {
1841
- id: id
1842
- });
1843
-
1844
- if (!(id === RELEASE_INJECTOR_ID)) {
1845
- _context2.next = 13;
1846
- break;
1847
- }
1848
-
1849
- _context2.t0 = generateGlobalInjectorCode;
1850
- _context2.next = 5;
1851
- return releaseNamePromise;
1852
-
1853
- case 5:
1854
- _context2.t1 = _context2.sent;
1855
- _context2.t2 = internalOptions.injectReleasesMap;
1856
- _context2.t3 = internalOptions.org;
1857
- _context2.t4 = internalOptions.project;
1858
- _context2.t5 = {
1859
- release: _context2.t1,
1860
- injectReleasesMap: _context2.t2,
1861
- org: _context2.t3,
1862
- project: _context2.t4
1863
- };
1864
- return _context2.abrupt("return", (0, _context2.t0)(_context2.t5));
1865
-
1866
- case 13:
1867
- return _context2.abrupt("return", undefined);
1868
-
1869
- case 14:
1870
- case "end":
1871
- return _context2.stop();
1872
- }
1873
- }
1874
- }, _callee2);
1875
- }))();
1808
+ return undefined;
1876
1809
  },
1877
1810
 
1878
1811
  /**
@@ -1889,11 +1822,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1889
1822
  }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
1890
1823
  // a windows style path to `releaseInjectionTargets`
1891
1824
 
1892
- var normalizedId = path__default["default"].normalize(id); // We don't want to transform our injected code.
1893
-
1894
- if (normalizedId === RELEASE_INJECTOR_ID) {
1895
- return false;
1896
- }
1825
+ var normalizedId = path__default["default"].normalize(id);
1897
1826
 
1898
1827
  if (internalOptions.releaseInjectionTargets) {
1899
1828
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
@@ -1909,13 +1838,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1909
1838
  return normalizedId === normalizedEntry;
1910
1839
  }
1911
1840
  });
1912
- } else {
1913
- var isInNodeModules = normalizedId.split(path__default["default"].sep).includes("node_modules");
1841
+ } else if (absolueEntrypointPaths.has(normalizedId)) {
1914
1842
  var pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#");
1915
1843
  var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
1916
1844
  return normalizedId.endsWith(allowedFileEnding);
1917
1845
  });
1918
- return !isInNodeModules && pathIsOrdinary && pathHasAllowedFileEnding;
1846
+ return pathIsOrdinary && pathHasAllowedFileEnding;
1847
+ } else {
1848
+ return false;
1919
1849
  }
1920
1850
  },
1921
1851
 
@@ -1928,26 +1858,57 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1928
1858
  * @returns transformed code + source map
1929
1859
  */
1930
1860
  transform: function transform(code, id) {
1931
- logger.debug('Called "transform":', {
1932
- id: id
1933
- }); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
1861
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1862
+ var ms;
1863
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1864
+ while (1) {
1865
+ switch (_context2.prev = _context2.next) {
1866
+ case 0:
1867
+ logger.debug('Called "transform":', {
1868
+ id: id
1869
+ }); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
1934
1870
 
1935
- var ms = new MagicString__default["default"](code); // Appending instead of prepending has less probability of mucking with user's source maps.
1936
- // Luckily import statements get hoisted to the top anyways.
1871
+ ms = new MagicString__default["default"](code);
1872
+ _context2.t0 = ms;
1873
+ _context2.t1 = generateGlobalInjectorCode;
1874
+ _context2.next = 6;
1875
+ return releaseNamePromise;
1937
1876
 
1938
- ms.append(";\nimport \"".concat(RELEASE_INJECTOR_ID, "\";"));
1877
+ case 6:
1878
+ _context2.t2 = _context2.sent;
1879
+ _context2.t3 = internalOptions.injectReleasesMap;
1880
+ _context2.t4 = internalOptions.org;
1881
+ _context2.t5 = internalOptions.project;
1882
+ _context2.t6 = {
1883
+ release: _context2.t2,
1884
+ injectReleasesMap: _context2.t3,
1885
+ org: _context2.t4,
1886
+ project: _context2.t5
1887
+ };
1888
+ _context2.t7 = (0, _context2.t1)(_context2.t6);
1939
1889
 
1940
- if (unpluginMetaContext.framework === "esbuild") {
1941
- // esbuild + unplugin is buggy at the moment when we return an object with a `map` (sourcemap) property.
1942
- // Currently just returning a string here seems to work and even correctly sourcemaps the code we generate.
1943
- // However, other bundlers need the `map` property
1944
- return ms.toString();
1945
- } else {
1946
- return {
1947
- code: ms.toString(),
1948
- map: ms.generateMap()
1949
- };
1950
- }
1890
+ _context2.t0.prepend.call(_context2.t0, _context2.t7);
1891
+
1892
+ if (!(unpluginMetaContext.framework === "esbuild")) {
1893
+ _context2.next = 17;
1894
+ break;
1895
+ }
1896
+
1897
+ return _context2.abrupt("return", ms.toString());
1898
+
1899
+ case 17:
1900
+ return _context2.abrupt("return", {
1901
+ code: ms.toString(),
1902
+ map: ms.generateMap()
1903
+ });
1904
+
1905
+ case 18:
1906
+ case "end":
1907
+ return _context2.stop();
1908
+ }
1909
+ }
1910
+ }, _callee2);
1911
+ }))();
1951
1912
  },
1952
1913
 
1953
1914
  /**
@@ -2089,7 +2050,7 @@ function generateGlobalInjectorCode(_ref2) {
2089
2050
 
2090
2051
  if (injectReleasesMap && project) {
2091
2052
  var key = org ? "".concat(project, "@").concat(org) : project;
2092
- code += "\n _global.SENTRY_RELEASES=_global.SENTRY_RELEASES || {};\n _global.SENTRY_RELEASES[\"".concat(key, "\"]={id:\"").concat(release, "\"};\n ");
2053
+ code += "\n _global.SENTRY_RELEASES=_global.SENTRY_RELEASES || {};\n _global.SENTRY_RELEASES[\"".concat(key, "\"]={id:\"").concat(release, "\"};");
2093
2054
  }
2094
2055
 
2095
2056
  return code;