Skip to content

Commit

Permalink
chore: migrate to fs/promises
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 13, 2021
1 parent e148234 commit 96d7813
Show file tree
Hide file tree
Showing 48 changed files with 716 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
test:
parallelism: 4
docker:
- image: electronuserland/builder:wine-mono
- image: electronuserland/builder:wine-mono-05.21@sha256:72d80fa707b724f7e08d42f97d960506445d6d6ffe8d0fa94c805c309644ee2a
environment:
JEST_JUNIT_OUTPUT_DIR: /tmp/test-reports/test.xml
TZ: Europe/Berlin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
runs-on: ubuntu-20.04
container:
image: electronuserland/builder:14-03.21@sha256:38761d41757f3cdaf6cd57587a2dbf54449fa4f49b3569808ac7bc9f097fa6cc
image: electronuserland/builder:14-05.21@sha256:e62bb9d32396037ec2a98a9d8f156b77238ddc9833ce067f788a0656e02029f2
env:
TEST_FILES: configurationValidationTest,globTest,RepoSlugTest,mainEntryTest,ArtifactPublisherTest,ignoreTest,filesTest,nsisUpdaterTest,extraMetadataTest,linuxPackagerTest,linuxArchiveTest,protonTest
steps:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ electron-builder-*.d.ts
/site/
/docs/

tsconfig.tsbuildinfo
tsconfig.tsbuildinfo

