Skip to content

Commit 0e60acb

Browse files
Lms24onurtemizkan
authored andcommitted
fix(angular): Use Angular compiler to compile @sentry/angular (#4641)
* switch from tsc to the Angular compiler to compile our Angular SDK. This is done via the Angular CLI which internally uses ngc and ng-packagr to build and package our SDK correctly so that the Angular runtime can process all SDK components (including TraceDirective) correctly. * important: This is a breaking change as it requires SDK users to use Angular >= 10. Currently, our SDK might support earlier Angular versions despite the fact that we only list Angular 10-13 as peer dependencies of the SDK. With this new compiler, applications using the Sentry Angular SDK on earlier versions than Angular 10 will not be able to compile correctly. * change some yarn scripts by making the Angular compiler the default builder
1 parent d556330 commit 0e60acb

9 files changed

+2891
-276
lines changed

Diff for: packages/angular/angular.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* To learn more about this file see: https://angular.io/guide/workspace-config */
2+
{
3+
"$schema": "../../node_modules/@angular/cli/lib/config/schema.json",
4+
"version": 1, // version of angular.json
5+
"projects": {
6+
"sentry-angular": {
7+
"projectType": "library",
8+
"root": ".",
9+
"sourceRoot": "src",
10+
"architect": {
11+
"build": {
12+
"builder": "@angular-devkit/build-angular:ng-packagr",
13+
"options": {
14+
"tsConfig": "tsconfig.ngc.json",
15+
"project": "ng-package.json"
16+
},
17+
"configurations": {
18+
"production": {
19+
"tsConfig": "tsconfig.ngc.json"
20+
}
21+
}
22+
}
23+
}
24+
}
25+
},
26+
"defaultProject": "sentry-angular"
27+
}

Diff for: packages/angular/ng-package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "build",
4+
"lib": {
5+
"entryFile": "src/index.ts",
6+
"umdModuleIds": {
7+
"@sentry/browser": "Sentry",
8+
"@sentry/utils": "Sentry.util"
9+
}
10+
},
11+
"whitelistedNonPeerDependencies": ["@sentry/browser", "@sentry/utils", "@sentry/types", "tslib"],
12+
"assets": ["README.md", "LICENSE"]
13+
}

Diff for: packages/angular/package.json

+20-22
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,43 @@
99
"engines": {
1010
"node": ">=8"
1111
},
12-
"main": "cjs/index.js",
13-
"module": "esm/index.js",
14-
"types": "build/types/index.d.ts",
12+
"main": "build/bundles/sentry-angular.umd.js",
13+
"module": "build/fesm2015/sentry-angular.js",
1514
"publishConfig": {
1615
"access": "public"
1716
},
1817
"peerDependencies": {
1918
"@angular/common": "10.x || 11.x || 12.x || 13.x",
2019
"@angular/core": "10.x || 11.x || 12.x || 13.x",
21-
"@angular/router": "10.x || 11.x || 12.x || 13.x"
20+
"@angular/router": "10.x || 11.x || 12.x || 13.x",
21+
"rxjs": "^6.5.5 || ^7.x"
2222
},
2323
"dependencies": {
2424
"@sentry/browser": "7.0.0-alpha.1",
2525
"@sentry/types": "7.0.0-alpha.1",
2626
"@sentry/utils": "7.0.0-alpha.1",
27-
"rxjs": "^6.6.0",
28-
"tslib": "^1.9.3"
27+
"tslib": "^2.0.0"
2928
},
3029
"devDependencies": {
31-
"@angular/common": "^10.0.3",
32-
"@angular/core": "^10.0.3",
33-
"@angular/router": "^10.0.3"
30+
"@angular-devkit/build-angular": "~0.1002.4",
31+
"@angular/cli": "^10.2.4",
32+
"@angular/common": "~10.2.5",
33+
"@angular/compiler": "^10.2.5",
34+
"@angular/compiler-cli": "~10.2.5",
35+
"@angular/core": "~10.2.5",
36+
"@angular/router": "~10.2.5",
37+
"ng-packagr": "^10.1.0",
38+
"typescript": "~4.0.2"
3439
},
3540
"scripts": {
36-
"build": "run-p build:cjs build:esm build:types",
37-
"build:cjs": "tsc -p tsconfig.cjs.json",
41+
"build": "yarn build:ngc",
42+
"build:ngc": "ng build --prod",
3843
"build:dev": "run-s build",
39-
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
40-
"build:esm": "tsc -p tsconfig.esm.json",
41-
"build:types": "tsc -p tsconfig.types.json",
42-
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
43-
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
44-
"build:dev:watch": "run-s build:watch",
45-
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
46-
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
47-
"build:types:watch": "tsc -p tsconfig.types.json --watch",
48-
"build:npm": "npm pack",
44+
"build:watch": "run-p build:ngc:watch",
45+
"build:ngc:watch": "ng build --prod --watch",
46+
"build:npm": "npm pack ./build",
4947
"circularDepCheck": "madge --circular src/index.ts",
50-
"clean": "rimraf cjs esm build coverage",
48+
"clean": "rimraf build coverage",
5149
"fix": "run-s fix:eslint fix:prettier",
5250
"fix:eslint": "eslint . --format stylish --fix",
5351
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.ts\"",

Diff for: packages/angular/src/errorhandler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpErrorResponse } from '@angular/common/http';
2-
import { ErrorHandler as AngularErrorHandler, Injectable } from '@angular/core';
2+
import { ErrorHandler as AngularErrorHandler, Inject, Injectable } from '@angular/core';
33
import * as Sentry from '@sentry/browser';
44

55
import { runOutsideAngular } from './zone';
@@ -26,7 +26,7 @@ export interface ErrorHandlerOptions {
2626
class SentryErrorHandler implements AngularErrorHandler {
2727
protected readonly _options: ErrorHandlerOptions;
2828

29-
public constructor(options?: ErrorHandlerOptions) {
29+
public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) {
3030
this._options = {
3131
logErrors: true,
3232
...options,

Diff for: packages/angular/tsconfig.cjs.json

-8
This file was deleted.

Diff for: packages/angular/tsconfig.esm.json

-8
This file was deleted.

Diff for: packages/angular/tsconfig.ngc.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
// This tsconfig is used when building @sentry/angular with the Angular
3+
// compiler and `ng-packagr`. It configures a production build conforming
4+
// to the Angular Package Format (APF).
5+
{
6+
"extends": "./tsconfig.json",
7+
"compilerOptions": {
8+
"target": "es2015",
9+
"lib": ["dom", "es2015"],
10+
"baseUrl": "./"
11+
},
12+
"angularCompilerOptions": {
13+
"skipTemplateCodegen": true,
14+
"strictMetadataEmit": true,
15+
"enableResourceInlining": true,
16+
"strictInjectionParameters": true,
17+
"strictInputAccessModifiers": true,
18+
"strictTemplates": true,
19+
// As per Angular 10, the recommendation from the library creation guide
20+
// is to disable compilation for the Ivy rendering engine in production builds
21+
// to ensure compatibility with Angular 10.
22+
// For Angular 11-13 applications, ngcc and the Angular linker convert the compiled JS
23+
// at application compile time into an Ivy-compatible version which is then further used in
24+
// the build process. This ensures compatibility with newer Angular versions than the one
25+
// that was used to initially compile the library (Angular 10 in our case).
26+
"enableIvy": false
27+
}
28+
}

Diff for: packages/angular/tsconfig.types.json

-10
This file was deleted.

0 commit comments

Comments
 (0)