svelte-prune 0.0.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +529 -2
- package/analysis-a7wbx6mr.js +1 -0
- package/index-34y0pc8q.js +2 -0
- package/index-4960rqxx.js +3 -0
- package/index-4992cggh.js +5 -0
- package/index-6g116bmb.js +2 -0
- package/index-gdmk0qve.js +2 -0
- package/index-n6hffmks.js +22 -0
- package/index-wkcyw7a9.js +9 -0
- package/index-xt8m9vw2.js +2 -0
- package/index-zq01wexv.js +2 -0
- package/index.d.ts +209 -0
- package/index.js +1 -0
- package/internal-analysis.d.ts +602 -0
- package/internal-analysis.js +1 -0
- package/internal.d.ts +451 -0
- package/internal.js +1 -0
- package/loader.js +1 -0
- package/package.json +53 -3
- package/tailwind-sources-w3ata1x1.js +1 -0
- package/variant-tables-tr82shep.js +1 -0
- package/vite.d.ts +119 -0
- package/vite.js +1 -0
- package/webpack.d.ts +195 -0
- package/webpack.js +1 -0
- package/index.ts +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{p}from"./index-4992cggh.js";var U=Array(2048).fill(void 0);function ue(){U.fill(void 0)}function We(e,t,r,n){let i=n&2047,s=U[i];if(s!==void 0&&s.length===r-t&&e.startsWith(s,t))return s;let o=e.slice(t,r);return U[i]=o,o}var R="",I=[0],P=0,N=0,D;function W(e){ue(),R=e,I=[0],P=0,N=0,D=void 0}function G(e){while(P<=e){let t=R.indexOf(`
|
|
2
|
+
`,P);if(t===-1){P=Number.POSITIVE_INFINITY;return}P=t+1,I.push(P)}}function Q(e){let t=[0],r=e.indexOf(`
|
|
3
|
+
`);while(r!==-1)t.push(r+1),r=e.indexOf(`
|
|
4
|
+
`,r+1);return t}function F(e,t,r){let n=0,i=e.length-1;if(t>=e[r])n=r;else i=r-1;if(n<i&&t<e[n+1])i=n;while(n<i){let s=n+i+1>>>1;if(e[s]<=t)n=s;else i=s-1}return n}function C(e){return G(e),N=F(I,e,N),{line:N+1,column:e-I[N],character:e}}var q=/\r\n?|\n|\u2028|\u2029/g,fe=/[\r\u2028\u2029]/;function je(e){if(D===void 0){D=fe.test(R)?[]:null,q.lastIndex=0;while(D!==null&&q.exec(R)!==null)D.push(q.lastIndex)}if(D===null)return G(e),F(I,e,N);let t=0,r=D.length;while(t<r){let n=t+r>>>1;if(D[n]<=e)t=n+1;else r=n}return t}function V(e){let{line:t,column:r}=C(e);return{line:t,column:r}}function ze(e){while(I.length<=e+1&&P!==Number.POSITIVE_INFINITY)G(P);if(e>=I.length)return;let t=e+1<I.length?I[e+1]-1:R.length;return R.slice(I[e],t)}function c(e){return typeof e==="object"&&e!==null&&typeof y(e).type==="string"}function y(e){return e}function ee(e,t){let r=y(e);for(let n in r){let i=r[n];if(Array.isArray(i)){for(let s=0;s<i.length;s++)if(c(i[s]))i[s]=t(i[s])}else if(c(i))r[n]=t(i)}}function Pe(e,...t){if(!t.some((r)=>r===e.type))throw Error(`expected ${t.join(" or ")}, got ${e.type}`)}function m(e){let t=[];return k(e,t),t}function k(e,t){switch(e.type){case"Identifier":t.push(e);return;case"ObjectPattern":for(let r of e.properties)k(r.type==="RestElement"?r.argument:r.value,t);return;case"ArrayPattern":for(let r of e.elements)if(r!==null)k(r,t);return;case"RestElement":k(e.argument,t);return;case"AssignmentPattern":k(e.left,t);return;case"TSParameterProperty":k(e.parameter,t);return;case"TSAsExpression":case"TSNonNullExpression":case"TSSatisfiesExpression":case"TSTypeAssertion":k(e.expression,t)}}function b(e,t){if(e.type!=="Identifier")return!1;if(t===null)return!0;switch(t.type){case"MemberExpression":return t.computed||e===t.object;case"MethodDefinition":return t.computed;case"Property":case"PropertyDefinition":return t.computed||e===t.value;case"ExportSpecifier":case"ImportSpecifier":return e===t.local;case"MetaProperty":case"ImportAttribute":case"ExportAllDeclaration":case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return!1;case"TSAsExpression":case"TSSatisfiesExpression":case"TSTypeAssertion":case"TSNonNullExpression":case"TSInstantiationExpression":case"TSExportAssignment":return e===t.expression;case"TSEnumMember":return e===t.initializer;case"TSParameterProperty":case"TSEnumDeclaration":case"TSImportEqualsDeclaration":return!0;default:return!t.type.startsWith("TS")}}var Te=64,K=new Map;function T(e,t){let r=K.get(e);if(r===void 0){if(K.size>=Te)K.delete(K.keys().next().value);r={starts:Q(e),last:0},K.set(e,r)}let n=F(r.starts,t,r.last);return r.last=n,{line:n+1,column:t-r.starts[n]}}function j(e){let t=e;while(t.type==="TSAsExpression"||t.type==="TSSatisfiesExpression"||t.type==="TSTypeAssertion"||t.type==="TSNonNullExpression"||t.type==="TSInstantiationExpression")t=t.expression;return t}var g={Root:["module","instance","fragment","css"],Script:["attributes","content"],Fragment:["nodes"],Text:[],Comment:[],ExpressionTag:["expression"],HtmlTag:["expression"],ConstTag:["declaration"],DeclarationTag:["declaration"],DebugTag:["identifiers"],RenderTag:["expression"],AttachTag:["expression"],Attribute:["value"],SpreadAttribute:["expression"],AnimateDirective:["expression"],BindDirective:["expression"],ClassDirective:["expression"],LetDirective:["expression"],OnDirective:["expression"],StyleDirective:["value"],TransitionDirective:["expression"],UseDirective:["expression"],Component:["attributes","fragment"],TitleElement:["attributes","fragment"],SlotElement:["attributes","fragment"],RegularElement:["attributes","fragment"],SvelteBody:["attributes","fragment"],SvelteBoundary:["attributes","fragment"],SvelteComponent:["expression","attributes","fragment"],SvelteDocument:["attributes","fragment"],SvelteElement:["tag","attributes","fragment"],SvelteFragment:["attributes","fragment"],SvelteHead:["attributes","fragment"],SvelteOptions:["attributes","fragment"],SvelteSelf:["attributes","fragment"],SvelteWindow:["attributes","fragment"],IfBlock:["test","consequent","alternate"],EachBlock:["expression","context","key","body","fallback"],AwaitBlock:["expression","pending","value","then","error","catch"],KeyBlock:["expression","fragment"],SnippetBlock:["expression","parameters","body"],StyleSheet:["attributes","children"],Rule:["prelude","block"],Atrule:["block"],SelectorList:["children"],ComplexSelector:["children"],RelativeSelector:["combinator","selectors"],Combinator:[],TypeSelector:[],IdSelector:[],ClassSelector:[],AttributeSelector:[],PseudoElementSelector:["args"],PseudoClassSelector:["args"],Percentage:[],Nth:[],NestingSelector:[],Block:["children"],Declaration:[],Program:["body"],ExpressionStatement:["expression"],BlockStatement:["body"],StaticBlock:["body"],EmptyStatement:[],DebuggerStatement:[],WithStatement:["object","body"],ReturnStatement:["argument"],LabeledStatement:["label","body"],BreakStatement:["label"],ContinueStatement:["label"],IfStatement:["test","consequent","alternate"],SwitchStatement:["discriminant","cases"],SwitchCase:["test","consequent"],ThrowStatement:["argument"],TryStatement:["block","handler","finalizer"],CatchClause:["param","body"],WhileStatement:["test","body"],DoWhileStatement:["body","test"],ForStatement:["init","test","update","body"],ForInStatement:["left","right","body"],ForOfStatement:["left","right","body"],FunctionDeclaration:["id","typeParameters","params","returnType","body"],FunctionExpression:["id","typeParameters","params","returnType","body"],ArrowFunctionExpression:["typeParameters","params","returnType","body"],VariableDeclaration:["declarations"],VariableDeclarator:["id","init"],ClassDeclaration:["decorators","id","typeParameters","superClass","superTypeParameters","implements","body"],ClassExpression:["decorators","id","typeParameters","superClass","superTypeParameters","implements","body"],ClassBody:["body"],MethodDefinition:["decorators","key","typeParameters","value"],PropertyDefinition:["decorators","key","typeAnnotation","value"],Property:["decorators","key","value"],ThisExpression:[],Super:[],Literal:[],Identifier:["decorators","typeAnnotation"],PrivateIdentifier:[],ArrayExpression:["elements"],ObjectExpression:["properties"],UnaryExpression:["argument"],UpdateExpression:["argument"],BinaryExpression:["left","right"],LogicalExpression:["left","right"],AssignmentExpression:["left","right"],MemberExpression:["object","property"],ConditionalExpression:["test","consequent","alternate"],CallExpression:["callee","typeArguments","arguments"],NewExpression:["callee","typeArguments","arguments"],SequenceExpression:["expressions"],TemplateLiteral:["quasis","expressions"],TaggedTemplateExpression:["tag","typeArguments","quasi"],TemplateElement:[],SpreadElement:["argument"],RestElement:["decorators","argument","typeAnnotation"],YieldExpression:["argument"],AwaitExpression:["argument"],ImportExpression:["source","options","arguments"],ChainExpression:["expression"],ParenthesizedExpression:["expression"],MetaProperty:["meta","property"],ObjectPattern:["decorators","properties","typeAnnotation"],ArrayPattern:["decorators","elements","typeAnnotation"],AssignmentPattern:["decorators","left","right"],ImportDeclaration:["specifiers","source","attributes"],ImportSpecifier:["imported","local"],ImportDefaultSpecifier:["local"],ImportNamespaceSpecifier:["local"],ImportAttribute:["key","value"],ExportNamedDeclaration:["declaration","specifiers","source","attributes"],ExportSpecifier:["local","exported"],ExportDefaultDeclaration:["declaration"],ExportAllDeclaration:["exported","source","attributes"],Decorator:["expression"],TSTypeAnnotation:["typeAnnotation"],TSTypeParameterDeclaration:["params"],TSTypeParameterInstantiation:["params"],TSTypeParameter:["constraint","default"],TSAnyKeyword:[],TSBigIntKeyword:[],TSBooleanKeyword:[],TSNeverKeyword:[],TSNullKeyword:[],TSNumberKeyword:[],TSObjectKeyword:[],TSStringKeyword:[],TSSymbolKeyword:[],TSUndefinedKeyword:[],TSUnknownKeyword:[],TSVoidKeyword:[],TSThisType:[],TSArrayType:["elementType"],TSTupleType:["elementTypes"],TSNamedTupleMember:["label","elementType"],TSOptionalType:["typeAnnotation"],TSRestType:["typeAnnotation"],TSUnionType:["types"],TSIntersectionType:["types"],TSConditionalType:["checkType","extendsType","trueType","falseType"],TSInferType:["typeParameter"],TSParenthesizedType:["typeAnnotation"],TSTypeOperator:["typeAnnotation"],TSIndexedAccessType:["objectType","indexType"],TSMappedType:["typeParameter","nameType","typeAnnotation"],TSLiteralType:["literal"],TSTypeReference:["typeName","typeArguments"],TSQualifiedName:["left","right"],TSTypeQuery:["exprName","typeArguments"],TSImportType:["argument","qualifier","typeArguments"],TSTypeLiteral:["members"],TSPropertySignature:["key","typeAnnotation"],TSMethodSignature:["key","typeParameters","parameters","typeAnnotation"],TSCallSignatureDeclaration:["typeParameters","parameters","typeAnnotation"],TSConstructSignatureDeclaration:["typeParameters","parameters","typeAnnotation"],TSFunctionType:["typeParameters","parameters","typeAnnotation"],TSConstructorType:["typeParameters","parameters","typeAnnotation"],TSIndexSignature:["decorators","parameters","typeAnnotation"],TSTypePredicate:["parameterName","typeAnnotation"],TSInterfaceDeclaration:["id","typeParameters","extends","body"],TSInterfaceBody:["body"],TSExpressionWithTypeArguments:["expression","typeParameters"],TSTypeAliasDeclaration:["id","typeParameters","typeAnnotation"],TSEnumDeclaration:["id","members"],TSEnumMember:["id","initializer"],TSModuleDeclaration:["id","body"],TSModuleBlock:["body"],TSImportEqualsDeclaration:["id","moduleReference"],TSExternalModuleReference:["expression"],TSExportAssignment:["expression"],TSNamespaceExportDeclaration:["id"],TSDeclareFunction:["id","typeParameters","params","returnType"],TSDeclareMethod:["typeParameters","params","returnType"],TSParameterProperty:["parameter"],TSAsExpression:["expression","typeAnnotation"],TSSatisfiesExpression:["expression","typeAnnotation"],TSTypeAssertion:["typeAnnotation","expression"],TSNonNullExpression:["expression"],TSInstantiationExpression:["expression","typeArguments"]};var a=[],v={...g,FunctionDeclaration:["id","params","body"],FunctionExpression:["id","params","body"],ArrowFunctionExpression:["params","body"],ClassDeclaration:["decorators","id","superClass","body"],ClassExpression:["decorators","id","superClass","body"],MethodDefinition:["decorators","key","value"],PropertyDefinition:["decorators","key","value"],Identifier:["decorators"],CallExpression:["callee","arguments"],NewExpression:["callee","arguments"],TaggedTemplateExpression:["tag","quasi"],RestElement:["decorators","argument"],ObjectPattern:["decorators","properties"],ArrayPattern:["decorators","elements"],TSTypeAnnotation:a,TSTypeParameterDeclaration:a,TSTypeParameterInstantiation:a,TSTypeParameter:a,TSArrayType:a,TSTupleType:a,TSNamedTupleMember:a,TSOptionalType:a,TSRestType:a,TSUnionType:a,TSIntersectionType:a,TSConditionalType:a,TSInferType:a,TSParenthesizedType:a,TSTypeOperator:a,TSIndexedAccessType:a,TSMappedType:a,TSLiteralType:a,TSTypeReference:a,TSTypeQuery:a,TSImportType:a,TSTypeLiteral:a,TSPropertySignature:a,TSMethodSignature:a,TSCallSignatureDeclaration:a,TSConstructSignatureDeclaration:a,TSFunctionType:a,TSConstructorType:a,TSIndexSignature:a,TSTypePredicate:a,TSInterfaceDeclaration:a,TSInterfaceBody:a,TSExpressionWithTypeArguments:a,TSTypeAliasDeclaration:a,TSNamespaceExportDeclaration:a,TSDeclareFunction:["id"],TSDeclareMethod:a,TSAsExpression:["expression"],TSSatisfiesExpression:["expression"],TSTypeAssertion:["expression"],TSInstantiationExpression:["expression"]},Se=Object.assign(Object.create(null),g),ge=Object.assign(Object.create(null),v),Z=[],X=Symbol("svelte-ast.walk.stop"),te=Symbol("svelte-ast.walk.skip");function f(e,t,r){_(e,null,null,null,t,he(r))}function he(e){if(e===void 0||e===g)return ne;if(e===v)return ie;return(t)=>re(e,t.type)}function re(e,t){return Object.hasOwn(e,t)?e[t]:void 0}function xe(e,t){if(e===void 0||e===g)return ne(t);if(e===v)return ie(t);return re(e,t.type)}function S(e,t,r){let n=xe(r,e);if(n===void 0)throw Error(`unknown node type: ${e.type}`);let i=y(e);for(let s=0;s<n.length;s++){let o=n[s],l=i[o];if(Array.isArray(l))for(let d=0;d<l.length;d++){let u=l[d];if(c(u))t(u,o,d)}else if(c(l))t(l,o,null)}}var be=Object.freeze([]),J=new WeakMap,Ee=new WeakMap;function Me(e,t=g){let r=t===g?Ee:J.get(t);if(r===void 0)r=new WeakMap,J.set(t,r);let n=r.get(e);if(n===void 0){let i=[];S(e,(s)=>i.push(s),t),n=i.length===0?be:i,r.set(e,n)}return n}function _(e,t,r,n,i,s){let o=s(e);if(o===void 0)throw Error(`unknown node type: ${e.type}`);let l=i.enter?.(e,t,r,n);if(l===X)return!0;if(l!==te){if(l!==e&&c(l))return ve(l,t,r,n,i,s);let d=y(e);for(let u=0;u<o.length;u++){let E=o[u],x=d[E];if(Array.isArray(x))for(let h=0;h<x.length;h++){let A=x[h];if(c(A)&&_(A,e,E,h,i,s))return!0}else if(c(x)&&_(x,e,E,null,i,s))return!0}}return i.leave?.(e,t,r,n)===X}function ne(e){let t=e.type;if(t==="Identifier")return e.typeAnnotation===void 0&&e.decorators===void 0?Z:g.Identifier;if(t==="Literal")return g.Literal;if(t==="Text")return g.Text;return Se[t]}function ie(e){let t=e.type;if(t==="Identifier")return e.decorators===void 0?Z:v.Identifier;if(t==="Literal")return v.Literal;if(t==="Text")return v.Text;return ge[t]}function ve(e,t,r,n,i,s){if(t===null||r===null)throw Error("walk can't replace the node it was called with");let o=y(t),l=o[r];if(n===null)o[r]=e;else if(Array.isArray(l))l[n]=e;return _(e,t,r,n,i,s)}import{readFileSync as Ae,statSync as Ie}from"node:fs";import O from"node:path";var we=/^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;function $e(e){return we.test(e)}var Ce=8;function De(e){let t=new Map;for(let r of p(Ae(e,"utf8"))){if(r.kind!=="export"||!r.source)continue;for(let{kind:n,local:i,exported:s}of r.specifiers)if(n==="named"&&s!==null&&$e(i)&&$e(s))t.set(s,{local:i,source:r.source.value})}return t}function de(e,t){let r=O.resolve(O.dirname(e),t);return[r,`${r}.js`,`${r}.svelte`,O.join(r,"index.js")].find((n)=>Ie(n,{throwIfNoEntry:!1})?.isFile()===!0)}function Re(e,t){return O.relative(e,t).split(O.sep).join("/")}function me(e,{name:t,srcDir:r,barrel:n}){let i=O.join(e,r),s=O.join(i,n),o=new Map,l=(u)=>{let E=o.get(u);if(!E)E=De(u),o.set(u,E);return E},d=new Map;for(let[u,E]of l(s)){let x=de(s,E.source),h=E.local;for(let A=0;x&&A<Ce;A++){if(h==="default"||!x.endsWith(".js"))break;let H=l(x).get(h);if(!H)break;let Y=de(x,H.source);if(!Y)break;x=Y,h=H.local}if(!x)continue;d.set(u,{path:`${t}/${r}/${Re(i,x)}`,name:h})}return d}function B(e,t,r){return{text:e.slice(t,r),runs:r>t?[[0,t,r-t]]:[]}}function M(...e){let t="",r=[];for(let n of e){if(typeof n==="string"){t+=n;continue}for(let[i,s,o]of n.runs)r.push([i+t.length,s,o]);t+=n.text}return{text:t,runs:r}}function z(e,t){if(t.length===0)return e;let r="",n=0,i=[];for(let o of t)i.push([n,o.start,r.length]),r+=e.text.slice(n,o.start)+(o.text??""),n=o.end;i.push([n,e.text.length,r.length]),r+=e.text.slice(n);let s=[];for(let[o,l,d]of e.runs)for(let[u,E,x]of i){let h=Math.max(o,u),A=Math.min(o+d,E);if(h<A)s.push([x+h-u,l+h-o,A-h])}return{text:r,runs:s}}function ye(e,t,r=0,n=e.text.length){let i=[];for(let s of e.text.slice(r,n).matchAll(t)){let o=r+s.index;i.push({start:o,end:o+s[0].length})}return z(e,i)}function Le(e,t,r){let n=new Oe,{text:i}=e,s=0,o=0;for(let[l,d,u]of e.runs){if(d<o)continue;if(l>s)n.replace(i.slice(s,l),t,o,d);else if(d>o)n.skip(t,o,d);n.copy(i.slice(l,l+u)),s=l+u,o=d+u}if(s<i.length)n.replace(i.slice(s),t,o,t.length);return{version:3,sources:[r],sourcesContent:[t],names:[],mappings:n.toString()}}var le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",se=44,oe=59,w=65,pe=new Uint8Array(16);for(let e=0;e<16;e++)pe[e]=le.charCodeAt(e<<1);var ce=new Uint8Array(128);for(let e=0;e<128;e++)ce[e]=e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95?1:0;var ke=new TextDecoder("latin1"),Ne=1048576,ae=new Uint8Array(4096);class Oe{buffer=ae;length=0;line=0;column=0;genColumn=0;lineHasSegments=!1;prevGenColumn=0;prevLine=0;prevColumn=0;copy(e){let t=e.length;if(t===0)return;this.reserve(t*5+64);let r=this.buffer,n=this.length,i=this.column,s=this.genColumn-i,o=this.prevColumn,l=!1,d=!1;for(let u=0;u<t;u++){let E=e.charCodeAt(u);if(E===10){r[n++]=oe,this.line++,i=0,s=0,this.prevGenColumn=0,this.lineHasSegments=!1,l=!1,d=!1;continue}let x=E<128&&ce[E]===1;if(!x||!l)if(d){let h=i-o;if(r[n++]=se,h<16){let A=pe[h];r[n++]=A,r[n++]=w,r[n++]=w,r[n++]=A}else n=L(r,n,h),r[n++]=w,r[n++]=w,n=L(r,n,h);o=i}else this.length=n,this.column=i,this.genColumn=i+s,this.prevColumn=o,this.addSegment(),n=this.length,o=i,d=!0;l=x,i++}if(this.length=n,this.column=i,this.genColumn=i+s,this.prevColumn=o,d)this.prevGenColumn=o+s}replace(e,t,r,n){this.addSegment();let i=0,s=e.indexOf(`
|
|
5
|
+
`);while(s!==-1){i=s+1,this.reserve(5);let o=this.buffer;if(o[this.length++]=oe,i<e.length)o[this.length++]=w,o[this.length++]=w,o[this.length++]=w,o[this.length++]=w;s=e.indexOf(`
|
|
6
|
+
`,i)}if(i===0)this.genColumn+=e.length;else this.genColumn=e.length-i,this.prevGenColumn=0,this.lineHasSegments=i<e.length;this.skip(t,r,n)}skip(e,t,r){let n=-1,i=e.indexOf(`
|
|
7
|
+
`,t);while(i!==-1&&i<r)this.line++,n=i,i=e.indexOf(`
|
|
8
|
+
`,i+1);this.column=n===-1?this.column+(r-t):r-n-1}addSegment(){let{genColumn:e,line:t,column:r}=this;this.reserve(25);let n=this.buffer,i=this.length;if(this.lineHasSegments)n[i++]=se;i=L(n,i,e-this.prevGenColumn),n[i++]=w,i=L(n,i,t-this.prevLine),i=L(n,i,r-this.prevColumn),this.length=i,this.lineHasSegments=!0,this.prevGenColumn=e,this.prevLine=t,this.prevColumn=r}reserve(e){let t=this.length+e;if(t<=this.buffer.length)return;let r=this.buffer.length*2;while(r<t)r*=2;let n=new Uint8Array(r);if(n.set(this.buffer.subarray(0,this.length)),this.buffer=n,r<=Ne)ae=n}toString(){return ke.decode(this.buffer.subarray(0,this.length))}}function L(e,t,r){let n=r<0?-r<<1|1:r<<1;do{let i=n&31;if(n>>>=5,n>0)i|=32;e[t++]=le.charCodeAt(i)}while(n>0);return t}
|
|
9
|
+
export{We,W,C,je,V,ze,c,y,ee,Pe,m,b,T,j,g,v,te,f,S,Me,$e,de,Re,me,B,M,z,ye,Le,Oe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Symbol.for("svelte-prune.optimizers");function D(){let e=globalThis;return e[o]??=new Map,e[o]}function Ne(e,r){let t=D().get(this.getOptions().id);if(t?.rewritable(this.resourcePath))for(let n of t.analyzed)this.addDependency(n);let i=t?.load(this.resourcePath+this.resourceQuery);if(i)this.callback(null,i.code,i.map);else this.callback(null,e,r)}
|
|
2
|
+
export{D,Ne};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{p,F,o,w,ue,u,N,G,k}from"./index-4992cggh.js";import{createHash as _}from"node:crypto";import{existsSync as K,globSync as C,readFileSync as B}from"node:fs";import x from"node:path";function Te(n,l,b){if(!l.includes(n.name))return!1;let{patterns:h}=u(n),d=!1,S=(m,t)=>{let v=h.directComponentName.exec(m);if(v)b.add(v[1]);else if(m===n.name)for(let L of t())if(L==="*")d=!0;else b.add(L)};for(let m of p(l)){let t=m.source?.value;if(!t||m.typeOnly)continue;S(t,()=>m.kind==="export"?m.specifiers.flatMap((v)=>v.typeOnly?[]:[v.local]):m.specifiers.flatMap((v)=>v.typeOnly||v.kind==="default"?[]:[v.imported]))}for(let m of l.matchAll(h.dynamicImport))if(m[2].includes("${"))d=!0;else S(m[2],()=>["*"]);return d}var D=["src/**/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"],U=/[\\/]/,E=/^\0/,W=/\.(svelte|[cm]?[jt]sx?)$/,V=/\b(?:from|import)\s*["']([^"'./][^"']*\.svelte)["']/g,O=(n,l)=>n.tailwind===!0&&G("tailwindcss",l)!==void 0;async function H(n,l,b){if(!O(n,l))return;let{writeLibraryForTailwind:h}=await import("./analysis-a7wbx6mr.js");return h(n,l,void 0,b.failure)}var q=(n)=>n.split(U).includes("node_modules"),j=(n,l)=>n.startsWith("\x00")||!x.isAbsolute(l);function J(n,l){let b=n.filter((d)=>d.includes("node_modules")),h=n.filter((d)=>!b.includes(d));return[...new Set([...h.length>0?C(h,{cwd:l,exclude:q}):[],...b.length>0?C(b,{cwd:l}):[]])]}function Q(n,l,b,h){if(!b.includes(n.name))return!1;if(!h&&!W.test(l))return n.patterns.importText.test(b);let d=new Set;return Te(n.spec,b,d)||d.size>0}async function Z(n,l,b){let h=new Map(l.map(({file:m})=>[w(m)??m,m])),d=new Map,S=[];for(let{file:m,code:t}of l){if(!t.includes(".svelte"))continue;for(let[,v]of t.matchAll(V)){if(n.isComponentFile(v))continue;S.push(b(v,m).then((L)=>{if(!L)return;let R=o(L),z=h.get(w(R)??R);if(z)d.set(ue(m,v),z)},()=>{}))}}return await Promise.all(S),d}var X={plugin:"svelte-prune",failure:{feature:"svelte-prune",fallback:"components were bundled unchanged"}};function M(n){return{root:n,sources:new Map,analyzed:new Set,missed:new Set,virtual:new Set,closed:new Set,escaped:new Map,unread:new Map,scriptImporters:new Map,readImport:()=>!0,realpaths:new Map,pruneStyles:void 0}}function Y(n,l,b){let h=b.plugin,{label:d}=n,S=u(n),m=l?.content??D,t=M(process.cwd()),v,L,R=(e)=>{if(!t.realpaths.has(e))t.realpaths.set(e,w(e));return t.realpaths.get(e)},z=(e)=>R(e)??e,T=(e)=>t.analyzed.has(z(o(e))),A=(e)=>{let i=R(e);return i?x.relative(z(t.root),i):x.relative(t.root,e)};return{async prepare(e,i){t=M(e);let a=[],s=_("sha1");for(let g of J(m,e)){let y=x.resolve(e,g),I;try{I=B(y,"utf8")}catch{continue}a.push({file:y,code:I}),s.update(`${y}\x00${I}\x00`),t.analyzed.add(z(y))}let c=i?await Z(S,a,i):void 0;for(let[g,y]of c??[])s.update(`${g}\x00${y}\x00`);let f=s.digest("hex");if(v?.hash!==f){let{specializeFiles:g}=await import("./analysis-a7wbx6mr.js");v={hash:f,result:await g({library:n,projectRoot:e,files:a,resolvedImports:c,failure:b.failure,options:{unwrap:l?.unwrap??(G("svelte",e)??0)>=5},safelist:l?.safelist})}}let{result:r}=v;if(O(n,e)){let g=x.join(e,"node_modules",".svelte-prune",n.name),y;try{let I=N(n.name,e);y=`${g}\x00${await k(I,n.srcDir)}`}catch{}if(L?.result!==r||y===void 0||L.key!==y||!K(g)){L=void 0;let{writeLibraryForTailwind:I}=await import("./analysis-a7wbx6mr.js"),P=await I(n,e,"warning"in r?void 0:r,b.failure);if(P)return{warning:P};if(y!==void 0)L={result:r,key:y}}}if("warning"in r)return{warning:r.warning};return t.pruneStyles=r.pruneStyles,t.sources=r.sources,t.readImport=r.readImport,t.closed=new Set([...r.closed].map(z)),{info:l?.silent?void 0:`rewrote ${r.sources.size-r.apps-r.tables.modules} ${d} components${r.apps>0?` and ${r.apps} of the app's own`:""}${r.tables.modules>0?` and ${r.tables.pruned+r.tables.emptied} tailwind-variants tables`:""} for this app (${r.edits} edits)`,report:l?.report?r.report():void 0}},get analyzed(){return t.analyzed},pruneStyles(e){let i=t.pruneStyles;if(!i)return;let a=0,s=0,c=0,f=0;for(let[y,I]of e){let P=i(I);a+=P.rules,s+=P.declarations,c+=I.length,f+=P.css.length,e.set(y,P.css)}if(a+s===0||l?.silent)return;let r=(y)=>`${(y/1000).toFixed(2)} kB`,g=s>0?` and ${s} custom properties`:"";return`removed ${a} unused ${d} CSS rules${g} (${r(c)} -> ${r(f)})`},rewritable(e){let i=o(e);if(i.endsWith(".js"))return S.moduleKey(i)!==void 0;return i.endsWith(".svelte")&&(S.isComponentFile(i)||T(i))},load(e){if(t.sources.size===0)return;let[i,a=""]=e.split("?");if(a.includes("svelte"))return;return t.sources.get(z(i))},check(e,i){if(t.sources.size===0)return;let a=o(e);if(S.isComponentFile(a)||F.test(a))return;if(T(a))return;let s=j(e,a);if(!Q(S,a,i,s))return;if(s)t.virtual.add(e.replace(E,""));else t.missed.add(A(a))},checkScriptImporters(e,i){let a=o(e);if(!a.endsWith(".js")||!t.sources.has(z(a)))return;for(let s of i){if(s!==void 0&&S.moduleKey(o(s)))continue;let c=A(a),f=t.scriptImporters.get(c)??new Set;f.add(s===void 0?"the bundler":x.isAbsolute(o(s))?A(o(s)):s),t.scriptImporters.set(c,f)}},isClosed(e){if(t.closed.size===0||e.includes("?"))return!1;return t.closed.has(z(e))},checkImporters(e,i,a){let s=new Set;for(let c of i)if(c===void 0)s.add("the bundler");else if(!T(c)){let f=o(c);s.add(x.isAbsolute(f)?A(f):c)}if(a)s.add("a dynamic import");if(s.size>0)t.escaped.set(A(e),[...s])},checkLibraryImport(e){if(t.sources.size===0)return;let{id:i,importer:a,specifier:s}=e,c=o(a);if(!S.importKey(i)||S.moduleKey(c))return;if(j(a,c)){t.virtual.add(a.replace(E,""));return}let f=z(c);if(!t.analyzed.has(f)){t.missed.add(A(c));return}let r=z(o(i)),g=s!==void 0&&!S.isSpecifier(s);if(!g&&t.readImport(f,r))return;let y=A(c),I=t.unread.get(y)??new Set;I.add(g?`\`${s}\``:S.importKey(r)===S.barrelKey?`\`${n.name}\``:`${d}'s ${x.basename(r,x.extname(r))}`),t.unread.set(y,I)},error(){let{escaped:e,missed:i,scriptImporters:a,unread:s,virtual:c}=t,f=[];for(let[r,g]of e)f.push(`${h} read the props of ${r} from its call sites in \`content\`, but ${g.join(", ")} also ${g.length===1?"renders":"render"} it. Add those files to \`content\`.`);if(i.size>0)f.push(`${h} rewrote ${d} components before seeing ${[...i].join(", ")}, which ${i.size===1?"imports":"import"} them. Add those files to \`content\` (now ${JSON.stringify(m)}); only a pattern that names \`node_modules\` reaches inside it.`);for(let[r,g]of s)f.push(`${h} can't read how ${r} imports ${[...g].join(", ")}, so it rewrote ${d} without that file's call sites. Import ${d} from \`${n.name}\` there, not through an alias, or remove ${h}.`);for(let[r,g]of a)f.push(`${h} rewrote the tailwind-variants tables in ${r} for the ${d} components that call them, but ${[...g].join(", ")} ${g.size===1?"imports":"import"} it directly. Import them from \`${n.name}\` instead, or remove ${h}.`);if(c.size>0)f.push(`${h} can't analyze ${[...c].join(", ")}, which ${c.size===1?`imports ${d} components but has`:`import ${d} components but have`} no file on disk. Import them from a file in \`content\` instead, or remove ${h}.`);return f.length>0?`${S.logPrefix} ${f.join(" ")}`:void 0}}}
|
|
2
|
+
export{Te,H,X,Y};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/** For a failed analysis's warning: the feature it turns off, and what happens instead. */
|
|
2
|
+
export type Failure = {
|
|
3
|
+
feature: string;
|
|
4
|
+
fallback: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type RewrittenSource = {
|
|
8
|
+
code: string;
|
|
9
|
+
map: SourceMap;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Library components rewritten for an app, by real path of their source. */
|
|
13
|
+
export type SpecializedComponents = {
|
|
14
|
+
sources: Map<string, RewrittenSource>;
|
|
15
|
+
edits: number;
|
|
16
|
+
/** App components whose props came from their analyzed call sites: nothing else may render them. */
|
|
17
|
+
closed: Set<string>;
|
|
18
|
+
/** How many of the app's own components `sources` holds. */
|
|
19
|
+
apps: number;
|
|
20
|
+
/** Module keys of the library components that can render. */
|
|
21
|
+
renderable: ReadonlySet<string>;
|
|
22
|
+
/** tailwind-variants tables rewritten (`sources` holds their modules). */
|
|
23
|
+
tables: Pick<RewrittenTables, "pruned" | "emptied" | "keys" | "compounds"> & {
|
|
24
|
+
modules: number;
|
|
25
|
+
};
|
|
26
|
+
report: () => string[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether the analysis read `importer`'s import of library module `id` (real
|
|
29
|
+
* paths): `false` for one it can't see (an alias), `true` for a module whose
|
|
30
|
+
* imports it doesn't read (a script, a stylesheet).
|
|
31
|
+
*/
|
|
32
|
+
readImport: (importer: string, id: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* With `styles` in the `LibrarySpec`: removes the rules of `css` that need
|
|
35
|
+
* a class the library's stylesheets define and nothing can render.
|
|
36
|
+
*/
|
|
37
|
+
pruneStyles?: StylePruner;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Rewrites each library component `files` render, and each app component whose every call site they hold. */
|
|
41
|
+
export declare function specializeFiles(input: {
|
|
42
|
+
library: LibrarySpec;
|
|
43
|
+
projectRoot: string;
|
|
44
|
+
files: Array<{
|
|
45
|
+
file: string;
|
|
46
|
+
code: string;
|
|
47
|
+
}>;
|
|
48
|
+
options?: SpecializeOptions;
|
|
49
|
+
/** Aliased `.svelte` imports the bundler resolved, by `importKey`. */
|
|
50
|
+
resolvedImports?: ReadonlyMap<string, string>;
|
|
51
|
+
failure: Failure;
|
|
52
|
+
/** Classes `pruneStyles` keeps whatever renders: ones the app builds from data. */
|
|
53
|
+
safelist?: readonly SafelistEntry[];
|
|
54
|
+
}): Promise<SpecializedComponents | {
|
|
55
|
+
warning: string;
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
type ClassTokens = {
|
|
59
|
+
/** Text that may name a class contains it (`"x--"`). */
|
|
60
|
+
marker: string;
|
|
61
|
+
text(text: string): string[];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type LibraryClassTokens = ClassTokens & {
|
|
65
|
+
script(code: string, into: Set<string>): void;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** A Svelte component library svelte-prune reads and rewrites. */
|
|
69
|
+
export type LibrarySpec = {
|
|
70
|
+
/** The package apps import: `"my-library"`. */
|
|
71
|
+
name: string;
|
|
72
|
+
/** The directory of its modules in the package: `"src"`. */
|
|
73
|
+
srcDir: string;
|
|
74
|
+
/** Its barrel, in `srcDir`: `"index.js"`. */
|
|
75
|
+
barrel: string;
|
|
76
|
+
/** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
|
|
77
|
+
componentPackages: readonly string[];
|
|
78
|
+
/** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
|
|
79
|
+
contextKeyPrefix: string;
|
|
80
|
+
/** Names the library in messages: `"My Library"`. */
|
|
81
|
+
label: string;
|
|
82
|
+
/** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
|
|
83
|
+
tool: string;
|
|
84
|
+
/**
|
|
85
|
+
* Reads class names, for pruning the library's styles: `text` a string
|
|
86
|
+
* containing `marker`, `script` a whole script module. Omit to read none,
|
|
87
|
+
* or, with `styles`, every run of word characters and hyphens.
|
|
88
|
+
*/
|
|
89
|
+
classTokens?: LibraryClassTokens;
|
|
90
|
+
/**
|
|
91
|
+
* The library's stylesheets. A production build drops the rules in the
|
|
92
|
+
* CSS it emits that need a class these stylesheets define and that
|
|
93
|
+
* nothing can render: no live component, none of the library's script
|
|
94
|
+
* modules, nothing in `content`. Omit to leave CSS as it is.
|
|
95
|
+
*/
|
|
96
|
+
styles?: {
|
|
97
|
+
/**
|
|
98
|
+
* Files in installed packages, each `"<package>/<path>"`, where `*`
|
|
99
|
+
* matches within a path segment: `"my-library/css/*.css"`.
|
|
100
|
+
*/
|
|
101
|
+
stylesheets: readonly string[];
|
|
102
|
+
/** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
|
|
103
|
+
keep?: readonly string[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* `true` for a library whose classes are Tailwind's: its tailwind-variants
|
|
107
|
+
* tables are rewritten, and with Tailwind installed, every build (the dev
|
|
108
|
+
* server's included) writes what of it can render to
|
|
109
|
+
* `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
|
|
110
|
+
*/
|
|
111
|
+
tailwind?: boolean;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
type Run = readonly [number, number, number];
|
|
115
|
+
|
|
116
|
+
type MappedText = {
|
|
117
|
+
text: string;
|
|
118
|
+
runs: Run[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
type SourceMap = {
|
|
122
|
+
version: 3;
|
|
123
|
+
sources: string[];
|
|
124
|
+
sourcesContent: string[];
|
|
125
|
+
names: string[];
|
|
126
|
+
mappings: string;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type SpecializeOptions = {
|
|
130
|
+
/**
|
|
131
|
+
* Replaces an `{#if}` that renders nothing between whitespace (removing it
|
|
132
|
+
* would merge the two). Not empty: Svelte 3/4 warn; not text: Svelte 5
|
|
133
|
+
* rejects text in elements like `<colgroup>`.
|
|
134
|
+
*/
|
|
135
|
+
emptyBlock?: string;
|
|
136
|
+
/** Remove top-level declarations nothing reads after the edits. */
|
|
137
|
+
dropUnused?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Replace an `{#if}` whose only live branch is known with that branch's
|
|
140
|
+
* content. Only Svelte 5 renders it identically: block boundaries decide
|
|
141
|
+
* how Svelte 3/4 trim whitespace.
|
|
142
|
+
*/
|
|
143
|
+
unwrap?: boolean;
|
|
144
|
+
/** Debugging: apply only the top-level edits this accepts (by index). */
|
|
145
|
+
editFilter?: (index: number, edit: {
|
|
146
|
+
start: number;
|
|
147
|
+
end: number;
|
|
148
|
+
}) => boolean;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
type PrunedStyles = {
|
|
152
|
+
css: string;
|
|
153
|
+
/** Rules removed whole, `@keyframes` included. */
|
|
154
|
+
rules: number;
|
|
155
|
+
/** Selectors removed from rules that stay. */
|
|
156
|
+
selectors: number;
|
|
157
|
+
/** Custom property declarations removed. */
|
|
158
|
+
declarations: number;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
type StylePruner = (css: string) => PrunedStyles;
|
|
162
|
+
|
|
163
|
+
type SafelistEntry = string | RegExp;
|
|
164
|
+
|
|
165
|
+
type RewrittenTables = {
|
|
166
|
+
/** Rewritten modules by key, with the source they were rewritten from. */
|
|
167
|
+
modules: Map<string, {
|
|
168
|
+
mapped: MappedText;
|
|
169
|
+
source: string;
|
|
170
|
+
}>;
|
|
171
|
+
pruned: number;
|
|
172
|
+
emptied: number;
|
|
173
|
+
keys: number;
|
|
174
|
+
compounds: number;
|
|
175
|
+
/** Tables a live component calls that keep every class, and why. */
|
|
176
|
+
kept: Map<string, string>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type SveltePruneOptions = {
|
|
180
|
+
/**
|
|
181
|
+
* Globs (relative to the project root) of every file that renders the
|
|
182
|
+
* library's components; a module outside them that imports one fails the
|
|
183
|
+
* build. Components imported from script, Markdown, MDX or Astro files
|
|
184
|
+
* keep every prop value. `node_modules` is skipped unless a pattern names it.
|
|
185
|
+
* @default ["src/**\/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]
|
|
186
|
+
*/
|
|
187
|
+
content?: string[];
|
|
188
|
+
/**
|
|
189
|
+
* Replace an `{#if}` whose only live branch is known with that branch.
|
|
190
|
+
* Svelte 5 only: Svelte 3/4 render whitespace differently without the block.
|
|
191
|
+
* @default true when the installed Svelte is 5 or later
|
|
192
|
+
*/
|
|
193
|
+
unwrap?: boolean;
|
|
194
|
+
/** Skip the per-build summary. @default false */
|
|
195
|
+
silent?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Print what each build rewrote: edits, child components no longer rendered
|
|
198
|
+
* or bundled, and each call site's prop values. Independent of `silent`.
|
|
199
|
+
* @default false
|
|
200
|
+
*/
|
|
201
|
+
report?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Selectors of the library's stylesheets (`styles` in the `LibrarySpec`)
|
|
204
|
+
* to keep whatever renders, for classes the app builds from data at
|
|
205
|
+
* runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every
|
|
206
|
+
* selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`).
|
|
207
|
+
*/
|
|
208
|
+
safelist?: Array<string | RegExp>;
|
|
209
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{he}from"./index-n6hffmks.js";export{he as specializeFiles};
|