From bd4df6855ee6bd3bfba046a8f36116caf2c04b0f Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 24 Jan 2017 23:50:48 +1100 Subject: [PATCH] fix(packager): fix resolving of afterCopy and afterExtract hook paths --- src/api/package.js | 5 +++-- src/util/require-search.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/package.js b/src/api/package.js index 493f9b89f0..b1e51470b0 100644 --- a/src/api/package.js +++ b/src/api/package.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, diff --git a/src/util/require-search.js b/src/util/require-search.js index b26a803c39..32c2616abf 100644 --- a/src/util/require-search.js +++ b/src/util/require-search.js @@ -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); };