.pnpm-store/
1 change: 1 addition & 0 deletions .idea/electron-builder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \
# python for node-gyp
# rpm is required for FPM to build rpm package
# libsecret-1-dev is required even for prebuild keytar (https://atom.github.io/node-keytar/)
apt-get -qq install --no-install-recommends qtbase5-dev build-essential autoconf libssl-dev gcc-multilib g++-multilib lzip rpm python libcurl4 git git-lfs ssh unzip \
apt-get -qq install --no-install-recommends qtbase5-dev build-essential autoconf libssl-dev gcc-multilib g++-multilib lzip rpm python libcurl4 git git-lfs ssh unzip libarchive-tools \
libsecret-1-dev \
libopenjp2-tools && \
# git-lfs
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"///": "Please see https://github.com/electron-userland/electron-builder/blob/master/CONTRIBUTING.md#run-test-using-cli how to run particular test instead full (and very slow) run",
"test": "node ./test/out/helpers/runTests.js skipArtifactPublisher ALL_TESTS=isCi",
"test-all": "pnpm pretest && node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -e UPDATE_SNAPSHOT=${UPDATE_SNAPSHOT:-false} -e TEST_FILES=\"${TEST_FILES:-HoistedNodeModuleTest}\" -v $(pwd):/project -v $(pwd)-node-modules:/project/node_modules -v $HOME/Library/Caches/electron:/root/.cache/electron -v $HOME/Library/Caches/electron-builder:/root/.cache/electron-builder electronuserland/builder:wine /bin/bash -c \"pnpm i && pnpm test-all\"",
"test-linux": "docker run --rm -ti -e UPDATE_SNAPSHOT=${UPDATE_SNAPSHOT:-false} -e TEST_FILES=\"${TEST_FILES:-HoistedNodeModuleTest}\" -v $(pwd):/project -v $(pwd)-node-modules:/project/node_modules -v $HOME/Library/Caches/electron:/root/.cache/electron -v $HOME/Library/Caches/electron-builder:/root/.cache/electron-builder electronuserland/builder:wine /bin/bash -c \"pnpm install && pnpm node ./test/out/helpers/runTests.js\"",
"test-update": "UPDATE_SNAPSHOT=true pnpm test-all",
"docker-images": "docker/build.sh",
"release": "pnpm compile && ./scripts/publish-packages.sh && pnpx --package conventional-changelog-cli conventional-changelog -p angular -i CHANGELOG.md -s",
Expand Down
20 changes: 10 additions & 10 deletions packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"repository": "electron-userland/electron-builder",
"engines": {
"node": ">=12.0.0"
"node": ">=14.17.0"
},
"keywords": [
"electron",
Expand Down Expand Up @@ -69,24 +69,24 @@
},
"///": "babel in devDependencies for proton tests",
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/core": "^7.14.2",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.15",
"@babel/plugin-proposal-decorators": "^7.14.2",
"@babel/plugin-proposal-do-expressions": "^7.14.0",
"@babel/plugin-proposal-export-default-from": "^7.12.13",
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
"@babel/plugin-proposal-export-namespace-from": "^7.14.2",
"@babel/plugin-proposal-function-bind": "^7.12.13",
"@babel/plugin-proposal-function-sent": "^7.12.13",
"@babel/plugin-proposal-json-strings": "^7.13.8",
"@babel/plugin-proposal-logical-assignment-operators": "^7.13.8",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
"@babel/plugin-proposal-numeric-separator": "^7.12.13",
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
"@babel/plugin-proposal-json-strings": "^7.14.2",
"@babel/plugin-proposal-logical-assignment-operators": "^7.14.2",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2",
"@babel/plugin-proposal-numeric-separator": "^7.14.2",
"@babel/plugin-proposal-optional-chaining": "^7.14.2",
"@babel/plugin-proposal-pipeline-operator": "^7.12.13",
"@babel/plugin-proposal-throw-expressions": "^7.12.13",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/preset-env": "^7.14.1",
"@babel/preset-env": "^7.14.2",
"@babel/preset-react": "^7.13.13",
"@types/debug": "^4.1.5",
"@types/ejs": "^3.0.6",
Expand Down
5 changes: 1 addition & 4 deletions packages/app-builder-lib/src/ProtonFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export class ProtonFramework extends LibUiFramework {

log.info(
{
options: safeStringifyJson(
babelOptions,
new Set<string>(["presets"])
),
options: safeStringifyJson(babelOptions, new Set<string>(["presets"])),
},
"transpile source code using Babel"
)
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/asar/integrity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { createHash } from "crypto"
import { createReadStream } from "fs"
import { readdir } from "fs-extra"
import { readdir } from "fs/promises"
import * as path from "path"

export interface AsarIntegrityOptions {
Expand Down
5 changes: 4 additions & 1 deletion packages/app-builder-lib/src/codeSign/windowsCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export async function getCertificateFromStoreInfo(options: WindowsConfiguration,
// ExcludeProperty doesn't work, so, we cannot exclude RawData, it is ok
// powershell can return object if the only item
const rawResult = await vm.exec("powershell.exe", [
"-NoProfile", "-NonInteractive", "-Command", "Get-ChildItem -Recurse Cert: -CodeSigningCert | Select-Object -Property Subject,PSParentPath,Thumbprint | ConvertTo-Json -Compress",
"-NoProfile",
"-NonInteractive",
"-Command",
"Get-ChildItem -Recurse Cert: -CodeSigningCert | Select-Object -Property Subject,PSParentPath,Thumbprint | ConvertTo-Json -Compress",
])
const certList = rawResult.length === 0 ? [] : asArray<CertInfo>(JSON.parse(rawResult))
for (const certInfo of certList) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export interface Configuration extends PlatformSpecificBuildOptions {
* @default true
*/
readonly removePackageScripts?: boolean

/**
* Whether to remove `keywords` field from `package.json` files.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/electron/ElectronFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isSafeToUnpackElectronOnRemoteBuildServer } from "../platformPackager"
import { getTemplatePath } from "../util/pathManager"
import { createMacApp } from "./electronMac"
import { computeElectronVersion, getElectronVersionFromInstalled } from "./electronVersion"
import { promises as fsPromises } from "fs"
import * as fs from "fs/promises"

export type ElectronPlatformName = "darwin" | "linux" | "win32" | "mas"

Expand Down Expand Up @@ -102,7 +102,7 @@ async function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {

const language = file.substring(0, file.length - langFileExt.length)
if (!wantedLanguages.includes(language)) {
return fsPromises.rmdir(path.join(resourcesDir, file), { recursive: false })
return fs.rm(path.join(resourcesDir, file), { force: true })
}
return
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/electron/electronMac.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { asArray, getPlatformIconFileName, InvalidConfigurationError, log } from "builder-util"
import { copyOrLinkFile, unlinkIfExists } from "builder-util/out/fs"
import { rename, utimes } from "fs-extra"
import { rename, utimes } from "fs/promises"
import * as path from "path"
import { filterCFBundleIdentifier } from "../appInfo"
import { AsarIntegrity } from "../asar/integrity"
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/fileTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debug, log, deepAssign } from "builder-util"
import { FileTransformer } from "builder-util/out/fs"
import { readFile } from "fs-extra"
import { readFile } from "fs/promises"
import * as path from "path"
import { Configuration } from "./configuration"
import { Packager } from "./packager"
Expand Down Expand Up @@ -41,7 +41,7 @@ export function createTransformer(srcDir: string, configuration: Configuration,
cleanupPackageJson(JSON.parse(it), {
isMain: false,
isRemovePackageScripts,
isRemovePackageKeywords
isRemovePackageKeywords,
})
)
.catch(e => log.warn(e))
Expand Down Expand Up @@ -116,7 +116,7 @@ async function modifyMainPackageJson(file: string, extraMetadata: any, isRemoveP
const serializedDataIfChanged = cleanupPackageJson(mainPackageData, {
isMain: true,
isRemovePackageScripts,
isRemovePackageKeywords
isRemovePackageKeywords,
})
if (serializedDataIfChanged != null) {
return serializedDataIfChanged
Expand Down
20 changes: 10 additions & 10 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { deepAssign, Arch, AsyncTaskManager, exec, InvalidConfigurationError, log, use, getArchSuffix } from "builder-util"
import { signAsync, SignOptions } from "../electron-osx-sign"
import { mkdirs, readdir } from "fs-extra"
import { mkdir, readdir } from "fs/promises"
import { Lazy } from "lazy-val"
import * as path from "path"
import { copyFile, unlinkIfExists } from "builder-util/out/fs"
Expand All @@ -18,7 +18,7 @@ import { PkgTarget, prepareProductBuildArgs } from "./targets/pkg"
import { createCommonTarget, NoOpTarget } from "./targets/targetFactory"
import { isMacOsHighSierra } from "./util/macosVersion"
import { getTemplatePath } from "./util/pathManager"
import { promisify } from "util"
import * as fs from "fs/promises"

export default class MacPackager extends PlatformPackager<MacConfiguration> {
readonly codeSigningInfo = new Lazy<CodeSigningInfo>(() => {
Expand Down Expand Up @@ -128,9 +128,8 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
outAppPath: path.join(appOutDir, appFile),
force: true,
})
const rmdir = promisify(require("fs").rmdir)
await rmdir(x64AppOutDir, { recursive: true })
await rmdir(arm64AppOutPath, { recursive: true })
await fs.rm(x64AppOutDir, { recursive: true, force: true })
await fs.rm(arm64AppOutPath, { recursive: true, force: true })
await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
break
}
Expand All @@ -145,9 +144,10 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {

if (!hasMas || targets.length > 1) {
const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged
nonMasPromise = (prepackaged
? Promise.resolve()
: this.doPack(outDir, path.dirname(appPath), this.platform.nodeName as ElectronPlatformName, arch, this.platformSpecificBuildOptions, targets)
nonMasPromise = (
prepackaged
? Promise.resolve()
: this.doPack(outDir, path.dirname(appPath), this.platform.nodeName as ElectronPlatformName, arch, this.platformSpecificBuildOptions, targets)
).then(() => this.packageInDistributableFormat(appPath, arch, targets, taskManager))
}

Expand Down Expand Up @@ -259,7 +259,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
)

/* Those are browser automating modules, browser (chromium, nightly) cannot be signed
https://github.com/electron-userland/electron-builder/issues/2010
https://github.com/electron-userland/electron-builder/issues/2010
https://github.com/electron-userland/electron-builder/issues/5383
*/
},
Expand Down Expand Up @@ -348,7 +348,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
//noinspection JSMethodCanBeStatic
protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | null | undefined): Promise<any> {
// productbuild doesn't created directory for out file
await mkdirs(path.dirname(outFile))
await mkdir(path.dirname(outFile), { recursive: true })

const args = prepareProductBuildArgs(identity, keychain)
args.push("--component", appPath, "/Applications")
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, deepAssign, getArc
import { defaultArchFromString, getArtifactArchName } from "builder-util/out/arch"
import { FileTransformer, statOrNull } from "builder-util/out/fs"
import { orIfFileNotExist } from "builder-util/out/promise"
import { readdir } from "fs-extra"
import { readdir } from "fs/promises"
import { Lazy } from "lazy-val"
import { Minimatch } from "minimatch"
import * as path from "path"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { GitHubPublisher } from "electron-publish/out/gitHubPublisher"
import { MultiProgress } from "electron-publish/out/multiProgress"
import S3Publisher from "./s3/s3Publisher"
import SpacesPublisher from "./s3/spacesPublisher"
import { writeFile } from "fs-extra"
import { writeFile } from "fs/promises"
import * as isCi from "is-ci"
import * as path from "path"
import { WriteStream as TtyWriteStream } from "tty"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/MsiTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getBinFromUrl } from "../binDownload"
import { walk } from "builder-util/out/fs"
import { createHash } from "crypto"
import * as ejs from "ejs"
import { readFile, writeFile } from "fs-extra"
import { readFile, writeFile } from "fs/promises"
import { Lazy } from "lazy-val"
import * as path from "path"
import { MsiOptions } from "../"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class NsisTarget extends Target {
// http://forums.winamp.com/showthread.php?p=3078545
if (isMacOsCatalina()) {
try {
UninstallerReader.exec(installerPath, uninstallerPath)
await UninstallerReader.exec(installerPath, uninstallerPath)
} catch (error) {
log.warn(`packager.vm is used: ${error.message}`)

Expand Down
14 changes: 6 additions & 8 deletions packages/app-builder-lib/src/targets/nsis/nsisUtil.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, log } from "builder-util"
import { PackageFileInfo } from "builder-util-runtime"
import { getBinFromUrl } from "../../binDownload"
import { copyFile } from "builder-util/out/fs"
import { unlink } from "fs-extra"
import * as path from "path"
import { getTemplatePath } from "../../util/pathManager"
import { NsisTarget } from "./NsisTarget"
import * as fs from "fs"
import * as fs from "fs/promises"
import * as zlib from "zlib"

export const nsisTemplatesDir = getTemplatePath("nsis")
Expand Down Expand Up @@ -59,7 +57,7 @@ export class AppPackageHelper {
}
}

await BluebirdPromise.map(filesToDelete, it => unlink(it))
await Promise.all(filesToDelete.map(it => fs.unlink(it)))
}
}

Expand Down Expand Up @@ -160,8 +158,8 @@ class BinaryReader {

export class UninstallerReader {
// noinspection SpellCheckingInspection
static exec(installerPath: string, uninstallerPath: string) {
const buffer = fs.readFileSync(installerPath)
static async exec(installerPath: string, uninstallerPath: string) {
const buffer = await fs.readFile(installerPath)
const reader = new BinaryReader(buffer)
// IMAGE_DOS_HEADER
if (!reader.match([0x4d, 0x5a])) {
Expand Down Expand Up @@ -241,7 +239,7 @@ export class UninstallerReader {
if (!innerBuffer) {
throw new Error("Inner block not found.")
}
fs.writeFileSync(uninstallerPath, executable)
fs.appendFileSync(uninstallerPath, innerBuffer)
await fs.writeFile(uninstallerPath, executable)
await fs.appendFile(uninstallerPath, innerBuffer)
}
}
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { statOrNull } from "builder-util/out/fs"
import { PkgOptions } from "../options/pkgOptions"
import { executeAppBuilderAndWriteJson, executeAppBuilderAsJson } from "../util/appBuilder"
import { getNotLocalizedLicenseFile } from "../util/license"
import { readFile, unlink, writeFile } from "fs-extra"
import { readFile, unlink, writeFile } from "fs/promises"
import * as path from "path"
import { filterCFBundleIdentifier } from "../appInfo"
import { findIdentity, Identity } from "../codeSign/macCodeSign"
Expand Down
8 changes: 4 additions & 4 deletions packages/app-builder-lib/src/targets/targetUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path"
import { Target, AppInfo } from "../"
import { Arch, debug } from "builder-util"
import { PlatformPackager } from "../platformPackager"
import { promises as fsPromises } from "fs"
import * as fs from "fs/promises"

export class StageDir {
constructor(readonly dir: string) {}
Expand All @@ -13,7 +13,7 @@ export class StageDir {

cleanup() {
if (!debug.enabled || process.env.ELECTRON_BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG === "true") {
return fsPromises.rmdir(this.dir, { recursive: true })
return fs.rm(this.dir, { recursive: true, force: true })
}
return Promise.resolve()
}
Expand All @@ -29,8 +29,8 @@ export async function createStageDir(target: Target, packager: PlatformPackager<

export async function createStageDirPath(target: Target, packager: PlatformPackager<any>, arch: Arch): Promise<string> {
const tempDir = packager.info.stageDirPathCustomizer(target, packager, arch)
await fsPromises.rmdir(tempDir, { recursive: true })
await fsPromises.mkdir(tempDir, { recursive: true })
await fs.rm(tempDir, { recursive: true, force: true })
await fs.mkdir(tempDir, { recursive: true })
return tempDir
}

Expand Down
Loading

2 comments on commit 96d7813

@Skywalker13
Copy link

@Skywalker13 Skywalker13 commented on 96d7813 Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @develar

This commit breaks with node 12 LTS because require('fs/promises') is new, require('fs').promises works with node 12 and 14

@aprilandjan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @develar

This commit breaks with node 12 LTS because require('fs/promises') is new, require('fs').promises works with node 12 and 14

The node official site says that fs/promises is available since node v14, which is electron v12 at lease(see this matching list)

I'm trying to upgrade electron-builder for my electron app(which is v11.3) and found that it is impossible if I keep current electron version 😞

Please sign in to comment.