Skip to content

Commit 50a9693

Browse files
committed
Add url_prefix
1 parent 3abd6f3 commit 50a9693

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ ignore_missing=true
104104
| org | Organization's slug | e.g. sentry-sdks (string) | yes | SENTRY_ORG |
105105
| auth_token | Auth Token | e.g. 64 random characteres (string) | yes | SENTRY_AUTH_TOKEN |
106106
| url | URL | e.g. https<area>://mysentry.invalid/ (string) | no | SENTRY_URL |
107+
| url_prefix | URL prefix for JS source maps | e.g. https<area>://mysentry.invalid/ (string) | no | - |
107108
| wait_for_processing | Wait for server-side processing of uploaded files | false (boolean) | no | - |
108109
| log_level | Configures the log level for sentry-cli | warn (string) | no | SENTRY_LOG_LEVEL |
109110
| release | The release version for source maps, it should match the release set by the SDK | name@version from pubspec (string) | no | SENTRY_RELEASE |

lib/sentry_dart_plugin.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ class SentryDartPlugin {
137137
_configuration.webBuildFilesFolder);
138138

139139
_addWait(releaseJsFilesParams);
140+
_addUrlPrefix(releaseJsFilesParams);
140141

141142
await _executeAndLog('Failed to upload source maps', releaseJsFilesParams);
142143

