diff --git a/install/canvas_sharp_compatibility.js b/install/canvas_sharp_compatibility.js new file mode 100644 index 0000000..284e889 --- /dev/null +++ b/install/canvas_sharp_compatibility.js @@ -0,0 +1,27 @@ +'use strict'; + +import * as process from 'process'; +import * as child_process from 'child_process'; +import * as url from 'url'; +import * as path from 'path'; + +const originalPath = process.cwd(); + +process.chdir( + path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..'), +); + +if ( + process.platform == 'win32' && + (process.arch == 'ia32' || process.arch == 'x64') +) { + child_process.spawn('powershell.exe', [ + '-ExecutionPolicy', + 'Bypass', + '-File', + 'install\\win32.ps1', + process.arch, + ]); +} + +process.chdir(originalPath); diff --git a/install/win32.ps1 b/install/win32.ps1 new file mode 100644 index 0000000..b67fc66 --- /dev/null +++ b/install/win32.ps1 @@ -0,0 +1,47 @@ +Set-Location ((Split-Path $MyInvocation.MyCommand.Path -Parent) + '\..\') + +$libraries = @( + 'libffi-8.dll', + 'libglib-2.0-0.dll', + 'libgobject-2.0-0.dll', + 'libiconv-2.dll', + 'libintl-8.dll', + 'libpcre2-8-0.dll' +) + +if (($libraries | foreach { Test-Path ([System.IO.Path]::Combine('./node_modules/sharp/build/Release', $_)) }) -contains $false) { + New-Item -Path temp -ItemType Directory + + $urls = @( + 'https://7-zip.org/a/7zr.exe', + 'https://github.com/mcmilk/7-Zip-zstd/releases/download/v22.01-v1.5.5-R2/7z22.01-zstd-x64.exe' + ) + + if ($args[0] -eq 'ia32') { + $urls += @( + 'https://repo.msys2.org/mingw/clang32/mingw-w64-clang-i686-glib2-2.76.1-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang32/mingw-w64-clang-i686-gettext-0.21.1-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang32/mingw-w64-clang-i686-libffi-3.4.4-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang32/mingw-w64-clang-i686-libiconv-1.17-3-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang32/mingw-w64-clang-i686-pcre2-10.42-1-any.pkg.tar.zst' + ) + } else { + $urls += @( + 'https://repo.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-glib2-2.76.1-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-gettext-0.21.1-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-libffi-3.4.4-1-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-libiconv-1.17-3-any.pkg.tar.zst', + 'https://repo.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-pcre2-10.42-1-any.pkg.tar.zst' + ) + } + + $urls | foreach { Invoke-WebRequest $_ -OutFile ('temp\' + (Split-Path $_ -Leaf)) } + + temp\7zr.exe x -otemp temp\7z22.01-zstd-x64.exe + + Get-ChildItem temp\*.zst | foreach { temp\7z.exe e -otemp $_ } + + Get-ChildItem temp\*.tar | foreach { temp\7z.exe e '-onode_modules/sharp/build/Release' $_ $libraries -r -y } + + Remove-Item temp -Recurse +} diff --git a/package-lock.json b/package-lock.json index a2fedda..a115564 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "tileserver-gl", "version": "4.4.10", + "hasInstallScript": true, "license": "BSD-2-Clause", "dependencies": { "@mapbox/glyph-pbf-composite": "0.0.3", diff --git a/package.json b/package.json index 31430e5..ecb2332 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "bin": "src/main.js", "type": "module", "scripts": { + "install": "node install/canvas_sharp_compatibility", "test": "mocha test/**.js --timeout 10000", "lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}", "lint:js": "npm run lint:eslint && npm run lint:prettier",