Skip to content

Commit e0aef03

Browse files
kamilogorekHazAT
authored andcommitted
ref: Minor changes related to bundle size
1 parent 50a0c64 commit e0aef03

File tree

5 files changed

+22
-36
lines changed

5 files changed

+22
-36
lines changed

packages/core/src/dsn.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { SentryError } from '@sentry/utils/error';
44
/** Regular expression used to parse a Dsn. */
55
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w\.-]+)(?::(\d+))?\/(.+)/;
66

7+
/** Error message */
8+
const ERROR_MESSAGE = 'Invalid Dsn';
9+
710
/** The Sentry Dsn, identifying a Sentry instance and project. */
811
export class Dsn implements DsnComponents {
912
/** Protocol used to connect to Sentry. */
@@ -54,7 +57,7 @@ export class Dsn implements DsnComponents {
5457
private fromString(str: string): void {
5558
const match = DSN_REGEX.exec(str);
5659
if (!match) {
57-
throw new SentryError('Invalid Dsn');
60+
throw new SentryError(ERROR_MESSAGE);
5861
}
5962

6063
const [protocol, user, pass = '', host, port = '', lastPath] = match.slice(1);
@@ -81,18 +84,18 @@ export class Dsn implements DsnComponents {
8184

8285
/** Validates this Dsn and throws on error. */
8386
private validate(): void {
84-
for (const component of ['protocol', 'user', 'host', 'projectId']) {
87+
['protocol', 'user', 'host', 'projectId'].forEach(component => {
8588
if (!this[component as keyof DsnComponents]) {
86-
throw new SentryError(`Invalid Dsn: Missing ${component}`);
89+
throw new SentryError(ERROR_MESSAGE);
8790
}
88-
}
91+
});
8992

9093
if (this.protocol !== 'http' && this.protocol !== 'https') {
91-
throw new SentryError(`Invalid Dsn: Unsupported protocol "${this.protocol}"`);
94+
throw new SentryError(ERROR_MESSAGE);
9295
}
9396

9497
if (this.port && Number.isNaN(parseInt(this.port, 10))) {
95-
throw new SentryError(`Invalid Dsn: Invalid port number "${this.port}"`);
98+
throw new SentryError(ERROR_MESSAGE);
9699
}
97100
}
98101
}

packages/core/src/integration.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ export function getIntegrationsToSetup(options: Options): Integration[] {
1515
let integrations: Integration[] = [];
1616
if (Array.isArray(userIntegrations)) {
1717
const userIntegrationsNames = userIntegrations.map(i => i.name);
18-
const pickedIntegrationsNames = [];
18+
const pickedIntegrationsNames: string[] = [];
1919

2020
// Leave only unique default integrations, that were not overridden with provided user integrations
21-
for (const defaultIntegration of defaultIntegrations) {
21+
defaultIntegrations.forEach(defaultIntegration => {
2222
if (
2323
userIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 &&
2424
pickedIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1
2525
) {
2626
integrations.push(defaultIntegration);
2727
pickedIntegrationsNames.push(getIntegrationName(defaultIntegration));
2828
}
29-
}
29+
});
3030

3131
// Don't add same user integration twice
32-
for (const userIntegration of userIntegrations) {
32+
userIntegrations.forEach(userIntegration => {
3333
if (pickedIntegrationsNames.indexOf(getIntegrationName(userIntegration)) === -1) {
3434
integrations.push(userIntegration);
3535
pickedIntegrationsNames.push(getIntegrationName(userIntegration));
3636
}
37-
}
37+
});
3838
} else if (typeof userIntegrations === 'function') {
3939
integrations = userIntegrations(defaultIntegrations);
4040
integrations = Array.isArray(integrations) ? integrations : [integrations];

packages/utils/src/fs.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
import { mkdir, mkdirSync, readFile, statSync } from 'fs';
1+
import { mkdir, mkdirSync, statSync } from 'fs';
22
import { dirname, resolve } from 'path';
33

44
const _0777 = parseInt('0777', 8);
55

6-
/**
7-
* Asynchronously reads given files content.
8-
*
9-
* @param path A relative or absolute path to the file
10-
* @returns A Promise that resolves when the file has been read.
11-
*/
12-
export async function readFileAsync(path: string): Promise<string> {
13-
// We cannot use util.promisify here because that was only introduced in Node
14-
// 8 and we need to support older Node versions.
15-
return new Promise<string>((res, reject) => {
16-
readFile(path, 'utf8', (err, data) => {
17-
if (err) {
18-
reject(err);
19-
} else {
20-
res(data);
21-
}
22-
});
23-
});
24-
}
25-
266
/**
277
* Asynchronously creates the given directory.
288
*

packages/utils/src/logger.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { consoleSandbox, getGlobalObject } from './misc';
33
// TODO: Implement different loggers for different environments
44
const global = getGlobalObject() as Window;
55

6+
/** Prefix for logging strings */
7+
const PREFIX = 'Sentry Logger ';
8+
69
/** JSDoc */
710
class Logger {
811
/** JSDoc */
@@ -29,7 +32,7 @@ class Logger {
2932
return;
3033
}
3134
consoleSandbox(() => {
32-
global.console.log(`Sentry Logger [Log]: ${args.join(' ')}`); // tslint:disable-line:no-console
35+
global.console.log(`${PREFIX}[Log]: ${args.join(' ')}`); // tslint:disable-line:no-console
3336
});
3437
}
3538

@@ -39,7 +42,7 @@ class Logger {
3942
return;
4043
}
4144
consoleSandbox(() => {
42-
global.console.warn(`Sentry Logger [Warn]: ${args.join(' ')}`); // tslint:disable-line:no-console
45+
global.console.warn(`${PREFIX}[Warn]: ${args.join(' ')}`); // tslint:disable-line:no-console
4346
});
4447
}
4548

@@ -49,7 +52,7 @@ class Logger {
4952
return;
5053
}
5154
consoleSandbox(() => {
52-
global.console.error(`Sentry Logger [Error]: ${args.join(' ')}`); // tslint:disable-line:no-console
55+
global.console.error(`${PREFIX}[Error]: ${args.join(' ')}`); // tslint:disable-line:no-console
5356
});
5457
}
5558
}

packages/utils/src/supports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export function supportsReferrerPolicy(): boolean {
131131

132132
try {
133133
// tslint:disable:no-unused-expression
134-
new Request('pickleRick', {
134+
new Request('_', {
135135
referrerPolicy: 'origin' as ReferrerPolicy,
136136
});
137137
return true;

0 commit comments

Comments
 (0)