Skip to content

Commit 7aacb15

Browse files
niikmalept
andauthored
fix: include swiftshader directory when creating installer for Electron 10+ (#375)
Co-authored-by: Mark Lee <[email protected]>
1 parent a524a6c commit 7aacb15

File tree

10 files changed

+70
-13
lines changed

10 files changed

+70
-13
lines changed

spec/fixtures/app/libEGL.dll

-90.5 KB
Binary file not shown.

spec/fixtures/app/libGLESv2.dll

-17.7 KB
Binary file not shown.

spec/fixtures/app/swiftshader/libEGL.dll

Whitespace-only changes.

spec/fixtures/app/swiftshader/libGLESv2.dll

Whitespace-only changes.

spec/fixtures/app/vk_swiftshader.dll

Whitespace-only changes.

spec/fixtures/app/vk_swiftshader_icd.json

Whitespace-only changes.

spec/installer-spec.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,39 @@ import path from 'path';
33
import { createTempDir } from '../src/temp-utils';
44
import fs from 'fs-extra';
55
import { createWindowsInstaller } from '../src';
6+
import spawn from '../src/spawn-promise';
67

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

9-
const appDirectory = path.join(__dirname, 'fixtures/app');
10+
const fixtureAppDirectory = path.join(__dirname, 'fixtures/app');
1011

11-
test.beforeEach(async (): Promise<void> => {
12-
const updateExePath = path.join(appDirectory, 'Squirrel.exe');
12+
function spawn7z(args: string[]): Promise<string> {
13+
const sevenZipPath = path.join(__dirname, '..', 'vendor', '7z.exe');
14+
const wineExe = process.arch === 'x64' ? 'wine64' : 'wine';
15+
return process.platform !== 'win32'
16+
? spawn(wineExe, [sevenZipPath, ...args])
17+
: spawn(sevenZipPath, args);
18+
}
1319

14-
if (await fs.pathExists(updateExePath)) {
15-
await fs.unlink(updateExePath);
16-
}
17-
});
20+
async function createTempAppDirectory(): Promise<string> {
21+
const appDirectory = await createTempDir('electron-winstaller-ad-');
22+
await fs.copy(fixtureAppDirectory, appDirectory);
23+
return appDirectory;
24+
}
1825

1926
test('creates a nuget package and installer', async (t): Promise<void> => {
2027
const outputDirectory = await createTempDir('ei-');
21-
22-
const options = {
23-
appDirectory: appDirectory,
24-
outputDirectory: outputDirectory
25-
};
28+
const appDirectory = await createTempAppDirectory();
29+
const options = { appDirectory, outputDirectory };
2630

2731
await createWindowsInstaller(options);
2832

2933
log(`Verifying assertions on ${outputDirectory}`);
3034
log(JSON.stringify(await fs.readdir(outputDirectory)));
3135

32-
t.true(await fs.pathExists(path.join(outputDirectory, 'myapp-1.0.0-full.nupkg')));
36+
const nupkgPath = path.join(outputDirectory, 'myapp-1.0.0-full.nupkg');
37+
38+
t.true(await fs.pathExists(nupkgPath));
3339
t.true(await fs.pathExists(path.join(outputDirectory, 'MyAppSetup.exe')));
3440

3541
if (process.platform === 'win32') {
@@ -38,4 +44,33 @@ test('creates a nuget package and installer', async (t): Promise<void> => {
3844

3945
log('Verifying Update.exe');
4046
t.true(await fs.pathExists(path.join(appDirectory, 'Squirrel.exe')));
47+
48+
log('Verifying contents of .nupkg');
49+
50+
const packageContents = await spawn7z(['l', nupkgPath]);
51+
52+
t.true(packageContents.includes('lib\\net45\\vk_swiftshader_icd.json'));
53+
t.true(packageContents.includes('lib\\net45\\swiftshader\\libEGL.dll'));
54+
});
55+
56+
test('creates an installer when swiftshader files are missing', async (t): Promise<void> => {
57+
const appDirectory = await createTempAppDirectory();
58+
const outputDirectory = await createTempDir('electron-winstaller-test-');
59+
const options = { appDirectory, outputDirectory };
60+
61+
// Remove swiftshader folder and swiftshader json file, simulating Electron < 10.0
62+
await fs.remove(path.join(appDirectory, 'swiftshader', 'libEGL.dll'));
63+
await fs.remove(path.join(appDirectory, 'swiftshader', 'libGLESv2.dll'));
64+
await fs.rmdir(path.join(appDirectory, 'swiftshader'));
65+
await fs.remove(path.join(appDirectory, 'vk_swiftshader_icd.json'));
66+
67+
await createWindowsInstaller(options);
68+
69+
const nupkgPath = path.join(outputDirectory, 'myapp-1.0.0-full.nupkg');
70+
71+
log('Verifying contents of .nupkg');
72+
73+
const packageContents = await spawn7z(['l', nupkgPath]);
74+
t.false(packageContents.includes('vk_swiftshader_icd.json'));
75+
t.false(packageContents.includes('swiftshader\\'));
4176
});

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,23 @@ export async function createWindowsInstaller(options: Options): Promise<void> {
103103
metadata.version = convertVersion(metadata.version as string);
104104
metadata.copyright = metadata.copyright ||
105105
`Copyright © ${new Date().getFullYear()} ${metadata.authors || metadata.owners}`;
106+
metadata.additionalFiles = metadata.additionalFiles || [];
107+
108+
if (await fs.pathExists(path.join(appDirectory, 'swiftshader'))) {
109+
metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' });
110+
}
111+
112+
if (await fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))) {
113+
metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' });
114+
}
106115

107116
let templateData = await fs.readFile(path.join(__dirname, '..', 'template.nuspectemplate'), 'utf8');
108117
if (path.sep === '/') {
109118
templateData = templateData.replace(/\\/g, '/');
119+
for (const f of metadata.additionalFiles) {
120+
f.src = f.src.replace(/\\/g, '/');
121+
f.target = f.target.replace(/\\/g, '/');
122+
}
110123
}
111124
const nuspecContent = template(templateData)(metadata);
112125

src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export interface PersonMetadata {
133133
url?: string;
134134
}
135135

136+
export interface AdditionalFile {
137+
src: string;
138+
target: string;
139+
}
140+
136141
export interface Metadata {
137142
name?: string;
138143
productName?: string;
@@ -143,4 +148,5 @@ export interface Metadata {
143148
owners?: string | PersonMetadata[];
144149
description?: string;
145150
iconUrl?: string;
151+
additionalFiles?: AdditionalFile[];
146152
}

template.nuspectemplate

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
<file src="Squirrel.exe" target="lib\net45\squirrel.exe" />
2424
<file src="LICENSE" target="lib\net45\LICENSE" />
2525
<file src="<%- exe %>" target="lib\net45\<%- exe %>" />
26+
<% additionalFiles.forEach(function(f) { %>
27+
<file src="<%- f.src %>" target="<%- f.target %>" />
28+
<% }); %>
2629
</files>
2730
</package>

0 commit comments

Comments
 (0)