@module-federation/native-federation-typescript 0.1.0 → 0.1.2
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 +82 -34
- package/dist/CHANGELOG.md +336 -0
- package/dist/DTSManagerOptions-3369791f.d.ts +9 -0
- package/dist/HostOptions-cf22e0ab.d.ts +23 -0
- package/dist/README.md +214 -0
- package/dist/chunk-2NC7LVYZ.js +864 -0
- package/dist/chunk-CF5CH54A.mjs +864 -0
- package/dist/chunk-JLWFNRJL.js +179 -0
- package/dist/chunk-QYHGZU7D.mjs +244 -0
- package/dist/chunk-VHQW5BQS.js +244 -0
- package/dist/chunk-VKKLMSMI.mjs +179 -0
- package/dist/esbuild.d.mts +9 -0
- package/dist/esbuild.d.ts +6 -3
- package/dist/esbuild.js +14 -1
- package/dist/esbuild.mjs +14 -1
- package/dist/helpers.d.mts +160 -0
- package/dist/helpers.d.ts +160 -0
- package/dist/helpers.js +40 -0
- package/dist/helpers.mjs +40 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +10 -1
- package/dist/index.mjs +10 -1
- package/dist/lib/forkGenerateDts.d.mts +9 -0
- package/dist/lib/forkGenerateDts.d.ts +9 -0
- package/dist/lib/forkGenerateDts.js +18 -0
- package/dist/lib/forkGenerateDts.mjs +18 -0
- package/dist/package.json +103 -0
- package/dist/rolldown.d.mts +9 -0
- package/dist/rolldown.d.ts +9 -0
- package/dist/rolldown.js +14 -0
- package/dist/rolldown.mjs +14 -0
- package/dist/rollup.d.mts +9 -0
- package/dist/rollup.d.ts +6 -3
- package/dist/rollup.js +14 -1
- package/dist/rollup.mjs +14 -1
- package/dist/rspack.d.mts +9 -0
- package/dist/rspack.d.ts +6 -3
- package/dist/rspack.js +14 -1
- package/dist/rspack.mjs +14 -1
- package/dist/vite.d.mts +9 -0
- package/dist/vite.d.ts +6 -3
- package/dist/vite.js +14 -1
- package/dist/vite.mjs +14 -1
- package/dist/webpack.d.mts +9 -0
- package/dist/webpack.d.ts +6 -3
- package/dist/webpack.js +14 -1
- package/dist/webpack.mjs +14 -1
- package/package.json +50 -5
- package/CHANGELOG.md +0 -28
- package/dist/RemoteOptions-ce85caac.d.ts +0 -17
- package/dist/chunk-HJB2AKNY.mjs +0 -682
- package/dist/chunk-WNKHVVXS.js +0 -682
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkVHQW5BQSjs = require('./chunk-VHQW5BQS.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk2NC7LVYZjs = require('./chunk-2NC7LVYZ.js');
|
|
10
|
+
|
|
11
|
+
// packages/native-federation-typescript/src/index.ts
|
|
12
|
+
var _unplugin = require('unplugin');
|
|
13
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
14
|
+
var NativeFederationTypeScriptRemote = _unplugin.createUnplugin.call(void 0,
|
|
15
|
+
(enhancedOptions) => {
|
|
16
|
+
const options = "extraOptions" in enhancedOptions ? enhancedOptions.remote : enhancedOptions;
|
|
17
|
+
const extraOptions = "extraOptions" in enhancedOptions ? enhancedOptions.extraOptions : void 0;
|
|
18
|
+
_chunk2NC7LVYZjs.validateOptions.call(void 0, options);
|
|
19
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
20
|
+
const generateTypesOptions = {
|
|
21
|
+
remote: options,
|
|
22
|
+
extraOptions
|
|
23
|
+
};
|
|
24
|
+
const getGenerateTypesFn = () => {
|
|
25
|
+
let fn = _chunk2NC7LVYZjs.generateTypes;
|
|
26
|
+
let res;
|
|
27
|
+
if (options.compileInChildProcess) {
|
|
28
|
+
fn = _chunkVHQW5BQSjs.generateTypesInChildProcess;
|
|
29
|
+
}
|
|
30
|
+
if (isProd) {
|
|
31
|
+
res = fn(generateTypesOptions);
|
|
32
|
+
return () => res;
|
|
33
|
+
}
|
|
34
|
+
return fn;
|
|
35
|
+
};
|
|
36
|
+
const generateTypesFn = getGenerateTypesFn();
|
|
37
|
+
return {
|
|
38
|
+
name: "native-federation-typescript/remote",
|
|
39
|
+
rollup: {
|
|
40
|
+
writeBundle: async () => {
|
|
41
|
+
await generateTypesFn(generateTypesOptions);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
vite: {
|
|
45
|
+
buildStart: async () => {
|
|
46
|
+
if (isProd) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await generateTypesFn(generateTypesOptions);
|
|
50
|
+
},
|
|
51
|
+
watchChange: async () => {
|
|
52
|
+
if (isProd) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await generateTypesFn(generateTypesOptions);
|
|
56
|
+
},
|
|
57
|
+
writeBundle: async () => {
|
|
58
|
+
await generateTypesFn(generateTypesOptions);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
webpack: (compiler) => {
|
|
62
|
+
compiler.hooks.thisCompilation.tap("generateTypes", (compilation) => {
|
|
63
|
+
const hookName = "mf:generateTypes";
|
|
64
|
+
compilation.hooks.processAssets.tapPromise(
|
|
65
|
+
{
|
|
66
|
+
name: hookName,
|
|
67
|
+
stage: (
|
|
68
|
+
// @ts-expect-error use runtime variable in case peer dep not installed
|
|
69
|
+
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
70
|
+
)
|
|
71
|
+
},
|
|
72
|
+
async () => {
|
|
73
|
+
try {
|
|
74
|
+
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = _chunk2NC7LVYZjs.retrieveTypesAssetsInfo.call(void 0, options);
|
|
75
|
+
if (zipName && compilation.getAsset(zipName)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
await generateTypesFn(generateTypesOptions);
|
|
79
|
+
if (zipTypesPath) {
|
|
80
|
+
compilation.emitAsset(
|
|
81
|
+
zipName,
|
|
82
|
+
new compiler.webpack.sources.RawSource(
|
|
83
|
+
_fs2.default.readFileSync(zipTypesPath),
|
|
84
|
+
false
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (apiTypesPath) {
|
|
89
|
+
compilation.emitAsset(
|
|
90
|
+
apiFileName,
|
|
91
|
+
new compiler.webpack.sources.RawSource(
|
|
92
|
+
_fs2.default.readFileSync(apiTypesPath),
|
|
93
|
+
false
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
rspack: (compiler) => {
|
|
105
|
+
compiler.hooks.thisCompilation.tap("generateTypes", (compilation) => {
|
|
106
|
+
const hookName = "mf:generateTypes";
|
|
107
|
+
compilation.hooks.processAssets.tapPromise(
|
|
108
|
+
{
|
|
109
|
+
name: hookName,
|
|
110
|
+
stage: (
|
|
111
|
+
// @ts-expect-error use runtime variable in case peer dep not installed
|
|
112
|
+
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
113
|
+
)
|
|
114
|
+
},
|
|
115
|
+
async () => {
|
|
116
|
+
try {
|
|
117
|
+
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = _chunk2NC7LVYZjs.retrieveTypesAssetsInfo.call(void 0, options);
|
|
118
|
+
if (zipName && compilation.getAsset(zipName)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
await generateTypesFn(generateTypesOptions);
|
|
122
|
+
if (zipTypesPath) {
|
|
123
|
+
compilation.emitAsset(
|
|
124
|
+
zipName,
|
|
125
|
+
new compiler.webpack.sources.RawSource(
|
|
126
|
+
_fs2.default.readFileSync(zipTypesPath),
|
|
127
|
+
false
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
if (apiTypesPath) {
|
|
132
|
+
compilation.emitAsset(
|
|
133
|
+
apiFileName,
|
|
134
|
+
new compiler.webpack.sources.RawSource(
|
|
135
|
+
_fs2.default.readFileSync(apiTypesPath),
|
|
136
|
+
false
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(err);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
var NativeFederationTypeScriptHost = _unplugin.createUnplugin.call(void 0,
|
|
151
|
+
(enhancedOptions) => {
|
|
152
|
+
const options = "extraOptions" in enhancedOptions ? enhancedOptions.host : enhancedOptions;
|
|
153
|
+
const extraOptions = "extraOptions" in enhancedOptions ? enhancedOptions.extraOptions : void 0;
|
|
154
|
+
_chunk2NC7LVYZjs.validateOptions.call(void 0, options);
|
|
155
|
+
const consumeTypesOptions = {
|
|
156
|
+
host: options,
|
|
157
|
+
extraOptions
|
|
158
|
+
};
|
|
159
|
+
const consumeTypesPromise = _chunkVHQW5BQSjs.consumeTypes.call(void 0, consumeTypesOptions);
|
|
160
|
+
return {
|
|
161
|
+
name: "native-federation-typescript/host",
|
|
162
|
+
async writeBundle() {
|
|
163
|
+
await consumeTypesPromise;
|
|
164
|
+
},
|
|
165
|
+
get vite() {
|
|
166
|
+
return process.env.NODE_ENV === "production" ? void 0 : {
|
|
167
|
+
buildStart: async () => {
|
|
168
|
+
await consumeTypesPromise;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
exports.NativeFederationTypeScriptRemote = NativeFederationTypeScriptRemote; exports.NativeFederationTypeScriptHost = NativeFederationTypeScriptHost;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RpcGMCallTypes,
|
|
3
|
+
__export,
|
|
4
|
+
exposeRpc,
|
|
5
|
+
getDTSManagerConstructor
|
|
6
|
+
} from "./chunk-CF5CH54A.mjs";
|
|
7
|
+
|
|
8
|
+
// packages/native-federation-typescript/src/lib/DtsWorker.ts
|
|
9
|
+
import path from "path";
|
|
10
|
+
import cloneDeepWith from "lodash.clonedeepwith";
|
|
11
|
+
|
|
12
|
+
// packages/native-federation-typescript/src/rpc/index.ts
|
|
13
|
+
var rpc_exports = {};
|
|
14
|
+
__export(rpc_exports, {
|
|
15
|
+
RpcExitError: () => RpcExitError,
|
|
16
|
+
RpcGMCallTypes: () => RpcGMCallTypes,
|
|
17
|
+
createRpcWorker: () => createRpcWorker,
|
|
18
|
+
exposeRpc: () => exposeRpc,
|
|
19
|
+
getRpcWorkerData: () => getRpcWorkerData,
|
|
20
|
+
wrapRpc: () => wrapRpc
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// packages/native-federation-typescript/src/rpc/rpc-error.ts
|
|
24
|
+
var RpcExitError = class extends Error {
|
|
25
|
+
constructor(message, code, signal) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.signal = signal;
|
|
29
|
+
this.name = "RpcExitError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// packages/native-federation-typescript/src/rpc/wrap-rpc.ts
|
|
34
|
+
function createControlledPromise() {
|
|
35
|
+
let resolve = () => void 0;
|
|
36
|
+
let reject = () => void 0;
|
|
37
|
+
const promise = new Promise((aResolve, aReject) => {
|
|
38
|
+
resolve = aResolve;
|
|
39
|
+
reject = aReject;
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
promise,
|
|
43
|
+
resolve,
|
|
44
|
+
reject
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function wrapRpc(childProcess, options) {
|
|
48
|
+
return async (...args) => {
|
|
49
|
+
if (!childProcess.send) {
|
|
50
|
+
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
51
|
+
} else if (!childProcess.connected) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Process ${childProcess.pid} doesn't have open IPC channels`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const { id, once } = options;
|
|
57
|
+
const {
|
|
58
|
+
promise: resultPromise,
|
|
59
|
+
resolve: resolveResult,
|
|
60
|
+
reject: rejectResult
|
|
61
|
+
} = createControlledPromise();
|
|
62
|
+
const {
|
|
63
|
+
promise: sendPromise,
|
|
64
|
+
resolve: resolveSend,
|
|
65
|
+
reject: rejectSend
|
|
66
|
+
} = createControlledPromise();
|
|
67
|
+
const handleMessage = (message) => {
|
|
68
|
+
if ((message == null ? void 0 : message.id) === id) {
|
|
69
|
+
if (message.type === "mf_resolve" /* RESOLVE */) {
|
|
70
|
+
resolveResult(message.value);
|
|
71
|
+
if (once) {
|
|
72
|
+
removeHandlers();
|
|
73
|
+
}
|
|
74
|
+
} else if (message.type === "mf_reject" /* REJECT */) {
|
|
75
|
+
rejectResult(message.error);
|
|
76
|
+
if (once) {
|
|
77
|
+
removeHandlers();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const handleClose = (code, signal) => {
|
|
83
|
+
rejectResult(
|
|
84
|
+
new RpcExitError(
|
|
85
|
+
code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`,
|
|
86
|
+
code,
|
|
87
|
+
signal
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
removeHandlers();
|
|
91
|
+
};
|
|
92
|
+
const removeHandlers = () => {
|
|
93
|
+
childProcess.off("message", handleMessage);
|
|
94
|
+
childProcess.off("close", handleClose);
|
|
95
|
+
};
|
|
96
|
+
childProcess.on("message", handleMessage);
|
|
97
|
+
childProcess.on("close", handleClose);
|
|
98
|
+
childProcess.on("error", (err) => {
|
|
99
|
+
console.error(err);
|
|
100
|
+
});
|
|
101
|
+
childProcess.send(
|
|
102
|
+
{
|
|
103
|
+
type: "mf_call" /* CALL */,
|
|
104
|
+
id,
|
|
105
|
+
args
|
|
106
|
+
},
|
|
107
|
+
(error) => {
|
|
108
|
+
if (error) {
|
|
109
|
+
rejectSend(error);
|
|
110
|
+
removeHandlers();
|
|
111
|
+
} else {
|
|
112
|
+
resolveSend(void 0);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
return sendPromise.then(() => resultPromise);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// packages/native-federation-typescript/src/rpc/rpc-worker.ts
|
|
121
|
+
import * as child_process from "child_process";
|
|
122
|
+
import * as process from "process";
|
|
123
|
+
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
124
|
+
function uuid() {
|
|
125
|
+
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
126
|
+
}
|
|
127
|
+
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
128
|
+
const options = {
|
|
129
|
+
env: {
|
|
130
|
+
...process.env,
|
|
131
|
+
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
132
|
+
},
|
|
133
|
+
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
134
|
+
serialization: "advanced"
|
|
135
|
+
};
|
|
136
|
+
if (memoryLimit) {
|
|
137
|
+
options.execArgv = [`--max-old-space-size=${memoryLimit}`];
|
|
138
|
+
}
|
|
139
|
+
let childProcess, remoteMethod;
|
|
140
|
+
const id = uuid();
|
|
141
|
+
const worker = {
|
|
142
|
+
connect(...args) {
|
|
143
|
+
if (childProcess && !childProcess.connected) {
|
|
144
|
+
childProcess.send({
|
|
145
|
+
type: "mf_exit" /* EXIT */,
|
|
146
|
+
id
|
|
147
|
+
});
|
|
148
|
+
childProcess = void 0;
|
|
149
|
+
remoteMethod = void 0;
|
|
150
|
+
}
|
|
151
|
+
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
152
|
+
childProcess = child_process.fork(modulePath, options);
|
|
153
|
+
remoteMethod = wrapRpc(childProcess, { id, once });
|
|
154
|
+
}
|
|
155
|
+
if (!remoteMethod) {
|
|
156
|
+
return Promise.reject("Worker is not connected - cannot perform RPC.");
|
|
157
|
+
}
|
|
158
|
+
return remoteMethod(...args);
|
|
159
|
+
},
|
|
160
|
+
terminate() {
|
|
161
|
+
if (childProcess) {
|
|
162
|
+
childProcess.send({
|
|
163
|
+
type: "mf_exit" /* EXIT */,
|
|
164
|
+
id
|
|
165
|
+
});
|
|
166
|
+
childProcess = void 0;
|
|
167
|
+
remoteMethod = void 0;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
get connected() {
|
|
171
|
+
return Boolean(childProcess == null ? void 0 : childProcess.connected);
|
|
172
|
+
},
|
|
173
|
+
get process() {
|
|
174
|
+
return childProcess;
|
|
175
|
+
},
|
|
176
|
+
get id() {
|
|
177
|
+
return id;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return worker;
|
|
181
|
+
}
|
|
182
|
+
function getRpcWorkerData() {
|
|
183
|
+
return JSON.parse(process.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// packages/native-federation-typescript/src/lib/DtsWorker.ts
|
|
187
|
+
var DtsWorker = class {
|
|
188
|
+
constructor(options) {
|
|
189
|
+
this._options = cloneDeepWith(options, (_value, key) => {
|
|
190
|
+
if (key === "manifest") {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
this.removeUnSerializationOptions();
|
|
195
|
+
this._rpcWorker = createRpcWorker(
|
|
196
|
+
path.resolve(__dirname, "./lib/forkGenerateDts.js"),
|
|
197
|
+
{},
|
|
198
|
+
void 0,
|
|
199
|
+
true
|
|
200
|
+
);
|
|
201
|
+
this._res = this._rpcWorker.connect(this._options);
|
|
202
|
+
Promise.resolve(this._res).then(() => {
|
|
203
|
+
this.exit();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
removeUnSerializationOptions() {
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
208
|
+
if ((_b = (_a = this._options.remote) == null ? void 0 : _a.moduleFederationConfig) == null ? void 0 : _b.manifest) {
|
|
209
|
+
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
210
|
+
}
|
|
211
|
+
if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
|
|
212
|
+
(_h = (_g = this._options.host) == null ? void 0 : _g.moduleFederationConfig) == null ? true : delete _h.manifest;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
get controlledPromise() {
|
|
216
|
+
return this._res;
|
|
217
|
+
}
|
|
218
|
+
exit() {
|
|
219
|
+
var _a;
|
|
220
|
+
(_a = this._rpcWorker) == null ? void 0 : _a.terminate();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// packages/native-federation-typescript/src/lib/generateTypesInChildProcess.ts
|
|
225
|
+
async function generateTypesInChildProcess(options) {
|
|
226
|
+
const dtsWorker = new DtsWorker(options);
|
|
227
|
+
return dtsWorker.controlledPromise;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// packages/native-federation-typescript/src/lib/consumeTypes.ts
|
|
231
|
+
async function consumeTypes(options) {
|
|
232
|
+
var _a;
|
|
233
|
+
const DTSManagerConstructor = getDTSManagerConstructor(
|
|
234
|
+
(_a = options.host) == null ? void 0 : _a.implementation
|
|
235
|
+
);
|
|
236
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
237
|
+
await dtsManager.consumeTypes();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
rpc_exports,
|
|
242
|
+
generateTypesInChildProcess,
|
|
243
|
+
consumeTypes
|
|
244
|
+
};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2NC7LVYZjs = require('./chunk-2NC7LVYZ.js');
|
|
7
|
+
|
|
8
|
+
// packages/native-federation-typescript/src/lib/DtsWorker.ts
|
|
9
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
10
|
+
var _lodashclonedeepwith = require('lodash.clonedeepwith'); var _lodashclonedeepwith2 = _interopRequireDefault(_lodashclonedeepwith);
|
|
11
|
+
|
|
12
|
+
// packages/native-federation-typescript/src/rpc/index.ts
|
|
13
|
+
var rpc_exports = {};
|
|
14
|
+
_chunk2NC7LVYZjs.__export.call(void 0, rpc_exports, {
|
|
15
|
+
RpcExitError: () => RpcExitError,
|
|
16
|
+
RpcGMCallTypes: () => _chunk2NC7LVYZjs.RpcGMCallTypes,
|
|
17
|
+
createRpcWorker: () => createRpcWorker,
|
|
18
|
+
exposeRpc: () => _chunk2NC7LVYZjs.exposeRpc,
|
|
19
|
+
getRpcWorkerData: () => getRpcWorkerData,
|
|
20
|
+
wrapRpc: () => wrapRpc
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// packages/native-federation-typescript/src/rpc/rpc-error.ts
|
|
24
|
+
var RpcExitError = class extends Error {
|
|
25
|
+
constructor(message, code, signal) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.signal = signal;
|
|
29
|
+
this.name = "RpcExitError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// packages/native-federation-typescript/src/rpc/wrap-rpc.ts
|
|
34
|
+
function createControlledPromise() {
|
|
35
|
+
let resolve = () => void 0;
|
|
36
|
+
let reject = () => void 0;
|
|
37
|
+
const promise = new Promise((aResolve, aReject) => {
|
|
38
|
+
resolve = aResolve;
|
|
39
|
+
reject = aReject;
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
promise,
|
|
43
|
+
resolve,
|
|
44
|
+
reject
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function wrapRpc(childProcess, options) {
|
|
48
|
+
return async (...args) => {
|
|
49
|
+
if (!childProcess.send) {
|
|
50
|
+
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
51
|
+
} else if (!childProcess.connected) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Process ${childProcess.pid} doesn't have open IPC channels`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const { id, once } = options;
|
|
57
|
+
const {
|
|
58
|
+
promise: resultPromise,
|
|
59
|
+
resolve: resolveResult,
|
|
60
|
+
reject: rejectResult
|
|
61
|
+
} = createControlledPromise();
|
|
62
|
+
const {
|
|
63
|
+
promise: sendPromise,
|
|
64
|
+
resolve: resolveSend,
|
|
65
|
+
reject: rejectSend
|
|
66
|
+
} = createControlledPromise();
|
|
67
|
+
const handleMessage = (message) => {
|
|
68
|
+
if ((message == null ? void 0 : message.id) === id) {
|
|
69
|
+
if (message.type === "mf_resolve" /* RESOLVE */) {
|
|
70
|
+
resolveResult(message.value);
|
|
71
|
+
if (once) {
|
|
72
|
+
removeHandlers();
|
|
73
|
+
}
|
|
74
|
+
} else if (message.type === "mf_reject" /* REJECT */) {
|
|
75
|
+
rejectResult(message.error);
|
|
76
|
+
if (once) {
|
|
77
|
+
removeHandlers();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const handleClose = (code, signal) => {
|
|
83
|
+
rejectResult(
|
|
84
|
+
new RpcExitError(
|
|
85
|
+
code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`,
|
|
86
|
+
code,
|
|
87
|
+
signal
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
removeHandlers();
|
|
91
|
+
};
|
|
92
|
+
const removeHandlers = () => {
|
|
93
|
+
childProcess.off("message", handleMessage);
|
|
94
|
+
childProcess.off("close", handleClose);
|
|
95
|
+
};
|
|
96
|
+
childProcess.on("message", handleMessage);
|
|
97
|
+
childProcess.on("close", handleClose);
|
|
98
|
+
childProcess.on("error", (err) => {
|
|
99
|
+
console.error(err);
|
|
100
|
+
});
|
|
101
|
+
childProcess.send(
|
|
102
|
+
{
|
|
103
|
+
type: "mf_call" /* CALL */,
|
|
104
|
+
id,
|
|
105
|
+
args
|
|
106
|
+
},
|
|
107
|
+
(error) => {
|
|
108
|
+
if (error) {
|
|
109
|
+
rejectSend(error);
|
|
110
|
+
removeHandlers();
|
|
111
|
+
} else {
|
|
112
|
+
resolveSend(void 0);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
return sendPromise.then(() => resultPromise);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// packages/native-federation-typescript/src/rpc/rpc-worker.ts
|
|
121
|
+
var _child_process = require('child_process'); var child_process = _interopRequireWildcard(_child_process);
|
|
122
|
+
var _process = require('process'); var process = _interopRequireWildcard(_process);
|
|
123
|
+
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
124
|
+
function uuid() {
|
|
125
|
+
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
126
|
+
}
|
|
127
|
+
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
128
|
+
const options = {
|
|
129
|
+
env: {
|
|
130
|
+
...process.env,
|
|
131
|
+
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
132
|
+
},
|
|
133
|
+
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
134
|
+
serialization: "advanced"
|
|
135
|
+
};
|
|
136
|
+
if (memoryLimit) {
|
|
137
|
+
options.execArgv = [`--max-old-space-size=${memoryLimit}`];
|
|
138
|
+
}
|
|
139
|
+
let childProcess, remoteMethod;
|
|
140
|
+
const id = uuid();
|
|
141
|
+
const worker = {
|
|
142
|
+
connect(...args) {
|
|
143
|
+
if (childProcess && !childProcess.connected) {
|
|
144
|
+
childProcess.send({
|
|
145
|
+
type: "mf_exit" /* EXIT */,
|
|
146
|
+
id
|
|
147
|
+
});
|
|
148
|
+
childProcess = void 0;
|
|
149
|
+
remoteMethod = void 0;
|
|
150
|
+
}
|
|
151
|
+
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
152
|
+
childProcess = child_process.fork(modulePath, options);
|
|
153
|
+
remoteMethod = wrapRpc(childProcess, { id, once });
|
|
154
|
+
}
|
|
155
|
+
if (!remoteMethod) {
|
|
156
|
+
return Promise.reject("Worker is not connected - cannot perform RPC.");
|
|
157
|
+
}
|
|
158
|
+
return remoteMethod(...args);
|
|
159
|
+
},
|
|
160
|
+
terminate() {
|
|
161
|
+
if (childProcess) {
|
|
162
|
+
childProcess.send({
|
|
163
|
+
type: "mf_exit" /* EXIT */,
|
|
164
|
+
id
|
|
165
|
+
});
|
|
166
|
+
childProcess = void 0;
|
|
167
|
+
remoteMethod = void 0;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
get connected() {
|
|
171
|
+
return Boolean(childProcess == null ? void 0 : childProcess.connected);
|
|
172
|
+
},
|
|
173
|
+
get process() {
|
|
174
|
+
return childProcess;
|
|
175
|
+
},
|
|
176
|
+
get id() {
|
|
177
|
+
return id;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return worker;
|
|
181
|
+
}
|
|
182
|
+
function getRpcWorkerData() {
|
|
183
|
+
return JSON.parse(process.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// packages/native-federation-typescript/src/lib/DtsWorker.ts
|
|
187
|
+
var DtsWorker = class {
|
|
188
|
+
constructor(options) {
|
|
189
|
+
this._options = _lodashclonedeepwith2.default.call(void 0, options, (_value, key) => {
|
|
190
|
+
if (key === "manifest") {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
this.removeUnSerializationOptions();
|
|
195
|
+
this._rpcWorker = createRpcWorker(
|
|
196
|
+
_path2.default.resolve(__dirname, "./lib/forkGenerateDts.js"),
|
|
197
|
+
{},
|
|
198
|
+
void 0,
|
|
199
|
+
true
|
|
200
|
+
);
|
|
201
|
+
this._res = this._rpcWorker.connect(this._options);
|
|
202
|
+
Promise.resolve(this._res).then(() => {
|
|
203
|
+
this.exit();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
removeUnSerializationOptions() {
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
208
|
+
if ((_b = (_a = this._options.remote) == null ? void 0 : _a.moduleFederationConfig) == null ? void 0 : _b.manifest) {
|
|
209
|
+
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
210
|
+
}
|
|
211
|
+
if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
|
|
212
|
+
(_h = (_g = this._options.host) == null ? void 0 : _g.moduleFederationConfig) == null ? true : delete _h.manifest;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
get controlledPromise() {
|
|
216
|
+
return this._res;
|
|
217
|
+
}
|
|
218
|
+
exit() {
|
|
219
|
+
var _a;
|
|
220
|
+
(_a = this._rpcWorker) == null ? void 0 : _a.terminate();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// packages/native-federation-typescript/src/lib/generateTypesInChildProcess.ts
|
|
225
|
+
async function generateTypesInChildProcess(options) {
|
|
226
|
+
const dtsWorker = new DtsWorker(options);
|
|
227
|
+
return dtsWorker.controlledPromise;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// packages/native-federation-typescript/src/lib/consumeTypes.ts
|
|
231
|
+
async function consumeTypes(options) {
|
|
232
|
+
var _a;
|
|
233
|
+
const DTSManagerConstructor = _chunk2NC7LVYZjs.getDTSManagerConstructor.call(void 0,
|
|
234
|
+
(_a = options.host) == null ? void 0 : _a.implementation
|
|
235
|
+
);
|
|
236
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
237
|
+
await dtsManager.consumeTypes();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
exports.rpc_exports = rpc_exports; exports.generateTypesInChildProcess = generateTypesInChildProcess; exports.consumeTypes = consumeTypes;
|