@sentry/bundler-plugin-core 0.2.4 → 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,7 @@ 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"],
813
+ headers: userOptions.headers,
817
814
  vcsRemote: userOptions.vcsRemote,
818
815
  // env var: `SENTRY_VSC_REMOTE`
819
816
  // Optional options
@@ -872,12 +869,12 @@ function normalizeInclude(userOptions) {
872
869
 
873
870
 
874
871
  function normalizeIncludeEntry(userOptions, includeEntry) {
875
- 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;
876
873
 
877
- 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"];
878
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()`
879
876
 
880
- 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"];
881
878
  var dotPrefixedExt = ext.map(function (extension) {
882
879
  return ".".concat(extension.replace(/^\./, ""));
883
880
  });
@@ -889,10 +886,10 @@ function normalizeIncludeEntry(userOptions, includeEntry) {
889
886
  urlPrefix: (_includeEntry$urlPref = includeEntry.urlPrefix) !== null && _includeEntry$urlPref !== void 0 ? _includeEntry$urlPref : userOptions.urlPrefix,
890
887
  urlSuffix: (_includeEntry$urlSuff = includeEntry.urlSuffix) !== null && _includeEntry$urlSuff !== void 0 ? _includeEntry$urlSuff : userOptions.urlSuffix,
891
888
  stripPrefix: (_includeEntry$stripPr = includeEntry.stripPrefix) !== null && _includeEntry$stripPr !== void 0 ? _includeEntry$stripPr : userOptions.stripPrefix,
892
- stripCommonPrefix: (_ref6 = (_includeEntry$stripCo = includeEntry.stripCommonPrefix) !== null && _includeEntry$stripCo !== void 0 ? _includeEntry$stripCo : userOptions.stripCommonPrefix) !== null && _ref6 !== void 0 ? _ref6 : false,
893
- sourceMapReference: (_ref7 = (_includeEntry$sourceM = includeEntry.sourceMapReference) !== null && _includeEntry$sourceM !== void 0 ? _includeEntry$sourceM : userOptions.sourceMapReference) !== null && _ref7 !== void 0 ? _ref7 : true,
894
- rewrite: (_ref8 = (_includeEntry$rewrite = includeEntry.rewrite) !== null && _includeEntry$rewrite !== void 0 ? _includeEntry$rewrite : userOptions.rewrite) !== null && _ref8 !== void 0 ? _ref8 : true,
895
- 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
896
893
  };
897
894
  }
898
895
  /**
@@ -946,7 +943,7 @@ function makeSentryClient(dsn, allowedToSendTelemetryPromise, userProject) {
946
943
  // a dashboard.
947
944
  // Yes, this is slightly abusing the purpose of this field.
948
945
  dist: userProject,
949
- release: "0.2.4",
946
+ release: "0.4.0",
950
947
  integrations: [],
951
948
  tracePropagationTargets: ["sentry.io/api"],
952
949
  stackParser: node.defaultStackParser,
@@ -1098,12 +1095,12 @@ function _shouldSendTelemetry() {
1098
1095
  _shouldSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
1099
1096
  var _cliInfo$split$, _cliInfo$split$$repla;
1100
1097
 
1101
- var silent, org, project, authToken, url, vcsRemote, customHeader, dist, telemetry, dryRun, cli, cliInfo, cliInfoUrl;
1098
+ var silent, org, project, authToken, url, vcsRemote, headers, telemetry, dryRun, cli, cliInfo, cliInfoUrl;
1102
1099
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1103
1100
  while (1) {
1104
1101
  switch (_context2.prev = _context2.next) {
1105
1102
  case 0:
1106
- silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, vcsRemote = options.vcsRemote, customHeader = options.customHeader, dist = options.dist, 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
1107
1104
 
1108
1105
  if (!(telemetry === false)) {
1109
1106
  _context2.next = 3;
@@ -1135,9 +1132,8 @@ function _shouldSendTelemetry() {
1135
1132
  org: org,
1136
1133
  project: project,
1137
1134
  vcsRemote: vcsRemote,
1138
- dist: dist,
1139
1135
  silent: silent,
1140
- customHeader: customHeader
1136
+ headers: headers
1141
1137
  });
1142
1138
  _context2.prev = 8;
1143
1139
  _context2.next = 11;
@@ -1299,7 +1295,8 @@ function _uploadSourceMaps() {
1299
1295
  _context3.prev = 2;
1300
1296
  _context3.next = 5;
1301
1297
  return ctx.cli.releases.uploadSourceMaps(releaseName, {
1302
- include: options.include
1298
+ include: options.include,
1299
+ dist: options.dist
1303
1300
  });
1304
1301
 
1305
1302
  case 5:
@@ -1593,17 +1590,15 @@ function getSentryCli(internalOptions, logger) {
1593
1590
  authToken = internalOptions.authToken,
1594
1591
  url = internalOptions.url,
1595
1592
  vcsRemote = internalOptions.vcsRemote,
1596
- customHeader = internalOptions.customHeader,
1597
- dist = internalOptions.dist;
1593
+ headers = internalOptions.headers;
1598
1594
  var cli = new SentryCli__default["default"](internalOptions.configFile, {
1599
1595
  url: url,
1600
1596
  authToken: authToken,
1601
1597
  org: org,
1602
1598
  project: project,
1603
1599
  vcsRemote: vcsRemote,
1604
- dist: dist,
1605
1600
  silent: silent,
1606
- customHeader: customHeader
1601
+ headers: headers
1607
1602
  });
1608
1603
 
1609
1604
  if (internalOptions.dryRun) {
@@ -1655,10 +1650,6 @@ function getDryRunCLI(cli, logger) {
1655
1650
  };
1656
1651
  }
1657
1652
 
1658
- // This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
1659
- // This probably doesn't work for all bundlers but for rollup it does.
1660
-
1661
- var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
1662
1653
  var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"];
1663
1654
  /**
1664
1655
  * The sentry bundler plugin concerns itself with two things:
@@ -1666,17 +1657,17 @@ var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"]
1666
1657
  * - Sourcemaps upload
1667
1658
  *
1668
1659
  * Release injection:
1669
- *
1670
- * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
1671
- * that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
1672
- * to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
1673
- * by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
1674
- * 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.
1675
1665
  *
1676
1666
  * Source maps upload:
1677
1667
  *
1678
- * The sentry bundler plugin will also take care of uploading source maps to Sentry. This is all done in the
1679
- * `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:
1680
1671
  *
1681
1672
  * 1. Create a new release
1682
1673
  * 2. Delete already uploaded artifacts for this release (if `cleanArtifacts` is enabled)
@@ -1723,6 +1714,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1723
1714
  });
