Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
configuration.cscKeyPassword = ""
}
else if ((configuration as Configuration).cscLink == null) {
packagerOptions = deepAssign({}, packagerOptions, {config: {mac: {identity: null}}})
}
const projectDirCreated = checkOptions.projectDirCreated
let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
// const isDoNotUseTempDir = platform === "darwin"
const customTmpDir = process.env.TEST_APP_TMP_DIR
const tmpDir = checkOptions.tmpDir || new TmpDir(`pack-tester: ${fixtureName}`)
// non-macOS test uses the same dir as macOS test, but we cannot share node_modules (because tests executed in parallel)
const dir = customTmpDir == null ? await tmpDir.createTempDir({prefix: "test-project"}) : path.resolve(customTmpDir)
if (customTmpDir != null) {
await emptyDir(dir)
log.info({customTmpDir}, "custom temp dir used")
}
await copyDir(projectDir, dir, {
filter: it => {
const basename = path.basename(it)
// if custom project dir specified, copy node_modules (i.e. do not ignore it)
return (packagerOptions.projectDir != null || basename !== "node_modules") && (!basename.startsWith(".") || basename === ".babelrc")
},
isUseHardLink: USE_HARD_LINKS,
})
projectDir = dir
await executeFinally((async () => {
if (projectDirCreated != null) {
await projectDirCreated(projectDir, tmpDir)
}
async prepareWine(wineDir: string) {
await emptyDir(wineDir)
//noinspection SpellCheckingInspection
const env = {
...process.env,
WINEDLLOVERRIDES: "winemenubuilder.exe=d",
WINEPREFIX: wineDir,
}
await exec("wineboot", ["--init"], {env})
// regedit often doesn't modify correctly
let systemReg = await fs.readFile(path.join(wineDir, "system.reg"), "utf8")
systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
// noinspection SpellCheckingInspection
systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
await fs.writeFile(path.join(wineDir, "system.reg"), systemReg)
// remove links to host OS
const userDir = this.userDir!!
const desktopDir = path.join(userDir, "Desktop")
await Promise.all([
unlinkIfExists(desktopDir),
await executeFinally((async () => {
if (projectDirCreated != null) {
await projectDirCreated(projectDir, tmpDir)
}
if (checkOptions.isInstallDepsBefore) {
// bin links required (e.g. for node-pre-gyp - if package refers to it in the install script)
await spawn(process.platform === "win32" ? "yarn.cmd" : "yarn", ["install", "--production", "--no-lockfile"], {
cwd: projectDir,
})
}
if (packagerOptions.projectDir != null) {
packagerOptions.projectDir = path.resolve(projectDir, packagerOptions.projectDir)
}
const {packager, outDir} = await packAndCheck({
projectDir,
...packagerOptions
}, checkOptions)
if (checkOptions.packed != null) {
function base(platform: Platform, arch?: Arch): string {
return path.join(outDir, `${platform.buildConfigurationKey}${getArchSuffix(arch == null ? Arch.x64 : arch)}${platform === Platform.MAC ? "" : "-unpacked"}`)
// regedit often doesn't modify correctly
let systemReg = await fs.readFile(path.join(wineDir, "system.reg"), "utf8")
systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
// noinspection SpellCheckingInspection
systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
await fs.writeFile(path.join(wineDir, "system.reg"), systemReg)
// remove links to host OS
const userDir = this.userDir!!
const desktopDir = path.join(userDir, "Desktop")
await Promise.all([
unlinkIfExists(desktopDir),
unlinkIfExists(path.join(userDir, "My Documents")),
unlinkIfExists(path.join(userDir, "My Music")),
unlinkIfExists(path.join(userDir, "My Pictures")),
unlinkIfExists(path.join(userDir, "My Videos")),
])
await ensureDir(desktopDir)
return env
}
}
// regedit often doesn't modify correctly
let systemReg = await fs.readFile(path.join(wineDir, "system.reg"), "utf8")
systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
// noinspection SpellCheckingInspection
systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
await fs.writeFile(path.join(wineDir, "system.reg"), systemReg)
// remove links to host OS
const userDir = this.userDir!!
const desktopDir = path.join(userDir, "Desktop")
await Promise.all([
unlinkIfExists(desktopDir),
unlinkIfExists(path.join(userDir, "My Documents")),
unlinkIfExists(path.join(userDir, "My Music")),
unlinkIfExists(path.join(userDir, "My Pictures")),
unlinkIfExists(path.join(userDir, "My Videos")),
])
await ensureDir(desktopDir)
return env
}
}
systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
// noinspection SpellCheckingInspection
systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
await fs.writeFile(path.join(wineDir, "system.reg"), systemReg)
// remove links to host OS
const userDir = this.userDir!!
const desktopDir = path.join(userDir, "Desktop")
await Promise.all([
unlinkIfExists(desktopDir),
unlinkIfExists(path.join(userDir, "My Documents")),
unlinkIfExists(path.join(userDir, "My Music")),
unlinkIfExists(path.join(userDir, "My Pictures")),
unlinkIfExists(path.join(userDir, "My Videos")),
])
await ensureDir(desktopDir)
return env
}
}
private getOrCreatePublisher(publishConfig: PublishConfiguration, appInfo: AppInfo): Publisher | null {
// to not include token into cache key
const providerCacheKey = safeStringifyJson(publishConfig)
let publisher = this.nameToPublisher.get(providerCacheKey)
if (publisher == null) {
publisher = createPublisher(this, appInfo.version, publishConfig, this.publishOptions, this.packager)
this.nameToPublisher.set(providerCacheKey, publisher)
log.info({publisher: publisher!!.toString()}, "publishing")
}
return publisher
}
const performDependenciesInstallOrRebuild = await beforeBuild({
appDir: this.appDir,
electronVersion: this.config.electronVersion!,
platform,
arch: Arch[arch]
})
// If beforeBuild resolves to false, it means that handling node_modules is done outside of electron-builder.
this._nodeModulesHandledExternally = !performDependenciesInstallOrRebuild
if (!performDependenciesInstallOrRebuild) {
return
}
}
if (config.buildDependenciesFromSource === true && platform.nodeName !== process.platform) {
log.info({reason: "platform is different and buildDependenciesFromSource is set to true"}, "skipped dependencies rebuild")
}
else {
await installOrRebuild(config, this.appDir, {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null),
})
}
}
identity: identity!,
type,
platform: isMas ? "mas" : "darwin",
version: this.config.electronVersion,
app: appPath,
keychain: keychainFile || undefined,
binaries: options.binaries || undefined,
requirements: isMas || this.platformSpecificBuildOptions.requirements == null ? undefined : await this.getResource(this.platformSpecificBuildOptions.requirements),
// https://github.com/electron-userland/electron-osx-sign/issues/196
// will fail on 10.14.5+ because a signed but unnotarized app is also rejected.
"gatekeeper-assess": options.gatekeeperAssess === true,
hardenedRuntime: options.hardenedRuntime !== false,
}
await this.adjustSignOptions(signOptions, masOptions)
log.info({
file: log.filePath(appPath),
identityName: identity.name,
identityHash: identity.hash,
provisioningProfile: signOptions["provisioning-profile"] || "none",
}, "signing")
await this.doSign(signOptions)
// https://github.com/electron-userland/electron-builder/issues/1196#issuecomment-312310209
if (masOptions != null && !isDevelopment) {
const certType = isDevelopment ? "Mac Developer" : "3rd Party Mac Developer Installer"
const masInstallerIdentity = await findIdentity(certType, masOptions.identity, keychainFile)
if (masInstallerIdentity == null) {
throw new InvalidConfigurationError(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://electron.build/code-signing`)
}
// mas uploaded to AppStore, so, use "-" instead of space for name
async function compileUsingElectronCompile(mainFileSet: ResolvedFileSet, packager: Packager): Promise {
log.info("compiling using electron-compile")
const electronCompileCache = await packager.tempDirManager.getTempDir({prefix: "electron-compile-cache"})
const cacheDir = path.join(electronCompileCache, ".cache")
// clear and create cache dir
await ensureDir(cacheDir)
const compilerHost = await createElectronCompilerHost(mainFileSet.src, cacheDir)
const nextSlashIndex = mainFileSet.src.length + 1
// pre-compute electron-compile to cache dir - we need to process only subdirectories, not direct files of app dir
await BluebirdPromise.map(mainFileSet.files, file => {
if (file.includes(NODE_MODULES_PATTERN) || file.includes(BOWER_COMPONENTS_PATTERN)
|| !file.includes(path.sep, nextSlashIndex) // ignore not root files
|| !mainFileSet.metadata.get(file)!.isFile()) {
return null
}
return compilerHost.compile(file)
.then(() => null)