From 5ae69d41f4408974d6176e98e633574d9cc92cf2 Mon Sep 17 00:00:00 2001 From: Noah Klayman Date: Sun, 29 Mar 2020 17:59:25 -0700 Subject: [PATCH] fix(build): remove font duplication, fixes #694 --- __tests__/commands.spec.js | 15 --------- index.js | 64 +++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/__tests__/commands.spec.js b/__tests__/commands.spec.js index dde7a0d8..ee1101f1 100644 --- a/__tests__/commands.spec.js +++ b/__tests__/commands.spec.js @@ -215,21 +215,6 @@ describe('electron:build', () => { expect(builder.build.mock.calls[0][0].config.shouldBe).toBe('expected') }) - test('Fonts folder is copied to css if it exists', async () => { - // Mock existence of fonts folder - fs.existsSync.mockReturnValueOnce(true) - await runCommand('electron:build') - // css/fonts folder was created - expect(fs.ensureDirSync).toBeCalledWith( - 'projectPath/dist_electron/bundled/css/fonts' - ) - // fonts was copied to css/fonts - expect(fs.copySync).toBeCalledWith( - 'projectPath/dist_electron/bundled/fonts', - 'projectPath/dist_electron/bundled/css/fonts' - ) - }) - test('.js and .ts are merged into file extensions', async () => { await runCommand('electron:build') diff --git a/index.js b/index.js index fd5532b3..832fb4b3 100644 --- a/index.js +++ b/index.js @@ -159,14 +159,6 @@ module.exports = (api, options) => { ) // Prevent electron-builder from installing app deps fs.ensureDirSync(`${outputDir}/bundled/node_modules`) - // Copy fonts to css/fonts. Fixes some issues with static font imports - if (fs.existsSync(api.resolve(outputDir + '/bundled/fonts'))) { - fs.ensureDirSync(api.resolve(outputDir + '/bundled/css/fonts')) - fs.copySync( - api.resolve(outputDir + '/bundled/fonts'), - api.resolve(outputDir + '/bundled/css/fonts') - ) - } if (bundleMainProcess) { // Build the main process into the renderer process output dir @@ -210,7 +202,7 @@ module.exports = (api, options) => { buildApp() } } - function buildApp () { + function buildApp() { info('Building app with electron-builder:') // Build the app using electron builder builder @@ -319,31 +311,32 @@ module.exports = (api, options) => { let child let firstBundleCompleted = false // Function to kill Electron process - const killElectron = () => new Promise(resolve => { - if (!child || child.killed) { - return resolve() - } - - const currentChild = child - currentChild.on('exit', () => { - resolve() - }) + const killElectron = () => + new Promise(resolve => { + if (!child || child.killed) { + return resolve() + } - // Attempt to kill gracefully - if (process.platform === 'win32') { - currentChild.send('graceful-exit') - } else { - currentChild.kill('SIGTERM') - } + const currentChild = child + currentChild.on('exit', () => { + resolve() + }) - // Kill unconditionally after 2 seconds if unsuccessful - setTimeout(() => { - if (!currentChild.killed) { - warn(`Force killing Electron (process #${currentChild.pid})`) - currentChild.kill('SIGKILL') + // Attempt to kill gracefully + if (process.platform === 'win32') { + currentChild.send('graceful-exit') + } else { + currentChild.kill('SIGTERM') } - }, 2000) - }) + + // Kill unconditionally after 2 seconds if unsuccessful + setTimeout(() => { + if (!currentChild.killed) { + warn(`Force killing Electron (process #${currentChild.pid})`) + currentChild.kill('SIGKILL') + } + }, 2000) + }) // Initial start of Electron startElectron() @@ -382,7 +375,7 @@ module.exports = (api, options) => { }) } - async function launchElectron () { + async function launchElectron() { firstBundleCompleted = true // Don't exit process when electron is killed if (child) { @@ -472,7 +465,7 @@ module.exports = (api, options) => { } } - function onChildExit () { + function onChildExit() { process.exit(0) } } @@ -518,7 +511,7 @@ module.exports = (api, options) => { ) } -function bundleMain ({ +function bundleMain({ mode, api, args, @@ -570,7 +563,8 @@ function bundleMain ({ } }) // Enable/disable nodeIntegration - envVars.ELECTRON_NODE_INTEGRATION = args.headless || pluginOptions.nodeIntegration || false + envVars.ELECTRON_NODE_INTEGRATION = + args.headless || pluginOptions.nodeIntegration || false config.plugin('env').use(webpack.EnvironmentPlugin, [envVars]) if (args.debug) {