TotallyInformation / node-red-contrib-uibuilder

Easily create data-driven web UI's for Node-RED using any (or no) front-end framework.
https://totallyinformation.github.io/node-red-contrib-uibuilder/#/
Apache License 2.0
452 stars 86 forks source link

installFolder is an absolute path which depends on the node red project path #321

Closed nandlab closed 5 months ago

nandlab commented 6 months ago

Current Behavior

When I clone my Node-RED project on another machine with a different .node-red path, the uibuilder.packages.vue.installFolder property changes in the package.json of uibuilder creating an unnecessary diff in the version control of the project.

Expected Behavior

It would be better if the installFolder property was a local path relative to the uibuilder directory. That way cloning a Node-RED project on another system would not directly modify a file.

Steps To Reproduce

  1. Create a Node-RED project
  2. Install uibuilder
  3. Install vue framework in uibuilder
  4. Commit changes
  5. Push project to a remote git repository
  6. Clone the Node-RED project on another system

Example Node-RED flow

No response

Environment

How is Node-RED installed? Globally with npm.

How/where is UIBUILDER installed? Installed in ~/.node-red/node_modules/node-red-contrib-uibuilder using palette manager.

Have you changed any of the uibuilder settings in your settings.js file? No.

package.json in uibuilder:

{
  "name": "uib-root",
  "version": "6.5.0",
  "dependencies": {
    "vue": "^3.3.4"
  },
  "uibuilder": {
    "packages": {
      "vue": {
        "spec": "^3.3.4",
        "installFolder": "/home/dan/.node-red/projects/node-red-escape-room-controller/uibuilder/node_modules/vue",
        "installedVersion": "3.3.4",
        "estimatedEntryPoint": "dist/vue.global.js",
        "homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme",
        "packageUrl": "/vue",
        "url": "../uibuilder/vendor/vue/dist/vue.global.js",
        "installedFrom": "npm",
        "outdated": {
          "current": "3.3.4",
          "wanted": "3.3.4",
          "latest": "3.4.21"
        }
      }
    }
  }
}
TotallyInformation commented 6 months ago

Hmm, interesting. The absolute path is actually a consequence of using Node.js's join function to ensure safe, cross-platform file paths. If it were to be made into a path relative to the uibRoot folder, when you copied to a new location, it still wouldn't work because you wouldn't actually have those packages installed (in <uibRoot>/node_modules/) and you would still have to install them.

In fact, what should really happen is that uibuilder should check whether its packages actually exist when Node-RED starts - in fact, I thought it did. And if they don't exist, it should warn you and empty the list.

It should, in fact, check on startup whether there is any difference between the actual installed packages and the list.

TotallyInformation commented 6 months ago

OK, so your issue sent me down a load of rabbit holes! 😁

That was good though because that part of the code really did need an update (or 20).

This has resulted in extensive reworking of the package management code for v7 and hopefully the removal of a number of edge-case bugs.

What it hasn't - yet - done is fix your direct issue.

However, what I have done is to make sure that any discrepancies between what is actually installed in <uibRoot>/node_modules/ and <uibRoot>/package.json is highlighted as a warning in the Node-RED log and also in the debug panel. So at least you will know that something needs to be done.

That warning will appear on startup but also whenever you install or remove a library via the uibuilder library manager tab.

On the backlog for a future release are some thoughts about automating the process of fixing discrepancies. This might have unintended consequences however, so more thought is required before I implement something.


PS: The <uibRoot>/package.json file is updated by several processes in uibuilder since the most common use-case is for people to be managing installations using the library manager tab.

Clearly, in your case, you don't perhaps want people to do this. In your specific case, the best workaround would be to move the uibRoot folder to a common location - perhaps one that is just read-only to Node-RED - you can do that in settings.js under the uibuilder section. Then, because you have a common location and because you are using Linux, the filing system name of the folder won't change.

nandlab commented 6 months ago

Thank you for working on this! It would be very convenient, if the uibuilder node_modules can be somehow reinstalled when cloning the Node-RED project on a new machine.

TotallyInformation commented 5 months ago

Closing this for now. Request is on the backlog for a future enhancement.