Skip to content

Commit 2ce4745

Browse files
authored
fix: Make utils package also esm (getsentry#1999)
Convert @sentry/utils package to expose esm builds
1 parent 913eafc commit 2ce4745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+162
-404
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 5.0.6
4+
5+
- [utils]: Change how we use `utils` and expose `esm` build
6+
- [utils]: Remove `store` and `fs` classes -> moved to @sentry/electron where this is used
7+
38
## 5.0.5
49

510
- [esm]: `module` in `package.json` now provides a `es5` build instead of `es2015`

packages/browser/rollup.config.js

+14-24
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@ const terserInstance = terser({
2121
},
2222
});
2323

24+
const paths = {
25+
'@sentry/utils': ['../utils/src'],
26+
'@sentry/core': ['../core/src'],
27+
'@sentry/hub': ['../hub/src'],
28+
'@sentry/types': ['../types/src'],
29+
'@sentry/minimal': ['../minimal/src'],
30+
};
31+
2432
const plugins = [
2533
typescript({
2634
tsconfig: 'tsconfig.build.json',
2735
tsconfigOverride: {
2836
compilerOptions: {
2937
declaration: false,
3038
module: 'ES2015',
31-
paths: {
32-
'@sentry/utils/*': ['../utils/src/*'],
33-
'@sentry/core': ['../core/src'],
34-
'@sentry/hub': ['../hub/src'],
35-
'@sentry/types': ['../types/src'],
36-
'@sentry/minimal': ['../minimal/src'],
37-
},
39+
paths,
3840
},
3941
},
4042
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
4143
}),
4244
resolve({
43-
browser: true,
44-
module: false,
45-
modulesOnly: true,
45+
module: true,
46+
browser: false,
47+
modulesOnly: false,
4648
}),
4749
commonjs(),
4850
];
@@ -97,13 +99,7 @@ export default [
9799
compilerOptions: {
98100
declaration: false,
99101
module: 'ES2015',
100-
paths: {
101-
'@sentry/utils/*': ['../utils/src/*'],
102-
'@sentry/core': ['../core/src'],
103-
'@sentry/hub': ['../hub/src'],
104-
'@sentry/types': ['../types/src'],
105-
'@sentry/minimal': ['../minimal/src'],
106-
},
102+
paths,
107103
target: 'es6',
108104
},
109105
},
@@ -125,13 +121,7 @@ export default [
125121
compilerOptions: {
126122
declaration: false,
127123
module: 'ES2015',
128-
paths: {
129-
'@sentry/utils/*': ['../utils/src/*'],
130-
'@sentry/core': ['../core/src'],
131-
'@sentry/hub': ['../hub/src'],
132-
'@sentry/types': ['../types/src'],
133-
'@sentry/minimal': ['../minimal/src'],
134-
},
124+
paths,
135125
target: 'es6',
136126
},
137127
},

packages/browser/src/backend.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { BaseBackend } from '@sentry/core';
22
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
3-
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
4-
import { addExceptionTypeValue } from '@sentry/utils/misc';
5-
import { supportsFetch } from '@sentry/utils/supports';
6-
import { SyncPromise } from '@sentry/utils/syncpromise';
3+
import {
4+
addExceptionTypeValue,
5+
isDOMError,
6+
isDOMException,
7+
isError,
8+
isErrorEvent,
9+
isPlainObject,
10+
supportsFetch,
11+
SyncPromise,
12+
} from '@sentry/utils';
713

