@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/cjs/index.js +38 -73
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +38 -73
- package/dist/esm/index.js.map +1 -1
- package/dist/types/options-mapping.d.ts +1 -1
- package/dist/types/types.d.ts +10 -7
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -827,7 +827,7 @@ function normalizeUserOptions(userOptions) {
|
|
|
827
827
|
// Optional options
|
|
828
828
|
setCommits: userOptions.setCommits,
|
|
829
829
|
deploy: userOptions.deploy,
|
|
830
|
-
|
|
830
|
+
releaseInjectionTargets: normalizeReleaseInjectionTargets(userOptions.releaseInjectionTargets),
|
|
831
831
|
dist: userOptions.dist,
|
|
832
832
|
errorHandler: userOptions.errorHandler,
|
|
833
833
|
configFile: userOptions.configFile
|
|
@@ -840,16 +840,17 @@ function normalizeUserOptions(userOptions) {
|
|
|
840
840
|
return options;
|
|
841
841
|
}
|
|
842
842
|
/**
|
|
843
|
-
* Converts the user-facing `
|
|
843
|
+
* Converts the user-facing `releaseInjectionTargets` option to the internal
|
|
844
|
+
* `releaseInjectionTargets` option
|
|
844
845
|
*/
|
|
845
846
|
|
|
846
|
-
function
|
|
847
|
-
if (
|
|
847
|
+
function normalizeReleaseInjectionTargets(userReleaseInjectionTargets) {
|
|
848
|
+
if (userReleaseInjectionTargets === undefined) {
|
|
848
849
|
return undefined;
|
|
849
|
-
} else if (typeof
|
|
850
|
-
return
|
|
850
|
+
} else if (typeof userReleaseInjectionTargets === "function") {
|
|
851
|
+
return userReleaseInjectionTargets;
|
|
851
852
|
} else {
|
|
852
|
-
return arrayify(
|
|
853
|
+
return arrayify(userReleaseInjectionTargets);
|
|
853
854
|
}
|
|
854
855
|
}
|
|
855
856
|
/**
|
|
@@ -954,7 +955,7 @@ function makeSentryClient(dsn, telemetryEnabled) {
|
|
|
954
955
|
enabled: telemetryEnabled,
|
|
955
956
|
tracesSampleRate: telemetryEnabled ? 1.0 : 0.0,
|
|
956
957
|
sampleRate: telemetryEnabled ? 1.0 : 0.0,
|
|
957
|
-
release: "0.
|
|
958
|
+
release: "0.2.0",
|
|
958
959
|
integrations: [new node.Integrations.Http({
|
|
959
960
|
tracing: true
|
|
960
961
|
})],
|
|
@@ -1484,6 +1485,7 @@ function getDryRunCLI(cli, logger) {
|
|
|
1484
1485
|
// This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
|
|
1485
1486
|
// This probably doesn't work for all bundlers but for rollup it does.
|
|
1486
1487
|
var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
|
|
1488
|
+
var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs"];
|
|
1487
1489
|
/**
|
|
1488
1490
|
* The sentry bundler plugin concerns itself with two things:
|
|
1489
1491
|
* - Release injection
|
|
@@ -1491,45 +1493,11 @@ var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
|
|
|
1491
1493
|
*
|
|
1492
1494
|
* Release injection:
|
|
1493
1495
|
*
|
|
1494
|
-
* Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE`
|
|
1495
|
-
* On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
|
|
1496
|
-
* of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
|
|
1497
|
-
* to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
|
|
1498
|
-
*
|
|
1499
|
-
* The resulting output approximately looks like this:
|
|
1500
|
-
*
|
|
1501
|
-
* ```text
|
|
1502
|
-
* entrypoint1.js (user file)
|
|
1503
|
-
* ┌─────────────────────────┐ ┌─────────────────────────────────────────────────┐
|
|
1504
|
-
* │ │ │ import { myFunction } from "./my-library.js"; │
|
|
1505
|
-
* │ sentry-bundler-plugin │ │ │
|
|
1506
|
-
* │ │ │ const myResult = myFunction(); │
|
|
1507
|
-
* └---------│--------------- │ export { myResult }; │
|
|
1508
|
-
* │ │ │
|
|
1509
|
-
* │ injects │ // injected by sentry plugin │
|
|
1510
|
-
* ├───────────────────► import "sentry-release-injector"; ─────────────────────┐
|
|
1511
|
-
* │ └─────────────────────────────────────────────────┘ │
|
|
1512
|
-
* │ │
|
|
1513
|
-
* │ │
|
|
1514
|
-
* │ entrypoint2.js (user file) │
|
|
1515
|
-
* │ ┌─────────────────────────────────────────────────┐ │
|
|
1516
|
-
* │ │ export function myFunction() { │ │
|
|
1517
|
-
* │ │ return "Hello world!"; │ │
|
|
1518
|
-
* │ │ } │ │
|
|
1519
|
-
* │ │ │ │
|
|
1520
|
-
* │ injects │ // injected by sentry plugin │ │
|
|
1521
|
-
* └───────────────────► import "sentry-release-injector"; ─────────────────────┤
|
|
1522
|
-
* └─────────────────────────────────────────────────┘ │
|
|
1523
|
-
* │
|
|
1524
|
-
* │
|
|
1525
|
-
* sentry-release-injector │
|
|
1526
|
-
* ┌──────────────────────────────────┐ │
|
|
1527
|
-
* │ │ is resolved │
|
|
1528
|
-
* │ global.SENTRY_RELEASE = { ... } │ by plugin │
|
|
1529
|
-
* │ // + a little more logic │<─────────────────────┘
|
|
1530
|
-
* │ │ (only once)
|
|
1531
|
-
* └──────────────────────────────────┘
|
|
1532
|
-
* ```
|
|
1496
|
+
* Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
|
|
1497
|
+
* that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
|
|
1498
|
+
* to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
|
|
1499
|
+
* by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
|
|
1500
|
+
* If a user wants to inject the release into a particular set of modules they can use the `releaseInjectionTargets` option.
|
|
1533
1501
|
*
|
|
1534
1502
|
* Source maps upload:
|
|
1535
1503
|
*
|
|
@@ -1578,12 +1546,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
|
|
|
1578
1546
|
});
|
|
1579
1547
|
sentryHub.setUser({
|
|
1580
1548
|
id: internalOptions.org
|
|
1581
|
-
});
|
|
1582
|
-
// we don't have guaranteed access to *absolute* paths of files if they're entrypoints. For non-entrypoints we're
|
|
1583
|
-
// guaranteed to have absolute paths - we're then using the paths in later hooks to make decisions about whether a
|
|
1584
|
-
// file is an entrypoint or a non-entrypoint.
|
|
1585
|
-
|
|
1586
|
-
var nonEntrypointSet = new Set();
|
|
1549
|
+
});
|
|
1587
1550
|
var transaction;
|
|
1588
1551
|
var releaseInjectionSpan;
|
|
1589
1552
|
return {
|
|
@@ -1660,10 +1623,6 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
|
|
|
1660
1623
|
level: "info"
|
|
1661
1624
|
});
|
|
1662
1625
|
|
|
1663
|
-
if (!isEntry) {
|
|
1664
|
-
nonEntrypointSet.add(id);
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
1626
|
if (id === RELEASE_INJECTOR_ID) {
|
|
1668
1627
|
return RELEASE_INJECTOR_ID;
|
|
1669
1628
|
} else {
|
|
@@ -1704,7 +1663,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
|
|
|
1704
1663
|
|
|
1705
1664
|
/**
|
|
1706
1665
|
* This hook determines whether we want to transform a module. In the sentry bundler plugin we want to transform every entrypoint
|
|
1707
|
-
* unless configured otherwise with the `
|
|
1666
|
+
* unless configured otherwise with the `releaseInjectionTargets` option.
|
|
1708
1667
|
*
|
|
1709
1668
|
* @param id Always the absolute (fully resolved) path to the module.
|
|
1710
1669
|
* @returns `true` or `false` depending on whether we want to transform the module. For the sentry bundler plugin we only
|
|
@@ -1714,30 +1673,37 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
|
|
|
1714
1673
|
sentryHub.addBreadcrumb({
|
|
1715
1674
|
category: "transformInclude",
|
|
1716
1675
|
level: "info"
|
|
1717
|
-
});
|
|
1676
|
+
}); // We don't want to transform our injected code.
|
|
1718
1677
|
|
|
1719
|
-
if (
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1678
|
+
if (id === RELEASE_INJECTOR_ID) {
|
|
1679
|
+
return false;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
if (internalOptions.releaseInjectionTargets) {
|
|
1683
|
+
// If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
|
|
1684
|
+
if (typeof internalOptions.releaseInjectionTargets === "function") {
|
|
1685
|
+
return internalOptions.releaseInjectionTargets(id);
|
|
1723
1686
|
}
|
|
1724
1687
|
|
|
1725
|
-
return internalOptions.
|
|
1688
|
+
return internalOptions.releaseInjectionTargets.some(function (entry) {
|
|
1726
1689
|
if (entry instanceof RegExp) {
|
|
1727
1690
|
return entry.test(id);
|
|
1728
1691
|
} else {
|
|
1729
1692
|
return id === entry;
|
|
1730
1693
|
}
|
|
1731
1694
|
});
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1695
|
+
} else {
|
|
1696
|
+
var pathIsOrdinary = !id.includes("?") && !id.includes("#");
|
|
1697
|
+
var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
|
|
1698
|
+
return id.endsWith(allowedFileEnding);
|
|
1699
|
+
});
|
|
1700
|
+
return pathIsOrdinary && pathHasAllowedFileEnding;
|
|
1701
|
+
}
|
|
1736
1702
|
},
|
|
1737
1703
|
|
|
1738
1704
|
/**
|
|
1739
1705
|
* This hook is responsible for injecting the "sentry release injector" imoprt statement into each entrypoint unless
|
|
1740
|
-
* configured otherwise with the `
|
|
1706
|
+
* configured otherwise with the `releaseInjectionTargets` option (logic for that is in the `transformInclude` hook).
|
|
1741
1707
|
*
|
|
1742
1708
|
* @param code Code of the file to transform.
|
|
1743
1709
|
* @param id Always the absolute (fully resolved) path to the module.
|
|
@@ -1749,11 +1715,10 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
|
|
|
1749
1715
|
level: "info"
|
|
1750
1716
|
}); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
|
|
1751
1717
|
|
|
1752
|
-
var ms = new MagicString__default["default"](code); //
|
|
1753
|
-
//
|
|
1754
|
-
// source maps and import statements get to the top anyways
|
|
1718
|
+
var ms = new MagicString__default["default"](code); // Appending instead of prepending has less probability of mucking with user's source maps.
|
|
1719
|
+
// Luckily import statements get hoisted to the top anyways.
|
|
1755
1720
|
|
|
1756
|
-
ms.append("
|
|
1721
|
+
ms.append(";\nimport \"".concat(RELEASE_INJECTOR_ID, "\";"));
|
|
1757
1722
|
|
|
1758
1723
|
if (unpluginMetaContext.framework === "esbuild") {
|
|
1759
1724
|
// esbuild + unplugin is buggy at the moment when we return an object with a `map` (sourcemap) property.
|