143-
144144
if (_configuration.uploadSources) {
145145
// upload source files (dart)
146146
List<String> releaseDartFilesParams = [];
@@ -158,6 +158,18 @@ class SentryDartPlugin {
158158
Log.taskCompleted(taskName);
159159
}
160160

161+
void _addUrlPrefix(List<String> releaseDartFilesParams) {
162+
if (_configuration.urlPrefix != null) {
163+
if (!_configuration.urlPrefix!.startsWith("~")) {
164+
Log.error(
165+
'urlPrefix must start with ~, please update the configuration.');
166+
return;
167+
}
168+
releaseDartFilesParams.add('--url-prefix');
169+
releaseDartFilesParams.add(_configuration.urlPrefix!);
170+
}
171+
}
172+
161173
void _setUrlAndTokenAndLog(List<String> params) {
162174
if (_configuration.url != null) {
163175
params.add('--url');

lib/src/configuration.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Configuration {
7070
/// the Web Build folder, defaults to build/web
7171
late String webBuildFilesFolder;
7272

73+
/// The URL prefix, defaults to null
74+
late String? urlPrefix;
75+
7376
/// Associate commits with the release. Defaults to `auto` which will discover
7477
/// commits from the current project and compare them with the ones associated
7578
/// to the previous release. See docs for other options:
@@ -151,6 +154,7 @@ class Configuration {
151154
waitForProcessing = configValues.waitForProcessing ?? false;
152155
authToken = configValues.authToken; // or env. var. SENTRY_AUTH_TOKEN
153156
url = configValues.url; // or env. var. SENTRY_URL
157+
urlPrefix = configValues.urlPrefix;
154158
logLevel = configValues.logLevel; // or env. var. SENTRY_LOG_LEVEL
155159
binDir = configValues.binDir ?? '.dart_tool/pub/bin/sentry_dart_plugin';
156160
binPath = configValues.binPath;

lib/src/configuration_values.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ConfigurationValues {
1212
final String? org;
1313
final String? authToken;
1414
final String? url;
15+
final String? urlPrefix;
1516
final bool? waitForProcessing;
1617
final String? logLevel;
1718
final String? release;
@@ -35,6 +36,7 @@ class ConfigurationValues {
3536
this.org,
3637
this.authToken,
3738
this.url,
39+
this.urlPrefix,
3840
this.waitForProcessing,
3941
this.logLevel,
4042
this.release,
@@ -85,6 +87,7 @@ class ConfigurationValues {
8587
org: sentryArguments['org'],
8688
authToken: sentryArguments['auth_token'],
8789
url: sentryArguments['url'],
90+
urlPrefix: sentryArguments['url_prefix'],
8891
waitForProcessing: boolFromString(sentryArguments['wait_for_processing']),
8992
logLevel: sentryArguments['log_level'],
9093
release: sentryArguments['release'],
@@ -117,6 +120,7 @@ class ConfigurationValues {
117120
org: configReader.getString('org'),
118121
authToken: configReader.getString('auth_token'),
119122
url: configReader.getString('url'),
123+
urlPrefix: configReader.getString('url_prefix'),
120124
waitForProcessing: configReader.getBool('wait_for_processing'),
121125
logLevel: configReader.getString('log_level'),
122126
release: configReader.getString('release'),
@@ -169,6 +173,7 @@ class ConfigurationValues {
169173
org: args.org ?? file.org,
170174
authToken: args.authToken ?? file.authToken,
171175
url: args.url ?? file.url,
176+
urlPrefix: args.urlPrefix ?? file.urlPrefix,
172177
waitForProcessing: args.waitForProcessing ?? file.waitForProcessing,
173178
logLevel: args.logLevel ?? file.logLevel,
174179
release: platformEnv.release ?? args.release ?? file.release,

test/configuration_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void main() {
6262
org: 'org-args-config',
6363
authToken: 'auth_token-args-config',
6464
url: 'url-args-config',
65+
urlPrefix: 'url-prefix-args-config',
6566
waitForProcessing: true,
6667
logLevel: 'warning',
6768
release: 'release-args-config',
@@ -85,6 +86,7 @@ void main() {
8586
org: 'org-file-config',
8687
authToken: 'auth_token-file-config',
8788
url: 'url-file-config',
89+
urlPrefix: 'url-prefix-file-config',
8890
waitForProcessing: false,
8991
logLevel: 'debug',
9092
release: 'release-file-config',
@@ -114,6 +116,7 @@ void main() {
114116
expect(sut.org, 'org-args-config');
115117
expect(sut.authToken, 'auth_token-args-config');
116118
expect(sut.url, 'url-args-config');
119+
expect(sut.urlPrefix, 'url-prefix-args-config');
117120
expect(sut.waitForProcessing, true);
118121
expect(sut.logLevel, 'warning');
119122
expect(sut.release, 'release-args-config');
@@ -147,6 +150,7 @@ void main() {
147150
org: 'org-file-config',
148151
authToken: 'auth_token-file-config',
149152
url: 'url-file-config',
153+
urlPrefix: 'url-prefix-file-config',
150154
waitForProcessing: true,
151155
logLevel: 'debug',
152156
release: 'release-file-config',
@@ -177,6 +181,7 @@ void main() {
177181
expect(sut.org, 'org-file-config');
178182
expect(sut.authToken, 'auth_token-file-config');
179183
expect(sut.url, 'url-file-config');
184+
expect(sut.urlPrefix, 'url-prefix-file-config');
180185
expect(sut.waitForProcessing, true);
181186
expect(sut.logLevel, 'debug');
182187
expect(sut.release, 'release-file-config');

test/plugin_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,14 @@ void main() {
341341
upload_source_maps: true
342342
release: $configRelease
343343
dist: $configDist
344+
url_prefix: ~/app/
344345
''';
345346
final commandLog = await runWith(version, config);
346347

347348
final args = commonArgs;
348349
expect(commandLog, [
349350
'$cli $args releases $orgAndProject new $configRelease',
350-
'$cli $args releases $orgAndProject files $configRelease upload-sourcemaps $buildDir/build/web --ext map --ext js --dist $configDist',
351+
'$cli $args releases $orgAndProject files $configRelease upload-sourcemaps $buildDir/build/web --ext map --ext js --dist $configDist --url-prefix ~/app/',
351352
'$cli $args releases $orgAndProject set-commits $configRelease --auto',
352353
'$cli $args releases $orgAndProject finalize $configRelease'
353354
]);

0 commit comments

Comments
 (0)