814
import { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';
915
import { computeStackTrace } from './tracekit';

packages/browser/src/client.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { API, BaseClient, Scope } from '@sentry/core';
22
import { DsnLike, Event, EventHint } from '@sentry/types';
3-
import { logger } from '@sentry/utils/logger';
4-
import { getGlobalObject } from '@sentry/utils/misc';
5-
import { SyncPromise } from '@sentry/utils/syncpromise';
3+
import { getGlobalObject, logger, SyncPromise } from '@sentry/utils';
64

75
import { BrowserBackend, BrowserOptions } from './backend';
86
import { SDK_NAME, SDK_VERSION } from './version';

packages/browser/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDi
3333
export { SDK_NAME, SDK_VERSION } from './version';
3434

3535
import { Integrations as CoreIntegrations } from '@sentry/core';
36-
import { getGlobalObject } from '@sentry/utils/misc';
36+
import { getGlobalObject } from '@sentry/utils';
3737

3838
import * as BrowserIntegrations from './integrations';
3939
import * as Transports from './transports';

packages/browser/src/integrations/breadcrumbs.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { API, getCurrentHub } from '@sentry/core';
22
import { Breadcrumb, BreadcrumbHint, Integration, Severity } from '@sentry/types';
3-
import { isString } from '@sentry/utils/is';
4-
import { logger } from '@sentry/utils/logger';
5-
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
6-
import { fill, normalize } from '@sentry/utils/object';
7-
import { safeJoin } from '@sentry/utils/string';
8-
import { supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
3+
import {
4+
fill,
5+
getEventDescription,
6+
getGlobalObject,
7+
isString,
8+
logger,
9+
normalize,
10+
parseUrl,
11+
safeJoin,
12+
supportsHistory,
13+
supportsNativeFetch,
14+
} from '@sentry/utils';
915

1016
import { BrowserClient } from '../client';
1117

packages/browser/src/integrations/globalhandlers.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import { Event, Integration } from '@sentry/types';
3-
import { logger } from '@sentry/utils/logger';
4-
import { addExceptionTypeValue } from '@sentry/utils/misc';
5-
import { normalize } from '@sentry/utils/object';
6-
import { truncate } from '@sentry/utils/string';
3+
import { addExceptionTypeValue, logger, normalize, truncate } from '@sentry/utils';
74

85
import { eventFromStacktrace } from '../parsers';
96
import {

packages/browser/src/integrations/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { captureException, getCurrentHub, withScope } from '@sentry/core';
22
import { Event as SentryEvent, Mechanism, WrappedFunction } from '@sentry/types';
3-
import { addExceptionTypeValue, htmlTreeAsString } from '@sentry/utils/misc';
4-
import { normalize } from '@sentry/utils/object';
3+
import { addExceptionTypeValue, htmlTreeAsString, normalize } from '@sentry/utils';
54

65
const debounceDuration: number = 1000;
76
let keypressTimeout: number | undefined;
@@ -38,6 +37,7 @@ export function wrap(
3837
fn: WrappedFunction,
3938
options: {
4039
mechanism?: Mechanism;
40+
capture?: boolean;
4141
} = {},
4242
before?: WrappedFunction,
4343
): any {

packages/browser/src/integrations/trycatch.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Integration, WrappedFunction } from '@sentry/types';
2-
import { getGlobalObject } from '@sentry/utils/misc';
3-
import { fill } from '@sentry/utils/object';
2+
import { fill, getGlobalObject } from '@sentry/utils';
43

54
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
65

packages/browser/src/integrations/useragent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22
import { Event, Integration } from '@sentry/types';
3-
import { getGlobalObject } from '@sentry/utils/misc';
3+
import { getGlobalObject } from '@sentry/utils';
44

55
const global = getGlobalObject<Window>();
66

packages/browser/src/parsers.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Event, Exception, StackFrame } from '@sentry/types';
2-
import { normalizeToSize } from '@sentry/utils/object';
3-
import { keysToEventMessage } from '@sentry/utils/string';
2+
import { keysToEventMessage, normalizeToSize } from '@sentry/utils';
43

54
import { computeStackTrace, StackFrame as TraceKitStackFrame, StackTrace as TraceKitStackTrace } from './tracekit';
65

packages/browser/src/tracekit.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// tslint:disable
22

3-
import { isError, isErrorEvent } from '@sentry/utils/is';
4-
import { getGlobalObject } from '@sentry/utils/misc';
3+
import { getGlobalObject, isError, isErrorEvent } from '@sentry/utils';
54

65
/**
76
* @hidden

packages/browser/src/transports/base.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { API } from '@sentry/core';
22
import { Event, Response, Transport, TransportOptions } from '@sentry/types';
3-
import { SentryError } from '@sentry/utils/error';
4-
import { PromiseBuffer } from '@sentry/utils/promisebuffer';
3+
import { PromiseBuffer, SentryError } from '@sentry/utils';
54

65
/** Base Transport class implementation */
76
export abstract class BaseTransport implements Transport {

packages/browser/src/transports/fetch.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Event, Response, Status } from '@sentry/types';
2-
import { getGlobalObject } from '@sentry/utils/misc';
3-
import { supportsReferrerPolicy } from '@sentry/utils/supports';
2+
import { getGlobalObject, supportsReferrerPolicy } from '@sentry/utils';
43

54
import { BaseTransport } from './base';
65

packages/browser/test/integration/common.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ function initSDK() {
117117
Sentry.init({
118118
dsn: 'https://public@example.com/1',
119119
// debug: true,
120-
integrations: [
121-
(Sentry.Integrations && Sentry.Integrations.Dedupe && new Sentry.Integrations.Dedupe()) ||
122-
(SentryIntegrations && new SentryIntegrations.Dedupe()),
123-
],
120+
integrations: [new Sentry.Integrations.Dedupe()],
124121
attachStacktrace: true,
125122
transport: DummyTransport,
126123
ignoreErrors: ['ignoreErrorTest'],

packages/browser/test/integration/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function _alt(title, condition) {
6464
return condition ? '⚠️ Skipped: ' + title : title;
6565
}
6666

67-
var frames = ['frame', 'loader', 'loader-lazy-no'];
67+
var frames = ['frame'];
6868

6969
for (var idx in frames) {
7070
(function() {
@@ -911,7 +911,7 @@ for (var idx in frames) {
911911
);
912912
});
913913

914-
it("should capture built-in's handlers fn name in mechanism data", function(done) {
914+
it.only("should capture built-in's handlers fn name in mechanism data", function(done) {
915915
var iframe = this.iframe;
916916

917917
iframeExecute(

packages/core/src/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DsnLike } from '@sentry/types';
2-
import { urlEncode } from '@sentry/utils/object';
2+
import { urlEncode } from '@sentry/utils';
33

44
import { Dsn } from './dsn';
55

packages/core/src/basebackend.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
2-
import { SentryError } from '@sentry/utils/error';
3-
import { logger } from '@sentry/utils/logger';
4-
import { SyncPromise } from '@sentry/utils/syncpromise';
2+
import { logger, SentryError, SyncPromise } from '@sentry/utils';
53

64
import { NoopTransport } from './transports/noop';
75

packages/core/src/baseclient.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { Scope } from '@sentry/hub';
22
import { Client, Event, EventHint, Integration, IntegrationClass, Options, SdkInfo, Severity } from '@sentry/types';
3-
import { isPrimitive, isThenable } from '@sentry/utils/is';
4-
import { logger } from '@sentry/utils/logger';
5-
import { uuid4 } from '@sentry/utils/misc';
6-
import { truncate } from '@sentry/utils/string';
7-
import { SyncPromise } from '@sentry/utils/syncpromise';
3+
import { isPrimitive, isThenable, logger, SyncPromise, truncate, uuid4 } from '@sentry/utils';
84

95
import { Backend, BackendClass } from './basebackend';
106
import { Dsn } from './dsn';

packages/core/src/dsn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
2-
import { SentryError } from '@sentry/utils/error';
2+
import { SentryError } from '@sentry/utils';
33

44
/** Regular expression used to parse a Dsn. */
55
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w\.-]+)(?::(\d+))?\/(.+)/;

packages/core/src/integration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
22
import { Integration, Options } from '@sentry/types';
3-
import { logger } from '@sentry/utils/logger';
3+
import { logger } from '@sentry/utils';
44

55
export const installedIntegrations: string[] = [];
66

packages/core/src/integrations/inboundfilters.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
22
import { Event, Integration } from '@sentry/types';
3-
import { isRegExp } from '@sentry/utils/is';
4-
import { logger } from '@sentry/utils/logger';
5-
import { getEventDescription } from '@sentry/utils/misc';
3+
import { getEventDescription, isRegExp, logger } from '@sentry/utils';
64

75
// "Script error." is hard coded into browsers for errors that it can't read.
86
// this is the result of a script being pulled in from an external domain and CORS.

packages/core/src/sdk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentHub } from '@sentry/hub';
22
import { Client, Options } from '@sentry/types';
3-
import { logger } from '@sentry/utils/logger';
3+
import { logger } from '@sentry/utils';
44

55
/** A class object that can instanciate Client objects. */
66
export type ClientClass<F extends Client, O extends Options> = new (options: O) => F;

packages/core/test/lib/base.test.ts

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
import { Hub, Scope } from '@sentry/hub';
22
import { Event } from '@sentry/types';
3-
import { SentryError } from '@sentry/utils/error';
3+
import { SentryError } from '@sentry/utils';
44

55
import { TestBackend } from '../mocks/backend';
66
import { TestClient } from '../mocks/client';
77
import { TestIntegration } from '../mocks/integration';
88

99
const PUBLIC_DSN = 'https://username@domain/path';
1010

11-
jest.mock('@sentry/utils/misc', () => ({
12-
uuid4(): string {
13-
return '42';
14-
},
15-
getGlobalObject(): object {
16-
return {
17-
console: {
18-
log(): void {
19-
// no-empty
11+
jest.mock('@sentry/utils', () => {
12+
const original = jest.requireActual('@sentry/utils');
13+
return {
14+
...original,
15+
16+
uuid4(): string {
17+
return '42';
18+
},
19+
getGlobalObject(): object {
20+
return {
21+
console: {
22+
log(): void {
23+
// no-empty
24+
},
25+
warn(): void {
26+
// no-empty
27+
},
28+
error(): void {
29+
// no-empty
30+
},
2031
},
21-
warn(): void {
22-
// no-empty
23-
},
24-
error(): void {
25-
// no-empty
26-
},
27-
},
28-
};
29-
},
30-
consoleSandbox(cb: () => any): any {
31-
return cb();
32-
},
33-
}));
34-
35-
jest.mock('@sentry/utils/string', () => ({
36-
truncate(str: string): string {
37-
return str;
38-
},
39-
}));
32+
};
33+
},
34+
consoleSandbox(cb: () => any): any {
35+
return cb();
36+
},
37+
truncate(str: string): string {
38+
return str;
39+
},
40+
};
41+
});
4042

4143
describe('BaseClient', () => {
4244
beforeEach(() => {

packages/core/test/lib/dsn.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SentryError } from '@sentry/utils/error';
1+
import { SentryError } from '@sentry/utils';
22

33
import { Dsn } from '../../src/dsn';
44

0 commit comments

Comments
 (0)