Skip to content

Commit 9d6c441

Browse files
authored
feat: add support to local shares
1 parent 6360a21 commit 9d6c441

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/utils/normalizeModuleFederationOptions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ export interface ShareItem {
106106
shareConfig: SharedConfig;
107107
}
108108

109-
function removePathFromNpmPackage(packageString: string): string {
109+
function removePathFromNpmPackage(packageString: string): string | undefined {
110110
// 匹配npm包名的正则表达式,忽略路径部分
111111
const regex = /^(?:@[^/]+\/)?[^/]+/;
112112

113113
// 使用正则表达式匹配并提取包名
114114
const match = packageString.match(regex);
115115

116116
// 返回匹配到的包名,如果没有匹配到则返回原字符串
117-
return match ? match[0] : packageString;
117+
return match?.[0];
118118
}
119119

120120
function normalizeShareItem(
@@ -132,7 +132,9 @@ function normalizeShareItem(
132132
): ShareItem {
133133
let version: string | undefined;
134134
try {
135-
version = require(path.join(removePathFromNpmPackage(key), 'package.json')).version;
135+
const npmPackage = removePathFromNpmPackage(key);
136+
// TODO get current package version
137+
version = npmPackage ? require(path.join(npmPackage, 'package.json')).version : undefined;
136138
} catch (e) {
137139
console.log(e);
138140
}

0 commit comments

Comments
 (0)