Skip to content

Commit 1533501

Browse files
authored
feat: Moved electronLanguages to global config to support win/linux (#7516)
* Removing `remoteBuild` functionality, it stopped working long ago when the service died. * Moved `electronLanguages` to global config to support win/linux
1 parent 63772e1 commit 1533501

15 files changed

+108
-445
lines changed

.changeset/brave-crabs-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": minor
3+
---
4+
5+
feat: Moved `electronLanguages` to global config to support win/linux

docs/configuration/configuration.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
175175
<p><code id="Configuration-beforeBuild">beforeBuild</code> (context: BeforeBuildContext) =&gt; Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when <code>npmRebuild</code> is set to <code>true</code>. Resolving to <code>false</code> will skip dependencies install or rebuild.</p>
176176
<p>If provided and <code>node_modules</code> are missing, it will not invoke production dependencies check.</p>
177177
</li>
178-
</ul>
179-
<hr>
180-
<ul>
181-
<li><code id="Configuration-remoteBuild">remoteBuild</code> = <code>true</code> Boolean - Whether to build using Electron Build Service if target not supported on current OS.</li>
182-
<li><code id="Configuration-includePdb">includePdb</code> = <code>false</code> Boolean - Whether to include PDB files.</li>
183-
<li><code id="Configuration-removePackageScripts">removePackageScripts</code> = <code>true</code> Boolean - Whether to remove <code>scripts</code> field from <code>package.json</code> files.</li>
184-
<li><code id="Configuration-removePackageKeywords">removePackageKeywords</code> = <code>true</code> Boolean - Whether to remove <code>keywords</code> field from <code>package.json</code> files.</li>
178+
<li>
179+
<p><code id="Configuration-includePdb">includePdb</code> = <code>false</code> Boolean - Whether to include PDB files.</p>
180+
</li>
181+
<li>
182+
<p><code id="Configuration-removePackageScripts">removePackageScripts</code> = <code>true</code> Boolean - Whether to remove <code>scripts</code> field from <code>package.json</code> files.</p>
183+
</li>
184+
<li>
185+
<p><code id="Configuration-removePackageKeywords">removePackageKeywords</code> = <code>true</code> Boolean - Whether to remove <code>keywords</code> field from <code>package.json</code> files.</p>
186+
</li>
185187
</ul>
186188

187189
<!-- end of generated block -->

docs/configuration/mac.md

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ The top-level [mac](configuration.md#Configuration-mac) key contains set of opti
7272
<p><code id="MacConfiguration-requirements">requirements</code> String | “undefined” - Path of <a href="https://developer.apple.com/library/mac/documentation/Security/Conceptual/CodeSigningGuide/RequirementLang/RequirementLang.html">requirements file</a> used in signing. Not applicable for MAS.</p>
7373
</li>
7474
<li>
75-
<p><code id="MacConfiguration-electronLanguages">electronLanguages</code> Array&lt;String&gt; | String - The electron locales. By default Electron locales used as is.</p>
76-
</li>
77-
<li>
7875
<p><code id="MacConfiguration-extraDistFiles">extraDistFiles</code> Array&lt;String&gt; | String | “undefined” - Extra files to put in archive. Not applicable for <code>tar.*</code>.</p>
7976
</li>
8077
<li>

docs/generated/PlatformSpecificBuildOptions.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<li><code id="Protocol-role">role</code> = <code>Editor</code> “Editor” | “Viewer” | “Shell” | “None” - <em>macOS-only</em> The app’s role with respect to the type.</li>
6767
</ul>
6868
</li>
69+
<li><code id="PlatformSpecificBuildOptions-electronLanguages">electronLanguages</code> Array&lt;String&gt; | String - The electron locales to keep. By default, all Electron locales used as-is.</li>
6970
</ul>
7071
<hr>
7172
<ul>

packages/app-builder-lib/scheme.json

+44-7
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,20 @@
17311731
"description": "Whether to infer update channel from application version pre-release components. e.g. if version `0.12.1-alpha.1`, channel will be set to `alpha`. Otherwise to `latest`.",
17321732
"type": "boolean"
17331733
},
1734+
"electronLanguages": {
1735+
"anyOf": [
1736+
{
1737+
"items": {
1738+
"type": "string"
1739+
},
1740+
"type": "array"
1741+
},
1742+
{
1743+
"type": "string"
1744+
}
1745+
],
1746+
"description": "The electron locales to keep. By default, all Electron locales used as-is."
1747+
},
17341748
"electronUpdaterCompatibility": {
17351749
"description": "The [electron-updater compatibility](/auto-update#compatibility) semver range.",
17361750
"type": [
@@ -2394,7 +2408,7 @@
23942408
"type": "string"
23952409
}
23962410
],
2397-
"description": "The electron locales. By default Electron locales used as is."
2411+
"description": "The electron locales to keep. By default, all Electron locales used as-is."
23982412
},
23992413
"electronUpdaterCompatibility": {
24002414
"description": "The [electron-updater compatibility](/auto-update#compatibility) semver range.",
@@ -3019,7 +3033,7 @@
30193033
"type": "string"
30203034
}
30213035
],
3022-
"description": "The electron locales. By default Electron locales used as is."
3036+
"description": "The electron locales to keep. By default, all Electron locales used as-is."
30233037
},
30243038
"electronUpdaterCompatibility": {
30253039
"description": "The [electron-updater compatibility](/auto-update#compatibility) semver range.",
@@ -6006,6 +6020,20 @@
60066020
"description": "Whether to infer update channel from application version pre-release components. e.g. if version `0.12.1-alpha.1`, channel will be set to `alpha`. Otherwise to `latest`.",
60076021
"type": "boolean"
60086022
},
6023+
"electronLanguages": {
6024+
"anyOf": [
6025+
{
6026+
"items": {
6027+
"type": "string"
6028+
},
6029+
"type": "array"
6030+
},
6031+
{
6032+
"type": "string"
6033+
}
6034+
],
6035+
"description": "The electron locales to keep. By default, all Electron locales used as-is."
6036+
},
60096037
"electronUpdaterCompatibility": {
60106038
"description": "The [electron-updater compatibility](/auto-update#compatibility) semver range.",
60116039
"type": [
@@ -6667,6 +6695,20 @@
66676695
"$ref": "#/definitions/ElectronDownloadOptions",
66686696
"description": "The [electron-download](https://github.com/electron-userland/electron-download#usage) options."
66696697
},
6698+
"electronLanguages": {
6699+
"anyOf": [
6700+
{
6701+
"items": {
6702+
"type": "string"
6703+
},
6704+
"type": "array"
6705+
},
6706+
{
6707+
"type": "string"
6708+
}
6709+
],
6710+
"description": "The electron locales to keep. By default, all Electron locales used as-is."
6711+
},
66706712
"electronUpdaterCompatibility": {
66716713
"description": "The [electron-updater compatibility](/auto-update#compatibility) semver range.",
66726714
"type": [
@@ -7142,11 +7184,6 @@
71427184
"$ref": "#/definitions/ReleaseInfo",
71437185
"description": "The release info. Intended for command line usage:\n\n```\n-c.releaseInfo.releaseNotes=\"new features\"\n```"
71447186
},
7145-
"remoteBuild": {
7146-
"default": true,
7147-
"description": "Whether to build using Electron Build Service if target not supported on current OS.",
7148-
"type": "boolean"
7149-
},
71507187
"removePackageKeywords": {
71517188
"default": true,
71527189
"description": "Whether to remove `keywords` field from `package.json` files.",

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

-6
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,6 @@ export interface Configuration extends PlatformSpecificBuildOptions {
255255
*/
256256
readonly beforeBuild?: ((context: BeforeBuildContext) => Promise<any>) | string | null
257257

258-
/**
259-
* Whether to build using Electron Build Service if target not supported on current OS.
260-
* @default true
261-
*/
262-
readonly remoteBuild?: boolean
263-
264258
/**
265259
* Whether to include PDB files.
266260
* @default false

packages/app-builder-lib/src/electron/ElectronFramework.ts

+40-33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { BeforeCopyExtraFilesOptions, Framework, PrepareApplicationStageDirector
88
import { Packager, Platform } from "../index"
99
import { LinuxPackager } from "../linuxPackager"
1010
import MacPackager from "../macPackager"
11-
import { isSafeToUnpackElectronOnRemoteBuildServer } from "../platformPackager"
1211
import { getTemplatePath } from "../util/pathManager"
1312
import { createMacApp } from "./electronMac"
1413
import { computeElectronVersion, getElectronVersionFromInstalled } from "./electronVersion"
@@ -70,44 +69,55 @@ function createDownloadOpts(opts: Configuration, platform: ElectronPlatformName,
7069
}
7170

7271
async function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {
73-
const packager = options.packager
74-
const appOutDir = options.appOutDir
72+
const { appOutDir, packager } = options
7573
const electronBranding = createBrandingOpts(packager.config)
7674
if (packager.platform === Platform.LINUX) {
77-
if (!isSafeToUnpackElectronOnRemoteBuildServer(packager)) {
78-
const linuxPackager = packager as LinuxPackager
79-
const executable = path.join(appOutDir, linuxPackager.executableName)
80-
await rename(path.join(appOutDir, electronBranding.projectName), executable)
81-
}
75+
const linuxPackager = packager as LinuxPackager
76+
const executable = path.join(appOutDir, linuxPackager.executableName)
77+
await rename(path.join(appOutDir, electronBranding.projectName), executable)
8278
} else if (packager.platform === Platform.WINDOWS) {
8379
const executable = path.join(appOutDir, `${packager.appInfo.productFilename}.exe`)
8480
await rename(path.join(appOutDir, `${electronBranding.projectName}.exe`), executable)
8581
} else {
8682
await createMacApp(packager as MacPackager, appOutDir, options.asarIntegrity, (options.platformName as ElectronPlatformName) === "mas")
83+
}
84+
await removeUnusedLanguagesIfNeeded(options)
85+
}
8786

88-
const wantedLanguages = asArray(packager.platformSpecificBuildOptions.electronLanguages)
89-
if (wantedLanguages.length === 0) {
90-
return
91-
}
87+
async function removeUnusedLanguagesIfNeeded(options: BeforeCopyExtraFilesOptions) {
88+
const {
89+
packager: { config, platformSpecificBuildOptions },
90+
} = options
91+
const wantedLanguages = asArray(platformSpecificBuildOptions.electronLanguages || config.electronLanguages)
92+
if (!wantedLanguages.length) {
93+
return
94+
}
9295

93-
// noinspection SpellCheckingInspection
94-
const langFileExt = ".lproj"
95-
const resourcesDir = packager.getResourcesDir(appOutDir)
96-
await BluebirdPromise.map(
97-
readdir(resourcesDir),
98-
file => {
99-
if (!file.endsWith(langFileExt)) {
100-
return
101-
}
102-
103-
const language = file.substring(0, file.length - langFileExt.length)
104-
if (!wantedLanguages.includes(language)) {
105-
return fs.rm(path.join(resourcesDir, file), { recursive: true, force: true })
106-
}
96+
const { dir, langFileExt } = getLocalesConfig(options)
97+
// noinspection SpellCheckingInspection
98+
await BluebirdPromise.map(
99+
readdir(dir),
100+
file => {
101+
if (!file.endsWith(langFileExt)) {
107102
return
108-
},
109-
CONCURRENCY
110-
)
103+
}
104+
105+
const language = file.substring(0, file.length - langFileExt.length)
106+
if (!wantedLanguages.includes(language)) {
107+
return fs.rm(path.join(dir, file), { recursive: true, force: true })
108+
}
109+
return
110+
},
111+
CONCURRENCY
112+
)
113+
114+
function getLocalesConfig(options: BeforeCopyExtraFilesOptions) {
115+
const { appOutDir, packager } = options
116+
if (packager.platform === Platform.MAC) {
117+
return { dir: packager.getResourcesDir(appOutDir), langFileExt: ".lproj" }
118+
} else {
119+
return { dir: path.join(packager.getResourcesDir(appOutDir), "..", "locales"), langFileExt: ".pak" }
120+
}
111121
}
112122
}
113123

@@ -172,17 +182,14 @@ async function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, o
172182
const zipFile = `electron-v${options.version}-${platformName}-${options.arch}.zip`
173183
const resolvedDist = path.isAbsolute(dist) ? dist : path.resolve(packager.projectDir, dist)
174184
if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {
175-
log.info({ resolvedDist, zipFile }, "Resolved electronDist")
185+
log.info({ resolvedDist, zipFile }, "resolved electronDist")
176186
options.cache = resolvedDist
177187
dist = null
178188
}
179189
}
180190

181191
let isFullCleanup = false
182192
if (dist == null) {
183-
if (isSafeToUnpackElectronOnRemoteBuildServer(packager)) {
184-
return
185-
}
186193
await executeAppBuilder(["unpack-electron", "--configuration", JSON.stringify([options]), "--output", appOutDir, "--distMacOsAppName", distMacOsAppName])
187194
} else {
188195
isFullCleanup = true

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

+3-50
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Arch, AsyncTaskManager, log } from "builder-util"
2-
import { DIR_TARGET, Platform, Target, TargetSpecificOptions } from "./core"
1+
import { Arch } from "builder-util"
2+
import { DIR_TARGET, Platform, Target } from "./core"
33
import { LinuxConfiguration } from "./options/linuxOptions"
44
import { Packager } from "./packager"
55
import { PlatformPackager } from "./platformPackager"
6-
import { RemoteBuilder } from "./remoteBuilder/RemoteBuilder"
76
import AppImageTarget from "./targets/AppImageTarget"
87
import FlatpakTarget from "./targets/FlatpakTarget"
98
import FpmTarget from "./targets/FpmTarget"
@@ -35,8 +34,6 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
3534
return helper
3635
}
3736

38-
let remoteBuilder: RemoteBuilder | null = null
39-
4037
for (const name of targets) {
4138
if (name === DIR_TARGET) {
4239
continue
@@ -68,56 +65,12 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
6865
return createCommonTarget(name, outDir, this)
6966
}
7067

71-
const target = new targetClass(name, this, getHelper(), outDir)
72-
if (process.platform === "win32" || process.env._REMOTE_BUILD) {
73-
if (remoteBuilder == null) {
74-
remoteBuilder = new RemoteBuilder(this)
75-
}
76-
// return remoteBuilder.buildTarget(this, arch, appOutDir, this.packager)
77-
return new RemoteTarget(target, remoteBuilder)
78-
}
79-
return target
68+
return new targetClass(name, this, getHelper(), outDir)
8069
})
8170
}
8271
}
8372
}
8473

85-
class RemoteTarget extends Target {
86-
private buildTaskManager = new AsyncTaskManager(this.remoteBuilder.packager.info.cancellationToken)
87-
88-
get options(): TargetSpecificOptions | null | undefined {
89-
return this.target.options
90-
}
91-
92-
get outDir(): string {
93-
return this.target.outDir
94-
}
95-
96-
constructor(private readonly target: Target, private readonly remoteBuilder: RemoteBuilder) {
97-
super(
98-
target.name,
99-
true /* all must be scheduled in time (so, on finishBuild RemoteBuilder will have all targets added - so, we must set isAsyncSupported to true (resolved promise is returned)) */
100-
)
101-
}
102-
103-
async finishBuild() {
104-
await this.buildTaskManager.awaitTasks()
105-
await this.remoteBuilder.build()
106-
}
107-
108-
build(appOutDir: string, arch: Arch) {
109-
const promise = this.doBuild(appOutDir, arch)
110-
this.buildTaskManager.addTask(promise)
111-
return promise
112-
}
113-
114-
private async doBuild(appOutDir: string, arch: Arch) {
115-
log.info({ target: this.target.name, arch: Arch[arch] }, "scheduling remote build")
116-
await this.target.checkOptions()
117-
this.remoteBuilder.scheduleBuild(this.target, arch, appOutDir)
118-
}
119-
}
120-
12174
export function toAppImageOrSnapArch(arch: Arch): string {
12275
switch (arch) {
12376
case Arch.x64:

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

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions {
7979
*/
8080
readonly protocols?: Array<Protocol> | Protocol
8181

82+
/**
83+
* The electron locales to keep. By default, all Electron locales used as-is.
84+
*/
85+
readonly electronLanguages?: Array<string> | string
86+
8287
/**
8388
* Whether to fail if app will be not code signed.
8489
*/

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

-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ export interface MacConfiguration extends PlatformSpecificBuildOptions {
136136
*/
137137
readonly requirements?: string | null
138138

139-
/**
140-
* The electron locales. By default Electron locales used as is.
141-
*/
142-
readonly electronLanguages?: Array<string> | string
143-
144139
/** @private */
145140
readonly cscInstallerLink?: string | null
146141
/** @private */

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BluebirdPromise from "bluebird-lst"
2-
import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, deepAssign, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, isEnvTrue } from "builder-util"
2+
import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, deepAssign, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log } from "builder-util"
33
import { defaultArchFromString, getArtifactArchName } from "builder-util/out/arch"
44
import { FileTransformer, statOrNull } from "builder-util/out/fs"
55
import { orIfFileNotExist } from "builder-util/out/promise"
@@ -786,14 +786,3 @@ export function chooseNotNull(v1: string | null | undefined, v2: string | null |
786786
function capitalizeFirstLetter(text: string) {
787787
return text.charAt(0).toUpperCase() + text.slice(1)
788788
}
789-
790-
export function isSafeToUnpackElectronOnRemoteBuildServer(packager: PlatformPackager<any>) {
791-
if (packager.platform !== Platform.LINUX || packager.config.remoteBuild === false) {
792-
return false
793-
}
794-
795-
if (process.platform === "win32" || isEnvTrue(process.env._REMOTE_BUILD)) {
796-
return packager.config.electronDist == null && packager.config.electronDownload == null
797-
}
798-
return false
799-
}

0 commit comments

Comments
 (0)