feat: update preinstalled skills and CLI scripts, enhance packaging process, and add configuration for Windows and macOS

This commit is contained in:
DEV_DSW
2026-04-27 14:21:23 +08:00
parent 1667688931
commit 90e02636c7
16 changed files with 733 additions and 16 deletions

View File

@@ -1,10 +1,13 @@
#!/usr/bin/env zx
import 'zx/globals';
import { configureZxShellForPlatform } from './configure-zx-shell.mjs';
import { readFileSync, existsSync, mkdirSync, rmSync, cpSync, writeFileSync } from 'node:fs';
import { join, dirname, basename } from 'node:path';
import { fileURLToPath } from 'node:url';
configureZxShellForPlatform();
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..');
const MANIFEST_PATH = join(ROOT, 'resources', 'skills', 'preinstalled-manifest.json');

View File

@@ -0,0 +1,7 @@
import { usePowerShell } from 'zx';
export function configureZxShellForPlatform() {
if (process.platform === 'win32') {
usePowerShell();
}
}

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env zx
import 'zx/globals';
import { configureZxShellForPlatform } from './configure-zx-shell.mjs';
configureZxShellForPlatform();
const ROOT_DIR = path.resolve(__dirname, '..');
const NODE_VERSION = '22.16.0';
@@ -130,4 +133,4 @@ try {
echo(chalk.yellow` Packaging will continue without external Node.js binary.`);
// Exit with code 0 to allow packaging to continue
process.exit(0);
}
}

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env zx
import 'zx/globals';
import { configureZxShellForPlatform } from './configure-zx-shell.mjs';
configureZxShellForPlatform();
const ROOT_DIR = path.resolve(__dirname, '..');
const UV_VERSION = '0.10.0';

View File

@@ -1,10 +1,13 @@
#!/usr/bin/env zx
import 'zx/globals';
import { configureZxShellForPlatform } from './configure-zx-shell.mjs';
import sharp from 'sharp';
import png2icons from 'png2icons';
import { fileURLToPath } from 'url';
configureZxShellForPlatform();
// Calculate paths
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const targetFile = require.resolve('app-builder-lib/out/targets/nsis/NsisTarget.js');
const patchMarker = 'zn-ai patch: retry NSIS stub execution on Windows';
const helperSnippet = `
// ${patchMarker}
function isRetryableWindowsSpawnError(error) {
const code = error != null && typeof error.code === "string" ? error.code : "";
const message = error != null && typeof error.message === "string" ? error.message : "";
return (code === "EPERM" ||
code === "EACCES" ||
message.includes("spawn EPERM") ||
message.includes("spawn EACCES") ||
message.includes("used by another process"));
}
async function execWineWithRetry(file, file64 = null, appArgs = [], options = {}) {
const maxAttempts = process.platform === "win32" ? 12 : 1;
let attempt = 0;
while (true) {
attempt++;
try {
return await (0, wine_1.execWine)(file, file64, appArgs, options);
}
catch (error) {
const shouldRetry = process.platform === "win32" &&
attempt < maxAttempts &&
isRetryableWindowsSpawnError(error);
if (!shouldRetry) {
throw error;
}
builder_util_1.log.warn({
attempt,
maxAttempts,
file,
reason: error.message || String(error),
}, "retrying NSIS stub execution after transient Windows spawn failure");
await new Promise(resolve => setTimeout(resolve, attempt * 1000));
}
}
}
`;
const originalCall = 'await (0, wine_1.execWine)(installerPath, null, [], { env: { __COMPAT_LAYER: "RunAsInvoker" } });';
const patchedCall = 'await execWineWithRetry(installerPath, null, [], { env: { __COMPAT_LAYER: "RunAsInvoker" } });';
const source = fs.readFileSync(targetFile, 'utf8');
if (source.includes(patchMarker)) {
console.log(`[patch-electron-builder-nsis] already patched: ${targetFile}`);
process.exit(0);
}
if (!source.includes(originalCall)) {
console.error(`[patch-electron-builder-nsis] target call not found in ${targetFile}`);
process.exit(1);
}
const classToken = 'class NsisTarget extends core_1.Target {';
if (!source.includes(classToken)) {
console.error(`[patch-electron-builder-nsis] class token not found in ${targetFile}`);
process.exit(1);
}
const patchedSource = source
.replace(classToken, `${helperSnippet}\n${classToken}`)
.replace(originalCall, patchedCall);
fs.writeFileSync(targetFile, patchedSource, 'utf8');
console.log(`[patch-electron-builder-nsis] patched ${targetFile}`);

View File

@@ -1,10 +1,13 @@
#!/usr/bin/env zx
import 'zx/globals';
import { configureZxShellForPlatform } from './configure-zx-shell.mjs';
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
configureZxShellForPlatform();
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..');
const lockPath = join(ROOT, 'build', 'preinstalled-skills', '.preinstalled-lock.json');