Skip to content

Commit 3a0ec5d

Browse files
HazATkamilogorek
authored andcommitted
feat: atomic @sentry/utils used only with submodule imports (#1413)
* feat: Add .gitignore for utils * fix: Utils submodule import * feat: Build from src into root for utils, Remove browser packages * feat: Move jest config into package.json to be consitent * fix: Lint error
1 parent 50d0005 commit 3a0ec5d

35 files changed

+109
-354
lines changed

packages/browser/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"rimraf": "^2.6.2",
3939
"rollup": "^0.58.2",
4040
"rollup-plugin-commonjs": "^9.1.3",
41-
"rollup-plugin-node-builtins": "^2.1.2",
4241
"rollup-plugin-node-resolve": "^3.3.0",
4342
"rollup-plugin-npm": "^2.0.0",
4443
"rollup-plugin-typescript2": "^0.13.0",

packages/browser/rollup.config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import commonjs from 'rollup-plugin-commonjs';
22
import uglify from 'rollup-plugin-uglify';
33
import resolve from 'rollup-plugin-node-resolve';
44
import typescript from 'rollup-plugin-typescript2';
5-
import builtins from 'rollup-plugin-node-builtins';
65

76
export default [
87
{
@@ -13,14 +12,8 @@ export default [
1312
exports: 'named',
1413
interop: false,
1514
},
16-
external: [
17-
'@sentry/core',
18-
'@sentry/hub',
19-
'@sentry/minimal',
20-
'@sentry/utils',
21-
],
15+
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal'],
2216
plugins: [
23-
builtins(),
2417
typescript({
2518
tsconfig: 'tsconfig.build.json',
2619
}),
@@ -39,12 +32,9 @@ export default [
3932
format: 'iife',
4033
name: 'Sentry',
4134
sourcemap: true,
42-
interop: false,
43-
extend: true,
4435
},
4536
context: 'window',
4637
plugins: [
47-
builtins(),
4838
typescript({
4939
tsconfig: 'tsconfig.build.json',
5040
tsconfigOverride: { compilerOptions: { declaration: false } },

packages/browser/src/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Backend, DSN, Options, SentryError } from '@sentry/core';
22
import { addBreadcrumb, captureEvent } from '@sentry/minimal';
33
import { SentryEvent } from '@sentry/types';
4-
import { supportsFetch } from '@sentry/utils';
4+
import { supportsFetch } from '@sentry/utils/supports';
55
import { Raven } from './raven';
66
import { FetchTransport, XHRTransport } from './transports';
77

packages/browser/src/integrations/onunhandledrejection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { captureException } from '@sentry/minimal';
22
import { Integration } from '@sentry/types';
3-
import { getGlobalObject } from '@sentry/utils';
3+
import { getGlobalObject } from '@sentry/utils/misc';
44

55
const global: any = getGlobalObject();
66

packages/browser/src/integrations/tracekit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isError, isErrorEvent } from '@sentry/utils/dist/is';
1+
import { isError, isErrorEvent } from '@sentry/utils/is';
22

33
/*
44
TraceKit - Cross brower stack traces

packages/browser/src/transports/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Transport,
66
TransportOptions,
77
} from '@sentry/types';
8-
import { urlEncode } from '@sentry/utils';
8+
import { urlEncode } from '@sentry/utils/object';
99

1010
/** Base Transport class implementation */
1111
export abstract class BaseTransport implements Transport {

packages/browser/src/transports/fetch.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { SentryEvent } from '@sentry/types';
2-
import {
3-
getGlobalObject,
4-
serialize,
5-
supportsReferrerPolicy,
6-
} from '@sentry/utils';
2+
import { getGlobalObject } from '@sentry/utils/misc';
3+
import { serialize } from '@sentry/utils/object';
4+
import { supportsReferrerPolicy } from '@sentry/utils/supports';
75
import { BaseTransport } from './base';
86

97
const global: any = getGlobalObject();

packages/browser/src/transports/xhr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SentryEvent } from '@sentry/types';
2-
import { serialize } from '@sentry/utils';
2+
import { serialize } from '@sentry/utils/object';
33
import { BaseTransport } from './base';
44

55
/** `XHR` based transport */

packages/core/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/core/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,17 @@
4040
"fix:tslint": "tslint --fix -t stylish -p .",
4141
"test": "jest",
4242
"test:watch": "jest --watch --notify"
43+
},
44+
"jest": {
45+
"collectCoverage": true,
46+
"transform": { "^.+\\.ts$": "ts-jest" },
47+
"moduleFileExtensions": ["js", "ts"],
48+
"testEnvironment": "node",
49+
"testMatch": ["**/*.test.ts"],
50+
"globals": {
51+
"ts-jest": {
52+
"tsConfigFile": "./tsconfig.json"
53+
}
54+
}
4355
}
4456
}

packages/core/src/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Scope } from '@sentry/hub';
22
import { Breadcrumb, SdkInfo, SentryEvent } from '@sentry/types';
3-
import { truncate, uuid4 } from '@sentry/utils';
3+
import { uuid4 } from '@sentry/utils/misc';
4+
import { truncate } from '@sentry/utils/string';
45
import { DSN } from './dsn';
56
import { Backend, Client, Options } from './interfaces';
67
import { SendStatus } from './status';

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { TEST_SDK, TestClient } from '../mocks/client';
66

77
const PUBLIC_DSN = 'https://username@domain/path';
88

9-
jest.mock('@sentry/utils', () => ({
9+
jest.mock('@sentry/utils/misc', () => ({
1010
uuid4(): string {
1111
return '42';
1212
},
13+
}));
14+
15+
jest.mock('@sentry/utils/string', () => ({
1316
truncate(str: string): string {
1417
return str;
1518
},

packages/hub/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/hub/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@
3737
"fix:tslint": "tslint --fix -t stylish -p .",
3838
"test": "jest",
3939
"test:watch": "jest --watch --notify"
40+
},
41+
"jest": {
42+
"collectCoverage": true,
43+
"transform": { "^.+\\.ts$": "ts-jest" },
44+
"moduleFileExtensions": ["js", "ts"],
45+
"testEnvironment": "node",
46+
"testMatch": ["**/*.test.ts"],
47+
"globals": {
48+
"ts-jest": {
49+
"tsConfigFile": "./tsconfig.json"
50+
}
51+
}
4052
}
4153
}

packages/minimal/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/minimal/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,17 @@
3838
"fix:tslint": "tslint --fix -t stylish -p .",
3939
"test": "jest",
4040
"test:watch": "jest --watch --notify"
41+
},
42+
"jest": {
43+
"collectCoverage": true,
44+
"transform": { "^.+\\.ts$": "ts-jest" },
45+
"moduleFileExtensions": ["js", "ts"],
46+
"testEnvironment": "node",
47+
"testMatch": ["**/*.test.ts"],
48+
"globals": {
49+
"ts-jest": {
50+
"tsConfigFile": "./tsconfig.json"
51+
}
52+
}
4153
}
4254
}

packages/node/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/node/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@
4242
"fix:tslint": "tslint --fix -t stylish -p .",
4343
"test": "jest",
4444
"test:watch": "jest --watch --notify"
45+
},
46+
"jest": {
47+
"collectCoverage": true,
48+
"transform": { "^.+\\.ts$": "ts-jest" },
49+
"moduleFileExtensions": ["js", "ts"],
50+
"testEnvironment": "node",
51+
"testMatch": ["**/*.test.ts"],
52+
"globals": {
53+
"ts-jest": {
54+
"tsConfigFile": "./tsconfig.json"
55+
}
56+
}
4557
}
4658
}

packages/node/src/integrations/console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addBreadcrumb } from '@sentry/minimal';
22
import { Integration, Severity } from '@sentry/types';
3-
import { fill } from '@sentry/utils';
3+
import { fill } from '@sentry/utils/object';
44
import { format } from 'util';
55

66
/**

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addBreadcrumb } from '@sentry/minimal';
22
import { Integration } from '@sentry/types';
3-
import { fill } from '@sentry/utils';
3+
import { fill } from '@sentry/utils/object';
44
import { ClientRequest, ClientRequestArgs, ServerResponse } from 'http';
55
import { inherits } from 'util';
66
import { getDefaultHub } from '../hub';

packages/typescript/tslint.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// This rule has side effects and must be disabled
55
"no-unused-variable": false,
66

7+
"no-submodule-imports": false,
8+
79
// We don't want these
810
"newline-before-return": false,
911
"no-any": false,

packages/utils/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js.map
2+
*.d.ts
3+
*.js

packages/utils/.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*
2-
!/dist/**/*
2+
!*.js.map
3+
!*.d.ts
4+
!*.js
5+
jest.config.js

packages/utils/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
[![npm dm](https://img.shields.io/npm/dm/@sentry/utils.svg)](https://www.npmjs.com/package/@sentry/utils)
1212
[![npm dt](https://img.shields.io/npm/dt/@sentry/utils.svg)](https://www.npmjs.com/package/@sentry/utils)
1313

14-
Common utilities used by the Sentry JavaScript SDKs.
14+
Common utilities used by the Sentry JavaScript SDKs. **Warning, only submodule
15+
imports are allowed here.**

packages/utils/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/utils/package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"types": "dist/index.d.ts",
1412
"publishConfig": {
1513
"access": "public"
1614
},
@@ -29,7 +27,7 @@
2927
},
3028
"scripts": {
3129
"build": "tsc -p tsconfig.build.json",
32-
"clean": "rimraf dist coverage",
30+
"clean": "rimraf dist coverage *.js *.js.map *.d.ts",
3331
"lint": "run-s lint:prettier lint:tslint",
3432
"lint:prettier": "prettier-check '{src,test}/**/*.ts'",
3533
"lint:tslint": "tslint -t stylish -p .",
@@ -38,5 +36,17 @@
3836
"fix:tslint": "tslint --fix -t stylish -p .",
3937
"test": "jest",
4038
"test:watch": "jest --watch --notify"
39+
},
40+
"jest": {
41+
"collectCoverage": true,
42+
"transform": { "^.+\\.ts$": "ts-jest" },
43+
"moduleFileExtensions": ["js", "ts"],
44+
"testEnvironment": "node",
45+
"testMatch": ["**/*.test.ts"],
46+
"globals": {
47+
"ts-jest": {
48+
"tsConfigFile": "./tsconfig.json"
49+
}
50+
}
4151
}
4252
}

packages/utils/src/index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
export { forget, filterAsync } from './async';
2-
export { mkdirp, mkdirpSync } from './fs';
3-
export { clone, deserialize, fill, serialize, urlEncode } from './object';
4-
export { Store } from './store';
5-
export { isError, isErrorEvent, isDOMError, isDOMException } from './is';
6-
export { truncate } from './string';
7-
export {
8-
supportsDOMError,
9-
supportsDOMException,
10-
supportsErrorEvent,
11-
supportsFetch,
12-
supportsReferrerPolicy,
13-
} from './supports';
14-
export { getGlobalObject, uuid4 } from './misc';
1+
// We do not export anything by default since we always want to deep import
2+
// like: import { getGlobalObject } from '@sentry/utils/misc';

packages/utils/src/object.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ export function fill(
137137
): void {
138138
const orig = source[name];
139139
source[name] = replacement(orig);
140+
// tslint:disable-next-line:no-unsafe-any
140141
source[name].__raven__ = true;
142+
// tslint:disable-next-line:no-unsafe-any
141143
source[name].__orig__ = orig;
142144
if (track) {
143145
track.push([source, name, orig]);
@@ -152,6 +154,9 @@ export function fill(
152154
*/
153155
export function urlEncode(object: { [key: string]: any }): string {
154156
return Object.keys(object)
155-
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`)
157+
.map(
158+
// tslint:disable-next-line:no-unsafe-any
159+
key => `${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`,
160+
)
156161
.join('&');
157162
}

packages/utils/test/async.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { filterAsync, forget } from '../src';
1+
import { filterAsync, forget } from '../src/async';
22

33
describe('forget', () => {
44
const console = {

packages/utils/test/is.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1+
import { isDOMError, isDOMException, isError, isErrorEvent } from '../src/is';
12
import {
2-
isDOMError,
3-
isDOMException,
4-
isError,
5-
isErrorEvent,
63
supportsDOMError,
74
supportsDOMException,
85
supportsErrorEvent,
9-
} from '../src';
6+
} from '../src/supports';
107

118
class SentryError extends Error {
129
public name: string;

0 commit comments

Comments
 (0)