-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(angular): Use Angular compiler to compile @sentry/angular #4641
Conversation
d9d39ad
to
b7d551e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick pass through, when this is properly ready to review lmk and I'll dive in!
Added some information and still open question to the PR description |
A few questions about the PR description (which overall is very thorough and helpful - nice job!):
Is this meant to point somewhere else, or is this copy pasta from somewhere else pointing to here?
I think this should now be
Same here? Also, the repo uses yarn as our package manager/script runner, so probably more idiomatic to |
Yes. I've added it to my list of changes. |
Yes. No reason why consumers of the SDK need our scripts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak to the angular-specific bits, but overall this looks pretty reasonable.
Whoops, this should have linked to #4644. Changed it.
Yes, fixed.
Right, also fixed.
Cool, thanks for the review! |
Corrected some yarn commands in PR description ( |
Have you found |
I thought so, too but |
Ohhhhh. Because |
I agree, another name for the script would be great (thinking about |
* rename the `pack` npm scripts in all `package.json`s to `build:npm`. Previously, these `pack` scripts could cause confusion in connection with yarn, as `yarn pack` and `yarn run pack` would do different things: While running the former would trigger the pack command of yarn (as in `npm pack`), the latter would execute whatever is defined in the resp. `package.json` under `pack`. Up to recently, this difference was not noticeable in most SDKs because the `pack` npm script would simply be `npm pack`. However, given that we're moving everything build-related into its own `build` directory (#4688, #4641), the pack script must point to the `package.json` inside `build`. As a consequence, `yarn run pack` and `yarn pack` will behave differently which can cause confusion when creating a tarball. * `yarn (run) build:npm` will create an NPM package (tarball). Besides modifying all SDK `package.json`s, this PR also adjusts the packing script in the root-level `package.json` and hence in the the packaging command in the `build.yml` file. * The motivation for making this change emerged after a [conversation about adjusting `yarn pack` to `yarn run pack` ](#4641 (comment)) to get a correct tarball.
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
un-stale |
…other SDKs includes deletion of .npmignore and the addition of `scripts/postbuild.ts` to make a few adjustments to folder structure and the shipped `package.json`
22dace4
to
e058520
Compare
size-limit report 📦
|
3cfb58a
to
cfac731
Compare
Revisited and updated this PR so that it can be merged into |
* 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
* 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
* 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
* 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
* 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
* 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
Add a new SDK package to our monorepo: `@sentry/angular-ivy`. While this is technically a new SDK, its content and functionality is identical to `@sentry/angular`. Only the build configuration differs: * The Ivy SDK is built with Angular 12, allowing for a compatibility of NG12-15 * The Ivy SDK is built with `compilationMode: partial`, enabeling a build format that is compatible with Angular's Ivy rendering engine. * This means that `ngcc` no longer needs to step in at initial build time to up-compile the SDK. Which is good because `ngcc` will be removed in Angular 16 (angular/angular-cli#24720) * The Ivy SDK's build output follows the Angular Package Format (APF) v12 standard ([spec](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview)) which is very similar to APF 10 which we used before (see #4641 for more details) Because functionality-wise there's no difference to `@sentry/angular`, I opted to symlink the source files instead of duplicating them. The only exception is `sdk.ts` which needed some adaption for the new package, like setting the SDK name and adjusting the min version check. For the same reason, this new package currently doesn't contain tests. We'll need to reconsider this approach (symlinking and testing) if we ever need to make package-specific adjustments.
Background
As brought to attention in #3282, our Angular SDK currently causes a compiler error when including
TraceDirective
(orTraceModule
) in an Angular application.Problem
The root cause for this problem is that the Angular SDK (as most our SDKs) is currently compiled with
tsc
. While this works fine for regular library interaction, it is a problem for Angular specific SDK items, such asTraceDirective
orTraceModule
. The reason is thattsc
treats these classes (and their decorators) like a normal typescript file and compiles them with the experimental decorators to JS. Angular and the Angular Runtime however, need a specific format whichtsc
does not deliver. A more detailed explanation on the compiler differences is given in #4644.Upon application compilation, the Angular compiler notices that
TraceDirective
is not compiled correctly and thus raises the compiler error mentioned in the issue.Solution
The solution is to switch from
tsc
to the Angular compiler to compile our Angular SDK. This is done via the Angular CLI which internally usesngc
andng-packagr
to build and package our SDK correctly so that the Angular runtime can process all SDK components (includingTraceDirective
) 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.
Angular compiler and APF
The angular compiler is added to this project via several devDependencies, including the Angular CLI which serves as a top level wrapper around
ngc
andng-packagr
. We use the CLI in our NPM scripts to build the library. The resulting build structure conforms to the Angular Package Format (AFP) v10. Basically, the NPM scriptbuild
triggers theng build --prod
command which creates a production build adhering to the APF. As a consequence, the package format of this SDK now differs significantly from our other SDKs (or from the current@sentry/angular
SDK:The main point in which the APF differs from our current packaging procedure:
Everything that should go into the NPM tarball is first compiled by
ngc
and then packaged and copied tobuild
byng-packagr
. This means, we do not useprepack.ts
to make changes to the central build directory like in most other SDKs.Building
This PR changes some yarn scripts by making the Angular compiler the default builder
and providing a "legacy" option to build and pack a.tsc
-compiled packageNote: These NPM scripts are a proposal and their applicability remains TBD at the moment!
yarn build
builds APF conform JS with the Angular compiler to./build
.yarn build:legacy
builds CJS and ESM modules withtsc
to./dist
and./esm
respectivelyboth compilersthe angular compiler by adding:watch
to the commandyarn build:npm
creates atgz
archive from the APF build in.
yarn build:npm:legacy
creates atgz
from thetsc
build in.
EDIT: We decided to hold off from creating a legacy package for the moment.
A note on
package.json
When running
yarn build
, everything is built withngc
and packaged withng-packagr
into one directory, namely./build
. During packaging,ng-packagr
will take the originalpackage.json
, make some changes to it and write the new version to./build/package.json
. The made changes are related to the entry points and they differ as follows:main
andmodule
no longer point toesm
anddist
resp. but tobundles
typings
is newly introduced and points to the generatedd.ts
entry file (sentry-angular.d.ts
)es2015
andfesm2015
are newly introduced and point to./fesm2015
esm2015
is newly introduced and points to./esm2015
metadata
is newly introduced and points tosentry-angular.metadata.json
which contains some Angular AOT compilation metadataTesting
As of this moment, there are no unit or integration tests available for
@sentry/angular
.What I primarily did to test this was to create four Angular projects (versions 10-13) and install the tgz NPM package locally to these projects.
These very basic applications can 1) throw sample errors, 2) create custom spans and 3) test
TraceDirectve
to ensure compatiblity.Caution when using
yarn link
: Given that at application compile time, the angular CLI will usengcc
or the Angular linker to modify the JS files from the built SDK to make it compatible with the application's Angular version, symlinking to the built JS will change the files there. This will become problematic when testing with multiple Angular versions as compiler errors will emerge. Hence, it is in this case easier to useyarn install ./path/to/tgz/file
which will actually install the library in the applicationsnode_modules
folder.fixes #3282
fixes #4644
ref: https://getsentry.atlassian.net/browse/WEB-622
ref: https://getsentry.atlassian.net/browse/WEB-852