Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 13d5831

Browse files
authored
feat(sourcemaps): Add deleteSourceMaps option (#76)
This adds a new option, `deleteSourceMaps` (or `SENTRY_DELETE_SOURCEMAPS` as an env variable), which will delete sourcemaps after uploading them. Really this should be done at the `sentry-cli` level (see getsentry/sentry-cli#1318), but in the meantime, we can do it manually. Fixes #40
1 parent 9f5145e commit 13d5831

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ For more information about the parameters below, please see the [Sentry release
122122
| `skipSetCommits` | - | If true, disable commit tracking. | `false` |
123123
| `skipSourceMaps` | - | If true, disable uploading source maps to Sentry. | `false` |
124124
| `deployPreviews` | - | If false, skip running the build plugin on preview deploys. | `true` |
125+
| `deleteSourceMaps` | SENTRY_DELETE_SOURCEMAPS | If true, delete source maps after uploading them to Sentry. May cause browser console errors if not used alongside your build tool's equivalent of webpack's [`hidden-source-map` option](https://webpack.js.org/configuration/devtool/). | `false` |
125126

126127
## `@sentry/netlify-build-plugin` vs. `@netlify/sentry`
127128

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const path = require('path');
1010
const SentryCli = require('@sentry/cli');
1111
const { promisify, inspect } = require('util');
1212
const { version } = require('./package.json');
13+
const rimraf = require('rimraf');
1314

1415
const writeFile = promisify(fs.writeFile);
1516
const deleteFile = promisify(fs.unlink);
@@ -37,6 +38,7 @@ module.exports = {
3738
const sentryRepository = process.env.SENTRY_REPOSITORY || inputs.sentryRepository;
3839
const sourceMapPath = inputs.sourceMapPath || PUBLISH_DIR;
3940
const sourceMapUrlPrefix = inputs.sourceMapUrlPrefix || DEFAULT_SOURCE_MAP_URL_PREFIX;
41+
const shouldDeleteMaps = inputs.deleteSourceMaps || SENTRY_DELETE_SOURCEMAPS;
4042

4143
if (RUNNING_IN_NETLIFY) {
4244
if (IS_PREVIEW && !inputs.deployPreviews) {
@@ -83,6 +85,13 @@ module.exports = {
8385
console.log();
8486

8587
await deleteSentryConfig();
88+
89+
if (shouldDeleteMaps) {
90+
console.log('Removing source map files.');
91+
await rimraf(sourceMapPath, {
92+
filter: filepath => filepath.endsWith('.map'),
93+
});
94+
}
8695
}
8796
},
8897
};

manifest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ inputs:
2525
- name: deployPreviews
2626
description: Set this to false if you want to skip running the build plugin on deploy previews.
2727
default: True
28+
- name: deleteSourceMaps
29+
description: If true, delete source maps after uploading them to Sentry.
30+
default: False

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"license": "Apache-2.0",
2424
"dependencies": {
25-
"@sentry/cli": "^1.52.3"
25+
"@sentry/cli": "^1.52.3",
26+
"rimraf": "^4.3.1"
2627
},
2728
"engines": {
2829
"node": ">=8.12.0"

yarn.lock

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4617,6 +4617,16 @@ glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
46174617
once "^1.3.0"
46184618
path-is-absolute "^1.0.0"
46194619

4620+
glob@^9.2.0:
4621+
version "9.2.1"
4622+
resolved "https://registry.yarnpkg.com/glob/-/glob-9.2.1.tgz#f47e34e1119e7d4f93a546e75851ba1f1e68de50"
4623+
integrity sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==
4624+
dependencies:
4625+
fs.realpath "^1.0.0"
4626+
minimatch "^7.4.1"
4627+
minipass "^4.2.4"
4628+
path-scurry "^1.6.1"
4629+
46204630
global-cache-dir@^1.0.1:
46214631
version "1.0.1"
46224632
resolved "https://registry.yarnpkg.com/global-cache-dir/-/global-cache-dir-1.0.1.tgz#2c0820b43bae8a6ef8adf96fd23ec6bbf52dd13c"
@@ -5866,6 +5876,11 @@ lru-cache@^6.0.0:
58665876
dependencies:
58675877
yallist "^4.0.0"
58685878

5879+
lru-cache@^7.14.1:
5880+
version "7.18.3"
5881+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.18.3.tgz#f793896e0fd0e954a59dfdd82f0773808df6aa89"
5882+
integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==
5883+
58695884
macos-release@^2.2.0:
58705885
version "2.5.1"
58715886
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.5.1.tgz#bccac4a8f7b93163a8d163b8ebf385b3c5f55bf9"
@@ -6074,6 +6089,13 @@ minimatch@^5.1.0:
60746089
dependencies:
60756090
brace-expansion "^2.0.1"
60766091

6092+
minimatch@^7.4.1:
6093+
version "7.4.2"
6094+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-7.4.2.tgz#157e847d79ca671054253b840656720cb733f10f"
6095+
integrity sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==
6096+
dependencies:
6097+
brace-expansion "^2.0.1"
6098+
60776099
minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
60786100
version "1.2.8"
60796101
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
@@ -6094,7 +6116,7 @@ minipass@^3.0.0:
60946116
dependencies:
60956117
yallist "^4.0.0"
60966118

6097-
minipass@^4.0.0:
6119+
minipass@^4.0.0, minipass@^4.0.2, minipass@^4.2.4:
60986120
version "4.2.4"
60996121
resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.4.tgz#7d0d97434b6a19f59c5c3221698b48bbf3b2cd06"
61006122
integrity sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ==
@@ -6994,6 +7016,14 @@ path-parse@^1.0.7:
69947016
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
69957017
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
69967018

7019+
path-scurry@^1.6.1:
7020+
version "1.6.1"
7021+
resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.6.1.tgz#dab45f7bb1d3f45a0e271ab258999f4ab7e23132"
7022+
integrity sha512-OW+5s+7cw6253Q4E+8qQ/u1fVvcJQCJo/VFD8pje+dbJCF1n5ZRMV2AEHbGp+5Q7jxQIYJxkHopnj6nzdGeZLA==
7023+
dependencies:
7024+
lru-cache "^7.14.1"
7025+
minipass "^4.0.2"
7026+
69977027
69987028
version "0.1.7"
69997029
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
@@ -7615,6 +7645,13 @@ rimraf@^3.0.0, rimraf@^3.0.2:
76157645
dependencies:
76167646
glob "^7.1.3"
76177647

7648+
rimraf@^4.3.1:
7649+
version "4.3.1"
7650+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.3.1.tgz#ccb3525e39100478acb334fae6d23029b87912ea"
7651+
integrity sha512-GfHJHBzFQra23IxDzIdBqhOWfbtdgS1/dCHrDy+yvhpoJY5TdwdT28oWaHWfRpKFDLd3GZnGTx6Mlt4+anbsxQ==
7652+
dependencies:
7653+
glob "^9.2.0"
7654+
76187655
rollup-plugin-inject@^3.0.0:
76197656
version "3.0.2"
76207657
resolved "https://registry.yarnpkg.com/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz#e4233855bfba6c0c12a312fd6649dff9a13ee9f4"

0 commit comments

Comments
 (0)