Skip to content

Commit dcf411b

Browse files
authored
Merge pull request #3 from jeremypele/master
Fix Angular Package + Update discardUncaughtJsExceptions
2 parents c56eb24 + b14b940 commit dcf411b

File tree

13 files changed

+2130
-31
lines changed

13 files changed

+2130
-31
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ import { SentryModule } from 'nativescript-sentry/angular';
4545
NgModule({
4646
// ...
4747
imports: [
48-
SentryModule.forRoot({dsn: 'https://<key>:<secret>@host/<project>'})
49-
],
48+
SentryModule.forRoot({
49+
dsn: 'https://<key>:<secret>@host/<project>',
50+
discardUncaughtJsExceptions: true
51+
})
52+
]
5053
// ...
51-
})
54+
});
5255
```
5356

5457
**Note:** this plugin adds a custom ErrorHandler to your angular app
@@ -180,6 +183,7 @@ in the dependencies. See the [demo app](/demo/app/App_Resources/Android/app.grad
180183
## Demo Apps
181184

182185
To run and test the demo apps you need to replace the placeholder `__YOUR_DSN_HERE__` by your own DSN in the following files:
186+
183187
- demo/App_Resources/Android/src/main/AndroidManifest.xml
184188
- demo/app/app.ts
185189
- demo-ng/App_Resources/Android/src/main/AndroidManifest.xml
@@ -203,7 +207,7 @@ Thanks to [@bradmartin](https://github.com/bradmartin)!
203207

204208
- Fix GitHub Workflow to use existing publishing scripts
205209

206-
### 1.10.1 – (17.04.2020)
210+
### 1.10.1 – (17.04.2020)
207211

208212
- Set up GitHub Workflow for npm publising
209213

demo-ng/src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { HomeComponent } from './home.component';
1111
NativeScriptModule,
1212
AppRoutingModule,
1313
SentryModule.forRoot({
14-
dsn: '__YOUR_DSN_HERE__'
14+
dsn: '__YOUR_DSN_HERE__',
15+
discardUncaughtJsExceptions: false
1516
})
1617
],
1718
declarations: [AppComponent, HomeComponent],

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

publish/pack.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pack() {
2929
echo 'Building /src...'
3030
cd "$TO_SOURCE_DIR"
3131
node_modules/.bin/tsc
32+
node_modules/.bin/ngc -skipLibCheck --project tsconfig.aot.json --outDir ./
3233
cd ..
3334

3435
echo 'Creating package...'

src/angular/app.module.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { InjectionToken, ModuleWithProviders } from '@angular/core';
22
import { SentryErrorHandler } from './error.handler';
33
export interface SentryConfig {
44
dsn: string;
5+
discardUncaughtJsExceptions?: boolean;
56
}
67
export declare const SentryService: InjectionToken<SentryConfig>;
78
export declare class SentryModule {

src/angular/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SentryErrorHandler } from './error.handler';
33

44
export interface SentryConfig {
55
dsn: string;
6+
discardUncaughtJsExceptions?: boolean;
67
}
78

89
export const SentryService = new InjectionToken<SentryConfig>('SentryConfig');

src/angular/error.handler.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ErrorHandler } from '@angular/core';
2-
export declare class SentryErrorHandler extends ErrorHandler {
3-
private config;
4-
private _discardUncaughtJsExceptions;
5-
constructor(config: any);
2+
export declare class SentryErrorHandler implements ErrorHandler {
3+
private _config;
4+
constructor(_config: any);
65
handleError(err: any): void;
76
private _setDSN;
8-
private _setDiscardUncaughtJsExceptions;
97
}

src/angular/error.handler.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import { Sentry } from '../';
33
import { SentryService } from './app.module';
44

55
@Injectable()
6-
export class SentryErrorHandler extends ErrorHandler {
7-
private _discardUncaughtJsExceptions: boolean = false;
8-
9-
constructor(@Inject(SentryService) private config) {
10-
super();
6+
export class SentryErrorHandler implements ErrorHandler {
7+
constructor(@Inject(SentryService) private _config) {
118
this._setDSN();
12-
this._setDiscardUncaughtJsExceptions();
139
}
1410

1511
handleError(err): void {
@@ -19,7 +15,7 @@ export class SentryErrorHandler extends ErrorHandler {
1915
console.log('[NativeScript-Sentry - SentryErrorHandler]', e);
2016
}
2117

22-
if (this._discardUncaughtJsExceptions) return;
18+
if (this._config?.discardUncaughtJsExceptions) return;
2319
throw err;
2420
}
2521

@@ -28,19 +24,10 @@ export class SentryErrorHandler extends ErrorHandler {
2824
*/
2925

3026
private _setDSN() {
31-
if (this.config && this.config.dsn) {
32-
Sentry.init(this.config.dsn);
27+
if (this._config?.dsn) {
28+
Sentry.init(this._config.dsn);
3329
} else {
3430
throw '[SentryAngular]: You need to provide your dsn on the forRoot method';
3531
}
3632
}
37-
38-
private _setDiscardUncaughtJsExceptions() {
39-
try {
40-
const packageJSON = require('~/package.json');
41-
if (packageJSON && packageJSON.discardUncaughtJsExceptions) {
42-
this._discardUncaughtJsExceptions = packageJSON.discardUncaughtJsExceptions;
43-
}
44-
} catch (e) {}
45-
}
4633
}

src/angular/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "nativescript-sentry",
3+
"ngPackage": {
4+
"lib": {
5+
"entryFile": "index.ts",
6+
"umdModuleIds": {
7+
"@nativescript/core": "ns-core",
8+
"@nativescript/angular": "ns-angular",
9+
"nativescript-sentry": "ns-sentry"
10+
}
11+
},
12+
"whitelistedNonPeerDependencies": [
13+
"."
14+
]
15+
},
16+
"scripts": {
17+
"build": "npm i && ng-packagr -p package.json && cd dist && cpy '**/*' '.' --parents",
18+
"clean": "npx rimraf node_modules dist package-lock.json -- *.js"
19+
},
20+
"devDependencies": {
21+
"@angular/compiler-cli": "~10.0.0",
22+
"@angular/common": "~10.0.0",
23+
"@angular/compiler": "~10.0.0",
24+
"@angular/core": "~10.0.0",
25+
"@angular/platform-browser": "~10.0.0",
26+
"@angular/platform-browser-dynamic": "~10.0.0",
27+
"@angular/router": "~10.0.0",
28+
"@nativescript/angular": "~10.0.0",
29+
"@nativescript/core": "~7.0.0",
30+
"cpy-cli": "~3.1.1",
31+
"nativescript-sentry": "file:../src",
32+
"ng-packagr": "~10.0.0",
33+
"rxjs": "^6.6.0",
34+
"tslint": "^5.14.0",
35+
"typescript": "~3.9.0",
36+
"zone.js": "^0.10.3"
37+
}
38+
}

0 commit comments

Comments
 (0)