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

Watching __dirname and not what I set path to #61

Open
jletey opened this issue Jul 22, 2019 · 21 comments
Open

Watching __dirname and not what I set path to #61

jletey opened this issue Jul 22, 2019 · 21 comments

Comments

@jletey
Copy link

jletey commented Jul 22, 2019

What is the problem

When I set the path to watch as a different path other than __dirname, it doesn't seem to work ... what I mean is that it seems to watch changes only in __dirname, and not the path that I specified

How to reproduce

  • Clone blocks/desktop
  • yarn
  • yarn add -D electron-reload
  • Add this code to main/index.js:
require('electron-reload')(path.join(__dirname, '..', 'src'), {
  electron: path.join(__dirname, '..', 'node_modules', '.bin', 'electron')
})
  • yarn start
  • Change line 83 in src/index.js to:
- <span sx={{ ml: 2 }}>Back</span>
+ <span sx={{ ml: 2 }}>Testing</span>
  • Navigate to some MD or MDX file in your filesystem
  • It will show up as <- Back and not as <- Testing! For example:
Before After

Additional information

OS: macOS 10.14.4 (18E226) ... Mojave
node: 10.15.2
yarn: 1.15.2
electron: 5.0.7

@jletey jletey mentioned this issue Jul 22, 2019
5 tasks
@yan-foto
Copy link
Owner

I don't know what you mean by "it doesn't seem to work". It would be best to provide a generic "how to reproduce" instruction instead of pointing to an external project.

Nonetheless, I suppose that you have problems with hard resets and don't require electron-reload from your main file. If this is the case, you should take a look at this line:

https://github.com/yan-foto/electron-reload/blob/master/main.js#L12

But this is just a wild guess, it might be something else. It might the case that you transpile your JSX to JS in some other folder and watch the sources instead of the transpiled files. I cannot debug your project.

@jletey
Copy link
Author

jletey commented Jul 22, 2019

I suppose that you have problems with hard resets and don't require electron-reload from your main file.

That is exactly what's going on

But this is just a wild guess, it might be something else. It might the case that you transpile your JSX to JS in some other folder and watch the sources instead of the transpiled files. I cannot debug your project.

Thank you so much for taking the time ... I will continue to debug and update you on what I find!

@yan-foto
Copy link
Owner

yan-foto commented Jul 22, 2019

Yes please let me know 🙏 . In the last release we made the assumption that the main file requires electron-reload. Maybe it doesn't make sense for specific projects and we need to revert back.

@jletey
Copy link
Author

jletey commented Jul 22, 2019

Maybe it doesn't make sense for specific projects and we need to revert back.

You should ... I believe that would fix my problem here!

@yan-foto
Copy link
Owner

