chore: 修改打包配置

This commit is contained in:
Wxw-Gu committed 2026-11-09 16:34:20 +08:00
1 parent f47af8024f
commit 6cadcb9a5a
7 files changed
+136 -47

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "tracememo",
"version": "2.5.2",
"version": "2.6.0",
"packageManager": "pnpm@7.33.7",
"description": "TraceMemo(迹忆)是一款本地优先、可追溯的 AI 微信知识与分析工作台。 原名 WechatExplorer,支持聊天记录搜索、知识库、微信群聊总结和 Agent 助手。",
"keywords": [
+14
View File
@@ -186,7 +186,21 @@ function validateMacEditionResources(runtimeResources, edition, platform) {
throw new Error(`Missing FFmpeg license/build notice: ${relative}`)
}
}
const ffmpegLicenseHashes = marker.ffmpegLicenseSha256
if (!ffmpegLicenseHashes || typeof ffmpegLicenseHashes !== 'object') {
throw new Error('Mac build marker is missing FFmpeg license/source notice hashes')
}
for (const [relative, expected] of Object.entries(ffmpegLicenseHashes)) {
const notice = path.join(resources, relative)
if (!/^[a-f0-9]{64}$/.test(expected) || !existsSync(notice) ||
createHash('sha256').update(readFileSync(notice)).digest('hex') !== expected) {
throw new Error(`Packaged FFmpeg license/source notice hash mismatch: ${relative}`)
}
}
if (edition === 'native') {
if (!readFileSync(host).includes(Buffer.from('/license/status'))) {
throw new Error('Native Host does not implement GET /license/status')
}
for (const binary of [helper, host, runtimeDylib]) {
if (!readBinaryArchitectures(binary).includes('arm64')) {
throw new Error(`Native binary lacks arm64 architecture: ${binary}`)
+15 -11
View File
@@ -1,13 +1,15 @@
const fs = require('node:fs')
const path = require('node:path')
const { spawnSync } = require('node:child_process')
const { assertStagingTargetDoesNotExist, prepareEdition, validateStagedEdition } = require('./prepare-macos-edition.cjs')
const {
assertStagingTargetDoesNotExist,
prepareEdition,
resolveEditionRoots,
validateStagedEdition
} = require('./prepare-macos-edition.cjs')
const ROOT = path.resolve(__dirname, '..')
const STAGE_ROOT = path.join(ROOT, 'build', 'mac-staging')
const OUTPUT_ROOT = path.join(ROOT, 'dist', 'mac')
const EDITIONS = ['public', 'native']
const CONFIG_ROOT = path.join(STAGE_ROOT, 'configs')
const YAML = require('yaml')
function run(args, env) {
@@ -82,7 +84,7 @@ function createBuilderConfig({ edition, stageRoot, buildOutput, outputRoot, appV
artifactName:
edition === 'native'
? `TraceMemo-${appVersion}-mac-arm64-native.dmg`
: `TraceMemo-${appVersion}-mac-arm64-public.dmg`
: `TraceMemo-${appVersion}-mac-arm64-oss.dmg`
},
npmRebuild: false
}
@@ -90,20 +92,22 @@ function createBuilderConfig({ edition, stageRoot, buildOutput, outputRoot, appV
function buildEdition(edition, options = {}) {
if (!EDITIONS.includes(edition)) throw new Error('Usage: build-macos-edition.cjs <public|native>')
const stageRoot = path.join(STAGE_ROOT, edition)
const outputRoot = path.join(OUTPUT_ROOT, edition)
const roots = resolveEditionRoots()
const stageRoot = path.join(roots.stageRoot, edition)
const outputRoot = path.join(roots.outputRoot, edition)
const configRoot = path.join(roots.stageRoot, 'configs')
if (fs.existsSync(stageRoot) && !options.reuseStaging) {
throw new Error(`Refusing to overwrite existing build staging: ${stageRoot}`)
}
if (fs.existsSync(outputRoot)) throw new Error(`Refusing to overwrite existing build output: ${outputRoot}`)
if (fs.existsSync(CONFIG_ROOT)) throw new Error(`Refusing to overwrite existing build config directory: ${CONFIG_ROOT}`)
if (fs.existsSync(configRoot)) throw new Error(`Refusing to overwrite existing build config directory: ${configRoot}`)
const preparation = fs.existsSync(stageRoot)
? Promise.resolve(validateStagedEdition(edition))
: prepareEdition(edition)
if (!preparation || typeof preparation.then !== 'function') throw new Error('Edition staging preparation did not return a Promise')
return preparation.then(() => {
const buildOutput = path.join(stageRoot, 'out')
const configPath = path.join(CONFIG_ROOT, `electron-builder-${edition}.yml`)
const configPath = path.join(configRoot, `electron-builder-${edition}.yml`)
let ownsConfigRoot = false
let buildSucceeded = false
try {
@@ -125,7 +129,7 @@ function buildEdition(edition, options = {}) {
],
env
)
fs.mkdirSync(CONFIG_ROOT)
fs.mkdirSync(configRoot, { recursive: true })
ownsConfigRoot = true
const config = createBuilderConfig({
edition,
@@ -147,7 +151,7 @@ function buildEdition(edition, options = {}) {
)
buildSucceeded = true
} finally {
if (ownsConfigRoot) fs.rmSync(CONFIG_ROOT, { recursive: true, force: true })
if (ownsConfigRoot) fs.rmSync(configRoot, { recursive: true, force: true })
if (!buildSucceeded && fs.existsSync(outputRoot)) {
fs.rmSync(outputRoot, { recursive: true, force: true })
}
+44 -7
View File
@@ -8,6 +8,12 @@ const { pipeline } = require('node:stream/promises')
const { readBinaryArchitectures } = require('./binary-arch.cjs')
const ROOT = path.resolve(__dirname, '..')
function resolveEditionRoots(projectRoot = ROOT, env = process.env) {
return {
stageRoot: path.resolve(env.TRACEMEMO_MAC_STAGE_ROOT || path.join(projectRoot, 'build', 'mac-staging')),
outputRoot: path.resolve(env.TRACEMEMO_MAC_OUTPUT_ROOT || path.join(projectRoot, 'dist', 'mac'))
}
}
const WCDB_DIST_ROOT = resolveWcdbDistRoot()
const NATIVE_DIST_ROOT =
process.env.TRACEMEMO_NATIVE_DIST_ROOT || path.resolve(ROOT, '..', 'native-runtime-dist')
@@ -121,6 +127,12 @@ function assertArm64(filePath, label) {
}
}
function validateLicenseStatusRoute(hostPath) {
if (!fs.readFileSync(hostPath).includes(Buffer.from('/license/status'))) {
throw new Error(`Native Host does not implement GET /license/status: ${hostPath}`)
}
}
function validateWcdbPair(apiPath, dependencyPath, profile) {
if (!fs.existsSync(apiPath) || !fs.existsSync(dependencyPath)) {
throw new Error(`Missing ${profile} WCDB library pair: ${apiPath}`)
@@ -227,6 +239,7 @@ function validateNativeBundle(bundleRoot, files) {
const runtimeDylib = bySuffix('/runtime/libtmwechat.dylib')
const runtimeManifestPath = bySuffix('/runtime/runtime-manifest.json')
const licenseDylib = bySuffix('/runtime/libtmlicense.dylib')
validateLicenseStatusRoute(host)
validateWcdbPair(api, companion, 'native')
for (const [binary, label] of [
[helper, 'WCDB helper'],
@@ -312,9 +325,17 @@ function copyPublicResources(sourceResources, destination) {
}
function copyFfmpegLicenses(destination) {
const packageRoot = path.dirname(require.resolve('ffmpeg-static/package.json'))
for (const [sourceName, destinationRelative] of FFMPEG_LICENSE_FILES) {
const source = path.join(packageRoot, sourceName)
const suppliedLicenseRoot = String(process.env.TRACEMEMO_FFMPEG_LICENSE_DIR || '').trim()
const packageRoot = suppliedLicenseRoot || path.dirname(require.resolve('ffmpeg-static/package.json'))
const files = suppliedLicenseRoot
? [
['LICENSE', 'LICENSE', 'licenses/ffmpeg-static/LICENSE'],
['FFMPEG-LICENSE.txt', 'FFMPEG-LICENSE.txt', 'licenses/ffmpeg-static/FFMPEG-LICENSE.txt'],
['FFMPEG-BUILD-INFO.txt', 'FFMPEG-BUILD-INFO.txt', 'licenses/ffmpeg-static/FFMPEG-BUILD-INFO.txt']
]
: FFMPEG_LICENSE_FILES.map(([source, relative]) => [source, source, relative])
for (const [sourceName, inputName, destinationRelative] of files) {
const source = path.join(packageRoot, inputName)
if (!fs.existsSync(source)) throw new Error(`Missing FFmpeg license/source notice: ${source}`)
const target = path.join(destination, destinationRelative)
fs.mkdirSync(path.dirname(target), { recursive: true })
@@ -389,8 +410,9 @@ function assertNoProtectedInputs(root) {
async function prepareEdition(edition) {
if (edition !== 'public' && edition !== 'native')
throw new Error('Usage: prepare-macos-edition.cjs <public|native>')
const stageRoot = path.join(ROOT, 'build', 'mac-staging', edition)
const outputRoot = path.join(ROOT, 'dist', 'mac', edition)
const roots = resolveEditionRoots()
const stageRoot = path.join(roots.stageRoot, edition)
const outputRoot = path.join(roots.outputRoot, edition)
assertStagingTargetDoesNotExist(stageRoot, outputRoot)
const sourceResources = path.join(ROOT, 'resources')
@@ -407,7 +429,13 @@ async function prepareEdition(edition) {
const marker = {
profile: edition,
appVersion: require(path.join(ROOT, 'package.json')).version,
ffmpegSha256
ffmpegSha256,
ffmpegLicenseSource: process.env.TRACEMEMO_FFMPEG_LICENSE_DIR
? 'provided verified license files'
: 'ffmpeg-static package',
ffmpegLicenseSha256: Object.fromEntries(
FFMPEG_LICENSE_FILES.map(([, relative]) => [relative, sha256(path.join(stagedResources, relative))])
)
}
if (edition === 'public') {
const api = path.join(WCDB_DIST_ROOT, 'libwcdb_api.dylib')
@@ -470,7 +498,7 @@ async function prepareEdition(edition) {
function validateStagedEdition(edition) {
if (edition !== 'public' && edition !== 'native')
throw new Error('Usage: validate staged edition <public|native>')
const resources = path.join(ROOT, 'build', 'mac-staging', edition, 'resources')
const resources = path.join(resolveEditionRoots().stageRoot, edition, 'resources')
const markerPath = path.join(resources, 'tracememo-build.json')
if (!fs.existsSync(markerPath)) throw new Error(`Missing staged edition marker: ${markerPath}`)
const marker = JSON.parse(fs.readFileSync(markerPath, 'utf8'))
@@ -487,6 +515,13 @@ function validateStagedEdition(edition) {
throw new Error('Staged FFmpeg SHA-256 does not match the edition marker')
}
assertArm64(ffmpeg, 'Staged FFmpeg')
for (const [, relative] of FFMPEG_LICENSE_FILES) {
const licensePath = path.join(resources, relative)
const expected = marker.ffmpegLicenseSha256?.[relative]
if (!fs.existsSync(licensePath) || !/^[a-f0-9]{64}$/.test(expected || '') || sha256(licensePath) !== expected) {
throw new Error(`Staged FFmpeg license/source notice hash mismatch: ${relative}`)
}
}
const api = path.join(resources, 'wcdb', 'macos', 'arm64', 'libwcdb_api.dylib')
const companion = path.join(resources, 'wcdb', 'macos', 'arm64', 'libWCDB.dylib')
validateWcdbPair(api, companion, edition)
@@ -608,6 +643,8 @@ if (require.main === module) {
}
module.exports = {
resolveEditionRoots,
validateLicenseStatusRoute,
assertNoProtectedInputs,
assertStagingTargetDoesNotExist,
copyPublicResources,
@@ -166,7 +166,7 @@ function summarizeDeviceId(deviceId: string): string {
}
/** 展示当前设备的授权状态,并提供刷新与复制设备 ID 的操作。 */
export function MacProLicenseCard({
export function MacNativeLicenseCard({
onNotice,
onStatusChange
}: {
@@ -231,16 +231,16 @@ export function MacProLicenseCard({
}
return (
<section className="settings-card mac-pro-license-card" aria-label="发送能力授权">
<header className="mac-pro-license-header">
<section className="settings-card mac-native-license-card" aria-label="发送能力授权">
<header className="mac-native-license-header">
<strong>发送能力授权</strong>
<span className={`mac-pro-license-status ${macLicenseStatusTone(license)}`}>
<span className={`mac-native-license-status ${macLicenseStatusTone(license)}`}>
{macLicenseStatusLabel(license)}
</span>
</header>
<div className="mac-pro-device-row">
<div className="mac-pro-device-value">
<div className="mac-native-device-row">
<div className="mac-native-device-value">
<span>本机设备 ID</span>
<code title={license.deviceId || undefined}>
{license.deviceId ? summarizeDeviceId(license.deviceId) : '(尚未生成)'}
@@ -257,16 +257,16 @@ export function MacProLicenseCard({
</Button>
</div>
{license.deviceId && (!license.authorized || licenseStateConflictsWithExpiry(license)) ? (
<p className="mac-pro-license-hint">{macLicenseStatusHint(license)}</p>
<p className="mac-native-license-hint">{macLicenseStatusHint(license)}</p>
) : null}
{license.authorized && license.features.length > 0 ? (
<div className="mac-pro-license-features" aria-label="已开通功能">
<div className="mac-native-license-features" aria-label="已开通功能">
{license.features.map((feature) => (
<span key={feature}>{macLicenseFeatureLabel[feature] || feature}</span>
))}
</div>
) : null}
<div className="mac-pro-license-meta">
<div className="mac-native-license-meta">
<span>
授权到期 <strong>{formatMacLicenseDate(license.licenseExpiresAt)}</strong>
</span>
@@ -274,7 +274,7 @@ export function MacProLicenseCard({
最近检测 <strong>{formatMacLicenseDateTime(license.lastCheckedAt)}</strong>
</span>
</div>
<div className="mac-pro-license-footer">
<div className="mac-native-license-footer">
<span />
<Button
variant="outline"
@@ -852,7 +852,10 @@ export function PersonalWechatSendPage({
{/* 发送能力授权卡片:仅在加载了发送组件的档位渲染。
OSS(runtime_missing)下不渲染,保证免费版不出现授权入口。 */}
{macRuntimeAvailability?.state === 'available' ? (
<MacProLicenseCard onNotice={onNotice} onStatusChange={setMacLicenseStatus} />
<MacNativeLicenseCard
onNotice={onNotice}
onStatusChange={setMacLicenseStatus}
/>
) : null}
<section
className="settings-card mac-wechat-environment-card"
+16 -16
View File
@@ -249,14 +249,14 @@
background: var(--wxex-bg-elevated);
padding: 24px 26px;
}
.mac-pro-license-card,
.mac-native-license-card,
.mac-wechat-environment-card {
display: grid;
gap: 14px;
min-width: 0;
padding: 20px 22px;
}
.mac-pro-license-header,
.mac-native-license-header,
.mac-wechat-environment-header {
display: flex;
min-width: 0;
@@ -270,26 +270,26 @@
font-weight: 650;
}
}
.mac-pro-license-status,
.mac-native-license-status,
.mac-wechat-environment-status {
flex: 0 0 auto;
color: var(--wxex-text-secondary);
font-size: 12px;
}
.mac-pro-license-status.is-ready,
.mac-native-license-status.is-ready,
.mac-wechat-environment-status.is-ready,
.mac-wechat-status-item .is-ready,
.mac-wechat-capability-details .is-ready {
color: var(--wxex-success);
}
.mac-pro-license-status.is-error {
.mac-native-license-status.is-error {
color: var(--wxex-danger);
}
.mac-pro-license-status.is-neutral,
.mac-native-license-status.is-neutral,
.mac-wechat-environment-status.is-neutral {
color: var(--wxex-text-muted);
}
.mac-pro-device-row {
.mac-native-device-row {
display: flex;
min-width: 0;
align-items: center;
@@ -298,7 +298,7 @@
background: color-mix(in srgb, var(--wxex-text-primary) 4%, transparent);
padding: 10px 12px;
}
.mac-pro-device-value {
.mac-native-device-value {
display: grid;
min-width: 0;
flex: 1;
@@ -317,12 +317,12 @@
white-space: nowrap;
}
}
.mac-pro-license-hint {
.mac-native-license-hint {
margin: -5px 0 0;
color: var(--wxex-text-secondary);
font-size: 12px;
}
.mac-pro-license-features {
.mac-native-license-features {
display: flex;
flex-wrap: wrap;
gap: 6px;
@@ -335,7 +335,7 @@
font-size: 11px;
}
}
.mac-pro-license-meta {
.mac-native-license-meta {
display: flex;
flex-wrap: wrap;
gap: 8px 24px;
@@ -348,14 +348,14 @@
font-weight: 550;
}
}
.mac-pro-license-footer {
.mac-native-license-footer {
display: flex;
min-width: 0;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.mac-pro-identity-note {
.mac-native-identity-note {
margin: 0;
}
.mac-wechat-status-grid {
@@ -462,12 +462,12 @@
}
}
@media (max-width: 560px) {
.mac-pro-license-card,
.mac-native-license-card,
.mac-wechat-environment-card {
padding: 16px;
}
.mac-pro-license-header,
.mac-native-license-header,
.mac-wechat-environment-header {
align-items: flex-start;
flex-direction: column;
@@ -486,7 +486,7 @@
}
}
.mac-pro-license-meta {
.mac-native-license-meta {
flex-direction: column;
gap: 5px;
}
+32 -1
View File
@@ -32,6 +32,13 @@ const { createBuilderConfig } = nodeRequire('../../scripts/build-macos-edition.c
dmg: { artifactName: string }
}
}
const { resolveEditionRoots, validateLicenseStatusRoute } = nodeRequire('../../scripts/prepare-macos-edition.cjs') as {
resolveEditionRoots: (projectRoot?: string, env?: NodeJS.ProcessEnv) => {
stageRoot: string
outputRoot: string
}
validateLicenseStatusRoute: (hostPath: string) => void
}
const {
validateAsarRuntimeDependencies,
validateFfmpegRuntime,
@@ -294,7 +301,7 @@ describe('production runtime packaging', () => {
(item) => typeof item === 'string' && !item.startsWith('!') && item.includes('resources')
)
).toBe(false)
expect(config.dmg.artifactName).toBe('TraceMemo-2.5.2-mac-arm64-public.dmg')
expect(config.dmg.artifactName).toBe('TraceMemo-2.5.2-mac-arm64-oss.dmg')
const nativeConfig = createBuilderConfig({
edition: 'native',
stageRoot: join(root, 'mac-staging', 'native'),
@@ -305,6 +312,30 @@ describe('production runtime packaging', () => {
expect(nativeConfig.dmg.artifactName).toBe('TraceMemo-2.5.2-mac-arm64-native.dmg')
})
it('supports isolated macOS staging and output roots without changing defaults', () => {
expect(resolveEditionRoots('/repo', {})).toEqual({
stageRoot: '/repo/build/mac-staging',
outputRoot: '/repo/dist/mac'
})
expect(
resolveEditionRoots('/repo', {
TRACEMEMO_MAC_STAGE_ROOT: '/tmp/candidate/staging',
TRACEMEMO_MAC_OUTPUT_ROOT: '/tmp/candidate/output'
})
).toEqual({
stageRoot: '/tmp/candidate/staging',
outputRoot: '/tmp/candidate/output'
})
})
it('rejects a native Host that cannot serve the license status route', () => {
const host = join(root, 'license-route-host')
writeFileSync(host, 'GET /healthz')
expect(() => validateLicenseStatusRoute(host)).toThrow(/GET \/license\/status/)
writeFileSync(host, 'GET /healthz GET /license/status')
expect(() => validateLicenseStatusRoute(host)).not.toThrow()
})
it('requires the matching Windows and macOS sherpa native runtime', () => {
const resources = join(root, 'sherpa-resources')
const unpacked = join(resources, 'app.asar.unpacked', 'node_modules')