@@ -19,6 +19,8 @@ import { WinPackager } from "../../winPackager"
19
19
import { archive , ArchiveOptions } from "../archive"
20
20
import { appendBlockmap , configureDifferentialAwareArchiveOptions , createBlockmap , createNsisWebDifferentialUpdateInfo } from "../differentialUpdateInfoBuilder"
21
21
import { getWindowsInstallationAppPackageName , getWindowsInstallationDirName } from "../targetUtil"
22
+ import { Commands } from "./Commands"
23
+ import { Defines } from "./Defines"
22
24
import { addCustomMessageFileInclude , createAddLangsMacro , LangConfigurator } from "./nsisLang"
23
25
import { computeLicensePage } from "./nsisLicense"
24
26
import { NsisOptions , PortableOptions } from "./nsisOptions"
@@ -71,7 +73,7 @@ export class NsisTarget extends Target {
71
73
return Promise . resolve ( )
72
74
}
73
75
74
- get isBuildDifferentialAware ( ) {
76
+ get isBuildDifferentialAware ( ) : boolean {
75
77
return ! this . isPortable && this . options . differentialPackage !== false
76
78
}
77
79
@@ -115,7 +117,7 @@ export class NsisTarget extends Target {
115
117
return "${productName} " + ( this . isPortable ? "" : "Setup " ) + "${version}.${ext}"
116
118
}
117
119
118
- private get isPortable ( ) {
120
+ private get isPortable ( ) : boolean {
119
121
return this . name === "portable"
120
122
}
121
123
@@ -176,7 +178,7 @@ export class NsisTarget extends Target {
176
178
177
179
const guid = options . guid || UUID . v5 ( appInfo . id , ELECTRON_BUILDER_NS_UUID )
178
180
const uninstallAppKey = guid . replace ( / \\ / g, " - " )
179
- const defines : any = {
181
+ const defines : Defines = {
180
182
APP_ID : appInfo . id ,
181
183
APP_GUID : guid ,
182
184
// Windows bug - entry in Software\Microsoft\Windows\CurrentVersion\Uninstall cannot have \ symbols (dir)
@@ -199,7 +201,7 @@ export class NsisTarget extends Target {
199
201
defines . UNINSTALL_REGISTRY_KEY_2 = `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${ guid } `
200
202
}
201
203
202
- const commands : any = {
204
+ const commands : Commands = {
203
205
OutFile : `"${ installerPath } "` ,
204
206
VIProductVersion : appInfo . getVersionInWeirdWindowsForm ( ) ,
205
207
VIAddVersionKey : this . computeVersionKey ( ) ,
@@ -231,9 +233,13 @@ export class NsisTarget extends Target {
231
233
const file = fileInfo . path
232
234
const defineKey = arch === Arch . x64 ? "APP_64" : arch === Arch . arm64 ? "APP_ARM64" : "APP_32"
233
235
defines [ defineKey ] = file
234
- defines [ `${ defineKey } _NAME` ] = path . basename ( file )
236
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
237
+ const defineNameKey = `${ defineKey } _NAME` as "APP_64_NAME" | "APP_ARM64_NAME" | "APP_32_NAME"
238
+ defines [ defineNameKey ] = path . basename ( file )
235
239
// nsis expect a hexadecimal string
236
- defines [ `${ defineKey } _HASH` ] = Buffer . from ( fileInfo . sha512 , "base64" ) . toString ( "hex" ) . toUpperCase ( )
240
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
241
+ const defineHashKey = `${ defineKey } _HASH` as "APP_64_HASH" | "APP_ARM64_HASH" | "APP_32_HASH"
242
+ defines [ defineHashKey ] = Buffer . from ( fileInfo . sha512 , "base64" ) . toString ( "hex" ) . toUpperCase ( )
237
243
238
244
if ( this . isWebInstaller ) {
239
245
await packager . dispatchArtifactCreated ( file , this , arch )
@@ -293,8 +299,8 @@ export class NsisTarget extends Target {
293
299
}
294
300
295
301
// prepare short-version variants of defines and commands, to make an uninstaller that doesn't differ much from the previous one
296
- const definesUninstaller : any = { ...defines }
297
- const commandsUninstaller : any = { ...commands }
302
+ const definesUninstaller = { ...defines }
303
+ const commandsUninstaller = { ...commands }
298
304
if ( appInfo . shortVersion != null ) {
299
305
definesUninstaller . VERSION = appInfo . shortVersion
300
306
commandsUninstaller . VIProductVersion = appInfo . shortVersionWindows
@@ -335,21 +341,21 @@ export class NsisTarget extends Target {
335
341
} )
336
342
}
337
343
338
- protected generateGitHubInstallerName ( ) {
344
+ protected generateGitHubInstallerName ( ) : string {
339
345
const appInfo = this . packager . appInfo
340
346
const classifier = appInfo . name . toLowerCase ( ) === appInfo . name ? "setup-" : "Setup-"
341
347
return `${ appInfo . name } -${ this . isPortable ? "" : classifier } ${ appInfo . version } .exe`
342
348
}
343
349
344
- private get isUnicodeEnabled ( ) {
350
+ private get isUnicodeEnabled ( ) : boolean {
345
351
return this . options . unicode !== false
346
352
}
347
353
348
354
get isWebInstaller ( ) : boolean {
349
355
return false
350
356
}
351
357
352
- private async computeScriptAndSignUninstaller ( defines : any , commands : any , installerPath : string , sharedHeader : string , archs : Map < Arch , string > ) {
358
+ private async computeScriptAndSignUninstaller ( defines : Defines , commands : Commands , installerPath : string , sharedHeader : string , archs : Map < Arch , string > ) : Promise < string > {
353
359
const packager = this . packager
354
360
const customScriptPath = await packager . getResource ( this . options . script , "installer.nsi" )
355
361
const script = await readFile ( customScriptPath || path . join ( nsisTemplatesDir , "installer.nsi" ) , "utf8" )
@@ -416,7 +422,7 @@ export class NsisTarget extends Target {
416
422
return versionKey
417
423
}
418
424
419
- protected configureDefines ( oneClick : boolean , defines : any ) : Promise < any > {
425
+ protected configureDefines ( oneClick : boolean , defines : Defines ) : Promise < any > {
420
426
const packager = this . packager
421
427
const options = this . options
422
428
@@ -514,7 +520,7 @@ export class NsisTarget extends Target {
514
520
return asyncTaskManager . awaitTasks ( )
515
521
}
516
522
517
- private configureDefinesForAllTypeOfInstaller ( defines : any ) {
523
+ private configureDefinesForAllTypeOfInstaller ( defines : Defines ) : void {
518
524
const appInfo = this . packager . appInfo
519
525
const companyName = appInfo . companyName
520
526
if ( companyName != null ) {
@@ -542,11 +548,11 @@ export class NsisTarget extends Target {
542
548
}
543
549
}
544
550
545
- private async executeMakensis ( defines : any , commands : any , script : string ) {
551
+ private async executeMakensis ( defines : Defines , commands : Commands , script : string ) : Promise < void > {
546
552
const args : Array < string > = this . options . warningsAsErrors === false ? [ ] : [ "-WX" ]
547
553
args . push ( "-INPUTCHARSET" , "UTF8" )
548
554
for ( const name of Object . keys ( defines ) ) {
549
- const value = defines [ name ]
555
+ const value = defines [ name as keyof Defines ]
550
556
if ( value == null ) {
551
557
args . push ( `-D${ name } ` )
552
558
} else {
@@ -555,7 +561,7 @@ export class NsisTarget extends Target {
555
561
}
556
562
557
563
for ( const name of Object . keys ( commands ) ) {
558
- const value = commands [ name ]
564
+ const value = commands [ name as keyof Commands ]
559
565
if ( Array . isArray ( value ) ) {
560
566
for ( const c of value ) {
561
567
args . push ( `-X${ name } ${ c } ` )
@@ -591,7 +597,7 @@ export class NsisTarget extends Target {
591
597
} )
592
598
}
593
599
594
- private async computeCommonInstallerScriptHeader ( ) {
600
+ private async computeCommonInstallerScriptHeader ( ) : Promise < string > {
595
601
const packager = this . packager
596
602
const options = this . options
597
603
const scriptGenerator = new NsisScriptGenerator ( )
@@ -640,7 +646,7 @@ export class NsisTarget extends Target {
640
646
return scriptGenerator . build ( )
641
647
}
642
648
643
- private async computeFinalScript ( originalScript : string , isInstaller : boolean , archs : Map < Arch , string > ) {
649
+ private async computeFinalScript ( originalScript : string , isInstaller : boolean , archs : Map < Arch , string > ) : Promise < string > {
644
650
const packager = this . packager
645
651
const options = this . options
646
652
const langConfigurator = new LangConfigurator ( options )
@@ -703,7 +709,7 @@ export class NsisTarget extends Target {
703
709
}
704
710
}
705
711
706
- async function generateForPreCompressed ( preCompressedFileExtensions : Array < string > , dir : string , arch : Arch , scriptGenerator : NsisScriptGenerator ) {
712
+ async function generateForPreCompressed ( preCompressedFileExtensions : Array < string > , dir : string , arch : Arch , scriptGenerator : NsisScriptGenerator ) : Promise < void > {
707
713
const resourcesDir = path . join ( dir , "resources" )
708
714
const dirInfo = await statOrNull ( resourcesDir )
709
715
if ( dirInfo == null || ! dirInfo . isDirectory ( ) ) {
@@ -728,7 +734,7 @@ async function generateForPreCompressed(preCompressedFileExtensions: Array<strin
728
734
}
729
735
}
730
736
731
- async function ensureNotBusy ( outFile : string ) {
737
+ async function ensureNotBusy ( outFile : string ) : Promise < void > {
732
738
function isBusy ( wasBusyBefore : boolean ) : Promise < boolean > {
733
739
return new Promise ( ( resolve , reject ) => {
734
740
fs . open ( outFile , "r+" , ( error , fd ) => {
0 commit comments