Skip to content

Commit

Permalink
fix: allow skipLibCheck: false (#8813)
Browse files Browse the repository at this point in the history
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]:
<anything> }` everywhere.
- Updated eslint to register `test/tsconfig.json`
- Fixes `skipLibCheck: false` by forcing UUID.ts to return a `Buffer`
instead of `Buffer<ArrayBuffer>`, which the compiler doesn't like
depending on version of node you're on
  • Loading branch information
mmaietta authored Jan 27, 2025
1 parent 2ee64a4 commit 0742966
Show file tree
Hide file tree
Showing 40 changed files with 124 additions and 87 deletions.
8 changes: 8 additions & 0 deletions .changeset/metal-bulldogs-film.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default [{
sourceType: "script",

parserOptions: {
project: ["./packages/*/tsconfig.json"],
project: ["./packages/*/tsconfig.json", "./test/tsconfig.json"],
},
},

Expand Down
5 changes: 3 additions & 2 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions packages/app-builder-lib/src/asar/asar.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<Node>

unpacked?: boolean

Expand All @@ -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()
}
}

Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -131,6 +132,10 @@ export class AsarFilesystem {
readFile(file: string): Promise<Buffer> {
return readFileFromAsar(this, file, this.getFile(file))
}

private newNode() {
return Object.create(null) as ObjectMap<Node>
}
}

export async function readAsarHeader(archive: string): Promise<ReadAsarHeader> {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/binDownload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { executeAppBuilder } from "builder-util"
import { Nullish } from "builder-util-runtime"

const versionToPromise = new Map<string, Promise<string>>()

Expand Down Expand Up @@ -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<string> {
function doGetBin(name: string, url: string | Nullish, checksum: string | Nullish): Promise<string> {
const args = ["download-artifact", "--name", name]
if (url != null) {
args.push("--url", url)
Expand Down
9 changes: 2 additions & 7 deletions packages/app-builder-lib/src/codeSign/macCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:"]

Expand Down Expand Up @@ -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 = ""
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/codeSign/signManager.ts
Original file line number Diff line number Diff line change
@@ -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<Array<string> | null>
readonly cscInfo: MemoLazy<WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null>
computePublisherName(target: Target, publisherName: string | null | undefined): Promise<string>
computePublisherName(target: Target, publisherName: string | Nullish): Promise<string>
initialize(): Promise<void>
signFile(options: WindowsSignOptions): Promise<boolean>
}
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/core.ts
Original file line number Diff line number Diff line change
@@ -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<AllPublishOptions> | null
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/electron/electronVersion.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<ObjectMap<any> | null>

const electronPackages = ["electron", "electron-prebuilt", "electron-prebuilt-compile", "electron-nightly"]

Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -38,7 +39,6 @@ function ensureNoEndSlash(file: string): string {
}
}

/** @internal */
export class FileMatcher {
readonly from: string
readonly to: string
Expand Down Expand Up @@ -233,7 +233,7 @@ export function getNodeModuleFileMatcher(
// grab only excludes
const matcher = new FileMatcher(appDir, destination, macroExpander)

function addPatterns(patterns: Array<string | FileSet> | string | null | undefined | FileSet) {
function addPatterns(patterns: Array<string | FileSet> | string | Nullish | FileSet) {
if (patterns == null) {
return
} else if (!Array.isArray(patterns)) {
Expand Down Expand Up @@ -295,7 +295,7 @@ export function getFileMatchers(
const defaultMatcher = new FileMatcher(options.defaultSrc, defaultDestination, options.macroExpander)
const fileMatchers: Array<FileMatcher> = []

function addPatterns(patterns: Array<string | FileSet> | string | null | undefined | FileSet) {
function addPatterns(patterns: Array<string | FileSet> | string | Nullish | FileSet) {
if (patterns == null) {
return
} else if (!Array.isArray(patterns)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -443,7 +443,7 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
}

//noinspection JSMethodCanBeStatic
protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | null | undefined): Promise<any> {
protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | Nullish): Promise<any> {
// productbuild doesn't created directory for out file
await mkdir(path.dirname(outFile), { recursive: true })

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ObjectMap } from "builder-util-runtime"
import { CompressionLevel, Publish, TargetConfiguration, TargetSpecificOptions } from "../core"
import { FileAssociation } from "./FileAssociation"

Expand Down Expand Up @@ -224,7 +225,7 @@ export interface ReleaseInfo {
/**
* Vendor specific information.
*/
vendor?: { [key: string]: any } | null
vendor?: ObjectMap<any> | null
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ObjectMap } from "builder-util-runtime"
import { TargetSpecificOptions } from "../core"
import { CommonLinuxOptions } from "./linuxOptions"

Expand All @@ -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<string> | null

/**
* The 78 character long summary. Defaults to [productName](./configuration.md#productName).
Expand Down Expand Up @@ -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<ObjectMap<string>> | 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.
Expand All @@ -144,9 +145,9 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
}

export interface PlugDescriptor {
[key: string]: { [key: string]: any } | null
[key: string]: ObjectMap<any> | null
}

export interface SlotDescriptor {
[key: string]: { [key: string]: any } | null
[key: string]: ObjectMap<any> | null
}
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/options/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ObjectMap } from "builder-util-runtime"
import { Configuration } from "../configuration"

export interface Metadata {
Expand Down Expand Up @@ -37,7 +38,7 @@ export interface Metadata {
readonly build?: Configuration

/** @private */
readonly dependencies?: { [key: string]: string }
readonly dependencies?: ObjectMap<string>
/** @private */
readonly version?: string
/** @private */
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/options/winOptions.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 0742966

Please sign in to comment.