Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the case where the entry file is in a subdirectory #10

Merged
merged 4 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
})();