From dd3e00fad551b0163ad4c34b233888af7e2be12c Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 14 Aug 2025 10:01:35 +0800 Subject: [PATCH] :wrench: Package management optimization --- .npmignore | 54 +++++++++++++++++++++++++++++++++++++ bin/builders/BaseBuilder.ts | 9 +++++-- bin/cli.ts | 5 +++- bin/options/index.ts | 2 -- dist/cli.js | 7 +++-- src-tauri/src/app/window.rs | 6 ++--- 6 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..cdabda8 --- /dev/null +++ b/.npmignore @@ -0,0 +1,54 @@ +# Development files +pnpm-lock.yaml +package-lock.json +yarn.lock + +# Development directories +node_modules/ +.vscode/ +.idea/ + +# Build artifacts +dist-ssr/ +*.local + +# Development configs +.env +.env.local +.env.development +.env.test +.env.production + +# Logs +logs/ +*.log +npm-debug.log* +yarn-debug.log* +pnpm-debug.log* + +# OS files +.DS_Store +Thumbs.db + +# Testing +coverage/ +.nyc_output/ + +# Documentation source +docs/ +*.md +!README.md + +# Development scripts +script/ +rollup.config.js +tsconfig.json +.prettierrc* +.eslintrc* + +# Tauri development files +src-tauri/target/ +src-tauri/.cargo/config.toml +src-tauri/.pake/ +src-tauri/gen/ +output/ diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts index a6a1666..e6899db 100644 --- a/bin/builders/BaseBuilder.ts +++ b/bin/builders/BaseBuilder.ts @@ -52,15 +52,19 @@ export default abstract class BaseBuilder { const projectConf = path.join(rustProjectDir, 'config.toml'); await fsExtra.ensureDir(rustProjectDir); + // For global CLI installation, always use npm + const packageManager = 'npm'; + const registryOption = isChina ? ' --registry=https://registry.npmmirror.com' : ''; + if (isChina) { logger.info('✺ Located in China, using npm/rsProxy CN mirror.'); const projectCnConf = path.join(tauriSrcPath, 'rust_proxy.toml'); await fsExtra.copy(projectCnConf, projectConf); await shellExec( - `cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com`, + `cd "${npmDirectory}" && ${packageManager} install${registryOption}`, ); } else { - await shellExec(`cd "${npmDirectory}" && npm install`); + await shellExec(`cd "${npmDirectory}" && ${packageManager} install`); } spinner.succeed(chalk.green('Package installed!')); if (!tauriTargetPathExists) { @@ -126,4 +130,5 @@ export default abstract class BaseBuilder { `${fileName}.${fileType}`, ); } + } diff --git a/bin/cli.ts b/bin/cli.ts index 555f208..db501be 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -68,7 +68,10 @@ program ) .option('--debug', 'Debug build and more output', DEFAULT.debug) .addOption( - new Option('--proxy-url ', 'Proxy URL for all network requests (http://, https://, socks5://)') + new Option( + '--proxy-url ', + 'Proxy URL for all network requests (http://, https://, socks5://)', + ) .default(DEFAULT_PAKE_OPTIONS.proxyUrl) .hideHelp(), ) diff --git a/bin/options/index.ts b/bin/options/index.ts index 1beb863..564ac0c 100644 --- a/bin/options/index.ts +++ b/bin/options/index.ts @@ -20,7 +20,6 @@ function isValidName(name: string, platform: NodeJS.Platform): boolean { return !!name && reg.test(name); } - export default async function handleOptions( options: PakeCliOptions, url: string, @@ -57,7 +56,6 @@ export default async function handleOptions( } } - const appOptions: PakeAppOptions = { ...options, name, diff --git a/dist/cli.js b/dist/cli.js index d32429c..ade099f 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -645,14 +645,17 @@ class BaseBuilder { const rustProjectDir = path.join(tauriSrcPath, '.cargo'); const projectConf = path.join(rustProjectDir, 'config.toml'); await fsExtra.ensureDir(rustProjectDir); + // For global CLI installation, always use npm + const packageManager = 'npm'; + const registryOption = isChina ? ' --registry=https://registry.npmmirror.com' : ''; if (isChina) { logger.info('✺ Located in China, using npm/rsProxy CN mirror.'); const projectCnConf = path.join(tauriSrcPath, 'rust_proxy.toml'); await fsExtra.copy(projectCnConf, projectConf); - await shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com`); + await shellExec(`cd "${npmDirectory}" && ${packageManager} install${registryOption}`); } else { - await shellExec(`cd "${npmDirectory}" && npm install`); + await shellExec(`cd "${npmDirectory}" && ${packageManager} install`); } spinner.succeed(chalk.green('Package installed!')); if (!tauriTargetPathExists) { diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 5302e1b..be5f686 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -74,7 +74,7 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) -> window_builder = window_builder .data_directory(_data_dir) .title(app.package_info().name.clone()); - + // Set theme to None for automatic system theme detection on Windows // This allows the window to respond to system theme changes automatically window_builder = window_builder.theme(None); @@ -85,8 +85,8 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) -> window_builder = window_builder .data_directory(_data_dir) .title(app.package_info().name.clone()); - - // Set theme to None for automatic system theme detection on Linux + + // Set theme to None for automatic system theme detection on Linux // This allows the window to respond to system theme changes automatically window_builder = window_builder.theme(None); }