Easier said than done! There was a reason why we did it (see #58 ) and I'd need a good reason to make new changes.

Why don't you require electron-reload from your main file?

@jletey
Copy link
Author

jletey commented Jul 22, 2019

Why don't you require electron-reload from your main file?

Because I get a blank screen:

Shot 2019-07-22 at 16 44 35

Note that I added this code:

require('electron-reload')(__dirname, {
  electron: path.join(__dirname, '..', 'node_modules', '.bin', 'electron')
})

@yan-foto
Copy link
Owner

yan-foto commented Jul 22, 2019

Now you just need to find out what goes wrong!

@jletey
Copy link
Author

jletey commented Jul 22, 2019

I think what is going wrong is that src/index.js doesn't actually do anything related to electron ... but main/index.js does

When I put the code in src/index.js, it shows up blank
When I put the code in main/index.js, it doesn't watch src/*

@yan-foto
Copy link
Owner

Do me a favor, change the source code of electron-reload in your node_modules directory and add this to line 13 of main.js and let me know what it shows:

console.log(mainFile)

@yan-foto
Copy link
Owner

You are talking about two different things: hard and soft resets. Soft resets happen when files are changed in the directory that you passed to electron-reload. It just reloads all BrowserWindows. Hard reset restarts electron completely when your main file (as defined in package.json) changes. I'm still not sure what's the situation here.

@jletey
Copy link
Author

jletey commented Jul 22, 2019

Do me a favor, change the source code of electron-reload in your node_modules directory and add this to line 13 of main.js and let me know what it shows:

Done ... but nothing prints:

Shot 2019-07-22 at 17 02 53

I'm still not sure what's the situation here.

The way you described it, I want to reload all BrowserWindows

FYI, main/index.js is set as the main file in package.json

@yan-foto
Copy link
Owner

Does the structure of transpiled files reflect the structure of your current source (i.e. before and after babel)

@jletey
Copy link
Author

jletey commented Jul 22, 2019

Does the structure of transpiled files reflect the structure of your current source

Where would I look for this exactly?

@jletey
Copy link
Author

jletey commented Jul 22, 2019

FYI, when I add the code to main/index.js (the main file) ... the console.log command prints "/Users/john/Desktop/desktop/main/index.js" ... so main/index.js

But it doesn't print anything for src/index.js

@yan-foto
Copy link
Owner

I am really sorry, but I think this ping-pong debugging is not going to help us. You are using a number of tools (babel, yarn, etc.) which transform your sources and probably restructure your project after building it. I suggest that you take a step back and try to figure out what is happening in the background.

For soft resets the path that you pass to electron-reload must be the same as where your transpiled files reside. That is the only thing that matter! You can easily find out if its the case by printing out variables and comparing it with whats going on in your project.

@jletey
Copy link
Author

jletey commented Jul 22, 2019

Thanks for all the help @yan-foto!

I think I've made some progress! When I put

require('electron-reload')(path.join(__dirname, '..', 'src'), {
  electron: path.join(__dirname, '..', 'node_modules', '.bin', 'electron')
})

into main/index.js (the main file) and then edit something in src/index.js, the app reloads ... but the changes don't appear

Is that a little bit more meaningful? Is that a better lead?

@yan-foto
Copy link
Owner

Yes! I know what happens! We should've known it earlier. When you start with yarn it initiates babel, which transpiles your files. electron-reload does not do that! What you'd need is some kind of event triggering, which is yet to be implemented. It would also solve #35 and is something that I meant to implement for some time now.

@jletey
Copy link
Author

jletey commented Jul 23, 2019

I see ... thanks for the help @yan-foto! I'll keep an eye on #35 and see if I can open a PR

@yan-foto
Copy link
Owner

Please leave this open. I'll use it as a cue for implementing the events.

@dough654
Copy link

You are talking about two different things: hard and soft resets. Soft resets happen when files are changed in the directory that you passed to electron-reload. It just reloads all BrowserWindows. Hard reset restarts electron completely when your main file (as defined in package.json) changes. I'm still not sure what's the situation here.

I know this is kind of late, and maybe it should be its' own feature request, but have you really thought through the usefulness of that feature? Shouldn't the process be watching for changes in the main file, but also any dependencies of the main file? If I import a module in to my main file, I would likely want my electron app restarted then as well. That's the scenario I find myself in. Just a thought.

@yan-foto
Copy link
Owner

@dough654 that makes perfect sense. Could you please open a new issue for discussions?

josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 10, 2020
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 11, 2020
This release fixes the following issues:
fixes: yan-foto#65
fixes: yan-foto#61
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 11, 2020
This release fixes:
fixes: yan-foto#65
&
fixes: yan-foto#61
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 18, 2020
Also reversed args for hard reset handler
- allows file-argument to be passed to electron in the correct order
- usecase: opening file in electron app from cli

fixes: yan-foto#65
&
fixes: yan-foto#61
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 18, 2020
This version fixes the following issues:
fixes: yan-foto#65
&
fixes: yan-foto#61
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 18, 2020
This suppresses ts errors about the declaration file.

This release fixes:
fixes: yan-foto#65
&
fixes: yan-foto#61
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Mar 19, 2020
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Apr 25, 2020
josheleonard added a commit to josheleonard/electron-reload that referenced this issue Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants