@angular-architects/native-federation 21.0.2 → 21.0.4

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