bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
320 stars 84 forks source link

change sourcePath.default #226

Closed mvdbastos closed 1 year ago

mvdbastos commented 1 year ago

proposal to try to solve the issue I think was introduced here: https://github.com/bennymeg/nx-electron/commit/955ca5dd3d2ff967c8f47ebda305ebd2556e62aa#r120927834, I had this problem in a brand new generated repo following all of the instructions and now I was able to bypass the default config, but changing this line will prevent future errors

bennymeg commented 1 year ago

Thanks!

bennymeg commented 1 year ago

@mvdbastos I'm trying to understand what the issue was here. Did you build your application before you invoked the package executor?

mvdbastos commented 1 year ago

@mvdbastos I'm trying to understand what the issue was here. Did you build your application before you invoked the package executor?

Yes I did, and it was a clean project generated with the nx-electron, I reported the output of the run here: https://github.com/bennymeg/nx-electron/commit/955ca5dd3d2ff967c8f47ebda305ebd2556e62aa#r120927834 Here is the output when I run the package script:

 *  Executing task: npx nx run electron-app:package 

> nx run electron-app:package

*********************************************************
DO NOT FORGET TO REBUILD YOUR FRONTEND & BACKEND PROJECTS
FOR PRODUCTION BEFORE PACKAGING / MAKING YOUR ARTIFACT!
*********************************************************
Error: ENOENT: no such file or directory, open 'C:\Users\User\Development\repo\dist\apps\electron-app\index.js'

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— 

 >  NX   Ran target package for project electron-app (2s)

    ×    1/1 failed
    √    0/1 succeeded [0 read from cache]

 *  The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command npx nx run electron-app:package" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

In a nutshell, the problem is that the package script of the solution doest't work out of the box because it generated for me a project.json file where it doesn't contains a SourcePath explicitly declared, on my project it was auto generated like the following:

...
"package": {
      "executor": "nx-electron:package",
      "options": {
        "name": "electron-app",
        "frontendProject": "frontend-project",
        "outputPath": "dist/packages",
        "prepackageOnly": true
      }
    },
...

Because of that, the packager falls down to the default value of SourcePath that is \dist\apps but the files are not there anymore, now the files are placed in dist/packages, so, in order to make the project work, I needed to explicitly specify the sourcePath in my project.json file, like that:

...
"package": {
      "executor": "nx-electron:package",
      "options": {
        "name": "electron-app",
        "frontendProject": "frontend-project",
        "sourcePath": "dist/packages", //explicitly declared
        "outputPath": "dist/packages",
        "prepackageOnly": true
      }
    },
...

So, the change proposed by me is to have the default "sourcePath": "dist/packages" declared correctly, so the new generated projects will package flawlessly out of the box.

bennymeg commented 1 year ago

I see, what I'm struggling about is way your compiled apps are placed in the packages directory? Did I missed something?

mvdbastos commented 1 year ago

I can try from scratch and see if I can reproduce this behavior, but I have to say that I'm not used to your code, I just tried nx-electron to see if it's suitable for my project and when I saw the bug, I just thought it wasn't catched in the workflow and tried to contribute