Skip to content

Commit e0b0e35

Browse files
authored
chore: refactor Publishers out of app-builder-lib into electron-publish and add to docs site (#8596)
1 parent d4ea0d9 commit e0b0e35

33 files changed

+198
-166
lines changed

.changeset/fluffy-wolves-smile.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"app-builder-lib": patch
3+
"builder-util": patch
4+
"dmg-builder": patch
5+
"electron-builder": patch
6+
"electron-builder-squirrel-windows": patch
7+
"electron-publish": patch
8+
---
9+
10+
chore: refactor files for publishing to electron-publish

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ nav:
8686
- electron-builder: electron-builder/globals.md
8787
- app-builder-lib: app-builder-lib/globals.md
8888
- electron-updater: electron-updater/globals.md
89+
- electron-publish: electron-publish/globals.md
8990

9091
- Configuration:
9192
- Common Configuration: configuration.md

packages/app-builder-lib/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"dotenv-expand": "^11.0.6",
6767
"ejs": "^3.1.8",
6868
"electron-publish": "workspace:*",
69-
"form-data": "^4.0.0",
7069
"fs-extra": "^10.1.0",
7170
"hosted-git-info": "^4.1.0",
7271
"is-ci": "^3.0.0",
@@ -76,7 +75,6 @@
7675
"lazy-val": "^1.0.5",
7776
"minimatch": "^10.0.0",
7877
"resedit": "^1.7.0",
79-
"sanitize-filename": "^1.6.3",
8078
"semver": "^7.3.8",
8179
"tar": "^6.1.12",
8280
"temp-file": "^3.4.0"

packages/app-builder-lib/scheme.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,8 @@
19651965
"string"
19661966
]
19671967
}
1968-
]
1968+
],
1969+
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
19691970
},
19701971
"releaseInfo": {
19711972
"$ref": "#/definitions/ReleaseInfo",
@@ -2742,7 +2743,8 @@
27422743
"string"
27432744
]
27442745
}
2745-
]
2746+
],
2747+
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
27462748
},
27472749
"releaseInfo": {
27482750
"$ref": "#/definitions/ReleaseInfo",
@@ -3383,7 +3385,8 @@
33833385
"string"
33843386
]
33853387
}
3386-
]
3388+
],
3389+
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
33873390
},
33883391
"releaseInfo": {
33893392
"$ref": "#/definitions/ReleaseInfo",
@@ -6453,7 +6456,8 @@
64536456
"string"
64546457
]
64556458
}
6456-
]
6459+
],
6460+
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
64576461
},
64586462
"publisherName": {
64596463
"anyOf": [
@@ -7547,7 +7551,8 @@
75477551
"string"
75487552
]
75497553
}
7550-
]
7554+
],
7555+
"description": "Publisher configuration. See [Auto Update](./publish.md) for more information."
75517556
},
75527557
"releaseInfo": {
75537558
"$ref": "#/definitions/ReleaseInfo",

packages/app-builder-lib/src/appInfo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { prerelease } from "semver"
33
import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOptions"
44
import { Packager } from "./packager"
55
import { expandMacro } from "./util/macroExpander"
6-
import { sanitizeFileName } from "./util/filename"
6+
import { sanitizeFileName } from "builder-util/out/filename"
77

88
// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
99
// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/

packages/app-builder-lib/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PublishOptions } from "electron-publish/out/publisher"
1+
import { PublishOptions } from "electron-publish"
22
import { log, InvalidConfigurationError, executeFinally } from "builder-util"
33
import { asArray } from "builder-util-runtime"
44
import { Packager } from "./packager"

packages/app-builder-lib/src/linuxPackager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import FpmTarget from "./targets/FpmTarget"
99
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
1010
import SnapTarget from "./targets/snap"
1111
import { createCommonTarget } from "./targets/targetFactory"
12-
import { sanitizeFileName } from "./util/filename"
12+
import { sanitizeFileName } from "builder-util/out/filename"
1313

1414
export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
1515
readonly executableName: string

packages/app-builder-lib/src/options/CommonWindowsInstallerConfiguration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InvalidConfigurationError, isEmptyOrSpaces } from "builder-util"
2-
import { sanitizeFileName } from "../util/filename"
2+
import { sanitizeFileName } from "builder-util/out/filename"
33
import { WinPackager } from "../winPackager"
44

