UNPKG

@visulima/packem

Version:

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

9 lines (6 loc) 7.39 kB
"use strict";var T=Object.defineProperty;var g=(e,t)=>T(e,"name",{value:t,configurable:!0});const w=require("node:url"),i=require("@visulima/path"),j=require("@visulima/path/utils"),x=require("../../../../../packem_shared/resolve-DSG4Zlek.cjs"),v=require("../../../../../packem_shared/url-C84CQz1g.cjs"),D=require("@visulima/fs"),U=require("mlly"),q=require("../../../../../packem_shared/index-CRpzVvnz.cjs");var F=Object.defineProperty,A=g((e,t)=>F(e,"name",{value:t,configurable:!0}),"s");const I=[".scss",".sass",".css"],M=["sass","style"],C=A((e,t,a)=>{const r=[],n=v.n(e);if(r.push(v.g(n),n),!v.h(e)&&!i.isAbsolute(e)&&!j.isRelative(e)){const o=v.n(`~${e}`);r.push(v.g(o),o)}const l={baseDirs:[i.dirname(t)],caller:"Sass importer",extensions:I,mainFields:M};return a(r,l)},"importerImpl"),z=A(e=>({file:e.replace(/\.css$/i,"")}),"finalize"),_=A((e,t)=>{try{return z(C(e,t,x.r))}catch{return null}},"importer");var k=Object.defineProperty,H=g((e,t)=>k(e,"name",{value:t,configurable:!0}),"e$1");const L=H(e=>{switch(e.toLowerCase()){case".css":return"css";case".sass":return"indented";case".scss":return"scss";default:return}},"resolveSyntax");var N=Object.defineProperty,W=g((e,t)=>N(e,"name",{value:t,configurable:!0}),"i$1");const J=[".scss",".sass",".css"],Z=["sass","style"],B=W((e,t)=>({canonicalize(a,r){const n=r.containingUrl?w.fileURLToPath(r.containingUrl.toString()):e;let l;const o=v.n(a),S=v.g(o);try{l=x.r([S,o],{baseDirs:[i.dirname(n)],caller:"Sass modern importer",extensions:J,mainFields:Z})}catch{return null}return new URL(U.pathToFileURL(l))},load(a){const r=i.extname(a.pathname),n=r?L(r.toLowerCase())??"scss":"scss";try{let l=D.readFileSync(a);return t&&(l=`/* ${a.pathname} */ ${l}`),{contents:l,sourceMapUrl:a,syntax:n}}catch{return null}}}),"importer");var V=Object.defineProperty,G=g((e,t)=>V(e,"name",{value:t,configurable:!0}),"d$1");let $;const K=G(async(e,t)=>{if(e.compileString!==void 0)return t==="modern"?a=>{const{data:r,...n}=a;return e.compileString(r,n)}:t==="modern-compiler"?a=>{const{data:r,...n}=a;return e.compileString(r,n)}:a=>e.renderSync(a);if(t==="modern"||t==="modern-compiler")throw new Error("Modern API is not supported for 'node-sass'");if(!$){const a=Number(process.env.UV_THREADPOOL_SIZE??4);$=new q.d({concurrency:a-1})}return async a=>await $.add(async()=>await new Promise((r,n)=>{e.render.bind(e)(a,(l,o)=>{if(l){n(l);return}r(o)})}))},"getCompileFunction");var Q=Object.defineProperty,R=g((e,t)=>Q(e,"name",{value:t,configurable:!0}),"o");const X=R(()=>{const e=["sass-embedded","sass","node-sass"];for(const t of e)try{return require.resolve(t),t}catch{}throw new Error("No supported Sass implementation found. Please install 'sass-embedded', 'sass', or 'node-sass'.")},"getDefaultSassImplementation"),Y=R(e=>{let t=e;typeof t=="string"&&(t=require(t));const{info:a=void 0}=t;if(!a)throw new Error(`Sass implementation is missing 'info' property. Implementation: ${JSON.stringify(t)}`);const r=a.split(" ");if(r.length<2)throw new Error(`Invalid Sass implementation info format. Expected at least 2 parts, got: "${a}".`);const[n]=r;if(n==="dart-sass"||n==="node-sass"||n==="sass-embedded")return t;throw new Error(`Unsupported Sass implementation: "${n}". Supported implementations are: dart-sass, node-sass, sass-embedded.`)},"getSassImplementation");var ee=Object.defineProperty,P=g((e,t)=>ee(e,"name",{value:t,configurable:!0}),"d");const te=P(async(e,t,a,r,n,l,o)=>{const{warnRuleAsWarning:S,...u}=r,s={...u,data:r.additionalData?typeof r.additionalData=="function"?await r.additionalData(n,e):`${r.additionalData} ${n}`:n};if(!s.logger){const m=S!==!1,y=P(p=>`Warning on line ${p.start.line}, column ${p.start.column} of ${p.url??"-"}:${p.start.line}:${p.start.column}: `,"formatSpan"),O=P(p=>`[debug:${p.start.line}:${p.start.column}] `,"formatDebugSpan");s.logger={debug(p,d){let f="";d.span&&(f=O(d.span)),f+=p,t.debug(f)},warn(p,d){let f="";if(d.deprecation&&(f+="Deprecation "),d.span&&(f+=y(d.span)),f+=p,d.span?.context&&(f+=` ${d.span.start.line} | ${d.span.context}`),d.stack&&d.stack!=="undefined"&&(f+=` ${d.stack}`),m){const b=new Error(f);b.name="SassWarning",b.stack=void 0,a(b)}else t.warn(f)}}}const c=o==="modern"||o==="modern-compiler",{resourcePath:h}=e;if(c){if(s.url=new URL(U.pathToFileURL(h)),l&&(s.sourceMap=!0),s.syntax===void 0){const m=i.extname(h);m&&(s.syntax=L(m.toLowerCase()))}s.loadPaths=[...(s.loadPaths?[...s.loadPaths]:[]).map(m=>i.isAbsolute(m)?m:i.join(process.cwd(),m)),...process.env.SASS_PATH?process.env.SASS_PATH.split(process.platform==="win32"?";":":"):[]],s.importers=s.importers?Array.isArray(s.importers)?[...s.importers]:s.importers:[]}else{s.file=h,l&&(s.sourceMap=!0,s.outFile=i.join(e.rootContext,"style.css.map"),s.sourceMapContents=!0,s.omitSourceMapUrl=!0,s.sourceMapEmbed=!1);const m=i.extname(h);s.indentedSyntax=m&&m.toLowerCase()===".sass"&&s.indentedSyntax===void 0?!0:!!s.indentedSyntax,s.importer=s.importer?Array.isArray(s.importer)?[...s.importer]:[s.importer]:[],s.importer.length===0&&(s.importer=void 0),s.includePaths=[...[process.cwd()].flat(),...(s.includePaths?[...s.includePaths]:[]).map(y=>i.isAbsolute(y)?y:i.join(process.cwd(),y)),...process.env.SASS_PATH?process.env.SASS_PATH.split(process.platform==="win32"?";":":"):[]],s.charset===void 0&&(s.charset=!0)}return s},"getSassOptions");var se=Object.defineProperty,E=g((e,t)=>se(e,"name",{value:t,configurable:!0}),"i");const re=/^[a-z]:[/\\]|^\\\\/i,ae=/^[A-Z0-9+\-.]+:/i,ne=E(e=>e.startsWith("/")?e.length>1&&e[1]==="/"?"scheme-relative":"path-absolute":re.test(e)?"path-absolute":ae.test(e)?"absolute":"path-relative","getURLType"),oe=E((e,t)=>{const a=e;return a.file!==void 0&&delete a.file,a.sourceRoot="",a.sources=a.sources.map(r=>{const n=ne(r);return n==="absolute"&&/^file:/i.test(r)?w.fileURLToPath(r):n==="path-relative"?i.resolve(t,i.normalize(r)):r}),a},"normalizeSourceMap");var ie=Object.defineProperty,le=g((e,t)=>ie(e,"name",{value:t,configurable:!0}),"r");const ce=le((e,t)=>{const a=(e.formatted??e.message??String(e)).replace(/^.*?Error:\s*/i,""),r=new Error(a,{cause:e});return r.name=e.name,r.stack=void 0,r.id=t,e.span?.start&&(r.line=e.span.start.line+1,r.column=e.span.start.column+1),r},"errorFactory"),pe={name:"sass",async process({code:e,map:t}){let a="modern-compiler";const r=this.options.implementation??X();r==="sass"?a="modern":r==="node-sass"&&(a="legacy");const n=a==="modern"||a==="modern-compiler",l=Y(r),o=await te({environment:this.environment,resourcePath:this.id,rootContext:this.cwd},this.logger,this.warn,this.options,e,this.useSourcemap,a);n?o.importers.push(B(this.id,this.debug??!1)):(o.importer&&!Array.isArray(o.importer)&&(o.importer=[o.importer]),o.importer=[...o.importer??[],_]);const S=await K(l,a);let u;try{u=await S(o)}catch(c){throw c.span&&c.span.url!==void 0?this.deps.add(w.fileURLToPath(c.span.url)):c.file&&this.deps.add(i.normalize(c.file)),ce(c,this.id)}let s=u.sourceMap??(u.map?JSON.parse(u.map.toString()):void 0);return s&&this.useSourcemap&&(s=oe(s,this.cwd)),u.loadedUrls?u.loadedUrls.filter(c=>c.protocol==="file:").forEach(c=>{const h=w.fileURLToPath(c);i.isAbsolute(h)&&this.deps.add(h)}):u.stats.includedFiles&&u.stats.includedFiles.forEach(c=>{const h=i.normalize(c);i.isAbsolute(h)&&this.deps.add(h)}),{code:Buffer.from(u.css).toString(),map:s?JSON.stringify(s):t}},test:/\.(sass|scss)$/i};module.exports=pe;