Skip to content

Commit

Permalink
chore: change printWidth from 250 to 180 (electron-userland#5714)
Browse files Browse the repository at this point in the history
* chore: change printWidth from 250 to 180, put test sources under prettier control

See https://prettier.io/docs/en/options.html#print-width

> Prettier’s printWidth option does not work the same way. It is not the hard upper allowed line length limit. It is a way to say to Prettier roughly how long you’d like lines to be. Prettier will make both shorter and longer lines, but generally strive to meet the specified printWidth.

* chore: enable @typescript-eslint/no-extra-non-null-assertion, @typescript-eslint/no-use-before-define, @typescript-eslint/no-inferrable-types rules
  • Loading branch information
develar authored Mar 15, 2021
1 parent 3dfb731 commit a879ba7
Show file tree
Hide file tree
Showing 147 changed files with 4,445 additions and 3,217 deletions.
39 changes: 18 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
rules: {
semi: "off",
"@typescript-eslint/member-delimiter-style": ["error", {
multiline: {
delimiter: "none",
"prettier/prettier": process.env.CI ? "error" : "warn",
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "none",
},
},
}],
],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-extra-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"no-constant-condition": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-function-return-type": ["off", {
// "allowExpressions": false,
}]
}
}
"@typescript-eslint/explicit-function-return-type": [
"off",
{
// "allowExpressions": false,
},
],
},
}
4 changes: 2 additions & 2 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
singleQuote: false
semi: false
arrowParens: avoid
trailingComma: all
printWidth: 250
trailingComma: es5
printWidth: 180
quoteProps: as-needed
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lint": "eslint packages --ext .ts",
"lint-deps": "node ./test/out/helpers/checkDeps.js",
"pretest": "pnpm compile && pnpm lint && pnpm lint-deps",
"prettier": "prettier \"packages/**/*.{ts, js}\" --write",
"prettier": "prettier 'packages/**/*.{ts, js}' 'test/src/**/*.ts' --write",
"///": "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",
Expand All @@ -44,8 +44,8 @@
"dmg-license": "~1.0.8"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/ProtonFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class ProtonFramework extends LibUiFramework {
{
options: safeStringifyJson(
babelOptions,
new Set<string>(["presets"]),
new Set<string>(["presets"])
),
},
"transpile source code using Babel",
"transpile source code using Babel"
)
return (file): Promise<any> | null => {
if (!(file.endsWith(".js") || file.endsWith(".jsx")) || file.includes(NODE_MODULES_PATTERN)) {
Expand Down
14 changes: 10 additions & 4 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ export class AppInfo {
readonly productFilename: string

constructor(private readonly info: Packager, buildVersion: string | null | undefined, private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null) {
this.version = info.metadata.version!!
this.version = info.metadata.version!

if (buildVersion == null) {
buildVersion = info.config.buildVersion
}

this.buildNumber = process.env.BUILD_NUMBER || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_BUILDNUMBER || process.env.CI_PIPELINE_IID
this.buildNumber =
process.env.BUILD_NUMBER ||
process.env.TRAVIS_BUILD_NUMBER ||
process.env.APPVEYOR_BUILD_NUMBER ||
process.env.CIRCLE_BUILD_NUM ||
process.env.BUILD_BUILDNUMBER ||
process.env.CI_PIPELINE_IID
if (buildVersion == null) {
buildVersion = this.version
if (!isEmptyOrSpaces(this.buildNumber)) {
Expand All @@ -55,7 +61,7 @@ export class AppInfo {
this.shortVersionWindows = info.metadata.shortVersionWindows
}

this.productName = info.config.productName || info.metadata.productName || info.metadata.name!!
this.productName = info.config.productName || info.metadata.productName || info.metadata.name!
this.sanitizedProductName = sanitizeFileName(this.productName)
this.productFilename = platformSpecificOptions?.executableName != null ? sanitizeFileName(platformSpecificOptions.executableName) : this.sanitizedProductName
}
Expand Down Expand Up @@ -114,7 +120,7 @@ export class AppInfo {
}

get name(): string {
return this.info.metadata.name!!
return this.info.metadata.name!
}

get linuxPackageName(): string {
Expand Down
10 changes: 5 additions & 5 deletions packages/app-builder-lib/src/asar/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export class AsarFilesystem {
}

getNode(p: string): Node | null {
const node = this.searchNodeFromDirectory(path.dirname(p), false)!!
return node.files!![path.basename(p)]
const node = this.searchNodeFromDirectory(path.dirname(p), false)!
return node.files![path.basename(p)]
}

getFile(p: string, followLinks: boolean = true): Node {
getFile(p: string, followLinks = true): Node {
const info = this.getNode(p)!
// if followLinks is false we don't resolve symlinks
return followLinks && info.link != null ? this.getFile(info.link) : info
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function readAsarJson(archive: string, file: string): Promise<any>
}

async function readFileFromAsar(filesystem: AsarFilesystem, filename: string, info: Node): Promise<Buffer> {
const size = info.size!!
const size = info.size!
const buffer = Buffer.allocUnsafe(size)
if (size <= 0) {
return buffer
Expand All @@ -157,7 +157,7 @@ async function readFileFromAsar(filesystem: AsarFilesystem, filename: string, in

const fd = await open(filesystem.src, "r")
try {
const offset = 8 + filesystem.headerSize + parseInt(info.offset!!, 10)
const offset = 8 + filesystem.headerSize + parseInt(info.offset!, 10)
await read(fd, buffer, 0, size, offset)
} finally {
await close(fd)
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/asar/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class AsarPackager {
let files = fileSets[0].files
let metadata = fileSets[0].metadata
let transformedFiles = fileSets[0].transformedFiles
let unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[0])!!
let unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[0])!
const w = (index: number) => {
while (true) {
if (index >= files.length) {
Expand All @@ -169,7 +169,7 @@ export class AsarPackager {
files = fileSets[fileSetIndex].files
metadata = fileSets[fileSetIndex].metadata
transformedFiles = fileSets[fileSetIndex].transformedFiles
unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[fileSetIndex])!!
unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[fileSetIndex])!
index = 0
}
}
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
Expand Up @@ -29,7 +29,7 @@ export async function computeData(resourcesPath: string, options?: AsarIntegrity
return { checksums: result, ...options }
}

function hashFile(file: string, algorithm: string = "sha512", encoding: "hex" | "base64" | "latin1" = "base64") {
function hashFile(file: string, algorithm = "sha512", encoding: "hex" | "base64" | "latin1" = "base64") {
return new Promise<string>((resolve, reject) => {
const hash = createHash(algorithm)
hash.on("error", reject).setEncoding(encoding)
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/asar/unpackDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDir
}
})
},
CONCURRENCY,
CONCURRENCY
)
}
}
27 changes: 20 additions & 7 deletions packages/app-builder-lib/src/codeSign/macCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ export function isSignAllowed(isPrintWarn = true): boolean {
} else {
if (isPrintWarn) {
// https://github.com/electron-userland/electron-builder/issues/1524
log.warn("Current build is a part of pull request, code signing will be skipped." + "\nSet env CSC_FOR_PULL_REQUEST to true to force code signing." + `\n${buildForPrWarning}`)
log.warn(
"Current build is a part of pull request, code signing will be skipped." + "\nSet env CSC_FOR_PULL_REQUEST to true to force code signing." + `\n${buildForPrWarning}`
)
}
return false
}
}
return true
}

export async function reportError(isMas: boolean, certificateType: CertType, qualifier: string | null | undefined, keychainFile: string | null | undefined, isForceCodeSigning: boolean) {
export async function reportError(
isMas: boolean,
certificateType: CertType,
qualifier: string | null | undefined,
keychainFile: string | null | undefined,
isForceCodeSigning: boolean
) {
const logFields: Fields = {}
if (qualifier == null) {
logFields.reason = ""
Expand Down Expand Up @@ -92,7 +100,10 @@ const bundledCertKeychainAdded = new Lazy<void>(async () => {
const cacheDir = getCacheDirectory()
const tmpKeychainPath = path.join(cacheDir, getTempName("electron-builder-root-certs"))
const keychainPath = path.join(cacheDir, "electron-builder-root-certs.keychain")
const results = await Promise.all<any>([listUserKeychains(), copyFile(path.join(__dirname, "..", "..", "certs", "root_certs.keychain"), tmpKeychainPath).then(() => rename(tmpKeychainPath, keychainPath))])
const results = await Promise.all<any>([
listUserKeychains(),
copyFile(path.join(__dirname, "..", "..", "certs", "root_certs.keychain"), tmpKeychainPath).then(() => rename(tmpKeychainPath, keychainPath)),
])
const list = results[0]
if (!list.includes(keychainPath)) {
await exec("security", ["list-keychains", "-d", "user", "-s", keychainPath].concat(list))
Expand All @@ -101,7 +112,7 @@ const bundledCertKeychainAdded = new Lazy<void>(async () => {

function getCacheDirectory(): string {
const env = process.env.ELECTRON_BUILDER_CACHE
return isEmptyOrSpaces(env) ? path.join(homedir(), "Library", "Caches", "electron-builder") : path.resolve(env!!)
return isEmptyOrSpaces(env) ? path.join(homedir(), "Library", "Caches", "electron-builder") : path.resolve(env!)
}

function listUserKeychains(): Promise<Array<string>> {
Expand All @@ -112,7 +123,7 @@ function listUserKeychains(): Promise<Array<string>> {
const r = it.trim()
return r.substring(1, r.length - 1)
})
.filter(it => it.length > 0),
.filter(it => it.length > 0)
)
}

Expand Down Expand Up @@ -227,13 +238,15 @@ async function getValidIdentities(keychain?: string | null): Promise<Array<strin
}
}
return false
}),
})
),
exec("security", addKeychain(["find-identity", "-v", "-p", "codesigning"])).then(it => it.trim().split("\n")),
]).then(it => {
const array = it[0]
.concat(it[1])
.filter(it => !it.includes("(Missing required extension)") && !it.includes("valid identities found") && !it.includes("iPhone ") && !it.includes("com.apple.idms.appleid.prd."))
.filter(
it => !it.includes("(Missing required extension)") && !it.includes("valid identities found") && !it.includes("iPhone ") && !it.includes("com.apple.idms.appleid.prd.")
)
// remove 1)
.map(it => it.substring(it.indexOf(")") + 1).trim())
return Array.from(new Set(array))
Expand Down
18 changes: 13 additions & 5 deletions packages/app-builder-lib/src/codeSign/windowsCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function sign(options: WindowsSignOptions, packager: WinPackager) {
...taskConfiguration,
computeSignToolArgs: isWin => computeSignToolArgs(taskConfiguration, isWin),
},
packager,
packager
)
isNest = true
if (taskConfiguration.resultOutputPath != null) {
Expand Down Expand Up @@ -108,10 +108,15 @@ export async function getCertificateFromStoreInfo(options: WindowsConfiguration,
const certificateSha1 = options.certificateSha1 ? options.certificateSha1.toUpperCase() : options.certificateSha1
// 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", ["Get-ChildItem -Recurse Cert: -CodeSigningCert | Select-Object -Property Subject,PSParentPath,Thumbprint | ConvertTo-Json -Compress"])
const rawResult = await vm.exec("powershell.exe", [
"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) {
if ((certificateSubjectName != null && !certInfo.Subject.includes(certificateSubjectName)) || (certificateSha1 != null && certInfo.Thumbprint.toUpperCase() !== certificateSha1)) {
if (
(certificateSubjectName != null && !certInfo.Subject.includes(certificateSubjectName)) ||
(certificateSha1 != null && certInfo.Thumbprint.toUpperCase() !== certificateSha1)
) {
continue
}

Expand Down Expand Up @@ -140,7 +145,7 @@ export async function doSign(configuration: CustomWindowsSignTaskConfiguration,
let args: Array<string>
let env = process.env
let vm: VmManager
if (configuration.path.endsWith(".appx") || !("file" in configuration.cscInfo!!) /* certificateSubjectName and other such options */) {
if (configuration.path.endsWith(".appx") || !("file" in configuration.cscInfo!) /* certificateSubjectName and other such options */) {
vm = await packager.vm.value
tool = getWinSignTool(await getSignVendorPath())
args = computeSignToolArgs(configuration, true, vm)
Expand Down Expand Up @@ -188,7 +193,10 @@ function computeSignToolArgs(options: WindowsSignTaskConfiguration, isWin: boole
if (process.env.ELECTRON_BUILDER_OFFLINE !== "true") {
const timestampingServiceUrl = options.options.timeStampServer || "http://timestamp.digicert.com"
if (isWin) {
args.push(options.isNest || options.hash === "sha256" ? "/tr" : "/t", options.isNest || options.hash === "sha256" ? options.options.rfc3161TimeStampServer || "http://timestamp.digicert.com" : timestampingServiceUrl)
args.push(
options.isNest || options.hash === "sha256" ? "/tr" : "/t",
options.isNest || options.hash === "sha256" ? options.options.rfc3161TimeStampServer || "http://timestamp.digicert.com" : timestampingServiceUrl
)
} else {
args.push("-t", timestampingServiceUrl)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/electron/ElectronFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {
}
return
},
CONCURRENCY,
CONCURRENCY
)
}
}
Expand Down
18 changes: 13 additions & 5 deletions packages/app-builder-lib/src/electron/electronMac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ function moveHelpers(helperSuffixes: Array<string>, frameworksPath: string, appN
})
}

function getAvailableHelperSuffixes(helperEHPlist: string | null, helperNPPlist: string | null, helperRendererPlist: string | null, helperPluginPlist: string | null, helperGPUPlist: string | null) {
function getAvailableHelperSuffixes(
helperEHPlist: string | null,
helperNPPlist: string | null,
helperRendererPlist: string | null,
helperPluginPlist: string | null,
helperGPUPlist: string | null
) {
const result = [" Helper"]
if (helperEHPlist != null) {
result.push(" Helper EH")
Expand Down Expand Up @@ -82,8 +88,8 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
throw new Error("corrupted Electron dist")
}

const appPlist = plistContent[0]!!
const helperPlist = plistContent[1]!!
const appPlist = plistContent[0]!
const helperPlist = plistContent[1]!
const helperEHPlist = plistContent[2]
const helperNPPlist = plistContent[3]
const helperRendererPlist = plistContent[4]
Expand All @@ -96,7 +102,7 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
Object.assign(appPlist, plistContent[8])
}

const buildMetadata = packager.config!!
const buildMetadata = packager.config!

/**
* Configure bundleIdentifier for the generic Electron Helper process
Expand Down Expand Up @@ -135,7 +141,9 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
function configureHelper(helper: any, postfix: string, userProvidedBundleIdentifier?: string | null) {
helper.CFBundleExecutable = `${appFilename} Helper ${postfix}`
helper.CFBundleDisplayName = `${appInfo.productName} Helper ${postfix}`
helper.CFBundleIdentifier = userProvidedBundleIdentifier ? filterCFBundleIdentifier(userProvidedBundleIdentifier) : filterCFBundleIdentifier(`${helperBundleIdentifier}.${postfix}`)
helper.CFBundleIdentifier = userProvidedBundleIdentifier
? filterCFBundleIdentifier(userProvidedBundleIdentifier)
: filterCFBundleIdentifier(`${helperBundleIdentifier}.${postfix}`)
helper.CFBundleVersion = appPlist.CFBundleVersion
}

Expand Down
Loading

0 comments on commit a879ba7

Please sign in to comment.