PowerHTML icon indicating copy to clipboard operation
PowerHTML copied to clipboard

Importing PowerHTML module in a directory with a Types folder containing multiple .ps1xml files fails

Open forevanyeung opened this issue 3 years ago • 1 comments

I'm using PowerHTML is one of my modules, my module contains a Types folder with multiple .ps1xml files. When I am in my module's root directory and try to import the PowerHTML module, it fails with this error:

PS /Users/evan.yeung/git/OktaPS> Import-Module PowerHTML
Import-Module: The member 'FormatsToProcess' in the module manifest is not valid: The path cannot be processed because it resolved to more than one file; only one file at a time can be processed.. Verify that a valid value is specified for this field in the '/Users/evan.yeung/.local/share/powershell/Modules/PowerHTML/0.1.7/PowerHTML.psd1' file.

forevanyeung avatar Oct 15 '22 20:10 forevanyeung

Submitted a PR that removes the wildcard matching in FormatsToProcess which fixes the problem.

Another alternative that will dynamically update format data for all files in the Types folder is adding the below code to the psm1 file.

#Append format data to session
$ModuleFormats = @( Get-ChildItem -Path $PSScriptRoot\Types\*.ps1xml -ErrorAction SilentlyContinue )
foreach ($t in $ModuleFormats)
{
    Write-Verbose "Appending format data: $($t.FullName)"
    Update-FormatData -Append $t
}

However, during my testing, this does not clean up after removing the module. So I opted to go for statically defining the format files.

PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }
PS /Users/evan.yeung/git/PowerHTML> import-module ../../git/PowerHTML/
PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }

TypeNames                         FormatViewDefinition
---------                         --------------------
{HtmlAgilityPack.HtmlNode}        {HtmlAgilityPack.HtmlNode}
{HtmlAgilityPack.HtmlTextNode}    {HtmlAgilityPack.HtmlNode}
{HtmlAgilityPack.HtmlCommentNode} {HtmlAgilityPack.HtmlNode}

PS /Users/evan.yeung/git/PowerHTML> remove-module powerhtml
PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }

TypeNames                         FormatViewDefinition
---------                         --------------------
{HtmlAgilityPack.HtmlNode}        {HtmlAgilityPack.HtmlNode}
{HtmlAgilityPack.HtmlTextNode}    {HtmlAgilityPack.HtmlNode}
{HtmlAgilityPack.HtmlCommentNode} {HtmlAgilityPack.HtmlNode}

forevanyeung avatar Oct 16 '22 16:10 forevanyeung