1724
1715
  var transaction;
1725
1716
  var releaseInjectionSpan;
1717
+ var absolueEntrypointPaths = new Set();
1726
1718
  return {
1727
1719
  name: "sentry-plugin",
1728
1720
  enforce: "pre",
@@ -1809,68 +1801,11 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1809
1801
  isEntry: isEntry
1810
1802
  });
1811
1803
 
1812
- if (id === RELEASE_INJECTOR_ID) {
1813
- return RELEASE_INJECTOR_ID;
1814
- } else {
1815
- return undefined;
1804
+ if (isEntry) {
1805
+ absolueEntrypointPaths.add(path__default["default"].resolve(path__default["default"].normalize(id)));
1816
1806
  }
1817
- },
1818
- loadInclude: function loadInclude(id) {
1819
- logger.debug('Called "loadInclude":', {
1820
- id: id
1821
- });
1822
- return id === RELEASE_INJECTOR_ID;
1823
- },
1824
1807
 
1825
- /**
1826
- * Responsible for "virtually" loading the "sentry-release-injector" module. "Virtual" means that the module is not
1827
- * read from somewhere on disk but rather just returned via a string.
1828
- *
1829
- * @param id Always the absolute (fully resolved) path to the module.
1830
- * @returns The global injector code when we load the "sentry-release-injector" module. Otherwise returns `undefined`.
1831
- */
1832
- load: function load(id) {
1833
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1834
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1835
- while (1) {
1836
- switch (_context2.prev = _context2.next) {
1837
- case 0:
1838
- logger.debug('Called "load":', {
1839
- id: id
1840
- });
1841
-
1842
- if (!(id === RELEASE_INJECTOR_ID)) {
1843
- _context2.next = 13;
1844
- break;
1845
- }
1846
-
1847
- _context2.t0 = generateGlobalInjectorCode;
1848
- _context2.next = 5;
1849
- return releaseNamePromise;
1850
-
1851
- case 5:
1852
- _context2.t1 = _context2.sent;
1853
- _context2.t2 = internalOptions.injectReleasesMap;
1854
- _context2.t3 = internalOptions.org;
1855
- _context2.t4 = internalOptions.project;
1856
- _context2.t5 = {
1857
- release: _context2.t1,
1858
- injectReleasesMap: _context2.t2,
1859
- org: _context2.t3,
1860
- project: _context2.t4
1861
- };
1862
- return _context2.abrupt("return", (0, _context2.t0)(_context2.t5));
1863
-
1864
- case 13:
1865
- return _context2.abrupt("return", undefined);
1866
-
1867
- case 14:
1868
- case "end":
1869
- return _context2.stop();
1870
- }
1871
- }
1872
- }, _callee2);
1873
- }))();
1808
+ return undefined;
1874
1809
  },
