Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
forevanyeung opened this issue Oct 15, 2022 · 1 comment

Comments

@forevanyeung
Copy link

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
Copy link
Author

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant