Update Prepare-StorePackage.ps1#135
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the store packaging PowerShell script to generate separate ZIPs for Chrome/Edge and Firefox, while centralizing packaging logic into reusable functions.
Changes:
- Bumps the default
$Versionand refactors packaging intoNew-StorePackage/Remove-DevelopmentFiles. - Produces two artifacts: a universal Chrome/Edge ZIP and a dedicated Firefox ZIP (renaming
manifest.firefox.jsonduring packaging). - Adds additional packaging steps (dev-file cleanup, manifest mutation, and attempted “dev mode” disabling).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Get-ChildItem $TargetDir -Name $pattern -Recurse -Force 2>$null | ForEach-Object { | ||
| $fullPath = Join-Path $TargetDir $_ | ||
| if (Test-Path $fullPath) { | ||
| Remove-Item $fullPath -Force | ||
| Write-Host "Removed dev file: $_" -ForegroundColor Gray | ||
| } | ||
| } |
There was a problem hiding this comment.
Get-ChildItem $TargetDir -Name $pattern ... is not filtering by $pattern: -Name is a switch parameter and the next argument ($pattern) is treated as another -Path, so the dev-file patterns likely won’t be matched/removed. Use -Filter or -Include with -Path $TargetDir -Recurse (and consider using -File and FullName to avoid manual Join-Path).
| Get-ChildItem $TargetDir -Name $pattern -Recurse -Force 2>$null | ForEach-Object { | |
| $fullPath = Join-Path $TargetDir $_ | |
| if (Test-Path $fullPath) { | |
| Remove-Item $fullPath -Force | |
| Write-Host "Removed dev file: $_" -ForegroundColor Gray | |
| } | |
| } | |
| if ($pattern -like '*`**' -or $pattern -like '*?*') { | |
| Get-ChildItem -Path $TargetDir -Recurse -Force -File -Filter $pattern 2>$null | ForEach-Object { | |
| Remove-Item $_.FullName -Force | |
| Write-Host "Removed dev file: $($_.FullName)" -ForegroundColor Gray | |
| } | |
| } | |
| else { | |
| Get-ChildItem -Path $TargetDir -Recurse -Force -File 2>$null | Where-Object { $_.Name -eq $pattern } | ForEach-Object { | |
| Remove-Item $_.FullName -Force | |
| Write-Host "Removed dev file: $($_.FullName)" -ForegroundColor Gray | |
| } | |
| } |
| $manifest.version = $Version | ||
| $manifestPath = Join-Path $tempDir 'manifest.json' | ||
| if (Test-Path $manifestPath) { | ||
| $manifest = Get-Content $manifestPath | ConvertFrom-Json |
There was a problem hiding this comment.
Get-Content $manifestPath | ConvertFrom-Json will fail for multi-line JSON because the pipeline feeds ConvertFrom-Json one line at a time. Use Get-Content -Raw (or otherwise read the whole file as a single string) before ConvertFrom-Json.
| $manifest = Get-Content $manifestPath | ConvertFrom-Json | |
| $manifest = Get-Content $manifestPath -Raw | ConvertFrom-Json |
| $manifest.content_security_policy = @{ | ||
| extension_pages = "script-src 'self'; object-src 'self'" |
There was a problem hiding this comment.
This overwrites content_security_policy with a hard-coded value that drops the existing font-src / style-src allowances currently present in the repo manifests, while extension pages reference Google Fonts (e.g., blocked.html, options/options.html, popup/popup.html). Either preserve the existing CSP directives when updating, or also remove/replace the external font usage so the packaged extension doesn’t break at runtime.
| $manifest.content_security_policy = @{ | |
| extension_pages = "script-src 'self'; object-src 'self'" | |
| $existingExtensionPagesCsp = $null | |
| if ($null -ne $manifest.content_security_policy) { | |
| if ($manifest.content_security_policy -is [string]) { | |
| $existingExtensionPagesCsp = $manifest.content_security_policy | |
| } | |
| elseif ($null -ne $manifest.content_security_policy.extension_pages) { | |
| $existingExtensionPagesCsp = $manifest.content_security_policy.extension_pages | |
| } | |
| } | |
| if ([string]::IsNullOrWhiteSpace($existingExtensionPagesCsp)) { | |
| $existingExtensionPagesCsp = "script-src 'self'; object-src 'self'" | |
| } | |
| else { | |
| if ($existingExtensionPagesCsp -notmatch "(^|;)\s*script-src\s+'self'(\s*;|$)") { | |
| $existingExtensionPagesCsp = "$existingExtensionPagesCsp; script-src 'self'" | |
| } | |
| if ($existingExtensionPagesCsp -notmatch "(^|;)\s*object-src\s+'self'(\s*;|$)") { | |
| $existingExtensionPagesCsp = "$existingExtensionPagesCsp; object-src 'self'" | |
| } | |
| } | |
| $manifest.content_security_policy = @{ | |
| extension_pages = $existingExtensionPagesCsp |
| foreach ($item in $FilesToInclude) { | ||
| $sourcePath = Join-Path $sourceDir $item | ||
| if (Test-Path $sourcePath) { | ||
| $destPath = Join-Path $tempDir $item | ||
| if (Test-Path $sourcePath -PathType Container) { | ||
| Copy-Item $sourcePath $destPath -Recurse -Force | ||
| } else { | ||
| Copy-Item $sourcePath $destPath -Force | ||
| } | ||
| Write-Host "✅ Included: $item" -ForegroundColor Green | ||
| } else { | ||
| Copy-Item $sourcePath $destPath -Force | ||
| Write-Host "⚠️ Not found: $item" -ForegroundColor Yellow | ||
| } | ||
| Write-Host "✅ Included: $item" -ForegroundColor Green | ||
| } else { | ||
| Write-Host "⚠️ Not found: $item" -ForegroundColor Yellow | ||
| } |
There was a problem hiding this comment.
If a required file (notably the manifest) is missing, the script only logs a warning and still produces a ZIP, which can lead to invalid store uploads while still reporting success. Consider treating missing required inputs as a terminating error (fail fast) and returning a non-zero exit code.
| # Convert back to JSON with proper formatting | ||
| $jsonString = $manifest | ConvertTo-Json -Depth 10 | ||
| $jsonString | Set-Content $manifestPath -Encoding UTF8 | ||
| $optionsPath = Join-Path $tempDir 'options\options.js' |
There was a problem hiding this comment.
Join-Path $tempDir 'options\\options.js' passes a child path containing path separators (and double backslashes), which is brittle and can behave unexpectedly on non-Windows PowerShell. Prefer joining path segments (Join-Path (Join-Path $tempDir 'options') 'options.js') or using a single separator.
| $optionsPath = Join-Path $tempDir 'options\options.js' | |
| $optionsPath = Join-Path (Join-Path $tempDir 'options') 'options.js' |
| Write-Host ' 🦊 Firefox Add-ons: https://addons.mozilla.org/developers/' -ForegroundColor Cyan | ||
| Write-Host '3. Note the assigned extension IDs from each store' -ForegroundColor White | ||
| Write-Host '4. Update enterprise registry files with store IDs:' -ForegroundColor White | ||
| Write-Host ' .\Update-StoreIDs.ps1 -ChromeID <chrome-id> -EdgeID <edge-id>' -ForegroundColor Gray |
There was a problem hiding this comment.
The “Next Steps” command uses -ChromeID / -EdgeID, but Update-StoreIDs.ps1 defines parameters -ChromeExtensionId, -EdgeExtensionId, and -FirefoxExtensionId. Update this output so users can copy/paste a working command.
| Write-Host ' .\Update-StoreIDs.ps1 -ChromeID <chrome-id> -EdgeID <edge-id>' -ForegroundColor Gray | |
| Write-Host ' .\Update-StoreIDs.ps1 -ChromeExtensionId <chrome-id> -EdgeExtensionId <edge-id> -FirefoxExtensionId <firefox-id>' -ForegroundColor Gray |
| $optionsPath = Join-Path $tempDir 'options\options.js' | ||
| if (Test-Path $optionsPath) { | ||
| $content = Get-Content $optionsPath -Raw | ||
| $content = $content -replace 'const DEVELOPMENT_MODE = true', 'const DEVELOPMENT_MODE = false' | ||
| $content | Set-Content $optionsPath -Encoding UTF8 | ||
| Write-Host '✅ Disabled development mode in options.js' -ForegroundColor Green | ||
| } | ||
|
|
There was a problem hiding this comment.
The “disable development mode” step replaces const DEVELOPMENT_MODE = true, but options/options.js in this repo doesn’t define that constant, so the replacement will be a no-op while still logging success. Either remove this step, or update it to modify the actual dev-mode mechanism used by the options UI (it currently derives isDev from the presence of update_url in the manifest).
| $optionsPath = Join-Path $tempDir 'options\options.js' | |
| if (Test-Path $optionsPath) { | |
| $content = Get-Content $optionsPath -Raw | |
| $content = $content -replace 'const DEVELOPMENT_MODE = true', 'const DEVELOPMENT_MODE = false' | |
| $content | Set-Content $optionsPath -Encoding UTF8 | |
| Write-Host '✅ Disabled development mode in options.js' -ForegroundColor Green | |
| } | |
No description provided.