Skip to content

Commit

Permalink
fix: file Extension util (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Nov 27, 2024
1 parent d4b5fce commit d8f958a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/utils/src/common/graph/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function formatAssetName(assetName: string, fileConfig?: string) {
}

export function isAssetMatchExtension(asset: SDK.AssetData, ext: string) {
return asset.path.slice(-ext.length) === ext;
return asset.path.slice(-ext.length) === ext || extname(asset.path) === ext;
}

export function isAssetMatchExtensions(asset: SDK.AssetData, exts: string[]) {
Expand Down Expand Up @@ -228,14 +228,14 @@ export function diffSize(bSize: number, cSize: number) {
const percent = isEqual
? 0
: bSize === 0
? 100
: (Math.abs(cSize - bSize) / bSize) * 100;
? 100
: (Math.abs(cSize - bSize) / bSize) * 100;

const state: Client.RsdoctorClientDiffState = isEqual
? Client.RsdoctorClientDiffState.Equal
: bSize > cSize
? Client.RsdoctorClientDiffState.Down
: Client.RsdoctorClientDiffState.Up;
? Client.RsdoctorClientDiffState.Down
: Client.RsdoctorClientDiffState.Up;

return { percent, state };
}
Expand Down Expand Up @@ -380,3 +380,11 @@ export function getAssetDetails(
modules: getModulesByAsset(asset, chunks, modules),
};
}

export function extname(filename: string) {
// 移除查询参数部分
const baseName = filename.split('?')[0];
// 使用正则表达式匹配扩展名
const matches = baseName.match(/\.([0-9a-z]+)(?:[\?#]|$)/i);
return matches ? `.${matches[1]}` : '';
}

0 comments on commit d8f958a

Please sign in to comment.