@module-federation/cli 0.0.0-next-20250312104826
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/LICENSE +21 -0
- package/README.md +63 -0
- package/bin/mf.js +4 -0
- package/dist/LICENSE +21 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +514 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/commands/dts.d.ts +4 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/types.d.ts +17 -0
- package/dist/src/utils/apply-common-options.d.ts +2 -0
- package/dist/src/utils/logger.d.ts +3 -0
- package/dist/src/utils/prepare.d.ts +2 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present hanric(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://module-federation.io/" target="blank"><img src="https://module-federation.io/module-federation.svg" alt="Module Federation 2.0" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @module-federation/cli
|
|
6
|
+
|
|
7
|
+
Module Federation CLI
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<a href="https://npmjs.com/package/@module-federation/cli">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@module-federation/cli?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
12
|
+
</a>
|
|
13
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
14
|
+
<a href="https://npmcharts.com/compare/@module-federation/cli?minimal=true"><img src="https://img.shields.io/npm/dm/@module-federation/cli.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## All commands
|
|
18
|
+
|
|
19
|
+
To view all available CLI commands, run the following command in the project directory:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @module-federation/cli -h
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The output is shown below:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
Usage: mf <command> [options]
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
-V, --version output the version number
|
|
32
|
+
-h, --help display help for command
|
|
33
|
+
|
|
34
|
+
Commands:
|
|
35
|
+
dts [options] generate or fetch the mf types
|
|
36
|
+
help [command] display help for command
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### mf dts
|
|
40
|
+
|
|
41
|
+
The mf dts command is used to generate or fetch remote types.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
Usage: mf dts [options]
|
|
45
|
+
|
|
46
|
+
generate or fetch the mf types
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
--root <root> specify the project root directory
|
|
50
|
+
--output <output> specify the generated dts output directory
|
|
51
|
+
--fetch <boolean> fetch types from remote, default is true (default: true)
|
|
52
|
+
--generate <boolean> generate types, default is true (default: true)
|
|
53
|
+
-c --config <config> specify the configuration file, can be a relative or absolute path
|
|
54
|
+
-h, --help display help for command
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
See [Documentation](https://module-federation.io/guide/start/quick-start).
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
[MIT](https://github.com/module-federation/core/blob/main/LICENSE).
|
package/bin/mf.js
ADDED
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present hanric(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var commander = require('commander');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var sdk = require('@module-federation/sdk');
|
|
6
|
+
var chalk = require('chalk');
|
|
7
|
+
var dtsPlugin = require('@module-federation/dts-plugin');
|
|
8
|
+
var nodeBundleRequire = require('@modern-js/node-bundle-require');
|
|
9
|
+
|
|
10
|
+
var applyCommonOptions = function(command) {
|
|
11
|
+
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function _tagged_template_literal(strings, raw) {
|
|
15
|
+
if (!raw) {
|
|
16
|
+
raw = strings.slice(0);
|
|
17
|
+
}
|
|
18
|
+
return Object.freeze(Object.defineProperties(strings, {
|
|
19
|
+
raw: {
|
|
20
|
+
value: Object.freeze(raw)
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function _templateObject() {
|
|
25
|
+
var data = _tagged_template_literal([
|
|
26
|
+
"{bold {cyan ",
|
|
27
|
+
"}}"
|
|
28
|
+
]);
|
|
29
|
+
_templateObject = function _templateObject() {
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
var PREFIX = '[ Module Federation CLI ]';
|
|
35
|
+
var logger = sdk.createLogger(chalk(_templateObject(), PREFIX));
|
|
36
|
+
|
|
37
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
38
|
+
try {
|
|
39
|
+
var info = gen[key](arg);
|
|
40
|
+
var value = info.value;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
reject(error);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (info.done) {
|
|
46
|
+
resolve(value);
|
|
47
|
+
} else {
|
|
48
|
+
Promise.resolve(value).then(_next, _throw);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function _async_to_generator$1(fn) {
|
|
52
|
+
return function() {
|
|
53
|
+
var self = this, args = arguments;
|
|
54
|
+
return new Promise(function(resolve, reject) {
|
|
55
|
+
var gen = fn.apply(self, args);
|
|
56
|
+
function _next(value) {
|
|
57
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
58
|
+
}
|
|
59
|
+
function _throw(err) {
|
|
60
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
61
|
+
}
|
|
62
|
+
_next(undefined);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function _ts_generator$1(thisArg, body) {
|
|
67
|
+
var f, y, t, g, _ = {
|
|
68
|
+
label: 0,
|
|
69
|
+
sent: function() {
|
|
70
|
+
if (t[0] & 1) throw t[1];
|
|
71
|
+
return t[1];
|
|
72
|
+
},
|
|
73
|
+
trys: [],
|
|
74
|
+
ops: []
|
|
75
|
+
};
|
|
76
|
+
return g = {
|
|
77
|
+
next: verb(0),
|
|
78
|
+
"throw": verb(1),
|
|
79
|
+
"return": verb(2)
|
|
80
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
81
|
+
return this;
|
|
82
|
+
}), g;
|
|
83
|
+
function verb(n) {
|
|
84
|
+
return function(v) {
|
|
85
|
+
return step([
|
|
86
|
+
n,
|
|
87
|
+
v
|
|
88
|
+
]);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
93
|
+
while(_)try {
|
|
94
|
+
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;
|
|
95
|
+
if (y = 0, t) op = [
|
|
96
|
+
op[0] & 2,
|
|
97
|
+
t.value
|
|
98
|
+
];
|
|
99
|
+
switch(op[0]){
|
|
100
|
+
case 0:
|
|
101
|
+
case 1:
|
|
102
|
+
t = op;
|
|
103
|
+
break;
|
|
104
|
+
case 4:
|
|
105
|
+
_.label++;
|
|
106
|
+
return {
|
|
107
|
+
value: op[1],
|
|
108
|
+
done: false
|
|
109
|
+
};
|
|
110
|
+
case 5:
|
|
111
|
+
_.label++;
|
|
112
|
+
y = op[1];
|
|
113
|
+
op = [
|
|
114
|
+
0
|
|
115
|
+
];
|
|
116
|
+
continue;
|
|
117
|
+
case 7:
|
|
118
|
+
op = _.ops.pop();
|
|
119
|
+
_.trys.pop();
|
|
120
|
+
continue;
|
|
121
|
+
default:
|
|
122
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
123
|
+
_ = 0;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
127
|
+
_.label = op[1];
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
131
|
+
_.label = t[1];
|
|
132
|
+
t = op;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
if (t && _.label < t[2]) {
|
|
136
|
+
_.label = t[2];
|
|
137
|
+
_.ops.push(op);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (t[2]) _.ops.pop();
|
|
141
|
+
_.trys.pop();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
op = body.call(thisArg, _);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
op = [
|
|
147
|
+
6,
|
|
148
|
+
e
|
|
149
|
+
];
|
|
150
|
+
y = 0;
|
|
151
|
+
} finally{
|
|
152
|
+
f = t = 0;
|
|
153
|
+
}
|
|
154
|
+
if (op[0] & 5) throw op[1];
|
|
155
|
+
return {
|
|
156
|
+
value: op[0] ? op[1] : void 0,
|
|
157
|
+
done: true
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function dts(options, _) {
|
|
162
|
+
return _dts.apply(this, arguments);
|
|
163
|
+
}
|
|
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) {
|
|
168
|
+
switch(_state.label){
|
|
169
|
+
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);
|
|
174
|
+
return [
|
|
175
|
+
4,
|
|
176
|
+
nodeBundleRequire.bundle(configPath)
|
|
177
|
+
];
|
|
178
|
+
case 1:
|
|
179
|
+
preBundlePath = _state.sent();
|
|
180
|
+
return [
|
|
181
|
+
4,
|
|
182
|
+
import(preBundlePath)
|
|
183
|
+
];
|
|
184
|
+
case 2:
|
|
185
|
+
mfConfig = _state.sent().default.default;
|
|
186
|
+
if (!dtsPlugin.isTSProject(mfConfig.dts, root)) {
|
|
187
|
+
logger.error('dts is only supported for TypeScript projects');
|
|
188
|
+
return [
|
|
189
|
+
2
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(mfConfig, root, {
|
|
193
|
+
defaultGenerateOptions: {
|
|
194
|
+
generateAPITypes: true,
|
|
195
|
+
compileInChildProcess: false,
|
|
196
|
+
abortOnError: true,
|
|
197
|
+
extractThirdParty: false,
|
|
198
|
+
extractRemoteTypes: false
|
|
199
|
+
},
|
|
200
|
+
defaultConsumeOptions: {
|
|
201
|
+
abortOnError: true,
|
|
202
|
+
consumeAPITypes: true
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (!normalizedDtsOptions) {
|
|
206
|
+
logger.error('dts is not enabled in module-federation.config.ts');
|
|
207
|
+
return [
|
|
208
|
+
2
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
if (!fetch) return [
|
|
212
|
+
3,
|
|
213
|
+
5
|
|
214
|
+
];
|
|
215
|
+
dtsManagerOptions = dtsPlugin.normalizeConsumeTypesOptions({
|
|
216
|
+
context: root,
|
|
217
|
+
dtsOptions: normalizedDtsOptions,
|
|
218
|
+
pluginOptions: mfConfig
|
|
219
|
+
});
|
|
220
|
+
if (!!dtsManagerOptions) return [
|
|
221
|
+
3,
|
|
222
|
+
3
|
|
223
|
+
];
|
|
224
|
+
logger.warn('dts.consumeTypes is not enabled in module-federation.config.ts, skip fetching remote types');
|
|
225
|
+
return [
|
|
226
|
+
3,
|
|
227
|
+
5
|
|
228
|
+
];
|
|
229
|
+
case 3:
|
|
230
|
+
logger.debug('start fetching remote types...');
|
|
231
|
+
return [
|
|
232
|
+
4,
|
|
233
|
+
dtsPlugin.consumeTypesAPI(dtsManagerOptions)
|
|
234
|
+
];
|
|
235
|
+
case 4:
|
|
236
|
+
_state.sent();
|
|
237
|
+
logger.debug('fetch remote types success!');
|
|
238
|
+
_state.label = 5;
|
|
239
|
+
case 5:
|
|
240
|
+
if (!generate) return [
|
|
241
|
+
3,
|
|
242
|
+
7
|
|
243
|
+
];
|
|
244
|
+
dtsManagerOptions1 = dtsPlugin.normalizeGenerateTypesOptions({
|
|
245
|
+
context: root,
|
|
246
|
+
outputDir: output,
|
|
247
|
+
dtsOptions: normalizedDtsOptions,
|
|
248
|
+
pluginOptions: mfConfig
|
|
249
|
+
});
|
|
250
|
+
if (!dtsManagerOptions1) {
|
|
251
|
+
logger.warn('dts.generateTypes is not enabled in module-federation.config.ts, skip generating types');
|
|
252
|
+
return [
|
|
253
|
+
2
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
logger.debug('start generating types...');
|
|
257
|
+
return [
|
|
258
|
+
4,
|
|
259
|
+
dtsPlugin.generateTypesAPI({
|
|
260
|
+
dtsManagerOptions: dtsManagerOptions1
|
|
261
|
+
})
|
|
262
|
+
];
|
|
263
|
+
case 6:
|
|
264
|
+
_state.sent();
|
|
265
|
+
logger.debug('generate types success!');
|
|
266
|
+
_state.label = 7;
|
|
267
|
+
case 7:
|
|
268
|
+
return [
|
|
269
|
+
2
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
return _dts.apply(this, arguments);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function prepareCli(param) {
|
|
278
|
+
var welcomeMsg = param.welcomeMsg;
|
|
279
|
+
// Print a blank line to keep the greet log nice.
|
|
280
|
+
// Some package managers automatically output a blank line, some do not.
|
|
281
|
+
var npm_execpath = process.env.npm_execpath;
|
|
282
|
+
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) {
|
|
283
|
+
console.log();
|
|
284
|
+
}
|
|
285
|
+
logger.info(welcomeMsg);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
289
|
+
try {
|
|
290
|
+
var info = gen[key](arg);
|
|
291
|
+
var value = info.value;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
reject(error);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (info.done) {
|
|
297
|
+
resolve(value);
|
|
298
|
+
} else {
|
|
299
|
+
Promise.resolve(value).then(_next, _throw);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function _async_to_generator(fn) {
|
|
303
|
+
return function() {
|
|
304
|
+
var self = this, args = arguments;
|
|
305
|
+
return new Promise(function(resolve, reject) {
|
|
306
|
+
var gen = fn.apply(self, args);
|
|
307
|
+
function _next(value) {
|
|
308
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
309
|
+
}
|
|
310
|
+
function _throw(err) {
|
|
311
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
312
|
+
}
|
|
313
|
+
_next(undefined);
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function _define_property(obj, key, value) {
|
|
318
|
+
if (key in obj) {
|
|
319
|
+
Object.defineProperty(obj, key, {
|
|
320
|
+
value: value,
|
|
321
|
+
enumerable: true,
|
|
322
|
+
configurable: true,
|
|
323
|
+
writable: true
|
|
324
|
+
});
|
|
325
|
+
} else {
|
|
326
|
+
obj[key] = value;
|
|
327
|
+
}
|
|
328
|
+
return obj;
|
|
329
|
+
}
|
|
330
|
+
function _object_spread(target) {
|
|
331
|
+
for(var i = 1; i < arguments.length; i++){
|
|
332
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
333
|
+
var ownKeys = Object.keys(source);
|
|
334
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
335
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
336
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
ownKeys.forEach(function(key) {
|
|
340
|
+
_define_property(target, key, source[key]);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return target;
|
|
344
|
+
}
|
|
345
|
+
function _ts_generator(thisArg, body) {
|
|
346
|
+
var f, y, t, g, _ = {
|
|
347
|
+
label: 0,
|
|
348
|
+
sent: function() {
|
|
349
|
+
if (t[0] & 1) throw t[1];
|
|
350
|
+
return t[1];
|
|
351
|
+
},
|
|
352
|
+
trys: [],
|
|
353
|
+
ops: []
|
|
354
|
+
};
|
|
355
|
+
return g = {
|
|
356
|
+
next: verb(0),
|
|
357
|
+
"throw": verb(1),
|
|
358
|
+
"return": verb(2)
|
|
359
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
360
|
+
return this;
|
|
361
|
+
}), g;
|
|
362
|
+
function verb(n) {
|
|
363
|
+
return function(v) {
|
|
364
|
+
return step([
|
|
365
|
+
n,
|
|
366
|
+
v
|
|
367
|
+
]);
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function step(op) {
|
|
371
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
372
|
+
while(_)try {
|
|
373
|
+
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;
|
|
374
|
+
if (y = 0, t) op = [
|
|
375
|
+
op[0] & 2,
|
|
376
|
+
t.value
|
|
377
|
+
];
|
|
378
|
+
switch(op[0]){
|
|
379
|
+
case 0:
|
|
380
|
+
case 1:
|
|
381
|
+
t = op;
|
|
382
|
+
break;
|
|
383
|
+
case 4:
|
|
384
|
+
_.label++;
|
|
385
|
+
return {
|
|
386
|
+
value: op[1],
|
|
387
|
+
done: false
|
|
388
|
+
};
|
|
389
|
+
case 5:
|
|
390
|
+
_.label++;
|
|
391
|
+
y = op[1];
|
|
392
|
+
op = [
|
|
393
|
+
0
|
|
394
|
+
];
|
|
395
|
+
continue;
|
|
396
|
+
case 7:
|
|
397
|
+
op = _.ops.pop();
|
|
398
|
+
_.trys.pop();
|
|
399
|
+
continue;
|
|
400
|
+
default:
|
|
401
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
402
|
+
_ = 0;
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
406
|
+
_.label = op[1];
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
410
|
+
_.label = t[1];
|
|
411
|
+
t = op;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
if (t && _.label < t[2]) {
|
|
415
|
+
_.label = t[2];
|
|
416
|
+
_.ops.push(op);
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
if (t[2]) _.ops.pop();
|
|
420
|
+
_.trys.pop();
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
op = body.call(thisArg, _);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
op = [
|
|
426
|
+
6,
|
|
427
|
+
e
|
|
428
|
+
];
|
|
429
|
+
y = 0;
|
|
430
|
+
} finally{
|
|
431
|
+
f = t = 0;
|
|
432
|
+
}
|
|
433
|
+
if (op[0] & 5) throw op[1];
|
|
434
|
+
return {
|
|
435
|
+
value: op[0] ? op[1] : void 0,
|
|
436
|
+
done: true
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function cli(param) {
|
|
441
|
+
var name = param.name, version = param.version, applyCommands = param.applyCommands, config = param.config;
|
|
442
|
+
commander.program.name(name).usage('<command> [options]').version(version);
|
|
443
|
+
var dtsCommand = commander.program.command('dts');
|
|
444
|
+
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) {
|
|
445
|
+
return value === 'true';
|
|
446
|
+
}, true).option('--generate <boolean>', 'generate types, default is true', function(value) {
|
|
447
|
+
return value === 'true';
|
|
448
|
+
}, true);
|
|
449
|
+
applyCommonOptions(dtsCommand);
|
|
450
|
+
dtsCommand.description('generate or fetch the mf types').action(/*#__PURE__*/ function() {
|
|
451
|
+
var _ref = _async_to_generator(function(options) {
|
|
452
|
+
var err;
|
|
453
|
+
return _ts_generator(this, function(_state) {
|
|
454
|
+
switch(_state.label){
|
|
455
|
+
case 0:
|
|
456
|
+
_state.trys.push([
|
|
457
|
+
0,
|
|
458
|
+
2,
|
|
459
|
+
,
|
|
460
|
+
3
|
|
461
|
+
]);
|
|
462
|
+
return [
|
|
463
|
+
4,
|
|
464
|
+
dts(options, {
|
|
465
|
+
defaultConfig: config
|
|
466
|
+
})
|
|
467
|
+
];
|
|
468
|
+
case 1:
|
|
469
|
+
_state.sent();
|
|
470
|
+
return [
|
|
471
|
+
3,
|
|
472
|
+
3
|
|
473
|
+
];
|
|
474
|
+
case 2:
|
|
475
|
+
err = _state.sent();
|
|
476
|
+
console.error(err);
|
|
477
|
+
process.exit(1);
|
|
478
|
+
return [
|
|
479
|
+
3,
|
|
480
|
+
3
|
|
481
|
+
];
|
|
482
|
+
case 3:
|
|
483
|
+
return [
|
|
484
|
+
2
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
return function(options) {
|
|
490
|
+
return _ref.apply(this, arguments);
|
|
491
|
+
};
|
|
492
|
+
}());
|
|
493
|
+
if (typeof applyCommands === 'function') {
|
|
494
|
+
applyCommands(commander.program, applyCommonOptions);
|
|
495
|
+
}
|
|
496
|
+
commander.program.parse();
|
|
497
|
+
}
|
|
498
|
+
function runCli(options) {
|
|
499
|
+
var normalizedOptions = _object_spread({
|
|
500
|
+
welcomeMsg: "".concat("Module Federation v".concat("0.10.0"), "\n"),
|
|
501
|
+
name: 'mf',
|
|
502
|
+
config: 'module-federation.config.ts',
|
|
503
|
+
version: "0.10.0",
|
|
504
|
+
applyCommands: function() {}
|
|
505
|
+
}, options);
|
|
506
|
+
prepareCli(normalizedOptions);
|
|
507
|
+
try {
|
|
508
|
+
cli(normalizedOptions);
|
|
509
|
+
} catch (err) {
|
|
510
|
+
console.error(err);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
exports.runCli = runCli;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runCli } from './cli';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
export type CommonOptions = {
|
|
3
|
+
config?: string;
|
|
4
|
+
};
|
|
5
|
+
export type DtsOptions = {
|
|
6
|
+
fetch?: boolean;
|
|
7
|
+
generate?: boolean;
|
|
8
|
+
root?: string;
|
|
9
|
+
output?: string;
|
|
10
|
+
} & CommonOptions;
|
|
11
|
+
export type CliOptions = {
|
|
12
|
+
welcomeMsg?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
config?: string;
|
|
16
|
+
applyCommands?: (command: Command, applyCommonOptions: (command: Command) => void) => void;
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/cli",
|
|
3
|
+
"version": "0.0.0-next-20250312104826",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"description": "Module Federation CLI",
|
|
6
|
+
"homepage": "https://module-federation.io",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/module-federation/core/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/module-federation/core",
|
|
13
|
+
"directory": "packages/cli"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"mf": "./bin/mf.js"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"main": "./dist/index.cjs.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"bin"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"commander": "11.1.0",
|
|
26
|
+
"chalk": "3.0.0",
|
|
27
|
+
"@modern-js/node-bundle-require": "2.65.1",
|
|
28
|
+
"@module-federation/sdk": "0.0.0-next-20250312104826",
|
|
29
|
+
"@module-federation/dts-plugin": "0.0.0-next-20250312104826"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "~16.11.7"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=16.0.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true,
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
}
|
|
42
|
+
}
|