From d1a090bb6bca8c1e02e2826e9580d87b0ffdc9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= <969409112@qq.com> Date: Mon, 10 Aug 2026 23:18:18 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9windows=E6=89=93?= =?UTF-8?q?=E5=8C=85=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/after-pack.cjs | 4 +++- tests/unit/runtime-packaging.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/after-pack.cjs b/scripts/after-pack.cjs index a804e97..eadebab 100644 --- a/scripts/after-pack.cjs +++ b/scripts/after-pack.cjs @@ -88,7 +88,9 @@ function validateAsarRuntimeDependencies(runtimeResources) { const asarPath = path.join(runtimeResources, 'app.asar') if (!existsSync(asarPath)) throw new Error(`Missing packaged application archive: ${asarPath}`) - const entries = new Set(asar.listPackage(asarPath)) + // @electron/asar returns platform-native separators. Normalize to POSIX + // paths so validation behaves consistently on Windows and macOS/Linux. + const entries = new Set(asar.listPackage(asarPath).map((entry) => entry.replaceAll('\\', '/'))) const missingPackages = REQUIRED_RUNTIME_PACKAGES.filter( (packageName) => !entries.has(`/node_modules/${packageName}/package.json`) ) diff --git a/tests/unit/runtime-packaging.test.ts b/tests/unit/runtime-packaging.test.ts index 43de4c5..2768da1 100644 --- a/tests/unit/runtime-packaging.test.ts +++ b/tests/unit/runtime-packaging.test.ts @@ -71,6 +71,30 @@ describe('production runtime packaging', () => { ) }) + it('accepts runtime dependencies when asar uses Windows path separators', async () => { + const resources = join(root, 'asar-complete-resources') + const source = join(root, 'asar-complete-source') + const packages = [ + '@electron-toolkit/preload', + '@electron-toolkit/utils', + 'archiver', + 'electron-updater', + 'ffmpeg-static', + 'fs-extra', + 'jsonrepair', + 'koffi' + ] + for (const packageName of packages) { + const packagePath = join(source, 'node_modules', ...packageName.split('/')) + mkdirSync(packagePath, { recursive: true }) + writeFileSync(join(packagePath, 'package.json'), '{}') + } + mkdirSync(resources, { recursive: true }) + await asar.createPackage(source, join(resources, 'app.asar')) + + expect(() => validateAsarRuntimeDependencies(resources)).not.toThrow() + }) + it('requires and unpacks the bundled ffmpeg-static executable', () => { const resources = join(root, 'ffmpeg-resources') const ffmpegPath = join(