File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 11function Get-InstallPath {
22
33 # returns OS specific path for module installation, it support only -Scope CurrentUser
4- if ($IsLinux -or $IsOSX ) {
4+
5+ $defaultPath = if ($IsLinux -or $IsOSX ) {
56 # "$HOME/.local/share/powershell/Modules"
67 # https://github.com/PowerShell/PowerShellGet/blob/d4dfebbbec4dfbe73392719a8a331541ed75d508/src/PowerShellGet/private/modulefile/PartOne.ps1#L71
78 Join-Path (Split-Path - Path ([System.Management.Automation.Platform ]::SelectProductNameForDirectory(' USER_MODULES' )) - Parent) ' Modules'
@@ -18,4 +19,22 @@ function Get-InstallPath {
1819 }
1920 }
2021
22+ $ModulePaths = $Env: PSModulePath -split (' ;:' [[int ]($IsLinux -or $IsMacOS )])
23+ if ($defaultPath -in $ModulePaths ) {
24+ $defaultPath
25+ } else {
26+ # default path is not in findable by get-module, try to avoid it
27+ $writablePath = ' '
28+ foreach ($P1 in $ModulePaths ) {
29+ if (([string ]::IsNullOrEmpty($writablePath )) -and (Test-PathWritable $P1 )) {
30+ $writablePath = $P1
31+ }
32+ }
33+ if ([string ]::IsNullOrEmpty($writablePath )) {
34+ # we found no writable paths, return default one
35+ $defaultPath
36+ } else {
37+ $writablePath
38+ }
39+ }
2140}
Original file line number Diff line number Diff line change 1+ function Test-PathWritable {
2+ param (
3+ [string ]$Path
4+ )
5+ # returns true if given directory is writable, false otherwise
6+ if (! (Test-Path $Path - PathType Container)) {
7+ # throw "Path $Path is not a directory"
8+ $false
9+ }
10+
11+ $FileName = Join-Path $Path ([io.path ]::GetRandomFileName())
12+
13+ try {
14+ [io.file ]::OpenWrite($FileName ).close()
15+ [io.file ]::Delete($FileName )
16+ $true
17+ } catch {
18+ $false
19+ }
20+
21+ }
Original file line number Diff line number Diff line change 1111$ModuleName = ' InstallModuleFromGit'
1212$here = Split-Path - Parent $MyInvocation.MyCommand.Path # Tests/Module folder
1313$root = (get-item $here ).Parent.Parent.FullName # module root folder
14- Import-Module (Join-Path $root " $ModuleName .psm1 " ) - Force
14+ Import-Module (Join-Path $root " $ModuleName .psd1 " ) - Force
1515
1616
1717#
@@ -67,6 +67,8 @@ Describe 'Proper Functions Declaration' -Tag 'Other' {
6767
6868Describe ' Proper Documentation' - Tag ' Documentation' {
6969
70+ Push-Location $root
71+
7072 It ' Updates documentation and does git diff' {
7173
7274 # install PlatyPS
@@ -92,6 +94,7 @@ Describe 'Proper Documentation' -Tag 'Documentation' {
9294 }
9395 }
9496
97+ Pop-Location
9598}
9699
97100
You can’t perform that action at this time.
0 commit comments