@angular-architects/native-federation 18.1.2 → 18.2.0

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 (105) hide show
  1. package/.eslintrc.json +25 -0
  2. package/README.md +1 -0
  3. package/docs/migrate.md +173 -0
  4. package/docs/share-faq.md +57 -0
  5. package/docs/update18.md +19 -0
  6. package/example.png +0 -0
  7. package/jest.config.ts +11 -0
  8. package/package.json +3 -5
  9. package/post-build.js +10 -0
  10. package/project.json +80 -0
  11. package/src/builders/build/builder.ts +370 -0
  12. package/src/config.ts +6 -0
  13. package/src/executors/build/executor.spec.ts +11 -0
  14. package/src/executors/build/executor.ts +12 -0
  15. package/src/generators/native-federation/generator.spec.ts +20 -0
  16. package/src/generators/native-federation/generator.ts +76 -0
  17. package/src/patch-angular-build.ts +8 -0
  18. package/src/plugin/dev-externals-mixin.ts +34 -0
  19. package/src/plugin/externals-skip-list.ts +5 -0
  20. package/src/plugin/index.ts +123 -0
  21. package/src/schematics/appbuilder/schematic.ts +148 -0
  22. package/src/schematics/init/schematic.ts +463 -0
  23. package/src/schematics/remove/schematic.ts +179 -0
  24. package/src/schematics/update18/schematic.ts +10 -0
  25. package/src/utils/angular-esbuild-adapter.ts +438 -0
  26. package/src/utils/create-compiler-options.ts +68 -0
  27. package/src/utils/dev-server.ts +117 -0
  28. package/src/utils/event-sorce.ts +18 -0
  29. package/src/utils/mem-resuts.ts +67 -0
  30. package/src/utils/patch-angular-build.ts +47 -0
  31. package/src/utils/rebuild-events.ts +9 -0
  32. package/src/utils/shared-mappings-plugin.ts +35 -0
  33. package/src/utils/updateIndexHtml.ts +55 -0
  34. package/tsconfig.json +23 -0
  35. package/tsconfig.lib.json +11 -0
  36. package/tsconfig.spec.json +15 -0
  37. package/config.js +0 -5
  38. package/config.js.map +0 -1
  39. package/src/builders/build/builder.d.ts +0 -5
  40. package/src/builders/build/builder.js +0 -255
  41. package/src/builders/build/builder.js.map +0 -1
  42. package/src/config.d.ts +0 -2
  43. package/src/config.js +0 -10
  44. package/src/config.js.map +0 -1
  45. package/src/executors/build/executor.d.ts +0 -4
  46. package/src/executors/build/executor.js +0 -13
  47. package/src/executors/build/executor.js.map +0 -1
  48. package/src/generators/native-federation/generator.d.ts +0 -3
  49. package/src/generators/native-federation/generator.js +0 -44
  50. package/src/generators/native-federation/generator.js.map +0 -1
  51. package/src/index.js +0 -1
  52. package/src/index.js.map +0 -1
  53. package/src/patch-angular-build.d.ts +0 -1
  54. package/src/patch-angular-build.js +0 -7
  55. package/src/patch-angular-build.js.map +0 -1
  56. package/src/plugin/dev-externals-mixin.d.ts +0 -1
  57. package/src/plugin/dev-externals-mixin.js +0 -30
  58. package/src/plugin/dev-externals-mixin.js.map +0 -1
  59. package/src/plugin/externals-skip-list.d.ts +0 -2
  60. package/src/plugin/externals-skip-list.js +0 -9
  61. package/src/plugin/externals-skip-list.js.map +0 -1
  62. package/src/plugin/index.d.ts +0 -2
  63. package/src/plugin/index.js +0 -107
  64. package/src/plugin/index.js.map +0 -1
  65. package/src/schematics/appbuilder/schematic.d.ts +0 -4
  66. package/src/schematics/appbuilder/schematic.js +0 -95
  67. package/src/schematics/appbuilder/schematic.js.map +0 -1
  68. package/src/schematics/init/schematic.d.ts +0 -6
  69. package/src/schematics/init/schematic.js +0 -312
  70. package/src/schematics/init/schematic.js.map +0 -1
  71. package/src/schematics/remove/schematic.d.ts +0 -4
  72. package/src/schematics/remove/schematic.js +0 -119
  73. package/src/schematics/remove/schematic.js.map +0 -1
  74. package/src/schematics/update18/schematic.d.ts +0 -2
  75. package/src/schematics/update18/schematic.js +0 -14
  76. package/src/schematics/update18/schematic.js.map +0 -1
  77. package/src/utils/angular-esbuild-adapter.d.ts +0 -9
  78. package/src/utils/angular-esbuild-adapter.js +0 -270
  79. package/src/utils/angular-esbuild-adapter.js.map +0 -1
  80. package/src/utils/create-compiler-options.d.ts +0 -4
  81. package/src/utils/create-compiler-options.js +0 -45
  82. package/src/utils/create-compiler-options.js.map +0 -1
  83. package/src/utils/dev-server.d.ts +0 -7
  84. package/src/utils/dev-server.js +0 -94
  85. package/src/utils/dev-server.js.map +0 -1
  86. package/src/utils/event-sorce.d.ts +0 -9
  87. package/src/utils/event-sorce.js +0 -20
  88. package/src/utils/event-sorce.js.map +0 -1
  89. package/src/utils/mem-resuts.d.ts +0 -29
  90. package/src/utils/mem-resuts.js +0 -58
  91. package/src/utils/mem-resuts.js.map +0 -1
  92. package/src/utils/patch-angular-build.d.ts +0 -3
  93. package/src/utils/patch-angular-build.js +0 -36
  94. package/src/utils/patch-angular-build.js.map +0 -1
  95. package/src/utils/rebuild-events.d.ts +0 -7
  96. package/src/utils/rebuild-events.js +0 -11
  97. package/src/utils/rebuild-events.js.map +0 -1
  98. package/src/utils/shared-mappings-plugin.d.ts +0 -3
  99. package/src/utils/shared-mappings-plugin.js +0 -31
  100. package/src/utils/shared-mappings-plugin.js.map +0 -1
  101. package/src/utils/updateIndexHtml.d.ts +0 -4
  102. package/src/utils/updateIndexHtml.js +0 -34
  103. package/src/utils/updateIndexHtml.js.map +0 -1
  104. /package/{config.d.ts → config.ts} +0 -0
  105. /package/src/{index.d.ts → index.ts} +0 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": ["../../.eslintrc.base.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ },
