Skip to content

Esm build #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 10, 2019
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules/
# build and test
build/
packages/*/dist/
/packages/*/esm
coverage/
scratch/
*.pyc
Expand All @@ -27,3 +28,6 @@ lerna-debug.log

docs
lint-results.json

# legacy
!/packages/raven-js/dist
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ init({
captureMessage('Hello, world!');
```

If you want sentry to be customized for the browsers you want to support use the `esm` build:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence (and the one below) sounds kinda confusing. I'd reword it somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I didn't come up with a better one, but if you have a better idea

```javascript
import { init, captureMessage } from '@sentry/browser/esm';
```

and add it to your babel/... build, if you want to support older browsers

> TIP: You can use [`<script type="module" str="newbrowser.js">` +
`<script nomodule src="oldbrowser.js">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#Module_Fallback)
to provide builds for newer and older browsers

## Other Packages

Besides the high-level SDKs, this repository contains shared packages, helpers and configuration used for SDK
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"private": true,
"scripts": {
"build": "lerna run --stream --concurrency 1 --sort build",
"build:es5": "lerna run --stream --concurrency 1 --sort build:es5",
"build:esm": "lerna run --stream --concurrency 1 --sort build:esm",
"build:watch": "lerna run build:watch --stream --no-sort --concurrency 9999",
"clean": "lerna run --stream clean",
"fix": "lerna run --stream --concurrency 1 fix",
Expand Down Expand Up @@ -39,7 +41,7 @@
"npm-run-all": "^4.1.2",
"prettier": "^1.14.0",
"prettier-check": "^2.0.0",
"replace-in-file": "^3.4.0",
"replace-in-file": "^3.4.2",
"rimraf": "^2.6.2",
"sinon": "^7.1.1",
"ts-jest": "^23.10.5",
Expand Down
1 change: 1 addition & 0 deletions packages/browser/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!/dist/**/*
!/build/**/*
!/esm/**/*
13 changes: 9 additions & 4 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/browser",
"version": "4.4.2",
"description": "Offical Sentry SDK for browsers",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/browser",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand Down Expand Up @@ -52,7 +52,11 @@
"webpack": "^4.26.0"
},
"scripts": {
"build": "rollup --config",
"build": "run-p build:esm build:es5",
"build:es5": "rollup --config",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "rollup --config --watch",
"clean": "rimraf dist coverage .rpt2_cache build",
"lint": "run-s lint:prettier lint:tslint",
Expand All @@ -71,5 +75,6 @@
"size:check": "cat build/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print $1,\"kB\";}'",
"version": "node ../../scripts/versionbump.js src/version.ts"
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions packages/browser/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm"
},
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions packages/core/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!/dist/**/*
!/esm/**/*
13 changes: 9 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/core",
"version": "4.4.2",
"description": "Base implementation for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/core",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/core",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand Down Expand Up @@ -31,7 +31,11 @@
"typescript": "^3.2.0"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage",
"lint": "run-s lint:prettier lint:tslint",
Expand Down Expand Up @@ -64,5 +68,6 @@
}
}
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
2 changes: 1 addition & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export function setupIntegration(integration: Integration, options: Options): vo
} catch (_Oo) {
/** @deprecated */
// TODO: Remove in v5
logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`);

// tslint:disable:deprecation
if (integration.install) {
logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`);
integration.install(options);
}
// tslint:enable:deprecation
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface Options {
* If this is set to false, default integrations will not be added, otherwise this will internally be set to the
* recommended default integrations.
*/
defaultIntegrations?: boolean | Integration[];
defaultIntegrations?: false | Integration[];

/**
* List of integrations that should be installed after SDK was initialized.
Expand Down
8 changes: 8 additions & 0 deletions packages/core/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm"
},
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions packages/hub/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!/dist/**/*
!/esm/**/*
13 changes: 9 additions & 4 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/hub",
"version": "4.4.2",
"description": "Sentry hub which handles global state managment.",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/hub",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/hub",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand All @@ -29,7 +29,11 @@
"typescript": "^3.2.0"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage",
"lint": "run-s lint:prettier lint:tslint",
Expand Down Expand Up @@ -62,5 +66,6 @@
}
}
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions packages/hub/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm"
},
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions packages/minimal/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!/dist/**/*
!/esm/**/*
13 changes: 9 additions & 4 deletions packages/minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/minimal",
"version": "4.4.2",
"description": "Sentry minimal library that can be used in other packages",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/minimal",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand All @@ -29,7 +29,11 @@
"typescript": "^3.2.0"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage",
"lint": "run-s lint:prettier lint:tslint",
Expand Down Expand Up @@ -62,5 +66,6 @@
}
}
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions packages/minimal/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm"
},
"include": ["src/**/*"]
}
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/node",
"version": "4.4.2",
"description": "Offical Sentry SDK for Node.js",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/node",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/node",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/types/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!/dist/**/*
!/esm/**/*
13 changes: 9 additions & 4 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/types",
"version": "4.4.2",
"description": "Types for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/types",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand All @@ -22,7 +22,11 @@
"typescript": "^3.2.0"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"lint": "run-s lint:prettier lint:tslint",
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
Expand All @@ -32,5 +36,6 @@
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"fix:tslint": "tslint --fix -t stylish -p ."
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
8 changes: 8 additions & 0 deletions packages/types/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm"
},
"include": ["src/**/*"]
}
13 changes: 9 additions & 4 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@sentry/utils",
"version": "4.4.2",
"description": "Utilities for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/utils",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/utils",
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
Expand All @@ -27,7 +27,11 @@
"typescript": "^3.2.0"
},
"scripts": {
"build": "run-s clean && tsc -p tsconfig.build.json",
"build": "run-s clean && run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage *.js *.js.map *.d.ts",
"lint": "run-s lint:prettier lint:tslint",
Expand Down Expand Up @@ -60,5 +64,6 @@
}
}
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d",
"sideEffects": false
}
10 changes: 10 additions & 0 deletions packages/utils/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm",
"rootDir": "src"
},
"exclude": [],
"include": ["src/**/*.ts"]
}
44 changes: 44 additions & 0 deletions scripts/esm-rewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { relative } = require('path');
const replace = require('replace-in-file');

