Skip to content
Permalink
Browse files

fix(packager): fix resolving of afterCopy and afterExtract hook paths

  • Loading branch information
MarshallOfSound committed Jan 24, 2017
1 parent 23d1aa9 commit bd4df6855ee6bd3bfba046a8f36116caf2c04b0f
Showing with 13 additions and 3 deletions.
  1. +3 −2 src/api/package.js
  2. +10 −1 src/util/require-search.js
@@ -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');
@@ -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,
@@ -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.
You can’t perform that action at this time.