dspace-angular icon indicating copy to clipboard operation
dspace-angular copied to clipboard

Refactor core, utils and config as libraries using angular's built-in tools

Open artlowel opened this issue 3 months ago • 0 comments

References

  • Alternative to https://github.com/DSpace/dspace-angular/pull/4019

Description

This PR builds on https://github.com/DSpace/dspace-angular/pull/4629

Here's a compare view

Generated libraries

  • Converted @dspace/core, @dspace/config, and @dspace/utils TypeScript path mappings into Angular libraries using:

    ng generate library @dspace/core
    
  • Moved the corresponding code into the lib folder of each new library.

Public APIs

  • Integrated barrelsby to generate each library’s public-api.ts, defining what can be imported externally.
  • Configured this to run automatically during both dev and prod builds.
    Eventually we will want it to watch for changes so it adds new files when you create them.

Import and path updates

  • Updated all imports in the main app to use each library’s public API.
    For example, import { Process } from '@dspace/core/processes/process.model' becomes import { Process } from '@dspace/core'.

  • Updated library paths in tsconfig.json to point directly to the public APIs rather than built outputs.
    This ensures that code changes in any library are immediately reflected in development mode.
    This also works for production, though we may later build the libraries separately to speed up prod builds when no library code has changed.

Bugfixes

  • Resolved circular dependencies that became apparent after splitting the code into libraries.
    • Some guards and resolvers originally in the core module were moved to the main app.
  • Fixed several naming conflicts, e.g. if two classes are called Metadata, they can't both be exported from the same public api without renaming one of them.

Building and testing

  • Uses the same build and run commands as DSpace: npm run start, npm run start:dev, and similar.
  • e2e tests run successfully.
    Unit tests currently fail due to imports that moved. I did not spend more time fixing these in case we decide not to proceed with this approach.

Custom lib poc

I added a custom library on top of this PR to test how that would work. You can find that code at atmire:ng-workspace-poc-with-custom-lib

Here's a compare view with this PR

artlowel avatar Oct 23 '25 15:10 artlowel