Zero-Overhead Compilation for High-Performance Modules.
FusePS is a PowerShell Module Bundler. It takes a development environment consisting of scattered functions, classes, and assemblies, and "fuses" them into a single, high-performance artifact (.psm1) optimized for fast loading and easy distribution.
It is not a transpiler. It is a static analysis and bundling engine that enforces industry-standard architecture while eliminating the runtime cost of dot-sourcing files.
π¨ Requirement: PowerShell Core 7+
π§· Function Reference π§· PSGallery π§· Chocolatey π§· GitHubπTable of Contents
- Single-File Artifacts: Compiles hundreds of
.ps1files into one.psm1, reducing module load time by up to 90%. - Smart Scoping & Exports: Automatically detects
FunctionsToExportandAliasesToExport(via[Alias()]attributes). It intelligently ignores private functions (prefixed with_) and nested helper functions, ensuring only your public API is exposed. - Namespace Hoisting: Scans all source files for
using namespacestatements and automatically hoists them to the top of the compiled artifact, preventing syntax errors in merged files. - Surgical Manifest Updates: Updates your
.psd1manifest using AST splicing. This allows it to update version numbers and export lists while guaranteeing that your comments and custom formatting are preserved 100%. - Smart DLL Injection: Drop
.dllfiles intosrc/Assemblies. FusePS creates abin/folder in the output and injects a loader at the top of your module automatically. - Visual Build Logs: Features a high-contrast, ANSI 256-color logging system with distinct badges for status updates, errors, and git operations.
- Syntax Safety: Performs a full AST syntax check on the compiled code before saving. It will never overwrite a valid build with broken code.
- Asset Mirroring: Automatically copies
src/Dataand configured assets (Licenses, Readmes) to the distribution folder.
FusePS relies on a specific "Convention over Configuration" directory layout.
MyProject/
βββ bootstrap.ps1 # The Bootstrapper (Entry point)
βββ build_config.json # Build Configuration
βββ src/
β βββ MyModule.psd1 # Manifest Template
β βββ Classes/ # [Optional] PowerShell Classes & Enums (Loaded 1st)
β βββ Assemblies/ # [Optional] C# .dll files (Loaded 0th)
β βββ Private/ # [Optional] Internal Helper Functions
β βββ Public/ # [Required] Exported Functions
β βββ Data/ # [Optional] JSON/XML/Assets (Copied to dist)
βββ dist/ # [Generated] Final Build Artifacts
Note: Files in
Classes/,Private/, andPublic/are sorted alphabetically before merging. If Class B depends on Class A, name them 01_ClassA.ps1 and 02_ClassB.ps1.
Create a build_config.json in your project root.
{
"psmcompiler": {
"ModuleName": "MyModule",
"SourcePath": "./src",
"DistPath": "./dist",
"VersionStrategy": "GitAuto",
"Options": {
"StripComments": false,
"RegionSeparators": true,
"AutoExport": true
},
"CopyPaths": [
"LICENSE",
"README.md",
"icon.pnd",
"tools",
"readme.txt",
''
]
}
}
| Key | Description |
|---|---|
| ModuleName | The name of the module (Must match .psd1 filename). |
| VersionStrategy | SemVer Auto Version or Manual (Reads from manifest). |
| CopyPaths | Array of file/folder paths (relative to root) to copy to dist/. |
| RegionSeparators | Adds # ____/[ Region ]____ headers to the compiled file for readability. |
FusePS is designed to build itself. You do not need the module installed to run the build. Use the provided build.ps1 script to shim the compiler into memory.
RUN:
build.ps1
# build.ps1
param($Task = "Build")
$Root = $PSScriptRoot
# 1. BOOTSTRAP: Load the compiler's own logic into memory
# This bypasses the need for the module to be installed.
$Source = Join-Path $Root "src"
. (Join-Path $Source "private/Write-Logr.ps1") # Load Logger first
. (Join-Path $Source "private/kvinc.ps1") # Load the AST Helper above
. (Join-Path $Source "public/Invoke-FusePS.ps1") # Load the Compiler/Builder
# 2. RUN
if ($Task -eq "Build") {
Invoke-PsmCompile -ProjectPath $Root
}# Run this in your console to load the "Raw" module for testing
$Root = "C:\Projects\MyModule"
Get-ChildItem "$Root/src/Classes/*.ps1" | ForEach { . $_.FullName }
Get-ChildItem "$Root/src/Private/*.ps1" | ForEach { . $_.FullName }
Get-ChildItem "$Root/src/Public/*.ps1" | ForEach { . $_.FullName }Do not build the module every time you change a line of code. Use a "Dev Loader" snippet in your profile or test script to load the raw source files into memory instantly.
When you are ready to ship, push, or verify:
- Run
./build.ps1. - Inspect the
dist/MyModulefolder. - Test the artifact in a fresh PowerShell session:
pwsh -NoProfile -Command "Import-Module ./dist/MyModule/MyModule.psd1; Get-Help Get-MyFunction"
If your module relies on compiled C# code:
- Place your
.dllfiles insrc/Assemblies/. - FusePS Action:
- Creates
dist/MyModule/bin/. - Copies the DLLs there.
- Injects
Add-Type -Path "$PSScriptRoot/bin/MyLib.dll"at the very top of your compiled.psm1.
- Creates
If your module needs to read JSON configuration or templates at runtime:
- Place files in
src/Data/. - FusePS Action: Copies the folder to
dist/MyModule/Data/. - Accessing it in code:
$Config = Get-Content (Join-Path $PSScriptRoot "Data/config.json") | ConvertFrom-Json
This is the entry point of the compiler.
Aliases: FusePS Fuse
Syntax:
Invoke-FusePS [-p|Path (string)]
Parameters:
| Name | Description |
|---|---|
| Path | The path to the module's root folder. |
| ParserOutPut | Output |
Example: Invoke-FusePS -Path "C:\Projects\MyModule"
-
Load Order:
- Assemblies (DLLs)
- Classes & Enums
- Private Functions
- Public Functions
-
Manifest Updates: FusePS uses the AST to locate the FunctionsToExport hashtable key. If your manifest is missing this key, the auto-export feature will skip the update (and warn you).
-
Aliases: FusePS scans for [Alias('Name')] attributes on your functions and automatically adds them to AliasesToExport in the manifest.
If you have a shared library (e.g., Logr), do not copy-paste code.
- Repo Structure: Keep
Logrin a separate repo or alibs/folder. - Symlink (Advanced): Symlink the file into
src/Private/. - Injector (FusePS V2 Feature): Eventually add a
Librariesarray tobuild_config.jsonthat FusePS reads and injects text content from external paths directly into the build stream.
- Syntax Errors: FusePS parses the final string before saving. If you miss a closing bracket
}in one file, the build will fail and tell you. - Missing Exports: Ensure your public functions are in
src/Public. FusePS only auto-exports functions found in that folder. - Class Order: If
Class BusesClass A, rename the files:src/Classes/01_ClassA.ps1,src/Classes/02_ClassB.ps1. FusePS sorts alphabetically.
This project is licensed under the MIT Licence, see the LICENSE file for details
Made with β€οΈ for Powershell Enthusiasts