FusionAuth/fusionauth-javascript-sdk

[Angular] core package should be a bundled dependency

Closed this issue · 1 comments

[Angular] Core Package Should Be a Bundled Dependency

Situation

@fusionauth-sdk/core is a dependency of the three SDKs (React, Angular, Vue). We are using a monorepo to manage these SDKs because they share this framework-agnostic core logic.

Problem

We want to bundle the core package with each SDK for distribution since it's not listed on the npm registry. We use Vite to do this for React and Vue. Angular is slightly different in that @angular-devkit/build-angular:ng-packagr—the builder for Angular libraries—doesn't support bundling dependencies whose source code lives outside the Angular workspace. We've not been able to find a compatible way to bundle the core package into the Angular SDK for distribution.

Solution

Copy the core package src directory into the Angular package without transpiling it and allow Angular's library builder to handle the rest as if it's not an external dependency. The Angular SDK will use relative paths to import the core module from the copied directory.

A script get-sdk-core from the Angular SDK package.json copies it into a git-ignored directory packages/sdk-angular/projects/fusionauth-angular-sdk/src/sdkcore. When developing/debugging, changes should not be made to the git-ignored directory; they should be made in packages/core and then consumed with get-sdk-core.

Drawbacks

Drawbacks of this approach include:

  • We can't use absolute paths within the core package.
  • It may be confusing to new developers on the project. We should add documentation that clarifies why this decision was made.

Alternate Solution

Publish the @fusionauth-sdk/core and allow SDKs to consume it as a non-bundled dependency.

Drawbacks

  • Another set of public documentation to maintain.
  • Adding another publishing cycle/versioning for the dependency.

I've filed an issue in the ng-packagr repo and see if I can get a better handle on this. ng-packagr/ng-packagr#2853

UPDATE: ng-packagr doesn't handle bundling dependencies. Will probably have to do something custom to build the core package into the angular bundle.