@module-federation/esbuild 0.0.0-next-20240524225331 → 0.0.0-next-20240528203231

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.
@@ -1,741 +0,0 @@
1
- 'use strict';
2
-
3
- var npmlog = require('npmlog');
4
- var path = require('path');
5
- var fs = require('fs');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var npmlog__default = /*#__PURE__*/_interopDefaultLegacy(npmlog);
28
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
29
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
30
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
31
-
32
- const levels = npmlog__default["default"].levels;
33
- npmlog__default["default"].addLevel('error', levels.error, {
34
- fg: 'brightWhite',
35
- bg: 'red'
36
- }, ' ERR! ');
37
- npmlog__default["default"].addLevel('warn', levels.info, {
38
- fg: 'brightWhite',
39
- bg: 'yellow'
40
- }, ' WARN ');
41
- npmlog__default["default"].addLevel('info', levels.warn, {
42
- fg: 'brightWhite',
43
- bg: 'green'
44
- }, ' INFO ');
45
- npmlog__default["default"].addLevel('notice', levels.notice, {
46
- fg: 'black',
47
- bg: 'brightYellow'
48
- }, ' NOTE ');
49
- npmlog__default["default"].addLevel('verbose', levels.verbose, {
50
- fg: 'brightWhite',
51
- bg: 'brightBlue'
52
- }, ' VRB! ');
53
- npmlog__default["default"].addLevel('silly', levels.silly, {
54
- fg: 'black',
55
- bg: 'white'
56
- }, ' DBG! ');
57
- const logger = {
58
- error: (msg)=>npmlog__default["default"].error('', msg),
59
- warn: (msg)=>npmlog__default["default"].warn('', msg),
60
- notice: (msg)=>npmlog__default["default"].notice('', msg),
61
- info: (msg)=>npmlog__default["default"].info('', msg),
62
- verbose: (msg)=>npmlog__default["default"].verbose('', msg),
63
- debug: (msg)=>npmlog__default["default"].silly('', msg)
64
- };
65
- const setLogLevel = (level)=>{
66
- npmlog__default["default"].level = level === 'debug' ? 'silly' : level;
67
- };
68
- setLogLevel('info');
69
-
70
- let _buildAdapter = async ()=>{
71
- logger.error('Please set a BuildAdapter!');
72
- return [];
73
- };
74
- function setBuildAdapter(buildAdapter) {
75
- _buildAdapter = buildAdapter;
76
- }
77
- function getBuildAdapter() {
78
- return _buildAdapter;
79
- }
80
-
81
- function _extends$2() {
82
- _extends$2 = Object.assign || function(target) {
83
- for(var i = 1; i < arguments.length; i++){
84
- var source = arguments[i];
85
- for(var key in source){
86
- if (Object.prototype.hasOwnProperty.call(source, key)) {
87
- target[key] = source[key];
88
- }
89
- }
90
- }
91
- return target;
92
- };
93
- return _extends$2.apply(this, arguments);
94
- }
95
- function writeImportMap(sharedInfo, fedOption) {
96
- const imports = sharedInfo.reduce((acc, cur)=>{
97
- return _extends$2({}, acc, {
98
- [cur.packageName]: cur.outFileName
99
- });
100
- }, {});
101
- const importMap = {
102
- imports
103
- };
104
- const importMapPath = path__namespace.join(fedOption.workspaceRoot, fedOption.outputPath, 'importmap.json');
105
- fs__namespace.writeFileSync(importMapPath, JSON.stringify(importMap, null, 2));
106
- }
107
-
108
- function writeFederationInfo(federationInfo, fedOptions) {
109
- const metaDataPath = path__namespace.join(fedOptions.workspaceRoot, fedOptions.outputPath, 'remoteEntry.json');
110
- fs__namespace.writeFileSync(metaDataPath, JSON.stringify(federationInfo, null, 2));
111
- }
112
-
113
- async function bundle(options) {
114
- const adapter = await getBuildAdapter();
115
- return await adapter(options);
116
- }
117
-
118
- function normalize(path, trailingSlash) {
119
- let cand = path.replace(/\\/g, '/');
120
- if (typeof trailingSlash === 'undefined') {
121
- return cand;
122
- }
123
- while(cand.endsWith('/')){
124
- cand = cand.substring(0, cand.length - 1);
125
- }
126
- if (trailingSlash) {
127
- return cand + '/';
128
- }
129
- return cand;
130
- }
131
-
132
- function _extends$1() {
133
- _extends$1 = Object.assign || function(target) {
134
- for(var i = 1; i < arguments.length; i++){
135
- var source = arguments[i];
136
- for(var key in source){
137
- if (Object.prototype.hasOwnProperty.call(source, key)) {
138
- target[key] = source[key];
139
- }
140
- }
141
- }
142
- return target;
143
- };
144
- return _extends$1.apply(this, arguments);
145
- }
146
- const packageCache = {};
147
- function findPackageJsonFiles(project, workspace) {
148
- return expandFolders(project, workspace).map((f)=>path__namespace.join(f, 'package.json')).filter((f)=>fs__namespace.existsSync(f));
149
- }
150
- function expandFolders(child, parent) {
151
- const result = [];
152
- parent = normalize(parent, true);
153
- child = normalize(child, true);
154
- if (!child.startsWith(parent)) {
155
- throw new Error(`Workspace folder ${path__namespace} needs to be a parent of the project folder ${child}`);
156
- }
157
- let current = child;
158
- while(current !== parent){
159
- result.push(current);
160
- const cand = normalize(path__namespace.dirname(current), true);
161
- if (cand === current) {
162
- break;
163
- }
164
- current = cand;
165
- }
166
- result.push(parent);
167
- return result;
168
- }
169
- function getPackageInfo(packageName, workspaceRoot) {
170
- workspaceRoot = normalize(workspaceRoot, true);
171
- const packageJsonInfos = getPackageJsonFiles(workspaceRoot, workspaceRoot);
172
- for (const info of packageJsonInfos){
173
- const cand = _getPackageInfo(packageName, info.directory);
174
- if (cand) {
175
- return cand;
176
- }
177
- }
178
- logger.warn('No meta data found for shared lib ' + packageName);
179
- return null;
180
- }
181
- function getVersionMapCacheKey(project, workspace) {
182
- return `${project}**${workspace}`;
183
- }
184
- function getVersionMaps(project, workspace) {
185
- return getPackageJsonFiles(project, workspace).map((json)=>_extends$1({}, json.content['dependencies']));
186
- }
187
- function getPackageJsonFiles(project, workspace) {
188
- const cacheKey = getVersionMapCacheKey(project, workspace);
189
- let maps = packageCache[cacheKey];
190
- if (maps) {
191
- return maps;
192
- }
193
- maps = findPackageJsonFiles(project, workspace).map((f)=>{
194
- const content = JSON.parse(fs__namespace.readFileSync(f, 'utf-8'));
195
- const directory = normalize(path__namespace.dirname(f), true);
196
- const result = {
197
- content,
198
- directory
199
- };
200
- return result;
201
- });
202
- packageCache[cacheKey] = maps;
203
- return maps;
204
- }
205
- function findDepPackageJson(packageName, projectRoot) {
206
- const mainPkgName = getPkgFolder(packageName);
207
- let mainPkgPath = path__namespace.join(projectRoot, 'node_modules', mainPkgName);
208
- let mainPkgJsonPath = path__namespace.join(mainPkgPath, 'package.json');
209
- let directory = projectRoot;
210
- while(path__namespace.dirname(directory) !== directory){
211
- if (fs__namespace.existsSync(mainPkgJsonPath)) {
212
- break;
213
- }
214
- directory = normalize(path__namespace.dirname(directory), true);
215
- mainPkgPath = path__namespace.join(directory, 'node_modules', mainPkgName);
216
- mainPkgJsonPath = path__namespace.join(mainPkgPath, 'package.json');
217
- }
218
- if (!fs__namespace.existsSync(mainPkgJsonPath)) {
219
- logger.verbose('No package.json found for ' + packageName + ' in ' + mainPkgPath);
220
- return null;
221
- }
222
- return mainPkgJsonPath;
223
- }
224
- function _getPackageInfo(packageName, directory) {
225
- var _mainPkgJson_exports, _mainPkgJson_exports_relSecondaryPath, _mainPkgJson_exports1, _mainPkgJson_exports_relSecondaryPath1, _mainPkgJson_exports2, _mainPkgJson_exports_relSecondaryPath2, _mainPkgJson_exports3;
226
- const mainPkgName = getPkgFolder(packageName);
227
- const mainPkgJsonPath = findDepPackageJson(packageName, directory);
228
- if (!mainPkgJsonPath) {
229
- return null;
230
- }
231
- const mainPkgPath = path__namespace.dirname(mainPkgJsonPath);
232
- const mainPkgJson = readJson(mainPkgJsonPath);
233
- const version = mainPkgJson['version'];
234
- const esm = mainPkgJson['type'] === 'module';
235
- if (!version) {
236
- logger.warn('No version found for ' + packageName);
237
- return null;
238
- }
239
- let relSecondaryPath = path__namespace.relative(mainPkgName, packageName);
240
- if (!relSecondaryPath) {
241
- relSecondaryPath = '.';
242
- } else {
243
- relSecondaryPath = './' + relSecondaryPath.replace(/\\/g, '/');
244
- }
245
- let cand = mainPkgJson == null ? void 0 : (_mainPkgJson_exports = mainPkgJson.exports) == null ? void 0 : _mainPkgJson_exports[relSecondaryPath];
246
- if (typeof cand === 'string') {
247
- return {
248
- entryPoint: path__namespace.join(mainPkgPath, cand),
249
- packageName,
250
- version,
251
- esm
252
- };
253
- }
254
- cand = mainPkgJson == null ? void 0 : (_mainPkgJson_exports1 = mainPkgJson.exports) == null ? void 0 : (_mainPkgJson_exports_relSecondaryPath = _mainPkgJson_exports1[relSecondaryPath]) == null ? void 0 : _mainPkgJson_exports_relSecondaryPath.import;
255
- if (typeof cand === 'object') {
256
- if (cand.module) {
257
- cand = cand.module;
258
- } else if (cand.import) {
259
- cand = cand.import;
260
- } else if (cand.default) {
261
- cand = cand.default;
262
- } else {
263
- cand = null;
264
- }
265
- }
266
- if (cand) {
267
- if (typeof cand === 'object') {
268
- if (cand.module) {
269
- cand = cand.module;
270
- } else if (cand.import) {
271
- cand = cand.import;
272
- } else if (cand.default) {
273
- cand = cand.default;
274
- } else {
275
- cand = null;
276
- }
277
- }
278
- return {
279
- entryPoint: path__namespace.join(mainPkgPath, cand),
280
- packageName,
281
- version,
282
- esm
283
- };
284
- }
285
- cand = mainPkgJson == null ? void 0 : (_mainPkgJson_exports2 = mainPkgJson.exports) == null ? void 0 : (_mainPkgJson_exports_relSecondaryPath1 = _mainPkgJson_exports2[relSecondaryPath]) == null ? void 0 : _mainPkgJson_exports_relSecondaryPath1.module;
286
- if (typeof cand === 'object') {
287
- if (cand.module) {
288
- cand = cand.module;
289
- } else if (cand.import) {
290
- cand = cand.import;
291
- } else if (cand.default) {
292
- cand = cand.default;
293
- } else {
294
- cand = null;
295
- }
296
- }
297
- if (cand) {
298
- return {
299
- entryPoint: path__namespace.join(mainPkgPath, cand),
300
- packageName,
301
- version,
302
- esm
303
- };
304
- }
305
- cand = mainPkgJson == null ? void 0 : (_mainPkgJson_exports3 = mainPkgJson.exports) == null ? void 0 : (_mainPkgJson_exports_relSecondaryPath2 = _mainPkgJson_exports3[relSecondaryPath]) == null ? void 0 : _mainPkgJson_exports_relSecondaryPath2.default;
306
- if (cand) {
307
- if (typeof cand === 'object') {
308
- if (cand.module) {
309
- cand = cand.module;
310
- } else if (cand.import) {
311
- cand = cand.import;
312
- } else if (cand.default) {
313
- cand = cand.default;
314
- } else {
315
- cand = null;
316
- }
317
- }
318
- return {
319
- entryPoint: path__namespace.join(mainPkgPath, cand),
320
- packageName,
321
- version,
322
- esm
323
- };
324
- }
325
- cand = mainPkgJson['module'];
326
- if (cand && relSecondaryPath === '.') {
327
- return {
328
- entryPoint: path__namespace.join(mainPkgPath, cand),
329
- packageName,
330
- version,
331
- esm: true
332
- };
333
- }
334
- const secondaryPgkPath = path__namespace.join(mainPkgPath, relSecondaryPath);
335
- const secondaryPgkJsonPath = path__namespace.join(secondaryPgkPath, 'package.json');
336
- let secondaryPgkJson = null;
337
- if (fs__namespace.existsSync(secondaryPgkJsonPath)) {
338
- secondaryPgkJson = readJson(secondaryPgkJsonPath);
339
- }
340
- if (secondaryPgkJson && secondaryPgkJson.module) {
341
- return {
342
- entryPoint: path__namespace.join(secondaryPgkPath, secondaryPgkJson.module),
343
- packageName,
344
- version,
345
- esm: true
346
- };
347
- }
348
- cand = path__namespace.join(secondaryPgkPath, 'index.mjs');
349
- if (fs__namespace.existsSync(cand)) {
350
- return {
351
- entryPoint: cand,
352
- packageName,
353
- version,
354
- esm: true
355
- };
356
- }
357
- if (secondaryPgkJson && secondaryPgkJson.main) {
358
- return {
359
- entryPoint: path__namespace.join(secondaryPgkPath, secondaryPgkJson.main),
360
- packageName,
361
- version,
362
- esm
363
- };
364
- }
365
- cand = path__namespace.join(secondaryPgkPath, 'index.js');
366
- if (fs__namespace.existsSync(cand)) {
367
- return {
368
- entryPoint: cand,
369
- packageName,
370
- version,
371
- esm
372
- };
373
- }
374
- logger.warn('No entry point found for ' + packageName);
375
- logger.warn("If you don't need this package, skip it in your federation.config.js or consider moving it into depDependencies in your package.json");
376
- return null;
377
- }
378
- function readJson(mainPkgJsonPath) {
379
- return JSON.parse(fs__namespace.readFileSync(mainPkgJsonPath, 'utf-8'));
380
- }
381
- function getPkgFolder(packageName) {
382
- const parts = packageName.split('/');
383
- let folder = parts[0];
384
- if (folder.startsWith('@')) {
385
- folder += '/' + parts[1];
386
- }
387
- return folder;
388
- }
389
-
390
- function copySrcMapIfExists(cachedFile, fullOutputPath) {
391
- const mapSrc = cachedFile + '.map';
392
- const mapDest = fullOutputPath + '.map';
393
- if (fs__namespace.existsSync(mapSrc)) {
394
- fs__namespace.copyFileSync(mapSrc, mapDest);
395
- }
396
- }
397
-
398
- async function bundleShared(config, fedOptions, externals) {
399
- const folder = fedOptions.packageJson ? path__namespace.dirname(fedOptions.packageJson) : fedOptions.workspaceRoot;
400
- const cachePath = path__namespace.join(fedOptions.workspaceRoot, 'node_modules/.cache/native-federation');
401
- fs__namespace.mkdirSync(cachePath, {
402
- recursive: true
403
- });
404
- const packageInfos = Object.keys(config.shared).map((packageName)=>getPackageInfo(packageName, folder)).filter((pi)=>!!pi);
405
- const allEntryPoints = packageInfos.map((pi)=>{
406
- const encName = pi.packageName.replace(/[^A-Za-z0-9]/g, '_');
407
- const encVersion = pi.version.replace(/[^A-Za-z0-9]/g, '_');
408
- const outName = fedOptions.dev ? `${encName}-${encVersion}-dev.js` : `${encName}-${encVersion}.js`;
409
- return {
410
- fileName: pi.entryPoint,
411
- outName
412
- };
413
- });
414
- const fullOutputPath = path__namespace.join(fedOptions.workspaceRoot, fedOptions.outputPath);
415
- const exptedResults = allEntryPoints.map((ep)=>path__namespace.join(fullOutputPath, ep.outName));
416
- const entryPoints = allEntryPoints.filter((ep)=>!fs__namespace.existsSync(path__namespace.join(cachePath, ep.outName)));
417
- if (entryPoints.length > 0) {
418
- logger.info('Preparing shared npm packages');
419
- logger.notice('This only needs to be done once, as results are cached');
420
- logger.notice("Skip packages you don't want to share in your federation config");
421
- }
422
- try {
423
- const build = await bundle({
424
- entryPoints,
425
- tsConfigPath: fedOptions.tsConfig,
426
- external: externals,
427
- outdir: cachePath,
428
- mappedPaths: config.sharedMappings,
429
- dev: fedOptions.dev,
430
- kind: 'shared-package',
431
- hash: false,
432
- packageInfos: packageInfos,
433
- name: config.name
434
- });
435
- for (const fileName of exptedResults){
436
- const outFileName = path__namespace.basename(fileName);
437
- const cachedFile = path__namespace.join(cachePath, outFileName);
438
- const realoutFileName = 'mf_' + path__namespace.basename(fileName);
439
- const realcachedFile = path__namespace.join(cachePath, realoutFileName);
440
- copyFileIfExists(cachedFile, fileName);
441
- copySrcMapIfExists(cachedFile, fileName);
442
- copyFileIfExists(realcachedFile, fileName.replace(outFileName, realoutFileName));
443
- copySrcMapIfExists(realcachedFile, fileName.replace(outFileName, realoutFileName));
444
- }
445
- } catch (e) {
446
- logger.error('Error bundling shared npm package ');
447
- if (e instanceof Error) {
448
- logger.error(e.message);
449
- }
450
- logger.error('For more information, run in verbose mode');
451
- logger.notice('');
452
- logger.notice('');
453
- logger.notice('** Important Information: ***');
454
- logger.notice('The error message above shows an issue with bundling a node_module.');
455
- logger.notice('In most cases this is because you (indirectly) shared a Node.js package,');
456
- logger.notice('while Native Federation builds for the browser.');
457
- logger.notice('You can move such packages into devDependencies or skip them in your federation.config.js.');
458
- logger.notice('');
459
- logger.notice('More Details: https://bit.ly/nf-issue');
460
- logger.notice('');
461
- logger.notice('');
462
- logger.verbose(e);
463
- }
464
- const outFileNames = [
465
- ...exptedResults
466
- ];
467
- return packageInfos.map((pi)=>{
468
- const shared = config.shared[pi.packageName];
469
- return {
470
- packageName: pi.packageName,
471
- outFileName: path__namespace.basename(outFileNames.shift() || ''),
472
- requiredVersion: shared.requiredVersion,
473
- singleton: shared.singleton,
474
- strictVersion: shared.strictVersion,
475
- version: pi.version,
476
- dev: !fedOptions.dev ? undefined : {
477
- entryPoint: normalize(pi.entryPoint)
478
- }
479
- };
480
- });
481
- }
482
- function copyFileIfExists(cachedFile, fullOutputPath) {
483
- fs__namespace.mkdirSync(path__namespace.dirname(fullOutputPath), {
484
- recursive: true
485
- });
486
- if (fs__namespace.existsSync(cachedFile)) {
487
- fs__namespace.copyFileSync(cachedFile, fullOutputPath);
488
- }
489
- }
490
-
491
- function createBuildResultMap(buildResult, isHashed) {
492
- const map = {};
493
- for (const item of buildResult){
494
- const resultName = path__default["default"].basename(item.fileName);
495
- let requestName = resultName;
496
- if (isHashed) {
497
- const start = resultName.lastIndexOf('-');
498
- const end = resultName.lastIndexOf('.');
499
- const part1 = resultName.substring(0, start);
500
- const part2 = resultName.substring(end);
501
- requestName = part1 + part2;
502
- }
503
- map[requestName] = resultName;
504
- }
505
- return map;
506
- }
507
- function lookupInResultMap(map, requestName) {
508
- const key = path__default["default"].basename(requestName);
509
- return map[key];
510
- }
511
-
512
- async function bundleExposedAndMappings(config, fedOptions, externals) {
513
- const shared = config.sharedMappings.map((sm)=>{
514
- const entryPoint = sm.path;
515
- const tmp = sm.key.replace(/[^A-Za-z0-9]/g, '_');
516
- const outFilePath = tmp + '.js';
517
- return {
518
- fileName: entryPoint,
519
- outName: outFilePath,
520
- key: sm.key
521
- };
522
- });
523
- const exposes = Object.keys(config.exposes).map((key)=>{
524
- const entryPoint = config.exposes[key];
525
- const outFilePath = key + '.js';
526
- return {
527
- fileName: entryPoint,
528
- outName: outFilePath,
529
- key
530
- };
531
- });
532
- const entryPoints = [
533
- ...shared,
534
- ...exposes
535
- ];
536
- const hash = !fedOptions.dev;
537
- logger.info('Building federation artefacts');
538
- const result = await bundle({
539
- entryPoints,
540
- outdir: fedOptions.outputPath,
541
- tsConfigPath: fedOptions.tsConfig,
542
- external: externals,
543
- dev: !!fedOptions.dev,
544
- watch: fedOptions.watch,
545
- mappedPaths: config.sharedMappings,
546
- kind: 'mapping-or-exposed',
547
- hash
548
- });
549
- const resultMap = createBuildResultMap(result, hash);
550
- const sharedResult = [];
551
- for (const item of shared){
552
- sharedResult.push({
553
- packageName: item.key,
554
- outFileName: lookupInResultMap(resultMap, item.outName),
555
- requiredVersion: '',
556
- singleton: true,
557
- strictVersion: false,
558
- version: '',
559
- dev: !fedOptions.dev ? undefined : {
560
- entryPoint: normalize(path__default["default"].normalize(item.fileName))
561
- }
562
- });
563
- }
564
- const exposedResult = [];
565
- for (const item of exposes){
566
- exposedResult.push({
567
- key: item.key,
568
- outFileName: lookupInResultMap(resultMap, item.outName),
569
- dev: !fedOptions.dev ? undefined : {
570
- entryPoint: normalize(path__default["default"].join(fedOptions.workspaceRoot, item.fileName))
571
- }
572
- });
573
- }
574
- return {
575
- mappings: sharedResult,
576
- exposes: exposedResult
577
- };
578
- }
579
- function describeExposed(config, options) {
580
- const result = [];
581
- for(const key in config.exposes){
582
- const localPath = normalize(path__default["default"].normalize(path__default["default"].join(options.workspaceRoot, config.exposes[key])));
583
- result.push({
584
- key,
585
- outFileName: '',
586
- dev: !options.dev ? undefined : {
587
- entryPoint: localPath
588
- }
589
- });
590
- }
591
- return result;
592
- }
593
- function describeSharedMappings(config, fedOptions) {
594
- const result = [];
595
- for (const m of config.sharedMappings){
596
- result.push({
597
- packageName: m.key,
598
- outFileName: '',
599
- requiredVersion: '',
600
- singleton: true,
601
- strictVersion: false,
602
- version: '',
603
- dev: !fedOptions.dev ? undefined : {
604
- entryPoint: normalize(path__default["default"].normalize(m.path))
605
- }
606
- });
607
- }
608
- return result;
609
- }
610
-
611
- const defaultBuildParams = {
612
- skipMappingsAndExposed: false
613
- };
614
- async function buildForFederation(config, fedOptions, externals, buildParams = defaultBuildParams) {
615
- let artefactInfo;
616
- if (!buildParams.skipMappingsAndExposed) {
617
- artefactInfo = await bundleExposedAndMappings(config, fedOptions, externals);
618
- }
619
- const exposedInfo = !artefactInfo ? describeExposed(config, fedOptions) : artefactInfo.exposes;
620
- const sharedPackageInfo = await bundleShared(config, fedOptions, externals);
621
- const sharedMappingInfo = !artefactInfo ? describeSharedMappings(config, fedOptions) : artefactInfo.mappings;
622
- const sharedInfo = [
623
- ...sharedPackageInfo,
624
- ...sharedMappingInfo
625
- ];
626
- const federationInfo = {
627
- name: config.name,
628
- shared: sharedInfo,
629
- exposes: exposedInfo
630
- };
631
- writeFederationInfo(federationInfo, fedOptions);
632
- writeImportMap(sharedInfo, fedOptions);
633
- return federationInfo;
634
- }
635
-
636
- function getExternals(config) {
637
- const shared = Object.keys(config.shared);
638
- const sharedMappings = config.sharedMappings.map((m)=>m.key);
639
- const remotes = config.remotes;
640
- Object.keys(remotes).reduce((acc, key)=>{
641
- if (!key) return acc;
642
- acc.push(key);
643
- acc.push(key + '/*');
644
- return acc;
645
- }, []);
646
- const externals = [
647
- ...shared,
648
- ...sharedMappings
649
- ];
650
- return externals;
651
- }
652
-
653
- async function loadFederationConfig(fedOptions) {
654
- const fullConfigPath = path__namespace.join(fedOptions.workspaceRoot, fedOptions.federationConfig);
655
- if (!fs__namespace.existsSync(fullConfigPath)) {
656
- throw new Error('Expected ' + fullConfigPath);
657
- }
658
- const config = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(`${fullConfigPath}`);
659
- return config;
660
- }
661
-
662
- function _extends() {
663
- _extends = Object.assign || function(target) {
664
- for(var i = 1; i < arguments.length; i++){
665
- var source = arguments[i];
666
- for(var key in source){
667
- if (Object.prototype.hasOwnProperty.call(source, key)) {
668
- target[key] = source[key];
669
- }
670
- }
671
- }
672
- return target;
673
- };
674
- return _extends.apply(this, arguments);
675
- }
676
- let _context = {};
677
- function useWorkspace(workspaceRoot) {
678
- _context = _extends({}, _context, {
679
- workspaceRoot
680
- });
681
- }
682
- function usePackageJson(packageJson) {
683
- _context = _extends({}, _context, {
684
- packageJson
685
- });
686
- }
687
- function getConfigContext() {
688
- return _context;
689
- }
690
-
691
- let externals = [];
692
- let config;
693
- let fedOptions;
694
- let fedInfo;
695
- async function init(params) {
696
- var _getConfigContext;
697
- setBuildAdapter(params.adapter);
698
- fedOptions = params.options;
699
- useWorkspace(params.options.workspaceRoot);
700
- usePackageJson(params.options.packageJson);
701
- config = await loadFederationConfig(fedOptions);
702
- var _getConfigContext_workspaceRoot;
703
- params.options.workspaceRoot = (_getConfigContext_workspaceRoot = (_getConfigContext = getConfigContext()) == null ? void 0 : _getConfigContext.workspaceRoot) != null ? _getConfigContext_workspaceRoot : params.options.workspaceRoot;
704
- externals = getExternals(config);
705
- }
706
- async function build(buildParams = defaultBuildParams) {
707
- fedInfo = await buildForFederation(config, fedOptions, externals, buildParams);
708
- }
709
- const federationBuilder = {
710
- init,
711
- build,
712
- get federationInfo () {
713
- return fedInfo;
714
- },
715
- get externals () {
716
- return externals;
717
- },
718
- get config () {
719
- return config;
720
- }
721
- };
722
-
723
- exports.buildForFederation = buildForFederation;
724
- exports.bundleExposedAndMappings = bundleExposedAndMappings;
725
- exports.createBuildResultMap = createBuildResultMap;
726
- exports.defaultBuildParams = defaultBuildParams;
727
- exports.describeExposed = describeExposed;
728
- exports.describeSharedMappings = describeSharedMappings;
729
- exports.federationBuilder = federationBuilder;
730
- exports.findDepPackageJson = findDepPackageJson;
731
- exports.getBuildAdapter = getBuildAdapter;
732
- exports.getConfigContext = getConfigContext;
733
- exports.getExternals = getExternals;
734
- exports.getVersionMaps = getVersionMaps;
735
- exports.loadFederationConfig = loadFederationConfig;
736
- exports.logger = logger;
737
- exports.lookupInResultMap = lookupInResultMap;
738
- exports.setBuildAdapter = setBuildAdapter;
739
- exports.setLogLevel = setLogLevel;
740
- exports.writeFederationInfo = writeFederationInfo;
741
- exports.writeImportMap = writeImportMap;