UNPKG

cmake-ts

Version:

cmake-js rewrite in typescript to support advanced build configurations

6 lines (5 loc) 2.78 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("module"),u=require("fs"),h=require("path");var l=typeof document<"u"?document.currentScript:null;function b(t){return t==="linux"?u.existsSync("/etc/alpine-release")?"musl":"glibc":t==="darwin"?"libc":t==="win32"?"msvc":"unknown"}class p{level=2;setLevel(e="info"){this.level=e==="trace"?4:e==="debug"?3:e==="info"?2:e==="warn"?1:e==="error"?0:-1}error(...e){this.level>=0&&console.error("\x1B[31m[ERROR cmake-ts]\x1B[0m",...e)}warn(...e){this.level>=1&&console.warn("\x1B[33m[WARN cmake-ts]\x1B[0m",...e)}info(...e){this.level>=2&&console.info("\x1B[32m[INFO cmake-ts]\x1B[0m",...e)}log(...e){return this.info(...e)}debug(...e){this.level>=3&&console.debug("\x1B[34m[DEBUG cmake-ts]\x1B[0m",...e)}trace(...e){this.level>=4&&console.trace("\x1B[34m[TRACE cmake-ts]\x1B[0m",...e)}}const s=new p;function f(t){return t instanceof Error&&t.stack!==void 0?t.stack:String(t)}class w{buildDir;manifest;constructor(e){this.buildDir=e;const n=h.resolve(e,"manifest.json");if(!u.existsSync(n))throw new Error(`Manifest file not found at ${n}`);try{s.debug(`Reading and parsing manifest file at ${n}`);const r=u.readFileSync(n,"utf-8");this.manifest=JSON.parse(r)}catch(r){throw new Error(`Failed to read and parse the manifest file at ${n}: ${f(r)}`)}}findCompatibleConfigs(e){const n=this.getConfigKeys(),r=[];for(const i of n)try{const o=this.getConfig(i);if(o.os!==e.os||o.arch!==e.arch||o.libc!==e.libc){s.debug(`Config ${i} is not compatible with the current runtime. Skipping...`);continue}const a=this.getAddonPath(i);r.push([o,h.resolve(this.buildDir,a)])}catch(o){s.warn(`Failed to parse config ${i}: ${f(o)}`)}if(r.length===0)throw new Error(`No compatible zeromq.js addon found for ${e.os} ${e.arch} ${e.libc}. The candidates were: ${n.join(` `)}`);return r.sort(([i,o],[a,c])=>{var d,m;return((d=a.abi)!=null?d:0)-((m=i.abi)!=null?m:0)}),r}getConfigKeys(){return Object.keys(this.manifest)}getConfig(e){return JSON.parse(e)}getAddonPath(e){return this.manifest[e]}}function y(){return{os:process.platform,arch:process.arch,libc:b(process.platform)}}function $(t){let e;try{const n=y(),i=new w(t).findCompatibleConfigs(n),o=typeof require=="function"?require:g.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:l&&l.tagName.toUpperCase()==="SCRIPT"&&l.src||new URL("loader.js",document.baseURI).href);for(const[a,c]of i)try{s.debug(`Loading addon at ${c}`),e=o(c);break}catch(d){s.warn(`Failed to load addon at ${c}: ${f(d)} Trying others...`)}}catch(n){throw new Error(`Failed to load zeromq.js addon.node: ${f(n)}`)}if(e===void 0)throw new Error("No compatible zeromq.js addon found");return e}exports.loadAddon=$; //# sourceMappingURL=loader.js.map