@module-federation/dts-plugin 0.2.8 → 0.3.0
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 +14 -0
- package/dist/{DTSManagerOptions-c0728719.d.ts → DTSManagerOptions-7109e8ac.d.ts} +1 -0
- package/dist/{DtsWorker-90454949.d.ts → DtsWorker-17de6ba4.d.ts} +2 -5
- package/dist/core.d.mts +8 -4
- package/dist/core.d.ts +8 -4
- package/dist/core.js +73 -40
- package/dist/dynamic-remote-type-hints-plugin.js +5 -7
- package/dist/esm/{chunk-MQRIERJP.js → chunk-6DND574L.js} +7 -15
- package/dist/esm/chunk-DEW2PNCR.js +283 -0
- package/dist/esm/chunk-HKRTV6ZH.js +900 -0
- package/dist/esm/{chunk-2RCHPGBO.js → chunk-SFEGBRA3.js} +329 -1428
- package/dist/esm/{chunk-G7ONFBMA.js → chunk-XKCIYRDL.js} +1 -1
- package/dist/esm/core.js +11 -11
- package/dist/esm/dynamic-remote-type-hints-plugin.js +2 -2
- package/dist/esm/fork-dev-worker.js +11 -7
- package/dist/esm/fork-generate-dts.js +3 -2
- package/dist/esm/index.js +21 -18
- package/dist/esm/start-broker.js +2 -2
- package/dist/fork-dev-worker.d.mts +1 -1
- package/dist/fork-dev-worker.d.ts +1 -1
- package/dist/fork-dev-worker.js +69 -38
- package/dist/fork-generate-dts.d.mts +2 -2
- package/dist/fork-generate-dts.d.ts +2 -2
- package/dist/fork-generate-dts.js +141 -289
- package/dist/iife/launch-web-client.js +5 -7
- package/dist/index.js +84 -51
- package/dist/package.json +1 -1
- package/dist/start-broker.js +28 -344
- package/package.json +5 -5
|
@@ -189,6 +189,7 @@ function getEffectiveRootDir(parsedCommandLine) {
|
|
|
189
189
|
}
|
|
190
190
|
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
191
191
|
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
192
|
+
var _a2;
|
|
192
193
|
const resolvedTsConfigPath = (0, import_path.resolve)(context, tsConfigPath);
|
|
193
194
|
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
194
195
|
if (readResult.error) {
|
|
@@ -207,6 +208,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
|
|
|
207
208
|
};
|
|
208
209
|
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
209
210
|
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
211
|
+
(_a2 = rawTsConfigJson.compilerOptions) == null ? true : delete _a2.paths;
|
|
210
212
|
const filesToCompile = [
|
|
211
213
|
...Object.values(mapComponentsToExpose),
|
|
212
214
|
...additionalFilesToCompile
|
|
@@ -215,10 +217,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
|
|
|
215
217
|
rawTsConfigJson.files = filesToCompile;
|
|
216
218
|
rawTsConfigJson.exclude = [];
|
|
217
219
|
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
218
|
-
|
|
219
|
-
if (extendsPath && extendsPath.startsWith(".")) {
|
|
220
|
-
rawTsConfigJson.extends = (0, import_path.resolve)(context, extendsPath);
|
|
221
|
-
}
|
|
220
|
+
rawTsConfigJson.extends = resolvedTsConfigPath;
|
|
222
221
|
return rawTsConfigJson;
|
|
223
222
|
}, "readTsConfig");
|
|
224
223
|
var TS_EXTENSIONS = [
|
|
@@ -271,7 +270,6 @@ var import_path4 = __toESM(require("path"));
|
|
|
271
270
|
var import_promises3 = require("fs/promises");
|
|
272
271
|
var import_fs2 = __toESM(require("fs"));
|
|
273
272
|
var import_sdk5 = require("@module-federation/sdk");
|
|
274
|
-
var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
|
|
275
273
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
276
274
|
|
|
277
275
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
@@ -281,8 +279,8 @@ var import_promises2 = require("fs/promises");
|
|
|
281
279
|
|
|
282
280
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
283
281
|
var import_fs_extra = require("fs-extra");
|
|
282
|
+
var import_crypto = __toESM(require("crypto"));
|
|
284
283
|
var import_promises = require("fs/promises");
|
|
285
|
-
var import_crypto = require("crypto");
|
|
286
284
|
var import_path2 = require("path");
|
|
287
285
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
288
286
|
var import_child_process = require("child_process");
|
|
@@ -293,8 +291,12 @@ var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
|
293
291
|
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path2.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
294
292
|
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path2.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
295
293
|
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path2.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
296
|
-
function writeTempTsConfig(tsConfig, context) {
|
|
297
|
-
const
|
|
294
|
+
function writeTempTsConfig(tsConfig, context, name) {
|
|
295
|
+
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
296
|
+
return import_crypto.default.createHash("md5").update(contents).digest("hex");
|
|
297
|
+
}, "createHash");
|
|
298
|
+
const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
|
|
299
|
+
const tempTsConfigJsonPath = (0, import_path2.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
|
|
298
300
|
(0, import_fs_extra.ensureDirSync)((0, import_path2.dirname)(tempTsConfigJsonPath));
|
|
299
301
|
(0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
300
302
|
return tempTsConfigJsonPath;
|
|
@@ -347,7 +349,7 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
|
|
|
347
349
|
return;
|
|
348
350
|
}
|
|
349
351
|
const { compilerOptions } = tsConfig;
|
|
350
|
-
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
352
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
|
|
351
353
|
try {
|
|
352
354
|
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
353
355
|
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path2.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
@@ -509,11 +511,16 @@ var import_chalk2 = __toESM(require("chalk"));
|
|
|
509
511
|
// packages/dts-plugin/src/server/constant.ts
|
|
510
512
|
var DEFAULT_WEB_SOCKET_PORT = 16322;
|
|
511
513
|
var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
|
|
514
|
+
var UpdateMode;
|
|
515
|
+
(function(UpdateMode2) {
|
|
516
|
+
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
517
|
+
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
518
|
+
})(UpdateMode || (UpdateMode = {}));
|
|
512
519
|
|
|
513
520
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
514
521
|
function fileLog(msg, module2, level) {
|
|
515
|
-
var
|
|
516
|
-
if (!((
|
|
522
|
+
var _a2, _b;
|
|
523
|
+
if (!((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2["FEDERATION_DEBUG"])) {
|
|
517
524
|
return;
|
|
518
525
|
}
|
|
519
526
|
log4js.configure({
|
|
@@ -654,255 +661,6 @@ var Publisher = _Publisher;
|
|
|
654
661
|
// packages/dts-plugin/src/server/DevServer.ts
|
|
655
662
|
var import_isomorphic_ws2 = __toESM(require("isomorphic-ws"));
|
|
656
663
|
|
|
657
|
-
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
658
|
-
var import_sdk4 = require("@module-federation/sdk");
|
|
659
|
-
var import_managers2 = require("@module-federation/managers");
|
|
660
|
-
var defaultOptions2 = {
|
|
661
|
-
typesFolder: "@mf-types",
|
|
662
|
-
remoteTypesFolder: "@mf-types",
|
|
663
|
-
deleteTypesFolder: true,
|
|
664
|
-
maxRetries: 3,
|
|
665
|
-
implementation: "",
|
|
666
|
-
context: process.cwd(),
|
|
667
|
-
abortOnError: true,
|
|
668
|
-
consumeAPITypes: false
|
|
669
|
-
};
|
|
670
|
-
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
671
|
-
const remoteUrl = new URL(url, "file:");
|
|
672
|
-
const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
|
|
673
|
-
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
|
|
674
|
-
return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
|
|
675
|
-
}, "buildZipUrl");
|
|
676
|
-
var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
677
|
-
if (!zipUrl) {
|
|
678
|
-
return void 0;
|
|
679
|
-
}
|
|
680
|
-
return zipUrl.replace(".zip", ".d.ts");
|
|
681
|
-
}, "buildApiTypeUrl");
|
|
682
|
-
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
683
|
-
const { hostOptions, remoteAlias, remote } = options;
|
|
684
|
-
let decodedRemote = remote;
|
|
685
|
-
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
686
|
-
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
687
|
-
}
|
|
688
|
-
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
689
|
-
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
690
|
-
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
691
|
-
return {
|
|
692
|
-
name: parsedInfo.name || remoteAlias,
|
|
693
|
-
url,
|
|
694
|
-
zipUrl,
|
|
695
|
-
apiTypeUrl: buildApiTypeUrl(zipUrl),
|
|
696
|
-
alias: remoteAlias
|
|
697
|
-
};
|
|
698
|
-
}, "retrieveRemoteInfo");
|
|
699
|
-
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
700
|
-
const parsedOptions = import_managers2.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
701
|
-
remote: Array.isArray(item) ? item[0] : item,
|
|
702
|
-
key
|
|
703
|
-
}), (item, key) => ({
|
|
704
|
-
remote: Array.isArray(item.external) ? item.external[0] : item.external,
|
|
705
|
-
key
|
|
706
|
-
}));
|
|
707
|
-
return parsedOptions.reduce((accumulator, item) => {
|
|
708
|
-
const { key, remote } = item[1];
|
|
709
|
-
accumulator[key] = retrieveRemoteInfo({
|
|
710
|
-
hostOptions,
|
|
711
|
-
remoteAlias: key,
|
|
712
|
-
remote
|
|
713
|
-
});
|
|
714
|
-
return accumulator;
|
|
715
|
-
}, {});
|
|
716
|
-
}, "resolveRemotes");
|
|
717
|
-
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
718
|
-
validateOptions(options);
|
|
719
|
-
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
720
|
-
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
721
|
-
return {
|
|
722
|
-
hostOptions,
|
|
723
|
-
mapRemotesToDownload
|
|
724
|
-
};
|
|
725
|
-
}, "retrieveHostConfig");
|
|
726
|
-
|
|
727
|
-
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
728
|
-
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
729
|
-
|
|
730
|
-
// packages/dts-plugin/src/core/rpc/index.ts
|
|
731
|
-
var rpc_exports = {};
|
|
732
|
-
__export(rpc_exports, {
|
|
733
|
-
RpcExitError: () => RpcExitError,
|
|
734
|
-
RpcGMCallTypes: () => RpcGMCallTypes,
|
|
735
|
-
createRpcWorker: () => createRpcWorker,
|
|
736
|
-
exposeRpc: () => exposeRpc,
|
|
737
|
-
getRpcWorkerData: () => getRpcWorkerData,
|
|
738
|
-
wrapRpc: () => wrapRpc
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
// packages/dts-plugin/src/core/rpc/rpc-error.ts
|
|
742
|
-
var _a;
|
|
743
|
-
var RpcExitError = (_a = class extends Error {
|
|
744
|
-
constructor(message, code, signal) {
|
|
745
|
-
super(message);
|
|
746
|
-
__publicField(this, "code");
|
|
747
|
-
__publicField(this, "signal");
|
|
748
|
-
this.code = code;
|
|
749
|
-
this.signal = signal;
|
|
750
|
-
this.name = "RpcExitError";
|
|
751
|
-
}
|
|
752
|
-
}, __name(_a, "RpcExitError"), _a);
|
|
753
|
-
|
|
754
|
-
// packages/dts-plugin/src/core/rpc/wrap-rpc.ts
|
|
755
|
-
function createControlledPromise() {
|
|
756
|
-
let resolve4 = /* @__PURE__ */ __name(() => void 0, "resolve");
|
|
757
|
-
let reject = /* @__PURE__ */ __name(() => void 0, "reject");
|
|
758
|
-
const promise = new Promise((aResolve, aReject) => {
|
|
759
|
-
resolve4 = aResolve;
|
|
760
|
-
reject = aReject;
|
|
761
|
-
});
|
|
762
|
-
return {
|
|
763
|
-
promise,
|
|
764
|
-
resolve: resolve4,
|
|
765
|
-
reject
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
__name(createControlledPromise, "createControlledPromise");
|
|
769
|
-
function wrapRpc(childProcess, options) {
|
|
770
|
-
return (...args) => __async(this, null, function* () {
|
|
771
|
-
if (!childProcess.send) {
|
|
772
|
-
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
773
|
-
} else if (!childProcess.connected) {
|
|
774
|
-
throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
|
|
775
|
-
}
|
|
776
|
-
const { id, once } = options;
|
|
777
|
-
const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
|
|
778
|
-
const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
|
|
779
|
-
const handleMessage = /* @__PURE__ */ __name((message) => {
|
|
780
|
-
if ((message == null ? void 0 : message.id) === id) {
|
|
781
|
-
if (message.type === RpcGMCallTypes.RESOLVE) {
|
|
782
|
-
resolveResult(message.value);
|
|
783
|
-
} else if (message.type === RpcGMCallTypes.REJECT) {
|
|
784
|
-
rejectResult(message.error);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
if (once && (childProcess == null ? void 0 : childProcess.kill)) {
|
|
788
|
-
childProcess.kill("SIGTERM");
|
|
789
|
-
}
|
|
790
|
-
}, "handleMessage");
|
|
791
|
-
const handleClose = /* @__PURE__ */ __name((code, signal) => {
|
|
792
|
-
rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
|
|
793
|
-
removeHandlers();
|
|
794
|
-
}, "handleClose");
|
|
795
|
-
const removeHandlers = /* @__PURE__ */ __name(() => {
|
|
796
|
-
childProcess.off("message", handleMessage);
|
|
797
|
-
childProcess.off("close", handleClose);
|
|
798
|
-
}, "removeHandlers");
|
|
799
|
-
if (once) {
|
|
800
|
-
childProcess.once("message", handleMessage);
|
|
801
|
-
} else {
|
|
802
|
-
childProcess.on("message", handleMessage);
|
|
803
|
-
}
|
|
804
|
-
childProcess.on("close", handleClose);
|
|
805
|
-
childProcess.send({
|
|
806
|
-
type: RpcGMCallTypes.CALL,
|
|
807
|
-
id,
|
|
808
|
-
args
|
|
809
|
-
}, (error2) => {
|
|
810
|
-
if (error2) {
|
|
811
|
-
rejectSend(error2);
|
|
812
|
-
removeHandlers();
|
|
813
|
-
} else {
|
|
814
|
-
resolveSend(void 0);
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
return sendPromise.then(() => resultPromise);
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
__name(wrapRpc, "wrapRpc");
|
|
821
|
-
|
|
822
|
-
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
823
|
-
var child_process = __toESM(require("child_process"));
|
|
824
|
-
var process3 = __toESM(require("process"));
|
|
825
|
-
var import_crypto2 = require("crypto");
|
|
826
|
-
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
827
|
-
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
828
|
-
const options = {
|
|
829
|
-
env: __spreadProps(__spreadValues({}, process3.env), {
|
|
830
|
-
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
831
|
-
}),
|
|
832
|
-
stdio: [
|
|
833
|
-
"inherit",
|
|
834
|
-
"inherit",
|
|
835
|
-
"inherit",
|
|
836
|
-
"ipc"
|
|
837
|
-
],
|
|
838
|
-
serialization: "advanced"
|
|
839
|
-
};
|
|
840
|
-
if (memoryLimit) {
|
|
841
|
-
options.execArgv = [
|
|
842
|
-
`--max-old-space-size=${memoryLimit}`
|
|
843
|
-
];
|
|
844
|
-
}
|
|
845
|
-
let childProcess, remoteMethod;
|
|
846
|
-
const id = (0, import_crypto2.randomUUID)();
|
|
847
|
-
const worker = {
|
|
848
|
-
connect(...args) {
|
|
849
|
-
if (childProcess && !childProcess.connected) {
|
|
850
|
-
childProcess.send({
|
|
851
|
-
type: RpcGMCallTypes.EXIT,
|
|
852
|
-
id
|
|
853
|
-
});
|
|
854
|
-
childProcess = void 0;
|
|
855
|
-
remoteMethod = void 0;
|
|
856
|
-
}
|
|
857
|
-
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
858
|
-
childProcess = child_process.fork(modulePath, options);
|
|
859
|
-
remoteMethod = wrapRpc(childProcess, {
|
|
860
|
-
id,
|
|
861
|
-
once
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
if (!remoteMethod) {
|
|
865
|
-
return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
|
|
866
|
-
}
|
|
867
|
-
return remoteMethod(...args);
|
|
868
|
-
},
|
|
869
|
-
terminate() {
|
|
870
|
-
var _a3;
|
|
871
|
-
(_a3 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a3.call(childProcess, {
|
|
872
|
-
type: RpcGMCallTypes.EXIT,
|
|
873
|
-
id
|
|
874
|
-
});
|
|
875
|
-
childProcess = void 0;
|
|
876
|
-
remoteMethod = void 0;
|
|
877
|
-
},
|
|
878
|
-
get connected() {
|
|
879
|
-
return Boolean(childProcess == null ? void 0 : childProcess.connected);
|
|
880
|
-
},
|
|
881
|
-
get process() {
|
|
882
|
-
return childProcess;
|
|
883
|
-
},
|
|
884
|
-
get id() {
|
|
885
|
-
return id;
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
return worker;
|
|
889
|
-
}
|
|
890
|
-
__name(createRpcWorker, "createRpcWorker");
|
|
891
|
-
function getRpcWorkerData() {
|
|
892
|
-
return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
893
|
-
}
|
|
894
|
-
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
895
|
-
|
|
896
|
-
// packages/dts-plugin/src/core/constant.ts
|
|
897
|
-
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
898
|
-
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
899
|
-
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
900
|
-
var UpdateMode;
|
|
901
|
-
(function(UpdateMode2) {
|
|
902
|
-
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
903
|
-
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
904
|
-
})(UpdateMode || (UpdateMode = {}));
|
|
905
|
-
|
|
906
664
|
// packages/dts-plugin/src/server/broker/Broker.ts
|
|
907
665
|
var import_http = require("http");
|
|
908
666
|
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
@@ -993,13 +751,13 @@ ${err.message}
|
|
|
993
751
|
this._webSocketServer = void 0;
|
|
994
752
|
});
|
|
995
753
|
server.on("upgrade", (req, socket, head) => {
|
|
996
|
-
var
|
|
754
|
+
var _a2;
|
|
997
755
|
if (req.url) {
|
|
998
756
|
const { pathname } = (0, import_url.parse)(req.url);
|
|
999
757
|
if (pathname === "/") {
|
|
1000
|
-
(
|
|
1001
|
-
var
|
|
1002
|
-
(
|
|
758
|
+
(_a2 = this._webSocketServer) == null ? void 0 : _a2.handleUpgrade(req, socket, head, (ws) => {
|
|
759
|
+
var _a3;
|
|
760
|
+
(_a3 = this._webSocketServer) == null ? void 0 : _a3.emit("connection", ws, req);
|
|
1003
761
|
});
|
|
1004
762
|
}
|
|
1005
763
|
}
|
|
@@ -1384,8 +1142,8 @@ ${err.message}
|
|
|
1384
1142
|
}
|
|
1385
1143
|
}
|
|
1386
1144
|
_getTmpSubScribers(publisherIdentifier) {
|
|
1387
|
-
var
|
|
1388
|
-
return (
|
|
1145
|
+
var _a2;
|
|
1146
|
+
return (_a2 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a2.subscribers;
|
|
1389
1147
|
}
|
|
1390
1148
|
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
1391
1149
|
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
@@ -1490,9 +1248,9 @@ ${err.message}
|
|
|
1490
1248
|
process.exit(0);
|
|
1491
1249
|
}
|
|
1492
1250
|
broadcast(message) {
|
|
1493
|
-
var
|
|
1251
|
+
var _a2, _b;
|
|
1494
1252
|
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
1495
|
-
(
|
|
1253
|
+
(_a2 = this._webSocketServer) == null ? void 0 : _a2.clients.forEach((client) => {
|
|
1496
1254
|
client.send(JSON.stringify(message));
|
|
1497
1255
|
});
|
|
1498
1256
|
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
@@ -1566,9 +1324,85 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1566
1324
|
});
|
|
1567
1325
|
}, "downloadTypesArchive");
|
|
1568
1326
|
|
|
1327
|
+
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1328
|
+
var import_sdk4 = require("@module-federation/sdk");
|
|
1329
|
+
var import_managers2 = require("@module-federation/managers");
|
|
1330
|
+
var defaultOptions2 = {
|
|
1331
|
+
typesFolder: "@mf-types",
|
|
1332
|
+
remoteTypesFolder: "@mf-types",
|
|
1333
|
+
deleteTypesFolder: true,
|
|
1334
|
+
maxRetries: 3,
|
|
1335
|
+
implementation: "",
|
|
1336
|
+
context: process.cwd(),
|
|
1337
|
+
abortOnError: true,
|
|
1338
|
+
consumeAPITypes: false,
|
|
1339
|
+
runtimePkgs: []
|
|
1340
|
+
};
|
|
1341
|
+
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1342
|
+
const remoteUrl = new URL(url, "file:");
|
|
1343
|
+
const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
|
|
1344
|
+
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
|
|
1345
|
+
return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
|
|
1346
|
+
}, "buildZipUrl");
|
|
1347
|
+
var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
1348
|
+
if (!zipUrl) {
|
|
1349
|
+
return void 0;
|
|
1350
|
+
}
|
|
1351
|
+
return zipUrl.replace(".zip", ".d.ts");
|
|
1352
|
+
}, "buildApiTypeUrl");
|
|
1353
|
+
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1354
|
+
const { hostOptions, remoteAlias, remote } = options;
|
|
1355
|
+
let decodedRemote = remote;
|
|
1356
|
+
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1357
|
+
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1358
|
+
}
|
|
1359
|
+
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1360
|
+
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1361
|
+
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1362
|
+
return {
|
|
1363
|
+
name: parsedInfo.name || remoteAlias,
|
|
1364
|
+
url,
|
|
1365
|
+
zipUrl,
|
|
1366
|
+
apiTypeUrl: buildApiTypeUrl(zipUrl),
|
|
1367
|
+
alias: remoteAlias
|
|
1368
|
+
};
|
|
1369
|
+
}, "retrieveRemoteInfo");
|
|
1370
|
+
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
1371
|
+
const parsedOptions = import_managers2.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
1372
|
+
remote: Array.isArray(item) ? item[0] : item,
|
|
1373
|
+
key
|
|
1374
|
+
}), (item, key) => ({
|
|
1375
|
+
remote: Array.isArray(item.external) ? item.external[0] : item.external,
|
|
1376
|
+
key
|
|
1377
|
+
}));
|
|
1378
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
1379
|
+
const { key, remote } = item[1];
|
|
1380
|
+
accumulator[key] = retrieveRemoteInfo({
|
|
1381
|
+
hostOptions,
|
|
1382
|
+
remoteAlias: key,
|
|
1383
|
+
remote
|
|
1384
|
+
});
|
|
1385
|
+
return accumulator;
|
|
1386
|
+
}, {});
|
|
1387
|
+
}, "resolveRemotes");
|
|
1388
|
+
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
1389
|
+
validateOptions(options);
|
|
1390
|
+
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1391
|
+
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
1392
|
+
return {
|
|
1393
|
+
hostOptions,
|
|
1394
|
+
mapRemotesToDownload
|
|
1395
|
+
};
|
|
1396
|
+
}, "retrieveHostConfig");
|
|
1397
|
+
|
|
1398
|
+
// packages/dts-plugin/src/core/constant.ts
|
|
1399
|
+
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
1400
|
+
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
1401
|
+
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
1402
|
+
|
|
1569
1403
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1570
|
-
var
|
|
1571
|
-
var DTSManager = (
|
|
1404
|
+
var _a;
|
|
1405
|
+
var DTSManager = (_a = class {
|
|
1572
1406
|
constructor(options) {
|
|
1573
1407
|
__publicField(this, "options");
|
|
1574
1408
|
__publicField(this, "runtimePkgs");
|
|
@@ -1576,11 +1410,7 @@ var DTSManager = (_a2 = class {
|
|
|
1576
1410
|
__publicField(this, "loadedRemoteAPIAlias");
|
|
1577
1411
|
__publicField(this, "extraOptions");
|
|
1578
1412
|
__publicField(this, "updatedRemoteInfos");
|
|
1579
|
-
this.options = (
|
|
1580
|
-
if (key === "manifest") {
|
|
1581
|
-
return false;
|
|
1582
|
-
}
|
|
1583
|
-
});
|
|
1413
|
+
this.options = cloneDeepOptions(options);
|
|
1584
1414
|
this.runtimePkgs = [
|
|
1585
1415
|
"@module-federation/runtime",
|
|
1586
1416
|
"@module-federation/enhanced/runtime",
|
|
@@ -1639,7 +1469,7 @@ var DTSManager = (_a2 = class {
|
|
|
1639
1469
|
}
|
|
1640
1470
|
generateTypes() {
|
|
1641
1471
|
return __async(this, null, function* () {
|
|
1642
|
-
var
|
|
1472
|
+
var _a2;
|
|
1643
1473
|
try {
|
|
1644
1474
|
const { options } = this;
|
|
1645
1475
|
if (!options.remote) {
|
|
@@ -1676,7 +1506,7 @@ var DTSManager = (_a2 = class {
|
|
|
1676
1506
|
}
|
|
1677
1507
|
console.log(import_ansi_colors.default.green("Federated types created correctly"));
|
|
1678
1508
|
} catch (error2) {
|
|
1679
|
-
if (((
|
|
1509
|
+
if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1680
1510
|
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
|
|
1681
1511
|
} else {
|
|
1682
1512
|
throw error2;
|
|
@@ -1791,7 +1621,16 @@ var DTSManager = (_a2 = class {
|
|
|
1791
1621
|
...packageTypes,
|
|
1792
1622
|
"Y"
|
|
1793
1623
|
].join(" :\n")} ;`;
|
|
1794
|
-
const
|
|
1624
|
+
const runtimePkgs = /* @__PURE__ */ new Set();
|
|
1625
|
+
[
|
|
1626
|
+
...this.runtimePkgs,
|
|
1627
|
+
...hostOptions.runtimePkgs
|
|
1628
|
+
].forEach((pkg) => {
|
|
1629
|
+
runtimePkgs.add(pkg);
|
|
1630
|
+
});
|
|
1631
|
+
const pkgsDeclareStr = [
|
|
1632
|
+
...runtimePkgs
|
|
1633
|
+
].map((pkg) => {
|
|
1795
1634
|
return `declare module "${pkg}" {
|
|
1796
1635
|
${remoteKeysStr}
|
|
1797
1636
|
${packageTypesStr}
|
|
@@ -1824,7 +1663,7 @@ var DTSManager = (_a2 = class {
|
|
|
1824
1663
|
}
|
|
1825
1664
|
consumeTypes() {
|
|
1826
1665
|
return __async(this, null, function* () {
|
|
1827
|
-
var
|
|
1666
|
+
var _a2;
|
|
1828
1667
|
try {
|
|
1829
1668
|
const { options } = this;
|
|
1830
1669
|
if (!options.host) {
|
|
@@ -1851,7 +1690,7 @@ var DTSManager = (_a2 = class {
|
|
|
1851
1690
|
}
|
|
1852
1691
|
console.log(import_ansi_colors.default.green("Federated types extraction completed"));
|
|
1853
1692
|
} catch (err) {
|
|
1854
|
-
if (((
|
|
1693
|
+
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1855
1694
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
1856
1695
|
} else {
|
|
1857
1696
|
throw err;
|
|
@@ -1861,10 +1700,10 @@ var DTSManager = (_a2 = class {
|
|
|
1861
1700
|
}
|
|
1862
1701
|
updateTypes(options) {
|
|
1863
1702
|
return __async(this, null, function* () {
|
|
1864
|
-
var
|
|
1703
|
+
var _a2, _b, _c;
|
|
1865
1704
|
try {
|
|
1866
1705
|
const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
|
|
1867
|
-
const hostName = (_c = (_b = (
|
|
1706
|
+
const hostName = (_c = (_b = (_a2 = this.options) == null ? void 0 : _a2.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
1868
1707
|
fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
|
|
1869
1708
|
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
1870
1709
|
if (!this.options.remote) {
|
|
@@ -1878,7 +1717,7 @@ var DTSManager = (_a2 = class {
|
|
|
1878
1717
|
}
|
|
1879
1718
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1880
1719
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1881
|
-
const
|
|
1720
|
+
const consumeTypes = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
1882
1721
|
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
|
|
1883
1722
|
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1884
1723
|
}), "consumeTypes");
|
|
@@ -1891,10 +1730,10 @@ var DTSManager = (_a2 = class {
|
|
|
1891
1730
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1892
1731
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1893
1732
|
}
|
|
1894
|
-
yield
|
|
1733
|
+
yield consumeTypes(this.remoteAliasMap[remoteInfo.alias]);
|
|
1895
1734
|
} else if (updatedRemoteInfo) {
|
|
1896
1735
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1897
|
-
yield
|
|
1736
|
+
yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1898
1737
|
this.consumeAPITypes(hostOptions);
|
|
1899
1738
|
}), "consumeDynamicRemoteTypes");
|
|
1900
1739
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -1913,7 +1752,7 @@ var DTSManager = (_a2 = class {
|
|
|
1913
1752
|
}
|
|
1914
1753
|
}
|
|
1915
1754
|
} else {
|
|
1916
|
-
yield
|
|
1755
|
+
yield consumeTypes(loadedRemoteInfo);
|
|
1917
1756
|
}
|
|
1918
1757
|
}
|
|
1919
1758
|
} catch (err) {
|
|
@@ -1921,9 +1760,10 @@ var DTSManager = (_a2 = class {
|
|
|
1921
1760
|
}
|
|
1922
1761
|
});
|
|
1923
1762
|
}
|
|
1924
|
-
}, __name(
|
|
1763
|
+
}, __name(_a, "DTSManager"), _a);
|
|
1925
1764
|
|
|
1926
1765
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1766
|
+
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
1927
1767
|
function getDTSManagerConstructor(implementation) {
|
|
1928
1768
|
if (implementation) {
|
|
1929
1769
|
const NewConstructor = require(implementation);
|
|
@@ -1941,6 +1781,18 @@ function isDebugMode() {
|
|
|
1941
1781
|
return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
|
|
1942
1782
|
}
|
|
1943
1783
|
__name(isDebugMode, "isDebugMode");
|
|
1784
|
+
function cloneDeepOptions(options) {
|
|
1785
|
+
const excludeKeys = [
|
|
1786
|
+
"manifest",
|
|
1787
|
+
"async"
|
|
1788
|
+
];
|
|
1789
|
+
return (0, import_lodash.default)(options, (_value, key) => {
|
|
1790
|
+
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
1944
1796
|
function axiosGet(url, config) {
|
|
1945
1797
|
return __async(this, null, function* () {
|
|
1946
1798
|
const httpAgent = new import_http2.default.Agent({
|
|
@@ -1960,8 +1812,8 @@ __name(axiosGet, "axiosGet");
|
|
|
1960
1812
|
// packages/dts-plugin/src/core/lib/generateTypes.ts
|
|
1961
1813
|
function generateTypes(options) {
|
|
1962
1814
|
return __async(this, null, function* () {
|
|
1963
|
-
var
|
|
1964
|
-
const DTSManagerConstructor = getDTSManagerConstructor((
|
|
1815
|
+
var _a2;
|
|
1816
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a2 = options.remote) == null ? void 0 : _a2.implementation);
|
|
1965
1817
|
const dtsManager = new DTSManagerConstructor(options);
|
|
1966
1818
|
return dtsManager.generateTypes();
|
|
1967
1819
|
});
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
// packages/dts-plugin/src/server/constant.ts
|
|
11
11
|
var DEFAULT_WEB_SOCKET_PORT = 16322;
|
|
12
12
|
var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
|
|
13
|
+
var UpdateMode;
|
|
14
|
+
(function(UpdateMode2) {
|
|
15
|
+
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
16
|
+
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
17
|
+
})(UpdateMode || (UpdateMode = {}));
|
|
13
18
|
|
|
14
19
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
15
20
|
var _Message = class _Message {
|
|
@@ -68,13 +73,6 @@
|
|
|
68
73
|
__name(_AddWebClientAction, "AddWebClientAction");
|
|
69
74
|
var AddWebClientAction = _AddWebClientAction;
|
|
70
75
|
|
|
71
|
-
// packages/dts-plugin/src/core/constant.ts
|
|
72
|
-
var UpdateMode;
|
|
73
|
-
(function(UpdateMode2) {
|
|
74
|
-
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
75
|
-
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
76
|
-
})(UpdateMode || (UpdateMode = {}));
|
|
77
|
-
|
|
78
76
|
// packages/dts-plugin/src/server/message/API/API.ts
|
|
79
77
|
var APIKind;
|
|
80
78
|
(function(APIKind2) {
|