Skip to content

Commit 0b8bff4

Browse files
committed
fix: detect electron-compile in the dev deps
1 parent 55ebed1 commit 0b8bff4

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

packages/electron-builder-util/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export function getCacheDirectory(): string {
212212
const localappdata = process.env.LOCALAPPDATA
213213
if (process.platform === "win32" && localappdata != null) {
214214
// https://github.com/electron-userland/electron-builder/issues/1164
215-
if (localappdata.includes("\\Windows\\System32\\") || process.env.USERNAME === "SYSTEM") {
215+
if (localappdata.toLowerCase().includes("\\windows\\system32\\") || (process.env.USERNAME || "").toLowerCase() === "system") {
216216
return path.join(tmpdir(), "electron-builder-cache")
217217
}
218218
return path.join(localappdata, "electron-builder", "cache")

packages/electron-builder/src/appInfo.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ export class AppInfo {
4848
}
4949

5050
get id(): string {
51-
let appId = (<any>this.config)["app-bundle-id"]
52-
if (appId != null) {
53-
warn("app-bundle-id is deprecated, please use appId")
54-
}
55-
51+
let appId
5652
if (this.config.appId != null) {
5753
appId = this.config.appId
5854
}
@@ -61,7 +57,7 @@ export class AppInfo {
6157
return `com.electron.${this.metadata.name!.toLowerCase()}`
6258
}
6359

64-
if (appId === "your.id" || isEmptyOrSpaces(appId)) {
60+
if (appId != null && (appId === "your.id" || isEmptyOrSpaces(appId))) {
6561
const incorrectAppId = appId
6662
appId = generateDefaultAppId()
6763
warn(`Do not use "${incorrectAppId}" as appId, "${appId}" will be used instead`)

packages/electron-builder/src/fileTransformer.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import { debug } from "electron-builder-util"
22
import { deepAssign } from "electron-builder-util/out/deepAssign"
3-
import { warn } from "electron-builder-util/out/log"
3+
import { log, warn } from "electron-builder-util/out/log"
44
import { readJson } from "fs-extra-p"
55
import mime from "mime"
66
import * as path from "path"
7+
import { BuildInfo } from "./packagerApi"
78
import { PlatformPackager } from "./platformPackager"
89

910
export type FileTransformer = (path: string) => Promise<null | string | Buffer> | null | string | Buffer
1011

11-
export async function createTransformer(projectDir: string, srcDir: string, packager: PlatformPackager<any>): Promise<FileTransformer> {
12-
const devDeps = packager.info.devMetadata.dependencies
13-
const deps = packager.info.metadata.dependencies
14-
const useElectronCompile = (devDeps != null && ("electron-compile" in devDeps)) || (deps != null && ("electron-compile" in deps))
12+
function isElectronCompileUsed(info: BuildInfo): boolean {
13+
const depList = [(<any>info.metadata).devDependencies, info.metadata.dependencies]
14+
if (info.isTwoPackageJsonProjectLayoutUsed) {
15+
depList.push((<any>info.devMetadata).devDependencies)
16+
depList.push(info.devMetadata.dependencies)
17+
}
18+
19+
for (const deps of depList) {
20+
if (deps != null && "electron-compile" in deps) {
21+
log("electron-compile detected — files will be compiled")
22+
return true
23+
}
24+
}
1525

26+
return false
27+
}
28+
29+
export async function createTransformer(projectDir: string, srcDir: string, packager: PlatformPackager<any>): Promise<FileTransformer> {
1630
const extraMetadata = packager.packagerOptions.extraMetadata
1731
const mainPackageJson = path.join(srcDir, "package.json")
1832

@@ -30,7 +44,7 @@ export async function createTransformer(projectDir: string, srcDir: string, pack
3044
}
3145
}
3246

33-
return useElectronCompile ? await createElectronCompileTransformer(projectDir, defaultTransformer) : defaultTransformer
47+
return isElectronCompileUsed(packager.info) ? await createElectronCompileTransformer(projectDir, defaultTransformer) : defaultTransformer
3448
}
3549

3650
async function createElectronCompileTransformer(projectDir: string, defaultTransformer: FileTransformer) {
@@ -60,7 +74,11 @@ async function createElectronCompileTransformer(projectDir: string, defaultTrans
6074

6175
const cache = compilerHost.cachesForCompilers.get(compiler)
6276
const result = await cache.getOrFetch(file, (file: string, hashInfo: any) => compilerHost.compileUncached(file, hashInfo, compiler))
63-
return result.code || result.binaryData
77+
const code = result.code
78+
if (type === "application/javascript" && code != null && (code.includes("require('electron-compile')") || code.includes('require("electron-compile")'))) {
79+
warn("electron-compile should be not used in the production code")
80+
}
81+
return code || result.binaryData
6482
}
6583
}
6684

0 commit comments

Comments
 (0)