@visulima/packem
Version:
A fast and modern bundler for Node.js and TypeScript.
4 lines (3 loc) • 1.87 kB
JavaScript
var m=Object.defineProperty;var a=(e,s)=>m(e,"name",{value:s,configurable:!0});import{isAccessibleSync as u,readFileSync as h}from"@visulima/fs";import{resolve as n,relative as f,normalize as l,isAbsolute as d,dirname as S}from"@visulima/path";import{SourceMapConsumer as g}from"source-map-js";const w=/\[hash(?::(\d+))?\]/,x=/(?<!^|[/\\])(\.[^\s.]+)/,y=/data:[^\n\r;]+(?:;charset=[^\n\r;]+)?;base64,([\d+/A-Za-z]+={0,2})/;var M=Object.defineProperty,t=a((e,s)=>M(e,"name",{value:s,configurable:!0}),"i");const p=/(?:\n|\r\n)?\/\*[#*@]+\s*sourceMappingURL\s*=\s*(\S+)\s*\*+\//g,c=/(?:\n|\r\n)?\/\/[#@]+\s*sourceMappingURL\s*=\s*(\S+)\s*?$/gm;class b{static{a(this,"S")}static{t(this,"MapModifier")}map;constructor(s){if(typeof s=="string")try{this.map=JSON.parse(s)}catch{}else this.map=s}modify(s){return this.map?(s(this.map),this):this}modifySources(s){return this.map?(this.map.sources&&(this.map.sources=this.map.sources.map(r=>s(r))),this):this}resolve(s=process.cwd()){return this.modifySources(r=>r==="<no source>"?r:n(s,r))}relative(s=process.cwd()){return this.modifySources(r=>r==="<no source>"?r:d(r)?f(s,r):l(r))}toObject(){return this.map}toString(){return this.map?JSON.stringify(this.map):this.map}toConsumer(){return this.map?new g(this.map):this.map}toCommentData(){const s=this.toString();return s?`
/*# sourceMappingURL=data:application/json;base64,${Buffer.from(s).toString("base64")} */`:""}toCommentFile(s){return this.map?`
/*# sourceMappingURL=${s} */`:""}}const O=t(async(e,s)=>{const[,r]=p.exec(e)??c.exec(e)??[];if(!r)return;const[,i]=y.exec(r)??[];if(i)return Buffer.from(i,"base64").toString();if(!s)throw new Error("Extracted map detected, but no ID is provided");const o=n(S(s),r);if(u(o))return h(o)},"getMap"),U=t(e=>e.replaceAll(p,"").replaceAll(c,""),"stripMap"),_=t(e=>new b(e),"mm");export{y as D,x as F,w as H,O as g,_ as m,U as s};