@module-federation/dts-plugin 2.1.0 → 2.2.1
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 +28 -1
- package/dist/{consumeTypes-AD2ig87l.js → consumeTypes-C78VTe8r.js} +1 -1
- package/dist/core.js +2 -2
- package/dist/esm/{consumeTypes-D51rVbSt.mjs → consumeTypes-IRrP9NIN.mjs} +1 -1
- package/dist/esm/core.mjs +2 -2
- package/dist/esm/{expose-rpc-DMhY1i8A.mjs → expose-rpc-DsABkfLc.mjs} +10 -6
- package/dist/esm/fork-dev-worker.mjs +18 -8
- package/dist/esm/fork-generate-dts.mjs +1 -1
- package/dist/esm/index.mjs +27 -7
- package/dist/{expose-rpc-BLAH20uj.js → expose-rpc-DkHFNYya.js} +9 -5
- package/dist/fork-dev-worker.js +18 -8
- package/dist/fork-generate-dts.js +1 -1
- package/dist/index.js +27 -7
- package/dist/package.json +12 -2
- package/package.json +17 -7
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @module-federation/dts-plugin
|
|
2
2
|
|
|
3
|
+
## 2.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @module-federation/sdk@2.2.1
|
|
8
|
+
- @module-federation/managers@2.2.1
|
|
9
|
+
- @module-federation/third-party-dts-extractor@2.2.1
|
|
10
|
+
- @module-federation/error-codes@2.2.1
|
|
11
|
+
|
|
12
|
+
## 2.2.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 12240bb: feat(dts-plugin): support custom outputDir for DTS type emission
|
|
17
|
+
|
|
18
|
+
Expose the `outputDir` option in `DtsRemoteOptions` so users can configure where `@mf-types.zip` and `@mf-types.d.ts` are emitted. Fix `GenerateTypesPlugin` to use `path.relative()` for correct asset placement in subdirectories.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 079aecd: fix(dts-plugin): use default import for fs-extra to fix ESM compatibility
|
|
23
|
+
- Updated dependencies [c856ec1]
|
|
24
|
+
- Updated dependencies [12240bb]
|
|
25
|
+
- Updated dependencies [e5dd6ef]
|
|
26
|
+
- @module-federation/sdk@2.2.0
|
|
27
|
+
- @module-federation/managers@2.2.0
|
|
28
|
+
- @module-federation/third-party-dts-extractor@2.2.0
|
|
29
|
+
- @module-federation/error-codes@2.2.0
|
|
30
|
+
|
|
3
31
|
## 2.1.0
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -248,7 +276,6 @@
|
|
|
248
276
|
### Patch Changes
|
|
249
277
|
|
|
250
278
|
- a7cf276: chore: upgrade NX to 21.2.3, Storybook to 9.0.9, and TypeScript to 5.8.3
|
|
251
|
-
|
|
252
279
|
- Upgraded NX from 21.0.3 to 21.2.3 with workspace configuration updates
|
|
253
280
|
- Migrated Storybook from 8.3.5 to 9.0.9 with updated configurations and automigrations
|
|
254
281
|
- Upgraded TypeScript from 5.7.3 to 5.8.3 with compatibility fixes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
2
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
2
|
+
const require_expose_rpc = require('./expose-rpc-DkHFNYya.js');
|
|
3
3
|
let path = require("path");
|
|
4
4
|
path = require_Action.__toESM(path);
|
|
5
5
|
let crypto = require("crypto");
|
package/dist/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('./Broker-DRlzScTT.js');
|
|
3
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
4
|
-
const require_consumeTypes = require('./consumeTypes-
|
|
3
|
+
const require_expose_rpc = require('./expose-rpc-DkHFNYya.js');
|
|
4
|
+
const require_consumeTypes = require('./consumeTypes-C78VTe8r.js');
|
|
5
5
|
|
|
6
6
|
exports.DTSManager = require_expose_rpc.DTSManager;
|
|
7
7
|
exports.DtsWorker = require_consumeTypes.DtsWorker;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-
|
|
1
|
+
import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-DsABkfLc.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
4
|
import * as child_process from "child_process";
|
package/dist/esm/core.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as retrieveMfTypesPath, c as isTSProject, d as DTSManager, f as HOST_API_TYPES_FILE_NAME, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, l as retrieveTypesAssetsInfo, m as REMOTE_API_TYPES_FILE_NAME, o as getDTSManagerConstructor, p as REMOTE_ALIAS_IDENTIFIER, r as generateTypes, u as validateOptions, v as retrieveOriginalOutDir } from "./expose-rpc-
|
|
1
|
+
import { _ as retrieveMfTypesPath, c as isTSProject, d as DTSManager, f as HOST_API_TYPES_FILE_NAME, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, l as retrieveTypesAssetsInfo, m as REMOTE_API_TYPES_FILE_NAME, o as getDTSManagerConstructor, p as REMOTE_ALIAS_IDENTIFIER, r as generateTypes, u as validateOptions, v as retrieveOriginalOutDir } from "./expose-rpc-DsABkfLc.mjs";
|
|
2
2
|
import "./Broker-BU4gToNr.mjs";
|
|
3
|
-
import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-
|
|
3
|
+
import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-IRrP9NIN.mjs";
|
|
4
4
|
|
|
5
5
|
export { DTSManager, DtsWorker, HOST_API_TYPES_FILE_NAME, REMOTE_ALIAS_IDENTIFIER, REMOTE_API_TYPES_FILE_NAME, consumeTypes, generateTypes, generateTypesInChildProcess, getDTSManagerConstructor, isTSProject, retrieveHostConfig, retrieveMfTypesPath, retrieveOriginalOutDir, retrieveRemoteConfig, retrieveTypesAssetsInfo, retrieveTypesZipPath, rpc_exports as rpc, validateOptions };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { a as MF_SERVER_IDENTIFIER, n as ActionKind, o as UpdateMode, r as DEFAULT_TAR_NAME, t as Action } from "./Action-DNNg2YDh.mjs";
|
|
2
2
|
import { a as getIdentifier, c as logger$1, i as getFreePort, l as LogKind, n as UpdateKind, o as getIPV4, r as fib, s as fileLog, t as Broker, u as APIKind } from "./Broker-BU4gToNr.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import fse
|
|
4
|
+
import fse from "fs-extra";
|
|
5
5
|
import path, { dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
6
|
-
import fs, { existsSync
|
|
6
|
+
import fs, { existsSync } from "fs";
|
|
7
7
|
import { utils } from "@module-federation/managers";
|
|
8
8
|
import typescript from "typescript";
|
|
9
9
|
import axios from "axios";
|
|
@@ -15,7 +15,8 @@ import { readFile, readdir, rm, stat, writeFile } from "fs/promises";
|
|
|
15
15
|
import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
|
|
16
16
|
import AdmZip from "adm-zip";
|
|
17
17
|
import crypto from "crypto";
|
|
18
|
-
import { TYPE_001,
|
|
18
|
+
import { TYPE_001, typeDescMap } from "@module-federation/error-codes";
|
|
19
|
+
import { logAndReport } from "@module-federation/error-codes/node";
|
|
19
20
|
import { execFile, fork } from "child_process";
|
|
20
21
|
import util from "util";
|
|
21
22
|
import WebSocket from "isomorphic-ws";
|
|
@@ -439,6 +440,7 @@ async function createHttpServer(options) {
|
|
|
439
440
|
|
|
440
441
|
//#endregion
|
|
441
442
|
//#region src/core/lib/typeScriptCompiler.ts
|
|
443
|
+
const { ensureDirSync, writeFileSync, existsSync: existsSync$1 } = fse;
|
|
442
444
|
const STARTS_WITH_SLASH = /^\//;
|
|
443
445
|
const DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
444
446
|
const retrieveMfTypesPath = (tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, ""));
|
|
@@ -467,7 +469,7 @@ function getExposeKey(options) {
|
|
|
467
469
|
}
|
|
468
470
|
const processTypesFile = async (options) => {
|
|
469
471
|
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
470
|
-
if (!existsSync(filePath)) return;
|
|
472
|
+
if (!existsSync$1(filePath)) return;
|
|
471
473
|
if ((await stat(filePath)).isDirectory()) {
|
|
472
474
|
const files = await readdir(filePath);
|
|
473
475
|
await Promise.all(files.map((file) => processTypesFile({
|
|
@@ -575,7 +577,9 @@ const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
575
577
|
if (compilerOptions.tsBuildInfoFile) try {
|
|
576
578
|
await rm(compilerOptions.tsBuildInfoFile);
|
|
577
579
|
} catch (e) {}
|
|
578
|
-
|
|
580
|
+
logAndReport(TYPE_001, typeDescMap, { cmd }, (msg) => {
|
|
581
|
+
throw new Error(msg);
|
|
582
|
+
}, void 0);
|
|
579
583
|
}
|
|
580
584
|
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
581
585
|
const normalizedFileName = normalize(filename);
|
|
@@ -1207,7 +1211,7 @@ const resolveWithExtension = (exposedPath, context) => {
|
|
|
1207
1211
|
if (extname(exposedPath)) return resolve(context, exposedPath);
|
|
1208
1212
|
for (const extension of TS_EXTENSIONS) {
|
|
1209
1213
|
const exposedPathWithExtension = resolve(context, `${exposedPath}.${extension}`);
|
|
1210
|
-
if (existsSync
|
|
1214
|
+
if (existsSync(exposedPathWithExtension)) return exposedPathWithExtension;
|
|
1211
1215
|
}
|
|
1212
1216
|
};
|
|
1213
1217
|
const resolveExposes = (remoteOptions) => {
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { _ as retrieveMfTypesPath, b as ModuleFederationDevServer, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, n as RpcGMCallTypes, o as getDTSManagerConstructor, t as exposeRpc, y as createHttpServer } from "./expose-rpc-
|
|
1
|
+
import { _ as retrieveMfTypesPath, b as ModuleFederationDevServer, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, n as RpcGMCallTypes, o as getDTSManagerConstructor, t as exposeRpc, y as createHttpServer } from "./expose-rpc-DsABkfLc.mjs";
|
|
2
2
|
import { o as UpdateMode, r as DEFAULT_TAR_NAME } from "./Action-DNNg2YDh.mjs";
|
|
3
3
|
import { n as UpdateKind, o as getIPV4, s as fileLog } from "./Broker-BU4gToNr.mjs";
|
|
4
|
-
import "./consumeTypes-
|
|
4
|
+
import "./consumeTypes-IRrP9NIN.mjs";
|
|
5
5
|
import "./core.mjs";
|
|
6
6
|
import { t as getIpFromEntry } from "./utils-CkPvDGOy.mjs";
|
|
7
7
|
import { decodeName } from "@module-federation/sdk";
|
|
8
8
|
|
|
9
|
+
//#region src/dev-worker/handleWorkerMessage.ts
|
|
10
|
+
function handleDevWorkerMessage(message, options = {}) {
|
|
11
|
+
const { moduleServer, processExit = process.exit, pid = process.pid, log = () => void 0 } = options;
|
|
12
|
+
log(`ChildProcess(${pid}), message: ${JSON.stringify(message)} `, "forkDevWorker", "info");
|
|
13
|
+
if (message.type === RpcGMCallTypes.EXIT) {
|
|
14
|
+
log(`ChildProcess(${pid}) SIGTERM, Federation DevServer will exit...`, "forkDevWorker", "error");
|
|
15
|
+
moduleServer?.exit();
|
|
16
|
+
processExit(0);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
9
21
|
//#region src/dev-worker/forkDevWorker.ts
|
|
10
22
|
let typesManager, serverAddress, moduleServer, cacheOptions;
|
|
11
23
|
function getLocalRemoteNames(options, encodeNameIdentifier) {
|
|
@@ -90,12 +102,10 @@ async function forkDevWorker(options, action) {
|
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
process.on("message", (message) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
fileLog
|
|
96
|
-
|
|
97
|
-
process.exit(0);
|
|
98
|
-
}
|
|
105
|
+
handleDevWorkerMessage(message, {
|
|
106
|
+
moduleServer,
|
|
107
|
+
log: fileLog
|
|
108
|
+
});
|
|
99
109
|
});
|
|
100
110
|
exposeRpc(forkDevWorker);
|
|
101
111
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as RpcGMCallTypes, r as generateTypes, t as exposeRpc } from "./expose-rpc-
|
|
1
|
+
import { n as RpcGMCallTypes, r as generateTypes, t as exposeRpc } from "./expose-rpc-DsABkfLc.mjs";
|
|
2
2
|
import "./Broker-BU4gToNr.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/lib/forkGenerateDts.ts
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as cloneDeepOptions, c as isTSProject, l as retrieveTypesAssetsInfo, n as RpcGMCallTypes, r as generateTypes, u as validateOptions } from "./expose-rpc-
|
|
1
|
+
import { a as cloneDeepOptions, c as isTSProject, l as retrieveTypesAssetsInfo, n as RpcGMCallTypes, r as generateTypes, u as validateOptions } from "./expose-rpc-DsABkfLc.mjs";
|
|
2
2
|
import { s as WEB_CLIENT_OPTIONS_IDENTIFIER } from "./Action-DNNg2YDh.mjs";
|
|
3
3
|
import { c as logger$1, o as getIPV4 } from "./Broker-BU4gToNr.mjs";
|
|
4
|
-
import { a as createRpcWorker, n as generateTypesInChildProcess, t as consumeTypes } from "./consumeTypes-
|
|
4
|
+
import { a as createRpcWorker, n as generateTypesInChildProcess, t as consumeTypes } from "./consumeTypes-IRrP9NIN.mjs";
|
|
5
5
|
import "./core.mjs";
|
|
6
6
|
import * as fse$1 from "fs-extra";
|
|
7
7
|
import fse from "fs-extra";
|
|
@@ -314,6 +314,15 @@ const getGenerateTypesFn = (dtsManagerOptions) => {
|
|
|
314
314
|
const generateTypesAPI = ({ dtsManagerOptions }) => {
|
|
315
315
|
return getGenerateTypesFn(dtsManagerOptions)(dtsManagerOptions);
|
|
316
316
|
};
|
|
317
|
+
const WINDOWS_ABSOLUTE_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
|
|
318
|
+
const isSafeRelativePath = (relativePath) => {
|
|
319
|
+
return Boolean(relativePath) && !relativePath.startsWith("..") && !path.isAbsolute(relativePath) && !WINDOWS_ABSOLUTE_PATH_REGEXP.test(relativePath);
|
|
320
|
+
};
|
|
321
|
+
const resolveEmitAssetName = ({ compilerOutputPath, assetPath, fallbackName }) => {
|
|
322
|
+
if (!assetPath) return fallbackName;
|
|
323
|
+
const relativePath = path.relative(compilerOutputPath, assetPath);
|
|
324
|
+
return isSafeRelativePath(relativePath) ? relativePath : fallbackName;
|
|
325
|
+
};
|
|
317
326
|
var GenerateTypesPlugin = class {
|
|
318
327
|
constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsPromise, callback) {
|
|
319
328
|
this.pluginOptions = pluginOptions;
|
|
@@ -336,10 +345,21 @@ var GenerateTypesPlugin = class {
|
|
|
336
345
|
return;
|
|
337
346
|
}
|
|
338
347
|
const isProd = !isDev();
|
|
348
|
+
const compilerOutputPath = path.resolve(context, outputDir);
|
|
339
349
|
const emitTypesFiles = async (compilation) => {
|
|
340
350
|
try {
|
|
341
351
|
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(dtsManagerOptions.remote);
|
|
342
|
-
|
|
352
|
+
const emitZipName = resolveEmitAssetName({
|
|
353
|
+
compilerOutputPath,
|
|
354
|
+
assetPath: zipTypesPath,
|
|
355
|
+
fallbackName: zipName
|
|
356
|
+
});
|
|
357
|
+
const emitApiFileName = resolveEmitAssetName({
|
|
358
|
+
compilerOutputPath,
|
|
359
|
+
assetPath: apiTypesPath,
|
|
360
|
+
fallbackName: apiFileName
|
|
361
|
+
});
|
|
362
|
+
if (isProd && emitZipName && compilation.getAsset(emitZipName)) {
|
|
343
363
|
callback();
|
|
344
364
|
return;
|
|
345
365
|
}
|
|
@@ -347,8 +367,8 @@ var GenerateTypesPlugin = class {
|
|
|
347
367
|
await generateTypesAPI({ dtsManagerOptions });
|
|
348
368
|
logger.debug("generate types success!");
|
|
349
369
|
if (isProd) {
|
|
350
|
-
if (zipTypesPath && !compilation.getAsset(
|
|
351
|
-
if (apiTypesPath && !compilation.getAsset(
|
|
370
|
+
if (zipTypesPath && !compilation.getAsset(emitZipName) && fs.existsSync(zipTypesPath)) compilation.emitAsset(emitZipName, new compiler.webpack.sources.RawSource(fs.readFileSync(zipTypesPath)));
|
|
371
|
+
if (apiTypesPath && !compilation.getAsset(emitApiFileName) && fs.existsSync(apiTypesPath)) compilation.emitAsset(emitApiFileName, new compiler.webpack.sources.RawSource(fs.readFileSync(apiTypesPath)));
|
|
352
372
|
callback();
|
|
353
373
|
} else {
|
|
354
374
|
const isEEXIST = (err) => {
|
|
@@ -356,7 +376,7 @@ var GenerateTypesPlugin = class {
|
|
|
356
376
|
};
|
|
357
377
|
if (zipTypesPath && fs.existsSync(zipTypesPath)) {
|
|
358
378
|
const zipContent = fs.readFileSync(zipTypesPath);
|
|
359
|
-
const zipOutputPath = path.join(compiler.outputPath,
|
|
379
|
+
const zipOutputPath = path.join(compiler.outputPath, emitZipName);
|
|
360
380
|
await new Promise((resolve, reject) => {
|
|
361
381
|
compiler.outputFileSystem.mkdir(path.dirname(zipOutputPath), { recursive: true }, (err) => {
|
|
362
382
|
if (err && !isEEXIST(err)) reject(err);
|
|
@@ -369,7 +389,7 @@ var GenerateTypesPlugin = class {
|
|
|
369
389
|
}
|
|
370
390
|
if (apiTypesPath && fs.existsSync(apiTypesPath)) {
|
|
371
391
|
const apiContent = fs.readFileSync(apiTypesPath);
|
|
372
|
-
const apiOutputPath = path.join(compiler.outputPath,
|
|
392
|
+
const apiOutputPath = path.join(compiler.outputPath, emitApiFileName);
|
|
373
393
|
await new Promise((resolve, reject) => {
|
|
374
394
|
compiler.outputFileSystem.mkdir(path.dirname(apiOutputPath), { recursive: true }, (err) => {
|
|
375
395
|
if (err && !isEEXIST(err)) reject(err);
|
|
@@ -25,6 +25,7 @@ adm_zip = require_Action.__toESM(adm_zip);
|
|
|
25
25
|
let crypto = require("crypto");
|
|
26
26
|
crypto = require_Action.__toESM(crypto);
|
|
27
27
|
let _module_federation_error_codes = require("@module-federation/error-codes");
|
|
28
|
+
let _module_federation_error_codes_node = require("@module-federation/error-codes/node");
|
|
28
29
|
let child_process = require("child_process");
|
|
29
30
|
let util = require("util");
|
|
30
31
|
util = require_Action.__toESM(util);
|
|
@@ -434,6 +435,7 @@ async function createHttpServer(options) {
|
|
|
434
435
|
|
|
435
436
|
//#endregion
|
|
436
437
|
//#region src/core/lib/typeScriptCompiler.ts
|
|
438
|
+
const { ensureDirSync, writeFileSync, existsSync: existsSync$1 } = fs_extra.default;
|
|
437
439
|
const STARTS_WITH_SLASH = /^\//;
|
|
438
440
|
const DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
439
441
|
const retrieveMfTypesPath = (tsConfig, remoteOptions) => (0, path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, ""));
|
|
@@ -445,8 +447,8 @@ function writeTempTsConfig(tsConfig, context, name, cwd) {
|
|
|
445
447
|
};
|
|
446
448
|
const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
|
|
447
449
|
const tempTsConfigJsonPath = (0, path.resolve)(cwd ?? context, "node_modules", _module_federation_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
|
|
448
|
-
|
|
449
|
-
|
|
450
|
+
ensureDirSync((0, path.dirname)(tempTsConfigJsonPath));
|
|
451
|
+
writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
450
452
|
return tempTsConfigJsonPath;
|
|
451
453
|
}
|
|
452
454
|
const removeExt = (f) => {
|
|
@@ -462,7 +464,7 @@ function getExposeKey(options) {
|
|
|
462
464
|
}
|
|
463
465
|
const processTypesFile = async (options) => {
|
|
464
466
|
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
465
|
-
if (!
|
|
467
|
+
if (!existsSync$1(filePath)) return;
|
|
466
468
|
if ((await (0, fs_promises.stat)(filePath)).isDirectory()) {
|
|
467
469
|
const files = await (0, fs_promises.readdir)(filePath);
|
|
468
470
|
await Promise.all(files.map((file) => processTypesFile({
|
|
@@ -480,7 +482,7 @@ const processTypesFile = async (options) => {
|
|
|
480
482
|
const mfeTypeEntry = (0, path.join)(mfTypePath, `${exposeKey === "." ? "index" : exposeKey}${DEFINITION_FILE_EXTENSION}`);
|
|
481
483
|
const mfeTypeEntryDirectory = (0, path.dirname)(mfeTypeEntry);
|
|
482
484
|
const relativePathToOutput = (0, path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(path.sep).join("/");
|
|
483
|
-
|
|
485
|
+
ensureDirSync(mfeTypeEntryDirectory);
|
|
484
486
|
await (0, fs_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';\nexport { default } from './${relativePathToOutput}';`);
|
|
485
487
|
}
|
|
486
488
|
cb(await (0, fs_promises.readFile)(filePath, "utf8"));
|
|
@@ -570,7 +572,9 @@ const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
570
572
|
if (compilerOptions.tsBuildInfoFile) try {
|
|
571
573
|
await (0, fs_promises.rm)(compilerOptions.tsBuildInfoFile);
|
|
572
574
|
} catch (e) {}
|
|
573
|
-
|
|
575
|
+
(0, _module_federation_error_codes_node.logAndReport)(_module_federation_error_codes.TYPE_001, _module_federation_error_codes.typeDescMap, { cmd }, (msg) => {
|
|
576
|
+
throw new Error(msg);
|
|
577
|
+
}, void 0);
|
|
574
578
|
}
|
|
575
579
|
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
576
580
|
const normalizedFileName = (0, path.normalize)(filename);
|
package/dist/fork-dev-worker.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
3
3
|
const require_Broker = require('./Broker-DRlzScTT.js');
|
|
4
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
5
|
-
require('./consumeTypes-
|
|
4
|
+
const require_expose_rpc = require('./expose-rpc-DkHFNYya.js');
|
|
5
|
+
require('./consumeTypes-C78VTe8r.js');
|
|
6
6
|
require('./core.js');
|
|
7
7
|
const require_utils = require('./utils-7KqCZHbb.js');
|
|
8
8
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
9
9
|
|
|
10
|
+
//#region src/dev-worker/handleWorkerMessage.ts
|
|
11
|
+
function handleDevWorkerMessage(message, options = {}) {
|
|
12
|
+
const { moduleServer, processExit = process.exit, pid = process.pid, log = () => void 0 } = options;
|
|
13
|
+
log(`ChildProcess(${pid}), message: ${JSON.stringify(message)} `, "forkDevWorker", "info");
|
|
14
|
+
if (message.type === require_expose_rpc.RpcGMCallTypes.EXIT) {
|
|
15
|
+
log(`ChildProcess(${pid}) SIGTERM, Federation DevServer will exit...`, "forkDevWorker", "error");
|
|
16
|
+
moduleServer?.exit();
|
|
17
|
+
processExit(0);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
10
22
|
//#region src/dev-worker/forkDevWorker.ts
|
|
11
23
|
let typesManager, serverAddress, moduleServer, cacheOptions;
|
|
12
24
|
function getLocalRemoteNames(options, encodeNameIdentifier) {
|
|
@@ -91,12 +103,10 @@ async function forkDevWorker(options, action) {
|
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
105
|
process.on("message", (message) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
require_Broker.fileLog
|
|
97
|
-
|
|
98
|
-
process.exit(0);
|
|
99
|
-
}
|
|
106
|
+
handleDevWorkerMessage(message, {
|
|
107
|
+
moduleServer,
|
|
108
|
+
log: require_Broker.fileLog
|
|
109
|
+
});
|
|
100
110
|
});
|
|
101
111
|
require_expose_rpc.exposeRpc(forkDevWorker);
|
|
102
112
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('./Broker-DRlzScTT.js');
|
|
3
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
3
|
+
const require_expose_rpc = require('./expose-rpc-DkHFNYya.js');
|
|
4
4
|
|
|
5
5
|
//#region src/core/lib/forkGenerateDts.ts
|
|
6
6
|
async function forkGenerateDts(options) {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
3
3
|
const require_Broker = require('./Broker-DRlzScTT.js');
|
|
4
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
5
|
-
const require_consumeTypes = require('./consumeTypes-
|
|
4
|
+
const require_expose_rpc = require('./expose-rpc-DkHFNYya.js');
|
|
5
|
+
const require_consumeTypes = require('./consumeTypes-C78VTe8r.js');
|
|
6
6
|
require('./core.js');
|
|
7
7
|
let fs_extra = require("fs-extra");
|
|
8
8
|
fs_extra = require_Action.__toESM(fs_extra);
|
|
@@ -316,6 +316,15 @@ const getGenerateTypesFn = (dtsManagerOptions) => {
|
|
|
316
316
|
const generateTypesAPI = ({ dtsManagerOptions }) => {
|
|
317
317
|
return getGenerateTypesFn(dtsManagerOptions)(dtsManagerOptions);
|
|
318
318
|
};
|
|
319
|
+
const WINDOWS_ABSOLUTE_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
|
|
320
|
+
const isSafeRelativePath = (relativePath) => {
|
|
321
|
+
return Boolean(relativePath) && !relativePath.startsWith("..") && !path.default.isAbsolute(relativePath) && !WINDOWS_ABSOLUTE_PATH_REGEXP.test(relativePath);
|
|
322
|
+
};
|
|
323
|
+
const resolveEmitAssetName = ({ compilerOutputPath, assetPath, fallbackName }) => {
|
|
324
|
+
if (!assetPath) return fallbackName;
|
|
325
|
+
const relativePath = path.default.relative(compilerOutputPath, assetPath);
|
|
326
|
+
return isSafeRelativePath(relativePath) ? relativePath : fallbackName;
|
|
327
|
+
};
|
|
319
328
|
var GenerateTypesPlugin = class {
|
|
320
329
|
constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsPromise, callback) {
|
|
321
330
|
this.pluginOptions = pluginOptions;
|
|
@@ -338,10 +347,21 @@ var GenerateTypesPlugin = class {
|
|
|
338
347
|
return;
|
|
339
348
|
}
|
|
340
349
|
const isProd = !isDev();
|
|
350
|
+
const compilerOutputPath = path.default.resolve(context, outputDir);
|
|
341
351
|
const emitTypesFiles = async (compilation) => {
|
|
342
352
|
try {
|
|
343
353
|
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = require_expose_rpc.retrieveTypesAssetsInfo(dtsManagerOptions.remote);
|
|
344
|
-
|
|
354
|
+
const emitZipName = resolveEmitAssetName({
|
|
355
|
+
compilerOutputPath,
|
|
356
|
+
assetPath: zipTypesPath,
|
|
357
|
+
fallbackName: zipName
|
|
358
|
+
});
|
|
359
|
+
const emitApiFileName = resolveEmitAssetName({
|
|
360
|
+
compilerOutputPath,
|
|
361
|
+
assetPath: apiTypesPath,
|
|
362
|
+
fallbackName: apiFileName
|
|
363
|
+
});
|
|
364
|
+
if (isProd && emitZipName && compilation.getAsset(emitZipName)) {
|
|
345
365
|
callback();
|
|
346
366
|
return;
|
|
347
367
|
}
|
|
@@ -349,8 +369,8 @@ var GenerateTypesPlugin = class {
|
|
|
349
369
|
await generateTypesAPI({ dtsManagerOptions });
|
|
350
370
|
_module_federation_sdk.logger.debug("generate types success!");
|
|
351
371
|
if (isProd) {
|
|
352
|
-
if (zipTypesPath && !compilation.getAsset(
|
|
353
|
-
if (apiTypesPath && !compilation.getAsset(
|
|
372
|
+
if (zipTypesPath && !compilation.getAsset(emitZipName) && fs.default.existsSync(zipTypesPath)) compilation.emitAsset(emitZipName, new compiler.webpack.sources.RawSource(fs.default.readFileSync(zipTypesPath)));
|
|
373
|
+
if (apiTypesPath && !compilation.getAsset(emitApiFileName) && fs.default.existsSync(apiTypesPath)) compilation.emitAsset(emitApiFileName, new compiler.webpack.sources.RawSource(fs.default.readFileSync(apiTypesPath)));
|
|
354
374
|
callback();
|
|
355
375
|
} else {
|
|
356
376
|
const isEEXIST = (err) => {
|
|
@@ -358,7 +378,7 @@ var GenerateTypesPlugin = class {
|
|
|
358
378
|
};
|
|
359
379
|
if (zipTypesPath && fs.default.existsSync(zipTypesPath)) {
|
|
360
380
|
const zipContent = fs.default.readFileSync(zipTypesPath);
|
|
361
|
-
const zipOutputPath = path.default.join(compiler.outputPath,
|
|
381
|
+
const zipOutputPath = path.default.join(compiler.outputPath, emitZipName);
|
|
362
382
|
await new Promise((resolve, reject) => {
|
|
363
383
|
compiler.outputFileSystem.mkdir(path.default.dirname(zipOutputPath), { recursive: true }, (err) => {
|
|
364
384
|
if (err && !isEEXIST(err)) reject(err);
|
|
@@ -371,7 +391,7 @@ var GenerateTypesPlugin = class {
|
|
|
371
391
|
}
|
|
372
392
|
if (apiTypesPath && fs.default.existsSync(apiTypesPath)) {
|
|
373
393
|
const apiContent = fs.default.readFileSync(apiTypesPath);
|
|
374
|
-
const apiOutputPath = path.default.join(compiler.outputPath,
|
|
394
|
+
const apiOutputPath = path.default.join(compiler.outputPath, emitApiFileName);
|
|
375
395
|
await new Promise((resolve, reject) => {
|
|
376
396
|
compiler.outputFileSystem.mkdir(path.default.dirname(apiOutputPath), { recursive: true }, (err) => {
|
|
377
397
|
if (err && !isEEXIST(err)) reject(err);
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@module-federation/third-party-dts-extractor": "workspace:*",
|
|
72
72
|
"adm-zip": "^0.5.10",
|
|
73
73
|
"ansi-colors": "^4.1.3",
|
|
74
|
-
"axios": "^1.
|
|
74
|
+
"axios": "^1.13.5",
|
|
75
75
|
"chalk": "3.0.0",
|
|
76
76
|
"fs-extra": "9.1.0",
|
|
77
77
|
"isomorphic-ws": "5.0.0",
|
|
@@ -89,6 +89,8 @@
|
|
|
89
89
|
"rimraf": "~6.0.1",
|
|
90
90
|
"vue": "^3.5.13",
|
|
91
91
|
"vue-tsc": "^2.2.10",
|
|
92
|
+
"directory-tree": "3.5.2",
|
|
93
|
+
"vitest": "1.6.0",
|
|
92
94
|
"webpack": "^5.104.1"
|
|
93
95
|
},
|
|
94
96
|
"peerDependencies": {
|
|
@@ -99,5 +101,13 @@
|
|
|
99
101
|
"vue-tsc": {
|
|
100
102
|
"optional": true
|
|
101
103
|
}
|
|
104
|
+
},
|
|
105
|
+
"scripts": {
|
|
106
|
+
"build": "tsdown --config ./tsdown.config.ts && sleep 1 && cp package.json ./dist && cp *.md ./dist",
|
|
107
|
+
"test": "node -e \"require('fs').rmSync('dist-test',{recursive:true,force:true,maxRetries:20,retryDelay:50})\" && pnpm run test-impl",
|
|
108
|
+
"test-impl": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
|
|
109
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
110
|
+
"build-debug": "FEDERATION_DEBUG=true pnpm run build",
|
|
111
|
+
"pre-release": "pnpm run test && pnpm run build"
|
|
102
112
|
}
|
|
103
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"adm-zip": "^0.5.10",
|
|
69
69
|
"ansi-colors": "^4.1.3",
|
|
70
|
-
"axios": "^1.
|
|
70
|
+
"axios": "^1.13.5",
|
|
71
71
|
"chalk": "3.0.0",
|
|
72
72
|
"fs-extra": "9.1.0",
|
|
73
73
|
"isomorphic-ws": "5.0.0",
|
|
@@ -76,10 +76,10 @@
|
|
|
76
76
|
"node-schedule": "2.1.1",
|
|
77
77
|
"rambda": "^9.1.0",
|
|
78
78
|
"ws": "8.18.0",
|
|
79
|
-
"@module-federation/error-codes": "2.1
|
|
80
|
-
"@module-federation/managers": "2.1
|
|
81
|
-
"@module-federation/sdk": "2.1
|
|
82
|
-
"@module-federation/third-party-dts-extractor": "2.1
|
|
79
|
+
"@module-federation/error-codes": "2.2.1",
|
|
80
|
+
"@module-federation/managers": "2.2.1",
|
|
81
|
+
"@module-federation/sdk": "2.2.1",
|
|
82
|
+
"@module-federation/third-party-dts-extractor": "2.2.1"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@types/node-schedule": "2.1.7",
|
|
@@ -88,8 +88,10 @@
|
|
|
88
88
|
"rimraf": "~6.0.1",
|
|
89
89
|
"vue": "^3.5.13",
|
|
90
90
|
"vue-tsc": "^2.2.10",
|
|
91
|
+
"directory-tree": "3.5.2",
|
|
92
|
+
"vitest": "1.6.0",
|
|
91
93
|
"webpack": "^5.104.1",
|
|
92
|
-
"@module-federation/runtime": "2.1
|
|
94
|
+
"@module-federation/runtime": "2.2.1"
|
|
93
95
|
},
|
|
94
96
|
"peerDependencies": {
|
|
95
97
|
"typescript": "^4.9.0 || ^5.0.0",
|
|
@@ -99,5 +101,13 @@
|
|
|
99
101
|
"vue-tsc": {
|
|
100
102
|
"optional": true
|
|
101
103
|
}
|
|
104
|
+
},
|
|
105
|
+
"scripts": {
|
|
106
|
+
"build": "tsdown --config ./tsdown.config.ts && sleep 1 && cp package.json ./dist && cp *.md ./dist",
|
|
107
|
+
"test": "node -e \"require('fs').rmSync('dist-test',{recursive:true,force:true,maxRetries:20,retryDelay:50})\" && pnpm run test-impl",
|
|
108
|
+
"test-impl": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
|
|
109
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
110
|
+
"build-debug": "FEDERATION_DEBUG=true pnpm run build",
|
|
111
|
+
"pre-release": "pnpm run test && pnpm run build"
|
|
102
112
|
}
|
|
103
113
|
}
|