@visulima/packem-rollup 1.0.0-alpha.3 → 1.0.0-alpha.31

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.
Files changed (146) hide show
  1. package/CHANGELOG.md +278 -0
  2. package/LICENSE.md +200 -591
  3. package/README.md +89 -2
  4. package/dist/index.d.ts +24 -56
  5. package/dist/index.js +1 -0
  6. package/dist/packem_shared/cachingPlugin-CLawAGhx.js +1 -0
  7. package/dist/packem_shared/createSplitChunks-Ceq_Ca5Y.js +1 -0
  8. package/dist/packem_shared/esbuildPlugin-pPPsJB9N.js +1 -0
  9. package/dist/packem_shared/{fix-dts-default-cjs-exports-BQc0nwIG.mjs → fix-dts-default-cjs-exports-EvsobpME.js} +3 -3
  10. package/dist/packem_shared/index-QEzU3Fey.js +1 -0
  11. package/dist/packem_shared/{metafilePlugin-ObS4J7mO.mjs → metafilePlugin-CVcqFpPJ.js} +1 -1
  12. package/dist/packem_shared/oxcResolvePlugin-Ccef6pyL.js +1 -0
  13. package/dist/packem_shared/patchTypescriptTypes-CZ4v3hr9.js +6 -0
  14. package/dist/packem_shared/resolveTsconfigPathsPlugin-CEasmDpi.js +1 -0
  15. package/dist/packem_shared/{resolveTsconfigRootDirectoriesPlugin-_93afm2q.mjs → resolveTsconfigRootDirectoriesPlugin-Cwj3tqCJ.js} +1 -1
  16. package/dist/plugins/babel/index.d.ts +10 -0
  17. package/dist/plugins/babel/index.js +1 -0
  18. package/dist/plugins/cache-plugin.d.ts +11 -0
  19. package/dist/plugins/chunk-splitter/gather.d.ts +8 -0
  20. package/dist/plugins/chunk-splitter/index.d.ts +6 -0
  21. package/dist/plugins/chunk-splitter/parse/index.d.ts +4 -0
  22. package/dist/plugins/chunk-splitter/parse/types.d.ts +24 -0
  23. package/dist/plugins/cjs-interop.d.ts +7 -0
  24. package/dist/{packem_shared/cjsInteropPlugin-D5wyoQ_B.mjs → plugins/cjs-interop.js} +1 -1
  25. package/dist/plugins/copy.d.ts +23 -0
  26. package/dist/plugins/copy.js +1 -0
  27. package/dist/plugins/data-uri.d.ts +25 -0
  28. package/dist/plugins/data-uri.js +1 -0
  29. package/dist/plugins/debarrel.d.ts +7 -0
  30. package/dist/plugins/debarrel.js +2 -0
  31. package/dist/{packem_shared/browserslist-to-esbuild-DY9HwYtp.d.mts → plugins/esbuild/browserslist-to-esbuild.d.ts} +1 -2
  32. package/dist/plugins/esbuild/esbuild-plugin.d.ts +3 -0
  33. package/dist/plugins/esbuild/index.d.ts +3 -25
  34. package/dist/plugins/esbuild/index.js +1 -0
  35. package/dist/plugins/esbuild/types.d.ts +39 -0
  36. package/dist/plugins/esbuild/utils/get-render-chunk.d.ts +14 -0
  37. package/dist/plugins/esbuild/utils/optimize-deps.d.ts +3 -0
  38. package/dist/plugins/esbuild/utils/warn.d.ts +4 -0
  39. package/dist/plugins/esm-shim-cjs-syntax.d.ts +9 -0
  40. package/dist/plugins/fix-dts-default-cjs-exports.d.ts +26 -0
  41. package/dist/plugins/fix-dts-default-cjs-exports.js +1 -0
  42. package/dist/plugins/fix-dynamic-import-extension.d.ts +3 -0
  43. package/dist/plugins/isolated-declarations/index.d.ts +8 -0
  44. package/dist/plugins/isolated-declarations/index.js +3 -0
  45. package/dist/plugins/isolated-declarations/utils/extend-string.d.ts +2 -0
  46. package/dist/plugins/isolated-declarations/utils/fix-dts-default-cjs-exports.d.ts +35 -0
  47. package/dist/plugins/isolated-declarations/utils/lowest-common-ancestor.d.ts +2 -0
  48. package/dist/plugins/isolated-declarations/utils/split-tsconfig-path-key.d.ts +2 -0
  49. package/dist/plugins/json.d.ts +4 -0
  50. package/dist/plugins/json.js +1 -0
  51. package/dist/plugins/jsx-remove-attributes.d.ts +7 -0
  52. package/dist/plugins/jsx-remove-attributes.js +1 -0
  53. package/dist/plugins/license.d.ts +17 -0
  54. package/dist/plugins/license.js +13 -0
  55. package/dist/plugins/metafile.d.ts +3 -0
  56. package/dist/plugins/minify-html-literals/index.d.ts +41 -0
  57. package/dist/plugins/minify-html-literals/index.js +3 -0
  58. package/dist/plugins/minify-html-literals/lib/minify-html-literals.d.ts +200 -0
  59. package/dist/plugins/minify-html-literals/lib/models.d.ts +25 -0
  60. package/dist/plugins/minify-html-literals/lib/parse-literals.d.ts +13 -0
  61. package/dist/plugins/minify-html-literals/lib/strategy.d.ts +69 -0
  62. package/dist/plugins/minify-html-literals/lib/typescript.d.ts +23 -0
  63. package/dist/plugins/native-modules-plugin.d.ts +14 -0
  64. package/dist/plugins/native-modules-plugin.js +1 -0
  65. package/dist/plugins/oxc/index.d.ts +4 -28
  66. package/dist/plugins/oxc/index.js +1 -0
  67. package/dist/plugins/oxc/isolated-declarations-oxc-transformer.d.ts +4 -0
  68. package/dist/plugins/oxc/oxc-resolve-plugin.d.ts +4 -0
  69. package/dist/plugins/oxc/oxc-transformer-plugin.d.ts +3 -0
  70. package/dist/plugins/oxc/types.d.ts +16 -0
  71. package/dist/plugins/preserve-directives.d.ts +16 -0
  72. package/dist/{packem_shared/preserveDirectivesPlugin-B49Cbykd.mjs → plugins/preserve-directives.js} +3 -3
  73. package/dist/plugins/raw.d.ts +7 -0
  74. package/dist/plugins/raw.js +6 -0
  75. package/dist/plugins/require-cjs-transformer.d.ts +43 -0
  76. package/dist/plugins/require-cjs-transformer.js +21 -0
  77. package/dist/plugins/resolve-file-url.d.ts +3 -0
  78. package/dist/plugins/shebang.d.ts +9 -0
  79. package/dist/plugins/source-maps.d.ts +7 -0
  80. package/dist/plugins/sucrase/index.d.ts +8 -19
  81. package/dist/plugins/swc/index.d.ts +3 -26
  82. package/dist/plugins/swc/index.js +1 -0
  83. package/dist/plugins/swc/isolated-declarations-swc-transformer.d.ts +3 -0
  84. package/dist/plugins/swc/swc-plugin.d.ts +3 -0
  85. package/dist/plugins/swc/types.d.ts +6 -0
  86. package/dist/plugins/typescript/index.d.ts +8 -29
  87. package/dist/plugins/typescript/index.js +1 -0
  88. package/dist/plugins/typescript/isolated-declarations-typescript-transformer.d.ts +4 -0
  89. package/dist/plugins/typescript/patch-typescript-types.d.ts +13 -0
  90. package/dist/plugins/typescript/resolve-tsconfig-paths-plugin.d.ts +11 -0
  91. package/dist/plugins/typescript/resolve-tsconfig-root-dirs.d.ts +24 -0
  92. package/dist/plugins/typescript/resolve-typescript-mjs-cjs.d.ts +10 -0
  93. package/dist/plugins/url.d.ts +72 -0
  94. package/dist/plugins/url.js +1 -0
  95. package/dist/types.d.ts +135 -0
  96. package/dist/utils/chunks/create-split-chunks.d.ts +11 -0
  97. package/dist/utils/chunks/get-custom-module-layer.d.ts +2 -0
  98. package/dist/utils/chunks/get-module-layer.d.ts +10 -0
  99. package/dist/utils/index.d.ts +4 -0
  100. package/dist/utils/is-pure-cjs.d.ts +9 -0
  101. package/package.json +112 -29
  102. package/dist/index.d.mts +0 -56
  103. package/dist/index.mjs +0 -1
  104. package/dist/packem_shared/browserslist-to-esbuild-DY9HwYtp.d.ts +0 -3
  105. package/dist/packem_shared/cachingPlugin-D0BBFJPD.mjs +0 -1
  106. package/dist/packem_shared/copyPlugin--6RITp1-.mjs +0 -1
  107. package/dist/packem_shared/createSplitChunks-CGDk55G3.mjs +0 -1
  108. package/dist/packem_shared/esbuildPlugin-BAwyhG6L.mjs +0 -1
  109. package/dist/packem_shared/fixDtsDefaultCjsExportsPlugin-Dp1UcHVR.mjs +0 -1
  110. package/dist/packem_shared/isolatedDeclarationsPlugin-A0wmmw3Y.mjs +0 -3
  111. package/dist/packem_shared/jsonPlugin-BAi3Da-h.mjs +0 -1
  112. package/dist/packem_shared/jsxRemoveAttributes-B1PLPffj.mjs +0 -1
  113. package/dist/packem_shared/licensePlugin-C5yzUqe-.mjs +0 -13
  114. package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG.mjs +0 -1
  115. package/dist/packem_shared/patchTypescriptTypes-BEdkvKxL.mjs +0 -6
  116. package/dist/packem_shared/rawPlugin-BqlR6ZOI.mjs +0 -1
  117. package/dist/packem_shared/resolveTsconfigPathsPlugin-Crf4lzxq.mjs +0 -1
  118. package/dist/packem_shared/types-C_grznAP.d.mts +0 -4539
  119. package/dist/packem_shared/types-C_grznAP.d.ts +0 -4539
  120. package/dist/packem_shared/urlPlugin-DBgFIkTc.mjs +0 -1
  121. package/dist/plugins/esbuild/index.d.mts +0 -25
  122. package/dist/plugins/esbuild/index.mjs +0 -1
  123. package/dist/plugins/oxc/index.d.mts +0 -28
  124. package/dist/plugins/oxc/index.mjs +0 -1
  125. package/dist/plugins/sucrase/index.d.mts +0 -19
  126. package/dist/plugins/swc/index.d.mts +0 -26
  127. package/dist/plugins/swc/index.mjs +0 -1
  128. package/dist/plugins/typescript/index.d.mts +0 -29
  129. package/dist/plugins/typescript/index.mjs +0 -1
  130. /package/dist/packem_shared/{browserslistToEsbuild-C0IWmbNe.mjs → browserslistToEsbuild-C0IWmbNe.js} +0 -0
  131. /package/dist/packem_shared/{chunkSplitter-DWAy1JkE.mjs → chunkSplitter-DWAy1JkE.js} +0 -0
  132. /package/dist/packem_shared/{fixDynamicImportExtension-BBGNRniz.mjs → fixDynamicImportExtension-BBGNRniz.js} +0 -0
  133. /package/dist/packem_shared/{getCustomModuleLayer-d8i66lfh.mjs → getCustomModuleLayer-d8i66lfh.js} +0 -0
  134. /package/dist/packem_shared/{getModuleLayer-rF9RxnJ5.mjs → getModuleLayer-rF9RxnJ5.js} +0 -0
  135. /package/dist/packem_shared/{index-Dq8IUFTs.mjs → index-Dq8IUFTs.js} +0 -0
  136. /package/dist/packem_shared/{isolatedDeclarationsOxcTransformer-WbfE6cGu.mjs → isolatedDeclarationsOxcTransformer-WbfE6cGu.js} +0 -0
  137. /package/dist/packem_shared/{isolatedDeclarationsSwcTransformer-Ch2AgtWC.mjs → isolatedDeclarationsSwcTransformer-Ch2AgtWC.js} +0 -0
  138. /package/dist/packem_shared/{isolatedDeclarationsTypescriptTransformer-DkuEkofo.mjs → isolatedDeclarationsTypescriptTransformer-DkuEkofo.js} +0 -0
  139. /package/dist/packem_shared/{oxcTransformPlugin-DfVQouIB.mjs → oxcTransformPlugin-DfVQouIB.js} +0 -0
  140. /package/dist/packem_shared/{resolveFileUrl-BkpjVHeK.mjs → resolveFileUrlPlugin-BkpjVHeK.js} +0 -0
  141. /package/dist/packem_shared/{resolveTypescriptMjsCtsPlugin-DcZrZTmM.mjs → resolveTypescriptMjsCtsPlugin-DcZrZTmM.js} +0 -0
  142. /package/dist/packem_shared/{swcPlugin-Boip4lWG.mjs → swcPlugin-Boip4lWG.js} +0 -0
  143. /package/dist/{packem_shared/esmShimCjsSyntaxPlugin-DjKqX4DE.mjs → plugins/esm-shim-cjs-syntax.js} +0 -0
  144. /package/dist/{packem_shared/makeExecutable-6aOVHoJR.mjs → plugins/shebang.js} +0 -0
  145. /package/dist/{packem_shared/sourcemapsPlugin-B4W3J79w.mjs → plugins/source-maps.js} +0 -0
  146. /package/dist/plugins/sucrase/{index.mjs → index.js} +0 -0
