UNPKG

@visulima/packem

Version:

A fast and modern bundler for Node.js and TypeScript.

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