Skip to content

Commit 5d01ea6

Browse files
authored
chore: integrate prettier (#5680)
1 parent 0b03f10 commit 5d01ea6

File tree

159 files changed

+2540
-2485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+2540
-2485
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
"eslint:recommended",
99
"plugin:@typescript-eslint/eslint-recommended",
1010
"plugin:@typescript-eslint/recommended",
11+
"plugin:prettier/recommended",
1112
],
1213
rules: {
1314
semi: "off",

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.d.ts
2+
out

.prettierrc.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
singleQuote: false
2+
semi: false
3+
arrowParens: avoid
4+
trailingComma: all
5+
printWidth: 250
6+
quoteProps: as-needed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lint": "eslint packages --ext .ts",
2525
"lint-deps": "node ./test/out/helpers/checkDeps.js",
2626
"pretest": "yarn compile && yarn lint && yarn lint-deps",
27+
"prettier": "prettier \"packages/**/*.{ts, js}\" --write",
2728
"///": "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",
2829
"test": "node ./test/out/helpers/runTests.js skipArtifactPublisher ALL_TESTS=isCi",
2930
"test-all": "yarn pretest && node ./test/out/helpers/runTests.js",
@@ -54,12 +55,15 @@
5455
"bluebird-lst": "^1.0.9",
5556
"electron-builder-tslint-config": "^1.1.0",
5657
"eslint": "^7.20.0",
58+
"eslint-config-prettier": "^8.1.0",
59+
"eslint-plugin-prettier": "^3.3.1",
5760
"fs-extra": "^9.1.0",
5861
"globby": "^11.0.2",
5962
"husky": "4.3.8",
6063
"jest-cli": "^26.6.3",
6164
"jsdoc-to-markdown": "^6.0.1",
6265
"lint-staged": "^10.5.4",
66+
"prettier": "^2.2.1",
6367
"ts-babel": "6.1.7",
6468
"ts-jsdoc": "^3.1.1",
6569
"typescript": "~4.1.5",

packages/app-builder-lib/src/Framework.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ export interface PrepareApplicationStageDirectoryOptions {
5151

5252
export function isElectronBased(framework: Framework): boolean {
5353
return framework.name === "electron"
54-
}
54+
}

packages/app-builder-lib/src/ProtonFramework.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,39 @@ export class ProtonFramework extends LibUiFramework {
1919
getDefaultIcon(platform: Platform): string {
2020
if (platform === Platform.WINDOWS) {
2121
return getTemplatePath("icons/proton-native/proton-native.ico")
22-
}
23-
else if (platform === Platform.LINUX) {
22+
} else if (platform === Platform.LINUX) {
2423
return getTemplatePath("icons/proton-native/linux")
25-
}
26-
else {
24+
} else {
2725
return getTemplatePath("icons/proton-native/proton-native.icns")
2826
}
2927
}
3028

3129
createTransformer(): FileTransformer | null {
3230
let babel: any
33-
const babelOptions: any = {ast: false, sourceMaps: "inline"}
31+
const babelOptions: any = { ast: false, sourceMaps: "inline" }
3432
if (process.env.TEST_SET_BABEL_PRESET === "true") {
3533
babel = require("@babel/core")
3634
// eslint-disable-next-line @typescript-eslint/no-use-before-define
3735
babel = testOnlyBabel(babel, babelOptions, this.version)
38-
}
39-
else {
36+
} else {
4037
try {
4138
babel = require("babel-core")
42-
}
43-
catch (e) {
39+
} catch (e) {
4440
// babel isn't installed
4541
log.debug(null, "don't transpile source code using Babel")
4642
return null
4743
}
4844
}
4945

50-
log.info({options: safeStringifyJson(babelOptions, new Set<string>(["presets"]))}, "transpile source code using Babel")
46+
log.info(
47+
{
48+
options: safeStringifyJson(
49+
babelOptions,
50+
new Set<string>(["presets"]),
51+
),
52+
},
53+
"transpile source code using Babel",
54+
)
5155
return (file): Promise<any> | null => {
5256
if (!(file.endsWith(".js") || file.endsWith(".jsx")) || file.includes(NODE_MODULES_PATTERN)) {
5357
return null
@@ -57,8 +61,7 @@ export class ProtonFramework extends LibUiFramework {
5761
return babel.transformFile(file, babelOptions, (error: Error, result: any) => {
5862
if (error == null) {
5963
resolve(result.code)
60-
}
61-
else {
64+
} else {
6265
reject(error)
6366
}
6467
})
@@ -69,24 +72,21 @@ export class ProtonFramework extends LibUiFramework {
6972

7073
function testOnlyBabel(babel: any, babelOptions: any, nodeVersion: string): any {
7174
// out test dir can be located outside of electron-builder node_modules and babel cannot resolve string names of preset
72-
babelOptions.presets = [
73-
[require("@babel/preset-env").default, {targets: {node: nodeVersion}}],
74-
require("@babel/preset-react"),
75-
]
75+
babelOptions.presets = [[require("@babel/preset-env").default, { targets: { node: nodeVersion } }], require("@babel/preset-react")]
7676
babelOptions.plugins = [
7777
// stage 0
7878
require("@babel/plugin-proposal-function-bind").default,
7979

8080
// stage 1
8181
require("@babel/plugin-proposal-export-default-from").default,
8282
require("@babel/plugin-proposal-logical-assignment-operators").default,
83-
[require("@babel/plugin-proposal-optional-chaining").default, {loose: false}],
84-
[require("@babel/plugin-proposal-pipeline-operator").default, {proposal: "minimal"}],
85-
[require("@babel/plugin-proposal-nullish-coalescing-operator").default, {loose: false}],
83+
[require("@babel/plugin-proposal-optional-chaining").default, { loose: false }],
84+
[require("@babel/plugin-proposal-pipeline-operator").default, { proposal: "minimal" }],
85+
[require("@babel/plugin-proposal-nullish-coalescing-operator").default, { loose: false }],
8686
require("@babel/plugin-proposal-do-expressions").default,
8787

8888
// stage 2
89-
[require("@babel/plugin-proposal-decorators").default, {legacy: true}],
89+
[require("@babel/plugin-proposal-decorators").default, { legacy: true }],
9090
require("@babel/plugin-proposal-function-sent").default,
9191
require("@babel/plugin-proposal-export-namespace-from").default,
9292
require("@babel/plugin-proposal-numeric-separator").default,
@@ -95,9 +95,9 @@ function testOnlyBabel(babel: any, babelOptions: any, nodeVersion: string): any
9595
// stage 3
9696
require("@babel/plugin-syntax-dynamic-import").default,
9797
require("@babel/plugin-syntax-import-meta").default,
98-
[require("@babel/plugin-proposal-class-properties").default, {loose: false}],
98+
[require("@babel/plugin-proposal-class-properties").default, { loose: false }],
9999
require("@babel/plugin-proposal-json-strings").default,
100100
]
101101
babelOptions.babelrc = false
102102
return babel
103-
}
103+
}

packages/app-builder-lib/src/appInfo.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export class AppInfo {
5757

5858
this.productName = info.config.productName || info.metadata.productName || info.metadata.name!!
5959
this.sanitizedProductName = sanitizeFileName(this.productName)
60-
this.productFilename = platformSpecificOptions?.executableName != null
61-
? sanitizeFileName(platformSpecificOptions.executableName)
62-
: this.sanitizedProductName
60+
this.productFilename = platformSpecificOptions?.executableName != null ? sanitizeFileName(platformSpecificOptions.executableName) : this.sanitizedProductName
6361
}
6462

6563
get channel(): string | null {

packages/app-builder-lib/src/asar/asar.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ export class AsarFilesystem {
7575
node.size = size
7676
if (unpacked) {
7777
node.unpacked = true
78-
}
79-
else {
78+
} else {
8079
// electron expects string
8180
node.offset = this.offset.toString()
82-
if (process.platform !== "win32" && (stat.mode & 0o100)) {
81+
if (process.platform !== "win32" && stat.mode & 0o100) {
8382
node.executable = true
8483
}
8584
this.offset += node.size
@@ -131,8 +130,7 @@ export async function readAsar(archive: string): Promise<AsarFilesystem> {
131130
if ((await read(fd, headerBuf, 0, size, null as any)).bytesRead !== size) {
132131
throw new Error("Unable to read header")
133132
}
134-
}
135-
finally {
133+
} finally {
136134
await close(fd)
137135
}
138136

@@ -161,8 +159,7 @@ async function readFileFromAsar(filesystem: AsarFilesystem, filename: string, in
161159
try {
162160
const offset = 8 + filesystem.headerSize + parseInt(info.offset!!, 10)
163161
await read(fd, buffer, 0, size, offset)
164-
}
165-
finally {
162+
} finally {
166163
await close(fd)
167164
}
168165
return buffer

packages/app-builder-lib/src/asar/asarFileChecker.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ export async function checkFileInArchive(asarFile: string, relativeFile: string,
1010
let fs
1111
try {
1212
fs = await readAsar(asarFile)
13-
}
14-
catch (e) {
13+
} catch (e) {
1514
throw error(`is corrupted: ${e}`)
1615
}
1716

1817
let stat: Node | null
1918
try {
2019
stat = fs.getFile(relativeFile)
21-
}
22-
catch (e) {
20+
} catch (e) {
2321
const fileStat = await statOrNull(asarFile)
2422
if (fileStat == null) {
2523
throw error(`does not exist. Seems like a wrong configuration.`)

packages/app-builder-lib/src/asar/asarUtil.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AsarPackager {
5252

5353
const correctDirNodeUnpackedFlag = async (filePathInArchive: string, dirNode: Node) => {
5454
for (const dir of unpackedDirs) {
55-
if (filePathInArchive.length > (dir.length + 2) && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {
55+
if (filePathInArchive.length > dir.length + 2 && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {
5656
dirNode.unpacked = true
5757
unpackedDirs.add(filePathInArchive)
5858
// not all dirs marked as unpacked after first iteration - because node module dir can be marked as unpacked after processing node module dir content
@@ -82,7 +82,7 @@ export class AsarPackager {
8282
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(file, fileSet))
8383

8484
if (stat.isSymbolicLink()) {
85-
const s = (stat as any)
85+
const s = stat as any
8686
this.fs.getOrCreateNode(pathInArchive).link = s.relativeLink
8787
s.pathInArchive = pathInArchive
8888
unpackedFileIndexSet.add(i)
@@ -105,8 +105,7 @@ export class AsarPackager {
105105
if (fileParent !== "" && !currentDirNode.unpacked) {
106106
if (unpackedDirs.has(fileParent)) {
107107
currentDirNode.unpacked = true
108-
}
109-
else {
108+
} else {
110109
await correctDirNodeUnpackedFlag(fileParent, currentDirNode)
111110
}
112111
}
@@ -166,8 +165,7 @@ export class AsarPackager {
166165
if (++fileSetIndex >= fileSets.length) {
167166
writeStream.end()
168167
return
169-
}
170-
else {
168+
} else {
171169
files = fileSets[fileSetIndex].files
172170
metadata = fileSets[fileSetIndex].metadata
173171
transformedFiles = fileSets[fileSetIndex].transformedFiles
@@ -178,8 +176,7 @@ export class AsarPackager {
178176

179177
if (!unpackedFileIndexSet.has(index)) {
180178
break
181-
}
182-
else {
179+
} else {
183180
const stat = metadata.get(files[index])
184181
if (stat != null && stat.isSymbolicLink()) {
185182
symlink((stat as any).linkRelativeToFile, path.join(this.unpackedDest, (stat as any).pathInArchive), () => w(index + 1))
@@ -198,20 +195,19 @@ export class AsarPackager {
198195

199196
// https://github.com/yarnpkg/yarn/pull/3539
200197
const stat = metadata.get(file)
201-
if (stat != null && stat.size < (2 * 1024 * 1024)) {
198+
if (stat != null && stat.size < 2 * 1024 * 1024) {
202199
readFile(file)
203200
.then(it => {
204201
writeStream.write(it, () => w(index + 1))
205202
})
206203
.catch(e => reject(`Cannot read file ${file}: ${e.stack || e}`))
207-
}
208-
else {
204+
} else {
209205
const readStream = createReadStream(file)
210206
readStream.on("error", reject)
211207
readStream.once("end", () => w(index + 1))
212208
readStream.on("open", () => {
213209
readStream.pipe(writeStream, {
214-
end: false
210+
end: false,
215211
})
216212
})
217213
}
@@ -256,15 +252,14 @@ async function order(filenames: Array<string>, orderingFile: string, src: string
256252
missing += 1
257253
}
258254
}
259-
log.info({coverage: ((total - missing) / total * 100)}, "ordering files in ASAR archive")
255+
log.info({ coverage: ((total - missing) / total) * 100 }, "ordering files in ASAR archive")
260256
return sortedFiles
261257
}
262258

263259
function copyFileOrData(fileCopier: FileCopier, data: string | Buffer | undefined | null, source: string, destination: string, stats: Stats) {
264260
if (data == null) {
265261
return fileCopier.copy(source, destination, stats)
266-
}
267-
else {
262+
} else {
268263
return writeFile(destination, data)
269264
}
270-
}
265+
}

packages/app-builder-lib/src/asar/integrity.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ export async function computeData(resourcesPath: string, options?: AsarIntegrity
2626
for (let i = 0; i < names.length; i++) {
2727
result[names[i]] = checksums[i]
2828
}
29-
return {checksums: result, ...options}
29+
return { checksums: result, ...options }
3030
}
3131

3232
function hashFile(file: string, algorithm: string = "sha512", encoding: "hex" | "base64" | "latin1" = "base64") {
3333
return new Promise<string>((resolve, reject) => {
3434
const hash = createHash(algorithm)
35-
hash
36-
.on("error", reject)
37-
.setEncoding(encoding)
35+
hash.on("error", reject).setEncoding(encoding)
3836

3937
createReadStream(file)
4038
.on("error", reject)
4139
.on("end", () => {
4240
hash.end()
4341
resolve(hash.read() as string)
4442
})
45-
.pipe(hash, {end: false})
43+
.pipe(hash, { end: false })
4644
})
47-
}
45+
}

0 commit comments

Comments
 (0)