Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Features

- Ignore path list for web ([#340](https://github.com/getsentry/sentry-dart-plugin/pull/340))
- You can use the `ignore_web_source_paths` field: e.g `ignore_web_source_paths: [test/**/*.js]`
- This will ignore all specified files and directories from being uploaded

## 3.1.1

### Fixes
Expand Down
80 changes: 52 additions & 28 deletions lib/sentry_dart_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:file/file.dart';
import 'package:glob/glob.dart';
import 'package:process/process.dart';
import 'package:sentry_dart_plugin/src/utils/extensions.dart';

Expand Down Expand Up @@ -225,46 +226,64 @@ class SentryDartPlugin {
await _executeAndLog('Failed to set commits', params);
}

Future<List<String>> _findAllJsFilePaths() async {
final List<String> jsFiles = [];
/// Returns every file inside [_configuration.webBuildFilesFolder] whose
/// path ends with [extension] **and** is *not* matched by an ignore glob.
///
/// The generic type `T` lets the caller decide what they want back
/// (e.g. `String` path vs. `File` object).
Future<List<T>> _collectWebFiles<T>({
required String extension,
required T Function(File) builder,
}) async {
final fs = injector.get<FileSystem>();
final webDir = fs.directory(_configuration.webBuildFilesFolder);

if (await webDir.exists()) {
await for (final entity
in webDir.list(recursive: true, followLinks: false)) {
if (entity is File && entity.path.toLowerCase().endsWith('.js')) {
jsFiles.add(entity.path);
}
}
} else {
// Fast-fail if the directory doesn’t exist.
if (!await webDir.exists()) {
Log.warn(
'Web build directory "${_configuration.webBuildFilesFolder}" does not exist, skipping JS file enumeration.',
'Web build directory "${_configuration.webBuildFilesFolder}" does not exist, '
'skipping $extension enumeration.',
);
return <T>[];
}
return jsFiles;
}

Future<List<File>> _findAllSourceMapFiles() async {
final List<File> sourceMapFiles = [];
final fs = injector.get<FileSystem>();
final webDir = fs.directory(_configuration.webBuildFilesFolder);
// Compile ignore globs once instead of on every iteration.
final ignoreGlobs =
_configuration.ignoreWebSourcePaths.map((p) => Glob(p)).toList();

if (await webDir.exists()) {
await for (final entity
in webDir.list(recursive: true, followLinks: false)) {
if (entity is File && entity.path.toLowerCase().endsWith('.js.map')) {
sourceMapFiles.add(entity.absolute);
}
bool shouldIgnore(String relative) =>
ignoreGlobs.any((g) => g.matches(relative));

final results = <T>[];

await for (final entity
in webDir.list(recursive: true, followLinks: false)) {
if (entity is! File) continue;

final path = entity.path;
if (!path.toLowerCase().endsWith(extension)) continue;

final relative =
fs.path.relative(path, from: _configuration.webBuildFilesFolder);

if (!shouldIgnore(relative)) {
results.add(builder(entity));
}
} else {
Log.warn(
'Web build directory "${_configuration.webBuildFilesFolder}" does not exist, skipping source map file enumeration.',
);
}
return sourceMapFiles;

return results;
}

Future<List<String>> _findAllJsFilePaths() => _collectWebFiles<String>(
extension: '.js',
builder: (file) => file.path,
);

Future<List<File>> _findAllSourceMapFiles() => _collectWebFiles<File>(
extension: '.js.map',
builder: (file) => file.absolute,
);

Future<bool> _injectDebugIds() async {
List<String> params = [];
params.add('sourcemaps');
Expand Down Expand Up @@ -331,6 +350,11 @@ class SentryDartPlugin {
params.add('dart');
}

for (final ignorePattern in _configuration.ignoreWebSourcePaths) {
params.add('--ignore');
params.add(ignorePattern);
}

params.addAll(_baseCliParams());

await _executeAndLog('Failed to sources files', params);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class Configuration {
/// Whether to use legacy web symbolication. Defaults to `false`.
late bool legacyWebSymbolication;

late List<String> ignoreWebSourcePaths;

/// Loads the configuration values
Future<void> getConfigValues(List<String> cliArguments) async {
const taskName = 'reading config values';
Expand Down Expand Up @@ -168,6 +170,7 @@ class Configuration {
'https://downloads.sentry-cdn.com/sentry-cli';
sentryCliVersion = configValues.sentryCliVersion;
legacyWebSymbolication = configValues.legacyWebSymbolication ?? false;
ignoreWebSourcePaths = configValues.ignoreWebSourcePaths ?? [];
}

/// Validates the configuration values and log an error if required fields
Expand Down
5 changes: 5 additions & 0 deletions lib/src/configuration_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ConfigurationValues {
final String? sentryCliCdnUrl;
final String? sentryCliVersion;
final bool? legacyWebSymbolication;
final List<String>? ignoreWebSourcePaths;

ConfigurationValues({
this.version,
Expand All @@ -53,6 +54,7 @@ class ConfigurationValues {
this.sentryCliCdnUrl,
this.sentryCliVersion,
this.legacyWebSymbolication,
this.ignoreWebSourcePaths,
});

factory ConfigurationValues.fromArguments(List<String> arguments) {
Expand Down Expand Up @@ -108,6 +110,7 @@ class ConfigurationValues {
legacyWebSymbolication: boolFromString(
sentryArguments['legacy_web_symbolication'],
),
ignoreWebSourcePaths: sentryArguments['ignore_web_source_paths']?.split(',').map((e) => e.trim()).toList(),
);
}

Expand Down Expand Up @@ -143,6 +146,7 @@ class ConfigurationValues {
sentryCliCdnUrl: configReader.getString('sentry_cli_cdn_url'),
sentryCliVersion: configReader.getString('sentry_cli_version'),
legacyWebSymbolication: configReader.getBool('legacy_web_symbolication'),
ignoreWebSourcePaths: configReader.getList('ignore_web_source_paths'),
);
}

Expand Down Expand Up @@ -201,6 +205,7 @@ class ConfigurationValues {
sentryCliVersion: args.sentryCliVersion ?? file.sentryCliVersion,
legacyWebSymbolication:
args.legacyWebSymbolication ?? file.legacyWebSymbolication,
ignoreWebSourcePaths: args.ignoreWebSourcePaths ?? file.ignoreWebSourcePaths,
);
}
}
1 change: 1 addition & 0 deletions lib/src/utils/config-reader/config_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'yaml_config_reader.dart';
abstract class ConfigReader {
String? getString(String key, {String? deprecatedKey});
bool? getBool(String key, {String? deprecatedKey});
List<String>? getList(String key, {String? deprecatedKey});
bool contains(String key);

/// This factory will try to load both pubspec.yaml and sentry.properties.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/utils/config-reader/fallback_config_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class FallbackConfigReader implements ConfigReader {
_fallbackConfigReader?.getString(key, deprecatedKey: deprecatedKey);
}

@override
List<String>? getList(String key, {String? deprecatedKey}) {
return _configReader?.getList(key, deprecatedKey: deprecatedKey) ??
_fallbackConfigReader?.getList(key, deprecatedKey: deprecatedKey);
}

@override
bool contains(String key) {
return _configReader?.contains(key) ??
Expand Down
5 changes: 5 additions & 0 deletions lib/src/utils/config-reader/no_op_config_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class NoOpConfigReader implements ConfigReader {
return null;
}

@override
List<String>? getList(String key, {String? deprecatedKey}) {
return null;
}

@override
bool contains(String key) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/utils/config-reader/properties_config_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class PropertiesConfigReader implements ConfigReader {
return get(key, deprecatedKey, (key) => _properties.get((key)));
}

@override
List<String>? getList(String key, {String? deprecatedKey}) {
return get(key, deprecatedKey, (key) {
final value = _properties.get(key);
if (value != null && value.isNotEmpty) {
return value.split(',').map((e) => e.trim()).toList();
}
return null;
});
}

@override
bool contains(String key) {
return _properties.contains(key);
Expand Down
13 changes: 13 additions & 0 deletions lib/src/utils/config-reader/yaml_config_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ class YamlConfigReader implements ConfigReader {
return get(key, deprecatedKey, (key) => (_yamlMap?[key]).toString());
}

@override
List<String>? getList(String key, {String? deprecatedKey}) {
return get(key, deprecatedKey, (key) {
final value = _yamlMap?[key];
if (value is YamlList) {
return value.map((e) => e.toString()).toList();
} else if (value is List) {
return value.map((e) => e.toString()).toList();
}
return null;
});
}

@override
bool contains(String key) {
return _yamlMap?.containsKey(key) ?? false;
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
convert: ^3.0.2
process: '>=4.2.4 <6.0.0'
properties: ^2.1.0
glob: ^2.1.3

dev_dependencies:
lints: '>=3.0.0'
Expand Down
6 changes: 6 additions & 0 deletions test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void main() {
sentryCliCdnUrl: 'sentryCliCdnUrl-args-config',
sentryCliVersion: '1.0.0-args-config',
legacyWebSymbolication: true,
ignoreWebSourcePaths: ['some/', '**/*.js'],
);
final fileConfig = ConfigurationValues(
version: 'version-file-config',
Expand All @@ -103,6 +104,7 @@ void main() {
sentryCliCdnUrl: 'sentryCliCdnUrl-file-config',
sentryCliVersion: '1.0.0-file-config',
legacyWebSymbolication: false,
ignoreWebSourcePaths: ['some-other/'],
);

final sut = fixture.getSut(
Expand Down Expand Up @@ -141,6 +143,7 @@ void main() {
expect(sut.sentryCliCdnUrl, 'sentryCliCdnUrl-args-config');
expect(sut.sentryCliVersion, '1.0.0-args-config');
expect(sut.legacyWebSymbolication, isTrue);
expect(sut.ignoreWebSourcePaths, ['some/', '**/*.js']);
});

test("takes values from file config", () {
Expand Down Expand Up @@ -171,6 +174,7 @@ void main() {
sentryCliCdnUrl: 'sentryCliCdnUrl-file-config',
sentryCliVersion: '1.0.0-file-config',
legacyWebSymbolication: true,
ignoreWebSourcePaths: ['some/', '**/*.js'],
);

final sut = fixture.getSut(
Expand Down Expand Up @@ -208,6 +212,7 @@ void main() {
expect(sut.sentryCliCdnUrl, 'sentryCliCdnUrl-file-config');
expect(sut.sentryCliVersion, '1.0.0-file-config');
expect(sut.legacyWebSymbolication, isTrue);
expect(sut.ignoreWebSourcePaths, ['some/', '**/*.js']);
});

test("falls back to default values", () {
Expand Down Expand Up @@ -240,6 +245,7 @@ void main() {
'https://downloads.sentry-cdn.com/sentry-cli',
);
expect(sut.legacyWebSymbolication, isFalse);
expect(sut.ignoreWebSourcePaths, []);
});
});
}
Expand Down
10 changes: 9 additions & 1 deletion test/configuration_values_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void main() {
"--sentry-define=bin_dir=fixture-bin_dir",
"--sentry-define=sentry_cli_cdn_url=fixture-sentry_cli_cdn_url",
"--sentry-define=sentry_cli_version=1.0.0",
"--sentry-define=legacy_web_symbolication=true"
"--sentry-define=legacy_web_symbolication=true",
"--sentry-define=ignore_web_source_paths=some/, **/*.js"
];
final sut = ConfigurationValues.fromArguments(arguments);
expect(sut.name, 'fixture-sentry-name');
Expand All @@ -60,6 +61,7 @@ void main() {
expect(sut.sentryCliCdnUrl, 'fixture-sentry_cli_cdn_url');
expect(sut.sentryCliVersion, '1.0.0');
expect(sut.legacyWebSymbolication, isTrue);
expect(sut.ignoreWebSourcePaths, ['some/', '**/*.js']);
});

test("fromArguments supports deprecated fields", () {
Expand Down Expand Up @@ -103,6 +105,9 @@ void main() {
sentry_cli_cdn_url: fixture-sentry_cli_cdn_url
sentry_cli_version: 1.0.0
legacy_web_symbolication: true
ignore_web_source_paths:
- some/
- '**/*.js'
''';

FileSystem fs = MemoryFileSystem.test();
Expand Down Expand Up @@ -145,6 +150,7 @@ void main() {
expect(sut.binDir, 'fixture-bin_dir');
expect(sut.sentryCliCdnUrl, 'fixture-sentry_cli_cdn_url');
expect(sut.legacyWebSymbolication, isTrue);
expect(sut.ignoreWebSourcePaths, ['some/', '**/*.js']);
});

test('from config reader as properties', () {
Expand All @@ -167,6 +173,7 @@ void main() {
bin_dir=fixture-bin_dir
sentry_cli_cdn_url=fixture-sentry_cli_cdn_url
sentry_cli_version=1.0.0
ignore_web_source_paths=[some/, **/*.js]
''';

FileSystem fs = MemoryFileSystem.test();
Expand Down Expand Up @@ -209,6 +216,7 @@ void main() {
expect(sut.binDir, 'fixture-bin_dir');
expect(sut.sentryCliCdnUrl, 'fixture-sentry_cli_cdn_url');
expect(sut.sentryCliVersion, '1.0.0');
expect(sut.ignoreWebSourcePaths, ['some/', '**/*.js']);
});

test('from config reader pubspec & properties', () {
Expand Down
4 changes: 2 additions & 2 deletions test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ void main() {
setUp(() {
createJsFilesForTesting();
});

test('works with all configuration files', () async {
const version = '1.0.0';
final config = '''
Expand All @@ -94,6 +93,7 @@ void main() {
upload_source_maps: true
log_level: debug
ignore_missing: true
ignore_web_source_paths: [testdir/**/*.js]
''';
final commandLog = await runWith(version, config);
const release = '$name@$version';
Expand All @@ -103,7 +103,7 @@ void main() {
'$cli $args debug-files upload $orgAndProject --include-sources $buildDir/app/outputs',
'$cli $args releases $orgAndProject new $release',
'$cli sourcemaps inject $buildDir/web/file.js $orgAndProject',
'$cli $args sourcemaps upload --release $release $buildDir/web --ext js --ext map --strip-prefix ../../Documents --strip-prefix ../../../../ --strip-prefix ../../ --strip-prefix ../ ./ --ext dart $orgAndProject',
'$cli $args sourcemaps upload --release $release $buildDir/web --ext js --ext map --strip-prefix ../../Documents --strip-prefix ../../../../ --strip-prefix ../../ --strip-prefix ../ ./ --ext dart --ignore testdir/**/*.js $orgAndProject',
'$cli $args releases $orgAndProject set-commits $release --auto --ignore-missing',
'$cli $args releases $orgAndProject finalize $release'
]);
Expand Down
Loading
Loading