From b211c9ea93e9d0218b3d40d7c7539b6d3bbfea7b Mon Sep 17 00:00:00 2001 From: isc-tleavitt <73311181+isc-tleavitt@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:11:18 -0500 Subject: [PATCH 1/2] Allow file promotion *after* Activate In case it couldn't be done before because the web application didn't exist yet. Fixes #4 --- CHANGELOG.md | 4 ++ cls/pkg/isc/ipm/js/base/processor.cls | 63 ++++++++++++++++----------- module.xml | 4 +- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc0623..085e1b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2] - 2023-02-17 +### Fixed +- Web application file copy handles package manager operation ordering more robustly (#4) + ## [1.1.1] - 2022-09-30 ### Fixed - Web application files are copied to proper target, not the current working directory diff --git a/cls/pkg/isc/ipm/js/base/processor.cls b/cls/pkg/isc/ipm/js/base/processor.cls index c65efd7..d050ebb 100644 --- a/cls/pkg/isc/ipm/js/base/processor.cls +++ b/cls/pkg/isc/ipm/js/base/processor.cls @@ -16,6 +16,8 @@ Property clearTarget As %Boolean [ InitialExpression = 1 ]; /// Either "install" or "ci"; default is "ci" Property installCommand As %String(VALUELIST = ",install,ci") [ InitialExpression = "ci" ]; +Property PromotedFiles As %Boolean [ InitialExpression = 0 ]; + Method OnBeforePhase(pPhase As %String, ByRef pParams) As %Status { Set tSC = $$$OK @@ -27,32 +29,7 @@ Method OnBeforePhase(pPhase As %String, ByRef pParams) As %Status // Compile the UI. Supposes npm is installed and on the PATH, but that's it. Do ..RunBuild(.pParams) } ElseIf (pPhase = "Activate") { - // Move files to the right place. - Set sourceDir = ##class(%Library.File).NormalizeDirectory(..GetSourceDirectory()) - Set targetDir = ..GetTargetDirectory() - If (targetDir = "") { - // Should never happen, but good to be safe (and avoid using working directory) - $$$ThrowStatus($$$ERROR($$$GeneralError,"Target directory not specified.")) - } - Set testFile = sourceDir_"index.html" - If '##class(%Library.File).Exists(testFile) { - $$$ThrowStatus($$$ERROR($$$GeneralError,$$$FormatText("File '%1' does not exist; will not activate %2 UI changes.",testFile,..#FLAVOR))) - } - If verbose { - Write !,"Activating "_..#FLAVOR_" application changes..." - Write !,"Copying ",sourceDir," to ",targetDir - } - $$$ThrowOnError(##class(%ZPM.PackageManager.Developer.File).CopyDir(sourceDir,targetDir,..clearTarget)) - // Clear CSPGateway caches... - If verbose { - Write !,"Clearing CSPGateway caches..." - } - #dim registry As %CSP.Mgr.GatewayRegistry - Set registry = $System.CSP.GetGatewayRegistry() - $$$ThrowOnError(registry.RemoveFilesFromCaches(..GetTargetDirectory()_"*")) - If verbose { - Write !,..#FLAVOR," UI changes activated." - } + Do ..PromoteFiles(verbose) } } Catch e { Set tSC = e.AsStatus() @@ -68,6 +45,9 @@ Method OnAfterPhase(pPhase As %String, ByRef pParams) As %Status Do ..CleanSettings() Set verbose = $Get(pParams("Verbose"),0) If (pPhase = "Activate") { + If '..PromotedFiles { + Do ..PromoteFiles(verbose) + } Do ..PerformActivateFileReplacements() } } Catch e { @@ -76,6 +56,37 @@ Method OnAfterPhase(pPhase As %String, ByRef pParams) As %Status Quit tSC } +Method PromoteFiles(verbose As %Boolean) +{ + // Move files to the right place. + Set sourceDir = ##class(%Library.File).NormalizeDirectory(..GetSourceDirectory()) + Set targetDir = ..GetTargetDirectory() + If (targetDir = "") { + // May happen due to a chicken-and-egg problem in module activation. + Quit + } + Set testFile = sourceDir_"index.html" + If '##class(%Library.File).Exists(testFile) { + $$$ThrowStatus($$$ERROR($$$GeneralError,$$$FormatText("File '%1' does not exist; will not activate %2 UI changes.",testFile,..#FLAVOR))) + } + If verbose { + Write !,"Activating "_..#FLAVOR_" application changes..." + Write !,"Copying ",sourceDir," to ",targetDir + } + $$$ThrowOnError(##class(%ZPM.PackageManager.Developer.File).CopyDir(sourceDir,targetDir,..clearTarget)) + // Clear CSPGateway caches... + If verbose { + Write !,"Clearing CSPGateway caches..." + } + #dim registry As %CSP.Mgr.GatewayRegistry + Set registry = $System.CSP.GetGatewayRegistry() + $$$ThrowOnError(registry.RemoveFilesFromCaches(..GetTargetDirectory()_"*")) + If verbose { + Write !,..#FLAVOR," UI changes activated." + } + Set ..PromotedFiles = 1 +} + Method CleanSettings() [ Abstract ] { } diff --git a/module.xml b/module.xml index f04b73b..287cfe1 100644 --- a/module.xml +++ b/module.xml @@ -2,7 +2,7 @@ isc.ipm.js - 1.1.1 + 1.1.2 isc.json @@ -10,7 +10,7 @@ module - + Module From ac3e76d5f94b339925d6893ffe93a3f30c257d63 Mon Sep 17 00:00:00 2001 From: isc-tleavitt <73311181+isc-tleavitt@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:32:58 -0500 Subject: [PATCH 2/2] Stash state in pParams Property might randomly be reinitialized, so store state in pParams instead. --- cls/pkg/isc/ipm/js/base/processor.cls | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cls/pkg/isc/ipm/js/base/processor.cls b/cls/pkg/isc/ipm/js/base/processor.cls index d050ebb..71ada1f 100644 --- a/cls/pkg/isc/ipm/js/base/processor.cls +++ b/cls/pkg/isc/ipm/js/base/processor.cls @@ -16,8 +16,6 @@ Property clearTarget As %Boolean [ InitialExpression = 1 ]; /// Either "install" or "ci"; default is "ci" Property installCommand As %String(VALUELIST = ",install,ci") [ InitialExpression = "ci" ]; -Property PromotedFiles As %Boolean [ InitialExpression = 0 ]; - Method OnBeforePhase(pPhase As %String, ByRef pParams) As %Status { Set tSC = $$$OK @@ -29,7 +27,7 @@ Method OnBeforePhase(pPhase As %String, ByRef pParams) As %Status // Compile the UI. Supposes npm is installed and on the PATH, but that's it. Do ..RunBuild(.pParams) } ElseIf (pPhase = "Activate") { - Do ..PromoteFiles(verbose) + Do ..PromoteFiles(verbose,.pParams) } } Catch e { Set tSC = e.AsStatus() @@ -45,8 +43,8 @@ Method OnAfterPhase(pPhase As %String, ByRef pParams) As %Status Do ..CleanSettings() Set verbose = $Get(pParams("Verbose"),0) If (pPhase = "Activate") { - If '..PromotedFiles { - Do ..PromoteFiles(verbose) + If '..PromotedFiles(.pParams) { + Do ..PromoteFiles(verbose,.pParams) } Do ..PerformActivateFileReplacements() } @@ -56,7 +54,12 @@ Method OnAfterPhase(pPhase As %String, ByRef pParams) As %Status Quit tSC } -Method PromoteFiles(verbose As %Boolean) +Method PromotedFiles(ByRef pParams) As %Boolean +{ + Quit $Get(pParams($classname(),..ResourceReference.Name,"PromotedFiles"),0) +} + +Method PromoteFiles(verbose As %Boolean, ByRef pParams) { // Move files to the right place. Set sourceDir = ##class(%Library.File).NormalizeDirectory(..GetSourceDirectory()) @@ -84,7 +87,7 @@ Method PromoteFiles(verbose As %Boolean) If verbose { Write !,..#FLAVOR," UI changes activated." } - Set ..PromotedFiles = 1 + Set pParams($classname(),..ResourceReference.Name,"PromotedFiles") = 1 } Method CleanSettings() [ Abstract ]