mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
feat: enhance package management for image processing libraries (#9721)
- Added support for downloading and retaining architecture-specific versions of the `@img/sharp` and `@img/sharp-libvips` packages for macOS, Linux, and Windows platforms. - Removed the deprecated function for deleting macOS-only packages, streamlining the package management process. - Updated the `after-pack.js` and `build-npm.js` scripts to ensure proper handling of image processing dependencies across different architectures.
This commit is contained in:
parent
54a92bf2c6
commit
03ebc4a794
@ -17,6 +17,14 @@ exports.default = async function (context) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
keepPackageNodeFiles(node_modules_path, '@libsql', arch === Arch.arm64 ? ['darwin-arm64'] : ['darwin-x64'])
|
keepPackageNodeFiles(node_modules_path, '@libsql', arch === Arch.arm64 ? ['darwin-arm64'] : ['darwin-x64'])
|
||||||
|
|
||||||
|
keepPackageNodeFiles(
|
||||||
|
node_modules_path,
|
||||||
|
'@img',
|
||||||
|
arch === Arch.arm64
|
||||||
|
? ['sharp-darwin-arm64', 'sharp-libvips-darwin-arm64']
|
||||||
|
: ['sharp-darwin-x64', 'sharp-libvips-darwin-x64']
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform === 'linux') {
|
if (platform === 'linux') {
|
||||||
@ -24,8 +32,13 @@ exports.default = async function (context) {
|
|||||||
const _arch = arch === Arch.arm64 ? ['linux-arm64-gnu', 'linux-arm64-musl'] : ['linux-x64-gnu', 'linux-x64-musl']
|
const _arch = arch === Arch.arm64 ? ['linux-arm64-gnu', 'linux-arm64-musl'] : ['linux-x64-gnu', 'linux-x64-musl']
|
||||||
keepPackageNodeFiles(node_modules_path, '@libsql', _arch)
|
keepPackageNodeFiles(node_modules_path, '@libsql', _arch)
|
||||||
|
|
||||||
// 删除 macOS 专用的 OCR 包
|
keepPackageNodeFiles(
|
||||||
removeMacOnlyPackages(node_modules_path)
|
node_modules_path,
|
||||||
|
'@img',
|
||||||
|
arch === Arch.arm64
|
||||||
|
? ['sharp-libvips-linux-arm64', 'sharp-linux-arm64']
|
||||||
|
: ['sharp-libvips-linux-x64', 'sharp-linux-x64']
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform === 'windows') {
|
if (platform === 'windows') {
|
||||||
@ -39,7 +52,13 @@ exports.default = async function (context) {
|
|||||||
keepPackageNodeFiles(node_modules_path, '@libsql', ['win32-x64-msvc'])
|
keepPackageNodeFiles(node_modules_path, '@libsql', ['win32-x64-msvc'])
|
||||||
}
|
}
|
||||||
|
|
||||||
removeMacOnlyPackages(node_modules_path)
|
keepPackageNodeFiles(
|
||||||
|
node_modules_path,
|
||||||
|
'@img',
|
||||||
|
arch === Arch.arm64
|
||||||
|
? ['sharp-win32-arm64', 'sharp-libvips-win32-arm64']
|
||||||
|
: ['sharp-win32-x64', 'sharp-libvips-win32-x64']
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform === 'windows') {
|
if (platform === 'windows') {
|
||||||
@ -48,22 +67,6 @@ exports.default = async function (context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除 macOS 专用的包
|
|
||||||
* @param {string} nodeModulesPath
|
|
||||||
*/
|
|
||||||
function removeMacOnlyPackages(nodeModulesPath) {
|
|
||||||
const macOnlyPackages = []
|
|
||||||
|
|
||||||
macOnlyPackages.forEach((packageName) => {
|
|
||||||
const packagePath = path.join(nodeModulesPath, packageName)
|
|
||||||
if (fs.existsSync(packagePath)) {
|
|
||||||
fs.rmSync(packagePath, { recursive: true, force: true })
|
|
||||||
console.log(`[After Pack] Removed macOS-only package: ${packageName}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用指定架构的 node_modules 文件
|
* 使用指定架构的 node_modules 文件
|
||||||
* @param {*} nodeModulesPath
|
* @param {*} nodeModulesPath
|
||||||
|
|||||||
@ -7,6 +7,24 @@ async function downloadNpm(platform) {
|
|||||||
'https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.7.tgz'
|
'https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.4.7.tgz'
|
||||||
)
|
)
|
||||||
downloadNpmPackage('@libsql/darwin-x64', 'https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.7.tgz')
|
downloadNpmPackage('@libsql/darwin-x64', 'https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.4.7.tgz')
|
||||||
|
|
||||||
|
// sharp for macOS
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-darwin-arm64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.3.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-darwin-x64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.3.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-darwin-arm64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.2.0.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-darwin-x64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.0.tgz'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!platform || platform === 'linux') {
|
if (!platform || platform === 'linux') {
|
||||||
@ -26,6 +44,23 @@ async function downloadNpm(platform) {
|
|||||||
'@libsql/linux-x64-musl',
|
'@libsql/linux-x64-musl',
|
||||||
'https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.7.tgz'
|
'https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.4.7.tgz'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-linux-arm64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.2.0.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-linux-x64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.2.0.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-linuxmusl-arm64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.2.0.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-libvips-linuxmusl-x64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.2.0.tgz'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!platform || platform === 'windows') {
|
if (!platform || platform === 'windows') {
|
||||||
@ -37,6 +72,15 @@ async function downloadNpm(platform) {
|
|||||||
'@strongtz/win32-arm64-msvc',
|
'@strongtz/win32-arm64-msvc',
|
||||||
'https://registry.npmjs.org/@strongtz/win32-arm64-msvc/-/win32-arm64-msvc-0.4.7.tgz'
|
'https://registry.npmjs.org/@strongtz/win32-arm64-msvc/-/win32-arm64-msvc-0.4.7.tgz'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-win32-arm64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.3.tgz'
|
||||||
|
)
|
||||||
|
downloadNpmPackage(
|
||||||
|
'@img/sharp-win32-x64',
|
||||||
|
'https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.3.tgz'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user