/**
* capture group 1
* `import/export [...] from [...]`
*/
const inExport = '(import|export)';
/**
* capture group 2
* Either `import {x, y, z} from [...]`, `import xyz from [...]` or `import * as xyz from [...]`
*/
const thing = '({[a-zA-Z0-9,\\s]*}| *(\\* as )?[a-zA-Z] *)';
/**
* capture group 4
* packages with esm modules
*/
const esmPkgs = `(${['browser', 'core', 'hub', 'minimal', 'types', 'utils'].join('|')})`;
/**
* `from '@sentry/pkg/dist/xyz';` > `from '@sentry/pkg/xyz';`
*/
const removeDist = '(/dist)?';
/**
* capture group 6
* `from '@sentry/pkg/xyz';` > `from '@sentry/pkg/esm/xyz';`, if not already imported from esm
*/
const subPath = '(/(?!esm)[a-zA-Z0-9/]+)?';

const options = {
files: `${process.cwd()}/esm/**/*.{js,d.ts}`,
from: new RegExp(`${inExport} ${thing} from '@sentry/${esmPkgs}${removeDist}${subPath}';`, 'gm'),
to: "$1 $2 from '@sentry/$4/esm$6';",
};

const changes = replace.sync(options);

if ('VERBOSE' in process.env) {
if (changes.length > 0) {
const esmDir = `${process.cwd()}/esm`;
console.log(`Imports rewritten to esm in:\n - ${changes.map(path => relative(esmDir, path)).join('\n - ')}`);
} else {
console.log('No imports rewritten');
}
}
Loading