Skip to content

Commit b73d9e9

Browse files
cromefireHazAT
authored andcommitted
feat: esm build (#1779)
* Added esm build and fixed some minor issues Signed-off-by: cromefire <[email protected]> * Fixed some ones prettier mismatch Signed-off-by: cromefire <[email protected]> * Utils es5 only Signed-off-by: cromefire <[email protected]> * esm for utils and import rewrites Signed-off-by: cromefire <[email protected]> * improved and documented rewrite regex Signed-off-by: cromefire <[email protected]> * Removed arrow function to support node 6 Signed-off-by: cromefire <[email protected]> * Trying to fix node 6 problem Signed-off-by: cromefire <[email protected]> * Added readme entry Signed-off-by: cromefire <[email protected]> * Mark as free of side-effects Signed-off-by: cromefire <[email protected]> * Fixed wrong bool value for side-effects Signed-off-by: cromefire <[email protected]> * Reordered .gitignore Signed-off-by: cromefire <[email protected]> * Removed as default for module builds Signed-off-by: cromefire <[email protected]> * Readded raven.js Signed-off-by: cromefire <[email protected]> * Added esm to browser .gitignore Signed-off-by: cromefire <[email protected]>
1 parent aff8415 commit b73d9e9

26 files changed

+184
-30
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules/
44
# build and test
55
build/
66
packages/*/dist/
7+
/packages/*/esm
78
coverage/
89
scratch/
910
*.pyc
@@ -27,3 +28,6 @@ lerna-debug.log
2728

2829
docs
2930
lint-results.json
31+
32+
# legacy
33+
!/packages/raven-js/dist

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ init({
7272
captureMessage('Hello, world!');
7373
```
7474

75+
If you want sentry to be customized for the browsers you want to support use the `esm` build:
76+
```javascript
77+
import { init, captureMessage } from '@sentry/browser/esm';
78+
```
79+
80+
and add it to your babel/... build, if you want to support older browsers
81+
82+
> TIP: You can use [`<script type="module" str="newbrowser.js">` +
83+
`<script nomodule src="oldbrowser.js">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#Module_Fallback)
84+
to provide builds for newer and older browsers
85+
7586
## Other Packages
7687

7788
Besides the high-level SDKs, this repository contains shared packages, helpers and configuration used for SDK

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"private": true,
33
"scripts": {
44
"build": "lerna run --stream --concurrency 1 --sort build",
5+
"build:es5": "lerna run --stream --concurrency 1 --sort build:es5",
6+
"build:esm": "lerna run --stream --concurrency 1 --sort build:esm",
57
"build:watch": "lerna run build:watch --stream --no-sort --concurrency 9999",
68
"clean": "lerna run --stream clean",
79
"fix": "lerna run --stream --concurrency 1 fix",
@@ -39,7 +41,7 @@
3941
"npm-run-all": "^4.1.2",
4042
"prettier": "^1.14.0",
4143
"prettier-check": "^2.0.0",
42-
"replace-in-file": "^3.4.0",
44+
"replace-in-file": "^3.4.2",
4345
"rimraf": "^2.6.2",
4446
"sinon": "^7.1.1",
4547
"ts-jest": "^23.10.5",

packages/browser/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*
22
!/dist/**/*
33
!/build/**/*
4+
!/esm/**/*

packages/browser/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/browser",
33
"version": "4.4.2",
44
"description": "Offical Sentry SDK for browsers",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/browser",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -52,7 +52,11 @@
5252
"webpack": "^4.26.0"
5353
},
5454
"scripts": {
55-
"build": "rollup --config",
55+
"build": "run-p build:esm build:es5",
56+
"build:es5": "rollup --config",
57+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
58+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
59+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
5660
"build:watch": "rollup --config --watch",
5761
"clean": "rimraf dist coverage .rpt2_cache build",
5862
"lint": "run-s lint:prettier lint:tslint",
@@ -71,5 +75,6 @@
7175
"size:check": "cat build/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print $1,\"kB\";}'",
7276
"version": "node ../../scripts/versionbump.js src/version.ts"
7377
},
74-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
78+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
79+
"sideEffects": false
7580
}

packages/browser/tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/core/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!/dist/**/*
3+
!/esm/**/*

packages/core/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/core",
33
"version": "4.4.2",
44
"description": "Base implementation for all Sentry JavaScript SDKs",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/core",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/core",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -31,7 +31,11 @@
3131
"typescript": "^3.2.0"
3232
},
3333
"scripts": {
34-
"build": "tsc -p tsconfig.build.json",
34+
"build": "run-p build:es5 build:esm",
35+
"build:es5": "tsc -p tsconfig.build.json",
36+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
37+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
38+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
3539
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3640
"clean": "rimraf dist coverage",
3741
"lint": "run-s lint:prettier lint:tslint",
@@ -64,5 +68,6 @@
6468
}
6569
}
6670
},
67-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
71+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
72+
"sideEffects": false
6873
}

packages/core/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ export function setupIntegration(integration: Integration, options: Options): vo
5757
} catch (_Oo) {
5858
/** @deprecated */
5959
// TODO: Remove in v5
60-
logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`);
6160

6261
// tslint:disable:deprecation
6362
if (integration.install) {
63+
logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`);
6464
integration.install(options);
6565
}
6666
// tslint:enable:deprecation

