From 4a5f21ed508883dfea911d0027b401b23852f6b5 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 14 Apr 2021 22:03:46 -0700 Subject: [PATCH 1/4] Allowing boolean flag to unpackDirName to utilize $PLUGINSDIR (unique to each portable app launch) when set explicitly to false. Implements #5764, #5382, #4105 --- packages/app-builder-lib/scheme.json | 7 +++++-- .../src/targets/nsis/NsisTarget.ts | 16 +++++++++++----- .../src/targets/nsis/nsisOptions.ts | 7 +++++-- .../app-builder-lib/templates/nsis/portable.nsi | 8 ++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 9f05359b6f..43e0e02e0b 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -4380,8 +4380,11 @@ "type": "boolean" }, "unpackDirName": { - "description": "The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\n\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).", - "type": "string" + "description": "The unpack directory for the portable app resources.\nIf set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\nIf set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application.\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).", + "type": [ + "string", + "boolean" + ] }, "useZip": { "default": false, diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 8ca3365b56..a1816df0ae 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -244,12 +244,18 @@ export class NsisTarget extends Target { this.configureDefinesForAllTypeOfInstaller(defines) if (isPortable) { - const portableOptions = options as PortableOptions - defines.REQUEST_EXECUTION_LEVEL = portableOptions.requestExecutionLevel || "user" - defines.UNPACK_DIR_NAME = portableOptions.unpackDirName || (await executeAppBuilder(["ksuid"])) + const { unpackDirName, requestExecutionLevel, splashImage} = options as PortableOptions + defines.REQUEST_EXECUTION_LEVEL = requestExecutionLevel || "user" + + // https://github.com/electron-userland/electron-builder/issues/5764 + if (typeof unpackDirName === 'string') { + defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) + } else if (unpackDirName !== false) { + defines.UNPACK_DIR_NAME = executeAppBuilder(["ksuid"]) + } - if (portableOptions.splashImage != null) { - defines.SPLASH_IMAGE = path.resolve(packager.projectDir, portableOptions.splashImage) + if (splashImage != null) { + defines.SPLASH_IMAGE = path.resolve(packager.projectDir, splashImage) } } else { await this.configureDefines(oneClick, defines) diff --git a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts index 6a8de5853b..9f45ab266d 100644 --- a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts +++ b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts @@ -169,11 +169,14 @@ export interface PortableOptions extends TargetSpecificOptions, CommonNsisOption readonly requestExecutionLevel?: "user" | "highest" | "admin" /** - * The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory. + * The unpack directory for the portable app resources. * + * If set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory + * If set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application. + * * Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable). */ - readonly unpackDirName?: string + readonly unpackDirName?: string | boolean /** * The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image. diff --git a/packages/app-builder-lib/templates/nsis/portable.nsi b/packages/app-builder-lib/templates/nsis/portable.nsi index e9085494e8..e5436bb0f8 100644 --- a/packages/app-builder-lib/templates/nsis/portable.nsi +++ b/packages/app-builder-lib/templates/nsis/portable.nsi @@ -30,7 +30,11 @@ Section HideWindow !endif - StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}" + StrCpy $INSTDIR "$PLUGINSDIR\app" + !ifdef UNPACK_DIR_NAME + StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}" + !endif + RMDir /r $INSTDIR SetOutPath $INSTDIR @@ -82,6 +86,6 @@ Section ExecWait "$INSTDIR\${APP_EXECUTABLE_FILENAME} $R0" $0 SetErrorLevel $0 - SetOutPath $PLUGINSDIR + SetOutPath $EXEDIR RMDir /r $INSTDIR SectionEnd From f2c3f5575de15704b3895be09b89e2db98f2428a Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 14 Apr 2021 22:05:55 -0700 Subject: [PATCH 2/4] fix await --- packages/app-builder-lib/src/targets/nsis/NsisTarget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index a1816df0ae..bbc3d38006 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -251,7 +251,7 @@ export class NsisTarget extends Target { if (typeof unpackDirName === 'string') { defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) } else if (unpackDirName !== false) { - defines.UNPACK_DIR_NAME = executeAppBuilder(["ksuid"]) + defines.UNPACK_DIR_NAME = await executeAppBuilder(["ksuid"]) } if (splashImage != null) { From aa879a07f85c510273f496b1ed9be69d8f985211 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 11 Jul 2021 10:22:53 -0700 Subject: [PATCH 3/4] running prettier --- packages/app-builder-lib/src/macPackager.ts | 16 +++++++++------- .../src/targets/nsis/NsisTarget.ts | 6 +++--- .../src/targets/nsis/nsisOptions.ts | 2 +- test/src/BuildTest.ts | 7 ++----- test/src/ignoreTest.ts | 13 ++++++------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/app-builder-lib/src/macPackager.ts b/packages/app-builder-lib/src/macPackager.ts index 6180ec0f88..5eec093391 100644 --- a/packages/app-builder-lib/src/macPackager.ts +++ b/packages/app-builder-lib/src/macPackager.ts @@ -241,15 +241,17 @@ export default class MacPackager extends PlatformPackager { let binaries = options.binaries || undefined if (binaries) { // Accept absolute paths for external binaries, else resolve relative paths from the artifact's app Contents path. - const userDefinedBinaries = await Promise.all(binaries.map(async (destination) => { - if (await statOrNull(destination)) { - return destination - } - return path.resolve(appPath, destination) - })) + const userDefinedBinaries = await Promise.all( + binaries.map(async destination => { + if (await statOrNull(destination)) { + return destination + } + return path.resolve(appPath, destination) + }) + ) // Insert at front to prioritize signing. We still sort by depth next binaries = userDefinedBinaries.concat(binaries) - log.info('Signing addtional user-defined binaries: ' + JSON.stringify(userDefinedBinaries, null, 1)) + log.info("Signing addtional user-defined binaries: " + JSON.stringify(userDefinedBinaries, null, 1)) } const signOptions: any = { diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 8ab9645611..3af308d98c 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -247,11 +247,11 @@ export class NsisTarget extends Target { this.configureDefinesForAllTypeOfInstaller(defines) if (isPortable) { - const { unpackDirName, requestExecutionLevel, splashImage} = options as PortableOptions + const { unpackDirName, requestExecutionLevel, splashImage } = options as PortableOptions defines.REQUEST_EXECUTION_LEVEL = requestExecutionLevel || "user" - + // https://github.com/electron-userland/electron-builder/issues/5764 - if (typeof unpackDirName === 'string') { + if (typeof unpackDirName === "string") { defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) } else if (unpackDirName !== false) { defines.UNPACK_DIR_NAME = await executeAppBuilder(["ksuid"]) diff --git a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts index 9f45ab266d..4aada863fe 100644 --- a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts +++ b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts @@ -173,7 +173,7 @@ export interface PortableOptions extends TargetSpecificOptions, CommonNsisOption * * If set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory * If set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application. - * + * * Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable). */ readonly unpackDirName?: string | boolean diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index 654077738e..ad5bdb1e75 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -367,11 +367,8 @@ test.ifDevOrLinuxCi( files: [ // test ignore pattern for node_modules defined as file set filter { - filter: [ - "!node_modules/napi-build-utils/napi-build-utils-1.0.0.tgz", - "!node_modules/node-abi/*" - ] - } + filter: ["!node_modules/napi-build-utils/napi-build-utils-1.0.0.tgz", "!node_modules/node-abi/*"], + }, ], }, }, diff --git a/test/src/ignoreTest.ts b/test/src/ignoreTest.ts index 5452b3eb82..00c686c23b 100644 --- a/test/src/ignoreTest.ts +++ b/test/src/ignoreTest.ts @@ -114,7 +114,7 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - includeSubNodeModules: false // defaults to false too + includeSubNodeModules: false, // defaults to false too }, }, { @@ -148,7 +148,7 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - includeSubNodeModules: true + includeSubNodeModules: true, }, }, { @@ -182,10 +182,7 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - files: [ - "**/*", - "*/submodule-1-test/node_modules/**", - ], + files: ["**/*", "*/submodule-1-test/node_modules/**"], }, }, { @@ -205,7 +202,9 @@ test.ifDevOrLinuxCi( packed: context => { return Promise.all([ assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules")).isDirectory(), - assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules", "package.json")).isFile(), + assertThat( + path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules", "package.json") + ).isFile(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-2-test", "node_modules")).doesNotExist(), ]) }, From bf60e46beca004c41e0966bf51ccec3ece67d696 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 24 Jul 2021 09:04:03 -0700 Subject: [PATCH 4/4] Consolidating fixed path vs ksuid logic for string entries and 'false' (or covers empty strings) (#5764) --- packages/app-builder-lib/src/targets/nsis/NsisTarget.ts | 4 +--- test/src/windows/portableTest.ts | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 3af308d98c..8fcf0c1ebf 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -251,10 +251,8 @@ export class NsisTarget extends Target { defines.REQUEST_EXECUTION_LEVEL = requestExecutionLevel || "user" // https://github.com/electron-userland/electron-builder/issues/5764 - if (typeof unpackDirName === "string") { + if (typeof unpackDirName === "string" || !unpackDirName) { defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) - } else if (unpackDirName !== false) { - defines.UNPACK_DIR_NAME = await executeAppBuilder(["ksuid"]) } if (splashImage != null) { diff --git a/test/src/windows/portableTest.ts b/test/src/windows/portableTest.ts index ca3ef42397..e3d201df51 100644 --- a/test/src/windows/portableTest.ts +++ b/test/src/windows/portableTest.ts @@ -39,6 +39,7 @@ test.ifAll.ifNotCi( publish: null, portable: { useZip: true, + unpackDirName: false, }, compression: "store", }, @@ -57,6 +58,7 @@ test.ifNotCiMac( installerIcon: "foo test space.ico", }, portable: { + unpackDirName: true, requestExecutionLevel: "admin", //tslint:disable-next-line:no-invalid-template-strings artifactName: "${productName}Portable.${version}.${ext}",