Skip to content

Commit b88f12d

Browse files
authored
Merge pull request #850 from apoint123/build/optimize-native-build
🔧 build: 优化原生模块构建
2 parents c5f9383 + 1d292ba commit b88f12d

10 files changed

Lines changed: 51 additions & 34 deletions

File tree

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ pnpm-lock.yaml
44
LICENSE.md
55
auto-imports.d.ts
66
components.d.ts
7+
native/**/index.d.ts
78
# tsconfig.json
89
# tsconfig.*.json
10+
auto-eslint.mjs

eslint.config.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
2-
import { fileURLToPath } from "node:url";
31
import { FlatCompat } from "@eslint/eslintrc";
4-
import vue from "eslint-plugin-vue";
52
import js from "@eslint/js";
3+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
4+
import vue from "eslint-plugin-vue";
65
import globals from "globals";
76
import path from "node:path";
7+
import { fileURLToPath } from "node:url";
88
import autoEslint from "./auto-eslint.mjs";
99

1010
const __filename = fileURLToPath(import.meta.url);
@@ -25,6 +25,7 @@ export default [
2525
"**/docs",
2626
"**/auto-imports.d.ts",
2727
"**/components.d.ts",
28+
"native/**/index.d.ts",
2829
],
2930
},
3031
...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"),

native/external-media-integration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"scripts": {
1212
"build": "napi build --release --no-const-enum",
13-
"build:debug": "napi build"
13+
"build:debug": "napi build --no-const-enum"
1414
}
1515
}

native/ferrous-opencc-wasm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"build": "wasm-pack build --target web"
6+
"build": "wasm-pack build --target web",
7+
"build:debug": "wasm-pack build --target web --dev"
78
},
89
"devDependencies": {
910
"wasm-pack": "^0.13.1"

native/taskbar-lyric/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"binaryName": "taskbar-lyric"
77
},
88
"scripts": {
9-
"build": "napi build --release --no-const-enum"
9+
"build": "napi build --release --no-const-enum",
10+
"build:debug": "napi build --no-const-enum"
1011
},
1112
"devDependencies": {
1213
"@napi-rs/cli": "^3.5.1"

native/tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"binaryName": "tools"
77
},
88
"scripts": {
9-
"build": "napi build --release --no-const-enum"
9+
"build": "napi build --release --no-const-enum",
10+
"build:debug": "napi build --no-const-enum"
1011
},
1112
"devDependencies": {
1213
"@napi-rs/cli": "^3"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"typecheck": "pnpm typecheck:node && pnpm typecheck:web",
2626
"build:native": "tsx scripts/build-native.ts",
2727
"start": "electron-vite preview",
28-
"dev": "pnpm build:native && tsx scripts/dev.ts",
28+
"dev": "pnpm build:native -- --dev && tsx scripts/dev.ts",
2929
"build": "rimraf dist && pnpm build:native && pnpm typecheck && electron-vite build",
3030
"postinstall": "electron-builder install-app-deps",
3131
"build:web": "pnpm build",

scripts/build-native.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import dotenv from "dotenv";
12
import { execSync } from "node:child_process";
23
import os from "node:os";
3-
import process from "node:process";
4-
import dotenv from "dotenv";
54
import path from "node:path";
5+
import process from "node:process";
6+
7+
interface NativeModule {
8+
name: string;
9+
enabled?: boolean;
10+
}
611

712
const isRustAvailable = () => {
813
try {
@@ -32,35 +37,37 @@ if (!isRustAvailable()) {
3237
process.exit(1);
3338
}
3439

35-
console.log(`[BuildNative] 当前构建目标: ${process.platform}`);
40+
const modules: NativeModule[] = [
41+
{
42+
name: "external-media-integration",
43+
},
44+
{
45+
name: "tools",
46+
},
47+
{
48+
name: "taskbar-lyric",
49+
enabled: isWindows,
50+
},
51+
// 有人抱怨编译 wasm 总是有问题,暂时注释掉
52+
// {
53+
// name: "ferrous-opencc-wasm",
54+
// },
55+
];
3656

3757
try {
38-
console.log("[BuildNative] 开始构建原生模块...");
39-
40-
execSync("pnpm --filter external-media-integration build", {
41-
stdio: "inherit",
42-
});
43-
44-
console.log("[BuildNative] 构建 tools 原生模块...");
45-
execSync("pnpm --filter tools build", {
46-
stdio: "inherit",
47-
});
58+
const args = process.argv.slice(2);
59+
const isDev = args.includes("--dev");
60+
const buildCommand = isDev ? "build:debug" : "build";
4861

49-
if (isWindows) {
50-
console.log("[BuildNative] 构建任务栏歌词原生模块...");
51-
execSync("pnpm --filter taskbar-lyric build", {
62+
for (const mod of modules) {
63+
if (mod.enabled === false) {
64+
continue;
65+
}
66+
execSync(`pnpm --filter ${mod.name} ${buildCommand}`, {
5267
stdio: "inherit",
5368
});
5469
}
55-
56-
// 有人抱怨编译 wasm 总是有问题,暂时注释掉
57-
// console.log("[BuildNative] 构建 ferrous-opencc-wasm...");
58-
// execSync("pnpm --filter ferrous-opencc-wasm build", {
59-
// stdio: "inherit",
60-
// });
6170
} catch (error) {
6271
console.error("[BuildNative] 模块构建失败", error);
6372
process.exit(1);
6473
}
65-
66-
console.log("[BuildNative] 原生模块构建完成");

src/components/Setting/MainSetting.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@
6969
class="set-content"
7070
:content-style="{ overflow: 'hidden', padding: '40px 0' }"
7171
>
72-
<Transition name="fade" mode="out-in" :duration="70" @after-leave="setScrollbar?.scrollTo({ top: 0 })">
72+
<Transition
73+
name="fade"
74+
mode="out-in"
75+
:duration="70"
76+
@after-leave="setScrollbar?.scrollTo({ top: 0 })"
77+
>
7378
<!-- 常规 -->
7479
<UniversalSetting
7580
v-if="activeKey === 'general'"

src/utils/lyric/qrc-parser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const domParser: QRCParserFn = (xmlStr) => {
1111
try {
1212
const parser = new DOMParser();
1313
const doc = parser.parseFromString(xmlStr, "text/xml");
14-
1514
// 检查解析错误(如未转义的 & 等)
1615
const parseError = doc.querySelector("parsererror");
1716
if (parseError) {

0 commit comments

Comments
 (0)