Skip to content
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

Typescript Core/Browser implementation #1149

Merged
merged 63 commits into from
Dec 7, 2017
Merged

Typescript Core/Browser implementation #1149

merged 63 commits into from
Dec 7, 2017

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented Nov 25, 2017

Proposal

This should become our Core for all our javascript related SDKs.
It's written in typescript to provide type safety BUT the javascript
API should also be easily human readable/usable.
You can take a look at core/lib/Client.ts for the implementation of the public API.
Also core/__tests__/client.ts shows a way of how to use it.

Structure

There is our core package called @sentry/core.
@sentry/browser is one adapter to use with the core.
Currently it's just wrapping raven-js until we decide to rewrite it.
Also, our react-native or the new Cordova SDK should build on this architecture.

@HazAT HazAT requested review from mitsuhiko and jan-auer November 29, 2017 13:20
Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

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

Seriously, awesome work Daniel! 🥇

Due to the size of this PR, I have a higher number of comments as well. Most of this is opinionated and or just minor stuff, but I'd like to discuss the bigger ones before this gets merged.

@@ -0,0 +1,18 @@
{
"[typescript]": {
Copy link
Member

Choose a reason for hiding this comment

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

I'd also add editor.rulers and editor.tabSize here.

"clean": "rm -rf ./dist",
"dist": "npm run clean && tsc -p tsconfig.json && npm run build-browser",
"test": "npm run dist && jest --forceExit",
"test:watch": "npm run dist && jest --watch --notify"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't really make sense as you have to re-run dist on changes, no?

"engines": {
"node": ">=6.9.5 <9.0.0",
"npm": ">=3.10.7 <6.0.0",
"yarn": ">=1.0.2 <2.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

Pinning npm and yarn this restrictively might cause pain once they release a new major version and there are no incompatibilities. Same goes for node - v9 and v10 are already in development and should actually work perfectly fine... Is there a specific reason you specify an upper bound?


describe('Browser Interface', () => {
test('sending a message', async done => {
let countExcpects = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Typo: countExpects


constructor(client: Client, public options: IBrowserOptions = {}) {
this.client = client;
return this;
Copy link
Member

Choose a reason for hiding this comment

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

No need to return this here.

context[key] = value;
}

export function merge<T extends IContext, K extends keyof T>(
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion: I'd call it mergeIn, as merge usually refers to shallow-merging all keys of two or more objects.

set(context, key, {});
}
if (value === undefined) {
delete context[key];
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure you want this behavior? Usually merge or assign functions as well as the object spread operator ignore sources that are falsy.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I took this merge function basically from raven-js and I guess we want to keep the same logic.

}

export class SentryError implements Error {
public name = 'SentryError';
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this implicitly defined if you extend Error?

"test": "npm run dist && jest",
"test:watch": "jest --watch --notify"
},
"jest": {
Copy link
Member

Choose a reason for hiding this comment

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

By default, jest applies the "jsdom" environment which essentially polyfills some browser APIs. However, this means that even though your tests pass, the code might not run in an actual node process. However, since you want to run it in both the browser and node, it might make sense to run tests in both environments and use the --env option to switch between them. If you don't want to do this, declare "testEnvironment": "node" here as this is more of a common demeanor.

Example for running both (needs npm-run-all as devDependency):

{
  "dist": "npm run clean && tsc -p tsconfig.json",
  "test:browser": "jest --env=jsdom",
  "test:node": "jest --env=node",
  "test": "npm-run-all dist test:browser test:node"
}

],
"lib": ["es2015", "dom"],
"declaration": false,
"allowJs": true,
Copy link
Member

Choose a reason for hiding this comment

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

@sentry/core uses false here. Purpose?

@HazAT
Copy link
Member Author

HazAT commented Nov 29, 2017

thumb_mother-of-god-meme

@HazAT
Copy link
Member Author

HazAT commented Dec 5, 2017

Note:
We cannot use yarn workspaces yet since it requires the root package.json to be private:true.

yarn install v1.3.2
info No lockfile found.
error Workspaces can only be enabled in private projects
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

@HazAT
Copy link
Member Author

HazAT commented Dec 6, 2017

I don't know why but travis has a hard time with this PR
It works without problems in my fork: https://travis-ci.org/HazAT/raven-js

@jan-auer
Copy link
Member

jan-auer commented Dec 6, 2017

🚀 it

@HazAT HazAT merged commit 5d2685f into getsentry:master Dec 7, 2017
@jan-auer
Copy link
Member

jan-auer commented Dec 7, 2017

🎉 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants