@visulima/packem-rollup 1.0.0-alpha.6 → 1.0.0-alpha.61
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/CHANGELOG.md +611 -0
- package/LICENSE.md +219 -477
- package/README.md +89 -2
- package/dist/index.d.ts +25 -64
- package/dist/index.js +1 -0
- package/dist/packem_shared/cachingPlugin-DLKoeQeF.js +1 -0
- package/dist/packem_shared/createSplitChunks-BrEBZq7d.js +1 -0
- package/dist/packem_shared/esbuildPlugin-C5x4_cXf.js +1 -0
- package/dist/packem_shared/{index-Cj1Okk1t.mjs → index-QEzU3Fey.js} +1 -1
- package/dist/packem_shared/{metafilePlugin-ObS4J7mO.mjs → metafilePlugin-CVcqFpPJ.js} +1 -1
- package/dist/packem_shared/oxcResolvePlugin-SH1JFonc.js +1 -0
- package/dist/packem_shared/oxcTransformPlugin-BGmQroQ4.js +4 -0
- package/dist/packem_shared/patchTypescriptTypes-CZ4v3hr9.js +6 -0
- package/dist/packem_shared/pureNewExpressionPlugin-DX9yMcH2.js +1 -0
- package/dist/packem_shared/resolveTsconfigPathsPlugin-CEasmDpi.js +1 -0
- package/dist/packem_shared/{resolveTsconfigRootDirectoriesPlugin-_93afm2q.mjs → resolveTsconfigRootDirectoriesPlugin-Cwj3tqCJ.js} +1 -1
- package/dist/packem_shared/resolveTypescriptMjsCtsPlugin-DX9at4BX.js +1 -0
- package/dist/plugins/babel/index.d.ts +10 -0
- package/dist/plugins/babel/index.js +1 -0
- package/dist/plugins/cache-plugin.d.ts +11 -0
- package/dist/plugins/chunk-splitter/gather.d.ts +8 -0
- package/dist/plugins/chunk-splitter/index.d.ts +6 -0
- package/dist/plugins/chunk-splitter/parse/index.d.ts +4 -0
- package/dist/plugins/chunk-splitter/parse/types.d.ts +24 -0
- package/dist/plugins/cjs-interop.d.ts +7 -0
- package/dist/{packem_shared/cjsInteropPlugin-D5wyoQ_B.mjs → plugins/cjs-interop.js} +1 -1
- package/dist/plugins/copy.d.ts +23 -0
- package/dist/plugins/copy.js +1 -0
- package/dist/plugins/data-uri.d.ts +25 -0
- package/dist/plugins/data-uri.js +1 -0
- package/dist/plugins/debarrel.d.ts +7 -0
- package/dist/plugins/debarrel.js +2 -0
- package/dist/{packem_shared/browserslist-to-esbuild-DY9HwYtp.d.mts → plugins/esbuild/browserslist-to-esbuild.d.ts} +1 -2
- package/dist/plugins/esbuild/esbuild-plugin.d.ts +3 -0
- package/dist/plugins/esbuild/index.d.ts +3 -25
- package/dist/plugins/esbuild/index.js +1 -0
- package/dist/plugins/esbuild/types.d.ts +39 -0
- package/dist/plugins/esbuild/utils/get-render-chunk.d.ts +14 -0
- package/dist/plugins/esbuild/utils/optimize-deps.d.ts +3 -0
- package/dist/plugins/esbuild/utils/warn.d.ts +4 -0
- package/dist/plugins/esm-shim-cjs-syntax.d.ts +9 -0
- package/dist/plugins/fix-dts-default-cjs-exports-util.d.ts +35 -0
- package/dist/plugins/fix-dts-default-cjs-exports.d.ts +26 -0
- package/dist/plugins/fix-dts-default-cjs-exports.js +26 -0
- package/dist/plugins/fix-dynamic-import-extension.d.ts +3 -0
- package/dist/plugins/import-attributes.d.ts +2 -0
- package/dist/plugins/import-attributes.js +1 -0
- package/dist/plugins/json.d.ts +4 -0
- package/dist/plugins/json.js +1 -0
- package/dist/plugins/jsx-remove-attributes.d.ts +7 -0
- package/dist/plugins/jsx-remove-attributes.js +1 -0
- package/dist/plugins/license.d.ts +17 -0
- package/dist/plugins/license.js +13 -0
- package/dist/plugins/metafile.d.ts +3 -0
- package/dist/plugins/minify-html-literals/index.d.ts +41 -0
- package/dist/plugins/minify-html-literals/index.js +3 -0
- package/dist/plugins/minify-html-literals/lib/minify-html-literals.d.ts +200 -0
- package/dist/plugins/minify-html-literals/lib/models.d.ts +25 -0
- package/dist/plugins/minify-html-literals/lib/parse-literals.d.ts +13 -0
- package/dist/plugins/minify-html-literals/lib/strategy.d.ts +69 -0
- package/dist/plugins/minify-html-literals/lib/typescript.d.ts +23 -0
- package/dist/plugins/native-modules-plugin.d.ts +14 -0
- package/dist/plugins/native-modules-plugin.js +1 -0
- package/dist/plugins/oxc/index.d.ts +3 -28
- package/dist/plugins/oxc/index.js +1 -0
- package/dist/plugins/oxc/oxc-resolve-plugin.d.ts +4 -0
- package/dist/plugins/oxc/oxc-transformer-plugin.d.ts +3 -0
- package/dist/plugins/oxc/types.d.ts +16 -0
- package/dist/plugins/preserve-directives.d.ts +16 -0
- package/dist/{packem_shared/preserveDirectivesPlugin-B49Cbykd.mjs → plugins/preserve-directives.js} +2 -2
- package/dist/plugins/pure-new-expression-plugin.d.ts +11 -0
- package/dist/plugins/raw.d.ts +7 -0
- package/dist/plugins/raw.js +6 -0
- package/dist/plugins/require-cjs-transformer.d.ts +43 -0
- package/dist/plugins/require-cjs-transformer.js +21 -0
- package/dist/plugins/resolve-file-url.d.ts +3 -0
- package/dist/plugins/shebang.d.ts +9 -0
- package/dist/plugins/source-maps.d.ts +7 -0
- package/dist/plugins/sucrase/index.d.ts +8 -19
- package/dist/plugins/swc/index.d.ts +2 -26
- package/dist/plugins/swc/index.js +1 -0
- package/dist/plugins/swc/swc-plugin.d.ts +3 -0
- package/dist/plugins/swc/types.d.ts +6 -0
- package/dist/plugins/typescript/index.d.ts +7 -29
- package/dist/plugins/typescript/index.js +1 -0
- package/dist/plugins/typescript/patch-typescript-types.d.ts +13 -0
- package/dist/plugins/typescript/resolve-tsconfig-paths-plugin.d.ts +11 -0
- package/dist/plugins/typescript/resolve-tsconfig-root-dirs.d.ts +24 -0
- package/dist/plugins/typescript/resolve-typescript-mjs-cjs.d.ts +3 -0
- package/dist/plugins/url.d.ts +72 -0
- package/dist/plugins/url.js +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/utils/chunks/create-split-chunks.d.ts +11 -0
- package/dist/utils/chunks/get-custom-module-layer.d.ts +2 -0
- package/dist/utils/chunks/get-module-layer.d.ts +10 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/is-pure-cjs.d.ts +9 -0
- package/package.json +120 -37
- package/dist/index.d.mts +0 -64
- package/dist/index.mjs +0 -1
- package/dist/packem_shared/browserslist-to-esbuild-DY9HwYtp.d.ts +0 -3
- package/dist/packem_shared/cachingPlugin-D0BBFJPD.mjs +0 -1
- package/dist/packem_shared/copyPlugin--6RITp1-.mjs +0 -1
- package/dist/packem_shared/createSplitChunks-CGDk55G3.mjs +0 -1
- package/dist/packem_shared/dataUriPlugin-BOjv6O2O.mjs +0 -1
- package/dist/packem_shared/esbuildPlugin-BAwyhG6L.mjs +0 -1
- package/dist/packem_shared/fix-dts-default-cjs-exports-BQc0nwIG.mjs +0 -26
- package/dist/packem_shared/fixDtsDefaultCjsExportsPlugin-Dp1UcHVR.mjs +0 -1
- package/dist/packem_shared/isolatedDeclarationsOxcTransformer-WbfE6cGu.mjs +0 -1
- package/dist/packem_shared/isolatedDeclarationsPlugin-A0wmmw3Y.mjs +0 -3
- package/dist/packem_shared/isolatedDeclarationsSwcTransformer-Ch2AgtWC.mjs +0 -1
- package/dist/packem_shared/isolatedDeclarationsTypescriptTransformer-DkuEkofo.mjs +0 -3
- package/dist/packem_shared/jsonPlugin-BAi3Da-h.mjs +0 -1
- package/dist/packem_shared/jsxRemoveAttributes-B1PLPffj.mjs +0 -1
- package/dist/packem_shared/licensePlugin-C5yzUqe-.mjs +0 -13
- package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG.mjs +0 -1
- package/dist/packem_shared/oxcTransformPlugin-DfVQouIB.mjs +0 -4
- package/dist/packem_shared/patchTypescriptTypes-BEdkvKxL.mjs +0 -6
- package/dist/packem_shared/rawPlugin-BqlR6ZOI.mjs +0 -1
- package/dist/packem_shared/resolveTsconfigPathsPlugin-Crf4lzxq.mjs +0 -1
- package/dist/packem_shared/resolveTypescriptMjsCtsPlugin-DcZrZTmM.mjs +0 -1
- package/dist/packem_shared/types-yL82LLIx.d.mts +0 -4541
- package/dist/packem_shared/types-yL82LLIx.d.ts +0 -4541
- package/dist/packem_shared/urlPlugin-Bm2IE00y.mjs +0 -1
- package/dist/plugins/esbuild/index.d.mts +0 -25
- package/dist/plugins/esbuild/index.mjs +0 -1
- package/dist/plugins/oxc/index.d.mts +0 -28
- package/dist/plugins/oxc/index.mjs +0 -1
- package/dist/plugins/sucrase/index.d.mts +0 -19
- package/dist/plugins/swc/index.d.mts +0 -26
- package/dist/plugins/swc/index.mjs +0 -1
- package/dist/plugins/typescript/index.d.mts +0 -29
- package/dist/plugins/typescript/index.mjs +0 -1
- /package/dist/packem_shared/{browserslistToEsbuild-C0IWmbNe.mjs → browserslistToEsbuild-C0IWmbNe.js} +0 -0
- /package/dist/packem_shared/{chunkSplitter-DWAy1JkE.mjs → chunkSplitter-DWAy1JkE.js} +0 -0
- /package/dist/packem_shared/{fixDynamicImportExtension-BBGNRniz.mjs → fixDynamicImportExtension-BBGNRniz.js} +0 -0
- /package/dist/packem_shared/{getCustomModuleLayer-d8i66lfh.mjs → getCustomModuleLayer-d8i66lfh.js} +0 -0
- /package/dist/packem_shared/{getModuleLayer-rF9RxnJ5.mjs → getModuleLayer-rF9RxnJ5.js} +0 -0
- /package/dist/packem_shared/{index-Dq8IUFTs.mjs → index-Dq8IUFTs.js} +0 -0
- /package/dist/packem_shared/{resolveFileUrlPlugin-BkpjVHeK.mjs → resolveFileUrlPlugin-BkpjVHeK.js} +0 -0
- /package/dist/packem_shared/{swcPlugin-Boip4lWG.mjs → swcPlugin-Boip4lWG.js} +0 -0
- /package/dist/{packem_shared/esmShimCjsSyntaxPlugin-DjKqX4DE.mjs → plugins/esm-shim-cjs-syntax.js} +0 -0
- /package/dist/{packem_shared/makeExecutable-6aOVHoJR.mjs → plugins/shebang.js} +0 -0
- /package/dist/{packem_shared/sourcemapsPlugin-B4W3J79w.mjs → plugins/source-maps.js} +0 -0
- /package/dist/plugins/sucrase/{index.mjs → index.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
var v=Object.defineProperty;var
|
|
1
|
+
var v=Object.defineProperty;var a=(o,r)=>v(o,"name",{value:r,configurable:!0});import{join as d,resolve as p}from"@visulima/path";var g=Object.defineProperty,c=a((o,r)=>g(o,"name",{value:r,configurable:!0}),"u");const m=c((o,r)=>{if(!r)return;const{config:s,path:t}=r;if(!s.compilerOptions)return;const{rootDirs:e}=s.compilerOptions;if(!e)return;const n=[];for(const i of e){if(i.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${t}.`);if(i.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${t}.`);n.push(p(o,i))}return n},"getRootDirectories"),w=c((o,r,s)=>{const t=m(o,s);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(e,n,i){if(!(t===void 0||t.length===0)&&e.startsWith("."))for(const l of t){const u=d(l,e),f=await this.resolve(u,n,{skipSelf:!0,...i});if(f)return r.debug({message:`Resolved ${e} to ${f.id} using rootDirs from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-root-dirs"}),f.id}}}},"resolveTsconfigRootDirectories");export{w as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var u=(e,t)=>m(e,"name",{value:t,configurable:!0});import{isAbsolute as p}from"node:path";var v=Object.defineProperty,l=u((e,t)=>v(e,"name",{value:t,configurable:!0}),"i");const d={".cjs":[".cts"],".js":[".ts",".tsx"],".jsx":[".tsx",".ts"],".mjs":[".mts"]},x=/\.(?:[mc]?js|jsx)$/,h=l(e=>{const t=e[0];return!(t==="."||t==="/"||t==="#"||p(e))},"isBareSpecifier"),w=l(()=>({name:"packem:resolve-typescript-mjs-cjs",async resolveId(e,t,j){if(!t)return;const n=x.exec(e);if(!n)return;const i=n[0],r=d[i];if(!r)return;const a=e.slice(0,-i.length),o={...j,skipSelf:!0};if(!h(e)&&!t.includes("/node_modules/")){for(const c of r){const s=await this.resolve(a+c,t,o);if(s)return s}return}const f=await this.resolve(e,t,o);if(f)return f;for(const c of r)try{const s=await this.resolve(a+c,t,o);if(s)return s}catch{}}}),"resolveTypescriptMjsCts");export{w as default};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TransformOptions } from "@babel/core";
|
|
2
|
+
import type { FilterPattern } from "@rollup/pluginutils";
|
|
3
|
+
import type { Plugin } from "rollup";
|
|
4
|
+
export interface BabelPluginConfig extends Omit<TransformOptions, "filename" | "sourceFileName" | "exclude" | "include"> {
|
|
5
|
+
exclude?: FilterPattern;
|
|
6
|
+
filename?: string;
|
|
7
|
+
include?: FilterPattern;
|
|
8
|
+
sourceFileName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const babelTransformPlugin: ({ exclude, filename, generatorOpts, include, sourceFileName, ...transformOptions }: BabelPluginConfig) => Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=Object.defineProperty;var g=(r,e)=>y(r,"name",{value:e,configurable:!0});import{transformAsync as A}from"@babel/core";import{createFilter as b}from"@rollup/pluginutils";import{EXCLUDE_REGEXP as h}from"@visulima/packem-share/constants";var x=Object.defineProperty,c=g((r,e)=>x(r,"name",{value:e,configurable:!0}),"a");const O=/\.tsx?$/,w=c(r=>{if(r)return r.find(e=>e==="babel-plugin-react-compiler"||Array.isArray(e)&&e[0]==="babel-plugin-react-compiler")},"getReactCompilerPlugin"),E=c((r,e)=>{if(!r||!Array.isArray(r)||r.length===0)return;const t=w(r),p=/['"]use memo['"]/;if(!(!t||!Array.isArray(t))&&t[1]?.compilationMode==="annotation"&&!p.test(e)){const i=r.indexOf(t);i!==-1&&r.splice(i,1)}},"filterReactCompilerByAnnotation"),C=c(({exclude:r,filename:e,generatorOpts:t,include:p,sourceFileName:i,...n})=>{const d=b(p,r??h);return{name:"packem:babel",async transform(m,s){if(!d(s))return;let a=[];n.plugins&&Array.isArray(n.plugins)&&(a=[...n.plugins]),a.length>0&&E(a,m);const o=[];(s.endsWith(".jsx")||s.endsWith(".tsx"))&&o.push("jsx"),O.test(s)&&o.push("typescript");const u=n.parserOpts?.plugins;u&&Array.isArray(u)&&o.unshift(...u);const f=[...new Set(o)],l=await A(m,{...n,filename:e??s,generatorOpts:{...t,decoratorsBeforeExport:!0,importAttributesKeyword:"with"},parserOpts:{...n.parserOpts,allowAwaitOutsideFunction:!0,plugins:f.length>0?f:[],sourceType:"module"},plugins:a.length>0?a:[],sourceFileName:i??s});if(!(!l||!l.code))return{code:l.code,map:l.map||void 0}}}},"babelTransformPlugin");export{C as babelTransformPlugin};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileCache } from "@visulima/packem-share/utils";
|
|
2
|
+
import type { Plugin } from "rollup";
|
|
3
|
+
/**
|
|
4
|
+
* Wrap a Rollup plugin to add caching to various hooks.
|
|
5
|
+
* @param plugin
|
|
6
|
+
* @param cache
|
|
7
|
+
* @param subDirectory
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
declare const cachePlugin: (plugin: Plugin, cache: FileCache, subDirectory?: string) => Plugin;
|
|
11
|
+
export default cachePlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleInfo, PluginContext } from "rollup";
|
|
2
|
+
interface ExportInfo {
|
|
3
|
+
exportedName: string;
|
|
4
|
+
id: string;
|
|
5
|
+
sourceName: string;
|
|
6
|
+
}
|
|
7
|
+
declare const gatherExports: (context: PluginContext, module_: ModuleInfo) => AsyncGenerator<ExportInfo>;
|
|
8
|
+
export default gatherExports;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface BarrelReExport {
|
|
2
|
+
from: "other";
|
|
3
|
+
source: string;
|
|
4
|
+
type: "barrel";
|
|
5
|
+
}
|
|
6
|
+
export interface ExportBinding {
|
|
7
|
+
exportedName: string;
|
|
8
|
+
importedName: string;
|
|
9
|
+
}
|
|
10
|
+
export interface NamedReExport {
|
|
11
|
+
bindings: ExportBinding[];
|
|
12
|
+
from: "other";
|
|
13
|
+
source: string;
|
|
14
|
+
type: "named";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Modified copy of https://github.com/cprecioso/rollup-plugin-chunk-per-export/blob/main/src/parse/types.ts
|
|
18
|
+
*/
|
|
19
|
+
export interface NamedSelfExport {
|
|
20
|
+
exportedName: string;
|
|
21
|
+
from: "self";
|
|
22
|
+
type: "named";
|
|
23
|
+
}
|
|
24
|
+
export type ParsedExportInfo = BarrelReExport | NamedReExport | NamedSelfExport;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=Object.defineProperty;var l=(e,r)=>c(e,"name",{value:r,configurable:!0});import d from"magic-string";var i=Object.defineProperty,s=l((e,r)=>i(e,"name",{value:r,configurable:!0}),"u");const g=s(({addDefaultProperty:e=!1,logger:r})=>({name:"packem:cjs-interop",renderChunk:s(async(u,o,a)=>{if(!(o.type!=="chunk"||!o.isEntry)&&a.format==="cjs"&&a.exports==="auto"){const n=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(u);if(n===null||n.length<3)return;const t=new d(u);t.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),t.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&t.append(`
|
|
2
2
|
module.exports.default = ${n[2]};`);let p=t.toString();return p=p.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),r.debug({message:`Applied CommonJS interop to entry chunk ${o.fileName}.`,prefix:"plugin:cjs-interop"}),{code:p,map:t.generateMap({hires:!0})}}},"renderChunk")}),"cjsInteropPlugin");export{g as cjsInteropPlugin};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin } from "rollup";
|
|
2
|
+
export type CopyPluginOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Copy items once. Useful in watch mode.
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
copyOnce?: boolean;
|
|
8
|
+
exactFileNames?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Remove the directory structure of copied files.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
flatten?: boolean;
|
|
14
|
+
targets: MultipleTargetsDesc;
|
|
15
|
+
};
|
|
16
|
+
type MultipleTargetsDesc = SingleTargetDesc | SingleTargetDesc[] | string[] | string;
|
|
17
|
+
type SingleTargetDesc = {
|
|
18
|
+
dest?: string;
|
|
19
|
+
exclude?: string[] | string;
|
|
20
|
+
src: string[] | string;
|
|
21
|
+
};
|
|
22
|
+
export declare const copyPlugin: (options: CopyPluginOptions, logger: Console) => Plugin;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=Object.defineProperty;var f=(c,a)=>g(c,"name",{value:a,configurable:!0});import{stat as x}from"node:fs/promises";import{readFile as h}from"@visulima/fs";import{arrayify as y}from"@visulima/packem-share/utils";import{normalize as b,join as u,relative as w,dirname as F,basename as A}from"@visulima/path";import P from"glob-parent";import{glob as $}from"tinyglobby";var v=Object.defineProperty,j=f((c,a)=>v(c,"name",{value:a,configurable:!0}),"f");const C=j((c,a)=>{const n=new Map,p={copyOnce:!0,exactFileNames:!0,flatten:!1,...c};let{targets:o}=p;return Array.isArray(o)?o=o.map(s=>{if(typeof s=="string")return{src:s};if(typeof s=="object"&&"src"in s)return s}).filter(Boolean):typeof o=="string"&&(o=[{src:o}]),{async buildStart(){const s=await Promise.all(o.flatMap(e=>Array.isArray(e.src)?e.src.map(r=>({...e,src:r})):e).map(async e=>await $(y(e.src),{ignore:y(e.exclude).filter(Boolean)}).then(r=>({dest:e.dest??"",parent:P(e.src),src:r}))));for(const e of s)for(const r of e.src){let i;n.has(r)?i=n.get(r):(i={copied:[],dest:[],timestamp:0},n.set(r,i));const t=p.flatten?b(e.dest):u(e.dest,w(e.parent,F(r)));i.dest.includes(t)||i.dest.push(t),this.addWatchFile(r)}a.info({message:"Copying files...",prefix:"plugin:copy"}),await Promise.all(Array.from(n,async([e,r])=>{let i;try{const t=await x(e);if(!t.isFile())return;const l=t.mtime.getTime();l>r.timestamp&&(r.timestamp=l,r.copied=[]),i=await h(e,{buffer:!0})}catch(t){a.error({context:[t],message:`error reading file ${e}`,prefix:"plugin:copy"});return}for(const t of r.dest){if(p.copyOnce&&r.copied.includes(t))continue;const l=A(e),m=u(t,l);try{this.emitFile({[p.exactFileNames?"fileName":"name"]:m,source:i,type:"asset"}),a.debug({message:`copied ${e} → ${m}`,prefix:"plugin:copy"}),r.copied.push(t)}catch(d){a.error({context:[d],message:`error copying file ${e} → ${m}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");export{C as copyPlugin};
|
|
@@ -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 I=Object.defineProperty;var $=(e,t)=>I(e,"name",{value:t,configurable:!0});import j from"node:fs/promises";import{createFilter as M}from"@rollup/pluginutils";import B from"magic-string";import*as E from"rs-module-lexer";var A=Object.defineProperty,d=$((e,t)=>A(e,"name",{value:t,configurable:!0}),"c");const D=/\.[mc]?tsx?(?:\?.*)?$/,O=/(?:\.(?:[tj]s|[tj]sx)|\/index\.(?:[tj]s|[tj]sx))(?:\?.*)?$/,k=/^\s*export/,z={exports:[],facade:!1,imports:[]},b=d(e=>D.test(e),"isSourceFile"),y=d(e=>e.includes("/build/cache/vite/")||e.includes("/node_modules/"),"isIgnoredModule"),K=d((e,t)=>y(e)?!1:O.test(e)?!0:t.possibleBarrelFiles?t.possibleBarrelFiles.some(r=>e.match(r)):!1,"isPossibleBarrelSpecifier"),N=d(e=>k.test(e)?"export":"import","getDeclarationKind"),{parseAsync:R}=E,C=d(async(e,t,r)=>{try{const{output:a}=await R({input:[{code:t,filename:e}]});return a[0]}catch(a){return r.debug({message:`Failed to parse ${e}:
|
|
2
|
+
${a instanceof Error?a.message:String(a)}`,prefix:"plugin:debarrel"}),z}},"safeParse"),T=d(async(e,t,r,a)=>{const s=e.parseCache.get(t);if(s!==void 0)return s;const i=await C(t,r,a);return e.parseCache.set(t,i),i},"parsePotentialBarrelFile"),P=d((e,t)=>{const r=e.fileCache.get(t);if(r!==void 0)return r;const a=j.readFile(t,"utf8");return e.fileCache.set(t,a),a},"readFileCached"),S=d(e=>{const t=/^(?:import|export)\s+([\w$]+)/,r=/([\w$]+)\s*,\s*\{|\}\s*,\s*([\w$]+)/,a=/[{,]\s*(type\s+)?([\w$]+)(?:\s+as\s+([\w$]+))?/gi;a.lastIndex=0;const s=[];if(e.includes("*"))return s;if(!e.includes("{")){const n=e.match(t);return n&&s.push({imported:"default",local:n[1]}),s}const i=e.match(r);i&&s.push({imported:"default",local:i[1]||i[2]});let o;for(;o=a.exec(e);)o[1]||o[2]&&s.push({imported:o[2],local:o[3]});return s},"getImportNames"),_=d((e,t,r)=>{let a=e.ln,s=t.find(i=>i.ss<e.s&&i.se>e.e&&i.d===-1);if(!s||!s.n){const i=a||r.slice(e.s).match(/default\s+([a-zA-Z_$][\w$]*)(?:;|\n|$)/)?.[1];i&&(s=t.find(o=>{const n=S(r.slice(o.ss,o.s)).find(l=>l.local===i);return n&&(a=n.imported),n}))}if(s&&!a){const i=r.slice(s.ss,e.s);if(!i.includes("*")){const o=i.match(/([\w$]+)\s*as\s*$/)?.[1];o&&(a=o)}}return{imp:s,localExportName:a}},"findMatchingImport"),v=d(async(e,t,r,a,s)=>{const{resolve:i}=e,o=await P(e,t),{exports:n,imports:l}=await T(e,t,o,s);for await(const c of n){const u=c.n;if(u!==r)continue;const f=_(c,l,o),{imp:p,localExportName:h}=f;if(!p||!p.n)return{exportName:r,id:t,resolved:!0};if(p.d>-1)return{exportName:r,id:t,resolved:!0};let g;const x=o.slice(p.ss,c.s);if(N(x)==="import"&&/\bas\b/.test(x)){const F=new RegExp(String.raw`(\w+)\s+as\s+${r}(?!\w)`);g=x.match(F)?.[0]}const w=(await i(p.n,t))?.id;return w?K(w,a)?v(e,w,h||u,a,s):{aliasedImportName:g,exportName:h||r,id:w,resolved:!1}:{aliasedImportName:g,exportName:h,id:t,resolved:!1}}const m=l.filter(c=>/^export\s+\*(?!\s+as)/.test(o.slice(c.ss,c.s)));if(m.length===1){const c=m[0]?.n,u=c?(await e.resolve(c,t))?.id:void 0;if(!u)return{exportName:r,id:t,resolved:!1};const f=await v(e,u,r,a,s);if(f.resolved)return f}else if(m.length>1){const c=(await Promise.all(m.map(async u=>{const f=u.n,p=f?(await e.resolve(f,t))?.id:void 0;if(p)return v(e,p,r,a,s)}))).find(u=>u?.resolved);if(c)return c}return{exportName:r,id:t,resolved:!1}},"resolveThroughBarrel"),J=d((e,t,r)=>{const{aliasedImportName:a,exportName:s}=e,i=t.local||t.imported;return a?`{${a}}`:s==="default"&&r!=="export"?i:`{${s!==i?`${s} as ${i}`:s}}`},"getDeclarationClause"),L=d(async(e,t,r,a,s)=>{const i=[],o=await P(e,t),{imports:n}=await C(t,o,s);return await Promise.all(n.map(async l=>{if(!l.n||l.d!==-1)return;const m=o.slice(l.ss,l.s),c=S(m);if(c.length===0)return;const u=(await e.resolve(l.n,t))?.id;if(!u||!b(u)||y(u))return;const f=N(m);try{const p=await Promise.all(c.map(async h=>{const g=await v(e,u,h.imported,a,s);if(!g)return;const x=J(g,h,f),w=JSON.stringify(g.id);return`${f} ${x} from ${w}`}));if(p.includes(void 0))return;i.push([l.ss,l.se,p.join(";")])}catch(p){s.warn({context:{error:p},message:String(p),prefix:"plugin:debarrel"})}})),i},"getDebarrelModifications"),X=d((e,t,r,a)=>{if(r.length===0)return;const s=new B(t,{filename:e});for(const[i,o,n]of r)s.update(i,o,n);return{code:s.toString(),map:a?s.generateMap({file:e}):void 0}},"applyModifications"),Q=d((e,t)=>{const r=new Map,a=new Map,s=d(()=>{r.clear(),a.clear()},"purgeCaches"),i=e.include?M(e.include,[]):void 0;let o=!0;return{buildEnd:s,buildStart:s,async load(n){const l=r.get(n);if(l)return await l},name:"packem:debarrel",options(n){(n.output&&(Array.isArray(n.output)?n.output[0]?.sourcemap:n?.output?.sourcemap))===!1&&(o=!1)},async transform(n,l){if(!b(l)||i&&!i(l))return;const m={fileCache:r,parseCache:a,resolve:this.resolve.bind(this)},c=await L(m,l,n,e,t);return X(l,n,c,o)},watchChange(n){r.delete(n),a.delete(n)}}},"debarrelPlugin");export{Q as debarrelPlugin};
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
export
|
|
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-C5x4_cXf.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,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,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,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,26 @@
|
|
|
1
|
+
var N=Object.defineProperty;var E=(r,t)=>N(r,"name",{value:t,configurable:!0});import y from"magic-string";import{findExports as j,findStaticImports as I,parseStaticImport as A}from"mlly";import{parseSync as C}from"oxc-parser";var T=Object.defineProperty,g=E((r,t)=>T(r,"name",{value:t,configurable:!0}),"h");const _=g((r,t,a)=>{const i=j(r).find(e=>e.names?.includes("default")),o=r.match(/^export\s+default\s+(\w+);/m);if(o&&o[1])return{defaultAlias:o[1],defaultExport:{code:o[0],end:o.index===void 0?void 0:o.index+o[0].length,names:["default"],specifier:void 0,start:o.index,type:"default"},exports:[]};if(!i)return;const p=i.code.match(/export\s*\{([^}]*)\}/);if(!p?.length){a.warn?.(`A default export was indicated in ${t.fileName}, but its structure could not be parsed.`);return}let l;const c=[];for(const e of p[1].split(",").map(n=>n.trim())){if(e==="default"){l=e;continue}const n=e.match(/\s*as\s+default\s*/);n?l=e.replace(n[0],""):c.push(e)}if(!l){a.warn?.(`A default export was indicated in ${t.fileName}, but its alias could not be determined from the export statement.`);return}return{defaultAlias:l,defaultExport:i,exports:c}},"extractExports"),k=g((r,t,a)=>{if("declarations"in t&&t.declarations.length>0){const i=t.declarations[0];if(i&&i.id.type==="Identifier"){r.set(i.id.name,{declare:t.declare===!0,end:t.end,isVariable:!0,start:t.start});return}}if("id"in t&&t.id&&t.id.type==="Identifier"){const{name:i}=t.id;r.set(i,{declare:t.declare===!0,end:t.end,isClass:t.type==="ClassDeclaration",start:t.start});return}r.set(a(),{declare:t.declare===!0,end:t.end,start:t.start})},"prepareDeclaration"),D=g((r,t,a,i)=>{const o=C(a.fileName,r,{astType:"ts",lang:"ts",sourceType:"module"});let p,l=0;const c=g(()=>(l+=1,`__unnamed_${l}$$`),"generateUnnamed"),e=new Map,n=new Map,{program:m}=o;for(const s of m.body)if(s.type==="ExportNamedDeclaration")for(const f of s.specifiers)f.exported.type==="Identifier"&&(f.exported.name==="default"?f.local.type==="Identifier"&&(p={end:f.end,local:f.local.name,start:f.start}):f.exported.type==="Identifier"&&n.set(f.exported.name,{type:f.exportKind==="type"}));else{if(s.type==="ImportDeclaration")continue;switch(s.type){case"ClassDeclaration":case"FunctionDeclaration":case"TSDeclareFunction":case"TSEnumDeclaration":case"TSInterfaceDeclaration":case"TSTypeAliasDeclaration":case"VariableDeclaration":{k(e,s,c);break}case"TSImportEqualsDeclaration":case"TSModuleDeclaration":{e.set(c(),{declare:!1,end:s.end,start:s.start});break}}}const x=[];if(p)for(const[s,f]of n.entries())s!==p.local&&f.type&&x.push(s);if(!p){const s=[...n.values()].every(f=>f.type);return t.startsWith("export type")&&n.size>0&&s||i.warn?.(`Cannot infer default export from the file: ${a.fileName}`),t}if(!e.get(p.local))return i.warn?.(`Cannot infer default export from the file: ${a.fileName}. Declaration for '${p.local}' not found.`),t;const u=t,d=new y(`${u}
|
|
2
|
+
declare namespace ${p.local} {
|
|
3
|
+
`);for(const[s,f]of e.entries()){if(x.includes(s)&&s!==p.local)continue;const h=r.slice(f.start,f.end).replace(/\s+\}$/," }");d.append(" "),f.declare?d.append(h.replace("declare","export").replaceAll(" "," ")):d.append(`export ${h}`.replaceAll(" "," ")),d.append(`
|
|
4
|
+
`)}return d.append(` import _default = ${p.local};
|
|
5
|
+
export { _default as default };
|
|
6
|
+
`),d.append(`}
|
|
7
|
+
export = ${p.local};
|
|
8
|
+
`),d.toString()},"createCjsNamespace"),v=g((r,t,a)=>{const{defaultExport:i,exports:o}=t;if(a){let x="";x=o.length===0?`export = ${a.defaultImport};`:`// @ts-ignore
|
|
9
|
+
export = ${a.defaultImport};
|
|
10
|
+
export { ${o.join(", ")} } from '${i.specifier}'`;const u=r.replace(i.code.replace(/;$/,""),x.replace(/;$/,""));return u.endsWith(";")?u:`${u};`}const p=`import _default from '${i.specifier}';`,l=new y(r),c=I(r),e=c.length>0?c.at(-1):void 0;e?.end!==void 0&&e.end>0?l.appendRight(e.end,`
|
|
11
|
+
${p}
|
|
12
|
+
`):l.prepend(`${p}
|
|
13
|
+
`);let n=l.toString();n=n.replaceAll(/(\r?\n\s*){2,}/g,`
|
|
14
|
+
`);let m;if(o.length===0)m=n.replace(i.code.replace(/;$/,""),"export = _default");else{const x=`// @ts-ignore
|
|
15
|
+
export = _default;
|
|
16
|
+
export { ${o.join(", ")} } from '${i.specifier}';`;m=n.replace(i.code.replace(/;$/,""),x)}return m.replaceAll(";;",";")},"handleDefaultCJSExportAsDefault"),M=g((r,t,a,i,o,p)=>{const{defaultAlias:l,defaultExport:c,exports:e}=a;if(p){if(p.namedImports?.[l]===l){if(e.length===0)return r.replace(c.code,`export = ${l}`);const d=`export { ${e.join(", ")} } from '${c.specifier}'`,s=new y(r).replace(c.code,d).toString();return D(r,s,t,o)}o.warn?.(`Cannot parse "${l}" named export from ${p.specifier} import at ${t.fileName}!.`);return}const n=`import { ${l} } from '${c.specifier}';
|
|
17
|
+
`;let m=r;const x=i.length>0?i.at(-1)?.end??0:0,u=new y(m);if(x>0?u.appendRight(x,`
|
|
18
|
+
${n}`):u.prepend(n),m=u.toString(),e.length>0){const d=`export { ${e.join(", ")} } from '${c.specifier}'`,s=new y(m).replace(c.code,d).toString();return D(r,s,t,o)}return new y(m).replace(c.code,`export = ${l}`).toString()},"handleDefaultNamedCJSExport"),S=g((r,t,{defaultAlias:a,defaultExport:i,exports:o},p)=>{const l=o.filter(e=>/^type\s+/.test(e)),c=o.filter(e=>!/^type\s+/.test(e));if(l.length>0){let e="";return a&&(e+=`// @ts-ignore
|
|
19
|
+
${a};
|
|
20
|
+
`),e+=`export type { ${l.map(n=>n.replace(/^type\s+/,"").trim()).join(", ")} };
|
|
21
|
+
`,c.length>0&&(e+=`export { ${c.join(", ")} };
|
|
22
|
+
`),D(r,e.trim(),t,p)}if(a&&c.length>0&&l.length===0){let e=`// @ts-ignore
|
|
23
|
+
${a};
|
|
24
|
+
`;return e+=`export { ${c.join(", ")} };
|
|
25
|
+
`,D(r,e.trim(),t,p)}if(a&&c.length===0&&l.length===0){const e=new RegExp(String.raw`^export\\s+default\\s+${a};`,"m"),n=r.match(e);return n?`${r.slice(0,Math.max(0,n.index??0))}export = ${a};`:r.replace(i.code,`export = ${a};`).replace(";;",";")}},"handleNoSpecifierDefaultCJSExport"),P=/^export\s+default\s+from\s+['"]([^'"]+)['"];?$/m,J=g((r,t,a)=>{const i=r.match(P);if(i)return{code:`import _default from '${i[1]}';
|
|
26
|
+
export = _default;`,map:void 0};const o=_(r,t,a);if(o){let e;if(o.defaultExport.specifier){const{specifier:n}=o.defaultExport,m=I(r),x=m.filter($=>$.imports).map($=>A($)),u=x.find($=>$.specifier===n),{defaultAlias:d,defaultExport:s,exports:f}=o,h=s.exports;if(d==="default"&&s.specifier&&f.length>0)e=v(r,o,u);else if(d==="default"&&s.specifier&&f.length===0&&h&&/\bas\s+default\b/.test(h))x.find($=>$.specifier===s.specifier)?.defaultImport?e=v(r,o,u):(a.warn?.(`Cannot parse default export name from ${s.specifier} import at ${t.fileName}!. The module might not have a default export, or it's aliased as 'default'.`),e=void 0);else if(d==="default"&&s.specifier&&f.length===0)e=v(r,o,u);else if(s.specifier&&d!=="default"){e=M(r,t,o,m,a,u);const $=u&&o.defaultExport.specifier&&d!=="default"&&(!u.namedImports||u.namedImports[d]!==d);if(!(e===void 0&&$)&&e===void 0&&!(d==="default"&&f.length===0&&h&&/\bas\s+default\b/.test(h))){const w=S(r,t,o,a);w&&(e=w)}}}else e=S(r,t,o,a);return e?{code:e,map:void 0}:void 0}const p=C(t.fileName,r,{astType:"ts",lang:"ts",sourceType:"module"});let l=[],c=!1;if(p.program.body.length>0){const e=p.program.body.at(-1);e?.type==="ExportNamedDeclaration"&&!e.declaration&&e.specifiers.length>0&&e.specifiers.every(n=>n.exportKind==="type")&&(c=!0,l=e.specifiers.map(n=>n.local.type==="Identifier"?n.local.name:"").filter(Boolean))}if(c&&l.length>0){const e=`export type { ${l.join(", ")} };`,n=D(r,e,t,a);return n?{code:n,map:void 0}:void 0}},"fixDtsDefaultCJSExports");var R=Object.defineProperty,b=E((r,t)=>R(r,"name",{value:t,configurable:!0}),"n");const W=b((r={})=>{const{matcher:t=b(a=>(a.type==="chunk"||a.type==="asset")&&a.exports?.length>0&&/\.d\.c?ts$/.test(a.fileName)&&a.isEntry,"matcher")}=r;return{name:"packem:fix-dts-default-cjs-exports-plugin",renderChunk(a,i){return t(i)?J(a,{fileName:i.fileName,imports:i.imports},{warn:this.warn}):void 0}}},"fixDtsDefaultCjsExportsPlugin");export{W as fixDtsDefaultCjsExportsPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var a=(e,t)=>o(e,"name",{value:t,configurable:!0});import{readFile as s}from"node:fs/promises";import{resolve as u,dirname as l}from"node:path";var p=Object.defineProperty,c=a((e,t)=>p(e,"name",{value:t,configurable:!0}),"o");const d=c(()=>{const e=new Map;return{name:"packem:import-attributes",async resolveId(t,r,{attributes:i}){if(i.type!=="text"&&i.type!=="bytes"||!r||!t.startsWith("./")&&!t.startsWith("../"))return null;const n=u(l(r),t);return e.set(n,i.type),n},async load(t){const r=e.get(t);if(!r)return null;if(this.addWatchFile(t),r==="text"){const i=await s(t,"utf8");return`export default ${JSON.stringify(i)}`}return r==="bytes"?`export default new Uint8Array([${(await s(t)).join(",")}])`:null}}},"importAttributesPlugin");export{d as importAttributesPlugin};
|
|
@@ -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 @@
|
|
|
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,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,O=g((t,e)=>$(t,"name",{value:e,configurable:!0}),"f");const S={One:"1",Two:"2",Zero:"0"},F=O(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"),C=O((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,removeAttributeQuotes:!1,removeComments:!0,removeEmptyAttributes:!0,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0},x=O((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=C(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=C(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),P=!!r.minifyCSS&&a(l);if(d||P){const v=r.getPlaceholder(l.parts);n&&n.ensurePlaceholderValid(v);const T=r.combineHTMLStrings(l.parts,v);let h;if(P){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};
|