55
export interface CommonWindowsInstallerConfiguration {

packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions, Fil
163163
*/
164164
readonly electronUpdaterCompatibility?: string | null
165165

166+
/**
167+
* Publisher configuration. See [Auto Update](./publish.md) for more information.
168+
*/
166169
publish?: Publish
167170

168171
/**

packages/app-builder-lib/src/publish/PublishManager.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ import {
1313
BitbucketOptions,
1414
} from "builder-util-runtime"
1515
import _debug from "debug"
16-
import { getCiTag, PublishContext, Publisher, PublishOptions, UploadTask } from "electron-publish"
17-
import { GitHubPublisher } from "electron-publish/out/gitHubPublisher"
18-
import { MultiProgress } from "electron-publish/out/multiProgress"
19-
import S3Publisher from "./s3/s3Publisher"
20-
import SpacesPublisher from "./s3/spacesPublisher"
16+
import {
17+
BitbucketPublisher,
18+
getCiTag,
19+
GitHubPublisher,
20+
KeygenPublisher,
21+
PublishContext,
22+
Publisher,
23+
PublishOptions,
24+
S3Publisher,
25+
SnapStorePublisher,
26+
SpacesPublisher,
27+
UploadTask,
28+
} from "electron-publish"
2129
import { writeFile } from "fs/promises"
2230
import * as isCi from "is-ci"
2331
import * as path from "path"
@@ -28,10 +36,8 @@ import { Packager } from "../packager"
2836
import { PlatformPackager } from "../platformPackager"
2937
import { expandMacro } from "../util/macroExpander"
3038
import { WinPackager } from "../winPackager"
31-
import { SnapStorePublisher } from "./SnapStorePublisher"
3239
import { createUpdateInfoTasks, UpdateInfoFileTask, writeUpdateInfoFiles } from "./updateInfoBuilder"
33-
import { KeygenPublisher } from "./KeygenPublisher"
34-
import { BitbucketPublisher } from "./BitbucketPublisher"
40+
import { MultiProgress } from "electron-publish/out/multiProgress"
3541

3642
const publishForPrWarning =
3743
"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)" +

packages/builder-util/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"https-proxy-agent": "^7.0.0",
2929
"is-ci": "^3.0.0",
3030
"js-yaml": "^4.1.0",
31+
"sanitize-filename": "^1.6.3",
3132
"source-map-support": "^0.5.19",
3233
"stat-mode": "^1.0.0",
3334
"temp-file": "^3.4.0"

packages/dmg-builder/src/dmg.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { findIdentity, isSignAllowed } from "app-builder-lib/out/codeSign/macCod
33
import { MacPackager } from "app-builder-lib/out/macPackager"
44
import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
55
import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
6-
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
6+
import { sanitizeFileName } from "builder-util/out/filename"
77
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, copyDir, copyFile, exists, statOrNull } from "builder-util"
88
import { CancellationToken } from "builder-util-runtime"
99
import { stat } from "fs-extra"

packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
1+
import { sanitizeFileName } from "builder-util/out/filename"
22
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
33
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
44
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"

packages/electron-builder/src/cli/create-self-signed-cert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
1+
import { sanitizeFileName } from "builder-util/out/filename"
22
import { exec, log, spawn, TmpDir, unlinkIfExists } from "builder-util"
33
import * as chalk from "chalk"
44
import { getSignVendorPath } from "app-builder-lib/out/codeSign/windowsSignToolManager"

packages/electron-builder/src/publish.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export function configurePublishCommand(yargs: yargs.Argv): yargs.Argv {
4040
.demandOption("files")
4141
}
4242

43-
export async function publish(args: { files: string[]; version: string | undefined; config: string | undefined }) {
43+
export async function publish(args: { files: string[]; version: string | undefined; configurationFilePath: string | undefined }) {
4444
const uploadTasks = args.files.map(f => {
4545
return {
4646
file: path.resolve(f),
4747
arch: null,
4848
}
4949
})
50-
return publishArtifactsWithOptions(uploadTasks, args.version, args.config)
50+
return publishArtifactsWithOptions(uploadTasks, args.version, args.configurationFilePath)
5151
}
5252

5353
export async function publishArtifactsWithOptions(

packages/electron-publish/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "electron-publish",
33
"version": "26.0.0-alpha.1",
4-
"main": "out/publisher.js",
4+
"main": "out/index.js",
55
"author": "Vladimir Krivosheev",
66
"license": "MIT",
77
"repository": {
@@ -19,11 +19,12 @@
1919
"builder-util": "workspace:*",
2020
"builder-util-runtime": "workspace:*",
2121
"chalk": "^4.1.2",
22+
"form-data": "^4.0.0",
2223
"fs-extra": "^10.1.0",
2324
"lazy-val": "^1.0.5",
2425
"mime": "^2.5.2"
2526
},
26-
"typings": "./out/publisher.d.ts",
27+
"typings": "./out/index.d.ts",
2728
"devDependencies": {
2829
"@types/mime": "2.0.3"
2930
}

packages/app-builder-lib/src/publish/BitbucketPublisher.ts renamed to packages/electron-publish/src/bitbucketPublisher.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Arch, InvalidConfigurationError, isEmptyOrSpaces, log } from "builder-util"
22
import { httpExecutor } from "builder-util"
33
import { ClientRequest, RequestOptions } from "http"
4-
import { HttpPublisher, PublishContext } from "electron-publish"
4+
import { PublishContext } from "./"
5+
import { HttpPublisher } from "./httpPublisher"
56
import { BitbucketOptions } from "builder-util-runtime/out/publishOptions"
67
import { configureRequestOptions, HttpExecutor } from "builder-util-runtime"
78
import * as FormData from "form-data"

packages/electron-publish/src/gitHubPublisher.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { ClientRequest } from "http"
55
import { Lazy } from "lazy-val"
66
import * as mime from "mime"
77
import { parse as parseUrl, UrlWithStringQuery } from "url"
8-
import { getCiTag, HttpPublisher, PublishContext, PublishOptions } from "./publisher"
8+
import { getCiTag } from "./publisher"
9+
import { HttpPublisher } from "./httpPublisher"
10+
import { PublishContext, PublishOptions } from "./index"
911

1012
export interface Release {
1113
id: number
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Arch } from "builder-util"
2+
import { stat } from "fs-extra"
3+
import { ClientRequest } from "http"
4+
import { basename } from "path/posix"
5+
import { Publisher } from "./publisher"
6+
import { PublishContext, UploadTask } from "."
7+
8+
export abstract class HttpPublisher extends Publisher {
9+
protected constructor(
10+
protected readonly context: PublishContext,
11+
private readonly useSafeArtifactName = false
12+
) {
13+
super(context)
14+
}
15+
16+
async upload(task: UploadTask): Promise<any> {
17+
const fileName = (this.useSafeArtifactName ? task.safeArtifactName : null) || basename(task.file)
18+
19+
if (task.fileContent != null) {
20+
await this.doUpload(
21+
fileName,
22+
task.arch || Arch.x64,
23+
task.fileContent.length,
24+
(request, reject) => {
25+
if (task.timeout) {
26+
request.setTimeout(task.timeout, () => {
27+
request.destroy()
28+
reject(new Error("Request timed out"))
29+
})
30+
}
31+
return request.end(task.fileContent)
32+
},
33+
task.file
34+
)
35+
return
36+
}
37+
38+
const fileStat = await stat(task.file)
39+
40+
const progressBar = this.createProgressBar(fileName, fileStat.size)
41+
return this.doUpload(
42+
fileName,
43+
task.arch || Arch.x64,
44+
fileStat.size,
45+
(request, reject) => {
46+
if (progressBar != null) {
47+
// reset (because can be called several times (several attempts)
48+
progressBar.update(0)
49+
}
50+
if (task.timeout) {
51+
request.setTimeout(task.timeout, () => {
52+
request.destroy()
53+
reject(new Error("Request timed out"))
54+
})
55+
}
56+
return this.createReadStreamAndProgressBar(task.file, fileStat, progressBar, reject).pipe(request)
57+
},
58+
task.file
59+
)
60+
}
61+
62+
protected abstract doUpload(
63+
fileName: string,
64+
arch: Arch,
65+
dataLength: number,
66+
requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void,
67+
file: string
68+
): Promise<any>
69+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { CancellationToken } from "builder-util-runtime"
2+
import { MultiProgress } from "./multiProgress"
3+
import { Arch } from "builder-util"
4+
5+
export { SpacesPublisher } from "./s3/spacesPublisher"
6+
export { KeygenPublisher } from "./keygenPublisher"
7+
export { SnapStorePublisher } from "./snapStorePublisher"
8+
export { S3Publisher } from "./s3/s3Publisher"
9+
export { GitHubPublisher } from "./gitHubPublisher"
10+
export { BitbucketPublisher } from "./bitbucketPublisher"
11+
12+
export type PublishPolicy = "onTag" | "onTagOrDraft" | "always" | "never"
13+
14+
export { ProgressCallback } from "./progress"
15+
16+
export interface PublishOptions {
17+
publish?: PublishPolicy | null
18+
}
19+
20+
export { Publisher, getCiTag } from "./publisher"
21+
export { HttpPublisher } from "./httpPublisher"
22+
23+
export interface PublishContext {
24+
readonly cancellationToken: CancellationToken
25+
readonly progress: MultiProgress | null
26+
}
27+
28+
export interface UploadTask {
29+
file: string
30+
fileContent?: Buffer | null
31+
32+
arch: Arch | null
33+
safeArtifactName?: string | null
34+
timeout?: number | null
35+
}

packages/app-builder-lib/src/publish/KeygenPublisher.ts renamed to packages/electron-publish/src/keygenPublisher.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Arch, InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
22
import { httpExecutor } from "builder-util"
33
import { ClientRequest, RequestOptions } from "http"
4-
import { HttpPublisher, PublishContext } from "electron-publish"
4+
import { PublishContext } from "./"
5+
import { HttpPublisher } from "./httpPublisher"
56
import { KeygenOptions } from "builder-util-runtime/out/publishOptions"
67
import { configureRequestOptions, HttpExecutor, parseJson } from "builder-util-runtime"
7-
import { getCompleteExtname } from "../util/filename"
8+
import { getCompleteExtname } from "builder-util/out/filename"
89

910
type RecursivePartial<T> = {
1011
[P in keyof T]?: RecursivePartial<T[P]>

0 commit comments

Comments
 (0)