Skip to content

Commit

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

function cleanShareItem(key: string) {
return key.replace(/^\//, '').replace(/\/$/, '');
}

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

Expand Down Expand Up @@ -139,14 +143,15 @@ function normalizeShareItem(
}
): ShareItem {
let version: string | undefined;
const shareName = cleanShareItem(key);
try {
version = findPackageJson(key).version;
version = findPackageJson(shareName).version;
} catch (e) {
console.log(e);
}
if (typeof shareItem === 'string') {
return {
name: shareItem,
name: shareName,
version,
scope: 'default',
from: '',
Expand All @@ -157,7 +162,7 @@ function normalizeShareItem(
};
}
return {
name: key,
name: shareName,
from: '',
version: shareItem.version || version,
scope: shareItem.shareScope || 'default',
Expand Down Expand Up @@ -321,7 +326,7 @@ export function getNormalizeModuleFederationOptions() {

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

Expand Down

0 comments on commit fed459d

Please sign in to comment.