@module-federation/esbuild 0.0.0-next-20240530211114 → 0.0.2

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 CHANGED
@@ -57,6 +57,18 @@ module.exports = withFederation({
57
57
  './Component': './src/Component',
58
58
  },
59
59
  shared: {
60
+ react: {
61
+ singleton: true,
62
+ version: '^18.2.0',
63
+ },
64
+ 'react-dom': {
65
+ singleton: true,
66
+ version: '^18.2.0',
67
+ },
68
+ rxjs: {
69
+ singleton: true,
70
+ version: '^7.8.1',
71
+ },
60
72
  ...shareAll({
61
73
  singleton: true,
62
74
  strictVersion: true,
@@ -98,7 +110,7 @@ Creates an esbuild plugin for Module Federation.
98
110
  - `remotes` (object, optional): An object specifying the remote applications and their entry points.
99
111
  - `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
100
112
  - `shared` (array, optional): An array of package names to be shared between the host and remote applications.
101
-
113
+
102
114
  Returns an esbuild plugin instance.
103
115
 
104
116
 
package/dist/build.cjs.js CHANGED
@@ -147,8 +147,8 @@ function normalize(path, trailingSlash) {
147
147
  return cand;
148
148
  }
149
149
 
150
- function _extends$1() {
151
- _extends$1 = Object.assign || function(target) {
150
+ function _extends$2() {
151
+ _extends$2 = Object.assign || function(target) {
152
152
  for(var i = 1; i < arguments.length; i++){
153
153
  var source = arguments[i];
154
154
  for(var key in source){
@@ -159,7 +159,7 @@ function _extends$1() {
159
159
  }
160
160
  return target;
161
161
  };
162
- return _extends$1.apply(this, arguments);
162
+ return _extends$2.apply(this, arguments);
163
163
  }
164
164
  const packageCache = {};
165
165
  function findPackageJsonFiles(project, workspace) {
@@ -188,7 +188,7 @@ function getVersionMapCacheKey(project, workspace) {
188
188
  return `${project}**${workspace}`;
189
189
  }
190
190
  function getVersionMaps(project, workspace) {
191
- return getPackageJsonFiles(project, workspace).map((json)=>_extends$1({}, json.content['dependencies']));
191
+ return getPackageJsonFiles(project, workspace).map((json)=>_extends$2({}, json.content['dependencies']));
192
192
  }
193
193
  function getPackageJsonFiles(project, workspace) {
194
194
  const cacheKey = getVersionMapCacheKey(project, workspace);
@@ -236,6 +236,20 @@ function getPkgFolder(packageName) {
236
236
  return folder;
237
237
  }
238
238
 
239
+ function _extends$1() {
240
+ _extends$1 = Object.assign || function(target) {
241
+ for(var i = 1; i < arguments.length; i++){
242
+ var source = arguments[i];
243
+ for(var key in source){
244
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
245
+ target[key] = source[key];
246
+ }
247
+ }
248
+ }
249
+ return target;
250
+ };
251
+ return _extends$1.apply(this, arguments);
252
+ }
239
253
  let inferVersion = false;
240
254
  const DEFAULT_SECONARIES_SKIP_LIST = [
241
255
  '@angular/router/upgrade',
@@ -261,7 +275,7 @@ function findPackageJson(folder) {
261
275
  if (fs__default["default"].existsSync(filePath)) {
262
276
  return filePath;
263
277
  }
264
- throw new Error('no package.json found. Searched the following folder and all parents: ' + folder);
278
+ throw new Error(`No package.json found. Searched the following folder and all parents: ${folder}`);
265
279
  }
266
280
  function lookupVersion(key, workspaceRoot) {
267
281
  const versionMaps = getVersionMaps(workspaceRoot, workspaceRoot);
@@ -276,17 +290,14 @@ function lookupVersion(key, workspaceRoot) {
276
290
  function lookupVersionInMap(key, versions) {
277
291
  const parts = key.split('/');
278
292
  if (parts.length >= 2 && parts[0].startsWith('@')) {
279
- key = parts[0] + '/' + parts[1];
293
+ key = `${parts[0]}/${parts[1]}`;
280
294
  } else {
281
295
  key = parts[0];
282
296
  }
283
297
  if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
284
298
  key = '@angular-architects/module-federation';
285
299
  }
286
- if (!versions[key]) {
287
- return null;
288
- }
289
- return versions[key];
300
+ return versions[key] || null;
290
301
  }
291
302
  function _findSecondaries(libPath, excludes, shareObject, acc) {
292
303
  const files = fs__default["default"].readdirSync(libPath);
@@ -300,7 +311,7 @@ function _findSecondaries(libPath, excludes, shareObject, acc) {
300
311
  if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
301
312
  continue;
302
313
  }
303
- acc[secondaryLibName] = Object.assign({}, shareObject);
314
+ acc[secondaryLibName] = _extends$1({}, shareObject);
304
315
  _findSecondaries(s, excludes, shareObject, acc);
305
316
  }
306
317
  }
@@ -330,8 +341,7 @@ function getSecondaries(includeSecondaries, libPath, key, shareObject) {
330
341
  return configured;
331
342
  }
332
343
  // Fallback: Search folders
333
- const secondaries = findSecondaries(libPath, exclude, shareObject);
334
- return secondaries;
344
+ return findSecondaries(libPath, exclude, shareObject);
335
345
  }
336
346
  function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
337
347
  const libPackageJson = path__default["default"].join(libPath, 'package.json');
@@ -343,10 +353,9 @@ function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
343
353
  if (!exports) {
344
354
  return null;
345
355
  }
346
- const keys = Object.keys(exports).filter((key)=>key != '.' && key != './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
356
+ const keys = Object.keys(exports).filter((key)=>key !== '.' && key !== './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
347
357
  const result = {};
348
358
  for (const key of keys){
349
- // const relPath = exports[key]['default'];
350
359
  const secondaryName = path__default["default"].join(parent, key).replace(/\\/g, '/');
351
360
  if (exclude.includes(secondaryName)) {
352
361
  continue;
@@ -356,13 +365,17 @@ function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
356
365
  }
357
366
  const entry = getDefaultEntry(exports, key);
358
367
  if (typeof entry !== 'string') {
359
- console.log('No entry point found for ' + secondaryName);
368
+ console.log(`No entry point found for ${secondaryName}`);
360
369
  continue;
361
370
  }
362
- if ((entry === null || entry === void 0 ? void 0 : entry.endsWith('.css')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.scss')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.less'))) {
371
+ if ([
372
+ '.css',
373
+ '.scss',
374
+ '.less'
375
+ ].some((ext)=>entry.endsWith(ext))) {
363
376
  continue;
364
377
  }
365
- result[secondaryName] = Object.assign({}, shareObject);
378
+ result[secondaryName] = _extends$1({}, shareObject);
366
379
  }
367
380
  return result;
368
381
  }
@@ -382,7 +395,7 @@ function getDefaultEntry(exports, key) {
382
395
  function shareAll(config, skip = DEFAULT_SKIP_LIST, projectPath = '') {
383
396
  projectPath = inferProjectPath(projectPath);
384
397
  const versionMaps = getVersionMaps(projectPath, projectPath);
385
- const share = {};
398
+ const shareConfig = {};
386
399
  for (const versions of versionMaps){
387
400
  const preparedSkipList = prepareSkipList(skip);
388
401
  for(const key in versions){
@@ -391,14 +404,14 @@ function shareAll(config, skip = DEFAULT_SKIP_LIST, projectPath = '') {
391
404
  }
392
405
  const inferVersion = !config.requiredVersion || config.requiredVersion === 'auto';
393
406
  const requiredVersion = inferVersion ? versions[key] : config.requiredVersion;
394
- if (!share[key]) {
395
- share[key] = Object.assign(Object.assign({}, config), {
407
+ if (!shareConfig[key]) {
408
+ shareConfig[key] = _extends$1({}, config, {
396
409
  requiredVersion
397
410
  });
398
411
  }
399
412
  }
400
413
  }
401
- return module.exports.share(share, projectPath);
414
+ return share(share, projectPath);
402
415
  }
403
416
  function inferProjectPath(projectPath) {
404
417
  if (!projectPath) {
@@ -418,7 +431,6 @@ function setInferVersion(infer) {
418
431
  function share(shareObjects, projectPath = '') {
419
432
  projectPath = inferProjectPath(projectPath);
420
433
  const packagePath = findPackageJson(projectPath);
421
- // const versions = readVersionMap(packagePath);
422
434
  const result = {};
423
435
  let includeSecondaries;
424
436
  for(const key in shareObjects){
@@ -440,7 +452,7 @@ function share(shareObjects, projectPath = '') {
440
452
  if (includeSecondaries) {
441
453
  const libPackageJson = findDepPackageJson(key, path__default["default"].dirname(packagePath));
442
454
  if (!libPackageJson) {
443
- logger.error('Could not find folder containing dep ' + key);
455
+ logger.error(`Could not find folder containing dep ${key}`);
444
456
  continue;
445
457
  }
446
458
  const libPath = path__default["default"].dirname(libPackageJson);
@@ -453,9 +465,7 @@ function share(shareObjects, projectPath = '') {
453
465
  return result;
454
466
  }
455
467
  function addSecondaries(secondaries, result) {
456
- for(const key in secondaries){
457
- result[key] = secondaries[key];
458
- }
468
+ Object.assign(result, secondaries);
459
469
  }
460
470
 
461
471
  function _extends() {
package/dist/build.esm.js CHANGED
@@ -118,8 +118,8 @@ function normalize(path, trailingSlash) {
118
118
  return cand;
119
119
  }
120
120
 
121
- function _extends$1() {
122
- _extends$1 = Object.assign || function(target) {
121
+ function _extends$2() {
122
+ _extends$2 = Object.assign || function(target) {
123
123
  for(var i = 1; i < arguments.length; i++){
124
124
  var source = arguments[i];
125
125
  for(var key in source){
@@ -130,7 +130,7 @@ function _extends$1() {
130
130
  }
131
131
  return target;
132
132
  };
133
- return _extends$1.apply(this, arguments);
133
+ return _extends$2.apply(this, arguments);
134
134
  }
135
135
  const packageCache = {};
136
136
  function findPackageJsonFiles(project, workspace) {
@@ -159,7 +159,7 @@ function getVersionMapCacheKey(project, workspace) {
159
159
  return `${project}**${workspace}`;
160
160
  }
161
161
  function getVersionMaps(project, workspace) {
162
- return getPackageJsonFiles(project, workspace).map((json)=>_extends$1({}, json.content['dependencies']));
162
+ return getPackageJsonFiles(project, workspace).map((json)=>_extends$2({}, json.content['dependencies']));
163
163
  }
164
164
  function getPackageJsonFiles(project, workspace) {
165
165
  const cacheKey = getVersionMapCacheKey(project, workspace);
@@ -207,6 +207,20 @@ function getPkgFolder(packageName) {
207
207
  return folder;
208
208
  }
209
209
 
210
+ function _extends$1() {
211
+ _extends$1 = Object.assign || function(target) {
212
+ for(var i = 1; i < arguments.length; i++){
213
+ var source = arguments[i];
214
+ for(var key in source){
215
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
216
+ target[key] = source[key];
217
+ }
218
+ }
219
+ }
220
+ return target;
221
+ };
222
+ return _extends$1.apply(this, arguments);
223
+ }
210
224
  let inferVersion = false;
211
225
  const DEFAULT_SECONARIES_SKIP_LIST = [
212
226
  '@angular/router/upgrade',
@@ -232,7 +246,7 @@ function findPackageJson(folder) {
232
246
  if (fs__default.existsSync(filePath)) {
233
247
  return filePath;
234
248
  }
235
- throw new Error('no package.json found. Searched the following folder and all parents: ' + folder);
249
+ throw new Error(`No package.json found. Searched the following folder and all parents: ${folder}`);
236
250
  }
237
251
  function lookupVersion(key, workspaceRoot) {
238
252
  const versionMaps = getVersionMaps(workspaceRoot, workspaceRoot);
@@ -247,17 +261,14 @@ function lookupVersion(key, workspaceRoot) {
247
261
  function lookupVersionInMap(key, versions) {
248
262
  const parts = key.split('/');
249
263
  if (parts.length >= 2 && parts[0].startsWith('@')) {
250
- key = parts[0] + '/' + parts[1];
264
+ key = `${parts[0]}/${parts[1]}`;
251
265
  } else {
252
266
  key = parts[0];
253
267
  }
254
268
  if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
255
269
  key = '@angular-architects/module-federation';
256
270
  }
257
- if (!versions[key]) {
258
- return null;
259
- }
260
- return versions[key];
271
+ return versions[key] || null;
261
272
  }
262
273
  function _findSecondaries(libPath, excludes, shareObject, acc) {
263
274
  const files = fs__default.readdirSync(libPath);
@@ -271,7 +282,7 @@ function _findSecondaries(libPath, excludes, shareObject, acc) {
271
282
  if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
272
283
  continue;
273
284
  }
274
- acc[secondaryLibName] = Object.assign({}, shareObject);
285
+ acc[secondaryLibName] = _extends$1({}, shareObject);
275
286
  _findSecondaries(s, excludes, shareObject, acc);
276
287
  }
277
288
  }
@@ -301,8 +312,7 @@ function getSecondaries(includeSecondaries, libPath, key, shareObject) {
301
312
  return configured;
302
313
  }
303
314
  // Fallback: Search folders
304
- const secondaries = findSecondaries(libPath, exclude, shareObject);
305
- return secondaries;
315
+ return findSecondaries(libPath, exclude, shareObject);
306
316
  }
307
317
  function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
308
318
  const libPackageJson = path__default.join(libPath, 'package.json');
@@ -314,10 +324,9 @@ function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
314
324
  if (!exports) {
315
325
  return null;
316
326
  }
317
- const keys = Object.keys(exports).filter((key)=>key != '.' && key != './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
327
+ const keys = Object.keys(exports).filter((key)=>key !== '.' && key !== './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
318
328
  const result = {};
319
329
  for (const key of keys){
320
- // const relPath = exports[key]['default'];
321
330
  const secondaryName = path__default.join(parent, key).replace(/\\/g, '/');
322
331
  if (exclude.includes(secondaryName)) {
323
332
  continue;
@@ -327,13 +336,17 @@ function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
327
336
  }
328
337
  const entry = getDefaultEntry(exports, key);
329
338
  if (typeof entry !== 'string') {
330
- console.log('No entry point found for ' + secondaryName);
339
+ console.log(`No entry point found for ${secondaryName}`);
331
340
  continue;
332
341
  }
333
- if ((entry === null || entry === void 0 ? void 0 : entry.endsWith('.css')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.scss')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.less'))) {
342
+ if ([
343
+ '.css',
344
+ '.scss',
345
+ '.less'
346
+ ].some((ext)=>entry.endsWith(ext))) {
334
347
  continue;
335
348
  }
336
- result[secondaryName] = Object.assign({}, shareObject);
349
+ result[secondaryName] = _extends$1({}, shareObject);
337
350
  }
338
351
  return result;
339
352
  }
@@ -353,7 +366,7 @@ function getDefaultEntry(exports, key) {
353
366
  function shareAll(config, skip = DEFAULT_SKIP_LIST, projectPath = '') {
354
367
  projectPath = inferProjectPath(projectPath);
355
368
  const versionMaps = getVersionMaps(projectPath, projectPath);
356
- const share = {};
369
+ const shareConfig = {};
357
370
  for (const versions of versionMaps){
358
371
  const preparedSkipList = prepareSkipList(skip);
359
372
  for(const key in versions){
@@ -362,14 +375,14 @@ function shareAll(config, skip = DEFAULT_SKIP_LIST, projectPath = '') {
362
375
  }
363
376
  const inferVersion = !config.requiredVersion || config.requiredVersion === 'auto';
364
377
  const requiredVersion = inferVersion ? versions[key] : config.requiredVersion;
365
- if (!share[key]) {
366
- share[key] = Object.assign(Object.assign({}, config), {
378
+ if (!shareConfig[key]) {
379
+ shareConfig[key] = _extends$1({}, config, {
367
380
  requiredVersion
368
381
  });
369
382
  }
370
383
  }
371
384
  }
372
- return module.exports.share(share, projectPath);
385
+ return share(share, projectPath);
373
386
  }
374
387
  function inferProjectPath(projectPath) {
375
388
  if (!projectPath) {
@@ -389,7 +402,6 @@ function setInferVersion(infer) {
389
402
  function share(shareObjects, projectPath = '') {
390
403
  projectPath = inferProjectPath(projectPath);
391
404
  const packagePath = findPackageJson(projectPath);
392
- // const versions = readVersionMap(packagePath);
393
405
  const result = {};
394
406
  let includeSecondaries;
395
407
  for(const key in shareObjects){
@@ -411,7 +423,7 @@ function share(shareObjects, projectPath = '') {
411
423
  if (includeSecondaries) {
412
424
  const libPackageJson = findDepPackageJson(key, path__default.dirname(packagePath));
413
425
  if (!libPackageJson) {
414
- logger.error('Could not find folder containing dep ' + key);
426
+ logger.error(`Could not find folder containing dep ${key}`);
415
427
  continue;
416
428
  }
417
429
  const libPath = path__default.dirname(libPackageJson);
@@ -424,9 +436,7 @@ function share(shareObjects, projectPath = '') {
424
436
  return result;
425
437
  }
426
438
  function addSecondaries(secondaries, result) {
427
- for(const key in secondaries){
428
- result[key] = secondaries[key];
429
- }
439
+ Object.assign(result, secondaries);
430
440
  }
431
441
 
432
442
  function _extends() {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/esbuild",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "author": "Zack Jackson (@ScriptedAlchemy)",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
@@ -51,20 +51,18 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "enhanced-resolve": "^5.16.1",
54
- "esm-cjs-lexer": "^0.10.0",
55
54
  "cjs-module-lexer": "^1.3.1",
56
- "@chialab/cjs-to-esm": "^0.18.0",
57
55
  "es-module-lexer": "^1.5.3",
58
- "@chialab/estransform": "^0.18.1",
59
56
  "@module-federation/sdk": "workspace:*",
60
57
  "json5": "^2.2.3",
61
58
  "@rollup/plugin-commonjs": "^22.0.2",
62
59
  "@rollup/plugin-node-resolve": "^13.3.0",
63
60
  "@rollup/plugin-replace": "^4.0.0",
64
61
  "rollup": "^2.79.0",
62
+ "@chialab/esbuild-plugin-commonjs": "^0.18.0",
63
+ "@hyrious/esbuild-plugin-commonjs": "^0.2.4",
65
64
  "rollup-plugin-node-externals": "^4.1.1",
66
65
  "esbuild": "^0.18.12",
67
- "npmlog": "^6.0.2",
68
- "acorn": "^8.8.1"
66
+ "npmlog": "^6.0.2"
69
67
  }
70
68
  }