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

Doesn't seem to re-transpile app/main.ts, associated with renderer process (should be main) #65

Closed
subatomicglue opened this issue Jan 18, 2022 · 5 comments
Labels
question Further information is requested

Comments

@subatomicglue
Copy link

subatomicglue commented Jan 18, 2022

I run:

ng serve -c web -o

and then:

wait-on tcp:4200 && tsc -p tsconfig.serve.json && npx electronmon . --serve

When I re-save ./app/main.ts, I see electronmon spit out:

[electronmon] renderer file change: app/main.ts

ok... but that's a main file, not a renderer file... and.... it didn't transpile. It didn't even re-run the main process, It reloaded the renderer only. So, I can't make an edit and hit save, and see it, unless I ctrl-C out of electronmon and totally restart, then it's fine.

-> It seems that electronmon is (incorrectly) associating main.ts with the renderer process, instead of the main process.

How do I fix this? The README.md gives patterns and some advice to ignore files, but doesn't tell me how to use that in the situation when electronmon is incorrectly associating the files with the wrong main vs renderer process.

saving package.json works:

[electronmon] main file change: package.json
will quit
[electronmon] restarting app due to file change

and trying to add a pattern to package.json doesn't make any changes (the main.ts does not rerun)

  "electronmon": {
    "patterns": ["app/**"]
  },

it just gives the same renderer line when saving main.ts

[electronmon] renderer file change: app/main.ts
@subatomicglue
Copy link
Author

subatomicglue commented Jan 18, 2022

Well, I figured out that maybe I should add the --watch to the tsc command above
This regenerates .js files when .ts files change (In the case of app/main.ts, it's the app/main.js):

wait-on tcp:4200 && tsc --watch -p tsconfig.serve.json && npx electronmon . --serve

which tsc --watch blocks, and electronmon never runs...
so I run in 2 separate terminals as a test:

Terminal 1

wait-on tcp:4200 && tsc --watch -p tsconfig.serve.json

Terminal 2

npx electronmon . --serve

It runs... But when I change & save app/main.ts I get another electron app running.
Change&Save it 3 times, I get 3 more apps....

Here's the output after I change & save app/main.ts
(must modify the app/main.ts or the .js wont generate and wont trigger the electronmon watcher)

[electronmon] renderer file change: app/main.ts
[electronmon] renderer file change: app/main.js.map
[electronmon] main file change: app/main.js
...partial console.logs (not seeing any global console.log from main.ts)....
will quit
[electronmon] restarting app due to file change
...full console.logs   (seeing all console logs from main.ts)....

Ideas how to prevent all the extra apps running?

@catdad
Copy link
Owner

catdad commented Jan 18, 2022

I think there are two issues here:

First, when you use a compile-to-javascript language, the source code (in your case the typescript files) is not what is run by Electron. Electron can only run JavaScript files. ng takes your source typescript and creates output JavaScript, which is then what Electron uses. When electronmon comes into play, it works the same way. It can only analyze code (that is, the JavaScript files output by your build), and makes the assumption that all the other files are "miscellaneous renderer files" that it just doesn't know how to analyze. Again, the only actual code that is run in your case is the output JavaScript files from the build. Typescript files cannot and are not run as code. You can ignore those (as well as sourcemaps) using the patterns property you mentioned.

Second, multiple apps... since there are no repro steps provided, I can only take guesses here. Electronmon sends standard kill signals to kill the app when restarting it. However, like any other signal, Electron can overload it and choose not to exit. My guess is that is what might be happening, but again, I have no way of knowing if there is no way for me to easily and simply reproduce this problem.

@catdad catdad added the question Further information is requested label Jan 18, 2022
@subatomicglue
Copy link
Author

subatomicglue commented Jan 19, 2022

Ok, that helps, so the typescript side of things needs extra config. Cool. Thanks for the explanation, that all makes sense.

I've edited the package.json so that npm start triggers the right tsc --watch and electronmon watchers... cool...

    "start": "set NODE_ENV=development && npm-run-all -p ng:serve electron:serve-tscwatch electron:serve-electron",
    "ng:serve": "ng serve -c web -o",
    "electron:serve-tscwatch": "tsc --watch -p tsconfig.serve.json",
    "electron:serve-electron": "wait-on tcp:4200 && npx electronmon . --serve",

This gets the *.js files in the main process to regenerate, which gets electronmon to relaunch, cool.

And added a pattern for electronmon to ignore the .ts files in the main process:

"electronmon": {
    "patterns": ["!app/*.ts"]
  },

seems to remove the redundant app/main.ts stuff from getting detected by electronmon in addition to the .js detections.


So, the remaining problem:
For the additional app getting launched, it seems to only happen when saving app/main.ts which generates app/main.js... If I save package.json, then no additional apps are added.

@subatomicglue
Copy link
Author

subatomicglue commented Jan 19, 2022

Found it!

if (serve) {
    win.webContents.openDevTools();
    require('electron-reload')(__dirname, {
      electron: require(path.join(__dirname, '/../node_modules/electron' ))
    });
    win.loadURL('http://localhost:4200');
  }

This was in my app/main.ts from the project I copied this from (angular + electron example I found online).

So, in the end - my app WAS exiting, but then 2 were launching. One from electron-reload and one from electronmon.
Commenting out the electron-reload fixes the issue with the extra app getting launched when saving app/main.ts.

All is good now.

@omardevelopsGit
Copy link

I have almost the same problem

But am not using typescript, the same exact problem, when changing main.js file, it considers it as renderer file, and also package.json is considered as renderer file.

Note: package.json "main" path is pointing to "main.js" file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants