You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

9 lines
11 KiB

#!/usr/bin/env node
var le=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ae=e=>{throw TypeError(e)};var G=(e,t,i)=>{if(t!=null){typeof t!="object"&&typeof t!="function"&&ae("Object expected");var r,o;i&&(r=t[le("asyncDispose")]),r===void 0&&(r=t[le("dispose")],i&&(o=r)),typeof r!="function"&&ae("Object not disposable"),o&&(r=function(){try{o.call(this)}catch(n){return Promise.reject(n)}}),e.push([i,r,t])}else i&&e.push([i]);return t},J=(e,t,i)=>{var r=typeof SuppressedError=="function"?SuppressedError:function(u,s,l,p){return p=Error(l),p.name="SuppressedError",p.error=u,p.suppressed=s,p},o=u=>t=i?new r(u,t,"An error was suppressed during disposal"):(i=!0,u),n=u=>{for(;u=e.pop();)try{var s=u[1]&&u[1].call(u[2]);if(u[0])return Promise.resolve(s).then(n,l=>(o(l),n()))}catch(l){o(l)}if(i)throw t};return n()};import ke from"mri";function pe(e,t=process.argv.slice(2)){for(let[o,n]of t.entries())n==="-"&&(t[o]="__IO_DEFAULT_VALUE__");let i=ke(t);for(let o in i){let n=i[o];o!=="_"&&Array.isArray(n)&&(n=n[n.length-1]),n==="__IO_DEFAULT_VALUE__"&&(n="-"),i[o]=n}let r={_:i._};for(let[o,{type:n,alias:u,default:s=n==="boolean"?!1:null}]of Object.entries(e)){if(r[o]=s,u){let l=u.slice(1);i[l]!==void 0&&(r[o]=ue(i[l],n))}{let l=o.slice(2);i[l]!==void 0&&(r[o]=ue(i[l],n))}}return r}function ue(e,t){switch(t){case"string":return D(e);case"boolean":return O(e);case"number":return R(e);case"boolean | string":return O(e)??D(e);case"number | string":return R(e)??D(e);case"boolean | number":return O(e)??R(e);case"boolean | number | string":return O(e)??R(e)??D(e);default:throw new Error(`Unhandled type: ${t}`)}}function O(e){if(e===!0||e===!1)return e;if(e==="true")return!0;if(e==="false")return!1}function R(e){if(typeof e=="number")return e;{let t=Number(e);if(!Number.isNaN(t))return t}}function D(e){return`${e}`}import We from"@parcel/watcher";import{compile as Ee,env as Ue,Instrumentation as he,optimize as Pe,toSourceMap as P}from"@tailwindcss/node";import{clearRequireCache as Ie}from"@tailwindcss/node/require-cache";import{Scanner as Le}from"@tailwindcss/oxide";import{existsSync as je}from"fs";import Z from"fs/promises";import C from"path";var A=class{#e=new Set([]);queueMacrotask(t){let i=setTimeout(t,0);return this.add(()=>{clearTimeout(i)})}add(t){return this.#e.add(t),()=>{this.#e.delete(t),t()}}async dispose(){for(let t of this.#e)await t();this.#e.clear()}};import Re from"fs";import me from"path";import{stripVTControlCharacters as De}from"util";import w from"picocolors";import ce from"enhanced-resolve";import Me from"fs";import{createRequire as Be}from"module";var Oe=Be(import.meta.url).resolve;function fe(e){if(typeof globalThis.__tw_resolve=="function"){let t=globalThis.__tw_resolve(e);if(t)return t}return Oe(e)}var Xe=ce.ResolverFactory.createResolver({fileSystem:new ce.CachedInputFileSystem(Me,4e3),useSyncFileSystemCalls:!0,extensions:[".css"],mainFields:["style"],conditionNames:["style"]});function de(e){let t=typeof e=="number"?BigInt(e):e;return t<1000n?`${t}ns`:(t/=1000n,t<1000n?`${t}\xB5s`:(t/=1000n,t<1000n?`${t}ms`:(t/=1000n,t<60n?`${t}s`:(t/=60n,t<60n?`${t}m`:(t/=60n,t<24n?`${t}h`:(t/=24n,`${t}d`))))))}var z={indent:2};function N(){return`${w.italic(w.bold(w.blue("\u2248")))} tailwindcss ${w.blue(`v${ze()}`)}`}function F(e){return`${w.dim(w.blue("`"))}${w.blue(e)}${w.dim(w.blue("`"))}`}function W(e,t=process.cwd(),{preferAbsoluteIfShorter:i=!0}={}){let r=me.relative(t,e);return r.startsWith("..")||(r=`.${me.sep}${r}`),i&&r.length>e.length?e:r}function Q(e,t){let i=e.split(" "),r=[],o="",n=0;for(let u of i){let s=De(u).length;n+s+1>t&&(r.push(o),o="",n=0),o+=(n?" ":"")+u,n+=s+(n?1:0)}return n&&r.push(o),r}function E(e){let t=de(e);return e<=50*1e6?w.green(t):e<=300*1e6?w.blue(t):e<=1e3*1e6?w.yellow(t):w.red(t)}function k(e,t=0){return`${" ".repeat(t+z.indent)}${e}`}function x(e=""){process.stderr.write(`${e}
`)}function h(e=""){process.stdout.write(`${e}
`)}function ze(){if(typeof globalThis.__tw_version=="string")return globalThis.__tw_version;let{version:e}=JSON.parse(Re.readFileSync(fe("tailwindcss/package.json"),"utf-8"));return e}import U from"fs/promises";import Ne from"path";function Y(){return new Promise((e,t)=>{let i="";process.stdin.on("data",r=>{i+=r}),process.stdin.on("end",()=>e(i)),process.stdin.on("error",r=>t(r))})}async function H(e,t){if(!await U.stat(e).then(r=>r.isCharacterDevice()||r.isFIFO()).catch(()=>!1))try{if(await U.readFile(e,"utf8")===t)return}catch{}await U.mkdir(Ne.dirname(e),{recursive:!0}),await U.writeFile(e,t,"utf8")}var ye=String.raw,a=Ue.DEBUG;function I(){return{"--input":{type:"string",description:"Input file",alias:"-i"},"--output":{type:"string",description:"Output file",alias:"-o",default:"-"},"--watch":{type:"boolean | string",description:"Watch for changes and rebuild as needed, and use `always` to keep watching when stdin is closed",alias:"-w",values:["always"]},"--minify":{type:"boolean",description:"Optimize and minify the output",alias:"-m"},"--optimize":{type:"boolean",description:"Optimize the output without minifying"},"--cwd":{type:"string",description:"The current working directory",default:"."},"--map":{type:"boolean | string",description:"Generate a source map",default:!1}}}async function X(e){try{return await e()}catch(t){t instanceof Error&&x(t.toString()),process.exit(1)}}async function ge(e){var ie=[];try{x(N());x();let t=G(ie,new he);a&&t.start("[@tailwindcss/cli] (initial build)");let i=C.resolve(e["--cwd"]);e["--output"]&&e["--output"]!=="-"&&(e["--output"]=C.resolve(i,e["--output"]));e["--input"]&&e["--input"]!=="-"&&(e["--input"]=C.resolve(i,e["--input"]),je(e["--input"])||(x(`Specified input file ${F(W(e["--input"]))} does not exist.`),process.exit(1)));e["--input"]===e["--output"]&&e["--input"]!=="-"&&(x(`Specified input file ${F(W(e["--input"]))} and output file ${F(W(e["--output"]))} are identical.`),process.exit(1));e["--map"]==="-"&&(x("Use --map without a value to inline the source map"),process.exit(1));e["--map"]&&e["--map"]!==!0&&(e["--map"]=C.resolve(i,e["--map"]));let r=process.hrtime.bigint();let o=e["--input"]?e["--input"]==="-"?await Y():await Z.readFile(e["--input"],"utf-8"):ye`
@import 'tailwindcss';
`;let n={css:"",optimizedCss:""};async function u(g,b,f,S){let $=g;if(f["--minify"]||f["--optimize"])if(g!==n.css){a&&S.start("Optimize CSS");let T=Pe(g,{file:f["--input"]??"input.css",minify:f["--minify"]??!1,map:b?.raw??void 0});a&&S.end("Optimize CSS"),n.css=g,n.optimizedCss=T.code,T.map&&(b=P(T.map)),$=T.code}else $=n.optimizedCss;b&&(f["--map"]===!0?($+=`
`,$+=b.inline):typeof f["--map"]=="string"&&(a&&S.start("Write source map"),await H(f["--map"],b.raw),a&&S.end("Write source map"))),a&&S.start("Write output"),f["--output"]&&f["--output"]!=="-"?await H(f["--output"],$):h($),a&&S.end("Write output")}let s=e["--input"]&&e["--input"]!=="-"?C.resolve(e["--input"]):null;let l=s?C.dirname(s):process.cwd();let p=s?[s]:[];async function m(g,b){a&&b.start("Setup compiler");let f=await Ee(g,{from:e["--output"]?s??"stdin.css":void 0,base:l,onDependency(T){p.push(T)}}),S=(f.root==="none"?[]:f.root===null?[{base:i,pattern:"**/*",negated:!1}]:[{...f.root,negated:!1}]).concat(f.sources),$=new Le({sources:S});return a&&b.end("Setup compiler"),[f,$]}let[d,y]=await X(()=>m(o,t));if(e["--watch"]){let g=[];g.push(await we(be(y),async function b(f){try{var S=[];try{if(f.length===1&&f[0]===e["--output"])return;let c=G(S,new he);a&&c.start("[@tailwindcss/cli] (watcher)");let re=process.hrtime.bigint();let oe=[];let j="incremental";let se=p;for(let _ of f){if(se.includes(_)){j="full";break}oe.push({file:_,extension:C.extname(_).slice(1)})}let V="";let q=null;if(j==="full"){let _=e["--input"]?e["--input"]==="-"?await Y():await Z.readFile(e["--input"],"utf-8"):ye`
@import 'tailwindcss';
`;Ie(se),p=s?[s]:[],[d,y]=await m(_,c),a&&c.start("Scan for candidates");let K=y.scan();a&&c.end("Scan for candidates"),a&&c.start("Setup new watchers");let Fe=await we(be(y),b);a&&c.end("Setup new watchers"),a&&c.start("Cleanup old watchers"),await Promise.all(g.splice(0).map(Ae=>Ae())),a&&c.end("Cleanup old watchers"),g.push(Fe),a&&c.start("Build CSS"),V=d.build(K),a&&c.end("Build CSS"),e["--map"]&&(a&&c.start("Build Source Map"),q=P(d.buildSourceMap()),a&&c.end("Build Source Map"))}else if(j==="incremental"){a&&c.start("Scan for candidates");let _=y.scanFiles(oe);if(a&&c.end("Scan for candidates"),_.length<=0){let K=process.hrtime.bigint();x(`Done in ${E(K-re)}`);return}a&&c.start("Build CSS"),V=d.build(_),a&&c.end("Build CSS"),e["--map"]&&(a&&c.start("Build Source Map"),q=P(d.buildSourceMap()),a&&c.end("Build Source Map"))}await u(V,q,e,c);let Ce=process.hrtime.bigint();x(`Done in ${E(Ce-re)}`)}catch($){var T=$,ve=!0}finally{J(S,T,ve)}}catch(c){c instanceof Error&&x(c.toString())}})),e["--watch"]!=="always"&&process.stdin.on("end",()=>{Promise.all(g.map(b=>b())).then(()=>process.exit(0),()=>process.exit(1))}),process.stdin.resume()}a&&t.start("Scan for candidates");let L=y.scan();a&&t.end("Scan for candidates");a&&t.start("Build CSS");let M=await X(()=>d.build(L));a&&t.end("Build CSS");let B=null;e["--map"]&&(a&&t.start("Build Source Map"),B=await X(()=>P(d.buildSourceMap())),a&&t.end("Build Source Map"));await u(M,B,e,t);let xe=process.hrtime.bigint();x(`Done in ${E(xe-r)}`)}catch($e){var Te=$e,_e=!0}finally{J(ie,Te,_e)}}async function we(e,t){e=e.sort((s,l)=>s.length-l.length);let i=[];for(let s=0;s<e.length;++s)for(let l=0;l<s;++l)e[s].startsWith(`${e[l]}/`)&&i.push(e[s]);e=e.filter(s=>!i.includes(s));let r=new A,o=new Set,n=new A;async function u(){await n.dispose(),n.queueMacrotask(()=>{t(Array.from(o)),o.clear()})}for(let s of e){let{unsubscribe:l}=await We.subscribe(s,async(p,m)=>{if(p){console.error(p);return}await Promise.all(m.map(async d=>{if(d.type==="delete")return;let y=null;try{y=await Z.lstat(d.path)}catch{}!y?.isFile()&&!y?.isSymbolicLink()||o.add(d.path)})),await u()});r.add(l)}return async()=>{await r.dispose(),await n.dispose()}}function be(e){return[...new Set(e.normalizedSources.flatMap(t=>t.base))]}import v from"picocolors";function ee({invalid:e,usage:t,options:i}){let r=process.stdout.columns;if(h(N()),e&&(h(),h(`${v.dim("Invalid command:")} ${e}`)),t&&t.length>0){h(),h(v.dim("Usage:"));for(let[o,n]of t.entries()){let u=n.slice(0,n.indexOf("[")),s=n.slice(n.indexOf("["));s=s.replace(/\[.*?\]/g,m=>v.dim(m));let p=Q(s,r-z.indent-u.length-1);p.length>1&&o!==0&&h(),h(k(`${u}${p.shift()}`));for(let m of p)h(k(m,u.length))}}if(i){let o=0;for(let{alias:l}of Object.values(i))l&&(o=Math.max(o,l.length));let n=[],u=0;for(let[l,{alias:p,values:m}]of Object.entries(i)){m?.length&&(l+=`[=${m.join(", ")}]`);let d=[p&&`${p.padStart(o)}`,p?l:" ".repeat(o+2)+l].filter(Boolean).join(", ");n.push(d),u=Math.max(u,d.length)}h(),h(v.dim("Options:"));let s=8;for(let{description:l,default:p=null}of Object.values(i)){let m=n.shift(),d=s+(u-m.length),y=2,L=r-m.length-d-y-z.indent,M=Q(p!==null?`${l} ${v.dim(`[default:\u202F${F(`${p}`)}]`)}`:l,L);h(k(`${v.blue(m)} ${v.dim(v.gray("\xB7")).repeat(d)} ${M.shift()}`));for(let B of M)h(k(`${" ".repeat(m.length+d+y)}${B}`))}}}var te={"--help":{type:"boolean",description:"Display usage information",alias:"-h"}},ne=pe({...I(),...te}),Se=ne._[0];Se&&(ee({invalid:Se,usage:["tailwindcss [options]"],options:{...I(),...te}}),process.exit(1));(process.stdout.isTTY&&process.argv[2]===void 0||ne["--help"])&&(ee({usage:["tailwindcss [--input input.css] [--output output.css] [--watch] [options\u2026]"],options:{...I(),...te}}),process.exit(0));ge(ne);