Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
"dependencies": {
"@electron/asar": "^3.2.1",
"debug": "^4.1.1",
"fs-extra": "^7.0.1",
"lodash": "^4.17.21",
"semver": "^7.6.3"
},
"devDependencies": {
"@types/fs-extra": "^5.0.5",
"@types/lodash": "^4.17.0",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path';
import fs from 'fs-extra';
import fs from 'fs/promises';

import { createTempDir } from '../../src/temp-utils';

export const FIXTURE_APP_DIR = path.join(__dirname, '../fixtures/app');

export async function createTempAppDirectory(): Promise<string> {
const appDirectory = await createTempDir('electron-winstaller-ad-');
await fs.copy(FIXTURE_APP_DIR, appDirectory);
await fs.cp(FIXTURE_APP_DIR, appDirectory);
return appDirectory;
}
2 changes: 1 addition & 1 deletion spec/helpers/windowsSignHook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');

module.exports = function(args) {
Expand Down
20 changes: 11 additions & 9 deletions spec/installer-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import path from 'path';
import { createTempDir } from '../src/temp-utils';
import fs from 'fs-extra';
import fs from 'fs/promises';
import { createWindowsInstaller } from '../src';
import spawn from '../src/spawn-promise';
import { createTempAppDirectory } from './helpers/helpers';
Expand All @@ -16,6 +16,8 @@ function spawn7z(args: string[]): Promise<string> {
: spawn(sevenZipPath, args);
}

const exists = (p: string) => fs.access(p).then(() => true).catch(() => false);


test.serial('creates a nuget package and installer', async (t): Promise<void> => {
const outputDirectory = await createTempDir('ei-');
Expand All @@ -29,15 +31,15 @@ test.serial('creates a nuget package and installer', async (t): Promise<void> =>

const nupkgPath = path.join(outputDirectory, 'myapp-1.0.0-full.nupkg');

t.true(await fs.pathExists(nupkgPath));
t.true(await fs.pathExists(path.join(outputDirectory, 'MyAppSetup.exe')));
t.true(await exists(nupkgPath));
t.true(await exists(path.join(outputDirectory, 'MyAppSetup.exe')));

if (process.platform === 'win32') {
t.true(await fs.pathExists(path.join(outputDirectory, 'MyAppSetup.msi')));
t.true(await exists(path.join(outputDirectory, 'MyAppSetup.msi')));
}

log('Verifying Update.exe');
t.true(await fs.pathExists(path.join(appDirectory, 'Squirrel.exe')));
t.true(await exists(path.join(appDirectory, 'Squirrel.exe')));

log('Verifying contents of .nupkg');

Expand All @@ -53,10 +55,10 @@ test.serial('creates an installer when swiftshader files are missing', async (t)
const options = { appDirectory, outputDirectory };

// Remove swiftshader folder and swiftshader json file, simulating Electron < 10.0
await fs.remove(path.join(appDirectory, 'swiftshader', 'libEGL.dll'));
await fs.remove(path.join(appDirectory, 'swiftshader', 'libGLESv2.dll'));
await fs.rmdir(path.join(appDirectory, 'swiftshader'));
await fs.remove(path.join(appDirectory, 'vk_swiftshader_icd.json'));
await fs.rm(path.join(appDirectory, 'swiftshader', 'libEGL.dll'), { force: true, recursive: true });
await fs.rm(path.join(appDirectory, 'swiftshader', 'libGLESv2.dll'), { force: true, recursive: true });
await fs.rm(path.join(appDirectory, 'swiftshader'), { force: true, recursive: true });
await fs.rm(path.join(appDirectory, 'vk_swiftshader_icd.json'), { force: true, recursive: true });

await createWindowsInstaller(options);

Expand Down
14 changes: 8 additions & 6 deletions spec/sign-spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import test from 'ava';
import path from 'path';
import { createTempDir } from '../src/temp-utils';
import fs from 'fs-extra';
import fs from 'fs/promises';
import { createWindowsInstaller } from '../src';
import { createTempAppDirectory } from './helpers/helpers';
import { SignToolOptions } from '@electron/windows-sign';
import semver from 'semver';

const log = require('debug')('electron-windows-installer:spec');

const exists = (p: string) => fs.access(p).then(() => true).catch(() => false);

if (process.platform === 'win32' && semver.gte(process.version, '20.0.0')) {
test.serial('creates a signtool.exe and uses it to sign', async (t): Promise<void> => {

Expand All @@ -20,7 +22,7 @@ if (process.platform === 'win32' && semver.gte(process.version, '20.0.0')) {
const options = { appDirectory, outputDirectory, windowsSign };

// Reset
await fs.remove(hookLogPath);
await fs.rm(hookLogPath, { force: true, recursive: true });

// Test
await createWindowsInstaller(options);
Expand All @@ -30,15 +32,15 @@ if (process.platform === 'win32' && semver.gte(process.version, '20.0.0')) {

const nupkgPath = path.join(outputDirectory, 'myapp-1.0.0-full.nupkg');

t.true(await fs.pathExists(nupkgPath));
t.true(await fs.pathExists(path.join(outputDirectory, 'MyAppSetup.exe')));
t.true(await exists(nupkgPath));
t.true(await exists(path.join(outputDirectory, 'MyAppSetup.exe')));

if (process.platform === 'win32') {
t.true(await fs.pathExists(path.join(outputDirectory, 'MyAppSetup.msi')));
t.true(await exists(path.join(outputDirectory, 'MyAppSetup.msi')));
}

log('Verifying Update.exe');
t.true(await fs.pathExists(path.join(appDirectory, 'Squirrel.exe')));
t.true(await exists(path.join(appDirectory, 'Squirrel.exe')));

log('Verifying that our hook got to "sign" all files');
const hookLog = await fs.readFile(hookLogPath, { encoding: 'utf8' });
Expand Down
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as asar from '@electron/asar';
import { createTempDir } from './temp-utils';
import * as fs from 'fs-extra';
import fs from 'fs/promises';
import { Metadata, SquirrelWindowsOptions, PersonMetadata } from './options';
import * as path from 'path';
import * as os from 'os';
Expand All @@ -14,6 +14,8 @@ export { SquirrelWindowsOptions as Options} from './options';

const log = require('debug')('electron-windows-installer:main');

const exists = (p: string) => fs.access(p).then(() => true).catch(() => false);

/**
* A utility function to convert SemVer version strings into NuGet-compatible
* version strings.
Expand Down Expand Up @@ -96,7 +98,8 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P
const vendorUpdate = path.join(vendorPath, 'Squirrel.exe');
const appUpdate = path.join(appDirectory, 'Squirrel.exe');

await fs.copy(vendorUpdate, appUpdate);
await fs.cp(vendorUpdate, appUpdate);

if (options.setupIcon && (options.skipUpdateIcon !== true)) {
let cmd = path.join(vendorPath, 'rcedit.exe');
const args = [
Expand Down Expand Up @@ -127,10 +130,11 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P
const asarFile = path.join(appResources, 'app.asar');
let appMetadata;

if (await fs.pathExists(asarFile)) {
if (await exists(asarFile)) {
appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json').toString());
} else {
appMetadata = await fs.readJson(path.join(appResources, 'app', 'package.json'));
const pkgBuffer = await fs.readFile(path.join(appResources, 'app', 'package.json'), 'utf8');
appMetadata = JSON.parse(pkgBuffer);
}

Object.assign(metadata, {
Expand Down Expand Up @@ -161,11 +165,11 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P
// See https://github.com/electron/windows-installer/issues/389
metadata.authors = sanitizeAuthors(metadata.authors as string);

if (await fs.pathExists(path.join(appDirectory, 'swiftshader'))) {
if (await exists(path.join(appDirectory, 'swiftshader'))) {
metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' });
}

if (await fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))) {
if (await exists(path.join(appDirectory, 'vk_swiftshader_icd.json'))) {
metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' });
}

Expand Down Expand Up @@ -284,7 +288,7 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P
if (metadata.productName || options.setupMsi) {
const msiPath = path.join(outputDirectory, options.setupMsi || `${metadata.productName}Setup.msi`);
const unfixedMsiPath = path.join(outputDirectory, 'Setup.msi');
if (await fs.pathExists(unfixedMsiPath)) {
if (await exists(unfixedMsiPath)) {
log(`Renaming ${unfixedMsiPath} => ${msiPath}`);
await fs.rename(unfixedMsiPath, msiPath);
}
Expand Down
14 changes: 8 additions & 6 deletions src/sign.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { createSeaSignTool as createSeaSignToolType } from '@electron/windows-sign';
import path from 'path';
import semver from 'semver';
import fs from 'fs-extra';
import fs from 'fs/promises';

import { SquirrelWindowsOptions } from './options';

Expand All @@ -10,6 +10,8 @@ let ORIGINAL_SIGN_TOOL_PATH: string;
let BACKUP_SIGN_TOOL_PATH: string;
let SIGN_LOG_PATH: string;

const exists = (p: string) => fs.access(p).then(() => true).catch(() => false);

/**
* This method uses @electron/windows-sign to create a fake signtool.exe
* that can be called by Squirrel - but then just calls @electron/windows-sign
Expand All @@ -31,10 +33,10 @@ export async function createSignTool(options: SquirrelWindowsOptions): Promise<v
const createSeaSignTool = await getCreateSeaSignTool();

await resetSignTool();
await fs.remove(SIGN_LOG_PATH);
await fs.remove(SIGN_LOG_PATH, { force: true, recursive: true });

// Make a backup of signtool.exe
await fs.copy(ORIGINAL_SIGN_TOOL_PATH, BACKUP_SIGN_TOOL_PATH, { overwrite: true });
await fs.cp(ORIGINAL_SIGN_TOOL_PATH, BACKUP_SIGN_TOOL_PATH, { force: true });

// Create a new signtool.exe using @electron/windows-sign
await createSeaSignTool({
Expand All @@ -48,10 +50,10 @@ export async function createSignTool(options: SquirrelWindowsOptions): Promise<v
* fake substitute.
*/
export async function resetSignTool() {
if (BACKUP_SIGN_TOOL_PATH && ORIGINAL_SIGN_TOOL_PATH && fs.existsSync(BACKUP_SIGN_TOOL_PATH)) {
if (BACKUP_SIGN_TOOL_PATH && ORIGINAL_SIGN_TOOL_PATH && await exists(BACKUP_SIGN_TOOL_PATH)) {
// Reset the backup of signtool.exe
await fs.copy(BACKUP_SIGN_TOOL_PATH, ORIGINAL_SIGN_TOOL_PATH, { overwrite: true });
await fs.remove(BACKUP_SIGN_TOOL_PATH);
await fs.cp(BACKUP_SIGN_TOOL_PATH, ORIGINAL_SIGN_TOOL_PATH, { force: true });
await fs.rm(BACKUP_SIGN_TOOL_PATH, { force: true, recursive: true });
}
}

Expand Down
16 changes: 0 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,6 @@
resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==

"@types/fs-extra@^5.0.5":
version "5.1.0"
resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.1.0.tgz"
integrity sha512-AInn5+UBFIK9FK5xc9yP5e3TQSPNNgjHByqYcj9g5elVBnDQcQL7PlO1CIRy2gWlbwK7UPYqi7vRvFA44dCmYQ==
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz"
Expand Down Expand Up @@ -1005,15 +998,6 @@ fs-extra@^11.1.1:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^7.0.1:
version "7.0.1"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz"
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
Expand Down