main funcions fixes

This commit is contained in:
2025-09-29 22:06:11 +09:00
parent 40e016e128
commit c8c3274527
7995 changed files with 1517998 additions and 1057 deletions

View File

@@ -0,0 +1,33 @@
import { Configuration } from "../configuration";
import { Framework } from "../Framework";
import { Packager } from "../index";
export type ElectronPlatformName = "darwin" | "linux" | "win32" | "mas";
/**
* Electron distributables branding options.
* @see [Electron BRANDING.json](https://github.com/electron/electron/blob/master/shell/app/BRANDING.json).
*/
export interface ElectronBrandingOptions {
projectName?: string;
productName?: string;
}
export declare function createBrandingOpts(opts: Configuration): Required<ElectronBrandingOptions>;
export interface ElectronDownloadOptions {
version?: string;
/**
* The [cache location](https://github.com/electron-userland/electron-download#cache-location).
*/
cache?: string | null;
/**
* The mirror.
*/
mirror?: string | null;
/** @private */
customDir?: string | null;
/** @private */
customFilename?: string | null;
strictSSL?: boolean;
isVerifyChecksum?: boolean;
platform?: ElectronPlatformName;
arch?: string;
}
export declare function createElectronFrameworkSupport(configuration: Configuration, packager: Packager): Promise<Framework>;

View File

