Skip to content

Commit e7c0009

Browse files
committed
♻️ Cleanup boot process
1 parent fc13b22 commit e7c0009

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

ModuleFast.ps1

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,35 @@ function Import-NuGetVersioningAssembly {
6262
Import-NuGetVersioningAssembly
6363
if ($ImportNugetVersioning) { return }
6464

65-
if (Get-Module $ModuleName) {
65+
if (-not (Get-Module $ModuleName)) {
66+
#Dont use a release, use the latest commit on main
67+
if ($UseMain) {
68+
$Uri = "https://raw.githubusercontent.com/$User/$Repo/main/$ModuleName.psm1"
69+
}
70+
71+
Write-Debug "Fetching $ModuleName from $Uri"
72+
$ProgressPreference = 'SilentlyContinue'
73+
try {
74+
$response = [HttpClient]::new().GetStringAsync($Uri).GetAwaiter().GetResult()
75+
} catch {
76+
$PSItem.ErrorDetails = "Failed to fetch $ModuleName from $Uri`: $PSItem"
77+
$PSCmdlet.ThrowTerminatingError($PSItem)
78+
}
79+
Write-Debug 'Fetched response'
80+
$scriptBlock = [ScriptBlock]::Create($response)
81+
$ProgressPreference = 'Continue'
82+
83+
$bootstrapModule = New-Module -Name $ModuleName -ScriptBlock $scriptblock | Import-Module -PassThru
84+
Write-Debug "Loaded Module $ModuleName"
85+
} else {
6686
Write-Warning "Module $ModuleName already loaded, skipping bootstrap."
67-
return
6887
}
6988

70-
#Dont use a release, use the latest commit on main
89+
#This is ModuleFast specific
7190
if ($UseMain) {
72-
$Uri = "https://raw.githubusercontent.com/$User/$Repo/main/$ModuleName.psm1"
73-
}
74-
75-
Write-Debug "Fetching $ModuleName from $Uri"
76-
$ProgressPreference = 'SilentlyContinue'
77-
try {
78-
$response = [HttpClient]::new().GetStringAsync($Uri).GetAwaiter().GetResult()
79-
} catch {
80-
$PSItem.ErrorDetails = "Failed to fetch $ModuleName from $Uri`: $PSItem"
81-
$PSCmdlet.ThrowTerminatingError($PSItem)
91+
Write-Debug 'UseMain Specified, ModuleFast will use preview.pwsh.gallery'
92+
& (Get-Module $ModuleName) { $SCRIPT:DefaultSource = 'https://preview.pwsh.gallery/index.json' }
8293
}
83-
Write-Debug 'Fetched response'
84-
$scriptBlock = [ScriptBlock]::Create($response)
85-
$ProgressPreference = 'Continue'
86-
87-
$bootstrapModule = New-Module -Name $ModuleName -ScriptBlock $scriptblock | Import-Module -PassThru
88-
Write-Debug "Loaded Module $ModuleName"
8994

9095
if ($installArgs) {
9196
Write-Debug "Detected we were started with args, running $Entrypoint $($installArgs -join ' ')"
@@ -95,8 +100,4 @@ if ($installArgs) {
95100
Remove-Module $bootstrapModule
96101
}
97102

98-
#This is ModuleFast specific
99-
if ($UseMain) {
100-
Write-Debug 'UseMain Specified, ModuleFast will use preview.pwsh.gallery'
101-
& (Get-Module $ModuleName) { $SCRIPT:DefaultSource = 'https://preview.pwsh.gallery/index.json' }
102-
}
103+

ModuleFast.psm1

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,28 @@ $ErrorActionPreference = 'Stop'
2626
$SCRIPT:DefaultSource = 'https://pwsh.gallery/index.json'
2727

2828
#region Public
29-
<#
30-
.SYNOPSIS
31-
High performance, declarative Powershell Module Installer
32-
.DESCRIPTION
33-
ModuleFast is a high performance, declarative PowerShell module installer. It is designed with no external dependencies and can be bootstrapped in a single line of code. It is ideal for Continuous Integration/Deployment and serverless scenarios where you want to install modules quickly and without any user interaction. It is inspired by pnpm and other high performance declarative package managers.
34-
35-
ModuleFast accepts a variety of familiar PowerShell syntaxes and objects for module specification as well as a custom shorthand syntax allowing complex version requirements to be defined in a single string.
36-
37-
ModuleFast can also install the required modules specified in the #Requires line of a script, or in the RequiredModules section of a module manifest, by simplying providing the path to that file in the -Path parameter (which also accepts remote UNC, http, and https URLs).
38-
39-
.EXAMPLE
40-
Install-ModuleFast 'Az'
41-
.EXAMPLE
42-
$plan = Get-ModuleFastPlan 'Az','VMWare.PowerCLI'
43-
$plan | Install-ModuleFast
44-
.EXAMPLE
45-
$plan = Install-ModuleFast 'Az','VMWare.PowerCLI' -WhatIf
46-
$plan | Install-ModuleFast
47-
#>
29+
4830
function Install-ModuleFast {
31+
<#
32+
.SYNOPSIS
33+
High performance, declarative Powershell Module Installer
34+
.DESCRIPTION
35+
ModuleFast is a high performance, declarative PowerShell module installer. It is designed with no external dependencies and can be bootstrapped in a single line of code. It is ideal for Continuous Integration/Deployment and serverless scenarios where you want to install modules quickly and without any user interaction. It is inspired by pnpm and other high performance declarative package managers.
36+
37+
ModuleFast accepts a variety of familiar PowerShell syntaxes and objects for module specification as well as a custom shorthand syntax allowing complex version requirements to be defined in a single string.
38+
39+
ModuleFast can also install the required modules specified in the #Requires line of a script, or in the RequiredModules section of a module manifest, by simplying providing the path to that file in the -Path parameter (which also accepts remote UNC, http, and https URLs).
40+
41+
.EXAMPLE
42+
Install-ModuleFast 'Az'
43+
.EXAMPLE
44+
$plan = Get-ModuleFastPlan 'Az','VMWare.PowerCLI'
45+
$plan | Install-ModuleFast
46+
.EXAMPLE
47+
$plan = Install-ModuleFast 'Az','VMWare.PowerCLI' -WhatIf
48+
$plan | Install-ModuleFast
49+
#>
50+
4951
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Specification')]
5052
param(
5153
#The module(s) to install. This can be a string, a ModuleSpecification, a hashtable with nuget version style (e.g. @{Name='test';Version='1.0'}), a hashtable with ModuleSpecification style (e.g. @{Name='test';RequiredVersion='1.0'}),

README.MD

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This is a PowerShell module installer that is optimized for high performance and no external dependencies so it can be
55
used as a bootstrap to quickly install and update modules in a declarative fashion.
66

7-
## Quick Start Bootstrap
7+
## Bootstrap Quick Start
88

99
### Load ModuleFast as a module for the session
1010

@@ -17,6 +17,12 @@ Install-ModuleFast ImportExcel
1717

1818
The bit.ly link will always point to the latest release of ModuleFast by default. In order to avoid breaking changes, you can pin to a specific release. This is recommended when using CI systems such as GitHub Actions to install dependencies but is generally not needed on an interactive basis.
1919

20+
### View the Detailed Help for ModuleFast
21+
```powershell
22+
iwr bit.ly/modulefast | iex
23+
Get-Help Install-ModuleFast -Full
24+
```
25+
2026
### Single Line Installation (good for CI/CD)
2127

2228
This syntax allows you to both load and invoke Install-Modulefast. Any additional arguments you pass to the command are the same as if you provided them as arguments to Install-ModuleFast

0 commit comments

Comments
 (0)