@yaagoub/federation-tools 1.2.7 β†’ 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +190 -33
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,63 +1,220 @@
1
1
  # FederationTools
2
2
 
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.3.0.
3
+ **FederationTools** is a lightweight utility library designed to simplify **environment variables**, **assets**, and **internationalization (i18n)** management across **Angular micro-frontend architectures** (Module Federation / Native Federation).
4
4
 
5
- ## Code scaffolding
5
+ It provides a **single, consistent API** that works across the **shell** and all **remote MFEs**, without iframes and without leaking configuration to `window`.
6
6
 
7
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
7
+ ---
8
+
9
+ ## πŸ“¦ Installation
10
+
11
+ Add the library to your workspace:
8
12
 
9
13
  ```bash
10
- ng generate component component-name
14
+ npm install @yaagoub/federation-tools
11
15
  ```
12
16
 
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
17
+ ---
14
18
 
15
- ```bash
16
- ng generate --help
19
+ ## πŸ“ Project Structure (Shell)
20
+
21
+ The shell application acts as the **single source of truth** for:
22
+
23
+ * environment variables
24
+ * translations
25
+ * asset origins
26
+
27
+ Recommended structure:
28
+
29
+ ```
30
+ └── πŸ“settings
31
+ β”œβ”€β”€ πŸ“env
32
+ β”‚ └── env.json # Shell environment variables
33
+ β”‚
34
+ β”œβ”€β”€ πŸ“i18n
35
+ β”‚ β”œβ”€β”€ en.json # English translations
36
+ β”‚ └── ar.json # Arabic translations
37
+ β”‚
38
+ └── πŸ“manifest
39
+ β”œβ”€β”€ πŸ“assets
40
+ β”‚ └── assets.manifest.json
41
+ β”‚ {
42
+ β”‚ "shell": "http://localhost:4200",
43
+ β”‚ "mfe1": "http://localhost:4201",
44
+ β”‚ "mfe2": "http://localhost:4202"
45
+ β”‚ }
46
+ β”‚
47
+ β”œβ”€β”€ πŸ“env
48
+ β”‚ └── env.manifest.json
49
+ β”‚ {
50
+ β”‚ "shell": "http://localhost:4200",
51
+ β”‚ "mfe1": "http://localhost:4201",
52
+ β”‚ "mfe2": "http://localhost:4202"
53
+ β”‚ }
54
+ β”‚
55
+ └── πŸ“i18n
56
+ └── i18n.manifest.json
57
+ {
58
+ "shell": "http://localhost:4200",
59
+ "mfe1": "http://localhost:4201",
60
+ "mfe2": "http://localhost:4202"
61
+ }
17
62
  ```
18
63
 
19
- ## Building
64
+ for remotes Recommended structure:
20
65
 
21
- To build the library, run:
66
+ ```
67
+ └── πŸ“settings
68
+ β”œβ”€β”€ πŸ“env
69
+ β”‚ └── env.json # mfe environment variables
70
+ β”‚
71
+ β”œβ”€β”€ πŸ“i18n
72
+ β”‚ β”œβ”€β”€ en.json # English translations
73
+ β”‚ └── ar.json # Arabic translations
74
+ ```
22
75
 
23
- ```bash
24
- ng build federation-tools
76
+ Each manifest defines **where to fetch data from** for each micro frontend.
77
+
78
+ ---
79
+
80
+ ## βš™οΈ Development Configuration (Angular)
81
+
82
+ During development, expose the manifests and settings using the Angular assets configuration:
83
+
84
+ ```json
85
+ "development": {
86
+ "assets": [
87
+ {
88
+ "glob": "**/*",
89
+ "input": "projects/lkhedma/public"
90
+ },
91
+ {
92
+ "glob": "env.manifest.json",
93
+ "input": "projects/../src/settings/manifest/env",
94
+ "output": "."
95
+ },
96
+ {
97
+ "glob": "assets.manifest.json",
98
+ "input": "projects/../src/settings/manifest/assets",
99
+ "output": "."
100
+ },
101
+ {
102
+ "glob": "i18n.manifest.json",
103
+ "input": "projects/../src/settings/manifest/i18n",
104
+ "output": "."
105
+ },
106
+ {
107
+ "glob": "**/*",
108
+ "input": "projects/../src/settings/i18n",
109
+ "output": "i18n"
110
+ },
111
+ {
112
+ "glob": "env.json",
113
+ "input": "projects/../src/settings/env",
114
+ "output": "."
115
+ }
116
+ ],
117
+ "optimization": false,
118
+ "extractLicenses": false,
119
+ "sourceMap": true
120
+ }
25
121
  ```
