@module-federation/dts-plugin 0.8.7 → 0.8.9
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/CHANGELOG.md +26 -0
- package/dist/{DTSManagerOptions-92108ee8.d.ts → DTSManagerOptions-c74c59ed.d.ts} +1 -0
- package/dist/{DtsWorker-1bad6327.d.ts → DtsWorker-484d9f4a.d.ts} +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +35 -9
- package/dist/esm/{chunk-PZ7TR7QG.js → chunk-2B3WPOMZ.js} +1 -1
- package/dist/esm/{chunk-M7Q7FIFW.js → chunk-7XB7PFWZ.js} +35 -9
- package/dist/esm/core.js +2 -2
- package/dist/esm/fork-dev-worker.js +2 -2
- package/dist/esm/fork-generate-dts.js +1 -1
- package/dist/esm/index.js +106 -121
- package/dist/fork-dev-worker.d.mts +1 -1
- package/dist/fork-dev-worker.d.ts +1 -1
- package/dist/fork-dev-worker.js +37 -11
- package/dist/fork-generate-dts.d.mts +2 -2
- package/dist/fork-generate-dts.d.ts +2 -2
- package/dist/fork-generate-dts.js +35 -9
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +179 -168
- package/dist/package.json +1 -1
- package/package.json +6 -6
package/dist/esm/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
consumeTypes,
|
|
3
3
|
generateTypesInChildProcess,
|
|
4
4
|
rpc_exports
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2B3WPOMZ.js";
|
|
6
6
|
import {
|
|
7
7
|
cloneDeepOptions,
|
|
8
8
|
generateTypes,
|
|
9
9
|
isTSProject,
|
|
10
10
|
retrieveTypesAssetsInfo,
|
|
11
11
|
validateOptions
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-7XB7PFWZ.js";
|
|
13
13
|
import {
|
|
14
14
|
getIPV4,
|
|
15
15
|
logger
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
|
|
26
26
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
27
27
|
import fs from "fs-extra";
|
|
28
|
+
import path4 from "path";
|
|
28
29
|
|
|
29
30
|
// packages/dts-plugin/src/dev-worker/createDevWorker.ts
|
|
30
31
|
import * as path2 from "path";
|
|
@@ -44,16 +45,16 @@ var _DevWorker = class _DevWorker {
|
|
|
44
45
|
}
|
|
45
46
|
// moduleFederationConfig.manifest may have un serialization options
|
|
46
47
|
removeUnSerializationOptions() {
|
|
47
|
-
var
|
|
48
|
-
(_b = (
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
(_b = (_a = this._options.host) == null ? void 0 : _a.moduleFederationConfig) == null ? true : delete _b.manifest;
|
|
49
50
|
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
50
51
|
}
|
|
51
52
|
get controlledPromise() {
|
|
52
53
|
return this._res;
|
|
53
54
|
}
|
|
54
55
|
update() {
|
|
55
|
-
var
|
|
56
|
-
(_b = (
|
|
56
|
+
var _a, _b;
|
|
57
|
+
(_b = (_a = this._rpcWorker.process) == null ? void 0 : _a.send) == null ? void 0 : _b.call(_a, {
|
|
57
58
|
type: rpc_exports.RpcGMCallTypes.CALL,
|
|
58
59
|
id: this._rpcWorker.id,
|
|
59
60
|
args: [
|
|
@@ -63,8 +64,8 @@ var _DevWorker = class _DevWorker {
|
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
exit() {
|
|
66
|
-
var
|
|
67
|
-
(
|
|
67
|
+
var _a;
|
|
68
|
+
(_a = this._rpcWorker) == null ? void 0 : _a.terminate();
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
__name(_DevWorker, "DevWorker");
|
|
@@ -90,13 +91,25 @@ __name(createDevWorker, "createDevWorker");
|
|
|
90
91
|
|
|
91
92
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
92
93
|
import { normalizeOptions, TEMP_DIR as BasicTempDir } from "@module-federation/sdk";
|
|
93
|
-
import path3 from "path";
|
|
94
94
|
|
|
95
95
|
// packages/dts-plugin/src/plugins/utils.ts
|
|
96
|
+
import path3 from "path";
|
|
96
97
|
function isDev() {
|
|
97
98
|
return process.env["NODE_ENV"] === "development";
|
|
98
99
|
}
|
|
99
100
|
__name(isDev, "isDev");
|
|
101
|
+
function isPrd() {
|
|
102
|
+
return process.env["NODE_ENV"] === "production";
|
|
103
|
+
}
|
|
104
|
+
__name(isPrd, "isPrd");
|
|
105
|
+
function getCompilerOutputDir(compiler) {
|
|
106
|
+
try {
|
|
107
|
+
return path3.relative(compiler.context, compiler.outputPath || compiler.options.output.path);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
__name(getCompilerOutputDir, "getCompilerOutputDir");
|
|
100
113
|
|
|
101
114
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
102
115
|
var PROCESS_EXIT_CODE;
|
|
@@ -106,22 +119,26 @@ var PROCESS_EXIT_CODE;
|
|
|
106
119
|
})(PROCESS_EXIT_CODE || (PROCESS_EXIT_CODE = {}));
|
|
107
120
|
function ensureTempDir(filePath) {
|
|
108
121
|
try {
|
|
109
|
-
const dir =
|
|
122
|
+
const dir = path4.dirname(filePath);
|
|
110
123
|
fs.ensureDirSync(dir);
|
|
111
124
|
} catch (_err) {
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
__name(ensureTempDir, "ensureTempDir");
|
|
115
128
|
var _DevPlugin = class _DevPlugin {
|
|
116
|
-
constructor(options) {
|
|
129
|
+
constructor(options, dtsOptions, fetchTypesPromise) {
|
|
117
130
|
__publicField(this, "name", "MFDevPlugin");
|
|
118
131
|
__publicField(this, "_options");
|
|
119
132
|
__publicField(this, "_devWorker");
|
|
133
|
+
__publicField(this, "dtsOptions");
|
|
134
|
+
__publicField(this, "fetchTypesPromise");
|
|
120
135
|
this._options = options;
|
|
136
|
+
this.fetchTypesPromise = fetchTypesPromise;
|
|
137
|
+
this.dtsOptions = dtsOptions;
|
|
121
138
|
}
|
|
122
139
|
static ensureLiveReloadEntry(options, filePath) {
|
|
123
140
|
ensureTempDir(filePath);
|
|
124
|
-
const liveReloadEntry = fs.readFileSync(
|
|
141
|
+
const liveReloadEntry = fs.readFileSync(path4.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
|
|
125
142
|
const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
|
|
126
143
|
fs.writeFileSync(filePath, liveReloadEntryWithOptions);
|
|
127
144
|
}
|
|
@@ -148,15 +165,16 @@ var _DevPlugin = class _DevPlugin {
|
|
|
148
165
|
});
|
|
149
166
|
}
|
|
150
167
|
_exit(exitCode = 0) {
|
|
151
|
-
var
|
|
152
|
-
(
|
|
168
|
+
var _a;
|
|
169
|
+
(_a = this._devWorker) == null ? void 0 : _a.exit();
|
|
153
170
|
process.exit(exitCode);
|
|
154
171
|
}
|
|
155
172
|
_afterEmit() {
|
|
156
|
-
var
|
|
157
|
-
(
|
|
173
|
+
var _a;
|
|
174
|
+
(_a = this._devWorker) == null ? void 0 : _a.update();
|
|
158
175
|
}
|
|
159
176
|
apply(compiler) {
|
|
177
|
+
var _a;
|
|
160
178
|
const { _options: { name, dev, dts } } = this;
|
|
161
179
|
new compiler.webpack.DefinePlugin({
|
|
162
180
|
FEDERATION_IPV4: JSON.stringify(getIPV4())
|
|
@@ -179,11 +197,11 @@ var _DevPlugin = class _DevPlugin {
|
|
|
179
197
|
if (!this._options.runtimePlugins) {
|
|
180
198
|
this._options.runtimePlugins = [];
|
|
181
199
|
}
|
|
182
|
-
this._options.runtimePlugins.push(
|
|
200
|
+
this._options.runtimePlugins.push(path4.resolve(__dirname, "dynamic-remote-type-hints-plugin.js"));
|
|
183
201
|
}
|
|
184
202
|
if (!normalizedDev.disableLiveReload) {
|
|
185
|
-
const TEMP_DIR =
|
|
186
|
-
const filepath =
|
|
203
|
+
const TEMP_DIR = path4.join(`${process.cwd()}/node_modules`, BasicTempDir);
|
|
204
|
+
const filepath = path4.join(TEMP_DIR, `live-reload.js`);
|
|
187
205
|
if (typeof compiler.options.entry === "object") {
|
|
188
206
|
_DevPlugin.ensureLiveReloadEntry({
|
|
189
207
|
name
|
|
@@ -206,13 +224,14 @@ var _DevPlugin = class _DevPlugin {
|
|
|
206
224
|
// remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
|
|
207
225
|
generateTypes: defaultGenerateTypes,
|
|
208
226
|
consumeTypes: defaultConsumeTypes,
|
|
209
|
-
extraOptions: {}
|
|
227
|
+
extraOptions: {},
|
|
228
|
+
displayErrorInTerminal: (_a = this.dtsOptions) == null ? void 0 : _a.displayErrorInTerminal
|
|
210
229
|
}, "mfOptions.dts")(dts);
|
|
211
230
|
const normalizedGenerateTypes = normalizeOptions(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
|
|
212
231
|
const remote = normalizedGenerateTypes === false ? void 0 : __spreadProps(__spreadValues({
|
|
213
232
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
214
233
|
context: compiler.context,
|
|
215
|
-
outputDir:
|
|
234
|
+
outputDir: getCompilerOutputDir(compiler),
|
|
216
235
|
moduleFederationConfig: __spreadValues({}, this._options),
|
|
217
236
|
hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || "@mf-types"
|
|
218
237
|
}, normalizedGenerateTypes), {
|
|
@@ -233,13 +252,15 @@ var _DevPlugin = class _DevPlugin {
|
|
|
233
252
|
if (remote && !(remote == null ? void 0 : remote.tsConfigPath) && typeof normalizedDtsOptions === "object" && normalizedDtsOptions.tsConfigPath) {
|
|
234
253
|
remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
|
|
235
254
|
}
|
|
236
|
-
this.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
255
|
+
this.fetchTypesPromise.then(() => {
|
|
256
|
+
this._devWorker = createDevWorker({
|
|
257
|
+
name,
|
|
258
|
+
remote,
|
|
259
|
+
host,
|
|
260
|
+
extraOptions,
|
|
261
|
+
disableLiveReload: normalizedDev.disableHotTypesReload,
|
|
262
|
+
disableHotTypesReload: normalizedDev.disableHotTypesReload
|
|
263
|
+
});
|
|
243
264
|
});
|
|
244
265
|
this._stopWhenSIGTERMOrSIGINT();
|
|
245
266
|
this._handleUnexpectedExit();
|
|
@@ -249,24 +270,31 @@ var _DevPlugin = class _DevPlugin {
|
|
|
249
270
|
__name(_DevPlugin, "DevPlugin");
|
|
250
271
|
var DevPlugin = _DevPlugin;
|
|
251
272
|
|
|
252
|
-
// packages/dts-plugin/src/plugins/
|
|
273
|
+
// packages/dts-plugin/src/plugins/DtsPlugin.ts
|
|
253
274
|
import { normalizeOptions as normalizeOptions4 } from "@module-federation/sdk";
|
|
254
275
|
|
|
255
276
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
256
277
|
import { normalizeOptions as normalizeOptions2 } from "@module-federation/sdk";
|
|
257
278
|
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
258
|
-
constructor(pluginOptions, dtsOptions, defaultOptions) {
|
|
279
|
+
constructor(pluginOptions, dtsOptions, defaultOptions, callback) {
|
|
259
280
|
__publicField(this, "pluginOptions");
|
|
260
281
|
__publicField(this, "dtsOptions");
|
|
261
282
|
__publicField(this, "defaultOptions");
|
|
283
|
+
__publicField(this, "callback");
|
|
262
284
|
this.pluginOptions = pluginOptions;
|
|
263
285
|
this.dtsOptions = dtsOptions;
|
|
264
286
|
this.defaultOptions = defaultOptions;
|
|
287
|
+
this.callback = callback;
|
|
265
288
|
}
|
|
266
289
|
apply(compiler) {
|
|
267
|
-
const { dtsOptions, defaultOptions, pluginOptions } = this;
|
|
290
|
+
const { dtsOptions, defaultOptions, pluginOptions, callback } = this;
|
|
291
|
+
if (isPrd()) {
|
|
292
|
+
callback();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
268
295
|
const normalizedConsumeTypes = normalizeOptions2(true, defaultOptions, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
269
296
|
if (!normalizedConsumeTypes) {
|
|
297
|
+
callback();
|
|
270
298
|
return;
|
|
271
299
|
}
|
|
272
300
|
const finalOptions = {
|
|
@@ -275,10 +303,15 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
275
303
|
context: compiler.context,
|
|
276
304
|
moduleFederationConfig: pluginOptions
|
|
277
305
|
}, normalizedConsumeTypes),
|
|
278
|
-
extraOptions: dtsOptions.extraOptions || {}
|
|
306
|
+
extraOptions: dtsOptions.extraOptions || {},
|
|
307
|
+
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
279
308
|
};
|
|
280
309
|
validateOptions(finalOptions.host);
|
|
281
|
-
consumeTypes(finalOptions)
|
|
310
|
+
consumeTypes(finalOptions).then(() => {
|
|
311
|
+
callback();
|
|
312
|
+
}).catch(() => {
|
|
313
|
+
callback();
|
|
314
|
+
});
|
|
282
315
|
}
|
|
283
316
|
};
|
|
284
317
|
__name(_ConsumeTypesPlugin, "ConsumeTypesPlugin");
|
|
@@ -286,31 +319,37 @@ var ConsumeTypesPlugin = _ConsumeTypesPlugin;
|
|
|
286
319
|
|
|
287
320
|
// packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
|
|
288
321
|
import fs2 from "fs";
|
|
322
|
+
import path5 from "path";
|
|
289
323
|
import { normalizeOptions as normalizeOptions3 } from "@module-federation/sdk";
|
|
290
|
-
import path4 from "path";
|
|
291
324
|
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
292
|
-
constructor(pluginOptions, dtsOptions, defaultOptions) {
|
|
325
|
+
constructor(pluginOptions, dtsOptions, defaultOptions, consumeTypesPromise, callback) {
|
|
293
326
|
__publicField(this, "pluginOptions");
|
|
294
327
|
__publicField(this, "dtsOptions");
|
|
295
328
|
__publicField(this, "defaultOptions");
|
|
329
|
+
__publicField(this, "consumeTypesPromise");
|
|
330
|
+
__publicField(this, "callback");
|
|
296
331
|
this.pluginOptions = pluginOptions;
|
|
297
332
|
this.dtsOptions = dtsOptions;
|
|
298
333
|
this.defaultOptions = defaultOptions;
|
|
334
|
+
this.consumeTypesPromise = consumeTypesPromise;
|
|
335
|
+
this.callback = callback;
|
|
299
336
|
}
|
|
300
337
|
apply(compiler) {
|
|
301
|
-
const { dtsOptions, defaultOptions, pluginOptions } = this;
|
|
338
|
+
const { dtsOptions, defaultOptions, pluginOptions, consumeTypesPromise, callback } = this;
|
|
302
339
|
const normalizedGenerateTypes = normalizeOptions3(true, defaultOptions, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
303
340
|
if (!normalizedGenerateTypes) {
|
|
341
|
+
callback();
|
|
304
342
|
return;
|
|
305
343
|
}
|
|
306
344
|
const finalOptions = {
|
|
307
345
|
remote: __spreadValues({
|
|
308
346
|
implementation: dtsOptions.implementation,
|
|
309
347
|
context: compiler.context,
|
|
310
|
-
outputDir:
|
|
348
|
+
outputDir: getCompilerOutputDir(compiler),
|
|
311
349
|
moduleFederationConfig: pluginOptions
|
|
312
350
|
}, normalizedGenerateTypes),
|
|
313
|
-
extraOptions: dtsOptions.extraOptions || {}
|
|
351
|
+
extraOptions: dtsOptions.extraOptions || {},
|
|
352
|
+
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
314
353
|
};
|
|
315
354
|
if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
|
|
316
355
|
finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
|
|
@@ -331,62 +370,6 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
331
370
|
}, "getGenerateTypesFn");
|
|
332
371
|
const generateTypesFn = getGenerateTypesFn();
|
|
333
372
|
let compiledOnce = false;
|
|
334
|
-
const emitTypesFilesDev = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
335
|
-
try {
|
|
336
|
-
if (!isDev()) {
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(finalOptions.remote);
|
|
340
|
-
yield generateTypesFn(finalOptions);
|
|
341
|
-
const config = finalOptions.remote.moduleFederationConfig;
|
|
342
|
-
let zipPrefix = "";
|
|
343
|
-
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
344
|
-
zipPrefix = config.manifest.filePath;
|
|
345
|
-
} else if (typeof config.manifest === "object" && config.manifest.fileName) {
|
|
346
|
-
zipPrefix = path4.dirname(config.manifest.fileName);
|
|
347
|
-
} else if (config.filename) {
|
|
348
|
-
zipPrefix = path4.dirname(config.filename);
|
|
349
|
-
}
|
|
350
|
-
if (zipTypesPath) {
|
|
351
|
-
const zipContent = fs2.readFileSync(zipTypesPath);
|
|
352
|
-
const zipOutputPath = path4.join(compiler.outputPath, zipPrefix, zipName);
|
|
353
|
-
yield new Promise((resolve2, reject) => {
|
|
354
|
-
compiler.outputFileSystem.mkdir(path4.dirname(zipOutputPath), (err) => {
|
|
355
|
-
if (err)
|
|
356
|
-
reject(err);
|
|
357
|
-
else {
|
|
358
|
-
compiler.outputFileSystem.writeFile(zipOutputPath, zipContent, (writeErr) => {
|
|
359
|
-
if (writeErr)
|
|
360
|
-
reject(writeErr);
|
|
361
|
-
else
|
|
362
|
-
resolve2();
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
if (apiTypesPath) {
|
|
369
|
-
const apiContent = fs2.readFileSync(apiTypesPath);
|
|
370
|
-
const apiOutputPath = path4.join(compiler.outputPath, zipPrefix, apiFileName);
|
|
371
|
-
yield new Promise((resolve2, reject) => {
|
|
372
|
-
compiler.outputFileSystem.mkdir(path4.dirname(apiOutputPath), (err) => {
|
|
373
|
-
if (err)
|
|
374
|
-
reject(err);
|
|
375
|
-
else {
|
|
376
|
-
compiler.outputFileSystem.writeFile(apiOutputPath, apiContent, (writeErr) => {
|
|
377
|
-
if (writeErr)
|
|
378
|
-
reject(writeErr);
|
|
379
|
-
else
|
|
380
|
-
resolve2();
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
} catch (err) {
|
|
387
|
-
console.error(err);
|
|
388
|
-
}
|
|
389
|
-
}), "emitTypesFilesDev");
|
|
390
373
|
compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
|
|
391
374
|
compilation.hooks.processAssets.tapPromise({
|
|
392
375
|
name: "mf:generateTypes",
|
|
@@ -395,12 +378,12 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
395
378
|
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
396
379
|
)
|
|
397
380
|
}, () => __async(this, null, function* () {
|
|
381
|
+
yield consumeTypesPromise;
|
|
398
382
|
try {
|
|
399
383
|
if (pluginOptions.dev === false && compiledOnce) {
|
|
400
384
|
return;
|
|
401
385
|
}
|
|
402
386
|
if (compiledOnce) {
|
|
403
|
-
emitTypesFilesDev();
|
|
404
387
|
return;
|
|
405
388
|
}
|
|
406
389
|
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(finalOptions.remote);
|
|
@@ -413,19 +396,25 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
413
396
|
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
414
397
|
zipPrefix = config.manifest.filePath;
|
|
415
398
|
} else if (typeof config.manifest === "object" && config.manifest.fileName) {
|
|
416
|
-
zipPrefix =
|
|
399
|
+
zipPrefix = path5.dirname(config.manifest.fileName);
|
|
417
400
|
} else if (config.filename) {
|
|
418
|
-
zipPrefix =
|
|
401
|
+
zipPrefix = path5.dirname(config.filename);
|
|
419
402
|
}
|
|
420
|
-
|
|
421
|
-
|
|
403
|
+
const zipAssetName = path5.join(zipPrefix, zipName);
|
|
404
|
+
if (zipTypesPath && !compilation.getAsset(zipAssetName)) {
|
|
405
|
+
compilation.emitAsset(path5.join(zipPrefix, zipName), new compiler.webpack.sources.RawSource(fs2.readFileSync(zipTypesPath), false));
|
|
422
406
|
}
|
|
423
|
-
|
|
424
|
-
|
|
407
|
+
const apiAssetName = path5.join(zipPrefix, apiFileName);
|
|
408
|
+
if (apiTypesPath && !compilation.getAsset(apiAssetName)) {
|
|
409
|
+
compilation.emitAsset(path5.join(zipPrefix, apiFileName), new compiler.webpack.sources.RawSource(fs2.readFileSync(apiTypesPath), false));
|
|
425
410
|
}
|
|
426
411
|
compiledOnce = true;
|
|
412
|
+
callback();
|
|
427
413
|
} catch (err) {
|
|
428
|
-
|
|
414
|
+
callback();
|
|
415
|
+
if (finalOptions.displayErrorInTerminal) {
|
|
416
|
+
console.error("Error in mf:generateTypes processAssets hook:", err);
|
|
417
|
+
}
|
|
429
418
|
}
|
|
430
419
|
}));
|
|
431
420
|
});
|
|
@@ -434,9 +423,8 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
434
423
|
__name(_GenerateTypesPlugin, "GenerateTypesPlugin");
|
|
435
424
|
var GenerateTypesPlugin = _GenerateTypesPlugin;
|
|
436
425
|
|
|
437
|
-
// packages/dts-plugin/src/plugins/
|
|
438
|
-
var
|
|
439
|
-
var TypesPlugin = (_a = class {
|
|
426
|
+
// packages/dts-plugin/src/plugins/DtsPlugin.ts
|
|
427
|
+
var _DtsPlugin = class _DtsPlugin {
|
|
440
428
|
constructor(options) {
|
|
441
429
|
__publicField(this, "options");
|
|
442
430
|
this.options = options;
|
|
@@ -457,26 +445,23 @@ var TypesPlugin = (_a = class {
|
|
|
457
445
|
const normalizedDtsOptions = normalizeOptions4(isTSProject(options.dts, compiler.context), {
|
|
458
446
|
generateTypes: defaultGenerateTypes,
|
|
459
447
|
consumeTypes: defaultConsumeTypes,
|
|
460
|
-
extraOptions: {}
|
|
448
|
+
extraOptions: {},
|
|
449
|
+
displayErrorInTerminal: true
|
|
461
450
|
}, "mfOptions.dts")(options.dts);
|
|
462
451
|
if (typeof normalizedDtsOptions !== "object") {
|
|
463
452
|
return;
|
|
464
453
|
}
|
|
465
|
-
|
|
466
|
-
new
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
apply(compiler) {
|
|
477
|
-
const { options } = this;
|
|
478
|
-
new DevPlugin(options).apply(compiler);
|
|
479
|
-
new TypesPlugin(options).apply(compiler);
|
|
454
|
+
let consumeTypesPromiseResolve;
|
|
455
|
+
const consumeTypesPromise = new Promise((resolve2) => {
|
|
456
|
+
consumeTypesPromiseResolve = resolve2;
|
|
457
|
+
});
|
|
458
|
+
let generateTypesPromiseResolve;
|
|
459
|
+
const generateTypesPromise = new Promise((resolve2) => {
|
|
460
|
+
generateTypesPromiseResolve = resolve2;
|
|
461
|
+
});
|
|
462
|
+
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise).apply(compiler);
|
|
463
|
+
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes, consumeTypesPromise, generateTypesPromiseResolve).apply(compiler);
|
|
464
|
+
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes, consumeTypesPromiseResolve).apply(compiler);
|
|
480
465
|
}
|
|
481
466
|
};
|
|
482
467
|
__name(_DtsPlugin, "DtsPlugin");
|
package/dist/fork-dev-worker.js
CHANGED
|
@@ -97,6 +97,7 @@ var import_typescript = __toESM(require("typescript"));
|
|
|
97
97
|
var import_axios = __toESM(require("axios"));
|
|
98
98
|
var import_http2 = __toESM(require("http"));
|
|
99
99
|
var import_https = __toESM(require("https"));
|
|
100
|
+
var import_sdk6 = require("@module-federation/sdk");
|
|
100
101
|
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
101
102
|
|
|
102
103
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
@@ -130,7 +131,7 @@ function writeTempTsConfig(tsConfig, context, name) {
|
|
|
130
131
|
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
131
132
|
return import_crypto.default.createHash("md5").update(contents).digest("hex");
|
|
132
133
|
}, "createHash");
|
|
133
|
-
const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
|
|
134
|
+
const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
|
|
134
135
|
const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
|
|
135
136
|
(0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
|
|
136
137
|
(0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
@@ -1669,6 +1670,7 @@ var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, d
|
|
|
1669
1670
|
var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
1670
1671
|
let retries = 0;
|
|
1671
1672
|
return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
|
|
1673
|
+
var _a3;
|
|
1672
1674
|
const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
|
|
1673
1675
|
while (retries++ < hostOptions.maxRetries) {
|
|
1674
1676
|
try {
|
|
@@ -1676,6 +1678,9 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1676
1678
|
const response = yield axiosGet(url, {
|
|
1677
1679
|
responseType: "arraybuffer"
|
|
1678
1680
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1681
|
+
if (typeof ((_a3 = response.headers) == null ? void 0 : _a3["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
|
|
1682
|
+
throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
|
|
1683
|
+
}
|
|
1679
1684
|
try {
|
|
1680
1685
|
if (hostOptions.deleteTypesFolder) {
|
|
1681
1686
|
yield (0, import_promises2.rm)(destinationPath, {
|
|
@@ -1688,6 +1693,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1688
1693
|
}
|
|
1689
1694
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1690
1695
|
zip.extractAllTo(destinationPath, true);
|
|
1696
|
+
fileLog(`zip.extractAllTo success destinationPath: ${destinationPath}; url: ${url}`, "downloadTypesArchive", "info");
|
|
1691
1697
|
return [
|
|
1692
1698
|
destinationFolder,
|
|
1693
1699
|
destinationPath
|
|
@@ -1888,7 +1894,9 @@ var DTSManager = (_a = class {
|
|
|
1888
1894
|
logger.success("Federated types created correctly");
|
|
1889
1895
|
} catch (error2) {
|
|
1890
1896
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1891
|
-
|
|
1897
|
+
if (this.options.displayErrorInTerminal) {
|
|
1898
|
+
logger.error(`Unable to compile federated types${error2}`);
|
|
1899
|
+
}
|
|
1892
1900
|
} else {
|
|
1893
1901
|
throw error2;
|
|
1894
1902
|
}
|
|
@@ -1967,8 +1975,9 @@ var DTSManager = (_a = class {
|
|
|
1967
1975
|
const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1968
1976
|
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1969
1977
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1978
|
+
fileLog(`success`, "downloadAPITypes", "info");
|
|
1970
1979
|
} catch (err) {
|
|
1971
|
-
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "
|
|
1980
|
+
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1972
1981
|
}
|
|
1973
1982
|
});
|
|
1974
1983
|
}
|
|
@@ -2083,9 +2092,10 @@ var DTSManager = (_a = class {
|
|
|
2083
2092
|
return __async(this, null, function* () {
|
|
2084
2093
|
var _a3, _b, _c;
|
|
2085
2094
|
try {
|
|
2086
|
-
const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
|
|
2095
|
+
const { remoteName, updateMode, remoteTarPath, remoteInfo: updatedRemoteInfo, once } = options;
|
|
2087
2096
|
const hostName = (_c = (_b = (_a3 = this.options) == null ? void 0 : _a3.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
2088
|
-
fileLog(`
|
|
2097
|
+
fileLog(`options: ${JSON.stringify(options, null, 2)};
|
|
2098
|
+
hostName: ${hostName}`, "updateTypes", "info");
|
|
2089
2099
|
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
2090
2100
|
if (!this.options.remote) {
|
|
2091
2101
|
return;
|
|
@@ -2099,13 +2109,23 @@ var DTSManager = (_a = class {
|
|
|
2099
2109
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
2100
2110
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
2101
2111
|
const consumeTypes2 = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
2102
|
-
|
|
2112
|
+
fileLog(`consumeTypes start`, "updateTypes", "info");
|
|
2113
|
+
if (!requiredRemoteInfo.zipUrl) {
|
|
2114
|
+
throw new Error(`Can not get ${requiredRemoteInfo.name}'s types archive url!`);
|
|
2115
|
+
}
|
|
2116
|
+
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, __spreadProps(__spreadValues({}, requiredRemoteInfo), {
|
|
2117
|
+
// use remoteTarPath first
|
|
2118
|
+
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
2119
|
+
}));
|
|
2103
2120
|
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
2121
|
+
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
2104
2122
|
}), "consumeTypes");
|
|
2123
|
+
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
2105
2124
|
if (!loadedRemoteInfo) {
|
|
2106
2125
|
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
2107
2126
|
return item.name === remoteName;
|
|
2108
2127
|
});
|
|
2128
|
+
fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
|
|
2109
2129
|
if (remoteInfo) {
|
|
2110
2130
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
2111
2131
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
@@ -2125,7 +2145,7 @@ var DTSManager = (_a = class {
|
|
|
2125
2145
|
});
|
|
2126
2146
|
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
2127
2147
|
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
2128
|
-
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "
|
|
2148
|
+
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
|
|
2129
2149
|
yield consumeDynamicRemoteTypes();
|
|
2130
2150
|
}
|
|
2131
2151
|
if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -2174,6 +2194,10 @@ function cloneDeepOptions(options) {
|
|
|
2174
2194
|
});
|
|
2175
2195
|
}
|
|
2176
2196
|
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
2197
|
+
var getEnvHeaders = /* @__PURE__ */ __name(() => {
|
|
2198
|
+
const headersStr = (0, import_sdk6.getProcessEnv)()["MF_ENV_HEADERS"] || "{}";
|
|
2199
|
+
return __spreadValues({}, JSON.parse(headersStr));
|
|
2200
|
+
}, "getEnvHeaders");
|
|
2177
2201
|
function axiosGet(url, config) {
|
|
2178
2202
|
return __async(this, null, function* () {
|
|
2179
2203
|
const httpAgent = new import_http2.default.Agent({
|
|
@@ -2182,10 +2206,12 @@ function axiosGet(url, config) {
|
|
|
2182
2206
|
const httpsAgent = new import_https.default.Agent({
|
|
2183
2207
|
family: 4
|
|
2184
2208
|
});
|
|
2185
|
-
return import_axios.default.get(url, __spreadValues({
|
|
2209
|
+
return import_axios.default.get(url, __spreadValues(__spreadValues({
|
|
2186
2210
|
httpAgent,
|
|
2187
2211
|
httpsAgent
|
|
2188
|
-
},
|
|
2212
|
+
}, {
|
|
2213
|
+
headers: getEnvHeaders()
|
|
2214
|
+
}), config));
|
|
2189
2215
|
});
|
|
2190
2216
|
}
|
|
2191
2217
|
__name(axiosGet, "axiosGet");
|
|
@@ -2550,7 +2576,7 @@ function getRpcWorkerData() {
|
|
|
2550
2576
|
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
2551
2577
|
|
|
2552
2578
|
// packages/dts-plugin/src/dev-worker/forkDevWorker.ts
|
|
2553
|
-
var
|
|
2579
|
+
var import_sdk7 = require("@module-federation/sdk");
|
|
2554
2580
|
|
|
2555
2581
|
// packages/dts-plugin/src/dev-worker/utils.ts
|
|
2556
2582
|
var DEFAULT_LOCAL_IPS = [
|
|
@@ -2581,7 +2607,7 @@ function getLocalRemoteNames(options, encodeNameIdentifier) {
|
|
|
2581
2607
|
const { mapRemotesToDownload } = retrieveHostConfig(options);
|
|
2582
2608
|
return Object.keys(mapRemotesToDownload).reduce((sum, remoteModuleName) => {
|
|
2583
2609
|
const remoteInfo = mapRemotesToDownload[remoteModuleName];
|
|
2584
|
-
const name = encodeNameIdentifier ? (0,
|
|
2610
|
+
const name = encodeNameIdentifier ? (0, import_sdk7.decodeName)(remoteInfo.name, encodeNameIdentifier) : remoteInfo.name;
|
|
2585
2611
|
const ip = getIpFromEntry(remoteInfo.url, getIPV4());
|
|
2586
2612
|
if (!ip) {
|
|
2587
2613
|
return sum;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { k as DtsWorkerOptions } from './DtsWorker-
|
|
1
|
+
import { k as DtsWorkerOptions } from './DtsWorker-484d9f4a.js';
|
|
2
2
|
import 'child_process';
|
|
3
|
-
import './DTSManagerOptions-
|
|
3
|
+
import './DTSManagerOptions-c74c59ed.js';
|
|
4
4
|
import '@module-federation/sdk';
|
|
5
5
|
import 'typescript';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { k as DtsWorkerOptions } from './DtsWorker-
|
|
1
|
+
import { k as DtsWorkerOptions } from './DtsWorker-484d9f4a.js';
|
|
2
2
|
import 'child_process';
|
|
3
|
-
import './DTSManagerOptions-
|
|
3
|
+
import './DTSManagerOptions-c74c59ed.js';
|
|
4
4
|
import '@module-federation/sdk';
|
|
5
5
|
import 'typescript';
|
|
6
6
|
|