@@ -0,0 +1,174 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBrandingOpts = createBrandingOpts;
exports.createElectronFrameworkSupport = createElectronFrameworkSupport;
const bluebird_lst_1 = require("bluebird-lst");
const builder_util_1 = require("builder-util");
const builder_util_2 = require("builder-util");
const fs_extra_1 = require("fs-extra");
const path = require("path");
const index_1 = require("../index");
const pathManager_1 = require("../util/pathManager");
const electronMac_1 = require("./electronMac");
const electronWin_1 = require("./electronWin");
const electronVersion_1 = require("./electronVersion");
const fs = require("fs/promises");
const injectFFMPEG_1 = require("./injectFFMPEG");
function createBrandingOpts(opts) {
var _a, _b;
return {
projectName: ((_a = opts.electronBranding) === null || _a === void 0 ? void 0 : _a.projectName) || "electron",
productName: ((_b = opts.electronBranding) === null || _b === void 0 ? void 0 : _b.productName) || "Electron",
};
}
function createDownloadOpts(opts, platform, arch, electronVersion) {
return {
platform,
arch,
version: electronVersion,
...opts.electronDownload,
};
}
async function beforeCopyExtraFiles(options) {
const { appOutDir, packager } = options;
const electronBranding = createBrandingOpts(packager.config);
if (packager.platform === index_1.Platform.LINUX) {
const linuxPackager = packager;
const executable = path.join(appOutDir, linuxPackager.executableName);
await (0, fs_extra_1.rename)(path.join(appOutDir, electronBranding.projectName), executable);
}
else if (packager.platform === index_1.Platform.WINDOWS) {
const executable = path.join(appOutDir, `${packager.appInfo.productFilename}.exe`);
await (0, fs_extra_1.rename)(path.join(appOutDir, `${electronBranding.projectName}.exe`), executable);
if (options.asarIntegrity) {
await (0, electronWin_1.addWinAsarIntegrity)(executable, options.asarIntegrity);
}
}
else {
await (0, electronMac_1.createMacApp)(packager, appOutDir, options.asarIntegrity, options.platformName === "mas");
}
await removeUnusedLanguagesIfNeeded(options);
}
async function removeUnusedLanguagesIfNeeded(options) {
const { packager: { config, platformSpecificBuildOptions }, } = options;
const wantedLanguages = (0, builder_util_1.asArray)(platformSpecificBuildOptions.electronLanguages || config.electronLanguages);
if (!wantedLanguages.length) {
return;
}
const { dir, langFileExt } = getLocalesConfig(options);
// noinspection SpellCheckingInspection
await bluebird_lst_1.default.map((0, fs_extra_1.readdir)(dir), file => {
if (!file.endsWith(langFileExt)) {
return;
}
const language = file.substring(0, file.length - langFileExt.length);
if (!wantedLanguages.includes(language)) {
return fs.rm(path.join(dir, file), { recursive: true, force: true });
}
return;
}, builder_util_2.CONCURRENCY);
function getLocalesConfig(options) {
const { appOutDir, packager } = options;
if (packager.platform === index_1.Platform.MAC) {
return { dir: packager.getResourcesDir(appOutDir), langFileExt: ".lproj" };
}
else {
return { dir: path.join(packager.getResourcesDir(appOutDir), "..", "locales"), langFileExt: ".pak" };
}
}
}
class ElectronFramework {
constructor(name, version, distMacOsAppName) {
this.name = name;
this.version = version;
this.distMacOsAppName = distMacOsAppName;
// noinspection JSUnusedGlobalSymbols
this.macOsDefaultTargets = ["zip", "dmg"];
// noinspection JSUnusedGlobalSymbols
this.defaultAppIdPrefix = "com.electron.";
// noinspection JSUnusedGlobalSymbols
this.isCopyElevateHelper = true;
// noinspection JSUnusedGlobalSymbols
this.isNpmRebuildRequired = true;
}
getDefaultIcon(platform) {
if (platform === index_1.Platform.LINUX) {
return path.join((0, pathManager_1.getTemplatePath)("icons"), "electron-linux");
}
else {
// default icon is embedded into app skeleton
return null;
}
}
async prepareApplicationStageDirectory(options) {
await unpack(options, createDownloadOpts(options.packager.config, options.platformName, options.arch, this.version), this.distMacOsAppName);
if (options.packager.config.downloadAlternateFFmpeg) {
await (0, injectFFMPEG_1.default)(options, this.version);
}
}
beforeCopyExtraFiles(options) {
return beforeCopyExtraFiles(options);
}
}
async function createElectronFrameworkSupport(configuration, packager) {
let version = configuration.electronVersion;
if (version == null) {
// for prepacked app asar no dev deps in the app.asar
if (packager.isPrepackedAppAsar) {
version = await (0, electronVersion_1.getElectronVersionFromInstalled)(packager.projectDir);
if (version == null) {
throw new Error(`Cannot compute electron version for prepacked asar`);
}
}
else {
version = await (0, electronVersion_1.computeElectronVersion)(packager.projectDir);
}
configuration.electronVersion = version;
}
const branding = createBrandingOpts(configuration);
return new ElectronFramework(branding.projectName, version, `${branding.productName}.app`);
}
async function unpack(prepareOptions, options, distMacOsAppName) {
const { packager, appOutDir, platformName } = prepareOptions;
const electronDist = packager.config.electronDist;
let dist = typeof electronDist === "function" ? electronDist(prepareOptions) : electronDist;
if (dist != null) {
const zipFile = `electron-v${options.version}-${platformName}-${options.arch}.zip`;
const resolvedDist = path.isAbsolute(dist) ? dist : path.resolve(packager.projectDir, dist);
if ((await (0, builder_util_2.statOrNull)(path.join(resolvedDist, zipFile))) != null) {
builder_util_1.log.info({ resolvedDist, zipFile }, "resolved electronDist");
options.cache = resolvedDist;
dist = null;
}
}
let isFullCleanup = false;
if (dist == null) {
await (0, builder_util_1.executeAppBuilder)(["unpack-electron", "--configuration", JSON.stringify([options]), "--output", appOutDir, "--distMacOsAppName", distMacOsAppName]);
}
else {
isFullCleanup = true;
const source = packager.getElectronSrcDir(dist);
const destination = packager.getElectronDestinationDir(appOutDir);
builder_util_1.log.info({ source, destination }, "copying Electron");
await (0, fs_extra_1.emptyDir)(appOutDir);
await (0, builder_util_2.copyDir)(source, destination, {
isUseHardLink: builder_util_2.DO_NOT_USE_HARD_LINKS,
});
}
await cleanupAfterUnpack(prepareOptions, distMacOsAppName, isFullCleanup);
}
function cleanupAfterUnpack(prepareOptions, distMacOsAppName, isFullCleanup) {
const out = prepareOptions.appOutDir;
const isMac = prepareOptions.packager.platform === index_1.Platform.MAC;
const resourcesPath = isMac ? path.join(out, distMacOsAppName, "Contents", "Resources") : path.join(out, "resources");
return Promise.all([
isFullCleanup ? (0, builder_util_2.unlinkIfExists)(path.join(resourcesPath, "default_app.asar")) : Promise.resolve(),
isFullCleanup ? (0, builder_util_2.unlinkIfExists)(path.join(out, "version")) : Promise.resolve(),
isMac
? Promise.resolve()
: (0, fs_extra_1.rename)(path.join(out, "LICENSE"), path.join(out, "LICENSE.electron.txt")).catch(() => {
/* ignore */
}),
]);
}
//# sourceMappingURL=ElectronFramework.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,268 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMacApp = createMacApp;
const bluebird_lst_1 = require("bluebird-lst");
const builder_util_1 = require("builder-util");
const builder_util_2 = require("builder-util");
const promises_1 = require("fs/promises");
const path = require("path");
const appInfo_1 = require("../appInfo");
const platformPackager_1 = require("../platformPackager");
const appBuilder_1 = require("../util/appBuilder");
const ElectronFramework_1 = require("./ElectronFramework");
function doRename(basePath, oldName, newName) {
return (0, promises_1.rename)(path.join(basePath, oldName), path.join(basePath, newName));
}
function moveHelpers(helperSuffixes, frameworksPath, appName, prefix) {
return bluebird_lst_1.default.map(helperSuffixes, suffix => {
const executableBasePath = path.join(frameworksPath, `${prefix}${suffix}.app`, "Contents", "MacOS");
return doRename(executableBasePath, `${prefix}${suffix}`, appName + suffix).then(() => doRename(frameworksPath, `${prefix}${suffix}.app`, `${appName}${suffix}.app`));
});
}
function getAvailableHelperSuffixes(helperEHPlist, helperNPPlist, helperRendererPlist, helperPluginPlist, helperGPUPlist) {
const result = [" Helper"];
if (helperEHPlist != null) {
result.push(" Helper EH");
}
if (helperNPPlist != null) {
result.push(" Helper NP");
}
if (helperRendererPlist != null) {
result.push(" Helper (Renderer)");
}
if (helperPluginPlist != null) {
result.push(" Helper (Plugin)");
}
if (helperGPUPlist != null) {
result.push(" Helper (GPU)");
}
return result;
}
/** @internal */
async function createMacApp(packager, appOutDir, asarIntegrity, isMas) {
var _a, _b;
const appInfo = packager.appInfo;
// Electon uses the application name (CFBundleName) to resolve helper apps
// https://github.com/electron/electron/blob/main/shell/app/electron_main_delegate_mac.mm
// https://github.com/electron-userland/electron-builder/issues/6962
const appFilename = appInfo.sanitizedProductName;
const electronBranding = (0, ElectronFramework_1.createBrandingOpts)(packager.config);
const contentsPath = path.join(appOutDir, packager.info.framework.distMacOsAppName, "Contents");
const frameworksPath = path.join(contentsPath, "Frameworks");
const loginItemPath = path.join(contentsPath, "Library", "LoginItems");
const appPlistFilename = path.join(contentsPath, "Info.plist");
const helperPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper.app`, "Contents", "Info.plist");
const helperEHPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper EH.app`, "Contents", "Info.plist");
const helperNPPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper NP.app`, "Contents", "Info.plist");
const helperRendererPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper (Renderer).app`, "Contents", "Info.plist");
const helperPluginPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper (Plugin).app`, "Contents", "Info.plist");
const helperGPUPlistFilename = path.join(frameworksPath, `${electronBranding.productName} Helper (GPU).app`, "Contents", "Info.plist");
const helperLoginPlistFilename = path.join(loginItemPath, `${electronBranding.productName} Login Helper.app`, "Contents", "Info.plist");
const plistContent = await (0, appBuilder_1.executeAppBuilderAsJson)([
"decode-plist",
"-f",
appPlistFilename,
"-f",
helperPlistFilename,
"-f",
helperEHPlistFilename,
"-f",
helperNPPlistFilename,
"-f",
helperRendererPlistFilename,
"-f",
helperPluginPlistFilename,
"-f",
helperGPUPlistFilename,
"-f",
helperLoginPlistFilename,
]);
if (plistContent[0] == null) {
throw new Error("corrupted Electron dist");
}
const appPlist = plistContent[0];
const helperPlist = plistContent[1];
const helperEHPlist = plistContent[2];
const helperNPPlist = plistContent[3];
const helperRendererPlist = plistContent[4];
const helperPluginPlist = plistContent[5];
const helperGPUPlist = plistContent[6];
const helperLoginPlist = plistContent[7];
// if an extend-info file was supplied, copy its contents in first
if (plistContent[8] != null) {
Object.assign(appPlist, plistContent[8]);
}
const buildMetadata = packager.config;
/**
* Configure bundleIdentifier for the generic Electron Helper process
*
* This was the only Helper in Electron 5 and before. Allow users to configure
* the bundleIdentifier for continuity.
*/
const oldHelperBundleId = buildMetadata["helper-bundle-id"];
if (oldHelperBundleId != null) {
builder_util_1.log.warn("build.helper-bundle-id is deprecated, please set as build.mac.helperBundleId");
}
const defaultAppId = packager.platformSpecificBuildOptions.appId;
const cfBundleIdentifier = (0, appInfo_1.filterCFBundleIdentifier)((isMas ? (_a = packager.config.mas) === null || _a === void 0 ? void 0 : _a.appId : defaultAppId) || defaultAppId || appInfo.macBundleIdentifier);
const defaultHelperId = packager.platformSpecificBuildOptions.helperBundleId;
const helperBundleIdentifier = (0, appInfo_1.filterCFBundleIdentifier)((isMas ? (_b = packager.config.mas) === null || _b === void 0 ? void 0 : _b.helperBundleId : defaultHelperId) || defaultHelperId || oldHelperBundleId || `${cfBundleIdentifier}.helper`);
appPlist.CFBundleIdentifier = cfBundleIdentifier;
await packager.applyCommonInfo(appPlist, contentsPath);
// required for electron-updater proxy
if (!isMas) {
configureLocalhostAts(appPlist);
}
helperPlist.CFBundleExecutable = `${appFilename} Helper`;
helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`;
helperPlist.CFBundleIdentifier = helperBundleIdentifier;
helperPlist.CFBundleVersion = appPlist.CFBundleVersion;
/**
* Configure bundleIdentifier for Electron 5+ Helper processes
*
* In Electron 6, parts of the generic Electron Helper process were split into
* individual helper processes. Allow users to configure the bundleIdentifiers
* for continuity, specifically because macOS keychain access relies on
* bundleIdentifiers not changing (i.e. across versions of Electron).
*/
function configureHelper(helper, postfix, userProvidedBundleIdentifier) {
helper.CFBundleExecutable = `${appFilename} Helper ${postfix}`;
helper.CFBundleDisplayName = `${appInfo.productName} Helper ${postfix}`;
helper.CFBundleIdentifier = userProvidedBundleIdentifier
? (0, appInfo_1.filterCFBundleIdentifier)(userProvidedBundleIdentifier)
: (0, appInfo_1.filterCFBundleIdentifier)(`${helperBundleIdentifier}.${postfix}`);
helper.CFBundleVersion = appPlist.CFBundleVersion;
}
if (helperRendererPlist != null) {
configureHelper(helperRendererPlist, "(Renderer)", packager.platformSpecificBuildOptions.helperRendererBundleId);
}
if (helperPluginPlist != null) {
configureHelper(helperPluginPlist, "(Plugin)", packager.platformSpecificBuildOptions.helperPluginBundleId);
}
if (helperGPUPlist != null) {
configureHelper(helperGPUPlist, "(GPU)", packager.platformSpecificBuildOptions.helperGPUBundleId);
}
if (helperEHPlist != null) {
configureHelper(helperEHPlist, "EH", packager.platformSpecificBuildOptions.helperEHBundleId);
}
if (helperNPPlist != null) {
configureHelper(helperNPPlist, "NP", packager.platformSpecificBuildOptions.helperNPBundleId);
}
if (helperLoginPlist != null) {
helperLoginPlist.CFBundleExecutable = `${appFilename} Login Helper`;
helperLoginPlist.CFBundleDisplayName = `${appInfo.productName} Login Helper`;
// noinspection SpellCheckingInspection
helperLoginPlist.CFBundleIdentifier = `${cfBundleIdentifier}.loginhelper`;
helperLoginPlist.CFBundleVersion = appPlist.CFBundleVersion;
}
const protocols = (0, builder_util_1.asArray)(buildMetadata.protocols).concat((0, builder_util_1.asArray)(packager.platformSpecificBuildOptions.protocols));
if (protocols.length > 0) {
appPlist.CFBundleURLTypes = protocols.map(protocol => {
const schemes = (0, builder_util_1.asArray)(protocol.schemes);
if (schemes.length === 0) {
throw new builder_util_1.InvalidConfigurationError(`Protocol "${protocol.name}": must be at least one scheme specified`);
}
return {
CFBundleURLName: protocol.name,
CFBundleTypeRole: protocol.role || "Editor",
CFBundleURLSchemes: schemes.slice(),
};
});
}
const fileAssociations = packager.fileAssociations;
if (fileAssociations.length > 0) {
const documentTypes = await bluebird_lst_1.default.map(fileAssociations, async (fileAssociation) => {
const extensions = (0, builder_util_1.asArray)(fileAssociation.ext).map(platformPackager_1.normalizeExt);
const customIcon = await packager.getResource((0, builder_util_1.getPlatformIconFileName)(fileAssociation.icon, true), `${extensions[0]}.icns`);
let iconFile = appPlist.CFBundleIconFile;
if (customIcon != null) {
iconFile = path.basename(customIcon);
await (0, builder_util_2.copyOrLinkFile)(customIcon, path.join(path.join(contentsPath, "Resources"), iconFile));
}
const result = {
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name || extensions[0],
CFBundleTypeRole: fileAssociation.role || "Editor",
LSHandlerRank: fileAssociation.rank || "Default",
CFBundleTypeIconFile: iconFile,
};
if (fileAssociation.isPackage) {
result.LSTypeIsPackage = true;
}
return result;
});
// `CFBundleDocumentTypes` may be defined in `mac.extendInfo`, so we need to merge it in that case
appPlist.CFBundleDocumentTypes = [...(appPlist.CFBundleDocumentTypes || []), ...documentTypes];
}
if (asarIntegrity != null) {
appPlist.ElectronAsarIntegrity = asarIntegrity;
}
const plistDataToWrite = {
[appPlistFilename]: appPlist,
[helperPlistFilename]: helperPlist,
};
if (helperEHPlist != null) {
plistDataToWrite[helperEHPlistFilename] = helperEHPlist;
}
if (helperNPPlist != null) {
plistDataToWrite[helperNPPlistFilename] = helperNPPlist;
}
if (helperRendererPlist != null) {
plistDataToWrite[helperRendererPlistFilename] = helperRendererPlist;
}
if (helperPluginPlist != null) {
plistDataToWrite[helperPluginPlistFilename] = helperPluginPlist;
}
if (helperGPUPlist != null) {
plistDataToWrite[helperGPUPlistFilename] = helperGPUPlist;
}
if (helperLoginPlist != null) {
plistDataToWrite[helperLoginPlistFilename] = helperLoginPlist;
}
await Promise.all([
(0, appBuilder_1.executeAppBuilderAndWriteJson)(["encode-plist"], plistDataToWrite),
doRename(path.join(contentsPath, "MacOS"), electronBranding.productName, appPlist.CFBundleExecutable),
(0, builder_util_2.unlinkIfExists)(path.join(appOutDir, "LICENSE")),
(0, builder_util_2.unlinkIfExists)(path.join(appOutDir, "LICENSES.chromium.html")),
]);
await moveHelpers(getAvailableHelperSuffixes(helperEHPlist, helperNPPlist, helperRendererPlist, helperPluginPlist, helperGPUPlist), frameworksPath, appFilename, electronBranding.productName);
if (helperLoginPlist != null) {
const prefix = electronBranding.productName;
const suffix = " Login Helper";
const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS");
await doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix).then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`));
}
const appPath = path.join(appOutDir, `${appInfo.productFilename}.app`);
await (0, promises_1.rename)(path.dirname(contentsPath), appPath);
// https://github.com/electron-userland/electron-builder/issues/840
const now = Date.now() / 1000;
await (0, promises_1.utimes)(appPath, now, now);
}
function configureLocalhostAts(appPlist) {
// https://bencoding.com/2015/07/20/app-transport-security-and-localhost/
let ats = appPlist.NSAppTransportSecurity;
if (ats == null) {
ats = {};
appPlist.NSAppTransportSecurity = ats;
}
ats.NSAllowsLocalNetworking = true;
// https://github.com/electron-userland/electron-builder/issues/3377#issuecomment-446035814
ats.NSAllowsArbitraryLoads = true;
let exceptionDomains = ats.NSExceptionDomains;
if (exceptionDomains == null) {
exceptionDomains = {};
ats.NSExceptionDomains = exceptionDomains;
}
if (exceptionDomains.localhost == null) {
const allowHttp = {
NSTemporaryExceptionAllowsInsecureHTTPSLoads: false,
NSIncludesSubdomains: false,
NSTemporaryExceptionAllowsInsecureHTTPLoads: true,
NSTemporaryExceptionMinimumTLSVersion: "1.0",
NSTemporaryExceptionRequiresForwardSecrecy: false,
};
exceptionDomains.localhost = allowHttp;
exceptionDomains["127.0.0.1"] = allowHttp;
}
}
//# sourceMappingURL=electronMac.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
import { Lazy } from "lazy-val";
import { Configuration } from "../configuration";
export type MetadataValue = Lazy<{
[key: string]: any;
} | null>;
export declare function getElectronVersion(projectDir: string, config?: Configuration): Promise<string>;
export declare function getElectronVersionFromInstalled(projectDir: string): Promise<string | null>;
export declare function getElectronPackage(projectDir: string): Promise<any>;

View File

@@ -0,0 +1,121 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getElectronVersion = getElectronVersion;
exports.getElectronVersionFromInstalled = getElectronVersionFromInstalled;
exports.getElectronPackage = getElectronPackage;
exports.computeElectronVersion = computeElectronVersion;
const search_module_1 = require("@electron/rebuild/lib/search-module");
const builder_util_1 = require("builder-util");
const builder_util_runtime_1 = require("builder-util-runtime");
const builder_util_2 = require("builder-util");
const fs_extra_1 = require("fs-extra");
const path = require("path");
const load_1 = require("../util/config/load");
const semver = require("semver");
const config_1 = require("../util/config/config");
const electronPackages = ["electron", "electron-prebuilt", "electron-prebuilt-compile", "electron-nightly"];
async function getElectronVersion(projectDir, config) {
if (config == null) {
config = await (0, config_1.getConfig)(projectDir, null, null);
}
if (config.electronVersion != null) {
return config.electronVersion;
}
return computeElectronVersion(projectDir);
}
async function getElectronVersionFromInstalled(projectDir) {
for (const name of electronPackages) {
try {
return (await (0, fs_extra_1.readJson)(path.join(projectDir, "node_modules", name, "package.json"))).version;
}
catch (e) {
if (e.code !== "ENOENT") {
builder_util_1.log.warn({ name, error: e }, `cannot read electron version package.json`);
}
}
}
return null;
}
async function getElectronPackage(projectDir) {
for (const name of electronPackages) {
try {
return await (0, fs_extra_1.readJson)(path.join(projectDir, "node_modules", name, "package.json"));
}
catch (e) {
if (e.code !== "ENOENT") {
builder_util_1.log.warn({ name, error: e }, `cannot find electron in package.json`);
}
}
}
return null;
}
/** @internal */
async function computeElectronVersion(projectDir) {
const result = await getElectronVersionFromInstalled(projectDir);
if (result != null) {
return result;
}
const potentialRootDirs = [projectDir, await (0, search_module_1.getProjectRootPath)(projectDir)];
let dependency = null;
for await (const dir of potentialRootDirs) {
const metadata = await (0, load_1.orNullIfFileNotExist)((0, fs_extra_1.readJson)(path.join(dir, "package.json")));
dependency = metadata ? findFromPackageMetadata(metadata) : null;
if (dependency) {
break;
}
}
if ((dependency === null || dependency === void 0 ? void 0 : dependency.name) === "electron-nightly") {
builder_util_1.log.info("You are using a nightly version of electron, be warned that those builds are highly unstable.");
const feedXml = await builder_util_2.httpExecutor.request({
hostname: "github.com",
path: `/electron/nightlies/releases.atom`,
headers: {
accept: "application/xml, application/atom+xml, text/xml, */*",
},
});
const feed = (0, builder_util_runtime_1.parseXml)(feedXml);
const latestRelease = feed.element("entry", false, `No published versions on GitHub`);
const v = /\/tag\/v?([^/]+)$/.exec(latestRelease.element("link").attribute("href"))[1];
return v.startsWith("v") ? v.substring(1) : v;
}
else if ((dependency === null || dependency === void 0 ? void 0 : dependency.version) === "latest") {
builder_util_1.log.warn('Electron version is set to "latest", but it is recommended to set it to some more restricted version range.');
try {
const releaseInfo = JSON.parse((await builder_util_2.httpExecutor.request({
hostname: "github.com",
path: `/electron/${dependency.name === "electron-nightly" ? "nightlies" : "electron"}/releases/latest`,
headers: {
accept: "application/json",
},
})));
const version = releaseInfo.tag_name.startsWith("v") ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name;
builder_util_1.log.info({ version }, `resolve ${dependency.name}@${dependency.version}`);
return version;
}
catch (e) {
builder_util_1.log.warn(e);
}
throw new builder_util_1.InvalidConfigurationError(`Cannot find electron dependency to get electron version in the '${path.join(projectDir, "package.json")}'`);
}
const version = dependency === null || dependency === void 0 ? void 0 : dependency.version;
if (version == null || !/^\d/.test(version)) {
const versionMessage = version == null ? "" : ` and version ("${version}") is not fixed in project`;
throw new builder_util_1.InvalidConfigurationError(`Cannot compute electron version from installed node modules - none of the possible electron modules are installed${versionMessage}.\nSee https://github.com/electron-userland/electron-builder/issues/3984#issuecomment-504968246`);
}
return semver.coerce(version).format();
}
function findFromPackageMetadata(packageData) {
for (const name of electronPackages) {
const devDependencies = packageData.devDependencies;
let dep = devDependencies == null ? null : devDependencies[name];
if (dep == null) {
const dependencies = packageData.dependencies;
dep = dependencies == null ? null : dependencies[name];
}
if (dep != null) {
return { name, version: dep };
}
}
return null;
}
//# sourceMappingURL=electronVersion.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addWinAsarIntegrity = addWinAsarIntegrity;
const promises_1 = require("fs/promises");
const builder_util_1 = require("builder-util");
const resedit_1 = require("resedit");
/** @internal */
async function addWinAsarIntegrity(executablePath, asarIntegrity) {
const buffer = await (0, promises_1.readFile)(executablePath);
const executable = resedit_1.NtExecutable.from(buffer);
const resource = resedit_1.NtExecutableResource.from(executable);
const versionInfo = resedit_1.Resource.VersionInfo.fromEntries(resource.entries);
if (versionInfo.length !== 1) {
throw new Error(`Failed to parse version info in ${executablePath}`);
}
const languages = versionInfo[0].getAllLanguagesForStringValues();
if (languages.length !== 1) {
throw new Error(`Failed to locate languages in ${executablePath}`);
}
// See: https://github.com/electron/packager/blob/00d20b99cf4aa4621103dbbd09ff7de7d2f7f539/src/resedit.ts#L124
const integrityList = Array.from(Object.entries(asarIntegrity)).map(([file, { algorithm: alg, hash: value }]) => ({
file,
alg,
value,
}));
resource.entries.push({
type: "INTEGRITY",
id: "ELECTRONASAR",
bin: Buffer.from(JSON.stringify(integrityList)),
lang: languages[0].lang,
codepage: languages[0].codepage,
});
resource.outputResource(executable);
await (0, promises_1.writeFile)(executablePath, Buffer.from(executable.generate()));
builder_util_1.log.info({ executablePath: builder_util_1.log.filePath(executablePath) }, "updating asar integrity executable resource");
}
//# sourceMappingURL=electronWin.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"electronWin.js","sourceRoot":"","sources":["../../src/electron/electronWin.ts"],"names":[],"mappings":";;AAMA,kDAkCC;AAxCD,0CAAiD;AACjD,+CAAkC;AAClC,qCAAsE;AAGtE,gBAAgB;AACT,KAAK,UAAU,mBAAmB,CAAC,cAAsB,EAAE,aAA4B;IAC5F,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAQ,EAAC,cAAc,CAAC,CAAA;IAC7C,MAAM,UAAU,GAAG,sBAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC5C,MAAM,QAAQ,GAAG,8BAAoB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAEtD,MAAM,WAAW,GAAG,kBAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IACtE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,cAAc,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,8BAA8B,EAAE,CAAA;IACjE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,iCAAiC,cAAc,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,8GAA8G;IAC9G,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAChH,IAAI;QACJ,GAAG;QACH,KAAK;KACN,CAAC,CAAC,CAAA;IAEH,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;QACpB,IAAI,EAAE,WAAW;QACjB,EAAE,EAAE,cAAc;QAClB,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI;QACvB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ;KAChC,CAAC,CAAA;IAEF,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;IAEnC,MAAM,IAAA,oBAAS,EAAC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IACnE,kBAAG,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,kBAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,6CAA6C,CAAC,CAAA;AAC3G,CAAC","sourcesContent":["import { readFile, writeFile } from \"fs/promises\"\nimport { log } from \"builder-util\"\nimport { NtExecutable, NtExecutableResource, Resource } from \"resedit\"\nimport { AsarIntegrity } from \"../asar/integrity\"\n\n/** @internal */\nexport async function addWinAsarIntegrity(executablePath: string, asarIntegrity: AsarIntegrity) {\n const buffer = await readFile(executablePath)\n const executable = NtExecutable.from(buffer)\n const resource = NtExecutableResource.from(executable)\n\n const versionInfo = Resource.VersionInfo.fromEntries(resource.entries)\n if (versionInfo.length !== 1) {\n throw new Error(`Failed to parse version info in ${executablePath}`)\n }\n\n const languages = versionInfo[0].getAllLanguagesForStringValues()\n if (languages.length !== 1) {\n throw new Error(`Failed to locate languages in ${executablePath}`)\n }\n\n // See: https://github.com/electron/packager/blob/00d20b99cf4aa4621103dbbd09ff7de7d2f7f539/src/resedit.ts#L124\n const integrityList = Array.from(Object.entries(asarIntegrity)).map(([file, { algorithm: alg, hash: value }]) => ({\n file,\n alg,\n value,\n }))\n\n resource.entries.push({\n type: \"INTEGRITY\",\n id: \"ELECTRONASAR\",\n bin: Buffer.from(JSON.stringify(integrityList)),\n lang: languages[0].lang,\n codepage: languages[0].codepage,\n })\n\n resource.outputResource(executable)\n\n await writeFile(executablePath, Buffer.from(executable.generate()))\n log.info({ executablePath: log.filePath(executablePath) }, \"updating asar integrity executable resource\")\n}\n"]}

