@module-federation/cli 0.0.0-next-20250321090937 → 0.0.0-next-20250324033412
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 +142 -123
- package/dist/src/commands/dts.d.ts +2 -2
- package/dist/src/types.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -9,6 +9,21 @@ var nodeBundleRequire = require('@modern-js/node-bundle-require');
|
|
|
9
9
|
|
|
10
10
|
var applyCommonOptions = function(command) {
|
|
11
11
|
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path');
|
|
12
|
+
command.option('-m --mode <mode>', 'Specify the runtime environment. You can choose "dev" or "prod". The default value is "dev". After setting, the process.env.NODE_ENV environment variable will be automatically injected with "development" or "production" according to the value.', function(value) {
|
|
13
|
+
var validChoices = {
|
|
14
|
+
dev: 'development',
|
|
15
|
+
prod: 'production'
|
|
16
|
+
};
|
|
17
|
+
if (!Object.keys(validChoices).includes(value)) {
|
|
18
|
+
throw new Error("Invalid mode: ".concat(value, ". Valid choices are: ").concat(Object.keys(validChoices).join(', ')));
|
|
19
|
+
}
|
|
20
|
+
var targetEnv = validChoices[value];
|
|
21
|
+
if (process.env.NODE_ENV !== targetEnv) {
|
|
22
|
+
console.log("process.env.NODE_ENV is set to ".concat(targetEnv));
|
|
23
|
+
}
|
|
24
|
+
process.env.NODE_ENV = targetEnv;
|
|
25
|
+
return value;
|
|
26
|
+
}, 'dev');
|
|
12
27
|
};
|
|
13
28
|
|
|
14
29
|
function _tagged_template_literal(strings, raw) {
|
|
@@ -158,42 +173,126 @@ function _ts_generator$2(thisArg, body) {
|
|
|
158
173
|
};
|
|
159
174
|
}
|
|
160
175
|
}
|
|
161
|
-
|
|
162
|
-
|
|
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);
|
|
176
|
+
function dts(options, _) {
|
|
177
|
+
return _dts.apply(this, arguments);
|
|
169
178
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
var
|
|
179
|
+
function _dts() {
|
|
180
|
+
_dts = _async_to_generator$2(function(options, param) {
|
|
181
|
+
var readConfig, _options_fetch, fetch, _options_generate, generate, _options_root, root, output, config, mfConfig, normalizedDtsOptions, dtsManagerOptions, dtsManagerOptions1;
|
|
173
182
|
return _ts_generator$2(this, function(_state) {
|
|
174
183
|
switch(_state.label){
|
|
175
184
|
case 0:
|
|
176
|
-
|
|
185
|
+
readConfig = param.readConfig;
|
|
186
|
+
_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;
|
|
177
187
|
return [
|
|
178
188
|
4,
|
|
179
|
-
|
|
189
|
+
readConfig(config)
|
|
180
190
|
];
|
|
181
191
|
case 1:
|
|
182
|
-
|
|
192
|
+
mfConfig = _state.sent();
|
|
193
|
+
if (!dtsPlugin.isTSProject(mfConfig.dts, root)) {
|
|
194
|
+
logger.error('dts is only supported for TypeScript projects');
|
|
195
|
+
return [
|
|
196
|
+
2
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(mfConfig, root, {
|
|
200
|
+
defaultGenerateOptions: {
|
|
201
|
+
generateAPITypes: true,
|
|
202
|
+
compileInChildProcess: false,
|
|
203
|
+
abortOnError: true,
|
|
204
|
+
extractThirdParty: false,
|
|
205
|
+
extractRemoteTypes: false
|
|
206
|
+
},
|
|
207
|
+
defaultConsumeOptions: {
|
|
208
|
+
abortOnError: true,
|
|
209
|
+
consumeAPITypes: true
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
if (!normalizedDtsOptions) {
|
|
213
|
+
logger.error('dts is not enabled in module-federation.config.ts');
|
|
214
|
+
return [
|
|
215
|
+
2
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
if (!fetch) return [
|
|
219
|
+
3,
|
|
220
|
+
4
|
|
221
|
+
];
|
|
222
|
+
dtsManagerOptions = dtsPlugin.normalizeConsumeTypesOptions({
|
|
223
|
+
context: root,
|
|
224
|
+
dtsOptions: normalizedDtsOptions,
|
|
225
|
+
pluginOptions: mfConfig
|
|
226
|
+
});
|
|
227
|
+
if (!!dtsManagerOptions) return [
|
|
228
|
+
3,
|
|
229
|
+
2
|
|
230
|
+
];
|
|
231
|
+
logger.warn('dts.consumeTypes is not enabled in module-federation.config.ts, skip fetching remote types');
|
|
183
232
|
return [
|
|
184
|
-
|
|
185
|
-
|
|
233
|
+
3,
|
|
234
|
+
4
|
|
186
235
|
];
|
|
187
236
|
case 2:
|
|
188
|
-
|
|
237
|
+
logger.debug('start fetching remote types...');
|
|
189
238
|
return [
|
|
190
|
-
|
|
191
|
-
|
|
239
|
+
4,
|
|
240
|
+
dtsPlugin.consumeTypesAPI(dtsManagerOptions)
|
|
241
|
+
];
|
|
242
|
+
case 3:
|
|
243
|
+
_state.sent();
|
|
244
|
+
logger.debug('fetch remote types success!');
|
|
245
|
+
_state.label = 4;
|
|
246
|
+
case 4:
|
|
247
|
+
if (!generate) return [
|
|
248
|
+
3,
|
|
249
|
+
6
|
|
250
|
+
];
|
|
251
|
+
dtsManagerOptions1 = dtsPlugin.normalizeGenerateTypesOptions({
|
|
252
|
+
context: root,
|
|
253
|
+
outputDir: output,
|
|
254
|
+
dtsOptions: normalizedDtsOptions,
|
|
255
|
+
pluginOptions: mfConfig
|
|
256
|
+
});
|
|
257
|
+
if (!dtsManagerOptions1) {
|
|
258
|
+
logger.warn('dts.generateTypes is not enabled in module-federation.config.ts, skip generating types');
|
|
259
|
+
return [
|
|
260
|
+
2
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
logger.debug('start generating types...');
|
|
264
|
+
return [
|
|
265
|
+
4,
|
|
266
|
+
dtsPlugin.generateTypesAPI({
|
|
267
|
+
dtsManagerOptions: dtsManagerOptions1
|
|
268
|
+
})
|
|
269
|
+
];
|
|
270
|
+
case 5:
|
|
271
|
+
_state.sent();
|
|
272
|
+
logger.debug('generate types success!');
|
|
273
|
+
_state.label = 6;
|
|
274
|
+
case 6:
|
|
275
|
+
return [
|
|
276
|
+
2
|
|
192
277
|
];
|
|
193
278
|
}
|
|
194
279
|
});
|
|
195
280
|
});
|
|
196
|
-
return
|
|
281
|
+
return _dts.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function prepareCli(param) {
|
|
285
|
+
var welcomeMsg = param.welcomeMsg;
|
|
286
|
+
if (!process.env.NODE_ENV) {
|
|
287
|
+
process.env.NODE_ENV = 'development';
|
|
288
|
+
}
|
|
289
|
+
// Print a blank line to keep the greet log nice.
|
|
290
|
+
// Some package managers automatically output a blank line, some do not.
|
|
291
|
+
var npm_execpath = process.env.npm_execpath;
|
|
292
|
+
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) {
|
|
293
|
+
console.log();
|
|
294
|
+
}
|
|
295
|
+
logger.info(welcomeMsg);
|
|
197
296
|
}
|
|
198
297
|
|
|
199
298
|
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -320,122 +419,42 @@ function _ts_generator$1(thisArg, body) {
|
|
|
320
419
|
};
|
|
321
420
|
}
|
|
322
421
|
}
|
|
323
|
-
|
|
324
|
-
|
|
422
|
+
var DEFAULT_CONFIG_PATH = 'module-federation.config.ts';
|
|
423
|
+
var getConfigPath = function(userConfigPath) {
|
|
424
|
+
var defaultPath = path.resolve(process.cwd(), DEFAULT_CONFIG_PATH);
|
|
425
|
+
var filepath = userConfigPath !== null && userConfigPath !== void 0 ? userConfigPath : defaultPath;
|
|
426
|
+
return path.isAbsolute(filepath) ? filepath : path.resolve(process.cwd(), filepath);
|
|
427
|
+
};
|
|
428
|
+
function readConfig(userConfigPath) {
|
|
429
|
+
return _readConfig.apply(this, arguments);
|
|
325
430
|
}
|
|
326
|
-
function
|
|
327
|
-
|
|
328
|
-
var
|
|
431
|
+
function _readConfig() {
|
|
432
|
+
_readConfig = _async_to_generator$1(function(userConfigPath) {
|
|
433
|
+
var configPath, preBundlePath, mfConfig;
|
|
329
434
|
return _ts_generator$1(this, function(_state) {
|
|
330
435
|
switch(_state.label){
|
|
331
436
|
case 0:
|
|
332
|
-
|
|
437
|
+
configPath = getConfigPath(userConfigPath);
|
|
333
438
|
return [
|
|
334
439
|
4,
|
|
335
|
-
|
|
440
|
+
nodeBundleRequire.bundle(configPath)
|
|
336
441
|
];
|
|
337
442
|
case 1:
|
|
338
|
-
|
|
339
|
-
if (!dtsPlugin.isTSProject(mfConfig.dts, root)) {
|
|
340
|
-
logger.error('dts is only supported for TypeScript projects');
|
|
341
|
-
return [
|
|
342
|
-
2
|
|
343
|
-
];
|
|
344
|
-
}
|
|
345
|
-
normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(mfConfig, root, {
|
|
346
|
-
defaultGenerateOptions: {
|
|
347
|
-
generateAPITypes: true,
|
|
348
|
-
compileInChildProcess: false,
|
|
349
|
-
abortOnError: true,
|
|
350
|
-
extractThirdParty: false,
|
|
351
|
-
extractRemoteTypes: false
|
|
352
|
-
},
|
|
353
|
-
defaultConsumeOptions: {
|
|
354
|
-
abortOnError: true,
|
|
355
|
-
consumeAPITypes: true
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
if (!normalizedDtsOptions) {
|
|
359
|
-
logger.error('dts is not enabled in module-federation.config.ts');
|
|
360
|
-
return [
|
|
361
|
-
2
|
|
362
|
-
];
|
|
363
|
-
}
|
|
364
|
-
if (!fetch) return [
|
|
365
|
-
3,
|
|
366
|
-
4
|
|
367
|
-
];
|
|
368
|
-
dtsManagerOptions = dtsPlugin.normalizeConsumeTypesOptions({
|
|
369
|
-
context: root,
|
|
370
|
-
dtsOptions: normalizedDtsOptions,
|
|
371
|
-
pluginOptions: mfConfig
|
|
372
|
-
});
|
|
373
|
-
if (!!dtsManagerOptions) return [
|
|
374
|
-
3,
|
|
375
|
-
2
|
|
376
|
-
];
|
|
377
|
-
logger.warn('dts.consumeTypes is not enabled in module-federation.config.ts, skip fetching remote types');
|
|
378
|
-
return [
|
|
379
|
-
3,
|
|
380
|
-
4
|
|
381
|
-
];
|
|
382
|
-
case 2:
|
|
383
|
-
logger.debug('start fetching remote types...');
|
|
384
|
-
return [
|
|
385
|
-
4,
|
|
386
|
-
dtsPlugin.consumeTypesAPI(dtsManagerOptions)
|
|
387
|
-
];
|
|
388
|
-
case 3:
|
|
389
|
-
_state.sent();
|
|
390
|
-
logger.debug('fetch remote types success!');
|
|
391
|
-
_state.label = 4;
|
|
392
|
-
case 4:
|
|
393
|
-
if (!generate) return [
|
|
394
|
-
3,
|
|
395
|
-
6
|
|
396
|
-
];
|
|
397
|
-
dtsManagerOptions1 = dtsPlugin.normalizeGenerateTypesOptions({
|
|
398
|
-
context: root,
|
|
399
|
-
outputDir: output,
|
|
400
|
-
dtsOptions: normalizedDtsOptions,
|
|
401
|
-
pluginOptions: mfConfig
|
|
402
|
-
});
|
|
403
|
-
if (!dtsManagerOptions1) {
|
|
404
|
-
logger.warn('dts.generateTypes is not enabled in module-federation.config.ts, skip generating types');
|
|
405
|
-
return [
|
|
406
|
-
2
|
|
407
|
-
];
|
|
408
|
-
}
|
|
409
|
-
logger.debug('start generating types...');
|
|
443
|
+
preBundlePath = _state.sent();
|
|
410
444
|
return [
|
|
411
445
|
4,
|
|
412
|
-
|
|
413
|
-
dtsManagerOptions: dtsManagerOptions1
|
|
414
|
-
})
|
|
446
|
+
import(preBundlePath)
|
|
415
447
|
];
|
|
416
|
-
case
|
|
417
|
-
_state.sent();
|
|
418
|
-
logger.debug('generate types success!');
|
|
419
|
-
_state.label = 6;
|
|
420
|
-
case 6:
|
|
448
|
+
case 2:
|
|
449
|
+
mfConfig = _state.sent().default.default;
|
|
421
450
|
return [
|
|
422
|
-
2
|
|
451
|
+
2,
|
|
452
|
+
mfConfig
|
|
423
453
|
];
|
|
424
454
|
}
|
|
425
455
|
});
|
|
426
456
|
});
|
|
427
|
-
return
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function prepareCli(param) {
|
|
431
|
-
var welcomeMsg = param.welcomeMsg;
|
|
432
|
-
// Print a blank line to keep the greet log nice.
|
|
433
|
-
// Some package managers automatically output a blank line, some do not.
|
|
434
|
-
var npm_execpath = process.env.npm_execpath;
|
|
435
|
-
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) {
|
|
436
|
-
console.log();
|
|
437
|
-
}
|
|
438
|
-
logger.info(welcomeMsg);
|
|
457
|
+
return _readConfig.apply(this, arguments);
|
|
439
458
|
}
|
|
440
459
|
|
|
441
460
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -590,8 +609,8 @@ function _ts_generator(thisArg, body) {
|
|
|
590
609
|
};
|
|
591
610
|
}
|
|
592
611
|
}
|
|
593
|
-
function cli(
|
|
594
|
-
var name =
|
|
612
|
+
function cli(cliOptions) {
|
|
613
|
+
var name = cliOptions.name, version = cliOptions.version, applyCommands = cliOptions.applyCommands;
|
|
595
614
|
commander.program.name(name).usage('<command> [options]').version(version);
|
|
596
615
|
var dtsCommand = commander.program.command('dts');
|
|
597
616
|
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) {
|
|
@@ -614,7 +633,7 @@ function cli(param) {
|
|
|
614
633
|
]);
|
|
615
634
|
return [
|
|
616
635
|
4,
|
|
617
|
-
dts(options)
|
|
636
|
+
dts(options, cliOptions)
|
|
618
637
|
];
|
|
619
638
|
case 1:
|
|
620
639
|
_state.sent();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DtsOptions } from '../types';
|
|
2
|
-
export declare function dts(options: DtsOptions): Promise<void>;
|
|
1
|
+
import type { CliOptions, DtsOptions } from '../types';
|
|
2
|
+
export declare function dts(options: DtsOptions, { readConfig }: Required<CliOptions>): Promise<void>;
|
package/dist/src/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/cli",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250324033412",
|
|
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-
|
|
29
|
-
"@module-federation/dts-plugin": "0.0.0-next-
|
|
28
|
+
"@module-federation/sdk": "0.0.0-next-20250324033412",
|
|
29
|
+
"@module-federation/dts-plugin": "0.0.0-next-20250324033412"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "~16.11.7"
|