From 07429661c0da2248cec5b92eb03390ae19266328 Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Mon, 27 Jan 2025 14:26:04 -0800 Subject: [PATCH] fix: allow `skipLibCheck: false` (#8813) Tasks: - Extract common `undefined | null` logic everywhere to reuse (now-exported) type `Nullish` - Expose `FileMatcher` by removing `@internal` flag (why was it internal to begin with?) - Created base type `ObjectMap` to reduce writing `{ [key: string]: }` everywhere. - Updated eslint to register `test/tsconfig.json` - Fixes `skipLibCheck: false` by forcing UUID.ts to return a `Buffer` instead of `Buffer`, which the compiler doesn't like depending on version of node you're on --- .changeset/metal-bulldogs-film.md | 8 +++++++ eslint.config.mjs | 2 +- packages/app-builder-lib/src/appInfo.ts | 5 +++-- packages/app-builder-lib/src/asar/asar.ts | 15 ++++++++----- packages/app-builder-lib/src/binDownload.ts | 3 ++- .../src/codeSign/macCodeSign.ts | 9 ++------ .../src/codeSign/signManager.ts | 4 ++-- packages/app-builder-lib/src/core.ts | 4 ++-- .../src/electron/electronVersion.ts | 4 ++-- packages/app-builder-lib/src/fileMatcher.ts | 6 +++--- packages/app-builder-lib/src/macPackager.ts | 4 ++-- .../options/PlatformSpecificBuildOptions.ts | 3 ++- .../src/options/SnapOptions.ts | 9 ++++---- .../app-builder-lib/src/options/metadata.ts | 3 ++- .../app-builder-lib/src/options/winOptions.ts | 3 ++- .../app-builder-lib/src/platformPackager.ts | 21 ++++++++++--------- .../src/publish/PublishManager.ts | 3 ++- .../app-builder-lib/src/targets/AppxTarget.ts | 5 +++-- .../app-builder-lib/src/targets/FpmTarget.ts | 3 ++- .../src/targets/LinuxTargetHelper.ts | 5 +++-- packages/app-builder-lib/src/targets/pkg.ts | 3 ++- packages/app-builder-lib/src/targets/snap.ts | 6 +++--- .../app-builder-lib/src/util/appBuilder.ts | 3 ++- .../app-builder-lib/src/util/bundledTool.ts | 4 +++- .../app-builder-lib/src/util/config/config.ts | 9 ++++---- .../app-builder-lib/src/util/config/load.ts | 3 ++- packages/app-builder-lib/src/util/license.ts | 3 ++- .../app-builder-lib/src/util/macroExpander.ts | 3 ++- .../src/util/packageMetadata.ts | 5 +++-- packages/app-builder-lib/src/util/yarn.ts | 3 ++- packages/app-builder-lib/src/winPackager.ts | 3 ++- .../builder-util-runtime/src/httpExecutor.ts | 3 ++- packages/builder-util-runtime/src/index.ts | 6 +++++- .../src/publishOptions.ts | 3 ++- packages/builder-util-runtime/src/uuid.ts | 4 ++-- packages/builder-util-runtime/src/xml.ts | 5 +++-- packages/builder-util/src/fs.ts | 3 ++- packages/builder-util/src/util.ts | 13 ++++++------ packages/dmg-builder/src/dmg.ts | 6 +++--- test/src/updater/differentialUpdateTest.ts | 4 ++-- 40 files changed, 124 insertions(+), 87 deletions(-) create mode 100644 .changeset/metal-bulldogs-film.md diff --git a/.changeset/metal-bulldogs-film.md b/.changeset/metal-bulldogs-film.md new file mode 100644 index 00000000000..f49686e4ddd --- /dev/null +++ b/.changeset/metal-bulldogs-film.md @@ -0,0 +1,8 @@ +--- +"app-builder-lib": patch +"builder-util": patch +"builder-util-runtime": patch +"dmg-builder": patch +--- + +chore: extract common `undefined | null` to reuse current (unexported) type `Nullish`. Expose `FileMatcher` instead of `@internal` flag diff --git a/eslint.config.mjs b/eslint.config.mjs index 8b02553eb11..1a635c3b28a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -41,7 +41,7 @@ export default [{ sourceType: "script", parserOptions: { - project: ["./packages/*/tsconfig.json"], + project: ["./packages/*/tsconfig.json", "./test/tsconfig.json"], }, }, diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index 95f6bbec845..aee84cfe9ae 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -4,6 +4,7 @@ import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOpt import { Packager } from "./packager" import { expandMacro } from "./util/macroExpander" import { sanitizeFileName } from "builder-util/out/filename" +import { Nullish } from "builder-util-runtime" // fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote // http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/ @@ -35,7 +36,7 @@ export class AppInfo { constructor( private readonly info: Packager, - buildVersion: string | null | undefined, + buildVersion: string | Nullish, private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null, normalizeNfd = false ) { @@ -116,7 +117,7 @@ export class AppInfo { } get id(): string { - let appId: string | null | undefined = null + let appId: string | Nullish = null for (const options of [this.platformSpecificOptions, this.info.config]) { if (options != null && appId == null) { appId = options.appId diff --git a/packages/app-builder-lib/src/asar/asar.ts b/packages/app-builder-lib/src/asar/asar.ts index 664d8eb565c..14910f667bf 100644 --- a/packages/app-builder-lib/src/asar/asar.ts +++ b/packages/app-builder-lib/src/asar/asar.ts @@ -1,3 +1,4 @@ +import { ObjectMap } from "builder-util-runtime" import { createFromBuffer } from "chromium-pickle-js" import { close, open, read, readFile, Stats } from "fs-extra" import * as path from "path" @@ -16,7 +17,7 @@ export interface NodeIntegrity { export class Node { // we don't use Map because later it will be stringified - files?: { [key: string]: Node } + files?: ObjectMap unpacked?: boolean @@ -40,7 +41,7 @@ export class AsarFilesystem { readonly headerSize: number = -1 ) { if (this.header.files == null) { - this.header.files = Object.create(null) as { [key: string]: Node } + this.header.files = this.newNode() } } @@ -54,7 +55,7 @@ export class AsarFilesystem { return null } child = new Node() - child.files = Object.create(null) as { [key: string]: Node } + child.files = this.newNode() node.files![dir] = child } node = child @@ -71,7 +72,7 @@ export class AsarFilesystem { const name = path.basename(p) const dirNode = this.searchNodeFromDirectory(path.dirname(p), true)! if (dirNode.files == null) { - dirNode.files = Object.create(null) as { [key: string]: Node } + dirNode.files = this.newNode() } let result = dirNode.files[name] @@ -105,7 +106,7 @@ export class AsarFilesystem { let children = dirNode.files if (children == null) { - children = Object.create(null) as { [key: string]: Node } + children = this.newNode() dirNode.files = children } children[path.basename(file)] = node @@ -131,6 +132,10 @@ export class AsarFilesystem { readFile(file: string): Promise { return readFileFromAsar(this, file, this.getFile(file)) } + + private newNode() { + return Object.create(null) as ObjectMap + } } export async function readAsarHeader(archive: string): Promise { diff --git a/packages/app-builder-lib/src/binDownload.ts b/packages/app-builder-lib/src/binDownload.ts index 7478192b268..9ad96d7284e 100644 --- a/packages/app-builder-lib/src/binDownload.ts +++ b/packages/app-builder-lib/src/binDownload.ts @@ -1,4 +1,5 @@ import { executeAppBuilder } from "builder-util" +import { Nullish } from "builder-util-runtime" const versionToPromise = new Map>() @@ -54,7 +55,7 @@ export function getBin(name: string, url?: string | null, checksum?: string | nu return promise } -function doGetBin(name: string, url: string | undefined | null, checksum: string | null | undefined): Promise { +function doGetBin(name: string, url: string | Nullish, checksum: string | Nullish): Promise { const args = ["download-artifact", "--name", name] if (url != null) { args.push("--url", url) diff --git a/packages/app-builder-lib/src/codeSign/macCodeSign.ts b/packages/app-builder-lib/src/codeSign/macCodeSign.ts index 399cbca909c..85320d36b73 100644 --- a/packages/app-builder-lib/src/codeSign/macCodeSign.ts +++ b/packages/app-builder-lib/src/codeSign/macCodeSign.ts @@ -13,6 +13,7 @@ import { importCertificate } from "./codesign" import { Identity as _Identity } from "@electron/osx-sign/dist/cjs/util-identities" import { SignOptions } from "@electron/osx-sign/dist/cjs/types" import { signAsync } from "@electron/osx-sign" +import { Nullish } from "builder-util-runtime" export const appleCertificatePrefixes = ["Developer ID Application:", "Developer ID Installer:", "3rd Party Mac Developer Application:", "3rd Party Mac Developer Installer:"] @@ -59,13 +60,7 @@ export function isSignAllowed(isPrintWarn = true): boolean { return true } -export async function reportError( - isMas: boolean, - certificateTypes: CertType[], - qualifier: string | null | undefined, - keychainFile: string | null | undefined, - isForceCodeSigning: boolean -) { +export async function reportError(isMas: boolean, certificateTypes: CertType[], qualifier: string | Nullish, keychainFile: string | Nullish, isForceCodeSigning: boolean) { const logFields: Fields = {} if (qualifier == null) { logFields.reason = "" diff --git a/packages/app-builder-lib/src/codeSign/signManager.ts b/packages/app-builder-lib/src/codeSign/signManager.ts index 37b16851032..09b535aafed 100644 --- a/packages/app-builder-lib/src/codeSign/signManager.ts +++ b/packages/app-builder-lib/src/codeSign/signManager.ts @@ -1,14 +1,14 @@ import { Lazy } from "lazy-val" import { WindowsSignOptions } from "./windowsCodeSign" import { Target } from "../core" -import { MemoLazy } from "builder-util-runtime" +import { MemoLazy, Nullish } from "builder-util-runtime" import { FileCodeSigningInfo, CertificateFromStoreInfo } from "./windowsSignToolManager" import { WindowsConfiguration } from "../options/winOptions" export interface SignManager { readonly computedPublisherName: Lazy | null> readonly cscInfo: MemoLazy - computePublisherName(target: Target, publisherName: string | null | undefined): Promise + computePublisherName(target: Target, publisherName: string | Nullish): Promise initialize(): Promise signFile(options: WindowsSignOptions): Promise } diff --git a/packages/app-builder-lib/src/core.ts b/packages/app-builder-lib/src/core.ts index 826c2fd63e8..ccada81dd26 100644 --- a/packages/app-builder-lib/src/core.ts +++ b/packages/app-builder-lib/src/core.ts @@ -1,5 +1,5 @@ import { Arch, archFromString, ArchType } from "builder-util" -import { AllPublishOptions } from "builder-util-runtime" +import { AllPublishOptions, Nullish } from "builder-util-runtime" // https://github.com/YousefED/typescript-json-schema/issues/80 export type Publish = AllPublishOptions | Array | null @@ -73,7 +73,7 @@ export class Platform { export abstract class Target { abstract readonly outDir: string - abstract readonly options: TargetSpecificOptions | null | undefined + abstract readonly options: TargetSpecificOptions | Nullish protected constructor( readonly name: string, diff --git a/packages/app-builder-lib/src/electron/electronVersion.ts b/packages/app-builder-lib/src/electron/electronVersion.ts index 57ed814f2c4..db34cfc12ef 100644 --- a/packages/app-builder-lib/src/electron/electronVersion.ts +++ b/packages/app-builder-lib/src/electron/electronVersion.ts @@ -1,7 +1,7 @@ import { getProjectRootPath } from "@electron/rebuild/lib/search-module" import { InvalidConfigurationError, log } from "builder-util" -import { parseXml } from "builder-util-runtime" +import { ObjectMap, parseXml } from "builder-util-runtime" import { httpExecutor } from "builder-util" import { readJson } from "fs-extra" import { Lazy } from "lazy-val" @@ -11,7 +11,7 @@ import * as semver from "semver" import { Configuration } from "../configuration" import { getConfig } from "../util/config/config" -export type MetadataValue = Lazy<{ [key: string]: any } | null> +export type MetadataValue = Lazy | null> const electronPackages = ["electron", "electron-prebuilt", "electron-prebuilt-compile", "electron-nightly"] diff --git a/packages/app-builder-lib/src/fileMatcher.ts b/packages/app-builder-lib/src/fileMatcher.ts index 61ca19efd18..3ae72d5799d 100644 --- a/packages/app-builder-lib/src/fileMatcher.ts +++ b/packages/app-builder-lib/src/fileMatcher.ts @@ -6,6 +6,7 @@ import * as path from "path" import { Configuration, FileSet, Packager, PlatformSpecificBuildOptions } from "./index" import { PlatformPackager } from "./platformPackager" import { createFilter, hasMagic } from "./util/filter" +import { Nullish } from "builder-util-runtime" // https://github.com/electron-userland/electron-builder/issues/733 const minimatchOptions = { dot: true } @@ -38,7 +39,6 @@ function ensureNoEndSlash(file: string): string { } } -/** @internal */ export class FileMatcher { readonly from: string readonly to: string @@ -233,7 +233,7 @@ export function getNodeModuleFileMatcher( // grab only excludes const matcher = new FileMatcher(appDir, destination, macroExpander) - function addPatterns(patterns: Array | string | null | undefined | FileSet) { + function addPatterns(patterns: Array | string | Nullish | FileSet) { if (patterns == null) { return } else if (!Array.isArray(patterns)) { @@ -295,7 +295,7 @@ export function getFileMatchers( const defaultMatcher = new FileMatcher(options.defaultSrc, defaultDestination, options.macroExpander) const fileMatchers: Array = [] - function addPatterns(patterns: Array | string | null | undefined | FileSet) { + function addPatterns(patterns: Array | string | Nullish | FileSet) { if (patterns == null) { return } else if (!Array.isArray(patterns)) { diff --git a/packages/app-builder-lib/src/macPackager.ts b/packages/app-builder-lib/src/macPackager.ts index f7a2efc633b..c19a6d12705 100644 --- a/packages/app-builder-lib/src/macPackager.ts +++ b/packages/app-builder-lib/src/macPackager.ts @@ -19,7 +19,7 @@ import { getTemplatePath } from "./util/pathManager" import * as fs from "fs/promises" import { notarize } from "@electron/notarize" import { NotarizeOptionsNotaryTool, NotaryToolKeychainCredentials } from "@electron/notarize/lib/types" -import { MemoLazy } from "builder-util-runtime" +import { MemoLazy, Nullish } from "builder-util-runtime" import { resolveFunction } from "./util/resolve" export type CustomMacSignOptions = SignOptions @@ -443,7 +443,7 @@ export class MacPackager extends PlatformPackager { } //noinspection JSMethodCanBeStatic - protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | null | undefined): Promise { + protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | Nullish): Promise { // productbuild doesn't created directory for out file await mkdir(path.dirname(outFile), { recursive: true }) diff --git a/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts b/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts index ea56efd8e8b..648666717d7 100644 --- a/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts +++ b/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts @@ -1,3 +1,4 @@ +import { ObjectMap } from "builder-util-runtime" import { CompressionLevel, Publish, TargetConfiguration, TargetSpecificOptions } from "../core" import { FileAssociation } from "./FileAssociation" @@ -224,7 +225,7 @@ export interface ReleaseInfo { /** * Vendor specific information. */ - vendor?: { [key: string]: any } | null + vendor?: ObjectMap | null } /** diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index 1ea3fbcb59a..1b9d2fd7adc 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -1,3 +1,4 @@ +import { ObjectMap } from "builder-util-runtime" import { TargetSpecificOptions } from "../core" import { CommonLinuxOptions } from "./linuxOptions" @@ -16,7 +17,7 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { /** * The custom environment. Defaults to `{"TMPDIR: "$XDG_RUNTIME_DIR"}`. If you set custom, it will be merged with default. */ - readonly environment?: { [key: string]: string } | null + readonly environment?: ObjectMap | null /** * The 78 character long summary. Defaults to [productName](./configuration.md#productName). @@ -117,7 +118,7 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { /** * Specifies any files to make accessible from locations such as `/usr`, `/var`, and `/etc`. See [snap layouts](https://snapcraft.io/docs/snap-layouts) to learn more. */ - readonly layout?: { [key: string]: { [key: string]: string } } | null + readonly layout?: ObjectMap> | null /** * Specifies which files from the app part to stage and which to exclude. Individual files, directories, wildcards, globstars, and exclusions are accepted. See [Snapcraft filesets](https://snapcraft.io/docs/snapcraft-filesets) to learn more about the format. @@ -144,9 +145,9 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { } export interface PlugDescriptor { - [key: string]: { [key: string]: any } | null + [key: string]: ObjectMap | null } export interface SlotDescriptor { - [key: string]: { [key: string]: any } | null + [key: string]: ObjectMap | null } diff --git a/packages/app-builder-lib/src/options/metadata.ts b/packages/app-builder-lib/src/options/metadata.ts index cda553185cd..ba72f6a6c07 100644 --- a/packages/app-builder-lib/src/options/metadata.ts +++ b/packages/app-builder-lib/src/options/metadata.ts @@ -1,3 +1,4 @@ +import { ObjectMap } from "builder-util-runtime" import { Configuration } from "../configuration" export interface Metadata { @@ -37,7 +38,7 @@ export interface Metadata { readonly build?: Configuration /** @private */ - readonly dependencies?: { [key: string]: string } + readonly dependencies?: ObjectMap /** @private */ readonly version?: string /** @private */ diff --git a/packages/app-builder-lib/src/options/winOptions.ts b/packages/app-builder-lib/src/options/winOptions.ts index 183949410c1..77f9e941a8a 100644 --- a/packages/app-builder-lib/src/options/winOptions.ts +++ b/packages/app-builder-lib/src/options/winOptions.ts @@ -1,5 +1,6 @@ import { PlatformSpecificBuildOptions, TargetConfigType } from "../index" import { CustomWindowsSign } from "../codeSign/windowsSignToolManager" +import { Nullish } from "builder-util-runtime" export interface WindowsConfiguration extends PlatformSpecificBuildOptions { /** @@ -167,5 +168,5 @@ export interface WindowsAzureSigningConfiguration { * Allow other CLI parameters (verbatim case-sensitive) to `Invoke-TrustedSigning` * Note: Key-Value pairs with `undefined`/`null` value are filtered out of the command. */ - [k: string]: string | undefined | null + [k: string]: string | Nullish } diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index 3d1f9fc9d8c..6235d2c295e 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -33,6 +33,7 @@ import { expandMacro as doExpandMacro } from "./util/macroExpander" import { resolveFunction } from "./util/resolve" import { flipFuses, FuseConfig, FuseV1Config, FuseV1Options, FuseVersion } from "@electron/fuses" import { FuseOptionsV1 } from "./configuration" +import { Nullish } from "builder-util-runtime" export type DoPackOptions = { outDir: string @@ -103,7 +104,7 @@ export abstract class PlatformPackager return new AppInfo(this.info, null, this.platformSpecificBuildOptions) } - private static normalizePlatformSpecificBuildOptions(options: any | null | undefined): any { + private static normalizePlatformSpecificBuildOptions(options: any | Nullish): any { return options == null ? Object.create(null) : options } @@ -119,13 +120,13 @@ export abstract class PlatformPackager } } - getCscLink(extraEnvName?: string | null): string | null | undefined { + getCscLink(extraEnvName?: string | null): string | Nullish { // allow to specify as empty string const envValue = chooseNotNull(extraEnvName == null ? null : process.env[extraEnvName], process.env.CSC_LINK) return chooseNotNull(chooseNotNull(this.info.config.cscLink, this.platformSpecificBuildOptions.cscLink), envValue) } - doGetCscPassword(): string | null | undefined { + doGetCscPassword(): string | Nullish { // allow to specify as empty string return chooseNotNull(chooseNotNull(this.info.config.cscKeyPassword, this.platformSpecificBuildOptions.cscKeyPassword), process.env.CSC_KEY_PASSWORD) } @@ -690,7 +691,7 @@ export abstract class PlatformPackager } expandArtifactNamePattern( - targetSpecificOptions: TargetSpecificOptions | null | undefined, + targetSpecificOptions: TargetSpecificOptions | Nullish, ext: string, arch?: Arch | null, defaultPattern?: string, @@ -701,7 +702,7 @@ export abstract class PlatformPackager return this.computeArtifactName(pattern, ext, !isUserForced && skipDefaultArch && arch === defaultArchFromString(defaultArch) ? null : arch) } - artifactPatternConfig(targetSpecificOptions: TargetSpecificOptions | null | undefined, defaultPattern: string | undefined) { + artifactPatternConfig(targetSpecificOptions: TargetSpecificOptions | Nullish, defaultPattern: string | undefined) { const userSpecifiedPattern = targetSpecificOptions?.artifactName || this.platformSpecificBuildOptions.artifactName || this.config.artifactName return { isUserForced: !!userSpecifiedPattern, @@ -709,12 +710,12 @@ export abstract class PlatformPackager } } - expandArtifactBeautyNamePattern(targetSpecificOptions: TargetSpecificOptions | null | undefined, ext: string, arch?: Arch | null): string { + expandArtifactBeautyNamePattern(targetSpecificOptions: TargetSpecificOptions | Nullish, ext: string, arch?: Arch | null): string { // tslint:disable-next-line:no-invalid-template-strings return this.expandArtifactNamePattern(targetSpecificOptions, ext, arch, "${productName} ${version} ${arch}.${ext}", true) } - private computeArtifactName(pattern: any, ext: string, arch: Arch | null | undefined): string { + private computeArtifactName(pattern: any, ext: string, arch: Arch | Nullish): string { const archName = arch == null ? null : getArtifactArchName(arch, ext) return this.expandMacro(pattern, archName, { ext, @@ -725,7 +726,7 @@ export abstract class PlatformPackager return doExpandMacro(pattern, arch, this.appInfo, { os: this.platform.buildConfigurationKey, ...extra }, isProductNameSanitized) } - generateName2(ext: string | null, classifier: string | null | undefined, deployment: boolean): string { + generateName2(ext: string | null, classifier: string | Nullish, deployment: boolean): string { const dotExt = ext == null ? "" : `.${ext}` const separator = ext === "deb" ? "_" : "-" return `${deployment ? this.appInfo.name : this.appInfo.productFilename}${separator}${this.appInfo.version}${classifier == null ? "" : `${separator}${classifier}`}${dotExt}` @@ -739,7 +740,7 @@ export abstract class PlatformPackager return asArray(this.config.fileAssociations).concat(asArray(this.platformSpecificBuildOptions.fileAssociations)) } - async getResource(custom: string | null | undefined, ...names: Array): Promise { + async getResource(custom: string | Nullish, ...names: Array): Promise { const resourcesDir = this.info.buildResourcesDir if (custom === undefined) { const resourceList = await this.resourceList @@ -869,7 +870,7 @@ export function normalizeExt(ext: string) { return ext.startsWith(".") ? ext.substring(1) : ext } -export function chooseNotNull(v1: T | null | undefined, v2: T | null | undefined): T | null | undefined { +export function chooseNotNull(v1: T | Nullish, v2: T | Nullish): T | Nullish { return v1 == null ? v2 : v1 } diff --git a/packages/app-builder-lib/src/publish/PublishManager.ts b/packages/app-builder-lib/src/publish/PublishManager.ts index 528b51b14ce..753353603be 100644 --- a/packages/app-builder-lib/src/publish/PublishManager.ts +++ b/packages/app-builder-lib/src/publish/PublishManager.ts @@ -11,6 +11,7 @@ import { PublishConfiguration, PublishProvider, BitbucketOptions, + Nullish, } from "builder-util-runtime" import _debug from "debug" import { @@ -390,7 +391,7 @@ export function computeDownloadUrl(publishConfiguration: PublishConfiguration, f export async function getPublishConfigs( platformPackager: PlatformPackager, - targetSpecificOptions: PlatformSpecificBuildOptions | null | undefined, + targetSpecificOptions: PlatformSpecificBuildOptions | Nullish, arch: Arch | null, errorIfCannot: boolean ): Promise | null> { diff --git a/packages/app-builder-lib/src/targets/AppxTarget.ts b/packages/app-builder-lib/src/targets/AppxTarget.ts index b24c54c6d3f..0a4c19ea86c 100644 --- a/packages/app-builder-lib/src/targets/AppxTarget.ts +++ b/packages/app-builder-lib/src/targets/AppxTarget.ts @@ -10,10 +10,11 @@ import { getTemplatePath } from "../util/pathManager" import { VmManager } from "../vm/vm" import { WinPackager } from "../winPackager" import { createStageDir } from "./targetUtil" +import { Nullish, ObjectMap } from "builder-util-runtime" const APPX_ASSETS_DIR_NAME = "appx" -const vendorAssetsForDefaultAssets: { [key: string]: string } = { +const vendorAssetsForDefaultAssets: ObjectMap = { "StoreLogo.png": "SampleAppx.50x50.png", "Square150x150Logo.png": "SampleAppx.150x150.png", "Square44x44Logo.png": "SampleAppx.44x44.png", @@ -386,7 +387,7 @@ export default class AppXTarget extends Target { } // get the resource - language tag, see https://docs.microsoft.com/en-us/windows/uwp/globalizing/manage-language-and-region#specify-the-supported-languages-in-the-apps-manifest -function resourceLanguageTag(userLanguages: Array | null | undefined): string { +function resourceLanguageTag(userLanguages: Array | Nullish): string { if (userLanguages == null || userLanguages.length === 0) { userLanguages = [DEFAULT_RESOURCE_LANG] } diff --git a/packages/app-builder-lib/src/targets/FpmTarget.ts b/packages/app-builder-lib/src/targets/FpmTarget.ts index 95057d952f3..04290db19cc 100644 --- a/packages/app-builder-lib/src/targets/FpmTarget.ts +++ b/packages/app-builder-lib/src/targets/FpmTarget.ts @@ -18,6 +18,7 @@ import { hashFile } from "../util/hash" import { ArtifactCreated } from "../packagerApi" import { getAppUpdatePublishConfiguration } from "../publish/PublishManager" import { getPath7za } from "builder-util" +import { Nullish } from "builder-util-runtime" interface FpmOptions { name: string @@ -60,7 +61,7 @@ export default class FpmTarget extends Target { ...packager.platformSpecificBuildOptions, } - function getResource(value: string | null | undefined, defaultFile: string) { + function getResource(value: string | Nullish, defaultFile: string) { if (value == null) { return path.join(defaultTemplatesDir, defaultFile) } diff --git a/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts b/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts index 8630802a609..c6476c80d30 100644 --- a/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts +++ b/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts @@ -5,6 +5,7 @@ import { LinuxPackager } from "../linuxPackager" import { LinuxTargetSpecificOptions } from "../options/linuxOptions" import { IconInfo } from "../platformPackager" import { join } from "path" +import { ObjectMap } from "builder-util-runtime" export const installPrefix = "/opt" @@ -91,14 +92,14 @@ export class LinuxTargetHelper { } } - async writeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, destination?: string | null, extra?: { [key: string]: string }): Promise { + async writeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, destination?: string | null, extra?: ObjectMap): Promise { const data = await this.computeDesktopEntry(targetSpecificOptions, exec, extra) const file = destination || (await this.packager.getTempFile(`${this.packager.appInfo.productFilename}.desktop`)) await outputFile(file, data) return file } - computeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, extra?: { [key: string]: string }): Promise { + computeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, extra?: ObjectMap): Promise { if (exec != null && exec.length === 0) { throw new Error("Specified exec is empty") } diff --git a/packages/app-builder-lib/src/targets/pkg.ts b/packages/app-builder-lib/src/targets/pkg.ts index c9a9c659e05..cc1514f561b 100644 --- a/packages/app-builder-lib/src/targets/pkg.ts +++ b/packages/app-builder-lib/src/targets/pkg.ts @@ -9,6 +9,7 @@ import { findIdentity, Identity } from "../codeSign/macCodeSign" import { Target } from "../core" import { MacPackager } from "../macPackager" import { readdirSync } from "fs" +import { Nullish } from "builder-util-runtime" const certType = "Developer ID Installer" @@ -205,7 +206,7 @@ export class PkgTarget extends Target { } } -export function prepareProductBuildArgs(identity: Identity | null, keychain: string | null | undefined): Array { +export function prepareProductBuildArgs(identity: Identity | null, keychain: string | Nullish): Array { const args: Array = [] if (identity != null) { args.push("--sign", identity.hash!) diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 770721fc35d..6d4b28a4c70 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -1,5 +1,5 @@ import { Arch, deepAssign, executeAppBuilder, InvalidConfigurationError, log, replaceDefault as _replaceDefault, serializeToYaml, toLinuxArchString } from "builder-util" -import { SnapStoreOptions, asArray } from "builder-util-runtime" +import { Nullish, ObjectMap, SnapStoreOptions, asArray } from "builder-util-runtime" import { outputFile, readFile } from "fs-extra" import { load } from "js-yaml" import * as path from "path" @@ -28,7 +28,7 @@ export default class SnapTarget extends Target { super(name) } - private replaceDefault(inList: Array | null | undefined, defaultList: Array) { + private replaceDefault(inList: Array | Nullish, defaultList: Array) { const result = _replaceDefault(inList, defaultList) if (result !== defaultList) { this.isUseTemplateApp = false @@ -350,7 +350,7 @@ function isArrayEqualRegardlessOfSort(a: Array, b: Array) { return a.length === b.length && a.every((value, index) => value === b[index]) } -function normalizePlugConfiguration(raw: Array | PlugDescriptor | null | undefined): { [key: string]: { [name: string]: any } | null } | null { +function normalizePlugConfiguration(raw: Array | PlugDescriptor | Nullish): ObjectMap | null> | null { if (raw == null) { return null } diff --git a/packages/app-builder-lib/src/util/appBuilder.ts b/packages/app-builder-lib/src/util/appBuilder.ts index 42cd4ba6265..33904775e2d 100644 --- a/packages/app-builder-lib/src/util/appBuilder.ts +++ b/packages/app-builder-lib/src/util/appBuilder.ts @@ -1,4 +1,5 @@ import { executeAppBuilder } from "builder-util" +import { ObjectMap } from "builder-util-runtime" import { SpawnOptions } from "child_process" export function executeAppBuilderAsJson(args: Array): Promise { @@ -28,7 +29,7 @@ export function executeAppBuilderAndWriteJson(args: Array, data: any, ex ) } -export function objectToArgs(to: Array, argNameToValue: { [key: string]: string | null }): void { +export function objectToArgs(to: Array, argNameToValue: ObjectMap): void { for (const name of Object.keys(argNameToValue)) { const value = argNameToValue[name] if (value != null) { diff --git a/packages/app-builder-lib/src/util/bundledTool.ts b/packages/app-builder-lib/src/util/bundledTool.ts index 35a5d513627..60d4dfb71c5 100644 --- a/packages/app-builder-lib/src/util/bundledTool.ts +++ b/packages/app-builder-lib/src/util/bundledTool.ts @@ -1,9 +1,11 @@ +import { Nullish } from "builder-util-runtime" + export interface ToolInfo { path: string env?: any } -export function computeEnv(oldValue: string | null | undefined, newValues: Array): string { +export function computeEnv(oldValue: string | Nullish, newValues: Array): string { const parsedOldValue = oldValue ? oldValue.split(":") : [] return newValues .concat(parsedOldValue) diff --git a/packages/app-builder-lib/src/util/config/config.ts b/packages/app-builder-lib/src/util/config/config.ts index 2aadb917ba1..046954ab413 100644 --- a/packages/app-builder-lib/src/util/config/config.ts +++ b/packages/app-builder-lib/src/util/config/config.ts @@ -7,6 +7,7 @@ import { Configuration } from "../../configuration" import { FileSet } from "../../options/PlatformSpecificBuildOptions" import { reactCra } from "../../presets/rectCra" import { PACKAGE_VERSION } from "../../version" +import { Nullish, ObjectMap } from "builder-util-runtime" const validateSchema = require("@develar/schema-utils") // https://github.com/electron-userland/electron-builder/issues/1847 @@ -35,8 +36,8 @@ function mergePublish(config: Configuration, configFromOptions: Configuration) { export async function getConfig( projectDir: string, configPath: string | null, - configFromOptions: Configuration | null | undefined, - packageMetadata: Lazy<{ [key: string]: any } | null> = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json")))) + configFromOptions: Configuration | Nullish, + packageMetadata: Lazy | null> = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json")))) ): Promise { const configRequest: ReadConfigRequest = { packageKey: "build", configFilename: "electron-builder", projectDir, packageMetadata } const configAndEffectiveFile = await _getConfig(configRequest, configPath) @@ -81,7 +82,7 @@ export async function getConfig( return doMergeConfigs([...parentConfigs, config]) } -function asArray(value: string[] | string | undefined | null): string[] { +function asArray(value: string[] | string | Nullish): string[] { return Array.isArray(value) ? value : typeof value === "string" ? [value] : [] } @@ -263,7 +264,7 @@ export async function validateConfiguration(config: Configuration, debugLogger: const DEFAULT_APP_DIR_NAMES = ["app", "www"] -export async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | null | undefined): Promise { +export async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | Nullish): Promise { if (userAppDir != null) { const absolutePath = path.resolve(projectDir, userAppDir) const stat = await statOrNull(absolutePath) diff --git a/packages/app-builder-lib/src/util/config/load.ts b/packages/app-builder-lib/src/util/config/load.ts index c4f21b793b6..c476ac5850b 100644 --- a/packages/app-builder-lib/src/util/config/load.ts +++ b/packages/app-builder-lib/src/util/config/load.ts @@ -7,6 +7,7 @@ import { loadTsConfig } from "config-file-ts" import { DotenvParseInput, expand } from "dotenv-expand" import { resolveModule } from "../resolve" import { log } from "builder-util" +import { ObjectMap } from "builder-util-runtime" export interface ReadConfigResult { readonly result: T @@ -73,7 +74,7 @@ export interface ReadConfigRequest { configFilename: string projectDir: string - packageMetadata: Lazy<{ [key: string]: any } | null> | null + packageMetadata: Lazy | null> | null } export async function loadConfig(request: ReadConfigRequest): Promise | null> { diff --git a/packages/app-builder-lib/src/util/license.ts b/packages/app-builder-lib/src/util/license.ts index cd8981df661..feb15ee559a 100644 --- a/packages/app-builder-lib/src/util/license.ts +++ b/packages/app-builder-lib/src/util/license.ts @@ -1,6 +1,7 @@ import * as path from "path" import { langIdToName, toLangWithRegion } from "./langs" import { PlatformPackager } from "../platformPackager" +import { Nullish } from "builder-util-runtime" export function getLicenseAssets(fileNames: Array, packager: PlatformPackager) { return fileNames @@ -24,7 +25,7 @@ export function getLicenseAssets(fileNames: Array, packager: PlatformPac } export async function getNotLocalizedLicenseFile( - custom: string | null | undefined, + custom: string | Nullish, packager: PlatformPackager, supportedExtension: Array = ["rtf", "txt", "html"] ): Promise { diff --git a/packages/app-builder-lib/src/util/macroExpander.ts b/packages/app-builder-lib/src/util/macroExpander.ts index 90f0aa09b94..f7a81bce70e 100644 --- a/packages/app-builder-lib/src/util/macroExpander.ts +++ b/packages/app-builder-lib/src/util/macroExpander.ts @@ -1,7 +1,8 @@ import { InvalidConfigurationError } from "builder-util" import { AppInfo } from "../appInfo" +import { Nullish } from "builder-util-runtime" -export function expandMacro(pattern: string, arch: string | null | undefined, appInfo: AppInfo, extra: any = {}, isProductNameSanitized = true): string { +export function expandMacro(pattern: string, arch: string | Nullish, appInfo: AppInfo, extra: any = {}, isProductNameSanitized = true): string { if (arch == null) { pattern = pattern // tslint:disable-next-line:no-invalid-template-strings diff --git a/packages/app-builder-lib/src/util/packageMetadata.ts b/packages/app-builder-lib/src/util/packageMetadata.ts index d896fab600c..76decc4d938 100644 --- a/packages/app-builder-lib/src/util/packageMetadata.ts +++ b/packages/app-builder-lib/src/util/packageMetadata.ts @@ -4,6 +4,7 @@ import * as path from "path" import * as semver from "semver" import { Metadata } from "../options/metadata" import { normalizePackageData } from "./normalizePackageData" +import { Nullish, ObjectMap } from "builder-util-runtime" /** @internal */ export async function readPackageJson(file: string): Promise { @@ -38,7 +39,7 @@ export function checkMetadata(metadata: Metadata, devMetadata: any | null, appPa errors.push(`Please specify '${missedFieldName}' in the package.json (${appPackageFile})`) } - const checkNotEmpty = (name: string, value: string | null | undefined) => { + const checkNotEmpty = (name: string, value: string | Nullish) => { if (isEmptyOrSpaces(value)) { reportError(name) } @@ -92,7 +93,7 @@ function versionSatisfies(version: string | semver.SemVer | null, range: string return semver.satisfies(coerced, range, loose) } -function checkDependencies(dependencies: { [key: string]: string } | null | undefined, errors: Array) { +function checkDependencies(dependencies: ObjectMap | Nullish, errors: Array) { if (dependencies == null) { return } diff --git a/packages/app-builder-lib/src/util/yarn.ts b/packages/app-builder-lib/src/util/yarn.ts index da721ab266f..e0d6c3fd608 100644 --- a/packages/app-builder-lib/src/util/yarn.ts +++ b/packages/app-builder-lib/src/util/yarn.ts @@ -10,6 +10,7 @@ import { getProjectRootPath } from "@electron/rebuild/lib/search-module" import { rebuild as remoteRebuild } from "./rebuild/rebuild" import { executeAppBuilderAndWriteJson } from "./appBuilder" import { RebuildMode } from "@electron/rebuild/lib/types" +import { Nullish } from "builder-util-runtime" export async function installOrRebuild(config: Configuration, appDir: string, options: RebuildOptions, forceInstall = false) { const effectiveOptions: RebuildOptions = { @@ -153,7 +154,7 @@ function getPackageToolPath() { } } -function isRunningYarn(execPath: string | null | undefined) { +function isRunningYarn(execPath: string | Nullish) { const userAgent = process.env.npm_config_user_agent return process.env.FORCE_YARN === "true" || (execPath != null && path.basename(execPath).startsWith("yarn")) || (userAgent != null && /\byarn\b/.test(userAgent)) } diff --git a/packages/app-builder-lib/src/winPackager.ts b/packages/app-builder-lib/src/winPackager.ts index e29bde660ef..ef1c1cfb6c1 100644 --- a/packages/app-builder-lib/src/winPackager.ts +++ b/packages/app-builder-lib/src/winPackager.ts @@ -25,6 +25,7 @@ import { time } from "./util/timer" import { getWindowsVm, VmManager } from "./vm/vm" import { execWine } from "./wine" import { SignManager } from "./codeSign/signManager" +import { Nullish } from "builder-util-runtime" export class WinPackager extends PlatformPackager { _iconPath = new Lazy(() => this.getOrConvertIcon("ico")) @@ -114,7 +115,7 @@ export class WinPackager extends PlatformPackager { return this._iconPath.value } - doGetCscPassword(): string | undefined | null { + doGetCscPassword(): string | Nullish { return chooseNotNull(chooseNotNull(this.platformSpecificBuildOptions.signtoolOptions?.certificatePassword, process.env.WIN_CSC_KEY_PASSWORD), super.doGetCscPassword()) } diff --git a/packages/builder-util-runtime/src/httpExecutor.ts b/packages/builder-util-runtime/src/httpExecutor.ts index 0da8772e70b..55080b4521d 100644 --- a/packages/builder-util-runtime/src/httpExecutor.ts +++ b/packages/builder-util-runtime/src/httpExecutor.ts @@ -8,6 +8,7 @@ import { URL } from "url" import { CancellationToken } from "./CancellationToken" import { newError } from "./error" import { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTransform" +import { Nullish } from "." const debug = _debug("electron-builder") @@ -424,7 +425,7 @@ export class DigestTransform extends Transform { } } -function checkSha2(sha2Header: string | null | undefined, sha2: string | null | undefined, callback: (error: Error | null) => void): boolean { +function checkSha2(sha2Header: string | Nullish, sha2: string | Nullish, callback: (error: Error | null) => void): boolean { if (sha2Header != null && sha2 != null && sha2Header !== sha2) { callback(new Error(`checksum mismatch: expected ${sha2} but got ${sha2Header} (X-Checksum-Sha2 header)`)) return false diff --git a/packages/builder-util-runtime/src/index.ts b/packages/builder-util-runtime/src/index.ts index 2947b1be854..0337b0074f3 100644 --- a/packages/builder-util-runtime/src/index.ts +++ b/packages/builder-util-runtime/src/index.ts @@ -44,7 +44,7 @@ export const CURRENT_APP_INSTALLER_FILE_NAME = "installer.exe" // nsis-web export const CURRENT_APP_PACKAGE_FILE_NAME = "package.7z" -export function asArray(v: null | undefined | T | Array): Array { +export function asArray(v: Nullish | T | Array): Array { if (v == null) { return [] } else if (Array.isArray(v)) { @@ -53,3 +53,7 @@ export function asArray(v: null | undefined | T | Array): Array { return [v] } } + +export type Nullish = null | undefined + +export type ObjectMap = { [key: string]: ValueType } diff --git a/packages/builder-util-runtime/src/publishOptions.ts b/packages/builder-util-runtime/src/publishOptions.ts index bc81327fb75..4dc2e118a87 100644 --- a/packages/builder-util-runtime/src/publishOptions.ts +++ b/packages/builder-util-runtime/src/publishOptions.ts @@ -1,4 +1,5 @@ import { OutgoingHttpHeaders } from "http" +import { Nullish } from "." export type PublishProvider = "github" | "s3" | "spaces" | "generic" | "custom" | "snapStore" | "keygen" | "bitbucket" @@ -427,7 +428,7 @@ function s3Url(options: S3Options) { return appendPath(url, options.path) } -function appendPath(url: string, p: string | null | undefined): string { +function appendPath(url: string, p: string | Nullish): string { if (p != null && p.length > 0) { if (!p.startsWith("/")) { url += "/" diff --git a/packages/builder-util-runtime/src/uuid.ts b/packages/builder-util-runtime/src/uuid.ts index e5a1b7fd243..74d5f6f1ca2 100644 --- a/packages/builder-util-runtime/src/uuid.ts +++ b/packages/builder-util-runtime/src/uuid.ts @@ -26,7 +26,7 @@ export class UUID { private readonly version: number // from rfc4122#appendix-C - static readonly OID = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8") + static readonly OID: Buffer = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8") constructor(uuid: Buffer | string) { const check = UUID.check(uuid) @@ -103,7 +103,7 @@ export class UUID { } // read stringified uuid into a Buffer - static parse(input: string) { + static parse(input: string): Buffer { const buffer = Buffer.allocUnsafe(16) let j = 0 for (let i = 0; i < 16; i++) { diff --git a/packages/builder-util-runtime/src/xml.ts b/packages/builder-util-runtime/src/xml.ts index 78d2daa2b44..a6b5296fedc 100644 --- a/packages/builder-util-runtime/src/xml.ts +++ b/packages/builder-util-runtime/src/xml.ts @@ -1,9 +1,10 @@ import * as sax from "sax" import { newError } from "./error" +import { ObjectMap } from "./" export class XElement { value = "" - attributes: { [key: string]: string } | null = null + attributes: ObjectMap | null = null isCData = false elements: Array | null = null @@ -83,7 +84,7 @@ export function parseXml(data: string): XElement { parser.onopentag = saxElement => { const element = new XElement(saxElement.name) - element.attributes = saxElement.attributes as { [key: string]: string } + element.attributes = saxElement.attributes as ObjectMap if (rootElement === null) { rootElement = element diff --git a/packages/builder-util/src/fs.ts b/packages/builder-util/src/fs.ts index 307bddced65..efe0f4a5554 100644 --- a/packages/builder-util/src/fs.ts +++ b/packages/builder-util/src/fs.ts @@ -8,6 +8,7 @@ import { Mode } from "stat-mode" import { log } from "./log" import { orIfFileNotExist, orNullIfFileNotExist } from "./promise" import * as isCI from "is-ci" +import { Nullish } from "builder-util-runtime" export const MAX_FILE_REQUESTS = 8 export const CONCURRENCY = { concurrency: MAX_FILE_REQUESTS } @@ -216,7 +217,7 @@ export function copyOrLinkFile(src: string, dest: string, stats?: Stats | null, return doCopyFile(src, dest, stats) } -function doCopyFile(src: string, dest: string, stats: Stats | null | undefined): Promise { +function doCopyFile(src: string, dest: string, stats: Stats | Nullish): Promise { const promise = _nodeCopyFile(src, dest) if (stats == null) { return promise diff --git a/packages/builder-util/src/util.ts b/packages/builder-util/src/util.ts index 0bc464579e5..57105b05d80 100644 --- a/packages/builder-util/src/util.ts +++ b/packages/builder-util/src/util.ts @@ -1,5 +1,5 @@ import { appBuilderPath } from "app-builder-bin" -import { safeStringifyJson, retry as _retry } from "builder-util-runtime" +import { safeStringifyJson, retry as _retry, ObjectMap, Nullish } from "builder-util-runtime" import * as chalk from "chalk" import { ChildProcess, execFile, ExecFileOptions, SpawnOptions } from "child_process" import { spawn as _spawn } from "cross-spawn" @@ -52,7 +52,7 @@ export function removePassword(input: string) { }) } -function getProcessEnv(env: { [key: string]: string | undefined } | undefined | null): NodeJS.ProcessEnv | undefined { +function getProcessEnv(env: ObjectMap | Nullish): NodeJS.ProcessEnv | undefined { if (process.platform === "win32") { return env == null ? undefined : env } @@ -276,12 +276,11 @@ export class ExecError extends Error { } } -type Nullish = null | undefined export function use(value: T | Nullish, task: (value: T) => R): R | null { return value == null ? null : task(value) } -export function isEmptyOrSpaces(s: string | null | undefined): s is "" | null | undefined { +export function isEmptyOrSpaces(s: string | Nullish): s is "" | Nullish { return s == null || s.trim().length === 0 } @@ -298,7 +297,7 @@ export function addValue(map: Map>, key: K, value: T) { } } -export function replaceDefault(inList: Array | null | undefined, defaultList: Array): Array { +export function replaceDefault(inList: Array | Nullish, defaultList: Array): Array { if (inList == null || (inList.length === 1 && inList[0] === "default")) { return defaultList } @@ -315,7 +314,7 @@ export function replaceDefault(inList: Array | null | undefined, default return inList } -export function getPlatformIconFileName(value: string | null | undefined, isMac: boolean) { +export function getPlatformIconFileName(value: string | Nullish, isMac: boolean) { if (value === undefined) { return undefined } @@ -346,7 +345,7 @@ export function isPullRequest() { ) } -export function isEnvTrue(value: string | null | undefined) { +export function isEnvTrue(value: string | Nullish) { if (value != null) { value = value.trim() } diff --git a/packages/dmg-builder/src/dmg.ts b/packages/dmg-builder/src/dmg.ts index 238ea4d293c..8b236893137 100644 --- a/packages/dmg-builder/src/dmg.ts +++ b/packages/dmg-builder/src/dmg.ts @@ -5,7 +5,7 @@ import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateIn import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder" import { sanitizeFileName } from "builder-util/out/filename" import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, copyDir, copyFile, exists, statOrNull } from "builder-util" -import { CancellationToken } from "builder-util-runtime" +import { CancellationToken, Nullish } from "builder-util-runtime" import { stat } from "fs-extra" import * as path from "path" import { TmpDir } from "temp-file" @@ -212,7 +212,7 @@ function addLogLevel(args: Array): Array { return args } -async function computeAssetSize(cancellationToken: CancellationToken, dmgFile: string, specification: DmgOptions, backgroundFile: string | null | undefined) { +async function computeAssetSize(cancellationToken: CancellationToken, dmgFile: string, specification: DmgOptions, backgroundFile: string | Nullish) { const asyncTaskManager = new AsyncTaskManager(cancellationToken) asyncTaskManager.addTask(stat(dmgFile)) @@ -233,7 +233,7 @@ async function computeAssetSize(cancellationToken: CancellationToken, dmgFile: s return result } -async function customizeDmg(volumePath: string, specification: DmgOptions, packager: MacPackager, backgroundFile: string | null | undefined) { +async function customizeDmg(volumePath: string, specification: DmgOptions, packager: MacPackager, backgroundFile: string | Nullish) { const window = specification.window const isValidIconTextSize = !!specification.iconTextSize && specification.iconTextSize >= 10 && specification.iconTextSize <= 16 const iconTextSize = isValidIconTextSize ? specification.iconTextSize : 12 diff --git a/test/src/updater/differentialUpdateTest.ts b/test/src/updater/differentialUpdateTest.ts index 2e63d937ea3..8d00cb185bf 100644 --- a/test/src/updater/differentialUpdateTest.ts +++ b/test/src/updater/differentialUpdateTest.ts @@ -1,7 +1,7 @@ import { Arch, Configuration, Platform } from "app-builder-lib" import { getBinFromUrl } from "app-builder-lib/out/binDownload" import { doSpawn, getArchSuffix } from "builder-util" -import { GenericServerOptions, S3Options } from "builder-util-runtime" +import { GenericServerOptions, Nullish, S3Options } from "builder-util-runtime" import { AppImageUpdater, BaseUpdater, MacUpdater, NoOpLogger, NsisUpdater } from "electron-updater" import { EventEmitter } from "events" import { move } from "fs-extra" @@ -29,7 +29,7 @@ async function doBuild(outDirs: Array, targets: Map>>, - extraConfig: Configuration | null | undefined, + extraConfig: Configuration | Nullish, packed: (context: PackedContext) => Promise ) { await assertPack(