1875
1810
 
1876
1811
  /**
@@ -1887,11 +1822,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1887
1822
  }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
1888
1823
  // a windows style path to `releaseInjectionTargets`
1889
1824
 
1890
- var normalizedId = path__default["default"].normalize(id); // We don't want to transform our injected code.
1891
-
1892
- if (normalizedId === RELEASE_INJECTOR_ID) {
1893
- return false;
1894
- }
1825
+ var normalizedId = path__default["default"].normalize(id);
1895
1826
 
1896
1827
  if (internalOptions.releaseInjectionTargets) {
1897
1828
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
@@ -1907,13 +1838,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1907
1838
  return normalizedId === normalizedEntry;
1908
1839
  }
1909
1840
  });
1910
- } else {
1911
- var isInNodeModules = normalizedId.split(path__default["default"].sep).includes("node_modules");
1841
+ } else if (absolueEntrypointPaths.has(normalizedId)) {
1912
1842
  var pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#");
1913
1843
  var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
1914
1844
  return normalizedId.endsWith(allowedFileEnding);
1915
1845
  });
1916
- return !isInNodeModules && pathIsOrdinary && pathHasAllowedFileEnding;
1846
+ return pathIsOrdinary && pathHasAllowedFileEnding;
1847
+ } else {
1848
+ return false;
1917
1849
  }
1918
1850
  },
1919
1851
 
@@ -1926,26 +1858,57 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1926
1858
  * @returns transformed code + source map
1927
1859
  */
1928
1860
  transform: function transform(code, id) {
1929
- logger.debug('Called "transform":', {
1930
- id: id
1931
- }); // 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.
1932
1870
 
1933
- var ms = new MagicString__default["default"](code); // Appending instead of prepending has less probability of mucking with user's source maps.
1934
- // 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;
1935
1876
 
1936
- 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);
1937
1889
 
1938
- if (unpluginMetaContext.framework === "esbuild") {
1939
- // esbuild + unplugin is buggy at the moment when we return an object with a `map` (sourcemap) property.
1940
- // Currently just returning a string here seems to work and even correctly sourcemaps the code we generate.
1941
- // However, other bundlers need the `map` property
1942
- return ms.toString();
1943
- } else {
1944
- return {
1945
- code: ms.toString(),
1946
- map: ms.generateMap()
1947
- };
1948
- }
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
+ }))();
1949
1912
  },
1950
1913
 
1951
1914
  /**
@@ -2087,7 +2050,7 @@ function generateGlobalInjectorCode(_ref2) {
2087
2050
 
2088
2051
  if (injectReleasesMap && project) {
2089
2052
  var key = org ? "".concat(project, "@").concat(org) : project;
2090
- 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, "\"};");
2091
2054
  }
2092
2055
 
2093
2056
  return code;