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