Skip to content
Permalink
Browse files

feat(rebuilder): allow configuration of electron-rebuild

Put an electronRebuildConfig in the forge config and pass it through to electron-rebuild.
  • Loading branch information
bendemboski authored and malept committed Dec 20, 2017
1 parent 8945e0a commit b986f2645f74c4bf9c32223399a62028a2b15771
Showing with 67 additions and 28 deletions.
  1. +8 −0 README.md
  2. +1 −1 src/api/package.js
  3. +3 −2 src/api/start.js
  4. +1 −0 src/util/forge-config.js
  5. +6 −2 src/util/rebuild.js
  6. +1 −0 test/fast/forge-config_spec.js
  7. +47 −23 test/slow/rebuild_spec_slow.js
@@ -155,6 +155,7 @@ config object:
"linux": ["deb", "rpm", "flatpak"] // An array of linux make targets
},
"electronPackagerConfig": {},
"electronRebuildConfig": {},
"electronWinstallerConfig": {},
"electronInstallerDMG": {},
"electronInstallerFlatpak": {},
@@ -188,6 +189,13 @@ You can set `electronPackagerConfig` with any of the options from
* `platform` (use the `--platform` Forge command line argument instead, so it's available to all of Forge)
* `quiet`

You can set `electronRebuildConfig` with any of the options from
[Electron Rebuild](https://github.com/electron/electron-rebuild/), except:

* `electronVersion`/`--version` (uses the exact version specified for `electron-prebuilt-compile` in your `devDependencies`)
* `arch`/`--arch` (use the `--arch` Forge command line argument instead, so it's available to all of Forge)
* `buildPath`/`--module-dir` (uses your project's `node_modules`)

**NOTE:** You can also set your `forge` config property of your package.json to point to a JS file that exports the config object:

```js
@@ -89,7 +89,7 @@ export default async (providedOptions = {}) => {
const pruneEnabled = !('prune' in forgeConfig.electronPackagerConfig) || forgeConfig.electronPackagerConfig.prune;

const rebuildHookFn = async (buildPath, electronVersion, pPlatform, pArch, done) => {
await rebuildHook(buildPath, electronVersion, pPlatform, pArch);
await rebuildHook(buildPath, electronVersion, pPlatform, pArch, forgeConfig.electronRebuildConfig);
packagerSpinner = ora('Packaging Application').start();
done();
};
@@ -50,7 +50,9 @@ export default async (providedOptions = {}) => {
throw `Please set your application's 'version' in '${dir}/package.json'.`;
}

await rebuild(dir, packageJSON.devDependencies['electron-prebuilt-compile'], process.platform, process.arch);
const forgeConfig = await getForgeConfig(dir);

await rebuild(dir, packageJSON.devDependencies['electron-prebuilt-compile'], process.platform, process.arch, forgeConfig.electronRebuildConfig);

const spawnOpts = {
cwd: dir,
@@ -73,7 +75,6 @@ export default async (providedOptions = {}) => {

let spawned;

const forgeConfig = await getForgeConfig(dir);
await runHook(forgeConfig, 'generateAssets');

await asyncOra('Launching Application', async () => {
@@ -68,6 +68,7 @@ export default async (dir) => {
make_targets: {},
publish_targets: {},
electronPackagerConfig: {},
electronRebuildConfig: {},
electronWinstallerConfig: {},
electronInstallerDebian: {},
electronInstallerDMG: {},
@@ -2,9 +2,13 @@ import rebuild from 'electron-rebuild';

import asyncOra from '../util/ora-handler';

export default async (buildPath, electronVersion, platform, arch) => {
export default async (buildPath, electronVersion, platform, arch, config = {}) => {
await asyncOra('Preparing native dependencies', async (rebuildSpinner) => {
const rebuilder = rebuild({ buildPath, electronVersion, arch });
const rebuilder = rebuild(Object.assign({}, config, {
buildPath,
electronVersion,
arch,
}));
const { lifecycle } = rebuilder;

let found = 0;
@@ -12,6 +12,7 @@ const defaults = {
},
electronInstallerDMG: {},
electronPackagerConfig: {},
electronRebuildConfig: {},
electronWinstallerConfig: {},
electronInstallerDebian: {},
electronInstallerRedhat: {},
@@ -10,43 +10,67 @@ import { yarnOrNpmSpawn, hasYarn } from '../../src/util/yarn-or-npm';
describe('rebuilder', () => {
const testModulePath = path.resolve(os.tmpdir(), 'electron-forge-rebuild-test');

before(async () => {
async function setupProject() {
await fs.remove(testModulePath);
await fs.mkdirs(testModulePath);
await fs.writeFile(path.resolve(testModulePath, 'package.json'), await fs.readFile(path.resolve(__dirname, '../fixture/native_app/package.json'), 'utf8'));
await yarnOrNpmSpawn(hasYarn() ? [] : ['install'], {
cwd: testModulePath,
stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
});
});
}

before(async () => {
await rebuild(testModulePath, '1.4.12', process.platform, process.arch);
});
async function doRebuild(config) {
await rebuild(testModulePath, '1.4.12', process.platform, process.arch, config);
}

it('should have rebuilt top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ref', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'ref build meta should exist').to.equal(true);
});
describe('no config', () => {
before(async () => {
await setupProject();
await doRebuild();
});

it('should have rebuilt children of top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'microtime', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'microtime build meta should exist').to.equal(true);
});
it('should have rebuilt top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ref', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'ref build meta should exist').to.equal(true);
});

it('should have rebuilt children of scoped top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', '@newrelic/native-metrics', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), '@newrelic/native-metrics build meta should exist').to.equal(true);
});
it('should have rebuilt children of top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'microtime', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'microtime build meta should exist').to.equal(true);
});

it('should have rebuilt children of scoped top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', '@newrelic/native-metrics', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), '@newrelic/native-metrics build meta should exist').to.equal(true);
});

it('should have rebuilt top level optional dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'zipfile', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'zipfile build meta should exist').to.equal(true);
});

it('should have rebuilt top level optional dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'zipfile', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'zipfile build meta should exist').to.equal(true);
it('should not have rebuilt top level devDependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ffi', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'ffi build meta should not exist').to.equal(false);
});
});

it('should not have rebuilt top level devDependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ffi', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'ffi build meta should not exist').to.equal(false);
describe('with config', () => {
before(async () => {
await setupProject();
await doRebuild({ onlyModules: ['ref'] });
});

it('should have rebuilt module in onlyModules', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ref', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'ref build meta should exist').to.equal(true);
});

it('should not have rebuilt module not in onlyModules', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'zipfile', 'build', 'Release', '.forge-meta');
expect(await fs.pathExists(forgeMeta), 'zipfile build meta should not exist').to.equal(false);
});
});

after(async () => {

0 comments on commit b986f26

Please sign in to comment.
You can’t perform that action at this time.