Skip to content

Commit

Permalink
fix(packager): fix resolving of afterCopy and afterExtract hook paths
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jan 24, 2017
1 parent 23d1aa9 commit bd4df68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import getForgeConfig from '../util/forge-config';
import packagerCompileHook from '../util/compile-hook';
import readPackageJSON from '../util/read-package-json';
import rebuildHook from '../util/rebuild';
import requireSearch from '../util/require-search';
import resolveDir from '../util/resolve-dir';

const d = debug('electron-forge:packager');
Expand Down Expand Up @@ -81,10 +82,10 @@ export default async (providedOptions = {}) => {
packagerSpinner = ora.ora('Packaging Application').start();
done();
}].concat(forgeConfig.electronPackagerConfig.afterCopy ? forgeConfig.electronPackagerConfig.afterCopy.map(item =>
(typeof item === 'string' ? require(item) : item)
(typeof item === 'string' ? requireSearch(dir, [item]) : item)
) : []),
afterExtract: forgeConfig.electronPackagerConfig.afterExtract ? forgeConfig.electronPackagerConfig.afterExtract.map(item =>
(typeof item === 'string' ? require(item) : item)
(typeof item === 'string' ? requireSearch(dir, [item]) : item)
) : [],
dir,
arch,
Expand Down
11 changes: 10 additions & 1 deletion src/util/require-search.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import debug from 'debug';
import path from 'path';

const d = debug('electron-forge:require-search');

export default (relativeTo, paths) => {
const testPaths = paths
.concat(paths.map(mapPath => path.resolve(relativeTo, mapPath)))
.concat(paths.map(mapPath => path.resolve(relativeTo, 'node_modules', mapPath)));
d('searching', testPaths, 'relative to', relativeTo);
let result;
for (const testPath of paths.concat(paths.map(mapPath => path.resolve(relativeTo, mapPath)))) {
for (const testPath of testPaths) {
try {
d('testing', testPath);
result = require(testPath);
return typeof result === 'object' && result && result.default ? result.default : result;
} catch (err) {
// Ignore the error
}
}
d('failed to find a module in', testPaths);
};

0 comments on commit bd4df68

Please sign in to comment.