Skip to content

Commit a68b774

Browse files
More fixes for Question: Best practice for automating UI Builder dependency installation? #186 Hopefully complete now
1 parent bd30d88 commit a68b774

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

Diff for: CHANGELOG.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ typora-root-url: docs/images
77
## Known Issues
88

99
* uibuilder - Editor
10-
* "Server folder: undefined/xxxxxx" - should show full folder path.
10+
* Library management
11+
* When adding libraries, new packages not showing unless uib restarted.
12+
* When removing libraries, package.json:uibuilder.packages not updated correctly. (the packages are actually removed)
13+
* Vue showing an "update" for v2 when v3 is installed. Only when bootstrap-vue installed.
1114
* Advanced/Serve - folder name not updated immediately when a new folder added. Have to exit and re-open the panel.
12-
* Deleting an Editor tab containing uibuilder nodes, the folder delete process is not called.
15+
* Deleting an Editor tab containing uibuilder nodes, the folder delete process is not called?
16+
* Issue [#184](https://github.com/TotallyInformation/node-red-contrib-uibuilder/issues/184)
1317

1418
## To do/In-progress
1519

@@ -31,8 +35,9 @@ Note that v5.1.1 had a number of new features that are not complete. They are in
3135
* Creating new folder - new folder should be selected after create.
3236
* Add link to [Configuring uibuilder nodes](uib-node-configuration.md) page.
3337
* Change fixed text to use `RED._` for l8n. See: https://discourse.nodered.org/t/flexdash-alpha-release-a-dashboard-for-node-red/65861/48
34-
* Add update indicator to Libraries tab
35-
* Add indicator to Libraries to show if new major version available
38+
* Libraries tab
39+
* Add update indicator to Libraries tab
40+
* Trigger indicator to Libraries to show if new major version available when switching to the tab
3641
* uibindex page
3742
* Add folders to Vendor Routes table (from `packageMgt.uibPackageJson.uibuilder.packages`)
3843
* uib-cache node
@@ -67,7 +72,7 @@ Note that v5.1.1 had a number of new features that are not complete. They are in
6772

6873
* `uib-cache`: Custom variable name was being ignored
6974
* `uibuilder`: Library tab might occasionally list a package that wasn't a direct installed dependency. Now resolved. Only packages listed in `<uibRoot>/package.json` dependencies property will be listed.
70-
* `nodes/libs/package-msg.js` `updateInstalledPackageDetails()`: Installations with a large number of installed libraries not correctly reporting their details. Resolved (hopefully) async issue. Was using `async` with `.forEach()` which doesn't work. Changed to use `Promise.all` with a map. Thanks to [dczysz](https://github.com/dczysz) for reporting.
75+
* `nodes/libs/package-msg.js` `updateInstalledPackageDetails()`: Installations with a large number of installed libraries not correctly reporting their details. Resolved (hopefully) async issue. Was using `async` with `.forEach()` which doesn't work. Changed to use `Promise.all` with a map. Thanks to [dczysz](https://github.com/dczysz) for reporting. Issue [#186](https://github.com/TotallyInformation/node-red-contrib-uibuilder/issues/186). Issue more complex than originally thought. Ended up doing a 2-stage update of the installed libraries data. First stage is quick and synchronous to allow the appropriate vendor folders to be added to the ExpressJS vendor routes. 2nd stage uses npm to get additional library information.
7176

7277
### New
7378

@@ -84,8 +89,9 @@ Note that v5.1.1 had a number of new features that are not complete. They are in
8489
* The currently installed uibuilder version is now shown on the Advanced tab.
8590
* The server's `instanceRoot` filing system folder is shown on the Core tab. This is the configuration and front-end code for this instance of uibuilder.
8691
* The info showing the current web server is now a link to the instance page (same as the Open button above it).
87-
* Package outdated markers added to Editor Library tab.
88-
* Package outdated markers are buttons that will update the installation of the package.
92+
* Library tab
93+
* Package outdated markers added to Editor Library tab. (_Currently only on Node-RED startup_. Will be improved later.)
94+
* Package outdated markers are buttons that will update the installation of the package.
8995

9096

9197
* `uib-cache` node

Diff for: nodes/libs/admin-api-v2.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ function adminRouterV2(uib, log) {
700700
// @ts-expect-error
701701
packageMgt.npmInstallPackage(params.url, params.package, params.tag)
702702
.then((npmOutput) => {
703-
// let success = false
703+
// Get the updated package.json file into packageMgt.uibPackageJson
704+
packageMgt.getUibRootPackageJson()
705+
706+
// Do a fast update of the min data in pj.uibuilder.packages required for web.serveVendorPackages() - re-saves the package.json file
707+
packageMgt.pkgsQuickUpd()
704708

705709
// Update the packageList
706710
web.serveVendorPackages()
@@ -723,6 +727,11 @@ function adminRouterV2(uib, log) {
723727
// @ts-ignore
724728
packageMgt.npmRemovePackage(params.package)
725729
.then((npmOutput) => {
730+
// Get the updated package.json file into packageMgt.uibPackageJson
731+
packageMgt.getUibRootPackageJson()
732+
733+
// Do a fast update of the min data in pj.uibuilder.packages required for web.serveVendorPackages() - re-saves the package.json file
734+
packageMgt.pkgsQuickUpd()
726735

727736
// TODO remove - just send back success
728737

Diff for: nodes/libs/package-mgt.js

+26-12
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ class UibPackages {
119119
if ( !pj.uibuilder ) pj.uibuilder = {}
120120
// Make sure there is a uibuilder.packagedetails prop
121121
if ( !pj.uibuilder.packages ) pj.uibuilder.packages = {}
122+
123+
this.pkgsQuickUpd()
124+
125+
// At this point we have the refs to uib and RED
126+
this.#isConfigured = true
127+
128+
// Re-build package.json uibuilder.packages with details & rewrite file [after 3sec] (async)
129+
this.updateInstalledPackageDetails()
130+
131+
log.trace('[uibuilder:package-mgt:setup] Package Management setup completed')
132+
} // ---- End of setup ---- //
133+
134+
/** Do a fast update of the min data in pj.uibuilder.packages required for web.serveVendorPackages() - re-saves the package.json file */
135+
pkgsQuickUpd() {
136+
if ( this.uib === undefined ) throw this.#uibUndefinedError
137+
if ( this.uib.rootFolder === null ) throw this.#rootFldrNullError
138+
139+
const pj = this.uibPackageJson
140+
122141
// Make sure no extra package details
123142
for (const pkgName in pj.uibuilder.packages) {
124143
if ( !pj.dependencies[pkgName] ) delete pj.uibuilder.packages[pkgName]
@@ -139,16 +158,10 @@ class UibPackages {
139158
pkg.packageUrl = '/' + pkgName
140159
}
141160

142-
// At this point we have the refs to uib and RED
143-
this.#isConfigured = true
144-
145-
this.setUibRootPackageJson(pj)
146-
147-
// Re-build package.json uibuilder.packages with details & rewrite file [after 3sec] (async)
148-
this.updateInstalledPackageDetails()
149-
150-
log.trace('[uibuilder:package-mgt:setup] Package Management setup completed')
151-
} // ---- End of setup ---- //
161+
// Re-save the updated file
162+
//this.setUibRootPackageJson(pj)
163+
this.writePackageJson(this.uib.rootFolder, pj)
164+
}
152165

153166
/** Read the contents of a package.json file
154167
* @param {string} folder The folder containing a package.json file
@@ -302,6 +315,7 @@ class UibPackages {
302315
}
303316
}
304317

318+
/** Use npm to get detailed pkg info (slow, async) to pj.uibuilder.packages & rewrite the pj file */
305319
async updateInstalledPackageDetails() {
306320
const pj = this.uibPackageJson
307321

@@ -682,7 +696,7 @@ class UibPackages {
682696
* @returns {Promise<string>} Command output
683697
*/
684698
async npmListInstalled(folder) {
685-
this.log.info('[uibuilder:package-mgt:npmListInstalled] npm list installed started')
699+
this.log.trace('[uibuilder:package-mgt:npmListInstalled] npm list installed started')
686700

687701
// if ( this._isConfigured !== true ) {
688702
// this.log.warn('[uibuilder:UibPackages:npmListInstalled] Cannot run. Setup has not been called.')
@@ -711,7 +725,7 @@ class UibPackages {
711725
res = e.stdout
712726
}
713727

714-
this.log.info('[uibuilder:package-mgt:npmListInstalled] npm list installed completed')
728+
this.log.trace('[uibuilder:package-mgt:npmListInstalled] npm list installed completed')
715729
return res
716730
} // ---- End of npmListInstalled ---- //
717731

0 commit comments

Comments
 (0)