更新依赖&版本号(2.12.3-beta.11)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
const { afterPack } = require('./deps')
|
||||
|
||||
const fs = require('fs').promises
|
||||
|
||||
// https://github.com/electron-userland/electron-builder/issues/4630
|
||||
// https://github.com/electron-userland/electron-builder/issues/4630#issuecomment-782020139
|
||||
|
||||
module.exports = async(context) => {
|
||||
await afterPack()
|
||||
const { electronPlatformName, appOutDir } = context
|
||||
if (electronPlatformName !== 'darwin') return
|
||||
const {
|
||||
|
||||
@@ -2,7 +2,8 @@ const fs = require('fs')
|
||||
const fsPromises = require('fs').promises
|
||||
const path = require('path')
|
||||
const { Arch } = require('electron-builder')
|
||||
const nodeAbi = require('node-abi')
|
||||
// const nodeAbi = require('node-abi')
|
||||
const { beforePack } = require('./deps')
|
||||
|
||||
const better_sqlite3_fileNameMap = {
|
||||
[Arch.x64]: 'linux-x64',
|
||||
@@ -16,7 +17,7 @@ const replaceSqliteLib = async(electronNodeAbi, arch) => {
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1102
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1161
|
||||
console.log('replace sqlite lib...')
|
||||
const filePath = path.join(__dirname, `./lib/better_sqlite3_electron-v${electronNodeAbi}-${better_sqlite3_fileNameMap[arch]}.node`)
|
||||
const filePath = path.join(__dirname, `./lib/better_sqlite3_${better_sqlite3_fileNameMap[arch]}.node`)
|
||||
console.log(filePath)
|
||||
const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
await fsPromises.unlink(targetPath).catch(_ => _)
|
||||
@@ -25,9 +26,10 @@ const replaceSqliteLib = async(electronNodeAbi, arch) => {
|
||||
|
||||
|
||||
module.exports = async(context) => {
|
||||
await beforePack()
|
||||
const { electronPlatformName, arch } = context
|
||||
const electronVersion = context.packager?.info?._framework?.version ?? require('../package.json').devDependencies.electron.replace(/^[^\d]*?(\d+)/, '$1')
|
||||
const electronNodeAbi = nodeAbi.getAbi(electronVersion, 'electron')
|
||||
// const electronVersion = context.packager?.info?._framework?.version ?? require('../package.json').devDependencies.electron.replace(/^[^\d]*?(\d+)/, '$1')
|
||||
// const electronNodeAbi = nodeAbi.getAbi(electronVersion, 'electron')
|
||||
if (electronPlatformName !== 'linux' || process.env.FORCE) return
|
||||
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
||||
const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
||||
@@ -39,7 +41,7 @@ module.exports = async(context) => {
|
||||
// console.log('rename binding file...')
|
||||
await fsPromises.rename(bindingFilePath, bindingBakFilePath)
|
||||
}
|
||||
await replaceSqliteLib(electronNodeAbi, arch)
|
||||
await replaceSqliteLib(arch)
|
||||
break
|
||||
|
||||
default:
|
||||
|
||||
@@ -6,20 +6,28 @@ const path = require('node:path')
|
||||
const rootPath = path.join(__dirname, '../')
|
||||
|
||||
const patchs = [
|
||||
// [
|
||||
// path.join(rootPath, './node_modules/ws/package.json'),
|
||||
// '\n "browser": "./browser.js",',
|
||||
// '',
|
||||
// ],
|
||||
// [
|
||||
// path.join(rootPath, './node_modules/music-metadata/package.json'),
|
||||
// '"default": "./lib/core.js"',
|
||||
// '"default": "./lib/index.js"',
|
||||
// ],
|
||||
// [
|
||||
// path.join(rootPath, './node_modules/strtok3/package.json'),
|
||||
// '"default": "./lib/core.js"',
|
||||
// '"default": "./lib/index.js"',
|
||||
// ],
|
||||
[
|
||||
path.join(rootPath, './node_modules/ws/package.json'),
|
||||
'\n "browser": "./browser.js",',
|
||||
'',
|
||||
],
|
||||
[
|
||||
path.join(rootPath, './node_modules/music-metadata/package.json'),
|
||||
'"default": "./lib/core.js"',
|
||||
'"default": "./lib/index.js"',
|
||||
],
|
||||
[
|
||||
path.join(rootPath, './node_modules/strtok3/package.json'),
|
||||
'"default": "./lib/core.js"',
|
||||
'"default": "./lib/index.js"',
|
||||
path.join(rootPath, './node_modules/better-sqlite3/package.json'),
|
||||
`{
|
||||
"build-release": "node-gyp clean && node-gyp rebuild --release --force_build=1",`,
|
||||
`{
|
||||
"install": "node -e \\"process.exit(require('fs').existsSync('build/Release/better_sqlite3.node') ? 0 : 1)\\" || node-gyp rebuild --release --force_build=1",
|
||||
"build-release": "node-gyp clean && node-gyp rebuild --release --force_build=1",`,
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
||||
// const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
||||
exports.beforePack = async() => {
|
||||
// if (!fs.existsSync(bindingFilePath)) return
|
||||
// fs.renameSync(bindingFilePath, bindingBakFilePath)
|
||||
try {
|
||||
fs.writeFileSync(
|
||||
bindingFilePath,
|
||||
fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 0,', '\'force_build%\': 1,'),
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
exports.afterPack = async() => {
|
||||
// if (fs.existsSync(bindingFilePath)) return
|
||||
// fs.renameSync(bindingBakFilePath, bindingFilePath)
|
||||
try {
|
||||
fs.writeFileSync(
|
||||
bindingFilePath,
|
||||
fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 1,', '\'force_build%\': 0,'),
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const replaceSqliteLib = async(arch) => {
|
||||
// console.log(await fs.readdir(path.join(context.appOutDir, './resources/')))
|
||||
// if (context.electronPlatformName != 'linux' || context.arch != Arch.arm64) return
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1102
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1161
|
||||
console.log('replace sqlite lib...')
|
||||
const filePath = path.join(__dirname, `./lib/better_sqlite3_${process.platform}-${arch}.node`)
|
||||
console.log(filePath)
|
||||
const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
await fs.promises.unlink(targetPath).catch(_ => _)
|
||||
await fs.promises.copyFile(filePath, targetPath)
|
||||
}
|
||||
exports.copyLib = async(arch = process.arch) => {
|
||||
if (process.platform === 'linux') {
|
||||
await replaceSqliteLib(arch)
|
||||
return
|
||||
}
|
||||
const libPath = path.join(__dirname, `../node_modules/better-sqlite3/prebuilds/${process.platform}-${arch}.node`)
|
||||
if (!fs.existsSync(libPath)) {
|
||||
console.error(`Better-sqlite3 prebuild not found for ${process.platform}-${arch}`)
|
||||
return
|
||||
}
|
||||
const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
await fs.promises.cp(libPath, targetPath, { recursive: true, force: true })
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const getGzipFiles = async() => {
|
||||
// for (const name of names) {
|
||||
// if (name.endsWith('.node')) await fs.promises.unlink(path.join(libDir, name))
|
||||
// }
|
||||
return names.filter(name => name.endsWith('.gz'))
|
||||
return names.filter((name) => name.endsWith('.gz'))
|
||||
}
|
||||
|
||||
const unzip = async(filePath) => {
|
||||
@@ -18,22 +18,20 @@ const unzip = async(filePath) => {
|
||||
await fs.promises.mkdir(targetDir)
|
||||
await tar.x({
|
||||
file: filePath,
|
||||
strip: 1,
|
||||
strip: 0,
|
||||
C: targetDir,
|
||||
})
|
||||
return targetDir
|
||||
}
|
||||
|
||||
const files = [
|
||||
'better_sqlite3',
|
||||
]
|
||||
const files = ['better_sqlite3']
|
||||
const moveFile = async(filePath) => {
|
||||
const name = 'electron-' + path.basename(filePath).split('-electron-')[1]
|
||||
const name = `${path.basename(filePath).split('_v')[0].replace('_', '-')}`
|
||||
for (const fileName of files) {
|
||||
if (fileName == 'better_sqlite3' && !name.includes('linux')) continue
|
||||
const targetPath = path.join(libDir, `${fileName}_${name}.node`)
|
||||
if (fs.existsSync(targetPath)) await fs.promises.unlink(targetPath)
|
||||
await fs.promises.rename(path.join(filePath, 'Release', fileName + '.node'), targetPath)
|
||||
await fs.promises.rename(path.join(filePath, `${fileName}.node`), targetPath)
|
||||
}
|
||||
await fs.promises.rm(filePath, { recursive: true })
|
||||
}
|
||||
@@ -49,4 +47,3 @@ const run = async() => {
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
const { copyLib } = require('./deps')
|
||||
|
||||
copyLib()
|
||||
Reference in New Issue
Block a user