UNPKG

@visulima/packem

Version:

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

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