UNPKG

@speedy-js/source-map

Version:
2 lines (1 loc) 4.34 kB
const{existsSync,readFileSync}=require("fs"),{join}=require("path"),{platform,arch}=process;let nativeBinding=null,localFileExisted=!1,loadError=null;function isMusl(){if(!process.report||typeof process.report.getReport!="function")try{return readFileSync("/usr/bin/ldd","utf8").includes("musl")}catch{return!1}else{const{glibcVersionRuntime:e}=process.report.getReport().header;return!Boolean(e)}}switch(platform){case"android":if(arch!=="arm64")throw new Error(`Unsupported architecture on Android ${arch}`);localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.android-arm64.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.android-arm64.node"):nativeBinding=require("@speedy-js/source-map-android-arm64")}catch(e){loadError=e}break;case"win32":switch(arch){case"x64":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.win32-x64-msvc.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.win32-x64-msvc.node"):nativeBinding=require("@speedy-js/source-map-win32-x64-msvc")}catch(e){loadError=e}break;case"ia32":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.win32-ia32-msvc.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.win32-ia32-msvc.node"):nativeBinding=require("@speedy-js/source-map-win32-ia32-msvc")}catch(e){loadError=e}break;case"arm64":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.win32-arm64-msvc.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.win32-arm64-msvc.node"):nativeBinding=require("@speedy-js/source-map-win32-arm64-msvc")}catch(e){loadError=e}break;default:throw new Error(`Unsupported architecture on Windows: ${arch}`)}break;case"darwin":switch(arch){case"x64":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.darwin-x64.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.darwin-x64.node"):nativeBinding=require("@speedy-js/source-map-darwin-x64")}catch(e){loadError=e}break;case"arm64":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.darwin-arm64.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.darwin-arm64.node"):nativeBinding=require("@speedy-js/source-map-darwin-arm64")}catch(e){loadError=e}break;default:throw new Error(`Unsupported architecture on macOS: ${arch}`)}break;case"freebsd":if(arch!=="x64")throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.freebsd-x64.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.freebsd-x64.node"):nativeBinding=require("@speedy-js/source-map-freebsd-x64")}catch(e){loadError=e}break;case"linux":switch(arch){case"x64":if(isMusl()){localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.linux-x64-musl.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.linux-x64-musl.node"):nativeBinding=require("@speedy-js/source-map-linux-x64-musl")}catch(e){loadError=e}}else{localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.linux-x64-gnu.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.linux-x64-gnu.node"):nativeBinding=require("@speedy-js/source-map-linux-x64-gnu")}catch(e){loadError=e}}break;case"arm64":if(isMusl()){localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.linux-arm64-musl.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.linux-arm64-musl.node"):nativeBinding=require("@speedy-js/source-map-linux-arm64-musl")}catch(e){loadError=e}}else{localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.linux-arm64-gnu.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.linux-arm64-gnu.node"):nativeBinding=require("@speedy-js/source-map-linux-arm64-gnu")}catch(e){loadError=e}}break;case"arm":localFileExisted=existsSync(join(__dirname,"speedy-sourcemap.linux-arm-gnueabihf.node"));try{localFileExisted?nativeBinding=require("./speedy-sourcemap.linux-arm-gnueabihf.node"):nativeBinding=require("@speedy-js/source-map-linux-arm-gnueabihf")}catch(e){loadError=e}break;default:throw new Error(`Unsupported architecture on Linux: ${arch}`)}break;default:throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)}if(!nativeBinding)throw loadError||new Error("Failed to load native binding");const{SourceMap}=nativeBinding;module.exports.SourceMap=SourceMap;