Initial commit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
import { Arch } from "builder-util";
|
||||
import { CancellationToken, Nullish, PublishConfiguration } from "builder-util-runtime";
|
||||
import { PublishContext, Publisher, PublishOptions, UploadTask } from "electron-publish";
|
||||
import { MultiProgress } from "electron-publish/out/multiProgress";
|
||||
import { AppInfo, PlatformSpecificBuildOptions, TargetSpecificOptions } from "../index";
|
||||
import { Packager } from "../packager";
|
||||
import { PlatformPackager } from "../platformPackager";
|
||||
export declare class PublishManager implements PublishContext {
|
||||
private readonly packager;
|
||||
private readonly publishOptions;
|
||||
readonly cancellationToken: CancellationToken;
|
||||
private readonly nameToPublisher;
|
||||
private readonly taskManager;
|
||||
readonly isPublish: boolean;
|
||||
readonly progress: MultiProgress | null;
|
||||
private readonly updateFileWriteTask;
|
||||
constructor(packager: Packager, publishOptions: PublishOptions, cancellationToken?: CancellationToken);
|
||||
private getAppInfo;
|
||||
getGlobalPublishConfigurations(): Promise<Array<PublishConfiguration> | null>;
|
||||
scheduleUpload(publishConfig: PublishConfiguration, event: UploadTask, appInfo: AppInfo): Promise<void>;
|
||||
private artifactCreatedWithoutExplicitPublishConfig;
|
||||
private getOrCreatePublisher;
|
||||
cancelTasks(): void;
|
||||
awaitTasks(): Promise<void>;
|
||||
}
|
||||
export declare function getAppUpdatePublishConfiguration(packager: PlatformPackager<any>, targetSpecificOptions: TargetSpecificOptions | Nullish, arch: Arch, errorIfCannot: boolean): Promise<PublishConfiguration | null>;
|
||||
export declare function getPublishConfigsForUpdateInfo(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration> | null, arch: Arch | null): Promise<Array<PublishConfiguration> | null>;
|
||||
export declare function createPublisher(context: PublishContext, version: string, publishConfig: PublishConfiguration, options: PublishOptions, packager: Packager): Promise<Publisher | null>;
|
||||
export declare function computeDownloadUrl(publishConfiguration: PublishConfiguration, fileName: string | null, packager: PlatformPackager<any>): string;
|
||||
export declare function getPublishConfigs(platformPackager: PlatformPackager<any>, targetSpecificOptions: PlatformSpecificBuildOptions | Nullish, arch: Arch | null, errorIfCannot: boolean): Promise<Array<PublishConfiguration> | null>;
|
||||
+469
@@ -0,0 +1,469 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PublishManager = void 0;
|
||||
exports.getAppUpdatePublishConfiguration = getAppUpdatePublishConfiguration;
|
||||
exports.getPublishConfigsForUpdateInfo = getPublishConfigsForUpdateInfo;
|
||||
exports.createPublisher = createPublisher;
|
||||
exports.computeDownloadUrl = computeDownloadUrl;
|
||||
exports.getPublishConfigs = getPublishConfigs;
|
||||
const builder_util_1 = require("builder-util");
|
||||
const builder_util_runtime_1 = require("builder-util-runtime");
|
||||
const debug_1 = require("debug");
|
||||
const electron_publish_1 = require("electron-publish");
|
||||
const multiProgress_1 = require("electron-publish/out/multiProgress");
|
||||
const promises_1 = require("fs/promises");
|
||||
const ci_info_1 = require("ci-info");
|
||||
const path = require("path");
|
||||
const url = require("url");
|
||||
const index_1 = require("../index");
|
||||
const macroExpander_1 = require("../util/macroExpander");
|
||||
const updateInfoBuilder_1 = require("./updateInfoBuilder");
|
||||
const resolve_1 = require("../util/resolve");
|
||||
const pathManager_1 = require("../util/pathManager");
|
||||
const publishForPrWarning = "There are serious security concerns with PUBLISH_FOR_PULL_REQUEST=true (see the CircleCI documentation (https://circleci.com/docs/1.0/fork-pr-builds/) for details)" +
|
||||
"\nIf you have SSH keys, sensitive env vars or AWS credentials stored in your project settings and untrusted forks can make pull requests against your repo, then this option isn't for you.";
|
||||
const debug = (0, debug_1.default)("electron-builder:publish");
|
||||
function checkOptions(publishPolicy) {
|
||||
if (publishPolicy != null && publishPolicy !== "onTag" && publishPolicy !== "onTagOrDraft" && publishPolicy !== "always" && publishPolicy !== "never") {
|
||||
if (typeof publishPolicy === "string") {
|
||||
throw new builder_util_1.InvalidConfigurationError(`Expected one of "onTag", "onTagOrDraft", "always", "never", but got ${JSON.stringify(publishPolicy)}.\nPlease note that publish configuration should be specified under "config"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
class PublishManager {
|
||||
constructor(packager, publishOptions, cancellationToken = packager.cancellationToken) {
|
||||
this.packager = packager;
|
||||
this.publishOptions = publishOptions;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.nameToPublisher = new Map();
|
||||
this.isPublish = false;
|
||||
this.progress = process.stdout.isTTY ? new multiProgress_1.MultiProgress() : null;
|
||||
this.updateFileWriteTask = [];
|
||||
checkOptions(publishOptions.publish);
|
||||
this.taskManager = new builder_util_1.AsyncTaskManager(cancellationToken);
|
||||
const forcePublishForPr = process.env.PUBLISH_FOR_PULL_REQUEST === "true";
|
||||
if (!(0, builder_util_1.isPullRequest)() || forcePublishForPr) {
|
||||
if (publishOptions.publish === undefined) {
|
||||
if (process.env.npm_lifecycle_event === "release") {
|
||||
builder_util_1.log.warn("Implicit publishing triggered by npm lifecycle event 'release'. This behavior will be disabled in electron-builder v27. Please use --publish explicitly.");
|
||||
publishOptions.publish = "always";
|
||||
}
|
||||
else {
|
||||
const tag = (0, electron_publish_1.getCiTag)();
|
||||
if (tag != null) {
|
||||
builder_util_1.log.warn({ tag }, "Implicit publishing triggered by git tag. This behavior will be disabled in electron-builder v27. Please use --publish explicitly.");
|
||||
publishOptions.publish = "onTag";
|
||||
}
|
||||
else if (ci_info_1.isCI) {
|
||||
builder_util_1.log.warn("Implicit publishing triggered by CI detection. This behavior will be disabled in electron-builder v27. Please use --publish explicitly.");
|
||||
publishOptions.publish = "onTagOrDraft";
|
||||
}
|
||||
}
|
||||
}
|
||||
const publishPolicy = publishOptions.publish;
|
||||
this.isPublish = publishPolicy != null && publishOptions.publish !== "never" && (publishPolicy !== "onTag" || (0, electron_publish_1.getCiTag)() != null);
|
||||
if (this.isPublish && forcePublishForPr) {
|
||||
builder_util_1.log.warn(publishForPrWarning);
|
||||
}
|
||||
}
|
||||
else if (publishOptions.publish !== "never") {
|
||||
builder_util_1.log.info({
|
||||
reason: "current build is a part of pull request",
|
||||
solution: `set env PUBLISH_FOR_PULL_REQUEST to true to force code signing\n${publishForPrWarning}`,
|
||||
}, "publishing will be skipped");
|
||||
}
|
||||
packager.onAfterPack(async (event) => {
|
||||
const packager = event.packager;
|
||||
if (event.electronPlatformName === "darwin") {
|
||||
if (!event.targets.some(it => it.name === "dmg" || it.name === "zip")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (packager.platform === index_1.Platform.WINDOWS) {
|
||||
if (!event.targets.some(it => isSuitableWindowsTarget(it))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const publishConfig = await getAppUpdatePublishConfiguration(packager, null, event.arch, this.isPublish);
|
||||
if (publishConfig != null) {
|
||||
await (0, promises_1.writeFile)(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), (0, builder_util_1.serializeToYaml)(publishConfig));
|
||||
}
|
||||
});
|
||||
packager.onArtifactCreated(async (event) => {
|
||||
const publishConfiguration = event.publishConfig;
|
||||
if (publishConfiguration == null) {
|
||||
this.taskManager.addTask(this.artifactCreatedWithoutExplicitPublishConfig(event));
|
||||
}
|
||||
else if (this.isPublish) {
|
||||
if (debug.enabled) {
|
||||
debug(`artifactCreated (isPublish: ${this.isPublish}): ${(0, builder_util_1.safeStringifyJson)(event, new Set(["packager"]))},\n publishConfig: ${(0, builder_util_1.safeStringifyJson)(publishConfiguration)}`);
|
||||
}
|
||||
await this.scheduleUpload(publishConfiguration, event, this.getAppInfo(event.packager));
|
||||
}
|
||||
});
|
||||
}
|
||||
getAppInfo(platformPackager) {
|
||||
return platformPackager == null ? this.packager.appInfo : platformPackager.appInfo;
|
||||
}
|
||||
async getGlobalPublishConfigurations() {
|
||||
const publishers = this.packager.config.publish;
|
||||
return await resolvePublishConfigurations(publishers, null, this.packager, null, true);
|
||||
}
|
||||
async scheduleUpload(publishConfig, event, appInfo) {
|
||||
if (publishConfig.provider === "generic") {
|
||||
return;
|
||||
}
|
||||
const publisher = await this.getOrCreatePublisher(publishConfig, appInfo);
|
||||
if (publisher == null) {
|
||||
builder_util_1.log.debug({
|
||||
file: builder_util_1.log.filePath(event.file),
|
||||
reason: "publisher is null",
|
||||
publishConfig: (0, builder_util_1.safeStringifyJson)(publishConfig),
|
||||
}, "not published");
|
||||
return;
|
||||
}
|
||||
const providerName = publisher.providerName;
|
||||
if (this.publishOptions.publish === "onTagOrDraft" && (0, electron_publish_1.getCiTag)() == null && providerName !== "bitbucket" && providerName !== "github") {
|
||||
builder_util_1.log.info({ file: builder_util_1.log.filePath(event.file), reason: "current build is not for a git tag", publishPolicy: "onTagOrDraft" }, `not published to ${providerName}`);
|
||||
return;
|
||||
}
|
||||
if (publishConfig.timeout) {
|
||||
event.timeout = publishConfig.timeout;
|
||||
}
|
||||
this.taskManager.addTask(publisher.upload(event));
|
||||
}
|
||||
async artifactCreatedWithoutExplicitPublishConfig(event) {
|
||||
const platformPackager = event.packager;
|
||||
const target = event.target;
|
||||
const publishConfigs = await getPublishConfigs(platformPackager, target == null ? null : target.options, event.arch, this.isPublish);
|
||||
if (debug.enabled) {
|
||||
debug(`artifactCreated (isPublish: ${this.isPublish}): ${(0, builder_util_1.safeStringifyJson)(event, new Set(["packager"]))},\n publishConfigs: ${(0, builder_util_1.safeStringifyJson)(publishConfigs)}`);
|
||||
}
|
||||
const eventFile = event.file;
|
||||
if (publishConfigs == null) {
|
||||
if (this.isPublish) {
|
||||
builder_util_1.log.debug({ file: eventFile, reason: "no publish configs" }, "not published");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.isPublish) {
|
||||
for (const publishConfig of publishConfigs) {
|
||||
if (this.cancellationToken.cancelled) {
|
||||
builder_util_1.log.debug({ file: event.file, reason: "cancelled" }, "not published");
|
||||
break;
|
||||
}
|
||||
await this.scheduleUpload(publishConfig, event, this.getAppInfo(platformPackager));
|
||||
}
|
||||
}
|
||||
if (event.isWriteUpdateInfo &&
|
||||
target != null &&
|
||||
eventFile != null &&
|
||||
!this.cancellationToken.cancelled &&
|
||||
(platformPackager.platform !== index_1.Platform.WINDOWS || isSuitableWindowsTarget(target))) {
|
||||
this.taskManager.addTask((0, updateInfoBuilder_1.createUpdateInfoTasks)(event, publishConfigs).then(it => this.updateFileWriteTask.push(...it)));
|
||||
}
|
||||
}
|
||||
async getOrCreatePublisher(publishConfig, appInfo) {
|
||||
// to not include token into cache key
|
||||
const providerCacheKey = (0, builder_util_1.safeStringifyJson)(publishConfig);
|
||||
let publisher = this.nameToPublisher.get(providerCacheKey);
|
||||
if (publisher == null) {
|
||||
publisher = await createPublisher(this, appInfo.version, publishConfig, this.publishOptions, this.packager);
|
||||
this.nameToPublisher.set(providerCacheKey, publisher);
|
||||
builder_util_1.log.info({ publisher: publisher.toString() }, "publishing");
|
||||
}
|
||||
return publisher;
|
||||
}
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
cancelTasks() {
|
||||
this.taskManager.cancelTasks();
|
||||
this.nameToPublisher.clear();
|
||||
}
|
||||
async awaitTasks() {
|
||||
await this.taskManager.awaitTasks();
|
||||
const updateInfoFileTasks = this.updateFileWriteTask;
|
||||
if (this.cancellationToken.cancelled || updateInfoFileTasks.length === 0) {
|
||||
return;
|
||||
}
|
||||
await (0, updateInfoBuilder_1.writeUpdateInfoFiles)(updateInfoFileTasks, this.packager);
|
||||
await this.taskManager.awaitTasks();
|
||||
}
|
||||
}
|
||||
exports.PublishManager = PublishManager;
|
||||
async function getAppUpdatePublishConfiguration(packager, targetSpecificOptions, arch, errorIfCannot) {
|
||||
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, null, arch, errorIfCannot), arch);
|
||||
if (publishConfigs == null || publishConfigs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const publishConfig = {
|
||||
...publishConfigs[0],
|
||||
updaterCacheDirName: packager.appInfo.updaterCacheDirName,
|
||||
};
|
||||
if (packager.platform === index_1.Platform.WINDOWS && publishConfig.publisherName == null) {
|
||||
const winPackager = packager;
|
||||
const publisherName = winPackager.isForceCodeSigningVerification ? await (await winPackager.signingManager.value).computedPublisherName.value : undefined;
|
||||
if (publisherName != null) {
|
||||
publishConfig.publisherName = publisherName;
|
||||
}
|
||||
}
|
||||
return publishConfig;
|
||||
}
|
||||
async function getPublishConfigsForUpdateInfo(packager, publishConfigs, arch) {
|
||||
if (publishConfigs === null) {
|
||||
return null;
|
||||
}
|
||||
if (publishConfigs.length === 0) {
|
||||
builder_util_1.log.debug(null, "getPublishConfigsForUpdateInfo: no publishConfigs, detect using repository info");
|
||||
// https://github.com/electron-userland/electron-builder/issues/925#issuecomment-261732378
|
||||
// default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually)
|
||||
const repositoryInfo = await packager.info.repositoryInfo;
|
||||
debug(`getPublishConfigsForUpdateInfo: ${(0, builder_util_1.safeStringifyJson)(repositoryInfo)}`);
|
||||
if (repositoryInfo != null && repositoryInfo.type === "github") {
|
||||
const resolvedPublishConfig = await getResolvedPublishConfig(packager, packager.info, { provider: repositoryInfo.type }, arch, false);
|
||||
if (resolvedPublishConfig != null) {
|
||||
debug(`getPublishConfigsForUpdateInfo: resolve to publish config ${(0, builder_util_1.safeStringifyJson)(resolvedPublishConfig)}`);
|
||||
return [resolvedPublishConfig];
|
||||
}
|
||||
}
|
||||
}
|
||||
return publishConfigs;
|
||||
}
|
||||
async function createPublisher(context, version, publishConfig, options, packager) {
|
||||
if (debug.enabled) {
|
||||
debug(`Create publisher: ${(0, builder_util_1.safeStringifyJson)(publishConfig)}`);
|
||||
}
|
||||
const provider = publishConfig.provider;
|
||||
switch (provider) {
|
||||
case "github":
|
||||
return new electron_publish_1.GitHubPublisher(context, publishConfig, version, options);
|
||||
case "gitlab":
|
||||
return new electron_publish_1.GitlabPublisher(context, publishConfig, version);
|
||||
case "keygen":
|
||||
return new electron_publish_1.KeygenPublisher(context, publishConfig, version);
|
||||
case "snapStore":
|
||||
return new electron_publish_1.SnapStorePublisher(context, publishConfig);
|
||||
case "generic":
|
||||
return null;
|
||||
default: {
|
||||
const clazz = await requireProviderClass(provider, packager);
|
||||
return clazz == null ? null : new clazz(context, publishConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function requireProviderClass(provider, packager) {
|
||||
switch (provider) {
|
||||
case "github":
|
||||
return electron_publish_1.GitHubPublisher;
|
||||
case "gitlab":
|
||||
return electron_publish_1.GitlabPublisher;
|
||||
case "generic":
|
||||
return null;
|
||||
case "keygen":
|
||||
return electron_publish_1.KeygenPublisher;
|
||||
case "s3":
|
||||
return electron_publish_1.S3Publisher;
|
||||
case "snapStore":
|
||||
return electron_publish_1.SnapStorePublisher;
|
||||
case "spaces":
|
||||
return electron_publish_1.SpacesPublisher;
|
||||
case "bitbucket":
|
||||
return electron_publish_1.BitbucketPublisher;
|
||||
default: {
|
||||
const extensions = ["mjs", "js", "cjs"];
|
||||
const template = `electron-publisher-${provider}`;
|
||||
const name = (ext) => `${template}.${ext}`;
|
||||
const validPublisherFiles = extensions.map(ext => path.join(packager.buildResourcesDir, name(ext)));
|
||||
for (const potentialFile of validPublisherFiles) {
|
||||
if (await (0, builder_util_1.exists)(potentialFile)) {
|
||||
const module = await (0, resolve_1.resolveModule)(packager.appInfo.type, potentialFile);
|
||||
return module.default || module;
|
||||
}
|
||||
}
|
||||
builder_util_1.log.error({ path: builder_util_1.log.filePath(packager.buildResourcesDir), template, extensionsChecked: extensions }, "unable to find publish provider in build resources");
|
||||
throw new builder_util_1.InvalidConfigurationError(`Cannot find module for publisher "${provider}" with any extension: ${extensions.join(", ")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
function computeDownloadUrl(publishConfiguration, fileName, packager) {
|
||||
if (publishConfiguration.provider === "generic") {
|
||||
const baseUrlString = publishConfiguration.url;
|
||||
if (fileName == null) {
|
||||
return baseUrlString;
|
||||
}
|
||||
const baseUrl = (0, pathManager_1.parseUrl)(baseUrlString);
|
||||
return url.format({ ...baseUrl, pathname: path.posix.resolve((baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.pathname) || "/", encodeURI(fileName)) });
|
||||
}
|
||||
let baseUrl;
|
||||
if (publishConfiguration.provider === "github") {
|
||||
const gh = publishConfiguration;
|
||||
baseUrl = `${(0, builder_util_runtime_1.githubUrl)(gh)}/${gh.owner}/${gh.repo}/releases/download/${(0, builder_util_runtime_1.githubTagPrefix)(gh)}${packager.appInfo.version}`;
|
||||
}
|
||||
else {
|
||||
baseUrl = (0, builder_util_runtime_1.getS3LikeProviderBaseUrl)(publishConfiguration);
|
||||
}
|
||||
if (fileName == null) {
|
||||
return baseUrl;
|
||||
}
|
||||
return `${baseUrl}/${encodeURI(fileName)}`;
|
||||
}
|
||||
async function getPublishConfigs(platformPackager, targetSpecificOptions, arch, errorIfCannot) {
|
||||
let publishers;
|
||||
// check build.nsis (target)
|
||||
if (targetSpecificOptions != null) {
|
||||
publishers = targetSpecificOptions.publish;
|
||||
// if explicitly set to null - do not publish
|
||||
if (publishers === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// check build.win (platform)
|
||||
if (publishers == null) {
|
||||
publishers = platformPackager.platformSpecificBuildOptions.publish;
|
||||
if (publishers === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (publishers == null) {
|
||||
publishers = platformPackager.config.publish;
|
||||
if (publishers === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return await resolvePublishConfigurations(publishers, platformPackager, platformPackager.info, arch, errorIfCannot);
|
||||
}
|
||||
async function resolvePublishConfigurations(publishers, platformPackager, packager, arch, errorIfCannot) {
|
||||
if (publishers == null) {
|
||||
let serviceName = null;
|
||||
if (!(0, builder_util_1.isEmptyOrSpaces)(process.env.GH_TOKEN) || !(0, builder_util_1.isEmptyOrSpaces)(process.env.GITHUB_TOKEN)) {
|
||||
serviceName = "github";
|
||||
}
|
||||
else if (!(0, builder_util_1.isEmptyOrSpaces)(process.env.GITLAB_TOKEN)) {
|
||||
serviceName = "gitlab";
|
||||
}
|
||||
else if (!(0, builder_util_1.isEmptyOrSpaces)(process.env.KEYGEN_TOKEN)) {
|
||||
serviceName = "keygen";
|
||||
}
|
||||
else if (!(0, builder_util_1.isEmptyOrSpaces)(process.env.BITBUCKET_TOKEN)) {
|
||||
serviceName = "bitbucket";
|
||||
}
|
||||
else if (!(0, builder_util_1.isEmptyOrSpaces)(process.env.BT_TOKEN)) {
|
||||
throw new Error("Bintray has been sunset and is no longer supported by electron-builder. Ref: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/");
|
||||
}
|
||||
if (serviceName != null) {
|
||||
builder_util_1.log.debug(null, `detect ${serviceName} as publish provider`);
|
||||
return [(await getResolvedPublishConfig(platformPackager, packager, { provider: serviceName }, arch, errorIfCannot))];
|
||||
}
|
||||
}
|
||||
if (publishers == null) {
|
||||
return [];
|
||||
}
|
||||
debug(`Explicit publish provider: ${(0, builder_util_1.safeStringifyJson)(publishers)}`);
|
||||
return (await Promise.all((0, builder_util_1.asArray)(publishers).map(it => getResolvedPublishConfig(platformPackager, packager, typeof it === "string" ? { provider: it } : it, arch, errorIfCannot))));
|
||||
}
|
||||
function isSuitableWindowsTarget(target) {
|
||||
if (target.name === "appx" && target.options != null && target.options.electronUpdaterAware) {
|
||||
return true;
|
||||
}
|
||||
return target.name === "nsis" || target.name.startsWith("nsis-");
|
||||
}
|
||||
function expandPublishConfig(options, platformPackager, packager, arch) {
|
||||
for (const name of Object.keys(options)) {
|
||||
const value = options[name];
|
||||
if (typeof value === "string") {
|
||||
const archValue = arch == null ? null : builder_util_1.Arch[arch];
|
||||
const expanded = platformPackager == null ? (0, macroExpander_1.expandMacro)(value, archValue, packager.appInfo) : platformPackager.expandMacro(value, archValue);
|
||||
if (expanded !== value) {
|
||||
options[name] = expanded;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function isDetectUpdateChannel(platformSpecificConfiguration, configuration) {
|
||||
const value = platformSpecificConfiguration == null ? null : platformSpecificConfiguration.detectUpdateChannel;
|
||||
return value == null ? configuration.detectUpdateChannel !== false : value;
|
||||
}
|
||||
async function getResolvedPublishConfig(platformPackager, packager, options, arch, errorIfCannot) {
|
||||
options = { ...options };
|
||||
expandPublishConfig(options, platformPackager, packager, arch);
|
||||
let channelFromAppVersion = null;
|
||||
if (options.channel == null &&
|
||||
isDetectUpdateChannel(platformPackager == null ? null : platformPackager.platformSpecificBuildOptions, packager.config)) {
|
||||
channelFromAppVersion = packager.appInfo.channel;
|
||||
}
|
||||
const provider = options.provider;
|
||||
if (provider === "generic") {
|
||||
const o = options;
|
||||
if (o.url == null) {
|
||||
throw new builder_util_1.InvalidConfigurationError(`Please specify "url" for "generic" update server`);
|
||||
}
|
||||
if (channelFromAppVersion != null) {
|
||||
;
|
||||
o.channel = channelFromAppVersion;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
const providerClass = await requireProviderClass(options.provider, packager);
|
||||
if (providerClass != null && providerClass.checkAndResolveOptions != null) {
|
||||
await providerClass.checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot);
|
||||
return options;
|
||||
}
|
||||
if (provider === "keygen") {
|
||||
return {
|
||||
...options,
|
||||
platform: platformPackager === null || platformPackager === void 0 ? void 0 : platformPackager.platform.name,
|
||||
};
|
||||
}
|
||||
const isGithub = provider === "github";
|
||||
if (!isGithub && provider !== "bitbucket") {
|
||||
return options;
|
||||
}
|
||||
let owner = isGithub ? options.owner : options.owner;
|
||||
let project = isGithub ? options.repo : options.slug;
|
||||
if (isGithub && owner == null && project != null) {
|
||||
const index = project.indexOf("/");
|
||||
if (index > 0) {
|
||||
const repo = project;
|
||||
project = repo.substring(0, index);
|
||||
owner = repo.substring(index + 1);
|
||||
}
|
||||
}
|
||||
async function getInfo() {
|
||||
const info = await packager.repositoryInfo;
|
||||
if (info != null) {
|
||||
return info;
|
||||
}
|
||||
const message = `Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).\nPlease see https://electron.build/publish`;
|
||||
if (errorIfCannot) {
|
||||
throw new Error(message);
|
||||
}
|
||||
else {
|
||||
builder_util_1.log.warn(message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!owner || !project) {
|
||||
builder_util_1.log.debug({ reason: "owner or project is not specified explicitly", provider, owner, project }, "calling getInfo");
|
||||
const info = await getInfo();
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
if (!owner) {
|
||||
owner = info.user;
|
||||
}
|
||||
if (!project) {
|
||||
project = info.project;
|
||||
}
|
||||
}
|
||||
if (isGithub) {
|
||||
if (options.token != null && !options.private) {
|
||||
builder_util_1.log.warn('"token" specified in the github publish options. It should be used only for [setFeedURL](module:electron-updater/out/AppUpdater.AppUpdater+setFeedURL).');
|
||||
}
|
||||
//tslint:disable-next-line:no-object-literal-type-assertion
|
||||
return { owner, repo: project, ...options };
|
||||
}
|
||||
else {
|
||||
//tslint:disable-next-line:no-object-literal-type-assertion
|
||||
return { owner, slug: project, ...options };
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=PublishManager.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+10
@@ -0,0 +1,10 @@
|
||||
import { PublishConfiguration, UpdateInfo } from "builder-util-runtime";
|
||||
import { Packager } from "../packager";
|
||||
import { PlatformPackager } from "../platformPackager";
|
||||
export interface UpdateInfoFileTask {
|
||||
readonly file: string;
|
||||
readonly info: UpdateInfo;
|
||||
readonly publishConfiguration: PublishConfiguration;
|
||||
readonly packager: PlatformPackager<any>;
|
||||
}
|
||||
export declare function writeUpdateInfoFiles(updateInfoFileTasks: Array<UpdateInfoFileTask>, packager: Packager): Promise<void>;
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createUpdateInfoTasks = createUpdateInfoTasks;
|
||||
exports.writeUpdateInfoFiles = writeUpdateInfoFiles;
|
||||
const tiny_async_pool_1 = require("tiny-async-pool");
|
||||
const builder_util_1 = require("builder-util");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const lazy_val_1 = require("lazy-val");
|
||||
const path = require("path");
|
||||
const semver = require("semver");
|
||||
const core_1 = require("../core");
|
||||
const hash_1 = require("../util/hash");
|
||||
const PublishManager_1 = require("./PublishManager");
|
||||
async function getReleaseInfo(packager) {
|
||||
const releaseInfo = { ...(packager.platformSpecificBuildOptions.releaseInfo || packager.config.releaseInfo) };
|
||||
if (releaseInfo.releaseNotes == null) {
|
||||
const releaseNotesFile = await packager.getResource(releaseInfo.releaseNotesFile, `release-notes-${packager.platform.buildConfigurationKey}.md`, `release-notes-${packager.platform.name}.md`, `release-notes-${packager.platform.nodeName}.md`, "release-notes.md");
|
||||
const releaseNotes = releaseNotesFile == null ? null : await (0, fs_extra_1.readFile)(releaseNotesFile, "utf-8");
|
||||
// to avoid undefined in the file, check for null
|
||||
if (releaseNotes != null) {
|
||||
releaseInfo.releaseNotes = releaseNotes;
|
||||
}
|
||||
}
|
||||
delete releaseInfo.releaseNotesFile;
|
||||
return releaseInfo;
|
||||
}
|
||||
function isGenerateUpdatesFilesForAllChannels(packager) {
|
||||
const value = packager.platformSpecificBuildOptions.generateUpdatesFilesForAllChannels;
|
||||
return value == null ? packager.config.generateUpdatesFilesForAllChannels : value;
|
||||
}
|
||||
/**
|
||||
if this is an "alpha" version, we need to generate only the "alpha" .yml file
|
||||
if this is a "beta" version, we need to generate both the "alpha" and "beta" .yml file
|
||||
if this is a "stable" version, we need to generate all the "alpha", "beta" and "stable" .yml file
|
||||
*/
|
||||
function computeChannelNames(packager, publishConfig) {
|
||||
const currentChannel = publishConfig.channel || "latest";
|
||||
// for GitHub should be pre-release way be used
|
||||
if (currentChannel === "alpha" || publishConfig.provider === "github" || !isGenerateUpdatesFilesForAllChannels(packager)) {
|
||||
return [currentChannel];
|
||||
}
|
||||
switch (currentChannel) {
|
||||
case "beta":
|
||||
return [currentChannel, "alpha"];
|
||||
case "latest":
|
||||
return [currentChannel, "alpha", "beta"];
|
||||
default:
|
||||
return [currentChannel];
|
||||
}
|
||||
}
|
||||
function getUpdateInfoFileName(channel, packager, arch) {
|
||||
const osSuffix = packager.platform === core_1.Platform.WINDOWS ? "" : `-${packager.platform.buildConfigurationKey}`;
|
||||
return `${channel}${osSuffix}${getArchPrefixForUpdateFile(arch, packager)}.yml`;
|
||||
}
|
||||
function getArchPrefixForUpdateFile(arch, packager) {
|
||||
if (arch == null || arch === builder_util_1.Arch.x64 || packager.platform !== core_1.Platform.LINUX) {
|
||||
return "";
|
||||
}
|
||||
return arch === builder_util_1.Arch.armv7l ? "-arm" : `-${builder_util_1.Arch[arch]}`;
|
||||
}
|
||||
function computeIsisElectronUpdater1xCompatibility(updaterCompatibility, publishConfiguration, packager) {
|
||||
if (updaterCompatibility != null) {
|
||||
return semver.satisfies("1.0.0", updaterCompatibility);
|
||||
}
|
||||
// spaces is a new publish provider, no need to keep backward compatibility
|
||||
if (publishConfiguration.provider === "spaces") {
|
||||
return false;
|
||||
}
|
||||
const updaterVersion = packager.metadata.dependencies == null ? null : packager.metadata.dependencies["electron-updater"];
|
||||
return updaterVersion == null || semver.lt(updaterVersion, "4.0.0");
|
||||
}
|
||||
/** @internal */
|
||||
async function createUpdateInfoTasks(event, _publishConfigs) {
|
||||
const packager = event.packager;
|
||||
const publishConfigs = await (0, PublishManager_1.getPublishConfigsForUpdateInfo)(packager, _publishConfigs, event.arch);
|
||||
if (publishConfigs == null || publishConfigs.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const outDir = event.target.outDir;
|
||||
const version = packager.appInfo.version;
|
||||
const sha2 = new lazy_val_1.Lazy(() => (0, hash_1.hashFile)(event.file, "sha256", "hex"));
|
||||
const isMac = packager.platform === core_1.Platform.MAC;
|
||||
const createdFiles = new Set();
|
||||
const sharedInfo = await createUpdateInfo(version, event, await getReleaseInfo(packager));
|
||||
const tasks = [];
|
||||
const electronUpdaterCompatibility = packager.platformSpecificBuildOptions.electronUpdaterCompatibility || packager.config.electronUpdaterCompatibility || ">=2.15";
|
||||
for (const publishConfiguration of publishConfigs) {
|
||||
let dir = outDir;
|
||||
if (publishConfigs.length > 1 && publishConfiguration !== publishConfigs[0]) {
|
||||
dir = path.join(outDir, publishConfiguration.provider);
|
||||
}
|
||||
let isElectronUpdater1xCompatibility = computeIsisElectronUpdater1xCompatibility(electronUpdaterCompatibility, publishConfiguration, packager.info);
|
||||
let info = sharedInfo;
|
||||
// noinspection JSDeprecatedSymbols
|
||||
if (isElectronUpdater1xCompatibility && packager.platform === core_1.Platform.WINDOWS) {
|
||||
info = {
|
||||
...info,
|
||||
};
|
||||
info.sha2 = await sha2.value;
|
||||
}
|
||||
if (event.safeArtifactName != null && publishConfiguration.provider === "github") {
|
||||
const newFiles = info.files.slice();
|
||||
newFiles[0].url = event.safeArtifactName;
|
||||
info = {
|
||||
...info,
|
||||
files: newFiles,
|
||||
path: event.safeArtifactName,
|
||||
};
|
||||
}
|
||||
for (const channel of computeChannelNames(packager, publishConfiguration)) {
|
||||
if (isMac && isElectronUpdater1xCompatibility && event.file.endsWith(".zip")) {
|
||||
// write only for first channel (generateUpdatesFilesForAllChannels is a new functionality, no need to generate old mac update info file)
|
||||
isElectronUpdater1xCompatibility = false;
|
||||
await writeOldMacInfo(publishConfiguration, outDir, dir, channel, createdFiles, version, packager);
|
||||
}
|
||||
const updateInfoFile = path.join(dir, getUpdateInfoFileName(channel, packager, event.arch));
|
||||
if (createdFiles.has(updateInfoFile)) {
|
||||
continue;
|
||||
}
|
||||
createdFiles.add(updateInfoFile);
|
||||
// artifact should be uploaded only to designated publish provider
|
||||
tasks.push({
|
||||
file: updateInfoFile,
|
||||
info,
|
||||
publishConfiguration,
|
||||
packager,
|
||||
});
|
||||
}
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
async function createUpdateInfo(version, event, releaseInfo) {
|
||||
const customUpdateInfo = event.updateInfo;
|
||||
const url = path.basename(event.file);
|
||||
const sha512 = (customUpdateInfo == null ? null : customUpdateInfo.sha512) || (await (0, hash_1.hashFile)(event.file));
|
||||
const files = [{ url, sha512 }];
|
||||
const result = {
|
||||
// @ts-ignore
|
||||
version,
|
||||
// @ts-ignore
|
||||
files,
|
||||
// @ts-ignore
|
||||
path: url /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */,
|
||||
// @ts-ignore
|
||||
sha512 /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */,
|
||||
...releaseInfo,
|
||||
};
|
||||
if (customUpdateInfo != null) {
|
||||
// file info or nsis web installer packages info
|
||||
Object.assign("sha512" in customUpdateInfo ? files[0] : result, customUpdateInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function writeUpdateInfoFiles(updateInfoFileTasks, packager) {
|
||||
// zip must be first and zip info must be used for old path/sha512 properties in the update info
|
||||
updateInfoFileTasks.sort((a, b) => (a.info.files[0].url.endsWith(".zip") ? 0 : 100) - (b.info.files[0].url.endsWith(".zip") ? 0 : 100));
|
||||
const updateChannelFileToInfo = new Map();
|
||||
for (const task of updateInfoFileTasks) {
|
||||
// https://github.com/electron-userland/electron-builder/pull/2994
|
||||
const key = `${task.file}@${(0, builder_util_1.safeStringifyJson)(task.publishConfiguration, new Set(["releaseType"]))}`;
|
||||
const existingTask = updateChannelFileToInfo.get(key);
|
||||
if (existingTask == null) {
|
||||
updateChannelFileToInfo.set(key, task);
|
||||
continue;
|
||||
}
|
||||
existingTask.info.files.push(...task.info.files);
|
||||
}
|
||||
const releaseDate = new Date().toISOString();
|
||||
const concurrency = 4;
|
||||
await (0, tiny_async_pool_1.default)(concurrency, Array.from(updateChannelFileToInfo.values()), async (task) => {
|
||||
const publishConfig = task.publishConfiguration;
|
||||
if (publishConfig.publishAutoUpdate === false) {
|
||||
builder_util_1.log.debug({
|
||||
provider: publishConfig.provider,
|
||||
reason: "publishAutoUpdate is set to false",
|
||||
}, "auto update metadata file not published");
|
||||
return;
|
||||
}
|
||||
if (task.info.releaseDate == null) {
|
||||
task.info.releaseDate = releaseDate;
|
||||
}
|
||||
const fileContent = Buffer.from((0, builder_util_1.serializeToYaml)(task.info, false, true));
|
||||
await (0, fs_extra_1.outputFile)(task.file, fileContent);
|
||||
await packager.emitArtifactCreated({
|
||||
file: task.file,
|
||||
fileContent,
|
||||
arch: null,
|
||||
packager: task.packager,
|
||||
target: null,
|
||||
publishConfig,
|
||||
});
|
||||
});
|
||||
}
|
||||
// backward compatibility - write json file
|
||||
async function writeOldMacInfo(publishConfig, outDir, dir, channel, createdFiles, version, packager) {
|
||||
const isGitHub = publishConfig.provider === "github";
|
||||
const updateInfoFile = isGitHub && outDir === dir ? path.join(dir, "github", `${channel}-mac.json`) : path.join(dir, `${channel}-mac.json`);
|
||||
if (!createdFiles.has(updateInfoFile)) {
|
||||
createdFiles.add(updateInfoFile);
|
||||
await (0, fs_extra_1.outputJson)(updateInfoFile, {
|
||||
version,
|
||||
releaseDate: new Date().toISOString(),
|
||||
url: (0, PublishManager_1.computeDownloadUrl)(publishConfig, packager.generateName2("zip", "mac", isGitHub), packager),
|
||||
}, { spaces: 2 });
|
||||
await packager.info.emitArtifactCreated({
|
||||
file: updateInfoFile,
|
||||
arch: null,
|
||||
packager,
|
||||
target: null,
|
||||
publishConfig,
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=updateInfoBuilder.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user