Skip to content

Commit

Permalink
Fix the case where the entry file is in a subdirectory (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vehmloewff authored Feb 7, 2020
1 parent b16f57f commit c1be741
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const chokidar = require('chokidar');
const isDev = require('electron-is-dev');
const dateTime = require('date-time');
const chalk = require('chalk');
const findUp = require('find-up');

function getMainProcessPaths(topModuleObject) {
const cwd = path.dirname(topModuleObject.filename);
function getMainProcessPaths(topModuleObject, cwd) {
const paths = new Set([topModuleObject.filename]);

const getPaths = moduleObject => {
Expand Down Expand Up @@ -43,8 +43,10 @@ module.exports = (moduleObj, options) => {
...options
};

const cwd = path.dirname(moduleObj.filename);
const mainProcessPaths = getMainProcessPaths(moduleObj);
const mainProcessDir = path.dirname(moduleObj.filename);
const packageDir = findUp.sync('package.json', {cwd: mainProcessDir});
const cwd = packageDir ? path.dirname(packageDir) : mainProcessDir;
const mainProcessPaths = getMainProcessPaths(moduleObj, cwd);
const watchPaths = options.watchRenderer ? cwd : [...mainProcessPaths];

const watcher = chokidar.watch(watchPaths, {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"test": "xo",
"start": "electron test"
"start": "electron test/main"
},
"files": [
"index.js"
Expand Down Expand Up @@ -39,7 +39,8 @@
"chalk": "^2.4.2",
"chokidar": "^3.0.0",
"date-time": "^3.1.0",
"electron-is-dev": "^1.1.0"
"electron-is-dev": "^1.1.0",
"find-up": "^4.1.0"
},
"devDependencies": {
"electron": "^5.0.1",
Expand Down
4 changes: 2 additions & 2 deletions test/index.js → test/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const path = require('path');
const {app, BrowserWindow} = require('electron');

require('..')(module, {
require('../..')(module, {
debug: true
});

Expand All @@ -12,5 +12,5 @@ let mainWindow;
await app.whenReady();

mainWindow = new BrowserWindow();
await mainWindow.loadFile(path.join(__dirname, 'index.html'));
await mainWindow.loadFile(path.join(__dirname, '../index.html'));
})();

0 comments on commit c1be741

Please sign in to comment.