26
122
 
27
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
123
+ > πŸ’‘ In production, these files are typically served by the shell (CDN, Nginx, or gateway).
28
124
 
29
- ### Publishing the Library
125
+ ---
30
126
 
31
- Once the project is built, you can publish your library by following these steps:
127
+ ## πŸ”Œ Shell Providers Setup
32
128
 
33
- 1. Navigate to the `dist` directory:
34
- ```bash
35
- cd dist/federation-tools
36
- ```
129
+ Register the FederationTools providers **once** in the shell application:
37
130
 
38
- 2. Run the `npm publish` command to publish your library to the npm registry:
39
- ```bash
40
- npm publish
41
- ```
131
+ ```ts
132
+ provideFederationAsset(),
133
+ provideFederationEnv(),
134
+ provideFederationTranslation('en') // default language
135
+ ```
42
136
 
43
- ## Running unit tests
137
+ These providers automatically:
44
138
 
45
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
139
+ * load manifests
140
+ * fetch remote data
141
+ * cache results
142
+ * expose a unified API to all MFEs
46
143
 
47
- ```bash
48
- ng test
144
+ ---
145
+
146
+ ## πŸ–ΌοΈ Federated Assets
147
+
148
+ Use assets from **any MFE** by prefixing the asset name with the micro frontend key.
149
+
150
+ ```html
151
+ <img [asset]="'mfe1:logo.png'" />
49
152
  ```
50
153
 
51
- ## Running end-to-end tests
154
+ ### Supported elements
52
155
 
53
- For end-to-end (e2e) testing, run:
156
+ The `asset` directive works with:
54
157
 
55
- ```bash
56
- ng e2e
158
+ * `img`
159
+ * `video`
160
+ * `audio`
161
+ * `iframe`
162
+ * `source`
163
+ * `a`
164
+ * `object`
165
+
166
+ The prefix (`mfe1`) must exist in `assets.manifest.json`.
167
+
168
+ ---
169
+
170
+ ## 🌍 Internationalization (i18n)
171
+
172
+ FederationTools provides a federated translation system shared across all MFEs.
173
+
174
+ ### Template usage
175
+
176
+ ```html
177
+ {{ 'home.title' | t }}
178
+ ```
179
+
180
+ ### Programmatic usage
181
+
182
+ ```ts
183
+ import { inject } from '@angular/core';
184
+ import { TranslationService } from '@yaagoub/federation-tools';
185
+
186
+ const translationService = inject(TranslationService);
187
+
188
+ translationService.t('home.title');
189
+ ```
190
+
191
+ Translations are:
192
+
193
+ * loaded lazily
194
+ * merged across shell + MFEs
195
+ * automatically updated when the language changes
196
+
197
+ ---
198
+
199
+ ## πŸ” Environment Variables
200
+
201
+ Environment variables are **not exposed on `window`** and are only accessible through the FederationTools API.
202
+
203
+ ### Waiting for environment initialization
204
+
205
+ ```ts
206
+ import { from } from 'rxjs';
207
+ import { waitForFederationEnv } from '@yaagoub/federation-tools';
208
+
209
+ from(waitForFederationEnv('mfe1')).subscribe(env => {
210
+ // Safe access to federated environment variables
211
+ });
57
212
  ```
58
213
 
59
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
214
+ ### Key guarantees
60
215
 
61
- ## Additional Resources
216
+ * βœ”οΈ Shell loads the environment first
217
+ * βœ”οΈ MFEs wait safely for availability
218
+ * βœ”οΈ Immutable, frozen configuration
219
+ * βœ”οΈ No global leaks
62
220
 
63
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaagoub/federation-tools",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=15.0.0",
6
6
  "@angular/core": ">=15.0.0"