17
+ {
18
+ "files": ["*.json"],
19
+ "parser": "jsonc-eslint-parser",
20
+ "rules": {
21
+ "@nx/dependency-checks": "warn"
22
+ }
23
+ }
24
+ ]
25
+ }
package/README.md CHANGED
@@ -26,6 +26,7 @@ We will at least provide a new version of this package per Angular major. If nec
26
26
  - Use version 17.1.x for Angular 17.1+
27
27
  - Use version 18.x for Angular 18+
28
28
  - Use version 18.1.x for Angular 18.1+
29
+ - Use version 18.2.x for Angular 18.2+
29
30
 
30
31
  ## Migration from Module Federation
31
32
 
@@ -0,0 +1,173 @@
1
+ # Migration Guide: Module Federation to Native Federation for Angular
2
+
3
+ ## Motivation
4
+
5
+ Since Angular 17, the CLI ships with an esbuild-based builder that is remarkable faster than the original webpack-based solution. This new builder is used for newly generated projects and beginning with Angular 18 ng updates also migrates existing projects.
6
+
7
+ Native Federation for Angular is a thin wrapper around the esbuild builder that allows to use the proven mental model of Module Federation.
8
+
9
+ ## Prerequisites
10
+
11
+ - Update your solution to the newest Angular and CLI version
12
+ - Update your solution to the newest version of `@angular-architects/module-federation` (!)
13
+ - Have a look to our [FAQs about sharing packages with Native Federation](share-faq.md)
14
+
15
+ In general, you need Native Federation for Angular 18.1 and Module Federation 18.x.
16
+
17
+ ## Migration for Angular CLI projects
18
+
19
+ 1. Remove Module Federation from your poject(s):
20
+
21
+ ```
22
+ ng g @angular-architects/module-federation:remove --project xyz
23
+ ```
24
+
25
+ 2. Update your workspace to the new esbuild-based build system:
26
+
27
+ ```
28
+ ng update @angular/cli --name use-application-builder
29
+ ```
30
+
31
+ 3. Initialize Native Federation for your projects:
32
+
33
+ ```
34
+ ng add @angular-architects/native-federation --project xyz --type remote --port 4201
35
+ ```
36
+
37
+ **Remarks:** Use type `remote` or type `dynamic-host`.
38
+
39
+ 4. Adjust your `federation.config.js` generated for Native Federation. You can mostly copy over the settings from your `webpack.config.js` used for Module Federation before.
40
+
41
+ 5. Update your EcmaScript imports in your source code. Make sure, you import from `@angular-architects/native-federation` instead of from `@angular-architects/module-federation`. Please also note that the signature of `loadRemoteModule` has been simplified:
42
+
43
+ ```typescript
44
+ // Before
45
+ import { loadRemoteModule } from '@angular-architects/module-federation';
46
+
47
+ [...]
48
+
49
+ export const APP_ROUTES: Routes = [
50
+ [...]
51
+ {
52
+ path: 'booking',
53
+ loadChildren: () =>
54
+ loadRemoteModule({
55
+ type: 'module',
56
+ remoteEntry: 'http://localhost:4201/remoteEntry.js',
57
+ exposedModule: './routes'
58
+ })
59
+ .then(m => m.MFE1_ROUTES)
60
+ },
61
+ [...]
62
+ ];
63
+ ```
64
+
65
+ ```typescript
66
+ // After
67
+ import { loadRemoteModule } from '@angular-architects/native-federation';
68
+
69
+ [...]
70
+
71
+ export const APP_ROUTES: Routes = [
72
+ [...]
73
+ {
74
+ path: 'flights',
75
+ loadComponent: () => loadRemoteModule('mfe1', './Component')
76
+ .then((m) => m.AppComponent),
77
+ },
78
+ [...]
79
+ ];
80
+ ```
81
+
82
+ Please also note that loadRemoteModule now always points to a logical name that is resolved via the shell's federation manifest (`src/assets/federation.manifest.json` or `public/federation.manifest.json`):
83
+
84
+ ```json
85
+ {
86
+ "mfe1": "http://localhost:4201/remoteEntry.json"
87
+ }
88
+ ```
89
+
90
+ Please also note that the remoteEntry is now a `.json` file.
91
+
92
+ 6. If everything works, delete your `webpack.config.js`
93
+
94
+ ## Migration for Nx projects
95
+
96
+ 1. Remove Module Federation from your poject(s):
97
+
98
+ ```
99
+ nx g @angular-architects/module-federation:remove --project xyz
100
+ ```
101
+
102
+ 2. Initialize Native Federation for your projects:
103
+
104
+ ```
105
+ npm i @angular-architects/native-federation
106
+
107
+ nx g @angular-architects/native-federation:init --project xyz --type remote --port 4201
108
+ ```
109
+
110
+ **Remarks:** Use type `remote` or type `dynamic-host`.
111
+
112
+ 3. Adjust your `federation.config.js` generated for Native Federation. You can mostly copy over the settings from your `webpack.config.js` used for Module Federation before.
113
+
114
+ 4. Update your EcmaScript imports in your source code. Make sure, you import from `@angular-architects/native-federation` instead of from `@angular-architects/module-federation`. Please also note that the signature of `loadRemoteModule` has been simplified:
115
+
116
+ ```typescript
117
+ // Before
118
+ import { loadRemoteModule } from '@angular-architects/module-federation';
119
+
120
+ [...]
121
+
122
+ export const APP_ROUTES: Routes = [
123
+ [...]
124
+ {
125
+ path: 'booking',
126
+ loadChildren: () =>
127
+ loadRemoteModule({
128
+ type: 'module',
129
+ remoteEntry: 'http://localhost:4201/remoteEntry.js',
130
+ exposedModule: './routes'
131
+ })
132
+ .then(m => m.MFE1_ROUTES)
133
+ },
134
+ [...]
135
+ ];
136
+ ```
137
+
138
+ ```typescript
139
+ // After
140
+ import { loadRemoteModule } from '@angular-architects/native-federation';
141
+
142
+ [...]
143
+
144
+ export const APP_ROUTES: Routes = [
145
+ [...]
146
+ {
147
+ path: 'flights',
148
+ loadComponent: () => loadRemoteModule('mfe1', './Component')
149
+ .then((m) => m.AppComponent),
150
+ },
151
+ [...]
152
+ ];
153
+ ```
154
+
155
+ Please also note that loadRemoteModule now always points to a logical name that is resolved via the shell's federation manifest (`src/assets/federation.manifest.json` or `public/federation.manifest.json`):
156
+
157
+ ```json
158
+ {
159
+ "mfe1": "http://localhost:4201/remoteEntry.json"
160
+ }
161
+ ```
162
+
163
+ Please also note that the remoteEntry is now a `.json` file.
164
+
165
+ 5. If everything works, delete your `webpack.config.js`
166
+
167
+ ## Module Federation Toolkit
168
+
169
+ For Module Federation, we offered a simple toolkit helping with Multi Version/ Multi Framework scenarios. However, this toolkit was quite simple and can be implemented with just a few lines of code. To give you more flexibility, instead of providing a respective package for Native Federation, [here](https://www.angulararchitects.io/blog/micro-frontends-with-modern-angular-part-2-multi-version-and-multi-framework-solutions-with-angular-elements-and-web-components/) we describe how to implement such a functionality by yourself.
170
+
171
+ ## Issues
172
+
173
+ We have tested this guide with several projects. However, each project is different. If you run into issues, feel free to let us know.
@@ -0,0 +1,57 @@
1
+ # FAQ for Sharing Libraries
2
+
3
+ ## Information for Nx Users
4
+
5
+ When using Nx, it's usual to subdivide an application into several libs. Libs that are only used by one application should not be shared via federation.
6
+
7
+ As by default, all packages found in your `package.json` but also all libs in your workspace are shared, you should add such libraries to your skip list:
8
+
9
+ ```
10
+ skip: [
11
+     '@my-scope/my-lib',
12
+ ]
13
+ ```
14
+
15
+ This speeds up your build and the initial page load. Also, it gives you automatic page reloads within your application when changing the source code.
16
+
17
+ ## Using Multiple Framework Versions
18
+
19
+ After compiling an Angular application, the compilation is accessing Angular's private API. As private APIs do not align with semver, there is no guarantee that your compiled application works with a different version of Angular. Even having a different minor or patch version at runtime can lead to issues.
20
+
21
+ Hence, when using several versions or frameworks, you need to bootstrap each remote separately. Often, the individual Micro Frontends are abstracted, e.g., by using Web Components. Please find [more details about this here](https://www.angulararchitects.io/blog/micro-frontends-with-modern-angular-part-2-multi-version-and-multi-framework-solutions-with-angular-elements-and-web-components/).
22
+
23
+ ## Sharing "Old-Style" Packages
24
+
25
+ To be useful in the long run, Native Federation fully leverages browser-native technologies like ESM and import maps. For this reason, old-style packages not following these standards can lead to challenges. In these cases, you might need to adjust your imports.
26
+
27
+ A good example of such a classical package is `lodash`. When we looked into it the last time, it was still `commonjs` and not ESM-based. As `commonjs` can not be converted to ESM in all cases, we needed to adjust the imports as follows:
28
+
29
+ ```typescript
30
+ // Works:
31
+ import _ from 'lodash';
32
+
33
+ // Does not work:
34
+ // import * as _ from 'lodash';
35
+ ```
36
+
37
+ Another solution is to find an ESM version of `lodash`.
38
+
39
+ The **good message** is: Angular's Package format implemented by ng build for libraries addresses ESM. Hence, Angular-based libraries really work well with Native Federation.
40
+
41
+ ## ShareAll
42
+
43
+ The shareAll helper used by default in the federatio.config.js makes your life far easier as it shares all dependencies found in your `package.json`. To optimize your build times and initial page loads, you can opt-out of sharing specific libraries by adding them to the above-mentioned `skip` list.
44
+
45
+ While this is an option in most cases, you **need to** skip Node.js libraries as they cannot be compiled for usage within the browser. Examples of such libraries are `@angular/ssr` or `express`.
46
+
47
+ ## Hint: Skip and RegExp
48
+
49
+ The skip list can contain a RegExp for excluding several entry points starting with the same name. This is especially interesting when using packages that come with several entry points, e.g. my-package/a and my-package/b. To skip all these entry points provided by my-package, you could use:
50
+
51
+ ```typescript
52
+ skip: [
53
+ 'this-package', // string-based entry
54
+ 'that-package', // another string-based one
55
+ /^my-package/, // RegExp
56
+ ];
57
+ ```
@@ -0,0 +1,19 @@
1
+ # Update to Native Federation for Angular 18
2
+
3
+ The package `@angular-architects/native-federation` version 18 was successfully tested with Angular 18.
4
+
5
+ ## Option 1
6
+
7
+ Just use `ng update`:
8
+
9
+ ```
10
+ ng update @angular-architects/native-federation
11
+ ```
12
+
13
+ ## Option 2
14
+
15
+ Use npm install:
16
+
17
+ ```
18
+ npm i @angular-architects/native-federation@^18
19
+ ```
package/example.png ADDED
Binary file
package/jest.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'native-federation',
4
+ preset: '../../jest.preset.js',
5
+ testEnvironment: 'node',
6
+ transform: {
7
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8
+ },
9
+ moduleFileExtensions: ['ts', 'js', 'html'],
10
+ coverageDirectory: '../../coverage/libs/native-federation',
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-architects/native-federation",
3
- "version": "18.1.2",
3
+ "version": "18.2.0",
4
4
  "main": "src/index.js",
5
5
  "generators": "./collection.json",
6
6
  "builders": "./builders.json",
@@ -29,7 +29,5 @@
29
29
  "npmlog": "^6.0.2",
30
30
  "process": "0.11.10"
31
31
  },
32
- "peerDependencies": {},
33
- "type": "commonjs",
34
- "types": "./src/index.d.ts"
35
- }
32
+ "peerDependencies": {}
33
+ }
package/post-build.js ADDED
@@ -0,0 +1,10 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const index = fs.readFileSync(path.join(__dirname, 'src/index.ts'), {
5
+ encoding: 'utf-8',
6
+ });
7
+ fs.writeFileSync(
8
+ path.join(__dirname, '../../dist/libs/native-federation/src/index.js'),
9
+ index
10
+ );
package/project.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "native-federation",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/native-federation/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/js:tsc",
9
+ "outputs": ["{options.outputPath}"],
10
+ "options": {
11
+ "outputPath": "dist/libs/native-federation",
12
+ "main": "libs/native-federation/src/index.ts",
13
+ "tsConfig": "libs/native-federation/tsconfig.lib.json",
14
+ "assets": [
15
+ "libs/native-federation/*.md",
16
+ "libs/native-federation/LICENSE",
17
+ {
18
+ "input": "./libs/native-federation/src",
19
+ "glob": "**/!(*.ts)",
20
+ "output": "./src"
21
+ },
22
+ {
23
+ "input": "./libs/native-federation/src",
24
+ "glob": "**/*.d.ts",
25
+ "output": "./src"
26
+ },
27
+ {
28
+ "input": "./libs/native-federation",
29
+ "glob": "generators.json",
30
+ "output": "."
31
+ },
32
+ {
33
+ "input": "./libs/native-federation",
34
+ "glob": "builders.json",
35
+ "output": "."
36
+ },
37
+ {
38
+ "input": "./libs/native-federation",
39
+ "glob": "migration-collection.json",
40
+ "output": "."
41
+ },
42
+ {
43
+ "input": "./libs/native-federation",
44
+ "glob": "executors.json",
45
+ "output": "."
46
+ },
47
+ {
48
+ "input": "./libs/native-federation",
49
+ "glob": "collection.json",
50
+ "output": "."
51
+ }
52
+ ]
53
+ }
54
+ },
55
+ "post-build": {
56
+ "dependsOn": ["build"],
57
+ "executor": "nx:run-commands",
58
+ "outputs": ["{options.outputPath}/src/index.js"],
59
+ "options": {
60
+ "cwd": "libs/native-federation",
61
+ "command": "node post-build.js"
62
+ }
63
+ },
64
+ "publish": {
65
+ "dependsOn": ["build", "post-build"],
66
+ "executor": "nx:run-commands",
67
+ "options": {
68
+ "command": "node tools/scripts/publish.mjs native-federation npm {args.ver} {args.tag}"
69
+ }
70
+ },
71
+ "publish-local": {
72
+ "dependsOn": ["build", "post-build"],
73
+ "executor": "nx:run-commands",
74
+ "options": {
75
+ "command": "node tools/scripts/publish.mjs native-federation verdaccio {args.ver}"
76
+ }
77
+ }
78
+ },
79
+ "tags": ["org:angular-architects", "scope:nf"]
80
+ }