Skip to content

Commit

Permalink
fix: remove function removePathFromNpmPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
f4562 committed Dec 13, 2024
1 parent d975fd3 commit 273cf70
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/utils/normalizeModuleFederationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ export interface ShareItem {
shareConfig: SharedConfig;
}

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

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

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

function findPackageJson(moduleName: string) {
const mainFilePath = require.resolve(moduleName);

Expand Down Expand Up @@ -151,7 +140,7 @@ function normalizeShareItem(
): ShareItem {
let version: string | undefined;
try {
version = findPackageJson(removePathFromNpmPackage(key)).version;
version = findPackageJson(key).version;
} catch (e) {
console.log(e);
}
Expand Down Expand Up @@ -332,9 +321,7 @@ export function getNormalizeModuleFederationOptions() {

export function getNormalizeShareItem(key: string) {
const options = getNormalizeModuleFederationOptions();
const shareItem =
options.shared[removePathFromNpmPackage(key)] ||
options.shared[removePathFromNpmPackage(key) + '/'];
const shareItem = options.shared[key] || options.shared[key + '/'];
return shareItem;
}

Expand Down

0 comments on commit 273cf70

Please sign in to comment.