patch(persist): Persistence with type [Object] and [Array] #3248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Totally rewrite using PowerShell's
Verb-Noun
.Reference: #2897 (comment) #3209 #3212
Refactor persistence implementation, by which maintainers could use
[Object]
or[Array]
(for backward compatible) type ofpersist
items to persist directories or files.persist
Demos(can also be found in
test\fixtures\persist
)[Object]
type persistence[Array]
type persistenceProperties Defination
[Object]
(forked from [WIP] Persistence rework with backward compatibility (persist) #3212)file
ordirectory
(alias:folder
,dir
) (optional)file
by default,directory
ifname
ends with\\
or/
(see demos)$persist_dir
(optional)$persist_dir
, link it; otherwise, copy to$persist_dir
and link it$persist_dir
, copy origin to$persist_dir
and link itASCII
, not used for directories)ASCII
,UTF8
,OEM
, etc.$persist_dir
,$architecture
, etc.)\r\n
, not used for directories)[Array]
(forked from fix(persist): Using [Array] to persist file #3209)[Array].Count
is used to determine if it is file or directory""
, not$null
)""
or$null
if not changed), and the remaining elements is file contents which will be joined with\r\n
Implementation
persist_data
into three part:PersistentHelper($Source, $Target, $Content, $Method, $Encoding)
Get-PersistentDefination($Persist)
$Persist
, use different mothods according to$Persist
's type ([PSCustomObject]
,[Object[]]
or[String]
)Add-PersistentLink($Persist, $InstalledPath, $PersistentPath)
Test Cases and Examples
Scoop-Install.Tests.ps1
: testing parsing$persist
, with item type[Object]
and[Array]
nvm-object.json
andnvm-array.json
attachedPlease test and review, thanks.
@r15ch13 @rasa @h404bi @Ash258