View File

@@ -0,0 +1,2 @@
import { PrepareApplicationStageDirectoryOptions } from "../Framework";
export default function injectFFMPEG(options: PrepareApplicationStageDirectoryOptions, electrionVersion: string): Promise<string>;

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = injectFFMPEG;
const fs = require("fs");
const path = require("path");
const builder_util_1 = require("builder-util");
const binDownload_1 = require("../binDownload");
// NOTE: Adapted from https://github.com/MarshallOfSound/electron-packager-plugin-non-proprietary-codecs-ffmpeg to resolve dependency vulnerabilities
const downloadFFMPEG = async (electronVersion, platform, arch) => {
const ffmpegFileName = `ffmpeg-v${electronVersion}-${platform}-${arch}.zip`;
const url = `https://github.com/electron/electron/releases/download/v${electronVersion}/${ffmpegFileName}`;
builder_util_1.log.info({ file: ffmpegFileName }, "downloading non-proprietary FFMPEG");
return (0, binDownload_1.getBin)(ffmpegFileName, url);
};
const copyFFMPEG = (targetPath, platform) => (sourcePath) => {
let fileName = "ffmpeg.dll";
if (["darwin", "mas"].includes(platform)) {
fileName = "libffmpeg.dylib";
}
else if (platform === "linux") {
fileName = "libffmpeg.so";
}
const libPath = path.resolve(sourcePath, fileName);
const libTargetPath = path.resolve(targetPath, fileName);
builder_util_1.log.info({ lib: builder_util_1.log.filePath(libPath), target: builder_util_1.log.filePath(libTargetPath) }, "copying non-proprietary FFMPEG");
// If the source doesn't exist we have a problem
if (!fs.existsSync(libPath)) {
throw new Error(`Failed to find FFMPEG library file at path: ${libPath}`);
}
// If we are copying to the source we can stop immediately
if (libPath !== libTargetPath) {
fs.copyFileSync(libPath, libTargetPath);
}
return libTargetPath;
};
function injectFFMPEG(options, electrionVersion) {
let libPath = options.appOutDir;
if (options.platformName === "darwin") {
libPath = path.resolve(options.appOutDir, "Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries");
}
return downloadFFMPEG(electrionVersion, options.platformName, options.arch).then(copyFFMPEG(libPath, options.platformName));
}
//# sourceMappingURL=injectFFMPEG.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"injectFFMPEG.js","sourceRoot":"","sources":["../../src/electron/injectFFMPEG.ts"],"names":[],"mappings":";;AAyCA,+BAOC;AAhDD,yBAAwB;AACxB,6BAA4B;AAG5B,+CAAkC;AAClC,gDAAuC;AAGvC,qJAAqJ;AACrJ,MAAM,cAAc,GAAG,KAAK,EAAE,eAAuB,EAAE,QAA8B,EAAE,IAAY,EAAE,EAAE;IACrG,MAAM,cAAc,GAAG,WAAW,eAAe,IAAI,QAAQ,IAAI,IAAI,MAAM,CAAA;IAC3E,MAAM,GAAG,GAAG,2DAA2D,eAAe,IAAI,cAAc,EAAE,CAAA;IAE1G,kBAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,oCAAoC,CAAC,CAAA;IACxE,OAAO,IAAA,oBAAM,EAAC,cAAc,EAAE,GAAG,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAE,QAA8B,EAAE,EAAE,CAAC,CAAC,UAAkB,EAAE,EAAE;IAChG,IAAI,QAAQ,GAAG,YAAY,CAAA;IAC3B,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,QAAQ,GAAG,iBAAiB,CAAA;IAC9B,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,QAAQ,GAAG,cAAc,CAAA;IAC3B,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACxD,kBAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,kBAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,gCAAgC,CAAC,CAAA;IAE/G,gDAAgD;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,+CAA+C,OAAO,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,0DAA0D;IAC1D,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;QAC9B,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAED,SAAwB,YAAY,CAAC,OAAgD,EAAE,gBAAwB;IAC7G,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,oFAAoF,CAAC,CAAA;IACjI,CAAC;IAED,OAAO,cAAc,CAAC,gBAAgB,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;AAC7H,CAAC","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport { ElectronPlatformName } from \"./ElectronFramework\"\n\nimport { log } from \"builder-util\"\nimport { getBin } from \"../binDownload\"\nimport { PrepareApplicationStageDirectoryOptions } from \"../Framework\"\n\n// NOTE: Adapted from https://github.com/MarshallOfSound/electron-packager-plugin-non-proprietary-codecs-ffmpeg to resolve dependency vulnerabilities\nconst downloadFFMPEG = async (electronVersion: string, platform: ElectronPlatformName, arch: string) => {\n const ffmpegFileName = `ffmpeg-v${electronVersion}-${platform}-${arch}.zip`\n const url = `https://github.com/electron/electron/releases/download/v${electronVersion}/${ffmpegFileName}`\n\n log.info({ file: ffmpegFileName }, \"downloading non-proprietary FFMPEG\")\n return getBin(ffmpegFileName, url)\n}\n\nconst copyFFMPEG = (targetPath: string, platform: ElectronPlatformName) => (sourcePath: string) => {\n let fileName = \"ffmpeg.dll\"\n if ([\"darwin\", \"mas\"].includes(platform)) {\n fileName = \"libffmpeg.dylib\"\n } else if (platform === \"linux\") {\n fileName = \"libffmpeg.so\"\n }\n\n const libPath = path.resolve(sourcePath, fileName)\n const libTargetPath = path.resolve(targetPath, fileName)\n log.info({ lib: log.filePath(libPath), target: log.filePath(libTargetPath) }, \"copying non-proprietary FFMPEG\")\n\n // If the source doesn't exist we have a problem\n if (!fs.existsSync(libPath)) {\n throw new Error(`Failed to find FFMPEG library file at path: ${libPath}`)\n }\n\n // If we are copying to the source we can stop immediately\n if (libPath !== libTargetPath) {\n fs.copyFileSync(libPath, libTargetPath)\n }\n return libTargetPath\n}\n\nexport default function injectFFMPEG(options: PrepareApplicationStageDirectoryOptions, electrionVersion: string) {\n let libPath = options.appOutDir\n if (options.platformName === \"darwin\") {\n libPath = path.resolve(options.appOutDir, \"Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries\")\n }\n\n return downloadFFMPEG(electrionVersion, options.platformName, options.arch).then(copyFFMPEG(libPath, options.platformName))\n}\n"]}