@@ -0,0 +1,25 @@
1
+ import type { FilterPattern } from "@rollup/pluginutils";
2
+ import type { Plugin } from "rollup";
3
+ export type DataUriPluginOptions = {
4
+ exclude?: FilterPattern;
5
+ include?: FilterPattern;
6
+ /** Encode spaces for use in srcset attribute */
7
+ srcset?: boolean;
8
+ };
9
+ /**
10
+ * Data URI plugin that converts files to data URIs for inline embedding.
11
+ *
12
+ * Query parameters:
13
+ * - ?data-uri - Basic data URI conversion
14
+ * - ?data-uri and encoding=css - Use CSS-optimized SVG encoding
15
+ * - ?data-uri and encoding=tiny - Use tiny SVG encoding (default)
16
+ * - ?data-uri and srcset - Encode spaces as %20 for srcset compatibility
17
+ *
18
+ * Examples:
19
+ * - ./icon.svg?data-uri - Tiny SVG encoding
20
+ * - ./icon.svg?data-uri and encoding=css - CSS-optimized SVG encoding
21
+ * - ./icon.svg?data-uri and srcset - Tiny SVG with srcset compatibility
22
+ * - ./icon.svg?data-uri and encoding=css and srcset - CSS encoding with srcset compatibility
23
+ */
24
+ export declare const dataUriPlugin: (options?: DataUriPluginOptions) => Plugin;
25
+ export default dataUriPlugin;
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var c=(a,e)=>p(a,"name",{value:e,configurable:!0});import{createFilter as g}from"@rollup/pluginutils";import{readFile as u}from"@visulima/fs";import{svgToCssDataUri as h,svgToTinyDataUri as b}from"@visulima/packem-share";import{R as v}from"../packem_shared/index-QEzU3Fey.js";var x=Object.defineProperty,$=c((a,e)=>x(a,"name",{value:e,configurable:!0}),"l");const F=$((a={})=>{const e=g(a.include??[/\?data-uri/],a.exclude);return{async load(s){if(!e(s)||!s.includes("?data-uri"))return;const i=new URL(s,"file://"),t=i.pathname,f=i.searchParams.get("encoding")||"tiny",l=i.searchParams.has("srcset")||a.srcset;this.addWatchFile(t);const r=v.getType(t)||"application/octet-stream";if(r==="image/svg+xml"){const n=await u(t,{buffer:!1}),o=f==="css"?h(n):b(n);return`export default "${l?o.replaceAll(" ","%20"):o}"`}const d=await u(t,{buffer:!0}),m=Buffer.from(d).toString("base64");return`export default "${`${r.startsWith("text/")?`data:${r};charset=utf-8;base64,`:`data:${r};base64,`}${m}`}"`},name:"packem:data-uri"}},"dataUriPlugin");export{F as dataUriPlugin,F as default};
@@ -0,0 +1,7 @@
1
+ import type { FilterPattern } from "@rollup/pluginutils";
2
+ import type { Plugin } from "rollup";
3
+ export interface DebarrelPluginOptions {
4
+ include?: FilterPattern;
5
+ possibleBarrelFiles?: (RegExp | string)[];
6
+ }
7
+ export declare const debarrelPlugin: (options: DebarrelPluginOptions, logger: Console) => Plugin;
@@ -0,0 +1,2 @@
1
+ var F=Object.defineProperty;var $=(e,t)=>F(e,"name",{value:t,configurable:!0});import I from"node:fs/promises";import{createFilter as j}from"@rollup/pluginutils";import M from"magic-string";import*as B from"rs-module-lexer";var E=Object.defineProperty,d=$((e,t)=>E(e,"name",{value:t,configurable:!0}),"u");const A=/\.[mc]?tsx?(?:\?.*)?$/,D=/(?:\.(?:[tj]s|[tj]sx)|\/index\.(?:[tj]s|[tj]sx))(?:\?.*)?$/,O=/^\s*export/,_={exports:[],facade:!1,imports:[]},y=d(e=>A.test(e),"isSourceFile"),b=d(e=>e.includes("/build/cache/vite/")||e.includes("/node_modules/"),"isIgnoredModule"),k=d((e,t)=>b(e)?!1:D.test(e)?!0:t.possibleBarrelFiles?t.possibleBarrelFiles.some(s=>e.match(s)):!1,"isPossibleBarrelSpecifier"),N=d(e=>O.test(e)?"export":"import","getDeclarationKind"),{parseAsync:z}=B,C=d(async(e,t,s)=>{try{const{output:r}=await z({input:[{code:t,filename:e}]});return r[0]}catch(r){return s.warn({message:`Failed to parse ${e}:
2
+ ${r instanceof Error?r.message:String(r)}`,prefix:"plugin:debarrel"}),_}},"safeParse"),K=d(async(e,t,s,r)=>{const a=e.parseCache.get(t);if(a!==void 0)return a;const o=await C(t,s,r);return e.parseCache.set(t,o),o},"parsePotentialBarrelFile"),R=d((e,t)=>{const s=e.fileCache.get(t);if(s!==void 0)return s;const r=I.readFile(t,"utf8");return e.fileCache.set(t,r),r},"readFileCached"),P=d(e=>{const t=/^(?:import|export)\s+([\w$]+)/,s=/([\w$]+)\s*,\s*\{|\}\s*,\s*([\w$]+)/,r=/[{,]\s*(type\s+)?([\w$]+)(?:\s+as\s+([\w$]+))?/gi;r.lastIndex=0;const a=[];if(e.includes("*"))return a;if(!e.includes("{")){const i=e.match(t);return i&&a.push({imported:"default",local:i[1]}),a}const o=e.match(s);o&&a.push({imported:"default",local:o[1]||o[2]});let n;for(;n=r.exec(e);)n[1]||n[2]&&a.push({imported:n[2],local:n[3]});return a},"getImportNames"),T=d((e,t,s)=>{let r=e.ln,a=t.find(o=>o.ss<e.s&&o.se>e.e&&o.d===-1);if(!a||!a.n){const o=r||s.slice(e.s).match(/default\s+([a-zA-Z_$][\w$]*)(?:;|\n|$)/)?.[1];o&&(a=t.find(n=>{const i=P(s.slice(n.ss,n.s)).find(c=>c.local===o);return i&&(r=i.imported),i}))}if(a&&!r){const o=s.slice(a.ss,e.s);if(!o.includes("*")){const n=o.match(/([\w$]+)\s*as\s*$/)?.[1];n&&(r=n)}}return{imp:a,localExportName:r}},"findMatchingImport"),v=d(async(e,t,s,r,a)=>{const{resolve:o}=e,n=await R(e,t),{exports:i,imports:c}=await K(e,t,n,a);for await(const l of i){const p=l.n;if(p!==s)continue;const u=T(l,c,n),{imp:f,localExportName:w}=u;if(!f||!f.n)return{exportName:s,id:t,resolved:!0};if(f.d>-1)return{exportName:s,id:t,resolved:!0};let h;const g=n.slice(f.ss,l.s);if(N(g)==="import"&&/\bas\b/.test(g)){const S=new RegExp(String.raw`(\w+)\s+as\s+${s}(?!\w)`);h=g.match(S)?.[0]}const x=(await o(f.n,t))?.id;return x?k(x,r)?v(e,x,w||p,r,a):{aliasedImportName:h,exportName:w||s,id:x,resolved:!1}:{aliasedImportName:h,exportName:w,id:t,resolved:!1}}const m=c.filter(l=>/^export\s+\*(?!\s+as)/.test(n.slice(l.ss,l.s)));if(m.length===1){const l=m[0]?.n,p=l?(await e.resolve(l,t))?.id:void 0;if(!p)return{exportName:s,id:t,resolved:!1};const u=await v(e,p,s,r);if(u.resolved)return u}else if(m.length>1){const l=(await Promise.all(m.map(async p=>{const u=p.n,f=u?(await e.resolve(u,t))?.id:void 0;if(f)return v(e,f,s,r)}))).find(p=>p?.resolved);if(l)return l}return{exportName:s,id:t,resolved:!1}},"resolveThroughBarrel"),J=d((e,t,s)=>{const{aliasedImportName:r,exportName:a}=e,o=t.local||t.imported;return r?`{${r}}`:a==="default"&&s!=="export"?o:`{${a!==o?`${a} as ${o}`:a}}`},"getDeclarationClause"),L=d(async(e,t,s,r,a)=>{const o=[],{imports:n}=await C(t,s,a);return await Promise.all(n.map(async i=>{if(!i.n||i.d!==-1)return;const c=s.slice(i.ss,i.s),m=P(c);if(m.length===0)return;const l=(await e.resolve(i.n,t))?.id;if(!l||!y(l)||b(l))return;const p=N(c);try{const u=await Promise.all(m.map(async f=>{const w=await v(e,l,f.imported,r);if(!w)return;const h=J(w,f,p),g=JSON.stringify(w.id);return`${p} ${h} from ${g}`}));if(u.includes(void 0))return;o.push([i.ss,i.se,u.join(";")])}catch(u){a.warn({context:{error:u},message:u.toString(),prefix:"plugin:debarrel"})}})),o},"getDebarrelModifications"),X=d((e,t,s,r)=>{if(s.length===0)return;const a=new M(t,{filename:e});for(const[o,n,i]of s)a.update(o,n,i);return{code:a.toString(),map:r?a.generateMap({file:e}):void 0}},"applyModifications"),Q=d((e,t)=>{const s=new Map,r=new Map,a=d(()=>{s.clear(),r.clear()},"purgeCaches"),o=e.include?j(e.include,[]):void 0;let n=!0;return{buildEnd:a,buildStart:a,async load(i){const c=s.get(i);if(c)return await c},name:"packem:debarrel",options(i){(i.output&&(Array.isArray(i.output)?i.output[0]?.sourcemap:i.output?.sourcemap))===!1&&(n=!1)},async transform(i,c){if(!y(c)||o&&!o(c))return;const m={fileCache:s,parseCache:r,resolve:this.resolve.bind(this)},l=await L(m,c,i,e,t);return X(c,i,l,n)},watchChange(i){s.delete(i),r.delete(i)}}},"debarrelPlugin");export{Q as debarrelPlugin};
@@ -1,3 +1,2 @@
1
1
  declare const browserslistToEsbuild: (browserList: string[]) => string[];
2
-
3
- export { browserslistToEsbuild as b };
2
+ export default browserslistToEsbuild;
@@ -0,0 +1,3 @@
1
+ import type { TransformerFn as TransformerFunction } from "../../types.d.ts";
2
+ declare const _default: TransformerFunction;
3
+ export default _default;
@@ -1,25 +1,3 @@
1
- export { b as browserslistToEsbuild } from '../../packem_shared/browserslist-to-esbuild-DY9HwYtp.js';
2
- import { T as TransformerFn } from '../../packem_shared/types-C_grznAP.js';
3
- export { t as EsbuildPluginConfig, v as OptimizeDepsOptions, w as OptimizeDepsResult, O as Optimized, x as Options } from '../../packem_shared/types-C_grznAP.js';
4
- import '@rollup/plugin-alias';
5
- import '@rollup/plugin-commonjs';
6
- import '@rollup/plugin-json';
7
- import '@rollup/plugin-node-resolve';
8
- import '@rollup/plugin-replace';
9
- import '@rollup/plugin-wasm';
10
- import '@rollup/pluginutils';
11
- import 'rollup';
12
- import 'rollup-plugin-dts';
13
- import 'rollup-plugin-polyfill-node';
14
- import 'rollup-plugin-pure';
15
- import 'rollup-plugin-visualizer';
16
- import 'esbuild';
17
- import '@visulima/package';
18
- import '@visulima/packem-share/types';
19
- import 'oxc-resolver';
20
- import 'oxc-transform';
21
- import 'sucrase';
22
-
23
- declare const _default: TransformerFn;
24
-
25
- export { _default as esbuildPlugin };
1
+ export { default as browserslistToEsbuild } from "./browserslist-to-esbuild.d.ts";
2
+ export { default as esbuildPlugin } from "./esbuild-plugin.d.ts";
3
+ export type * from "./types.d.ts";
@@ -0,0 +1 @@
1
+ import{default as l}from"../../packem_shared/browserslistToEsbuild-C0IWmbNe.js";import{default as r}from"../../packem_shared/esbuildPlugin-pPPsJB9N.js";export{l as browserslistToEsbuild,r as esbuildPlugin};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Modified copy of https://github.com/egoist/rollup-plugin-esbuild/blob/dev/src/index.ts
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2020 EGOIST
7
+ */
8
+ import type { FilterPattern } from "@rollup/pluginutils";
9
+ import type { BuildOptions as EsbuildOptions, Loader, TransformOptions } from "esbuild";
10
+ type MarkOptional<Type, Keys extends keyof Type> = Type extends Type ? Omit<Type, Keys> & Partial<Pick<Type, Keys>> : never;
11
+ export type EsbuildPluginConfig = Options & {
12
+ logger: Console;
13
+ };
14
+ export type Optimized = Map<string, {
15
+ file: string;
16
+ }>;
17
+ export type OptimizeDepsOptions = {
18
+ cwd: string;
19
+ esbuildOptions?: EsbuildOptions;
20
+ exclude?: string[];
21
+ include: string[];
22
+ sourceMap: boolean;
23
+ };
24
+ export type OptimizeDepsResult = {
25
+ cacheDir: string;
26
+ optimized: Optimized;
27
+ };
28
+ export type Options = Omit<TransformOptions, "loader" | "sourcemap"> & {
29
+ exclude?: FilterPattern;
30
+ include?: FilterPattern;
31
+ /**
32
+ * Map extension to esbuild loader
33
+ * Note that each entry (the extension) needs to start with a dot
34
+ */
35
+ loaders?: Record<string, Loader | false>;
36
+ optimizeDeps?: MarkOptional<OptimizeDepsOptions, "cwd" | "sourceMap">;
37
+ sourceMap?: boolean;
38
+ };
39
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Modified copy of https://github.com/egoist/rollup-plugin-esbuild/blob/dev/src/minify.ts
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2020 EGOIST
7
+ */
8
+ import type { TransformOptions } from "esbuild";
9
+ import type { Plugin } from "rollup";
10
+ type Options = Omit<TransformOptions, "sourcemap"> & {
11
+ sourceMap?: boolean;
12
+ };
13
+ declare const getRenderChunk: ({ sourceMap, ...options }: Options) => Plugin["renderChunk"];
14
+ export default getRenderChunk;
@@ -0,0 +1,3 @@
1
+ import type { OptimizeDepsOptions, OptimizeDepsResult } from "../types.d.ts";
2
+ declare const optimizeDeps: (options: OptimizeDepsOptions) => Promise<OptimizeDepsResult>;
3
+ export default optimizeDeps;
@@ -0,0 +1,4 @@
1
+ import type { Message } from "esbuild";
2
+ import type { PluginContext } from "rollup";
3
+ declare const warn: (pluginContext: PluginContext, messages: Message[]) => Promise<void>;
4
+ export default warn;
@@ -0,0 +1,9 @@
1
+ import type { FilterPattern } from "@rollup/pluginutils";
2
+ import type { PackageJson } from "@visulima/package";
3
+ import type { Plugin } from "rollup";
4
+ export declare const GLOBAL_REQUIRE_REGEX: RegExp;
5
+ export interface EsmShimCjsSyntaxOptions {
6
+ exclude?: FilterPattern;
7
+ include?: FilterPattern;
8
+ }
9
+ export declare const esmShimCjsSyntaxPlugin: (packageJson: PackageJson, options: EsmShimCjsSyntaxOptions) => Plugin;
@@ -0,0 +1,26 @@
1
+ import type { Plugin, RenderedChunk } from "rollup";
2
+ export type FixDtsDefaultCjsExportsPluginOptions = {
3
+ /**
4
+ * A function to determine if a chunk should be processed by this plugin.
5
+ * Defaults to processing .d.ts, .d.cts, or .d.mts files that are entry chunks and have exports.
6
+ * @param info The Rollup RenderedChunk object.
7
+ * @returns True if the chunk should be processed, false otherwise.
8
+ */
9
+ matcher?: (info: RenderedChunk) => boolean;
10
+ };
11
+ /**
12
+ * A Rollup plugin to fix default exports in TypeScript declaration files (.d.ts)
13
+ * to ensure they are CJS compatible (using `export = ...` and namespaces).
14
+ * This is particularly useful for libraries that want to support both ESM and CJS consumers correctly.
15
+ *
16
+ * The plugin handles various scenarios:
17
+ * - `export { MyClass as default };`
18
+ * - `export { default } from 'some-module';`
19
+ * - `export { name as default } from 'some-module';`
20
+ * - `export default from 'some-module';` (an mlly quirk)
21
+ * - Combinations with named exports (value and type exports), creating namespaces where appropriate.
22
+ * - Pure type-only exports like `export { type Foo, type Bar };`
23
+ * @param options Optional configuration for the plugin.
24
+ * @returns The Rollup plugin object.
25
+ */
26
+ export declare const fixDtsDefaultCjsExportsPlugin: (options?: FixDtsDefaultCjsExportsPluginOptions) => Plugin;
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var n=(e,r)=>i(e,"name",{value:r,configurable:!0});import{_ as o}from"../packem_shared/fix-dts-default-cjs-exports-EvsobpME.js";var p=Object.defineProperty,a=n((e,r)=>p(e,"name",{value:r,configurable:!0}),"n");const l=a((e={})=>{const{matcher:r=a(t=>(t.type==="chunk"||t.type==="asset")&&t.exports?.length>0&&/\.d\.c?ts$/.test(t.fileName)&&t.isEntry,"matcher")}=e;return{name:"packem:fix-dts-default-cjs-exports-plugin",renderChunk(t,s){return r(s)?o(t,{fileName:s.fileName,imports:s.imports},{warn:this.warn}):void 0}}},"fixDtsDefaultCjsExportsPlugin");export{l as fixDtsDefaultCjsExportsPlugin};
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "rollup";
2
+ declare const fixDynamicImportExtension: () => Plugin;
3
+ export default fixDynamicImportExtension;
@@ -0,0 +1,8 @@
1
+ import type { FilterPattern } from "@rollup/pluginutils";
2
+ import type { BuildContext } from "@visulima/packem-share/types";
3
+ import type { Plugin } from "rollup";
4
+ export type IsolatedDeclarationsOptions = {
5
+ exclude?: FilterPattern;
6
+ ignoreErrors?: boolean;
7
+ };
8
+ export declare const isolatedDeclarationsPlugin: <T extends Record<string, any>>(sourceDirectory: string, context: BuildContext<T>) => Plugin;
@@ -0,0 +1,3 @@
1
+ var U=Object.defineProperty;var x=(t,e)=>U(t,"name",{value:e,configurable:!0});import{createFilter as X}from"@rollup/pluginutils";import{readFile as W}from"@visulima/fs";import{EXCLUDE_REGEXP as _,ENDING_REGEX as E}from"@visulima/packem-share/constants";import{getDtsExtension as L}from"@visulima/packem-share/utils";import{dirname as R,toNamespacedPath as D,sep as k,extname as J,isAbsolute as q,relative as C,join as A,basename as O}from"@visulima/path";import{parseSync as z}from"oxc-parser";import{_ as B}from"../../packem_shared/fix-dts-default-cjs-exports-EvsobpME.js";var H=Object.defineProperty,Q=x((t,e)=>H(t,"name",{value:e,configurable:!0}),"e");const P=/^([\w-]+):/,K=Q(t=>{if(!t||typeof t!="string")throw new Error("Invalid key: Key must be a non-empty string.");const e=[],c=P.exec(t);c&&(e.push(c[1]),t=t.replace(P,""));const n=t.split("/");for(const p of n)(p.includes("*")||p)&&e.push(p);return e},"splitTsconfigPathKey");var V=Object.defineProperty,Y=x((t,e)=>V(t,"name",{value:e,configurable:!0}),"h");const Z=Y((t,e)=>{const c=t.replace(/^\.\//,""),n=e.replace(/^\.\//,"");if(n.startsWith(c))return t+n.slice(c.length);if(t.endsWith(e))return t;const p=K(t),d=K(e);let l=p.length-1,r=d.length-1;for(;l>=0&&r>=0&&p[l]===d[r];)l--,r--;let a=p.slice(0,l).join("/");const f=d.slice(r).join("/");return(!a.startsWith(".")||a==="")&&(a=`./${a}`),a+(f?`/${f}`:"")},"extendString");var ee=Object.defineProperty,te=x((t,e)=>ee(t,"name",{value:e,configurable:!0}),"s");const re=te((...t)=>{if(t.length===0)return"";if(t.length===1)return R(t[0]);t=t.map(p=>D(p).split(k).join("/"));const[e,...c]=t;let n=e.split("/");for(const p of c){const d=p.split("/",n.length);let l=0;for(const r of d)if(r===n[l])l+=1;else{n=n.slice(0,l);break}n=n.slice(0,l)}return(n.length<=1&&n[0]===""?`/${n[0]}`:n.join("/")).split("/").join(k)},"lowestCommonAncestor");var ie=Object.defineProperty,j=x((t,e)=>ie(t,"name",{value:e,configurable:!0}),"g");const S=j((t,e)=>`${t}
2
+ //# sourceMappingURL=${O(e)}.map
3
+ `,"appendMapUrl"),I=j((t,e,c)=>JSON.stringify({file:O(c),mappings:t,names:[],sourceRoot:"",sources:[C(R(c),e)],version:3}),"generateDtsMap"),fe=j((t,e)=>{const c=X(/\.(?:[mc]?ts|[jt]sx?)$/,e.options.rollup.isolatedDeclarations?.exclude||_);let n=Object.create(null);const p=j((r,a)=>{n[r.replace(E,"")]={...a,ext:J(r)}},"addOutput");let d=[];e.tsconfig?.config.compilerOptions&&(d=Object.entries(e.tsconfig.config.compilerOptions.paths??{}).map(([r])=>r.endsWith("*")?new RegExp(`^${r.replace("*","(.*)")}$`):new RegExp(`^${r}$`)));async function l(r,a){if(!c(a))return;e.logger.debug({message:`Processing file: ${a}`,prefix:"packem:isolated-declarations"});let f;try{f=z(a,r).program}catch(s){e.logger.debug({message:s.message,prefix:"packem:isolated-declarations"})}if(f){const s=f.body.filter(i=>(i.type==="ImportDeclaration"||i.type==="ExportAllDeclaration"||i.type==="ExportNamedDeclaration")&&i.source);for await(const i of s){if(O(i.source.value).includes("."))continue;const o=await this.resolve(i.source.value,a);if(!(!o||o.external)&&(o.id.endsWith(".ts")||o.id.endsWith(".cts")||o.id.endsWith(".mts")||o.id.endsWith(".tsx")||o.id.endsWith(".ctsx")||o.id.endsWith(".mtsx"))){const g=o.id.replace(`${t}/`,"");let u=i.source.value;d.some($=>$.test(i.source.value))&&!i.source.value.startsWith(".")&&(u=`./${i.source.value}`),r=r.replaceAll(`from "${i.source.value}"`,`from "${Z(u,g)}"`)}}}const{errors:b,map:w,sourceText:m}=await e.options.isolatedDeclarationTransformer(a,r,e.options.sourcemap,e.tsconfig?.config?.compilerOptions);if(b.length>0){if(e.options.rollup.isolatedDeclarations.ignoreErrors){this.warn(b[0]);return}return this.error(b[0])}if(p(a,{map:w,source:m}),!f)return;const h=f.body.filter(s=>!("source"in s)||!s.source?!1:"importKind"in s&&s.importKind==="type"||"exportKind"in s&&s.exportKind==="type"?!0:s.type==="ImportDeclaration"?s.specifiers&&s.specifiers.every(i=>i.type==="ImportSpecifier"&&i.importKind==="type"):s.type==="ExportNamedDeclaration"&&s.specifiers&&s.specifiers.every(i=>i.exportKind==="type"));for await(const s of h){if(!s.source)continue;const i=await this.resolve(s.source.value,a);if(!i)return;const o=i.id;if(c(o)&&!n[o.replace(E,"")])try{const g=await W(o);await l.call(this,g,o)}catch{}}}return x(l,"N"),j(l,"transform"),{buildStart(){n=Object.create(null)},name:"packem:isolated-declarations",async renderStart(r,{input:a}){const f=re(...Array.isArray(a)?a:Object.values(a));e.logger.debug({message:`Input base:${f}`,prefix:"packem:isolated-declarations"});const b=Array.isArray(a)?a:Object.values(a);for await(const m of b)if(c(m)&&!n[m.replace(E,"")])try{const h=await W(m);await l.call(this,h,m)}catch{}typeof r.entryFileNames=="function"&&(r.entryFileNames=r.entryFileNames({name:r.name}));const w=r.entryFileNames.replace(/\.(.)?[jt]sx?$/,(m,h)=>`.d.${h||""}ts`);for await(let[m,{ext:h,map:s,source:i}]of Object.entries(n)){let o;if(q(m)){if(!m.startsWith(t)){e.logger.debug({message:`Skipping file outside sourceDirectory: ${m}`,prefix:"packem:isolated-declarations"});continue}o=C(t,m)}else o=m.replace(`${t}/`,"");if(o.startsWith("/")&&(o=o.slice(1)),e.options.rollup.cjsInterop&&r.format==="cjs"){const y=B(i,{fileName:o,imports:[]},{warn:this.warn});y&&(i=y.code)}const g=i.includes("from '")?"'":'"',u=o+h;if((e.options.declaration===!0||e.options.declaration==="compatible")&&r.format==="cjs"){e.logger.debug({message:`Emit compatible dts file: ${o}`,prefix:"packem:isolated-declarations"});const y=w.replace("[name]",D(o)).replace(".cts",".ts");let v=i;e.options.sourcemap&&s&&(v=S(v.trim(),y),this.emitFile({fileName:`${y}.map`,originalFileName:u,source:I(s,u,A(r.dir,y)),type:"asset"})),this.emitFile({fileName:y,originalFileName:u,source:v.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(F,N,M,T)=>`${N+g+(T||M)}.d.ts${g};`),type:"asset"})}e.logger.debug({message:`Emit dts file: ${o}`,prefix:"packem:isolated-declarations"});const $=w.replace("[name]",D(o));e.options.sourcemap&&s&&(i=S(i.trim(),$),this.emitFile({fileName:`${$}.map`,originalFileName:u,source:I(s,u,A(r.dir,$)),type:"asset"}));const G=L(e,r.format==="cjs"?"cjs":"esm");this.emitFile({fileName:$,originalFileName:u,source:i.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(y,v,F,N)=>`${v+g+(N||F)}.${G}${g};`),type:"asset"})}},transform:l}},"isolatedDeclarationsPlugin");export{fe as isolatedDeclarationsPlugin};
@@ -0,0 +1,2 @@
1
+ declare const extendString: (baseString: string, referenceString: string) => string;
2
+ export default extendString;
@@ -0,0 +1,35 @@
1
+ import type { LoggingFunction, SourceMapInput } from "rollup";
2
+ /**
3
+ * Options for the plugin.
4
+ */
5
+ type Options = {
6
+ /**
7
+ * Rollup's warning function.
8
+ */
9
+ warn?: LoggingFunction;
10
+ };
11
+ /**
12
+ * Information about the code being processed.
13
+ */
14
+ interface CodeInfo {
15
+ /**
16
+ * The name of the file.
17
+ */
18
+ fileName: string;
19
+ /**
20
+ * A list of import specifiers in the file.
21
+ */
22
+ imports: string[];
23
+ }
24
+ /**
25
+ * Main internal function to transform ES module default exports in .d.ts files to be CJS compatible.
26
+ * @param code The code of the chunk.
27
+ * @param info Information about the file (name, imports).
28
+ * @param options Plugin options, including the warning function.
29
+ * @returns An object with the transformed code and a null map, or undefined if no transformation occurs or an error happens.
30
+ */
31
+ declare const fixDtsDefaultCJSExports: (code: string, info: CodeInfo, options: Options) => {
32
+ code: string;
33
+ map: SourceMapInput | undefined;
34
+ } | undefined;
35
+ export default fixDtsDefaultCJSExports;
@@ -0,0 +1,2 @@
1
+ declare const lowestCommonAncestor: (...filepaths: string[]) => string;
2
+ export default lowestCommonAncestor;
@@ -0,0 +1,2 @@
1
+ declare const splitTsconfigPathKey: (key: string) => string[];
2
+ export default splitTsconfigPathKey;
@@ -0,0 +1,4 @@
1
+ import type { RollupJsonOptions } from "@rollup/plugin-json";
2
+ import type { Plugin } from "rollup";
3
+ export type { RollupJsonOptions } from "@rollup/plugin-json";
4
+ export declare const JsonPlugin: (options: RollupJsonOptions) => Plugin;
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var t=(o,r)=>c(o,"name",{value:r,configurable:!0});import i from"@rollup/plugin-json";var l=Object.defineProperty,d=t((o,r)=>l(o,"name",{value:r,configurable:!0}),"t");const n="export default ",m=d(o=>{const r=i(o);return{...r,name:"packem:json",transform:{filter:{id:/\.json$/},handler(s,a){const e=r.transform?.call(this,s,a);return e&&typeof e!="string"&&"code"in e&&e.code?.startsWith(n)&&(e.code=e.code.replace(n,"module.exports = ")),e}}}},"JsonPlugin");export{m as JsonPlugin};
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from "rollup";
2
+ export type JSXRemoveAttributesPlugin = {
3
+ attributes: string[];
4
+ };
5
+ export declare const jsxRemoveAttributes: ({ attributes, logger }: JSXRemoveAttributesPlugin & {
6
+ logger: Console;
7
+ }) => Plugin;
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var p=(e,a)=>c(e,"name",{value:a,configurable:!0});import{w as y}from"../packem_shared/index-Dq8IUFTs.js";import f from"magic-string";var b=Object.defineProperty,v=p((e,a)=>b(e,"name",{value:a,configurable:!0}),"l");const g=v(({attributes:e,logger:a})=>{if(!Array.isArray(e)||e.length===0)throw new Error("[packem:jsx-remove-attributes]: attributes must be a non-empty array of strings.");return{name:"packem:jsx-remove-attributes",transform:{filter:{id:/\.[tj]sx$/},async handler(i,u){let n;try{n=this.parse(i,{allowReturnOutsideFunction:!0})}catch(r){this.warn({code:"PARSE_ERROR",message:`[packem:jsx-remove-attributes]: failed to parse "${u}" and remove the jsx attribute.`}),a.warn(r);return}let l=!1;const o=new f(i);if(y(n,{enter(r){if(r.type==="CallExpression"&&r.callee.type==="Identifier"&&r.callee.name==="jsx"){const m=r.arguments.filter(s=>s.type==="ObjectExpression"&&Array.isArray(s.properties));for(const s of m)for(const t of s.properties)t.type==="Property"&&t.key.type==="Literal"&&t.value.type==="Literal"&&e.includes(t.key.value)&&(o.overwrite(t.start-2,t.end,""),l=!0)}}}),!!l)return{code:o.toString(),map:o.generateMap({hires:!0})}}}}},"jsxRemoveAttributes");export{g as jsxRemoveAttributes};
@@ -0,0 +1,17 @@
1
+ import type { Plugin } from "rollup";
2
+ export interface LicenseOptions {
3
+ dependenciesMarker?: string;
4
+ dependenciesTemplate?: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
5
+ dtsMarker?: string;
6
+ dtsTemplate?: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
7
+ path?: string;
8
+ }
9
+ export declare const licensePlugin: ({ dtsMarker, licenseFilePath, licenseTemplate, logger, marker, mode, packageName, }: {
10
+ dtsMarker?: string;
11
+ licenseFilePath: string;
12
+ licenseTemplate: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
13
+ logger: Console;
14
+ marker: string;
15
+ mode: "dependencies" | "types";
16
+ packageName: string | undefined;
17
+ }) => Plugin;
@@ -0,0 +1,13 @@
1
+ var P=Object.defineProperty;var h=(r,e)=>P(r,"name",{value:e,configurable:!0});import{readFileSync as b,writeFileSync as v}from"@visulima/fs";import{replaceContentWithinMarker as w}from"@visulima/packem-share/utils";import F from"rollup-plugin-license";var N=Object.defineProperty,y=h((r,e)=>N(r,"name",{value:e,configurable:!0}),"d");const C=y(r=>{const e=[],c=[];return r.forEach(t=>{t.startsWith("(")?e.push(t):c.push(t)}),[...c.toSorted(),...e.toSorted()]},"sortLicenses"),z=y(({dtsMarker:r,licenseFilePath:e,licenseTemplate:c,logger:t,marker:s,mode:m,packageName:S})=>F({thirdParty(x){const u=new Set,d=x.toSorted(({name:n},{name:i})=>(n||0)>(i||0)?1:(i||0)>(n||0)?-1:0).map(({author:n,contributors:i,license:a,licenseText:$,maintainers:j,name:k,repository:p})=>{let l=`## ${k}
2
+ `;a&&(l+=`License: ${a}
3
+ `);const f=new Set;for(const o of[n,...j,...i]){const g=typeof o=="string"?o:o?.name;g&&f.add(g)}return f.size>0&&(l+=`By: ${[...f].join(", ")}
4
+ `),p&&(l+=`Repository: ${typeof p=="string"?p:p.url}
5
+ `),$&&(l+=`
6
+ ${$.trim().replaceAll(/\r\n|\r/g,`
7
+ `).replaceAll(`<!-- ${s} -->`,"").replaceAll(r?`<!-- ${r} -->`:"","").replaceAll(`<!-- /${s} -->`,"").replaceAll(r?`<!-- /${r} -->`:"","").trim().split(`
8
+ `).map(o=>o?`> ${o}`:">").join(`
9
+ `)}
10
+ `),a&&u.add(a),l}).join(`
11
+ ---------------------------------------
12
+
13
+ `);if(d===""){t.info({message:"No dependencies license information found.",prefix:`plugin:license:${m}`});return}const A=c(C(u),d,S);try{const n=b(e),i=w(n,s,A);if(!i){t.error({message:`Could not find the license marker: <!-- ${s} --><!-- /${s} --> in ${e}`,prefix:`plugin:license:${m}`});return}n!==i&&(v(e,i),t.info({message:`${e} updated.`,prefix:`plugin:license:${m}`}))}catch(n){t.error(n)}}}),"licensePlugin");export{z as licensePlugin};
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "rollup";
2
+ declare const metafilePlugin: () => Plugin;
3
+ export default metafilePlugin;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
3
+ *
4
+ * BSD-3-Clause License
5
+ *
6
+ * Copyright (c) 2024 Google LLC
7
+ */
8
+ import type { FilterPattern } from "@rollup/pluginutils";
9
+ import type { Plugin } from "rollup";
10
+ import * as minify from "./lib/minify-html-literals.d.ts";
11
+ /**
12
+ * Plugin options.
13
+ */
14
+ export interface MinifyHTMLLiteralsOptions {
15
+ /**
16
+ * Pattern or array of patterns of files not to minify.
17
+ */
18
+ exclude?: FilterPattern;
19
+ /**
20
+ * If true, any errors while parsing or minifying will abort the bundle
21
+ * process. Defaults to false, which will only show a warning.
22
+ */
23
+ failOnError?: boolean;
24
+ /**
25
+ * Pattern or array of patterns of files to minify.
26
+ */
27
+ include?: FilterPattern;
28
+ /**
29
+ * Override minify-html-literals function.
30
+ */
31
+ minifyHTMLLiterals?: typeof minify.minifyHTMLLiterals;
32
+ /**
33
+ * Minify options, see
34
+ * https://www.npmjs.com/package/minify-html-literals#options.
35
+ */
36
+ options?: Partial<minify.Options>;
37
+ }
38
+ export declare const minifyHTMLLiteralsPlugin: ({ exclude, failOnError, include, logger, minifyHTMLLiterals, options, }: MinifyHTMLLiteralsOptions & {
39
+ logger: Console;
40
+ }) => Plugin;
41
+ export default minifyHTMLLiteralsPlugin;
@@ -0,0 +1,3 @@
1
+ var b=Object.defineProperty;var g=(t,e)=>b(t,"name",{value:e,configurable:!0});import{createFilter as E}from"@rollup/pluginutils";import H from"magic-string";import p from"typescript";import N from"clean-css";import{minify as j}from"html-minifier-next";let y;const A={getHeadTemplatePart(t){const e=t.getFullText(y),i=e.indexOf("`")+1,r=p.isTemplateHead(t)?-2:-1;return{end:t.end+r,start:t.pos+i,text:e.slice(i,e.length+r)}},getMiddleTailTemplatePart(t){const e=t.getText(y),i=p.isTemplateMiddle(t)?2:1;return{end:t.end-i,start:t.getStart(y)+1,text:e.slice(1,e.length-i)}},getRootNode(t,e=""){return p.createSourceFile(e,t,p.ScriptTarget.ESNext)},getTaggedTemplateTemplate(t){return t.template},getTagText(t){return t.tag.getText(y)},getTemplateParts(t){return p.isNoSubstitutionTemplateLiteral(t)?[this.getHeadTemplatePart(t)]:[this.getHeadTemplatePart(t.head),...t.templateSpans.map(e=>this.getMiddleTailTemplatePart(e.literal))]},isTaggedTemplate:p.isTaggedTemplateExpression,isTemplate:p.isTemplateLiteral,walkChildNodes(t,e){e(t),p.forEachChild(t,i=>{this.walkChildNodes(i,e)})},walkNodes(t,e){y=t,this.walkChildNodes(t,e),y=void 0}};var k=Object.defineProperty,V=g((t,e)=>k(t,"name",{value:e,configurable:!0}),"i");const W=V((t,e={})=>{const i={...A,...e.strategy},r=[],s=[];return i.walkNodes(i.getRootNode(t,e.fileName),a=>{if(i.isTaggedTemplate(a)){const n=i.getTaggedTemplateTemplate(a);s.push(n),r.push({parts:i.getTemplateParts(n),tag:i.getTagText(a)})}else i.isTemplate(a)&&!s.includes(a)&&r.push({parts:i.getTemplateParts(a)})}),r},"parseLiterals");var $=Object.defineProperty,C=g((t,e)=>$(t,"name",{value:e,configurable:!0}),"f");const S={One:"1",Two:"2",Zero:"0"},F=C(t=>{const e={[S.One]:{tidySelectors:!1,transform:void 0},[S.Two]:{tidySelectors:!1,transform:void 0},[S.Zero]:{}};if(t===void 0)return e;if(typeof t=="number"){const i=t.toString();return{...e,[i]:{...e[i]}}}return t},"optimizationLevelFrom"),P=C((t,e)=>{const i=/(:.+\((.*)\))\s*\{/g;let r;for(;(r=i.exec(t))!==null;){const s=r[1],a=r[2];if(!s||!a||!/\s/.test(a))continue;const n=a.replaceAll(/\s/g,""),o=s.replace(a,n),f=e.indexOf(o);if(f===-1)continue;const u=f+o.length;e=e.slice(0,Math.max(0,f))+s+e.slice(Math.max(0,u))}return e},"fixCleanCssTidySelectors"),R={},B={caseSensitive:!0,collapseWhitespace:!0,decodeEntities:!0,minifyCSS:R,minifyJS:!0,processConditionalComments:!0,removeAttributeQuotes:!1,removeComments:!0,removeEmptyAttributes:!0,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0},x=C((t={})=>{const e=F(t.level),i=typeof t.level=="object"&&t.level[1]&&t.level[1].transform;return e[S.One].transform=(r,s)=>s.startsWith("@TEMPLATE_EXPRESSION")&&!s.endsWith(";")?s=`${s};`:i?i(r,s):s,{...t,level:e}},"adjustMinifyCSSOptions"),_={combineHTMLStrings(t,e){return t.map(i=>i.text).join(e)},getPlaceholder(t){let e="@TEMPLATE_EXPRESSION";for(;t.some(i=>i.text.includes(e+"();"));)e+="_";return e+"();"},minifyCSS(t,e={}){const i=x(e),r=new N(i).minify(t);if(r.errors&&r.errors.length>0)throw new Error(r.errors.join(`
2
+
3
+ `));return i.level[S.One].tidySelectors&&(r.styles=P(t,r.styles)),r.styles},async minifyHTML(t,e={}){let i;e.minifyCSS?i=e.minifyCSS!==!0&&typeof e.minifyCSS!="function"?{...e.minifyCSS}:{}:i=!1;let r=!1;i&&(r=x(i));let s=await j(t,{...e,minifyCSS:r});if(e.collapseWhitespace){const a=[...s.matchAll(/<svg/g)].reverse();for(const n of a){const o=n.index,f=s.indexOf("</svg",o);if(f===-1)continue;const u=s.slice(0,Math.max(0,o));let l=s.substring(o,f);const d=s.slice(Math.max(0,f));l=l.replaceAll(/\r?\n/g,""),s=u+l+d}}return r&&r.level[S.One].tidySelectors&&(s=P(t,s)),s},splitHTMLByPlaceholder(t,e){const i=t.split(e);if(e.endsWith(";")){const r=e.slice(0,Math.max(0,e.length-1));for(let s=i.length-1;s>=0;s--){const a=i[s];a!==void 0&&i.splice(s,1,...a.split(r))}}return i}};var G=Object.defineProperty,M=g((t,e)=>G(t,"name",{value:e,configurable:!0}),"l");const I=M((t,e)=>t.generateMap({file:`${e}.map`,hires:!0,source:e}),"defaultGenerateSourceMap"),X=M(t=>{const e=t.tag&&t.tag.toLowerCase();return!!e&&(e.includes("html")||e.includes("svg"))},"defaultShouldMinify"),Z=M(t=>!!t.tag&&t.tag.toLowerCase().includes("css"),"defaultShouldMinifyCSS"),z={ensureHTMLPartsValid(t,e){if(t.length!==e.length)throw new Error("splitHTMLByPlaceholder() must return same number of strings as template parts")},ensurePlaceholderValid(t){if(typeof t!="string"||t.length===0)throw new Error("getPlaceholder() must return a non-empty string")}};async function w(t,e={}){e.minifyOptions={...B,...e.minifyOptions},e.MagicString||(e.MagicString=H),e.parseLiterals||(e.parseLiterals=W),e.shouldMinify||(e.shouldMinify=X),e.shouldMinifyCSS||(e.shouldMinifyCSS=Z),e.parseLiteralsOptions={fileName:e.fileName,...e.parseLiteralsOptions};const i=e.parseLiterals(t,e.parseLiteralsOptions),r=e.strategy||_,{shouldMinify:s,shouldMinifyCSS:a}=e;let n;e.validate!==!1&&(n=e.validate||z);const o=new e.MagicString(t);for(const l of i){const d=s(l),O=!!r.minifyCSS&&a(l);if(d||O){const v=r.getPlaceholder(l.parts);n&&n.ensurePlaceholderValid(v);const T=r.combineHTMLStrings(l.parts,v);let h;if(O){const c=(e.minifyOptions||{}).minifyCSS;if(typeof c=="function"){const m=c(T);h=typeof m=="string"?m:await m}else if(c===!1)h=T;else{const m=typeof c=="object"?c:void 0;h=await r.minifyCSS(T,m)}}else h=await r.minifyHTML(T,e.minifyOptions);const L=r.splitHTMLByPlaceholder(h,v);n&&n.ensureHTMLPartsValid(l.parts,L),l.parts.forEach((c,m)=>{c.start<c.end&&L[m]!==void 0&&o.overwrite(c.start,c.end,L[m])})}}const f=o.toString();if(t===f)return;let u;return e.generateSourceMap!==!1&&(u=(e.generateSourceMap||I)(o,e.fileName??"")),{code:f,map:u}}g(w,"minifyHTMLLiterals");M(w,"minifyHTMLLiterals");var D=Object.defineProperty,J=g((t,e)=>D(t,"name",{value:e,configurable:!0}),"o");const te=J(({exclude:t,failOnError:e=!1,include:i,logger:r,minifyHTMLLiterals:s,options:a})=>{s||(s=w);const n=E(i,t),o=a||{};return{name:"packem:minify-html-literals",async transform(f,u){if(n(u))try{return await s(f,{...o,fileName:u})}catch(l){const d=l instanceof Error?l.message:l;e?this.error(d):r.warn({message:d,prefix:"plugin:minify-html-literals"})}}}},"minifyHTMLLiteralsPlugin");export{te as default,te as minifyHTMLLiteralsPlugin};
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
3
+ *
4
+ * BSD-3-Clause License
5
+ *
6
+ * Copyright (c) 2024 Google LLC
7
+ */
8
+ import type { SourceMapOptions } from "magic-string";
9
+ import type { Template, TemplatePart } from "./models.d.ts";
10
+ import type { ParseLiteralsOptions } from "./parse-literals.d.ts";
11
+ import { parseLiterals } from "./parse-literals.d.ts";
12
+ import type { Strategy } from "./strategy.d.ts";
13
+ import { defaultMinifyOptions } from "./strategy.d.ts";
14
+ /**
15
+ * Options for &lt;code>minifyHTMLLiterals()&lt;/code>.
16
+ */
17
+ export type Options = DefaultOptions | CustomOptions<unknown>;
18
+ /**
19
+ * Options for &lt;code>minifyHTMLLiterals()&lt;/code>, using default html-minifier
20
+ * strategy.
21
+ */
22
+ export interface DefaultOptions extends BaseOptions {
23
+ /**
24
+ * &lt;code>html-minifier&lt;/code> options to use. Defaults to
25
+ * &lt;code>defaultMinifyOptions&lt;/code>, for production-ready minification.
26
+ */
27
+ minifyOptions?: Partial<typeof defaultMinifyOptions>;
28
+ }
29
+ /**
30
+ * Options for &lt;code>minifyHTMLLiterals()&lt;/code>, using a custom strategy.
31
+ */
32
+ export interface CustomOptions<S extends Strategy | unknown> extends BaseOptions {
33
+ /**
34
+ * HTML minification options.
35
+ */
36
+ minifyOptions?: S extends Strategy<infer O> ? Partial<O> : never;
37
+ /**
38
+ * Override the default strategy for how to minify HTML. The default is to
39
+ * use &lt;code>html-minifier&lt;/code>.
40
+ */
41
+ strategy: S;
42
+ }
43
+ /**
44
+ * Options for &lt;code>minifyHTMLLiterals()&lt;/code>.
45
+ */
46
+ export interface BaseOptions {
47
+ /**
48
+ * The name of the file. This is used to determine how to parse the source
49
+ * code and for source map filenames. It may be a base name, relative, or
50
+ * absolute path.
51
+ */
52
+ fileName?: string;
53
+ /**
54
+ * Override how source maps are generated. Set to false to disable source map
55
+ * generation.
56
+ * @param ms the MagicString instance with code modifications
57
+ * @param fileName the name or path of the file
58
+ * @returns a v3 SourceMap or undefined
59
+ */
60
+ generateSourceMap?: ((ms: MagicStringLike, fileName: string) => SourceMap | undefined) | false;
61
+ /**
62
+ * The MagicString-like constructor to use. MagicString is used to replace
63
+ * strings and generate source maps.
64
+ *
65
+ * Override if you want to set your own version of MagicString or change how
66
+ * strings are overridden. Use &lt;code>generateSourceMap&lt;/code> if you want to
67
+ * change how source maps are created.
68
+ */
69
+ MagicString?: new (source: string) => MagicStringLike;
70
+ /**
71
+ * Override how template literals are parsed from a source string.
72
+ */
73
+ parseLiterals?: typeof parseLiterals;
74
+ /**
75
+ * Options for &lt;code>parseLiterals()&lt;/code>.
76
+ */
77
+ parseLiteralsOptions?: Partial<ParseLiteralsOptions>;
78
+ /**
79
+ * Determines whether or not a template should be minified. The default is to
80
+ * minify all tagged template whose tag name contains "html" (case
81
+ * insensitive).
82
+ * @param template the template to check
83
+ * @returns true if the template should be minified
84
+ */
85
+ shouldMinify?: (template: Template) => boolean;
86
+ /**
87
+ * Determines whether or not a CSS template should be minified. The default is
88
+ * to minify all tagged template whose tag name contains "css" (case
89
+ * insensitive).
90
+ * @param template the template to check
91
+ * @returns true if the template should be minified
92
+ */
93
+ shouldMinifyCSS?: (template: Template) => boolean;
94
+ /**
95
+ * Override custom validation or set to false to disable validation. This is
96
+ * only useful when implementing your own strategy that may return
97
+ * unexpected results.
98
+ */
99
+ validate?: Validation | false;
100
+ }
101
+ /**
102
+ * A MagicString-like instance. &lt;code>minify-html-literals&lt;/code> only uses a
103
+ * subset of the MagicString API to overwrite the source code and generate
104
+ * source maps.
105
+ */
106
+ export interface MagicStringLike {
107
+ generateMap: (options?: Partial<SourceMapOptions>) => SourceMap;
108
+ overwrite: (start: number, end: number, content: string) => unknown;
109
+ toString: () => string;
110
+ }
111
+ /**
112
+ * A v3 SourceMap.
113
+ *
114
+ * &lt;code>magic-string> incorrectly declares the SourceMap type with a version
115
+ * string instead of a number, so &lt;code>minify-html-literals&lt;/code> declares
116
+ * its own type.
117
+ */
118
+ export interface SourceMap {
119
+ file?: string;
120
+ mappings: string;
121
+ names: string[];
122
+ sources: string[];
123
+ sourcesContent?: string[];
124
+ toString: () => string;
125
+ toUrl: () => string;
126
+ version: number;
127
+ }
128
+ /**
129
+ * Validation that is executed when minifying HTML to ensure there are no
130
+ * unexpected errors. This is to alleviate hard-to-troubleshoot errors such as
131
+ * undefined errors.
132
+ */
133
+ export interface Validation {
134
+ /**
135
+ * Throws an error if &lt;code>strategy.splitHTMLByPlaceholder()&lt;/code> does not
136
+ * return an HTML part string for each template part.
137
+ * @param parts the template parts that generated the strings
138
+ * @param htmlParts the split HTML strings
139
+ */
140
+ ensureHTMLPartsValid: (parts: TemplatePart[], htmlParts: string[]) => void;
141
+ /**
142
+ * Throws an error if &lt;code>strategy.getPlaceholder()&lt;/code> does not return
143
+ * a valid placeholder string.
144
+ * @param placeholder the placeholder to check
145
+ */
146
+ ensurePlaceholderValid: (placeholder: unknown) => void;
147
+ }
148
+ /**
149
+ * The result of a call to &lt;code>minifyHTMLLiterals()&lt;/code>.
150
+ */
151
+ export interface Result {
152
+ /**
153
+ * The minified code.
154
+ */
155
+ code: string;
156
+ /**
157
+ * Optional v3 SourceMap for the code.
158
+ */
159
+ map: SourceMap | undefined;
160
+ }
161
+ /**
162
+ * The default method to generate a SourceMap. It will generate the SourceMap
163
+ * from the provided MagicString instance using "fileName.map" as the file and
164
+ * "fileName" as the source.
165
+ * @param ms the MagicString instance with code modifications
166
+ * @param fileName the name of the source file
167
+ * @returns a v3 SourceMap
168
+ */
169
+ export declare const defaultGenerateSourceMap: (ms: MagicStringLike, fileName: string) => SourceMap;
170
+ /**
171
+ * The default method to determine whether or not to minify a template. It will
172
+ * return true for all tagged templates whose tag name contains "html" (case
173
+ * insensitive).
174
+ * @param template the template to check
175
+ * @returns true if the template should be minified
176
+ */
177
+ export declare const defaultShouldMinify: (template: Template) => boolean;
178
+ /**
179
+ * The default method to determine whether or not to minify a CSS template. It
180
+ * will return true for all tagged templates whose tag name contains "css" (case
181
+ * insensitive).
182
+ * @param template the template to check
183
+ * @returns true if the template should be minified
184
+ */
185
+ export declare const defaultShouldMinifyCSS: (template: Template) => boolean;
186
+ export declare const defaultValidation: Validation;
187
+ /**
188
+ * Minifies all HTML template literals in the provided source string.
189
+ * @param source the source code
190
+ * @param options minification options
191
+ * @returns the minified code, or null if no minification occurred.
192
+ */
193
+ export declare function minifyHTMLLiterals(source: string, options?: DefaultOptions): Promise<Result | null>;
194
+ /**
195
+ * Minifies all HTML template literals in the provided source string.
196
+ * @param source the source code
197
+ * @param options minification options
198
+ * @returns the minified code, or null if no minification occurred.
199
+ */
200
+ export declare function minifyHTMLLiterals<S extends Strategy>(source: string, options?: CustomOptions<S>): Promise<Result | undefined>;