diff --git a/spec/fixtures/app/libEGL.dll b/spec/fixtures/app/libEGL.dll deleted file mode 100644 index b3bcb032..00000000 Binary files a/spec/fixtures/app/libEGL.dll and /dev/null differ diff --git a/spec/fixtures/app/libGLESv2.dll b/spec/fixtures/app/libGLESv2.dll deleted file mode 100644 index 25e81dcc..00000000 Binary files a/spec/fixtures/app/libGLESv2.dll and /dev/null differ diff --git a/spec/fixtures/app/swiftshader/libEGL.dll b/spec/fixtures/app/swiftshader/libEGL.dll new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/app/swiftshader/libGLESv2.dll b/spec/fixtures/app/swiftshader/libGLESv2.dll new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/app/vk_swiftshader.dll b/spec/fixtures/app/vk_swiftshader.dll new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/app/vk_swiftshader_icd.json b/spec/fixtures/app/vk_swiftshader_icd.json new file mode 100644 index 00000000..e69de29b diff --git a/spec/installer-spec.ts b/spec/installer-spec.ts index ec931418..2879c697 100644 --- a/spec/installer-spec.ts +++ b/spec/installer-spec.ts @@ -3,33 +3,39 @@ import path from 'path'; import { createTempDir } from '../src/temp-utils'; import fs from 'fs-extra'; import { createWindowsInstaller } from '../src'; +import spawn from '../src/spawn-promise'; const log = require('debug')('electron-windows-installer:spec'); -const appDirectory = path.join(__dirname, 'fixtures/app'); +const fixtureAppDirectory = path.join(__dirname, 'fixtures/app'); -test.beforeEach(async (): Promise => { - const updateExePath = path.join(appDirectory, 'Squirrel.exe'); +function spawn7z(args: string[]): Promise { + const sevenZipPath = path.join(__dirname, '..', 'vendor', '7z.exe'); + const wineExe = process.arch === 'x64' ? 'wine64' : 'wine'; + return process.platform !== 'win32' + ? spawn(wineExe, [sevenZipPath, ...args]) + : spawn(sevenZipPath, args); +} - if (await fs.pathExists(updateExePath)) { - await fs.unlink(updateExePath); - } -}); +async function createTempAppDirectory(): Promise { + const appDirectory = await createTempDir('electron-winstaller-ad-'); + await fs.copy(fixtureAppDirectory, appDirectory); + return appDirectory; +} test('creates a nuget package and installer', async (t): Promise => { const outputDirectory = await createTempDir('ei-'); - - const options = { - appDirectory: appDirectory, - outputDirectory: outputDirectory - }; + const appDirectory = await createTempAppDirectory(); + const options = { appDirectory, outputDirectory }; await createWindowsInstaller(options); log(`Verifying assertions on ${outputDirectory}`); log(JSON.stringify(await fs.readdir(outputDirectory))); - t.true(await fs.pathExists(path.join(outputDirectory, 'myapp-1.0.0-full.nupkg'))); + 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'))); if (process.platform === 'win32') { @@ -38,4 +44,33 @@ test('creates a nuget package and installer', async (t): Promise => { log('Verifying Update.exe'); t.true(await fs.pathExists(path.join(appDirectory, 'Squirrel.exe'))); + + log('Verifying contents of .nupkg'); + + const packageContents = await spawn7z(['l', nupkgPath]); + + t.true(packageContents.includes('lib\\net45\\vk_swiftshader_icd.json')); + t.true(packageContents.includes('lib\\net45\\swiftshader\\libEGL.dll')); +}); + +test('creates an installer when swiftshader files are missing', async (t): Promise => { + const appDirectory = await createTempAppDirectory(); + const outputDirectory = await createTempDir('electron-winstaller-test-'); + 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 createWindowsInstaller(options); + + const nupkgPath = path.join(outputDirectory, 'myapp-1.0.0-full.nupkg'); + + log('Verifying contents of .nupkg'); + + const packageContents = await spawn7z(['l', nupkgPath]); + t.false(packageContents.includes('vk_swiftshader_icd.json')); + t.false(packageContents.includes('swiftshader\\')); }); diff --git a/src/index.ts b/src/index.ts index 56a59c47..64932f54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,10 +103,23 @@ export async function createWindowsInstaller(options: Options): Promise { metadata.version = convertVersion(metadata.version as string); metadata.copyright = metadata.copyright || `Copyright © ${new Date().getFullYear()} ${metadata.authors || metadata.owners}`; + metadata.additionalFiles = metadata.additionalFiles || []; + + if (await fs.pathExists(path.join(appDirectory, 'swiftshader'))) { + metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' }); + } + + if (await fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))) { + metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' }); + } let templateData = await fs.readFile(path.join(__dirname, '..', 'template.nuspectemplate'), 'utf8'); if (path.sep === '/') { templateData = templateData.replace(/\\/g, '/'); + for (const f of metadata.additionalFiles) { + f.src = f.src.replace(/\\/g, '/'); + f.target = f.target.replace(/\\/g, '/'); + } } const nuspecContent = template(templateData)(metadata); diff --git a/src/options.ts b/src/options.ts index e5e3bd3f..8cde35d2 100644 --- a/src/options.ts +++ b/src/options.ts @@ -133,6 +133,11 @@ export interface PersonMetadata { url?: string; } +export interface AdditionalFile { + src: string; + target: string; +} + export interface Metadata { name?: string; productName?: string; @@ -143,4 +148,5 @@ export interface Metadata { owners?: string | PersonMetadata[]; description?: string; iconUrl?: string; + additionalFiles?: AdditionalFile[]; } diff --git a/template.nuspectemplate b/template.nuspectemplate index 7cf5bbdc..6817fd45 100644 --- a/template.nuspectemplate +++ b/template.nuspectemplate @@ -23,5 +23,8 @@ + <% additionalFiles.forEach(function(f) { %> + + <% }); %>