packages/core/src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface Options {
5050
* If this is set to false, default integrations will not be added, otherwise this will internally be set to the
5151
* recommended default integrations.
5252
*/
53-
defaultIntegrations?: boolean | Integration[];
53+
defaultIntegrations?: false | Integration[];
5454

5555
/**
5656
* List of integrations that should be installed after SDK was initialized.

packages/core/tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/hub/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!/dist/**/*
3+
!/esm/**/*

packages/hub/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/hub",
33
"version": "4.4.2",
44
"description": "Sentry hub which handles global state managment.",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/hub",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/hub",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -29,7 +29,11 @@
2929
"typescript": "^3.2.0"
3030
},
3131
"scripts": {
32-
"build": "tsc -p tsconfig.build.json",
32+
"build": "run-p build:es5 build:esm",
33+
"build:es5": "tsc -p tsconfig.build.json",
34+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
35+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
36+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
3337
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3438
"clean": "rimraf dist coverage",
3539
"lint": "run-s lint:prettier lint:tslint",
@@ -62,5 +66,6 @@
6266
}
6367
}
6468
},
65-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
69+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
70+
"sideEffects": false
6671
}

packages/hub/tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/minimal/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!/dist/**/*
3+
!/esm/**/*

packages/minimal/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/minimal",
33
"version": "4.4.2",
44
"description": "Sentry minimal library that can be used in other packages",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/minimal",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -29,7 +29,11 @@
2929
"typescript": "^3.2.0"
3030
},
3131
"scripts": {
32-
"build": "tsc -p tsconfig.build.json",
32+
"build": "run-p build:es5 build:esm",
33+
"build:es5": "tsc -p tsconfig.build.json",
34+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
35+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
36+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
3337
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3438
"clean": "rimraf dist coverage",
3539
"lint": "run-s lint:prettier lint:tslint",
@@ -62,5 +66,6 @@
6266
}
6367
}
6468
},
65-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
69+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
70+
"sideEffects": false
6671
}

packages/minimal/tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/node",
33
"version": "4.4.2",
44
"description": "Offical Sentry SDK for Node.js",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/node",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/node",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {

packages/types/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!/dist/**/*
3+
!/esm/**/*

packages/types/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/types",
33
"version": "4.4.2",
44
"description": "Types for all Sentry JavaScript SDKs",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/types",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -22,7 +22,11 @@
2222
"typescript": "^3.2.0"
2323
},
2424
"scripts": {
25-
"build": "tsc -p tsconfig.build.json",
25+
"build": "run-p build:es5 build:esm",
26+
"build:es5": "tsc -p tsconfig.build.json",
27+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
28+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
29+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
2630
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
2731
"lint": "run-s lint:prettier lint:tslint",
2832
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
@@ -32,5 +36,6 @@
3236
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
3337
"fix:tslint": "tslint --fix -t stylish -p ."
3438
},
35-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
39+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
40+
"sideEffects": false
3641
}

packages/types/tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/utils/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@sentry/utils",
33
"version": "4.4.2",
44
"description": "Utilities for all Sentry JavaScript SDKs",
5-
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/utils",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/utils",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -27,7 +27,11 @@
2727
"typescript": "^3.2.0"
2828
},
2929
"scripts": {
30-
"build": "run-s clean && tsc -p tsconfig.build.json",
30+
"build": "run-s clean && run-p build:es5 build:esm",
31+
"build:es5": "tsc -p tsconfig.build.json",
32+
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
33+
"build:esm:transpile": "tsc -p tsconfig.esm.json",
34+
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
3135
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
3236
"clean": "rimraf dist coverage *.js *.js.map *.d.ts",
3337
"lint": "run-s lint:prettier lint:tslint",
@@ -60,5 +64,6 @@
6064
}
6165
}
6266
},
63-
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
67+
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
68+
"sideEffects": false
6469
}

packages/utils/tsconfig.esm.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm",
6+
"rootDir": "src"
7+
},
8+
"exclude": [],
9+
"include": ["src/**/*.ts"]
10+
}

scripts/esm-rewrite.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { relative } = require('path');
2+
const replace = require('replace-in-file');
3+
4+
/**
5+
* capture group 1
6+
* `import/export [...] from [...]`
7+
*/
8+
const inExport = '(import|export)';
9+
/**
10+
* capture group 2
11+
* Either `import {x, y, z} from [...]`, `import xyz from [...]` or `import * as xyz from [...]`
12+
*/
13+
const thing = '({[a-zA-Z0-9,\\s]*}| *(\\* as )?[a-zA-Z] *)';
14+
/**
15+
* capture group 4
16+
* packages with esm modules
17+
*/
18+
const esmPkgs = `(${['browser', 'core', 'hub', 'minimal', 'types', 'utils'].join('|')})`;
19+
/**
20+
* `from '@sentry/pkg/dist/xyz';` > `from '@sentry/pkg/xyz';`
21+
*/
22+
const removeDist = '(/dist)?';
23+
/**
24+
* capture group 6
25+
* `from '@sentry/pkg/xyz';` > `from '@sentry/pkg/esm/xyz';`, if not already imported from esm
26+
*/
27+
const subPath = '(/(?!esm)[a-zA-Z0-9/]+)?';
28+
29+
const options = {
30+
files: `${process.cwd()}/esm/**/*.{js,d.ts}`,
31+
from: new RegExp(`${inExport} ${thing} from '@sentry/${esmPkgs}${removeDist}${subPath}';`, 'gm'),
32+
to: "$1 $2 from '@sentry/$4/esm$6';",
33+
};
34+
35+
const changes = replace.sync(options);
36+
37+
if ('VERBOSE' in process.env) {
38+
if (changes.length > 0) {
39+
const esmDir = `${process.cwd()}/esm`;
40+
console.log(`Imports rewritten to esm in:\n - ${changes.map(path => relative(esmDir, path)).join('\n - ')}`);
41+
} else {
42+
console.log('No imports rewritten');
43+
}
44+
}

0 commit comments

Comments
 (0)