@module-federation/cli 0.0.0-next-20250321032801 → 0.0.0-next-20250321084248

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/dist/index.cjs.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var commander = require('commander');
4
- var path = require('path');
4
+ var dtsPlugin = require('@module-federation/dts-plugin');
5
5
  var sdk = require('@module-federation/sdk');
6
6
  var chalk = require('chalk');
7
- var dtsPlugin = require('@module-federation/dts-plugin');
7
+ var path = require('path');
8
8
  var nodeBundleRequire = require('@modern-js/node-bundle-require');
9
9
 
10
10
  var applyCommonOptions = function(command) {
@@ -34,7 +34,7 @@ function _templateObject() {
34
34
  var PREFIX = '[ Module Federation CLI ]';
35
35
  var logger = sdk.createLogger(chalk(_templateObject(), PREFIX));
36
36
 
37
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
37
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
38
38
  try {
39
39
  var info = gen[key](arg);
40
40
  var value = info.value;
@@ -48,22 +48,22 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
48
48
  Promise.resolve(value).then(_next, _throw);
49
49
  }
50
50
  }
51
- function _async_to_generator$1(fn) {
51
+ function _async_to_generator$2(fn) {
52
52
  return function() {
53
53
  var self = this, args = arguments;
54
54
  return new Promise(function(resolve, reject) {
55
55
  var gen = fn.apply(self, args);
56
56
  function _next(value) {
57
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
57
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
58
58
  }
59
59
  function _throw(err) {
60
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
60
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
61
61
  }
62
62
  _next(undefined);
63
63
  });
64
64
  };
65
65
  }
66
- function _ts_generator$1(thisArg, body) {
66
+ function _ts_generator$2(thisArg, body) {
67
67
  var f, y, t, g, _ = {
68
68
  label: 0,
69
69
  sent: function() {
@@ -158,19 +158,22 @@ function _ts_generator$1(thisArg, body) {
158
158
  };
159
159
  }
160
160
  }
161
- function dts(options, _) {
162
- return _dts.apply(this, arguments);
161
+ var DEFAULT_CONFIG_PATH = 'module-federation.config.ts';
162
+ var getConfigPath = function(userConfigPath) {
163
+ var defaultPath = path.resolve(process.cwd(), DEFAULT_CONFIG_PATH);
164
+ var filepath = userConfigPath !== null && userConfigPath !== void 0 ? userConfigPath : defaultPath;
165
+ return path.isAbsolute(filepath) ? filepath : path.resolve(process.cwd(), filepath);
166
+ };
167
+ function readConfig(userConfigPath) {
168
+ return _readConfig.apply(this, arguments);
163
169
  }
164
- function _dts() {
165
- _dts = _async_to_generator$1(function(options, param) {
166
- var defaultConfig, defaultPath, _options_fetch, fetch, _options_generate, generate, _options_root, root, output, _options_config, config, configPath, preBundlePath, mfConfig, normalizedDtsOptions, dtsManagerOptions, dtsManagerOptions1;
167
- return _ts_generator$1(this, function(_state) {
170
+ function _readConfig() {
171
+ _readConfig = _async_to_generator$2(function(userConfigPath) {
172
+ var configPath, preBundlePath, mfConfig;
173
+ return _ts_generator$2(this, function(_state) {
168
174
  switch(_state.label){
169
175
  case 0:
170
- defaultConfig = param.defaultConfig;
171
- defaultPath = path.resolve(process.cwd(), defaultConfig);
172
- _options_fetch = options.fetch, fetch = _options_fetch === void 0 ? true : _options_fetch, _options_generate = options.generate, generate = _options_generate === void 0 ? true : _options_generate, _options_root = options.root, root = _options_root === void 0 ? process.cwd() : _options_root, output = options.output, _options_config = options.config, config = _options_config === void 0 ? defaultPath : _options_config;
173
- configPath = path.isAbsolute(config) ? config : path.resolve(process.cwd(), config);
176
+ configPath = getConfigPath(userConfigPath);
174
177
  return [
175
178
  4,
176
179
  nodeBundleRequire.bundle(configPath)
@@ -183,6 +186,156 @@ function _dts() {
183
186
  ];
184
187
  case 2:
185
188
  mfConfig = _state.sent().default.default;
189
+ return [
190
+ 2,
191
+ mfConfig
192
+ ];
193
+ }
194
+ });
195
+ });
196
+ return _readConfig.apply(this, arguments);
197
+ }
198
+
199
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
200
+ try {
201
+ var info = gen[key](arg);
202
+ var value = info.value;
203
+ } catch (error) {
204
+ reject(error);
205
+ return;
206
+ }
207
+ if (info.done) {
208
+ resolve(value);
209
+ } else {
210
+ Promise.resolve(value).then(_next, _throw);
211
+ }
212
+ }
213
+ function _async_to_generator$1(fn) {
214
+ return function() {
215
+ var self = this, args = arguments;
216
+ return new Promise(function(resolve, reject) {
217
+ var gen = fn.apply(self, args);
218
+ function _next(value) {
219
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
220
+ }
221
+ function _throw(err) {
222
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
223
+ }
224
+ _next(undefined);
225
+ });
226
+ };
227
+ }
228
+ function _ts_generator$1(thisArg, body) {
229
+ var f, y, t, g, _ = {
230
+ label: 0,
231
+ sent: function() {
232
+ if (t[0] & 1) throw t[1];
233
+ return t[1];
234
+ },
235
+ trys: [],
236
+ ops: []
237
+ };
238
+ return g = {
239
+ next: verb(0),
240
+ "throw": verb(1),
241
+ "return": verb(2)
242
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
243
+ return this;
244
+ }), g;
245
+ function verb(n) {
246
+ return function(v) {
247
+ return step([
248
+ n,
249
+ v
250
+ ]);
251
+ };
252
+ }
253
+ function step(op) {
254
+ if (f) throw new TypeError("Generator is already executing.");
255
+ while(_)try {
256
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
257
+ if (y = 0, t) op = [
258
+ op[0] & 2,
259
+ t.value
260
+ ];
261
+ switch(op[0]){
262
+ case 0:
263
+ case 1:
264
+ t = op;
265
+ break;
266
+ case 4:
267
+ _.label++;
268
+ return {
269
+ value: op[1],
270
+ done: false
271
+ };
272
+ case 5:
273
+ _.label++;
274
+ y = op[1];
275
+ op = [
276
+ 0
277
+ ];
278
+ continue;
279
+ case 7:
280
+ op = _.ops.pop();
281
+ _.trys.pop();
282
+ continue;
283
+ default:
284
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
285
+ _ = 0;
286
+ continue;
287
+ }
288
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
289
+ _.label = op[1];
290
+ break;
291
+ }
292
+ if (op[0] === 6 && _.label < t[1]) {
293
+ _.label = t[1];
294
+ t = op;
295
+ break;
296
+ }
297
+ if (t && _.label < t[2]) {
298
+ _.label = t[2];
299
+ _.ops.push(op);
300
+ break;
301
+ }
302
+ if (t[2]) _.ops.pop();
303
+ _.trys.pop();
304
+ continue;
305
+ }
306
+ op = body.call(thisArg, _);
307
+ } catch (e) {
308
+ op = [
309
+ 6,
310
+ e
311
+ ];
312
+ y = 0;
313
+ } finally{
314
+ f = t = 0;
315
+ }
316
+ if (op[0] & 5) throw op[1];
317
+ return {
318
+ value: op[0] ? op[1] : void 0,
319
+ done: true
320
+ };
321
+ }
322
+ }
323
+ function dts(options) {
324
+ return _dts.apply(this, arguments);
325
+ }
326
+ function _dts() {
327
+ _dts = _async_to_generator$1(function(options) {
328
+ var _options_fetch, fetch, _options_generate, generate, _options_root, root, output, config, mfConfig, normalizedDtsOptions, dtsManagerOptions, dtsManagerOptions1;
329
+ return _ts_generator$1(this, function(_state) {
330
+ switch(_state.label){
331
+ case 0:
332
+ _options_fetch = options.fetch, fetch = _options_fetch === void 0 ? true : _options_fetch, _options_generate = options.generate, generate = _options_generate === void 0 ? true : _options_generate, _options_root = options.root, root = _options_root === void 0 ? process.cwd() : _options_root, output = options.output, config = options.config;
333
+ return [
334
+ 4,
335
+ readConfig(config)
336
+ ];
337
+ case 1:
338
+ mfConfig = _state.sent();
186
339
  if (!dtsPlugin.isTSProject(mfConfig.dts, root)) {
187
340
  logger.error('dts is only supported for TypeScript projects');
188
341
  return [
@@ -210,7 +363,7 @@ function _dts() {
210
363
  }
211
364
  if (!fetch) return [
212
365
  3,
213
- 5
366
+ 4
214
367
  ];
215
368
  dtsManagerOptions = dtsPlugin.normalizeConsumeTypesOptions({
216
369
  context: root,
@@ -219,27 +372,27 @@ function _dts() {
219
372
  });
220
373
  if (!!dtsManagerOptions) return [
221
374
  3,
222
- 3
375
+ 2
223
376
  ];
224
377
  logger.warn('dts.consumeTypes is not enabled in module-federation.config.ts, skip fetching remote types');
225
378
  return [
226
379
  3,
227
- 5
380
+ 4
228
381
  ];
229
- case 3:
382
+ case 2:
230
383
  logger.debug('start fetching remote types...');
231
384
  return [
232
385
  4,
233
386
  dtsPlugin.consumeTypesAPI(dtsManagerOptions)
234
387
  ];
235
- case 4:
388
+ case 3:
236
389
  _state.sent();
237
390
  logger.debug('fetch remote types success!');
238
- _state.label = 5;
239
- case 5:
391
+ _state.label = 4;
392
+ case 4:
240
393
  if (!generate) return [
241
394
  3,
242
- 7
395
+ 6
243
396
  ];
244
397
  dtsManagerOptions1 = dtsPlugin.normalizeGenerateTypesOptions({
245
398
  context: root,
@@ -260,11 +413,11 @@ function _dts() {
260
413
  dtsManagerOptions: dtsManagerOptions1
261
414
  })
262
415
  ];
263
- case 6:
416
+ case 5:
264
417
  _state.sent();
265
418
  logger.debug('generate types success!');
266
- _state.label = 7;
267
- case 7:
419
+ _state.label = 6;
420
+ case 6:
268
421
  return [
269
422
  2
270
423
  ];
@@ -438,7 +591,7 @@ function _ts_generator(thisArg, body) {
438
591
  }
439
592
  }
440
593
  function cli(param) {
441
- var name = param.name, version = param.version, applyCommands = param.applyCommands, config = param.config;
594
+ var name = param.name, version = param.version, applyCommands = param.applyCommands;
442
595
  commander.program.name(name).usage('<command> [options]').version(version);
443
596
  var dtsCommand = commander.program.command('dts');
444
597
  dtsCommand.option('--root <root>', 'specify the project root directory').option('--output <output>', 'specify the generated dts output directory').option('--fetch <boolean>', 'fetch types from remote, default is true', function(value) {
@@ -461,9 +614,7 @@ function cli(param) {
461
614
  ]);
462
615
  return [
463
616
  4,
464
- dts(options, {
465
- defaultConfig: config
466
- })
617
+ dts(options)
467
618
  ];
468
619
  case 1:
469
620
  _state.sent();
@@ -497,12 +648,14 @@ function cli(param) {
497
648
  }
498
649
  function runCli(options) {
499
650
  var normalizedOptions = _object_spread({
651
+ loggerPrefix: PREFIX,
500
652
  welcomeMsg: "".concat("Module Federation v".concat("0.10.0"), "\n"),
501
653
  name: 'mf',
502
- config: 'module-federation.config.ts',
654
+ readConfig: readConfig,
503
655
  version: "0.10.0",
504
656
  applyCommands: function() {}
505
657
  }, options);
658
+ logger.setPrefix(normalizedOptions.loggerPrefix);
506
659
  prepareCli(normalizedOptions);
507
660
  try {
508
661
  cli(normalizedOptions);
@@ -1,4 +1,2 @@
1
1
  import type { DtsOptions } from '../types';
2
- export declare function dts(options: DtsOptions, { defaultConfig }: {
3
- defaultConfig: string;
4
- }): Promise<void>;
2
+ export declare function dts(options: DtsOptions): Promise<void>;
@@ -1,4 +1,5 @@
1
1
  import type { Command } from 'commander';
2
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
2
3
  export type CommonOptions = {
3
4
  config?: string;
4
5
  };
@@ -10,8 +11,9 @@ export type DtsOptions = {
10
11
  } & CommonOptions;
11
12
  export type CliOptions = {
12
13
  welcomeMsg?: string;
14
+ loggerPrefix?: string;
13
15
  name?: string;
14
16
  version?: string;
15
- config?: string;
17
+ readConfig?: (userConfigPath?: string) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
16
18
  applyCommands?: (command: Command, applyCommonOptions: (command: Command) => void) => void;
17
19
  };
@@ -1,3 +1,4 @@
1
1
  import { type Logger } from '@module-federation/sdk';
2
+ export declare const PREFIX = "[ Module Federation CLI ]";
2
3
  declare const logger: Logger;
3
4
  export default logger;
@@ -0,0 +1,3 @@
1
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
2
+ export declare const getConfigPath: (userConfigPath?: string) => string;
3
+ export declare function readConfig(userConfigPath?: string): Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/cli",
3
- "version": "0.0.0-next-20250321032801",
3
+ "version": "0.0.0-next-20250321084248",
4
4
  "type": "commonjs",
5
5
  "description": "Module Federation CLI",
6
6
  "homepage": "https://module-federation.io",
@@ -25,8 +25,8 @@
25
25
  "commander": "11.1.0",
26
26
  "chalk": "3.0.0",
27
27
  "@modern-js/node-bundle-require": "2.65.1",
28
- "@module-federation/sdk": "0.0.0-next-20250321032801",
29
- "@module-federation/dts-plugin": "0.0.0-next-20250321032801"
28
+ "@module-federation/sdk": "0.0.0-next-20250321084248",
29
+ "@module-federation/dts-plugin": "0.0.0-next-20250321084248"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "~16.11.7"