@angular-architects/native-federation 20.1.6 → 20.3.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.
- package/README.md +6 -10
- package/package.json +4 -4
- package/src/builders/build/builder.js +272 -232
- package/src/builders/build/builder.js.map +1 -1
- package/src/builders/build/federation-build-notifier.d.ts +4 -0
- package/src/builders/build/federation-build-notifier.js +13 -5
- package/src/builders/build/federation-build-notifier.js.map +1 -1
- package/src/builders/build/schema.d.ts +1 -0
- package/src/executors/build/executor.js +5 -8
- package/src/executors/build/executor.js.map +1 -1
- package/src/generators/native-federation/generator.js +24 -18
- package/src/generators/native-federation/generator.js.map +1 -1
- package/src/plugin/dev-externals-mixin.js +6 -4
- package/src/plugin/dev-externals-mixin.js.map +1 -1
- package/src/plugin/index.js +18 -21
- package/src/plugin/index.js.map +1 -1
- package/src/schematics/appbuilder/schematic.js +12 -16
- package/src/schematics/appbuilder/schematic.js.map +1 -1
- package/src/schematics/init/files/federation.config.js__tmpl__ +2 -2
- package/src/schematics/init/schematic.js +154 -160
- package/src/schematics/init/schematic.js.map +1 -1
- package/src/schematics/remove/schematic.js +15 -19
- package/src/schematics/remove/schematic.js.map +1 -1
- package/src/schematics/update18/schematic.js +3 -6
- package/src/schematics/update18/schematic.js.map +1 -1
- package/src/tools/fstart-as-data-url.d.ts +1 -1
- package/src/tools/fstart-as-data-url.js +1 -1
- package/src/tools/fstart-as-data-url.js.map +1 -1
- package/src/utils/angular-esbuild-adapter.js +156 -129
- package/src/utils/angular-esbuild-adapter.js.map +1 -1
- package/src/utils/angular-locales.d.ts +4 -1
- package/src/utils/angular-locales.js +17 -8
- package/src/utils/angular-locales.js.map +1 -1
- package/src/utils/create-awaitable-compiler-plugin.d.ts +5 -0
- package/src/utils/create-awaitable-compiler-plugin.js +33 -0
- package/src/utils/create-awaitable-compiler-plugin.js.map +1 -0
- package/src/utils/create-compiler-options.js +3 -2
- package/src/utils/create-compiler-options.js.map +1 -1
- package/src/utils/event-sorce.js +4 -9
- package/src/utils/event-sorce.js.map +1 -1
- package/src/utils/i18n.d.ts +7 -1
- package/src/utils/i18n.js +36 -40
- package/src/utils/i18n.js.map +1 -1
- package/src/utils/mem-resuts.js +6 -4
- package/src/utils/mem-resuts.js.map +1 -1
- package/src/utils/rebuild-events.js +1 -3
- package/src/utils/rebuild-events.js.map +1 -1
- package/src/utils/shared-mappings-plugin.js +2 -2
- package/src/utils/shared-mappings-plugin.js.map +1 -1
- package/src/utils/updateIndexHtml.js +6 -3
- package/src/utils/updateIndexHtml.js.map +1 -1
- package/src/utils/rollup.ts.bak +0 -60
- package/src/utils/rollup.ts.bak.bak +0 -60
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ We will at least provide a new version of this package per Angular major. If nec
|
|
|
36
36
|
- Use version 19.x for Angular 19.x
|
|
37
37
|
- Use version 20.0.x for Angular 20.0.x
|
|
38
38
|
- Use version 20.1.x for Angular 20.1.x
|
|
39
|
+
- Use version 21.x for Angular 21.x
|
|
39
40
|
|
|
40
41
|
## Demo Repo
|
|
41
42
|
|
|
@@ -172,12 +173,10 @@ A dynamic host reads the configuration data at runtime from a `.json` file.
|
|
|
172
173
|
The host configuration (`projects/shell/federation.config.js`) looks like what you know from our Module Federation plugin:
|
|
173
174
|
|
|
174
175
|
```javascript
|
|
175
|
-
const {
|
|
176
|
-
withNativeFederation,
|
|
177
|
-
shareAll,
|
|
178
|
-
} = require('@angular-architects/native-federation/config');
|
|
176
|
+
const { withNativeFederation, shareAll } = require('@angular-architects/native-federation/config');
|
|
179
177
|
|
|
180
178
|
module.exports = withNativeFederation({
|
|
179
|
+
name: 'my-host',
|
|
181
180
|
shared: {
|
|
182
181
|
...shareAll({
|
|
183
182
|
singleton: true,
|
|
@@ -203,10 +202,7 @@ module.exports = withNativeFederation({
|
|
|
203
202
|
Also, the remote configuration (`projects/mfe1/federation.config.js`) looks familiar:
|
|
204
203
|
|
|
205
204
|
```javascript
|
|
206
|
-
const {
|
|
207
|
-
withNativeFederation,
|
|
208
|
-
shareAll,
|
|
209
|
-
} = require('@angular-architects/native-federation/config');
|
|
205
|
+
const { withNativeFederation, shareAll } = require('@angular-architects/native-federation/config');
|
|
210
206
|
|
|
211
207
|
module.exports = withNativeFederation({
|
|
212
208
|
name: 'mfe1',
|
|
@@ -305,8 +301,7 @@ export const APP_ROUTES: Routes = [
|
|
|
305
301
|
// Add this route:
|
|
306
302
|
{
|
|
307
303
|
path: 'flights',
|
|
308
|
-
loadComponent: () =>
|
|
309
|
-
loadRemoteModule('mfe1', './Component').then((m) => m.AppComponent),
|
|
304
|
+
loadComponent: () => loadRemoteModule('mfe1', './Component').then((m) => m.AppComponent),
|
|
310
305
|
},
|
|
311
306
|
|
|
312
307
|
{
|
|
@@ -379,6 +374,7 @@ module.exports = withNativeFederation({
|
|
|
379
374
|
shared: {
|
|
380
375
|
...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
|
|
381
376
|
...shareAngularLocales(['en', 'de', 'fr']),
|
|
377
|
+
//...shareAngularLocales(['en', 'de', 'fr'], {legacy: true}), // ng19 or older
|
|
382
378
|
}
|
|
383
379
|
});
|
|
384
380
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-architects/native-federation",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.3.0",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"generators": "./collection.json",
|
|
6
6
|
"builders": "./builders.json",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/core": "^7.19.0",
|
|
23
|
-
"@softarc/native-federation": "3.
|
|
24
|
-
"@softarc/native-federation-runtime": "3.
|
|
25
|
-
"@chialab/esbuild-plugin-commonjs": "^0.
|
|
23
|
+
"@softarc/native-federation": "~3.5.1",
|
|
24
|
+
"@softarc/native-federation-runtime": "~3.5.1",
|
|
25
|
+
"@chialab/esbuild-plugin-commonjs": "^0.19.0",
|
|
26
26
|
"esbuild": "^0.25.1",
|
|
27
27
|
"mrmime": "^1.0.1",
|
|
28
28
|
"signale": "^1.4.0",
|
|
@@ -43,245 +43,282 @@ function _buildApplication(options, context, pluginsOrExtensions) {
|
|
|
43
43
|
}
|
|
44
44
|
return (0, private_1.buildApplicationInternal)(options, context, extensions);
|
|
45
45
|
}
|
|
46
|
-
function runBuilder(nfOptions, context) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const watch = nfOptions.watch;
|
|
81
|
-
if (runServer) {
|
|
82
|
-
target = (0, architect_1.targetFromTargetString)(outerOptions.buildTarget);
|
|
83
|
-
_options = (yield tslib_1.__await(context.getTargetOptions(target)));
|
|
84
|
-
builder = yield tslib_1.__await(context.getBuilderNameForTarget(target));
|
|
85
|
-
options = (yield tslib_1.__await(context.validateOptions(_options, builder)));
|
|
86
|
-
}
|
|
87
|
-
options.watch = watch;
|
|
88
|
-
if (nfOptions.baseHref) {
|
|
89
|
-
options.baseHref = nfOptions.baseHref;
|
|
90
|
-
}
|
|
91
|
-
if (nfOptions.outputPath) {
|
|
92
|
-
options.outputPath = nfOptions.outputPath;
|
|
93
|
-
}
|
|
94
|
-
const rebuildEvents = new rebuild_events_1.RebuildHubs();
|
|
95
|
-
const adapter = (0, angular_esbuild_adapter_1.createAngularBuildAdapter)(options, context, rebuildEvents);
|
|
96
|
-
(0, build_2.setBuildAdapter)(adapter);
|
|
97
|
-
(0, build_2.setLogLevel)(options.verbose ? 'verbose' : 'info');
|
|
98
|
-
if (!options.outputPath) {
|
|
99
|
-
options.outputPath = `dist/${context.target.project}`;
|
|
100
|
-
}
|
|
101
|
-
const outputPath = options.outputPath;
|
|
102
|
-
const outputOptions = Object.assign(Object.assign({ browser: 'browser', server: 'server', media: 'media' }, (typeof outputPath === 'string' ? undefined : outputPath)), { base: typeof outputPath === 'string' ? outputPath : outputPath.base });
|
|
103
|
-
const i18n = yield tslib_1.__await((0, i18n_1.getI18nConfig)(context));
|
|
104
|
-
const localeFilter = getLocaleFilter(options, runServer);
|
|
105
|
-
const sourceLocaleSegment = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.sourceLocale) === 'string'
|
|
106
|
-
? i18n.sourceLocale
|
|
107
|
-
: ((_d = i18n === null || i18n === void 0 ? void 0 : i18n.sourceLocale) === null || _d === void 0 ? void 0 : _d.subPath) || ((_e = i18n === null || i18n === void 0 ? void 0 : i18n.sourceLocale) === null || _e === void 0 ? void 0 : _e.code) || '';
|
|
108
|
-
const browserOutputPath = path.join(outputOptions.base, outputOptions.browser, options.localize ? sourceLocaleSegment : '');
|
|
109
|
-
const differentDevServerOutputPath = Array.isArray(localeFilter) && localeFilter.length === 1;
|
|
110
|
-
const devServerOutputPath = !differentDevServerOutputPath
|
|
111
|
-
? browserOutputPath
|
|
112
|
-
: path.join(outputOptions.base, outputOptions.browser, options.localize[0]);
|
|
113
|
-
const entryPoint = path.join(path.dirname(options.tsConfig), 'src/main.ts');
|
|
114
|
-
const fedOptions = {
|
|
115
|
-
workspaceRoot: context.workspaceRoot,
|
|
116
|
-
outputPath: browserOutputPath,
|
|
117
|
-
federationConfig: infereConfigPath(options.tsConfig),
|
|
118
|
-
tsConfig: options.tsConfig,
|
|
119
|
-
verbose: options.verbose,
|
|
120
|
-
watch: false, // options.watch,
|
|
121
|
-
dev: !!nfOptions.dev,
|
|
122
|
-
entryPoint,
|
|
123
|
-
buildNotifications: nfOptions.buildNotifications,
|
|
124
|
-
};
|
|
125
|
-
const activateSsr = nfOptions.ssr && !nfOptions.dev;
|
|
126
|
-
const config = yield tslib_1.__await((0, build_2.loadFederationConfig)(fedOptions));
|
|
127
|
-
const externals = (0, build_2.getExternals)(config);
|
|
128
|
-
const plugins = [
|
|
129
|
-
(0, shared_mappings_plugin_1.createSharedMappingsPlugin)(config.sharedMappings),
|
|
130
|
-
{
|
|
131
|
-
name: 'externals',
|
|
132
|
-
setup(build) {
|
|
133
|
-
if (!activateSsr && build.initialOptions.platform !== 'node') {
|
|
134
|
-
build.initialOptions.external = externals.filter((e) => e !== 'tslib');
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
// SSR build fails when externals are provided via the plugin
|
|
140
|
-
if (activateSsr) {
|
|
141
|
-
options.externalDependencies = externals;
|
|
142
|
-
}
|
|
143
|
-
const isLocalDevelopment = runServer && nfOptions.dev;
|
|
144
|
-
// Initialize SSE reloader only for local development
|
|
145
|
-
if (isLocalDevelopment && ((_f = nfOptions.buildNotifications) === null || _f === void 0 ? void 0 : _f.enable)) {
|
|
146
|
-
federation_build_notifier_1.federationBuildNotifier.initialize(nfOptions.buildNotifications.endpoint);
|
|
46
|
+
async function* runBuilder(nfOptions, context) {
|
|
47
|
+
let target = (0, architect_1.targetFromTargetString)(nfOptions.target);
|
|
48
|
+
let targetOptions = (await context.getTargetOptions(target));
|
|
49
|
+
let builder = await context.getBuilderNameForTarget(target);
|
|
50
|
+
if (builder === '@angular-devkit/build-angular:browser-esbuild') {
|
|
51
|
+
build_2.logger.info('.: NATIVE FEDERATION - UPDATE NEEDED :.');
|
|
52
|
+
build_2.logger.info('');
|
|
53
|
+
build_2.logger.info("Since version 17.1, Native Federation uses Angular's");
|
|
54
|
+
build_2.logger.info('Application-Builder and its Dev-Server.');
|
|
55
|
+
build_2.logger.info('');
|
|
56
|
+
build_2.logger.info('If you are sill on Angular 17.0.x, please update to');
|
|
57
|
+
build_2.logger.info('Angular 17.1.x or downgrade to Native Federation 17.0.x.');
|
|
58
|
+
build_2.logger.info('');
|
|
59
|
+
build_2.logger.info('For working with Native Federation 17.1.x (recommented), ');
|
|
60
|
+
build_2.logger.info('please update your project config, e.g. in angular.json');
|
|
61
|
+
build_2.logger.info('');
|
|
62
|
+
build_2.logger.info('This command performs the needed update for default configs:');
|
|
63
|
+
build_2.logger.info('');
|
|
64
|
+
build_2.logger.info('\tng g @angular-architects/native-federation:appbuilder');
|
|
65
|
+
build_2.logger.info('');
|
|
66
|
+
build_2.logger.info('You need to run it once per application to migrate');
|
|
67
|
+
build_2.logger.info('Please find more information here: https://shorturl.at/gADJW');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Explicitly defined as devServer or if the target contains "serve"
|
|
72
|
+
*/
|
|
73
|
+
const runServer = typeof nfOptions.devServer !== 'undefined'
|
|
74
|
+
? !!nfOptions.devServer
|
|
75
|
+
: target.target.includes('serve');
|
|
76
|
+
let options = (await context.validateOptions(runServer
|
|
77
|
+
? {
|
|
78
|
+
...targetOptions,
|
|
79
|
+
port: nfOptions.port || targetOptions['port'],
|
|
147
80
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
81
|
+
: targetOptions, builder));
|
|
82
|
+
let serverOptions = null;
|
|
83
|
+
const write = true;
|
|
84
|
+
const watch = nfOptions.watch;
|
|
85
|
+
if (options['buildTarget']) {
|
|
86
|
+
serverOptions = await (0, options_1.normalizeOptions)(context, context.target.project, options);
|
|
87
|
+
target = (0, architect_1.targetFromTargetString)(options['buildTarget']);
|
|
88
|
+
targetOptions = (await context.getTargetOptions(target));
|
|
89
|
+
builder = await context.getBuilderNameForTarget(target);
|
|
90
|
+
options = (await context.validateOptions(targetOptions, builder));
|
|
91
|
+
}
|
|
92
|
+
options.watch = watch;
|
|
93
|
+
if (nfOptions.baseHref) {
|
|
94
|
+
options.baseHref = nfOptions.baseHref;
|
|
95
|
+
}
|
|
96
|
+
if (nfOptions.outputPath) {
|
|
97
|
+
options.outputPath = nfOptions.outputPath;
|
|
98
|
+
}
|
|
99
|
+
const rebuildEvents = new rebuild_events_1.RebuildHubs();
|
|
100
|
+
const adapter = (0, angular_esbuild_adapter_1.createAngularBuildAdapter)(options, context, rebuildEvents);
|
|
101
|
+
(0, build_2.setBuildAdapter)(adapter);
|
|
102
|
+
(0, build_2.setLogLevel)(options.verbose ? 'verbose' : 'info');
|
|
103
|
+
if (!options.outputPath) {
|
|
104
|
+
options.outputPath = `dist/${context.target.project}`;
|
|
105
|
+
}
|
|
106
|
+
const outputPath = options.outputPath;
|
|
107
|
+
const outputOptions = {
|
|
108
|
+
browser: 'browser',
|
|
109
|
+
server: 'server',
|
|
110
|
+
media: 'media',
|
|
111
|
+
...(typeof outputPath === 'string' ? undefined : outputPath),
|
|
112
|
+
base: typeof outputPath === 'string' ? outputPath : outputPath.base,
|
|
113
|
+
};
|
|
114
|
+
const i18n = await (0, i18n_1.getI18nConfig)(context);
|
|
115
|
+
const localeFilter = getLocaleFilter(options, runServer);
|
|
116
|
+
const sourceLocaleSegment = typeof i18n?.sourceLocale === 'string'
|
|
117
|
+
? i18n.sourceLocale
|
|
118
|
+
: i18n?.sourceLocale?.subPath || i18n?.sourceLocale?.code || '';
|
|
119
|
+
const browserOutputPath = path.join(outputOptions.base, outputOptions.browser, options.localize ? sourceLocaleSegment : '');
|
|
120
|
+
const differentDevServerOutputPath = Array.isArray(localeFilter) && localeFilter.length === 1;
|
|
121
|
+
const devServerOutputPath = !differentDevServerOutputPath
|
|
122
|
+
? browserOutputPath
|
|
123
|
+
: path.join(outputOptions.base, outputOptions.browser, options.localize[0]);
|
|
124
|
+
const entryPoint = path.join(path.dirname(options.tsConfig), 'src/main.ts');
|
|
125
|
+
const fedOptions = {
|
|
126
|
+
workspaceRoot: context.workspaceRoot,
|
|
127
|
+
outputPath: browserOutputPath,
|
|
128
|
+
federationConfig: inferConfigPath(options.tsConfig),
|
|
129
|
+
tsConfig: options.tsConfig,
|
|
130
|
+
verbose: options.verbose,
|
|
131
|
+
watch: false, // options.watch,
|
|
132
|
+
dev: !!nfOptions.dev,
|
|
133
|
+
entryPoint,
|
|
134
|
+
buildNotifications: nfOptions.buildNotifications,
|
|
135
|
+
cacheExternalArtifacts: nfOptions.cacheExternalArtifacts,
|
|
136
|
+
};
|
|
137
|
+
const activateSsr = nfOptions.ssr && !nfOptions.dev;
|
|
138
|
+
const start = process.hrtime();
|
|
139
|
+
const config = await (0, build_2.loadFederationConfig)(fedOptions);
|
|
140
|
+
build_2.logger.measure(start, 'To load the federation config.');
|
|
141
|
+
const externals = (0, build_2.getExternals)(config);
|
|
142
|
+
const plugins = [
|
|
143
|
+
(0, shared_mappings_plugin_1.createSharedMappingsPlugin)(config.sharedMappings),
|
|
144
|
+
{
|
|
145
|
+
name: 'externals',
|
|
146
|
+
setup(build) {
|
|
147
|
+
if (!activateSsr && build.initialOptions.platform !== 'node') {
|
|
148
|
+
build.initialOptions.external = externals.filter((e) => e !== 'tslib');
|
|
175
149
|
}
|
|
176
150
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
// SSR build fails when externals are provided via the plugin
|
|
154
|
+
if (activateSsr) {
|
|
155
|
+
options.externalDependencies = externals;
|
|
156
|
+
}
|
|
157
|
+
const isLocalDevelopment = runServer && nfOptions.dev;
|
|
158
|
+
// Initialize SSE reloader only for local development
|
|
159
|
+
if (isLocalDevelopment && nfOptions.buildNotifications?.enable) {
|
|
160
|
+
federation_build_notifier_1.federationBuildNotifier.initialize(nfOptions.buildNotifications.endpoint);
|
|
161
|
+
}
|
|
162
|
+
const middleware = [
|
|
163
|
+
...(isLocalDevelopment
|
|
164
|
+
? [
|
|
165
|
+
federation_build_notifier_1.federationBuildNotifier.createEventMiddleware((req) => removeBaseHref(req, options.baseHref)),
|
|
166
|
+
]
|
|
167
|
+
: []),
|
|
168
|
+
(req, res, next) => {
|
|
169
|
+
const url = removeBaseHref(req, options.baseHref);
|
|
170
|
+
const fileName = path.join(fedOptions.workspaceRoot, devServerOutputPath, url);
|
|
171
|
+
const exists = fs.existsSync(fileName);
|
|
172
|
+
if (url !== '/' && url !== '' && exists) {
|
|
173
|
+
const lookup = mrmime.lookup;
|
|
174
|
+
const mimeType = lookup(path.extname(fileName)) || 'text/javascript';
|
|
175
|
+
const rawBody = fs.readFileSync(fileName, 'utf-8');
|
|
176
|
+
// TODO: Evaluate need for debug infos
|
|
177
|
+
// const body = addDebugInformation(url, rawBody);
|
|
178
|
+
const body = rawBody;
|
|
179
|
+
res.writeHead(200, {
|
|
180
|
+
'Content-Type': mimeType,
|
|
181
|
+
'Access-Control-Allow-Origin': '*',
|
|
182
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
|
|
183
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
184
|
+
});
|
|
185
|
+
res.end(body);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
next();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
const memResults = new mem_resuts_1.MemResults();
|
|
193
|
+
let first = true;
|
|
194
|
+
let lastResult;
|
|
195
|
+
if ((0, fs_1.existsSync)(fedOptions.outputPath)) {
|
|
196
|
+
(0, fs_1.rmSync)(fedOptions.outputPath, { recursive: true });
|
|
197
|
+
}
|
|
198
|
+
if (!(0, fs_1.existsSync)(fedOptions.outputPath)) {
|
|
199
|
+
(0, fs_1.mkdirSync)(fedOptions.outputPath, { recursive: true });
|
|
200
|
+
}
|
|
201
|
+
if (!write) {
|
|
202
|
+
(0, angular_esbuild_adapter_1.setMemResultHandler)((outFiles, outDir) => {
|
|
203
|
+
const fullOutDir = outDir
|
|
204
|
+
? path.join(fedOptions.workspaceRoot, outDir)
|
|
205
|
+
: null;
|
|
206
|
+
memResults.add(outFiles.map((f) => new mem_resuts_1.EsBuildResult(f, fullOutDir)));
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
let federationResult;
|
|
210
|
+
try {
|
|
211
|
+
const start = process.hrtime();
|
|
212
|
+
federationResult = await (0, build_2.buildForFederation)(config, fedOptions, externals);
|
|
213
|
+
build_2.logger.measure(start, 'To build the artifacts.');
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
build_2.logger.error(e?.message ?? 'Building the artifacts failed');
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
if (activateSsr) {
|
|
220
|
+
writeFstartScript(fedOptions);
|
|
221
|
+
}
|
|
222
|
+
const hasLocales = i18n?.locales && Object.keys(i18n.locales).length > 0;
|
|
223
|
+
if (hasLocales && localeFilter) {
|
|
224
|
+
const start = process.hrtime();
|
|
225
|
+
(0, i18n_1.translateFederationArtefacts)(i18n, localeFilter, outputOptions.base, federationResult);
|
|
226
|
+
build_2.logger.measure(start, 'To translate the artifacts.');
|
|
227
|
+
}
|
|
228
|
+
options.deleteOutputPath = false;
|
|
229
|
+
const appBuilderName = '@angular/build:application';
|
|
230
|
+
const builderRun = runServer
|
|
231
|
+
? (0, private_1.serveWithVite)(serverOptions, appBuilderName, _buildApplication, context, nfOptions.skipHtmlTransform
|
|
232
|
+
? {}
|
|
233
|
+
: { indexHtml: transformIndexHtml(nfOptions) }, {
|
|
234
|
+
buildPlugins: plugins,
|
|
235
|
+
middleware,
|
|
236
|
+
})
|
|
237
|
+
: (0, build_1.buildApplication)(options, context, {
|
|
238
|
+
codePlugins: plugins,
|
|
239
|
+
indexHtmlTransformer: transformIndexHtml(nfOptions),
|
|
240
|
+
});
|
|
241
|
+
const rebuildQueue = new build_2.RebuildQueue();
|
|
242
|
+
try {
|
|
243
|
+
for await (const output of builderRun) {
|
|
244
|
+
lastResult = output;
|
|
245
|
+
if (!write && output['outputFiles']) {
|
|
246
|
+
memResults.add(output['outputFiles'].map((file) => new mem_resuts_1.EsBuildResult(file)));
|
|
247
|
+
}
|
|
248
|
+
if (!write && output['assetFiles']) {
|
|
249
|
+
memResults.add(output['assetFiles'].map((file) => new mem_resuts_1.NgCliAssetResult(file)));
|
|
250
|
+
}
|
|
251
|
+
// if (write && !runServer && !nfOptions.skipHtmlTransform) {
|
|
252
|
+
// updateIndexHtml(fedOptions, nfOptions);
|
|
253
|
+
// }
|
|
254
|
+
// if (!runServer) {
|
|
255
|
+
// yield output;
|
|
256
|
+
// }
|
|
257
|
+
if (!first && (nfOptions.dev || watch)) {
|
|
258
|
+
rebuildQueue
|
|
259
|
+
.enqueue(async (signal) => {
|
|
260
|
+
if (signal?.aborted) {
|
|
261
|
+
throw new build_2.AbortedError('Build canceled before starting');
|
|
262
|
+
}
|
|
263
|
+
await new Promise((resolve, reject) => {
|
|
264
|
+
const timeout = setTimeout(resolve, Math.max(10, nfOptions.rebuildDelay));
|
|
265
|
+
if (signal) {
|
|
266
|
+
const abortHandler = () => {
|
|
267
|
+
clearTimeout(timeout);
|
|
268
|
+
reject(new build_2.AbortedError('[builder] During delay.'));
|
|
269
|
+
};
|
|
270
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
if (signal?.aborted) {
|
|
274
|
+
throw new build_2.AbortedError('[builder] Before federation build.');
|
|
232
275
|
}
|
|
233
|
-
|
|
234
|
-
|
|
276
|
+
const start = process.hrtime();
|
|
277
|
+
federationResult = await (0, build_2.buildForFederation)(config, fedOptions, externals, {
|
|
278
|
+
skipMappingsAndExposed: false,
|
|
279
|
+
skipShared: true,
|
|
280
|
+
signal,
|
|
281
|
+
});
|
|
282
|
+
if (signal?.aborted) {
|
|
283
|
+
throw new build_2.AbortedError('[builder] After federation build.');
|
|
235
284
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// }
|
|
239
|
-
// if (!runServer) {
|
|
240
|
-
// yield output;
|
|
241
|
-
// }
|
|
242
|
-
if (!first && (nfOptions.dev || watch)) {
|
|
243
|
-
setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
try {
|
|
245
|
-
federationResult = yield (0, build_2.buildForFederation)(config, fedOptions, externals, {
|
|
246
|
-
skipMappingsAndExposed: false,
|
|
247
|
-
skipShared: true,
|
|
248
|
-
});
|
|
249
|
-
if (hasLocales && localeFilter) {
|
|
250
|
-
(0, i18n_1.translateFederationArtefacts)(i18n, localeFilter, outputOptions.base, federationResult);
|
|
251
|
-
}
|
|
252
|
-
build_2.logger.info('Done!');
|
|
253
|
-
// Notifies about build completion
|
|
254
|
-
if (isLocalDevelopment) {
|
|
255
|
-
federation_build_notifier_1.federationBuildNotifier.broadcastBuildCompletion();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
build_2.logger.error('Federation rebuild failed!');
|
|
260
|
-
// Notifies about build failure
|
|
261
|
-
if (isLocalDevelopment) {
|
|
262
|
-
federation_build_notifier_1.federationBuildNotifier.broadcastBuildError(error);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}), nfOptions.rebuildDelay);
|
|
285
|
+
if (hasLocales && localeFilter) {
|
|
286
|
+
(0, i18n_1.translateFederationArtefacts)(i18n, localeFilter, outputOptions.base, federationResult);
|
|
266
287
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
288
|
+
if (signal?.aborted) {
|
|
289
|
+
throw new build_2.AbortedError('[builder] After federation translations.');
|
|
290
|
+
}
|
|
291
|
+
build_2.logger.info('Done!');
|
|
292
|
+
if (isLocalDevelopment) {
|
|
293
|
+
federation_build_notifier_1.federationBuildNotifier.broadcastBuildCompletion();
|
|
294
|
+
}
|
|
295
|
+
build_2.logger.measure(start, 'To rebuild the federation artifacts.');
|
|
296
|
+
})
|
|
297
|
+
.catch((error) => {
|
|
298
|
+
if (error instanceof build_2.AbortedError) {
|
|
299
|
+
build_2.logger.verbose('Rebuild was canceled. Cancellation point: ' + error?.message);
|
|
300
|
+
federation_build_notifier_1.federationBuildNotifier.broadcastBuildCancellation();
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
build_2.logger.error('Federation rebuild failed!');
|
|
304
|
+
if (options.verbose)
|
|
305
|
+
console.error(error);
|
|
306
|
+
if (isLocalDevelopment) {
|
|
307
|
+
federation_build_notifier_1.federationBuildNotifier.broadcastBuildError(error);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
276
311
|
}
|
|
312
|
+
first = false;
|
|
277
313
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
rebuildQueue.dispose();
|
|
317
|
+
if (isLocalDevelopment) {
|
|
318
|
+
federation_build_notifier_1.federationBuildNotifier.stopEventServer();
|
|
282
319
|
}
|
|
283
|
-
|
|
284
|
-
}
|
|
320
|
+
}
|
|
321
|
+
yield lastResult || { success: false };
|
|
285
322
|
}
|
|
286
323
|
function removeBaseHref(req, baseHref) {
|
|
287
324
|
let url = req.url;
|
|
@@ -307,7 +344,7 @@ function getLocaleFilter(options, runServer) {
|
|
|
307
344
|
}
|
|
308
345
|
return localize;
|
|
309
346
|
}
|
|
310
|
-
function
|
|
347
|
+
function inferConfigPath(tsConfig) {
|
|
311
348
|
const relProjectPath = path.dirname(tsConfig);
|
|
312
349
|
const relConfigPath = path.join(relProjectPath, 'federation.config.js');
|
|
313
350
|
return relConfigPath;
|
|
@@ -324,7 +361,10 @@ function addDebugInformation(fileName, rawBody) {
|
|
|
324
361
|
if (!shared) {
|
|
325
362
|
return rawBody;
|
|
326
363
|
}
|
|
327
|
-
const sharedForVite = shared.map((s) => (
|
|
364
|
+
const sharedForVite = shared.map((s) => ({
|
|
365
|
+
...s,
|
|
366
|
+
packageName: `/@id/${s.packageName}`,
|
|
367
|
+
}));
|
|
328
368
|
remoteEntry.shared = [...shared, ...sharedForVite];
|
|
329
369
|
return JSON.stringify(remoteEntry, null, 2);
|
|
330
370
|
}
|