Merge branch 'main' of https://git.mailib.ru/ifontosh/DndGamePlayer
This commit is contained in:
@@ -52,4 +52,15 @@ void test('package.json: конфиг electron-builder (mac/win/linux)', () => {
|
|||||||
assert.ok(!pkg.build.appImage?.artifactName?.includes('version'));
|
assert.ok(!pkg.build.appImage?.artifactName?.includes('version'));
|
||||||
assert.ok(!pkg.build.nsis?.artifactName?.includes('version'));
|
assert.ok(!pkg.build.nsis?.artifactName?.includes('version'));
|
||||||
assert.ok(pkg.build.files.includes('dist/**/*'));
|
assert.ok(pkg.build.files.includes('dist/**/*'));
|
||||||
|
assert.ok(
|
||||||
|
pkg.build.asarUnpack.some((p) => p.includes('@img')),
|
||||||
|
'sharp native binaries live under node_modules/@img',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
void test('package.json: pack:mac runs release-mac-prep before electron-builder', () => {
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')) as {
|
||||||
|
scripts: { 'pack:mac': string };
|
||||||
|
};
|
||||||
|
assert.match(pkg.scripts['pack:mac'], /release-mac-prep\.mjs/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
|
||||||
npm run pack:mac
|
npm run pack:mac
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`pack:mac` сам вызывает `build` и `scripts/release-mac-prep.mjs` — подтягивает **оба** набора нативных бинарников sharp (x64 и arm64). Без этого x64-сборка с Apple Silicon падает при старте с ошибкой `Could not load the "sharp" module using the darwin-x64 runtime`.
|
||||||
|
|
||||||
В `release/` (имена **без версии**):
|
В `release/` (имена **без версии**):
|
||||||
|
|
||||||
- `latest-mac.yml` — сгенерирован electron-builder, не копируйте старый с Windows
|
- `latest-mac.yml` — сгенерирован electron-builder, не копируйте старый с Windows
|
||||||
|
|||||||
+2
-2
@@ -10,14 +10,14 @@
|
|||||||
"build:obfuscate": "node scripts/build.mjs --production --obfuscate",
|
"build:obfuscate": "node scripts/build.mjs --production --obfuscate",
|
||||||
"lint": "eslint . --max-warnings 0",
|
"lint": "eslint . --max-warnings 0",
|
||||||
"typecheck": "tsc -p tsconfig.eslint.json --noEmit",
|
"typecheck": "tsc -p tsconfig.eslint.json --noEmit",
|
||||||
"test": "tsx --test app/renderer/shared/ui/controls.tooltip.test.ts app/renderer/editor/state/projectState.race.test.ts app/renderer/editor/graph/sceneCardById.test.ts app/renderer/editor/i18n/editorMessages.locale.test.ts app/shared/ipc/contracts.mediaRemoval.test.ts app/shared/effectEraserHitTest.test.ts app/renderer/control/controlApp.effectsPanel.test.ts app/renderer/shared/effects/PxiEffectsOverlay.pointer.test.ts app/main/windows/createWindows.editorClose.test.ts app/main/windows/bootWindow.test.ts app/main/effects/effectsStore.test.ts app/main/project/assetPrune.test.ts app/main/project/optimizeImageImport.test.ts app/main/project/scenePreviewThumbnail.test.ts app/main/project/fsRetry.test.ts app/main/project/zipRead.test.ts app/main/project/replaceFileAtomic.test.ts app/main/project/zipStore.legacyContract.test.ts app/shared/package.build.test.ts app/shared/license/canonicalJson.test.ts app/shared/license/productKey.test.ts app/shared/license/licenseService.networkRegression.test.ts app/shared/video/videoPlaybackPerf.networkRegression.test.ts app/shared/video/videoPlaybackLoop.networkRegression.test.ts app/main/license/verifyLicenseToken.test.ts && node --test scripts/build-env.test.mjs scripts/obfuscate-main.test.mjs",
|
"test": "tsx --test app/renderer/shared/ui/controls.tooltip.test.ts app/renderer/editor/state/projectState.race.test.ts app/renderer/editor/graph/sceneCardById.test.ts app/renderer/editor/i18n/editorMessages.locale.test.ts app/shared/ipc/contracts.mediaRemoval.test.ts app/shared/effectEraserHitTest.test.ts app/renderer/control/controlApp.effectsPanel.test.ts app/renderer/shared/effects/PxiEffectsOverlay.pointer.test.ts app/main/windows/createWindows.editorClose.test.ts app/main/windows/bootWindow.test.ts app/main/effects/effectsStore.test.ts app/main/project/assetPrune.test.ts app/main/project/optimizeImageImport.test.ts app/main/project/scenePreviewThumbnail.test.ts app/main/project/fsRetry.test.ts app/main/project/zipRead.test.ts app/main/project/replaceFileAtomic.test.ts app/main/project/zipStore.legacyContract.test.ts app/shared/package.build.test.ts app/shared/license/canonicalJson.test.ts app/shared/license/productKey.test.ts app/shared/license/licenseService.networkRegression.test.ts app/shared/video/videoPlaybackPerf.networkRegression.test.ts app/shared/video/videoPlaybackLoop.networkRegression.test.ts app/main/license/verifyLicenseToken.test.ts && node --test scripts/build-env.test.mjs scripts/obfuscate-main.test.mjs scripts/release-mac-prep.test.mjs",
|
||||||
"format": "prettier . --check",
|
"format": "prettier . --check",
|
||||||
"format:write": "prettier . --write",
|
"format:write": "prettier . --write",
|
||||||
"postinstall": "patch-package",
|
"postinstall": "patch-package",
|
||||||
"release:info": "node scripts/print-release-info.mjs",
|
"release:info": "node scripts/print-release-info.mjs",
|
||||||
"pack": "npm run build && node scripts/release-win-prep.mjs && electron-builder",
|
"pack": "npm run build && node scripts/release-win-prep.mjs && electron-builder",
|
||||||
"pack:dir": "npm run build && node scripts/release-win-prep.mjs && electron-builder --dir",
|
"pack:dir": "npm run build && node scripts/release-win-prep.mjs && electron-builder --dir",
|
||||||
"pack:mac": "npm run build && electron-builder --mac",
|
"pack:mac": "npm run build && node scripts/release-mac-prep.mjs && electron-builder --mac",
|
||||||
"pack:win": "npm run build && node scripts/release-win-prep.mjs && electron-builder --win",
|
"pack:win": "npm run build && node scripts/release-win-prep.mjs && electron-builder --win",
|
||||||
"pack:linux": "node scripts/release-linux-pack.mjs",
|
"pack:linux": "node scripts/release-linux-pack.mjs",
|
||||||
"release": "powershell -ExecutionPolicy Bypass -File scripts/ttrpg-release/release.ps1",
|
"release": "powershell -ExecutionPolicy Bypass -File scripts/ttrpg-release/release.ps1",
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* Перед `electron-builder --mac`: npm ставит sharp только под CPU хоста.
|
||||||
|
* В release идут x64 и arm64 — в .app должны быть оба набора @img/sharp-darwin-*.
|
||||||
|
*/
|
||||||
|
import { execFileSync } from 'node:child_process';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const MAC_SHARP_IMG_PACKAGES = [
|
||||||
|
'@img/sharp-darwin-arm64',
|
||||||
|
'@img/sharp-libvips-darwin-arm64',
|
||||||
|
'@img/sharp-darwin-x64',
|
||||||
|
'@img/sharp-libvips-darwin-x64',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} root
|
||||||
|
* @returns {string[]} entries like `@img/sharp-darwin-x64@0.34.5` missing under node_modules
|
||||||
|
*/
|
||||||
|
export function macSharpImgPackagesToInstall(root) {
|
||||||
|
const sharpPkgPath = path.join(root, 'node_modules', 'sharp', 'package.json');
|
||||||
|
if (!fs.existsSync(sharpPkgPath)) {
|
||||||
|
throw new Error('[release-mac-prep] sharp is not installed — run npm ci first');
|
||||||
|
}
|
||||||
|
|
||||||
|
const sharpPkg = JSON.parse(fs.readFileSync(sharpPkgPath, 'utf8'));
|
||||||
|
const versions = sharpPkg.optionalDependencies ?? {};
|
||||||
|
const missing = [];
|
||||||
|
|
||||||
|
for (const name of MAC_SHARP_IMG_PACKAGES) {
|
||||||
|
const version = versions[name];
|
||||||
|
if (!version) {
|
||||||
|
throw new Error(`[release-mac-prep] sharp optionalDependency missing: ${name}`);
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(path.join(root, 'node_modules', name))) {
|
||||||
|
missing.push(`${name}@${version}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return missing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} root
|
||||||
|
* @param {{ runInstall?: boolean }} [opts]
|
||||||
|
*/
|
||||||
|
export function ensureMacSharpBinaries(root, opts = {}) {
|
||||||
|
const { runInstall = true } = opts;
|
||||||
|
const toInstall = macSharpImgPackagesToInstall(root);
|
||||||
|
|
||||||
|
if (toInstall.length === 0) {
|
||||||
|
console.log('[release-mac-prep] all macOS sharp binaries present');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[release-mac-prep] installing', toInstall.join(', '));
|
||||||
|
if (!runInstall) return;
|
||||||
|
|
||||||
|
execFileSync('npm', ['install', '--no-save', '--force', ...toInstall], {
|
||||||
|
cwd: root,
|
||||||
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
||||||
|
if (isMain) {
|
||||||
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
console.warn('[release-mac-prep] skipped: not macOS (no dual-arch sharp prep needed here)');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
ensureMacSharpBinaries(root);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
import { macSharpImgPackagesToInstall } from './release-mac-prep.mjs';
|
||||||
|
|
||||||
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||||
|
|
||||||
|
void test('macSharpImgPackagesToInstall: empty when all four @img darwin packages exist', () => {
|
||||||
|
const missing = macSharpImgPackagesToInstall(root);
|
||||||
|
assert.deepEqual(missing, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
void test('macSharpImgPackagesToInstall: lists missing darwin-x64 on arm64-only tree', () => {
|
||||||
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mac-sharp-prep-'));
|
||||||
|
try {
|
||||||
|
const sharpOpt = {
|
||||||
|
'@img/sharp-darwin-arm64': '0.34.5',
|
||||||
|
'@img/sharp-libvips-darwin-arm64': '1.2.4',
|
||||||
|
'@img/sharp-darwin-x64': '0.34.5',
|
||||||
|
'@img/sharp-libvips-darwin-x64': '1.2.4',
|
||||||
|
};
|
||||||
|
fs.mkdirSync(path.join(tmp, 'node_modules', 'sharp'), { recursive: true });
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(tmp, 'node_modules', 'sharp', 'package.json'),
|
||||||
|
JSON.stringify({ optionalDependencies: sharpOpt }),
|
||||||
|
);
|
||||||
|
for (const name of ['@img/sharp-darwin-arm64', '@img/sharp-libvips-darwin-arm64']) {
|
||||||
|
const dir = path.join(tmp, 'node_modules', name);
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
||||||
|
}
|
||||||
|
|
||||||
|
const missing = macSharpImgPackagesToInstall(tmp);
|
||||||
|
assert.deepEqual(missing, ['@img/sharp-darwin-x64@0.34.5', '@img/sharp-libvips-darwin-x64@1.2.4']);
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(tmp, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user