From f7c3ba24d7beab5f05d2a7a9725c6dd5a091faee Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Tue, 12 May 2026 01:13:52 +0200 Subject: [PATCH] refactor(libs): graduate Icon / LayoutStateService / brand tokens to libs/shared/* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per ADR-0020 §"Shared-libs graduation": the three primitives that both `portal-shell` (today) and `portal-admin` (next) will share move out of `apps/portal-shell/src/` and into the workspace libs. Mechanical move — no behaviour change. Graduated: - `Icon` component → `libs/shared/ui/src/lib/icon/`. Selector renamed `app-icon` → `lib-icon` (consumed via ``), `IconName` re-exported from `shared-ui`. - `LayoutStateService` (+ `ThemeMode` type) → `libs/shared/state/src/lib/`. New library generated via `nx g @nx/angular:library` to match the existing `feature-auth` / `shared-ui` shape. - Brand-palette `@theme` block → `libs/shared/tokens/src/brand-tokens.css`. `portal-shell`'s `styles.css` imports it by relative path. Lib tags updated so the module-boundary lint rule lets both apps consume them: - `shared-state`: new lib → `scope:shared, type:shared`. - `shared-ui`: was `scope:portal-shell` (stopgap from the initial scaffold) → `scope:shared, type:shared`. Side-edits: - `tsconfig.base.json` gains the `shared-state` path alias (generator-applied). - `shared-tokens` is now CSS-only — its placeholder TS function is removed and its vitest config flips `passWithNoTests: true` since there is nothing to test there yet. - Placeholder `shared-ui/shared-ui.{ts,html,css,spec.ts}` files removed. Verification: - Lint / test / build run-many across the four projects — green. - portal-shell: 28 tests, shared-state: 9, shared-ui: 3 (= the same 40 specs as before, redistributed across the new libs). - Production build: 128.7 KB gzip initial per locale (was 128.5 KB on main — noise-level delta). - Brand tokens still inlined in the produced `styles-*.css`. - Both `dist/.../browser/{en,fr}/` emitted as expected. No public-API breakage. The migration to `portal-admin` is now a clean `import { Icon } from 'shared-ui'` + `LayoutStateService` inject + `@import` of `brand-tokens.css` on admin's `styles.css` — no duplication. --- .../src/app/components/header/header.html | 8 +-- .../src/app/components/header/header.spec.ts | 2 +- .../src/app/components/header/header.ts | 4 +- .../locale-switcher/locale-switcher.html | 6 +-- .../locale-switcher/locale-switcher.ts | 2 +- .../src/app/components/sidebar/sidebar.html | 6 +-- .../src/app/components/sidebar/sidebar.ts | 4 +- .../theme-switcher/theme-switcher.html | 6 +-- .../theme-switcher/theme-switcher.spec.ts | 2 +- .../theme-switcher/theme-switcher.ts | 4 +- apps/portal-shell/src/styles.css | 51 ++----------------- apps/portal-shell/tsconfig.app.json | 10 +++- libs/shared/state/README.md | 7 +++ libs/shared/state/eslint.config.mjs | 34 +++++++++++++ libs/shared/state/project.json | 13 +++++ libs/shared/state/src/index.ts | 1 + .../src/lib}/layout-state.service.spec.ts | 0 .../state/src/lib}/layout-state.service.ts | 0 libs/shared/state/src/test-setup.ts | 5 ++ libs/shared/state/tsconfig.json | 23 +++++++++ libs/shared/state/tsconfig.lib.json | 26 ++++++++++ libs/shared/state/tsconfig.spec.json | 23 +++++++++ libs/shared/state/vite.config.mts | 28 ++++++++++ libs/shared/tokens/src/brand-tokens.css | 46 +++++++++++++++++ libs/shared/tokens/src/index.ts | 8 ++- .../tokens/src/lib/shared-tokens.spec.ts | 7 --- libs/shared/tokens/src/lib/shared-tokens.ts | 3 -- libs/shared/tokens/vitest.config.mts | 3 ++ libs/shared/ui/project.json | 2 +- libs/shared/ui/src/index.ts | 2 +- .../shared/ui/src/lib}/icon/icon.spec.ts | 10 ++-- .../shared/ui/src/lib}/icon/icon.ts | 12 ++--- .../shared/ui/src/lib/shared-ui/shared-ui.css | 0 .../ui/src/lib/shared-ui/shared-ui.html | 1 - .../ui/src/lib/shared-ui/shared-ui.spec.ts | 21 -------- libs/shared/ui/src/lib/shared-ui/shared-ui.ts | 9 ---- tsconfig.base.json | 3 +- 37 files changed, 267 insertions(+), 125 deletions(-) create mode 100644 libs/shared/state/README.md create mode 100644 libs/shared/state/eslint.config.mjs create mode 100644 libs/shared/state/project.json create mode 100644 libs/shared/state/src/index.ts rename {apps/portal-shell/src/app/state => libs/shared/state/src/lib}/layout-state.service.spec.ts (100%) rename {apps/portal-shell/src/app/state => libs/shared/state/src/lib}/layout-state.service.ts (100%) create mode 100644 libs/shared/state/src/test-setup.ts create mode 100644 libs/shared/state/tsconfig.json create mode 100644 libs/shared/state/tsconfig.lib.json create mode 100644 libs/shared/state/tsconfig.spec.json create mode 100644 libs/shared/state/vite.config.mts create mode 100644 libs/shared/tokens/src/brand-tokens.css delete mode 100644 libs/shared/tokens/src/lib/shared-tokens.spec.ts delete mode 100644 libs/shared/tokens/src/lib/shared-tokens.ts rename {apps/portal-shell/src/app/components => libs/shared/ui/src/lib}/icon/icon.spec.ts (85%) rename {apps/portal-shell/src/app/components => libs/shared/ui/src/lib}/icon/icon.ts (87%) delete mode 100644 libs/shared/ui/src/lib/shared-ui/shared-ui.css delete mode 100644 libs/shared/ui/src/lib/shared-ui/shared-ui.html delete mode 100644 libs/shared/ui/src/lib/shared-ui/shared-ui.spec.ts delete mode 100644 libs/shared/ui/src/lib/shared-ui/shared-ui.ts diff --git a/apps/portal-shell/src/app/components/header/header.html b/apps/portal-shell/src/app/components/header/header.html index aac8858..e7693dc 100644 --- a/apps/portal-shell/src/app/components/header/header.html +++ b/apps/portal-shell/src/app/components/header/header.html @@ -29,7 +29,7 @@
- + - +